123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <template>
- <picker @change="pickerChange" @columnchange="columnchange" :range="array" range-key="name" :value="value" mode="multiSelector">
- <slot></slot>
- </picker>
- </template>
- <script>
-
- export default {
- data() {
- return{
- value: [],
- array: [],
- index: 0,
- AllAddress:[]
- }
- },
- props:{
-
- level:{
- type: Number,
- default: 3
- }
- },
- created() {
- console.log('请求地址')
- this.getAllAddress()
- },
- methods:{
- getAllAddress(){
- uni.showLoading({
- title:'加载中'
- })
- uni.$u.http.post('/api/Publics/area').then(res => {
- uni.hideLoading()
- this.AllAddress=res.data
- this.init()
- }).catch(err=>{
- uni.hideLoading()
- })
- },
-
- init() {
- this.array = new Array(this.level);
- for(let i = 0; i<this.array.length;i++){
- if(i==0){
- this.array[i] = this.AllAddress
- } else {
- this.array[i] = [];
- if (this.array[i-1][0].children != null) {
- this.array[i] = this.array[i-1][0].children;
- }
- }
-
- }
- this.$forceUpdate()
- },
-
- columnchange(e) {
-
- let aIndex = JSON.parse(JSON.stringify(e.detail.column+1));
- let j = e.detail.value;
-
-
-
- for(let i=aIndex; i<this.array.length; i++){
-
-
-
- this.array[i] = [];
- console.log('this.array[i] ',i,)
- if(e.detail.column === 0 && i===2){
- if (this.array[i-1][0].children != null) {
- this.array[i] = this.array[i-1][0].children;
- }
- }else{
- if (this.array[i-1][j].children != null) {
- this.array[i] = this.array[i-1][j].children;
- }
- }
-
-
- }
-
- this.$forceUpdate();
- },
-
- pickerChange(e) {
- var result = [];
- for(let i=0; i<this.array.length; i++){
- result.push({
- name: this.array[i][e.target.value[i]].name,
- id: this.array[i][e.target.value[i]].id
- })
- };
- this.$emit('change', {
- data: result
- })
- }
-
- }
- }
- </script>
- <style>
- </style>
|