address.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view>
  3. <u-navbar title="地址管理" rightText="新增地址" autoBack placeholder @rightClick="rightClick"></u-navbar>
  4. <view v-if="list.length > 0">
  5. <view class="card_address" v-for="(item,index) in list" :key="index">
  6. <view class="center_item">
  7. <view class="title_item">{{item.name}}</view>
  8. <view class="phone_title">
  9. <view class="title_item">{{hidePhone(item.phone)}}</view>
  10. <view class="tag_phone" v-if="item.isDefault">默认</view>
  11. </view>
  12. </view>
  13. <view class="center_item address_item">
  14. <view class="title_address">
  15. {{cityScreening(item.city, areaData)}}{{cityScreening(item.area, areaData)}}{{item.address}}
  16. </view>
  17. <view @click="goAmend(item)"><u-icon name="edit-pen" size="30"></u-icon></view>
  18. </view>
  19. </view>
  20. </view>
  21. <view style="margin-top: 30%;" v-else>
  22. <u-empty mode="address"></u-empty>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. urbanArea
  29. } from '@/static/js/districtCode.js'
  30. export default {
  31. data() {
  32. return {
  33. areaData: urbanArea(), //原始数据
  34. list: []
  35. }
  36. },
  37. onShow() {
  38. console.log(23)
  39. this.getList()
  40. },
  41. mounted() {
  42. // this.getList()
  43. },
  44. methods: {
  45. getList() {
  46. this.$api.get('/api/applet/address').then(res => {
  47. if (res.code == 200) {
  48. this.list = res.data.list
  49. }
  50. })
  51. },
  52. // 城市筛选
  53. cityScreening(value, list) {
  54. function getChildById(parentArray, id) {
  55. for (let i = 0; i < parentArray.length; i++) {
  56. if (parentArray[i].value === id) { // 如果当前元素的ID与目标ID相等,则返回该元素
  57. return parentArray[i];
  58. } else if (parentArray[i].children && Array.isArray(parentArray[i]
  59. .children)) { // 判断当前元素是否有子节点且类型为数组
  60. const result = getChildById(parentArray[i].children, id); // 对子节点进行递归调用
  61. if (result !== null) { // 若子节点存在结果,则返回该结果
  62. return result;
  63. }
  64. }
  65. }
  66. return null; // 没有找到符合条件的元素时返回null
  67. }
  68. var name = getChildById(list, value)
  69. if (name != null) {
  70. return name.label
  71. }
  72. },
  73. hidePhone(phoneNumber) {
  74. function hidePhoneNumber(phoneNumber) {
  75. return phoneNumber.slice(0, 3) + '****' + phoneNumber.slice(-4);
  76. }
  77. const hiddenPhoneNumber = hidePhoneNumber(phoneNumber);
  78. return hiddenPhoneNumber
  79. },
  80. // 新增地址
  81. rightClick() {
  82. uni.navigateTo({
  83. url: '/pages/mine/addAddress'
  84. });
  85. },
  86. // 修改地址
  87. goAmend(value) {
  88. this.$cache.setCache('addressInfo', value)
  89. uni.navigateTo({
  90. url: '/pages/mine/addAddress?revamp=' + true + '&id=' + value.id
  91. });
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .card_address {
  98. margin: 30rpx 20rpx 20rpx 20rpx;
  99. padding: 10rpx;
  100. border-bottom: 2rpx solid #e7e6e4;
  101. // border-image: linear-gradient(to bottom, transparent 50%, #e7e6e4 50%) 0 0 100% 0;
  102. }
  103. .center_item {
  104. display: flex;
  105. align-items: center;
  106. }
  107. .title_item {
  108. font-size: 26rpx;
  109. color: #606266;
  110. }
  111. .phone_title {
  112. position: relative;
  113. margin-left: 30rpx;
  114. }
  115. .tag_phone {
  116. position: absolute;
  117. right: -53rpx;
  118. top: -14rpx;
  119. padding: 2rpx 4rpx;
  120. border: 1rpx solid #2b85e4;
  121. font-size: 20rpx;
  122. color: #2b85e4;
  123. }
  124. .title_address {
  125. font-size: 30rpx;
  126. color: #303133;
  127. font-weight: 600;
  128. }
  129. .address_item {
  130. display: flex;
  131. justify-content: space-between;
  132. margin-top: 6rpx;
  133. }
  134. </style>