address-card.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="address-card" :class="{ 'address-card--selected': selected }">
  3. <!-- 选中状态的勾 -->
  4. <view class="selected-icon no-select-icon" v-if="isSelect == 1" @tap="handleClick">
  5. <u-icon name="checkmark" color="#FFFFFF" size="24"></u-icon>
  6. </view>
  7. <view class="selected-icon" v-if="selected" @tap="handleClick">
  8. <u-icon name="checkmark" color="#FFFFFF" size="24"></u-icon>
  9. </view>
  10. <!-- 主要内容区 -->
  11. <view class="content flex-a" @click="handleClick">
  12. <image src="/pages-mine/static/adderss.png" style="width: 40rpx; height: 40rpx"></image>
  13. <view class="flex-1 mr-40 ml-24 flex-d">
  14. <view class="header flex-a flex-1 mb-24">
  15. <view class="name-phone">
  16. <text class="common-text-2">{{ address.name }}</text>
  17. <text class="common-text-2 ml-20">{{ address.mobile }}</text>
  18. </view>
  19. <view class="status ml-40" v-if="address.defaultFlag == 1">默认</view>
  20. </view>
  21. <view class="common-text-2">{{ address.fullAddress }}</view>
  22. </view>
  23. <!-- 右侧箭头 -->
  24. <view class="arrow-container" @tap.stop="updateAddress">
  25. <u-icon name="arrow-right" size="32" color="#999"></u-icon>
  26. </view>
  27. </view>
  28. <!-- 底部操作区 -->
  29. <view class="footer flex-a flex-j-b">
  30. <view class="common-text-2">
  31. <u-checkbox v-model="isDefault" @change="onDefaultChange" shape="circle" active-color="#38C148"
  32. >默认地址</u-checkbox
  33. >
  34. </view>
  35. <view class="common-text-2" @click.stop="onDelete">删除</view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. name: "address-item",
  42. props: {
  43. address: {
  44. type: Object,
  45. default: () => ({}),
  46. },
  47. selected: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. isSelect: {
  52. type: [Boolean, Number, String],
  53. default: false,
  54. },
  55. },
  56. data() {
  57. return {
  58. isDefault: false,
  59. };
  60. },
  61. watch: {
  62. address: {
  63. handler(value) {
  64. this.isDefault = value.defaultFlag == 1;
  65. },
  66. deep: true,
  67. immediate: true,
  68. },
  69. },
  70. methods: {
  71. handleClick() {
  72. this.$emit("tapItem", this.address);
  73. },
  74. //更新地址
  75. updateAddress(event) {
  76. // 微信小程序中阻止事件冒泡
  77. if (event) {
  78. event.stopPropagation();
  79. event.preventDefault();
  80. // 微信小程序特有的事件阻止方法
  81. if (event.detail && event.detail.stopPropagation) {
  82. event.detail.stopPropagation();
  83. }
  84. }
  85. uni.navigateTo({
  86. url: "/pages-mine/pages/address/add-or-update?id=" + this.address.id,
  87. });
  88. return
  89. if (!this.isSelect) {
  90. uni.navigateTo({
  91. url: "/pages-mine/pages/address/add-or-update?id=" + this.address.id,
  92. });
  93. } else {
  94. this.$emit("tapItem", this.address);
  95. }
  96. },
  97. onDefaultChange(value) {
  98. if (this.address.defaultFlag == 1) return (this.isDefault = true);
  99. let id = this.address.id;
  100. uni.$u.http.post(`/token/user/address/setDefault/${id}`).then((res) => {
  101. if (res.code == 200) {
  102. uni.showToast({
  103. icon: "none",
  104. title: "设置默认地址成功",
  105. });
  106. this.$emit("success");
  107. } else {
  108. uni.showToast({
  109. icon: "none",
  110. title: res.msg,
  111. });
  112. this.isDefault = false;
  113. }
  114. });
  115. },
  116. onDelete() {
  117. this.$emit("delete", this.address.id);
  118. },
  119. },
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. .address-card {
  124. position: relative;
  125. background-color: #ffffff;
  126. padding: 20rpx 30rpx;
  127. margin-bottom: 20rpx;
  128. border-radius: 12rpx;
  129. border: 2rpx solid transparent;
  130. transition: all 0.3s;
  131. margin-bottom: 20rpx;
  132. // 选中状态样式
  133. &--selected {
  134. border-color: #38c148;
  135. background-color: rgba(56, 193, 72, 0.05);
  136. }
  137. // 选中状态的勾
  138. .selected-icon {
  139. position: absolute;
  140. right: -2rpx;
  141. top: -2rpx;
  142. width: 40rpx;
  143. height: 40rpx;
  144. background-color: #38c148;
  145. display: flex;
  146. align-items: center;
  147. justify-content: center;
  148. border-bottom-left-radius: 12rpx;
  149. border-top-right-radius: 12rpx;
  150. &.no-select-icon {
  151. background-color: #d8d8d8;
  152. }
  153. }
  154. .status {
  155. font-size: 24rpx;
  156. color: #38c148;
  157. padding: 4rpx 12rpx;
  158. border: 1px solid #38c148;
  159. border-radius: 6rpx;
  160. }
  161. .footer {
  162. margin-top: 20rpx;
  163. padding-top: 20rpx;
  164. border-top: 1rpx solid #eeeeee;
  165. }
  166. .arrow-container {
  167. display: flex;
  168. align-items: center;
  169. justify-content: center;
  170. padding: 10rpx;
  171. // 确保点击区域足够大,避免误触
  172. min-width: 60rpx;
  173. min-height: 60rpx;
  174. }
  175. }
  176. </style>