selectAddress.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view>
  3. <picker @change="bindPickerChange" :value="multiIndex" :range="multiArray" range-key='label'
  4. mode="multiSelector" @columnchange='columnchange'>
  5. <view class="text" :style="textStyle">{{searchPlace}}</view>
  6. </picker>
  7. </view>
  8. </template>
  9. <script>
  10. import {
  11. address
  12. } from '@/components/data/data.js'
  13. export default {
  14. name: 'selectAddress',
  15. props: {
  16. series: {
  17. type: String,
  18. default: '1'
  19. },
  20. textStyle: {
  21. type: Object,
  22. }
  23. },
  24. watch: {
  25. // keyword:function(val){
  26. // let arr = this.tList;
  27. // if(val!=''){
  28. // this.list = arr.filter(v => {
  29. // let flag = false
  30. // if(v.members.length>0){
  31. // v.members.forEach(m=>{
  32. // if(m.groupNickName.includes(val)){
  33. // flag = true
  34. // }
  35. // })
  36. // }
  37. // return flag
  38. // })
  39. // }else {
  40. // this.list = this.tList
  41. // }
  42. // }
  43. },
  44. data() {
  45. return {
  46. searchPlace: '全国',
  47. multiIndex: [0, 0, 0],
  48. multiArray: [
  49. [],
  50. [],
  51. []
  52. ],
  53. }
  54. },
  55. mounted() {
  56. for (let i = 0; i < address.length; i++) {
  57. this.multiArray[0].push(address[i])
  58. }
  59. },
  60. methods: {
  61. columnchange(e) {
  62. console.log('picker发送选择改变', e.detail)
  63. this.multiIndex[e.detail.column] = e.detail.value
  64. console.log("this.multiIndex", this.multiIndex)
  65. switch (e.detail.column) {
  66. case 0: //拖动第1列
  67. this.multiArray[1] = address[e.detail.value].child
  68. this.multiArray[2] = this.multiArray[1][0].child
  69. console.log(this.multiArray[1])
  70. this.multiIndex.splice(1, 1, 0)
  71. this.multiIndex.splice(2, 1, 0)
  72. break
  73. case 1: //拖动第2列
  74. this.multiArray[2] = this.multiArray[1][this.multiIndex[1]].child
  75. this.multiIndex.splice(2, 1, 0)
  76. break
  77. }
  78. this.$forceUpdate()
  79. },
  80. bindPickerChange: function(e) {
  81. console.log('picker发送选择改变,携带值为', e.detail.value)
  82. this.index = e.detail.value
  83. console.log(this.multiArray)
  84. //判断全部
  85. let _address = ''
  86. let _showVal = ''
  87. if (this.multiArray[0][e.detail.value[0]].label == '全国') {
  88. _address = ""
  89. _showVal = '全国'
  90. } else if (this.multiArray[1][e.detail.value[1]]
  91. .label == '全部') {
  92. _address = this.multiArray[0][e.detail.value[0]].label
  93. this.searchPlace = this.multiArray[0][e.detail.value[0]].label
  94. } else if (this.multiArray[2][e.detail.value[2]].label == '全部') {
  95. _address = this.multiArray[0][e.detail.value[0]].label + this.multiArray[1][e.detail.value[1]]
  96. .label
  97. this.searchPlace = this.multiArray[1][e.detail.value[1]].label
  98. } else {
  99. _address = this.multiArray[0][e.detail.value[0]].label + this.multiArray[1][e.detail.value[1]]
  100. .label + this.multiArray[2][e.detail.value[2]].label
  101. this.searchPlace = this.multiArray[2][e.detail.value[2]].label
  102. }
  103. if (this.series == 3) {
  104. if (!_address) {
  105. this.searchPlace = '全国'
  106. return
  107. }
  108. this.searchPlace = _address
  109. }
  110. console.log("_showVal", _showVal)
  111. console.log("_address", _address)
  112. this.$emit('selectAddress', _address)
  113. }
  114. },
  115. }
  116. </script>
  117. <style lang="scss">
  118. .list-cell {
  119. display: flex;
  120. box-sizing: border-box;
  121. width: 100%;
  122. padding: 10px 24rpx;
  123. overflow: hidden;
  124. color: #323233;
  125. font-size: 28rpx;
  126. font-weight: 800;
  127. line-height: 48rpx;
  128. background-color: #fff;
  129. border-bottom: solid 3rpx #eeeeee;
  130. align-items: center;
  131. image {
  132. width: 76rpx;
  133. height: 76rpx;
  134. border-radius: 12rpx;
  135. flex: 0 0 76rpx;
  136. }
  137. &-name {
  138. padding-left: 20rpx;
  139. }
  140. }
  141. </style>