selectAddress.vue 4.0 KB

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