addressModel.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view>
  3. <view class="address">
  4. <view
  5. class="address_item"
  6. :class="addressList.length ? '' : 'flex'"
  7. @click="addressClick"
  8. >
  9. <template v-if="addressList.length">
  10. <view class="_item">
  11. <view class="_item_top">
  12. <view class="_top_left">
  13. <view class="name"
  14. >{{ selectItem.firstName }}&nbsp;{{
  15. selectItem.lastName
  16. }}</view
  17. >
  18. <view class="phone">{{ selectItem.phoneNo }}</view>
  19. <view class="code">{{ selectItem.zipCode }}</view>
  20. </view>
  21. <i class="icon-font icon-left"></i>
  22. </view>
  23. <view class="_item_middle">
  24. {{ selectItem.country }}&nbsp;{{ selectItem.province }},{{
  25. selectItem.city
  26. }},{{ selectItem.address }}
  27. </view>
  28. <view class="_item_bottom">
  29. <view class="default_btn" v-if="selectItem.default == 1">
  30. <trans _t="默认" />
  31. </view>
  32. <view class="label_btn" v-if="selectItem.label">{{
  33. selectItem.label
  34. }}</view>
  35. </view>
  36. </view>
  37. </template>
  38. <template v-else>
  39. <view class="address_empty">
  40. <trans _t="请选择地址" />
  41. <up-icon name="arrow-right"></up-icon>
  42. </view>
  43. </template>
  44. </view>
  45. </view>
  46. <popup title="请选择地址" isClose ref="popRef">
  47. <template #content>
  48. <view class="pop_cont">
  49. <view
  50. class="cont_list"
  51. v-for="(item, index) in addressList"
  52. :key="index"
  53. @click="listClick(item)"
  54. >
  55. <view class="_list_item">
  56. <view class="_item_top">
  57. <view class="_top_left">
  58. <view class="name"
  59. >{{ item.firstName }}&nbsp;{{ item.lastName }}</view
  60. >
  61. <view class="phone">{{ item.phoneNo }}</view>
  62. </view>
  63. </view>
  64. <view class="_item_middle">
  65. {{ item.country }}&nbsp;{{ item.province }},{{ item.city }},{{
  66. item.address
  67. }}
  68. </view>
  69. <view class="_item_bottom">
  70. <view class="default_btn" v-if="item.default == 1">
  71. <trans _t="默认" />
  72. </view>
  73. <view class="label_btn" v-if="item.label">{{
  74. item.label
  75. }}</view>
  76. </view>
  77. </view>
  78. <view @click.stop="editAddress(item)">
  79. <i class="icon-font icon-edit"></i>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <template #footer>
  85. <view class="footer_btn" @click="addressOpen">
  86. <trans _t="添加送货地址" />
  87. </view>
  88. </template>
  89. </popup>
  90. <Address ref="addressRef" />
  91. </view>
  92. </template>
  93. <script setup>
  94. import { computed, ref, reactive, nextTick } from "vue";
  95. import Popup from "@/components/popup.vue";
  96. import { t } from "@/locale";
  97. import { useShopStore } from "@/store";
  98. import Address from "@/components/address";
  99. import { onShow } from "@dcloudio/uni-app";
  100. const emit = defineEmits(["confirm", "open", "close"]);
  101. const popRef = ref(null);
  102. const addressRef = ref(null);
  103. const useShop = useShopStore();
  104. const ids = ref([]);
  105. const addressList = computed(() => {
  106. const list = useShop.getAddressList;
  107. const items = list.length && (list.find((item) => item.default == 1) || {});
  108. let obj = list.length && (JSON.stringify(items) === "{}" ? list[0] : items);
  109. ids.value = [obj.id || ""];
  110. return list;
  111. });
  112. const selectItem = computed(() => {
  113. let item = {};
  114. if (addressList.value.length) {
  115. item = addressList.value.find((item) => item.id == ids.value[0]) || {};
  116. getCheck(item);
  117. return item;
  118. }
  119. return item;
  120. });
  121. const getCheck = (item) => {
  122. emit("confirm", item || selectItem.value);
  123. };
  124. const form = reactive({
  125. id: "",
  126. express_name: "",
  127. express_no: "",
  128. });
  129. const open = () => {
  130. emit("open");
  131. popRef.value && popRef.value.open();
  132. };
  133. const close = () => {
  134. emit("close");
  135. popRef.value && popRef.value.close();
  136. };
  137. const addressClick = () => {
  138. popRef.value && popRef.value.open();
  139. };
  140. const listClick = (item) => {
  141. ids.value = [item.id];
  142. nextTick(() => {
  143. getCheck();
  144. popRef.value && popRef.value.close();
  145. });
  146. };
  147. const editAddress = (item) => {
  148. popRef.value && popRef.value.close();
  149. addressRef.value && addressRef.value.open(item);
  150. };
  151. const addressOpen = () => {
  152. popRef.value && popRef.value.close();
  153. addressRef.value && addressRef.value.open();
  154. };
  155. onShow(() => {
  156. nextTick(() => {
  157. useShop.setAddressList();
  158. });
  159. });
  160. defineExpose({ open, close });
  161. </script>
  162. <style lang="less" scoped>
  163. @import url("@/style.less");
  164. .address {
  165. margin-top: 24rpx;
  166. background: url("@/static/address_bg.png") no-repeat 50%;
  167. background-size: cover;
  168. padding: 2px;
  169. border-radius: 16rpx;
  170. &_item {
  171. padding: 24rpx 20rpx;
  172. background-color: var(--light);
  173. border-radius: 16rpx;
  174. min-height: 160rpx;
  175. .address_empty {
  176. height: inherit;
  177. flex: 1;
  178. .flex_position(space-between);
  179. color: var(--text-01);
  180. line-height: 60rpx;
  181. .size(28rpx);
  182. .icon-left {
  183. .size(36rpx);
  184. transform: rotate(180deg);
  185. }
  186. }
  187. ._item {
  188. overflow: hidden;
  189. &_top {
  190. .flex_position(space-between);
  191. padding-right: 30rpx;
  192. line-height: 60rpx;
  193. ._top_left {
  194. .ver();
  195. .name {
  196. .size(36rpx);
  197. font-weight: 700;
  198. color: var(--text);
  199. }
  200. .phone,
  201. .code {
  202. color: var(--text-01);
  203. margin-left: 30rpx;
  204. .size(28rpx);
  205. font-weight: 700;
  206. }
  207. }
  208. .icon-left {
  209. color: var(--text-01);
  210. transform: rotate(180deg);
  211. .size();
  212. }
  213. }
  214. &_middle {
  215. text-wrap: wrap;
  216. white-space: pre-wrap;
  217. word-wrap: break-word;
  218. .size(28rpx);
  219. color: var(--text-01);
  220. margin-top: 8rpx;
  221. line-height: 48rpx;
  222. margin-bottom: 12rpx;
  223. }
  224. &_bottom {
  225. .flex();
  226. flex-wrap: wrap;
  227. gap: 24rpx;
  228. .default_btn,
  229. .label_btn {
  230. padding: 8rpx 16rpx;
  231. .size(24rpx);
  232. border-radius: 8rpx;
  233. }
  234. .default_btn {
  235. color: var(--danger);
  236. background-color: #e62e2e1a;
  237. }
  238. .label_btn {
  239. background-color: #ff66331a;
  240. color: var(--primary);
  241. }
  242. }
  243. }
  244. }
  245. }
  246. .pop_cont {
  247. .cont_list {
  248. .ver();
  249. ._list_item {
  250. flex: 1;
  251. margin-left: 12rpx;
  252. ._item_top {
  253. line-height: 48rpx;
  254. ._top_left {
  255. .ver();
  256. color: var(--text);
  257. .name,
  258. .phone {
  259. .size(28rpx);
  260. font-weight: 700;
  261. }
  262. .phone {
  263. margin-left: 16rpx;
  264. }
  265. }
  266. }
  267. ._item_middle {
  268. color: var(--text-02);
  269. .size(24rpx);
  270. line-height: 40rpx;
  271. text-wrap: wrap;
  272. white-space: pre-wrap;
  273. word-wrap: break-word;
  274. margin-bottom: 12rpx;
  275. word-break: break-all;
  276. }
  277. ._item_bottom {
  278. .flex();
  279. flex-wrap: wrap;
  280. gap: 24rpx;
  281. .default_btn,
  282. .label_btn {
  283. padding: 8rpx 16rpx;
  284. .size(24rpx);
  285. border-radius: 8rpx;
  286. }
  287. .default_btn {
  288. color: var(--danger);
  289. background-color: #e62e2e1a;
  290. }
  291. .label_btn {
  292. background-color: #ff66331a;
  293. color: var(--primary);
  294. }
  295. }
  296. }
  297. .icon-edit {
  298. .size(36rpx);
  299. color: var(--primary);
  300. }
  301. }
  302. }
  303. .footer_btn {
  304. height: 38px;
  305. padding: 16rpx 30rpx;
  306. background-color: var(--black);
  307. color: var(--light);
  308. .flex_center();
  309. border-radius: 16rpx;
  310. .size(24rpx);
  311. }
  312. </style>