selectAddress.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view>
  3. <picker class="pickerClass" ref='picker' :disabled="disabled" @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. disabled:{
  39. value: Boolean,
  40. default: false
  41. }
  42. },
  43. watch: {
  44. disabled(oldValue, newValue) {
  45. console.log(123)
  46. console.log(oldValue, newValue)
  47. if(newValue){
  48. }else{
  49. // this.$refs.picker.change()
  50. // console.log(this.$refs.picker)
  51. this.bindPickerChange(this.$refs.picker.value)
  52. // this.bindPickerChange()
  53. }
  54. // if (val != '') {
  55. // this.place = val
  56. // }
  57. }
  58. // searchPlace(oldValue, newValue) {
  59. // console.log(123)
  60. // console.log(oldValue, newValue)
  61. // // if (val != '') {
  62. // // this.place = val
  63. // // }
  64. // }
  65. },
  66. data() {
  67. return {
  68. check: false,
  69. place: '',
  70. textStyleEmpty: {
  71. "color": '#C5CAD4',
  72. "font-size": '32rpx'
  73. },
  74. multiIndex: [0, 0, 0],
  75. multiArray: [
  76. [],
  77. [],
  78. []
  79. ],
  80. }
  81. },
  82. mounted() {
  83. console.log(this.disabled)
  84. this.place = this.searchPlace
  85. console.log("this.series", this.series)
  86. for (let i = 0; i < address.length; i++) {
  87. this.multiArray[0].push(address[i])
  88. }
  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] = address[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">
  159. .pickerClass{
  160. width: 80%;
  161. position: absolute;
  162. right:11px;
  163. padding:0 20px;
  164. top:50%;
  165. transform: translateY(-50%);
  166. z-index:2
  167. }
  168. </style>