123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <template>
- <view>
- <picker @change="bindPickerChange" :value="multiIndex" :range="multiArray" range-key='label'
- mode="multiSelector" @columnchange='columnchange'>
- <view class="text" :style="textStyle">{{searchPlace}}</view>
- </picker>
- </view>
- </template>
- <script>
- import {
- address
- } from '@/components/data/data.js'
- export default {
- name: 'selectAddress',
- props: {
- series: {
- type: String,
- default: '1'
- },
- textStyle: {
- type: Object,
- },
- placeHolder:{
- type: String,
- default: '全国'
- },
- forbid:{
- type: Boolean,
- default: false
- }
- },
- watch: {
- placeHolder:{
- handler(val){
- console.log(val)
- this.searchPlace=val
- this.placeHolder=val
- },
- deep:true
- }
- // keyword:function(val){
- // let arr = this.tList;
- // if(val!=''){
- // this.list = arr.filter(v => {
- // let flag = false
- // if(v.members.length>0){
- // v.members.forEach(m=>{
- // if(m.groupNickName.includes(val)){
- // flag = true
- // }
- // })
- // }
- // return flag
- // })
- // }else {
- // this.list = this.tList
- // }
- // }
- },
- data() {
- return {
- searchPlace: this.placeHolder,
- multiIndex: [0, 0, 0],
- multiArray: [
- [],
- [],
- []
- ],
- }
- },
- mounted() {
- for (let i = 0; i < address.length; i++) {
- this.multiArray[0].push(address[i])
- }
- // this.$emit('selectAddress', '')
- },
- methods: {
- columnchange(e) {
-
- console.log('picker发送选择改变', e.detail)
- this.multiIndex[e.detail.column] = e.detail.value
- console.log("this.multiIndex", this.multiIndex)
- switch (e.detail.column) {
- case 0: //拖动第1列
- this.multiArray[1] = address[e.detail.value].child
- this.multiArray[2] = this.multiArray[1][0].child
- console.log(this.multiArray[1])
- this.multiIndex.splice(1, 1, 0)
- this.multiIndex.splice(2, 1, 0)
- break
- case 1: //拖动第2列
- this.multiArray[2] = this.multiArray[1][this.multiIndex[1]].child
- this.multiIndex.splice(2, 1, 0)
- break
- }
- this.$forceUpdate()
- },
- bindPickerChange: function(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- console.log(e.detail.value[0])
- if(this.forbid&&e.detail.value[0]==0){
- uni.showToast({
- title: "请选择除全国外的其他区域!",
- icon: 'none',
- duration: 2000
- })
- return
- }
- this.index = e.detail.value
- console.log(this.multiArray)
- //判断全部
- let _address = ''
- let _showVal = ''
- if (this.multiArray[0][e.detail.value[0]].label == '全国') {
- _address = "全国"
- _showVal = '全国'
- } else if (this.multiArray[1][e.detail.value[1]]
- .label == '全部') {
- _address = this.multiArray[0][e.detail.value[0]].label
- this.searchPlace = this.multiArray[0][e.detail.value[0]].label
- } else if (this.multiArray[2][e.detail.value[2]].label == '全部') {
- _address = this.multiArray[0][e.detail.value[0]].label + this.multiArray[1][e.detail.value[1]]
- .label
- this.searchPlace = this.multiArray[1][e.detail.value[1]].label
- } else {
- _address = this.multiArray[0][e.detail.value[0]].label + this.multiArray[1][e.detail.value[1]]
- .label + this.multiArray[2][e.detail.value[2]].label
- this.searchPlace = this.multiArray[2][e.detail.value[2]].label
- }
- if (this.series == 3) {
- if (!_address) {
- this.searchPlace = '全国'
- return
- }
- this.searchPlace = _address
- }
- console.log("_showVal", _showVal)
- console.log("_address", _address)
- this.$emit('selectAddress', _address)
- }
- },
- }
- </script>
- <style lang="scss">
- .list-cell {
- display: flex;
- box-sizing: border-box;
- width: 100%;
- padding: 10px 24rpx;
- overflow: hidden;
- color: #323233;
- font-size: 28rpx;
- font-weight: 800;
- line-height: 48rpx;
- background-color: #fff;
- border-bottom: solid 3rpx #eeeeee;
- align-items: center;
- image {
- width: 76rpx;
- height: 76rpx;
- border-radius: 12rpx;
- flex: 0 0 76rpx;
- }
- &-name {
- padding-left: 20rpx;
- }
- }
- </style>
|