index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <Navbar title="收货地址" fixed />
  5. <view class="content">
  6. <view class="address">
  7. <view class="address_list" v-for="item, index in addressList" :key="index">
  8. <view class="top">
  9. <view class="top_title">
  10. <view class="name">{{ item.firstName }} {{ item.lastName }}</view>
  11. <view class="phone">{{ item.phoneNo }}</view>
  12. </view>
  13. <view class="top_address">
  14. {{ item.country }}&nbsp;{{ item.province }}&nbsp;{{ item.city }}&nbsp;{{ item.address
  15. }}
  16. </view>
  17. </view>
  18. <view class="bottom">
  19. <up-radio-group v-model="radioModel" placement="column" @change="groupChange(item)"
  20. activeColor="var(--black)" inactiveColor="var(--text-01)" size="16">
  21. <up-radio :name="item.id">
  22. <template #label>
  23. <trans class="radio_text" _t="默认" />
  24. </template>
  25. </up-radio>
  26. </up-radio-group>
  27. <view class="btns">
  28. <view class="del" @click="deleteClick(item.id)">
  29. <view class="_icon">
  30. <image src="../../static/shop/del.png" class="img"></image>
  31. </view>
  32. <trans class="label" _t="删除" />
  33. </view>
  34. <view class="del" @click="editAddress(item)">
  35. <view class="_icon">
  36. <image src="../../static/shop/edit.png" class="img"></image>
  37. </view>
  38. <trans class="label" _t="编辑" />
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="btn" @click="addressOpen">
  46. <trans _t="新增收货地址" />
  47. </view>
  48. </view>
  49. <Address ref="addressRef" />
  50. <popup title="提醒" isClose ref="popRef">
  51. <template #content>
  52. <trans class="pop_cont" _t="您确认删除吗" />
  53. </template>
  54. <template #footer>
  55. <view class="footer_btn">
  56. <view class="btn" @click="() => popRef.close()">
  57. <trans _t="取消" />
  58. </view>
  59. <view class="btn submit_btn" @click="submitClick">
  60. <trans _t="确认" />
  61. </view>
  62. </view>
  63. </template>
  64. </popup>
  65. </Theme>
  66. </template>
  67. <script setup>
  68. import Navbar from '@/components/navbar';
  69. import { computed, onMounted, nextTick, ref } from 'vue'
  70. import { useShopStore } from "@/store"
  71. import Address from "@/components/address";
  72. import { SHOP_ADDRESS_ADD, SHOP_ADDRESS_DEL } from "@/api"
  73. import { Toast } from "@/utils";
  74. import popup from '@/components/popup';
  75. const useShop = useShopStore();
  76. const addressRef = ref(null);
  77. const popRef = ref(null);
  78. const radioModel = ref('');
  79. const selectId = ref('');
  80. const addressList = computed(() => {
  81. let list = useShop.getAddressList;
  82. let obj = list.find(item => item.default == 1);
  83. radioModel.value = obj && obj.id
  84. return list
  85. });
  86. const groupChange = (item) => {
  87. addressAdd({ ...item, default: item.default === 1 ? 0 : 1 })
  88. }
  89. const editAddress = (item) => {
  90. addressRef.value && addressRef.value.open(item);
  91. }
  92. const addressOpen = () => {
  93. addressRef.value && addressRef.value.open();
  94. }
  95. const addressAdd = async (params) => {
  96. try {
  97. await SHOP_ADDRESS_ADD(params);
  98. nextTick(() => {
  99. useShop.setAddressList();
  100. })
  101. } catch (error) {
  102. Toast(error.msg);
  103. }
  104. }
  105. const deleteClick = (id) => {
  106. popRef.value && popRef.value.open();
  107. selectId.value = id;
  108. }
  109. const submitClick = async () => {
  110. try {
  111. await SHOP_ADDRESS_DEL(selectId.value);
  112. popRef.value && popRef.value.close();
  113. nextTick(() => {
  114. useShop.setAddressList();
  115. })
  116. } catch (error) {
  117. popRef.value && popRef.value.close();
  118. Toast(error.msg);
  119. }
  120. }
  121. onMounted(() => {
  122. nextTick(() => {
  123. useShop.setAddressList();
  124. })
  125. })
  126. </script>
  127. <style lang="less" scoped>
  128. @import url('@/style.less');
  129. .wrap {
  130. background: var(--bg);
  131. min-height: 100vh;
  132. .content {
  133. padding: 0 28rpx;
  134. padding-bottom: 128rpx;
  135. .address {
  136. .address_list {
  137. background-color: var(--inputBg);
  138. border-radius: 10px;
  139. margin-top: 28rpx;
  140. .top {
  141. border-bottom: 1px solid #F3F3F3;
  142. padding: 24rpx 20rpx;
  143. &_title {
  144. .flex_position(space-between);
  145. .name,
  146. .phone {
  147. .size();
  148. line-height: 44rpx;
  149. color: var(--black);
  150. }
  151. }
  152. &_address {
  153. word-wrap: break-word;
  154. overflow-wrap: break-word;
  155. white-space: pre-wrap;
  156. padding-top: 16rpx;
  157. color: var(--text-02);
  158. line-height: 44rpx;
  159. .size(28rpx);
  160. }
  161. }
  162. .bottom {
  163. padding: 20rpx;
  164. .flex_position(space-between);
  165. :deep(.u-radio) {
  166. margin: 0;
  167. align-items: baseline;
  168. .u-radio__label-wrap {
  169. .flex();
  170. }
  171. }
  172. .radio_text {
  173. .size(24rpx);
  174. line-height: 24rpx;
  175. }
  176. .btns {
  177. .ver();
  178. .del {
  179. .ver(flex-start);
  180. margin-left: 24rpx;
  181. ._icon {
  182. width: 32rpx;
  183. height: 32rpx;
  184. .img {
  185. width: inherit;
  186. height: inherit;
  187. }
  188. }
  189. .label {
  190. color: var(--text-02);
  191. .size(20rpx);
  192. line-height: 44rpx;
  193. margin-left: 6rpx;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. .btn {
  202. height: 100rpx;
  203. position: fixed;
  204. left: 28rpx;
  205. right: 28rpx;
  206. bottom: 28rpx;
  207. background-color: var(--black);
  208. padding: 28rpx;
  209. .size();
  210. color: var(--light);
  211. font-weight: bold;
  212. text-align: center;
  213. border-radius: 20rpx;
  214. }
  215. }
  216. .pop_cont {
  217. color: var(--text-01);
  218. .size(28rpx);
  219. line-height: 60rpx;
  220. }
  221. .footer_btn {
  222. .ver();
  223. column-gap: 24rpx;
  224. .btn {
  225. flex: 1;
  226. height: 38px;
  227. padding: 16rpx 30rpx;
  228. border: 1px solid var(--black);
  229. border-radius: 16rpx;
  230. .size(24rpx);
  231. color: var(--black);
  232. text-align: center;
  233. }
  234. .submit_btn {
  235. background-color: var(--black);
  236. color: var(--light);
  237. }
  238. }
  239. </style>