selectAddress.vue 4.2 KB

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