selectAddress.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view>
  3. <picker :class="disabled?'pickerClass':''" ref='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. <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. multiArray: [
  63. [],
  64. [],
  65. []
  66. ],
  67. }
  68. },
  69. mounted() {
  70. console.log(this.disabled)
  71. this.place = this.searchPlace
  72. console.log("this.series", this.series)
  73. for (let i = 0; i < address.length; i++) {
  74. this.multiArray[0].push(address[i])
  75. }
  76. // this.$emit('selectAddress', '')
  77. },
  78. methods: {
  79. columnchange(e) {
  80. console.log('picker发送选择改变', e.detail)
  81. this.multiIndex[e.detail.column] =e.detail.value
  82. console.log("this.multiIndex", this.multiIndex)
  83. switch (e.detail.column) {
  84. case 0: //拖动第1列
  85. this.multiArray[1] = address[e.detail.value].child
  86. this.multiArray[2] = this.multiArray[1][0].child
  87. console.log(this.multiArray[1])
  88. this.multiIndex.splice(1, 1, 0)
  89. this.multiIndex.splice(2, 1, 0)
  90. break
  91. case 1: //拖动第2列
  92. this.multiArray[2] = this.multiArray[1][this.multiIndex[1]].child
  93. this.multiIndex.splice(2, 1, 0)
  94. break
  95. }
  96. this.$forceUpdate()
  97. },
  98. bindPickerChange: function(e) {
  99. this.check = false
  100. console.log('picker发送选择改变,携带值为', e.detail.value)
  101. this.index = e.detail.value
  102. console.log(this.multiArray)
  103. //判断全部
  104. let _address = ''
  105. let _showVal = ''
  106. if (this.multiArray[0][e.detail.value[0]].label == '全国') {
  107. _address = ''
  108. this.place = '全国'
  109. } else if (this.multiArray[1][e.detail.value[1]]
  110. .label == '全部') {
  111. _address = this.multiArray[0][e.detail.value[0]].label
  112. this.place = this.multiArray[0][e.detail.value[0]].label
  113. } else if (this.multiArray[2][e.detail.value[2]].label == '全部') {
  114. _address = this.multiArray[0][e.detail.value[0]].label + this.multiArray[1][e.detail.value[1]]
  115. .label
  116. this.place = this.multiArray[1][e.detail.value[1]].label
  117. } else {
  118. _address = this.multiArray[0][e.detail.value[0]].label + this.multiArray[1][e.detail.value[1]]
  119. .label + this.multiArray[2][e.detail.value[2]].label
  120. this.place = this.multiArray[2][e.detail.value[2]].label
  121. this.check = true
  122. }
  123. if (this.series == 3) {
  124. if (!_address) {
  125. this.place = '全国'
  126. }
  127. if (this.check) {
  128. this.place = _address
  129. } else {
  130. this.place = this.searchPlace
  131. }
  132. }
  133. console.log("_showVal", this.place)
  134. console.log("_address", _address)
  135. console.log("this.check", this.check)
  136. this.$emit('selectAddress', {
  137. showVal: this.place,
  138. address: _address,
  139. check: this.check
  140. })
  141. }
  142. },
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .text{
  147. display:inline-block;
  148. }
  149. </style>