select-addr.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <!-- 地址读取数据接口 -->
  2. <template>
  3. <view class="select-addr">
  4. <view class="select-wrap">
  5. <view @tap="handleTap('pickerAddr')"
  6. class="select-item full"
  7. ref="pickerAddrText">{{ defaultTtext }}</view>
  8. </view>
  9. <lb-picker
  10. ref="pickerAddr"
  11. v-model="value"
  12. mode="multiSelector"
  13. :list="areaList"
  14. :level="5"
  15. :column-num="7"
  16. emptyText="请稍后重试"
  17. @change="handleChange"
  18. @confirm="handleConfirm"
  19. @cancel="handleCancel">
  20. <view slot="action-center">上下滑动选择市县乡村</view>
  21. </lb-picker>
  22. </view>
  23. </template>
  24. <script>
  25. import LbPicker from '@/components/lb-picker'
  26. import {config} from '@/common/config.js'
  27. export default {
  28. name: 'selectAddr',
  29. components: {
  30. LbPicker
  31. },
  32. props:{
  33. defaultTtext:{
  34. type:String,
  35. default:'全部地区'
  36. }
  37. },
  38. created() {
  39. //获取地址数据
  40. if(uni.getStorageSync('addrData')){
  41. this.areaList = uni.getStorageSync('addrData');
  42. }else{
  43. // this.$api.http.get('/wap/treeOrganize/get/preToJson')
  44. this.$u.get(config.addrApi,{}).then(res => {
  45. // console.log('preToJson',res);
  46. if (res.retHead.errCode == 0) {
  47. this.areaList = res.retBody;
  48. uni.setStorageSync('addrData', res.retBody);
  49. } else {
  50. this.$api.msg(res.retHead.errMsg)
  51. }
  52. }).catch(err =>{console.log('获取地址数据',err)});
  53. }
  54. },
  55. data() {
  56. return {
  57. value: [],//指定默认值
  58. // value: ["522600000000", "522633000000", "522633107000", "522633107202"],//指定默认值
  59. areaList: [],
  60. areaProps: {
  61. label: 'orgName',
  62. value: 'parentOrgId',
  63. },
  64. pickerIndex: 0,
  65. text: "",
  66. params:{
  67. cityId:'',
  68. countyId:'',
  69. townId:'',
  70. villageId:'',
  71. textArray:[],
  72. addrLevel:null,
  73. },
  74. };
  75. },
  76. methods: {
  77. //地址选择
  78. handleTap (picker) {
  79. this.resetAddr();
  80. this.$refs[picker].show();
  81. // uni.hideTabBar();
  82. // console.log('this.$refs[picker]',this.$refs[picker]);
  83. },
  84. handleChange (item) {
  85. // console.log('change::', item)
  86. },
  87. handleConfirm (item) {
  88. let that = this;
  89. let text = '';
  90. item.item.forEach(function(item,index,array){
  91. if(item.label == "全部"){
  92. return
  93. }
  94. text+=item.label+'-'
  95. that.params.textArray.push(item.label);
  96. });
  97. if(text.charAt(text.length-1)=="-"){
  98. text = text.substr(0,text.length-1)
  99. };
  100. if(text == ''){
  101. text = this.defaultTtext;
  102. that.$refs.pickerAddrText.$el.style.color = "gray";
  103. }else{
  104. that.$refs.pickerAddrText.$el.style.color = "#333";
  105. };
  106. that.$refs.pickerAddrText.$el.innerText=text;
  107. this.params.addrLevel = this.params.textArray.length + 1;
  108. this.params.cityId = item.value[0];
  109. this.params.countyId = item.value[1];
  110. this.params.townId = item.value[2];
  111. this.params.villageId = item.value[3];
  112. // console.log('this.params::', this.params)
  113. //给父组件传值
  114. this.$emit('getAddr',this.params)
  115. // uni.showTabBar();
  116. },
  117. handleCancel (item) {
  118. // uni.showTabBar();
  119. // console.log('cancel::', item)
  120. },
  121. resetAddr(){
  122. this.params.cityId = "";
  123. this.params.countyId = "";
  124. this.params.townId = "";
  125. this.params.villageId = "";
  126. this.params.textArray=[];
  127. }
  128. }
  129. }
  130. </script>
  131. <style scoped>
  132. .select-wrap{display: flex;margin-top: 15rpx;}
  133. .select-wrap .select-item{flex: 1;font-size: 28rpx;color: gray;height: 80rpx;line-height: 80rpx;box-sizing: border-box;padding: 0 16rpx 0 16rpx;border: 1rpx solid #E5E5E5;position: relative;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;border-radius: 8px;margin-right: 7rpx;}
  134. .select-wrap .select-item:last-of-type{margin-right: 0;}
  135. .select-wrap .select-item::after{content: '';width: 0;height: 0;border-left: 5rpx solid transparent;border-right: 5rpx solid transparent;border-top: 8rpx solid #666;position: absolute;right: 10rpx;top: 50%;}
  136. .select-wrap .select-item.full::after{right: 15rpx;border-left-width: 8rpx;border-right-width: 8rpx;border-top-width: 10rpx;}
  137. .select-wrap .select-item.full{padding-right: 30rpx;}
  138. .normal .select-wrap .select-item{padding: 0;border: 0;}
  139. .normal .select-wrap .select-item::after{border: 0;}
  140. .select-addr >>> .picker-item .lb-picker-column{font-size: 30rpx;}
  141. .select-addr >>> .uni-picker-view-wrapper uni-picker-view-column:first-of-type{width: 140rpx;flex: unset;}
  142. </style>