address.vue 3.2 KB

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