AddressItem.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="address-item" @click="toSaveAddress">
  3. <view class="address-item-top display-flex-center">
  4. <!-- <image :src="`${$getImgBaseUrl()}icon-address.png`" mode="aspectFill"
  5. style="width: 64rpx;height: 64rpx;flex-shrink: 0;margin-right: 24rpx;"></image> -->
  6. <view class="top-info">
  7. <view class="title color-23 display-flex-center">
  8. <u-icon name="account-fill" color="#CACACA" size="15"></u-icon>
  9. <text class="fs15 fw600 ml5">{{itemData.name}}</text>
  10. </view>
  11. <view class="display-flex-center color-23 mt10 mb10">
  12. <u-icon name="phone-fill" color="#CACACA" size="15"></u-icon>
  13. <text class="ml5">{{itemData.phone}}</text>
  14. </view>
  15. <view class="fs12 color-5f display-flex">
  16. <u-icon name="map-fill" color="#CACACA" size="15"></u-icon>
  17. <text class="ml5">{{addressDisplay}}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="address-item-bottom display-flex-between">
  22. <u-switch @click.stop="" @change="statusChange" :loading="loading" :activeValue="1" :inactiveValue="0"
  23. v-model="itemData.type" size="20" active-color="#F39800" inactive-color="#DCDCDC"></u-switch>
  24. <view class="operate-item display-flex-center">
  25. <view @click.stop="toEdit">
  26. <u1-icon name="edit-pen"></u1-icon>
  27. <text>编辑</text>
  28. </view>
  29. <view class="color-del ml28" @click.stop="deleteItem">
  30. <u1-icon name="trash" color="#FF4E4A"></u1-icon>
  31. <text>删除</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 删除确认 -->
  36. <u-modal :show="show" showCancelButton @cancel="show= false" @close="show=false" @confirm="confirm"
  37. :asyncClose="true" title="删除" content='确认删除吗'></u-modal>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. name: "AddressItem",
  43. props: {
  44. itemData: {
  45. type: Object,
  46. default: () => {
  47. return {}
  48. }
  49. },
  50. isBack: {
  51. type: Boolean,
  52. default: false
  53. },
  54. },
  55. data() {
  56. return {
  57. loading: false,
  58. show: false,
  59. };
  60. },
  61. watch: {
  62. 'itemData.type'(nv, ov) {
  63. console.log(8999, nv, ov)
  64. }
  65. },
  66. computed: {
  67. addressDisplay() {
  68. const {
  69. province,
  70. city,
  71. area,
  72. address
  73. } = this.itemData
  74. return province + city + area + address || ''
  75. }
  76. },
  77. methods: {
  78. statusChange(data) {
  79. console.log(8999, data)
  80. this.loading = true
  81. const {
  82. code
  83. } = this.itemData
  84. this.$api.updateAddress(this.itemData).then(res => {
  85. this.loading = false
  86. this.$emit('refresh')
  87. // if (res.code != 1) {
  88. // this.itemData.type = nv || 0
  89. // }
  90. }).catch(() => {
  91. // this.loading = false
  92. // this.itemData.type = nv || 0
  93. })
  94. },
  95. toSaveAddress() {
  96. console.log(1222, this.isBack)
  97. if (!this.isBack) {
  98. // this.toEdit()
  99. return
  100. }
  101. uni.setStorageSync('selectAddress', JSON.stringify(this.itemData))
  102. uni.navigateBack()
  103. },
  104. toEdit() {
  105. uni.navigateTo({
  106. url: '/subPages/addAddress/addAddress?code=' + this.itemData.code
  107. })
  108. },
  109. deleteItem() {
  110. this.show = true
  111. },
  112. confirm() {
  113. uni.showLoading();
  114. this.$api.deleteAddress({
  115. code: this.itemData.code
  116. }).then(res => {
  117. uni.hideLoading()
  118. this.show = false
  119. if (res.code === 200) {
  120. this.$emit('refresh')
  121. uni.showToast({
  122. title: '删除成功'
  123. })
  124. } else {
  125. uni.showToast({
  126. title: '删除失败'
  127. })
  128. }
  129. }).catch(() => {
  130. uni.hideLoading()
  131. })
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .address-item {
  138. background: #FFFFFF;
  139. border-radius: 15rpx 15rpx 15rpx 15rpx;
  140. padding: 15rpx 0 24rpx;
  141. margin-bottom: 20rpx;
  142. &-top {
  143. padding: 0 24rpx 24rpx;
  144. border-bottom: 2rpx solid #F4F4F4;
  145. margin-bottom: 24rpx;
  146. }
  147. &-bottom {
  148. padding: 0 34rpx;
  149. }
  150. }
  151. </style>