selectAddress.vue 4.1 KB

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