selectAddress.vue 3.9 KB

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