selectAddress.vue 4.1 KB

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