company.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <!-- 选择公司 -->
  3. <view>
  4. <u-navbar title="选择公司" autoBack placeholder></u-navbar>
  5. <view class="card_company" v-if="treeList.length > 0">
  6. <view class="hint_title">请选择燃气公司</view>
  7. <firm-tree v-for="item in treeList" :key="item.id" :item="item" @confirm="confirm"></firm-tree>
  8. </view>
  9. <view style="margin-top: 30%;" v-else>
  10. <u-empty mode="list" text="该区/县暂无商家入驻"></u-empty>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import firmTree from '@/components/firmTree.vue';
  16. import {
  17. urbanArea
  18. } from '@/static/js/districtCode.js'
  19. export default {
  20. components: {
  21. firmTree
  22. },
  23. data() {
  24. return {
  25. src: 'https://cdn.uviewui.com/uview/album/1.jpg',
  26. treeList: [],
  27. areaData: urbanArea(), //原始数据
  28. }
  29. },
  30. mounted() {
  31. this.getList()
  32. },
  33. methods: {
  34. getList() {
  35. var city1 = this.$cache.getCache('city')
  36. var district2 = this.$cache.getCache('district')
  37. let params = {
  38. city: '',
  39. district: ''
  40. }
  41. if (city1) {
  42. params.city = this.cityScreening(city1, this.areaData)
  43. } else if (district2) {
  44. params.district = this.cityScreening(district2, this.areaData)
  45. }
  46. this.$api.get('/api/applet/store', params).then(res => {
  47. if (res.code == 200) {
  48. if (res.data) {
  49. this.treeList = res.data
  50. }
  51. }
  52. })
  53. },
  54. // 城市筛选
  55. cityScreening(value, list) {
  56. function getChildById(parentArray, id) {
  57. for (let i = 0; i < parentArray.length; i++) {
  58. if (parentArray[i].label === id) { // 如果当前元素的ID与目标ID相等,则返回该元素
  59. return parentArray[i];
  60. } else if (parentArray[i].children && Array.isArray(parentArray[i]
  61. .children)) { // 判断当前元素是否有子节点且类型为数组
  62. const result = getChildById(parentArray[i].children, id); // 对子节点进行递归调用
  63. if (result !== null) { // 若子节点存在结果,则返回该结果
  64. return result;
  65. }
  66. }
  67. }
  68. return null; // 没有找到符合条件的元素时返回null
  69. }
  70. var name = getChildById(list, value)
  71. if (name != null) {
  72. return name.value
  73. }
  74. },
  75. // 选择门店\去订气
  76. confirm(cmpCode) {
  77. this.$cache.setCache('orderList', {})
  78. uni.navigateTo({
  79. url: '/pages/order/booking?companyId=' + cmpCode
  80. });
  81. },
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. .card_company {
  87. display: flex;
  88. flex-direction: column,
  89. }
  90. .hint_title {
  91. padding-left: 30rpx;
  92. margin-top: 20rpx;
  93. padding-bottom: 20rpx;
  94. border-bottom: 2rpx solid transparent;
  95. border-image: linear-gradient(to bottom, transparent 50%, #e7e6e4 50%) 0 0 100% 0;
  96. font-size: 32rpx;
  97. font-weight: 600;
  98. color: #000;
  99. }
  100. </style>