addressList.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="container">
  3. <uv-navbar title="收货地址" placeholder autoBack></uv-navbar>
  4. <view class="list">
  5. <radio-group>
  6. <view class="item u-bg-fff" v-for="item in addressList" :key="item.id">
  7. <view class="u-border-one-one userInfo" @click="backSurePay(item.id)">
  8. <view
  9. >收货人:<text class="u-999">{{ item.receiverName }}</text>
  10. <text class="u-ml80">{{ item.receiverPhone }}</text>
  11. </view>
  12. <view class="u-mt5 u-text2"
  13. >收货地址:<text class="u-999"
  14. >{{ item.provinceName }}{{ item.cityName }}{{ item.areaName
  15. }}{{ item.detailAddress }}</text
  16. >
  17. </view>
  18. </view>
  19. <view class="operation u-flex-center-sb u-font24 u-999">
  20. <view class="u-flex-center" @click="isDefault(item.id)">
  21. <view class="kuang">
  22. <uv-icon
  23. v-if="item.defaultStatus"
  24. name="checkmark-circle-fill"
  25. color="#e93534"
  26. size="34rpx"
  27. ></uv-icon>
  28. <uv-icon
  29. v-else
  30. name="checkmark-circle"
  31. size="34rpx"
  32. ></uv-icon>
  33. <text class="" style="margin-left: 10rpx;">{{
  34. item.defaultStatus ? "默认地址" : "设为默认"
  35. }}</text>
  36. </view>
  37. </view>
  38. <view class="u-flex-center">
  39. <view class="u-mr45" @click="edit(item.id)">编辑</view>
  40. <view @click="del(item.id)">删除</view>
  41. </view>
  42. </view>
  43. </view>
  44. </radio-group>
  45. </view>
  46. <!-- 没有数据 -->
  47. <view
  48. class="nogoods u-mt30 u-flex-column-center"
  49. v-if="addressList.length == 0"
  50. >
  51. <noData :config="{ top: 5, content: '您还没有添加地址~' }"></noData>
  52. </view>
  53. <view class="add-btn" @click="goAddEditAddress">
  54. <view class="u-plr30">
  55. <button class="u-btn-two u-FFF">添加新地址</button>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import { ref } from "vue";
  62. import { onLoad, onShow } from "@dcloudio/uni-app";
  63. import {
  64. useraddressList_Api,
  65. useraddressDel_Api,
  66. useraddressSetDefaultStatus_Api,
  67. } from "@/api/userInfo.js";
  68. const formType = ref(null);
  69. const addressList = ref([]);
  70. // 获取地址列表
  71. const getAddressList = async () => {
  72. useraddressList_Api().then(async (res) => {
  73. // console.log("res", res);
  74. if (res.code == 200) {
  75. addressList.value = res.data;
  76. }
  77. });
  78. };
  79. // 跳转确认下单
  80. const backSurePay = (id) => {
  81. if (formType.value == "mine") return false;
  82. uni.showModal({
  83. title: "提示",
  84. content: "确认使用该地址收货吗?",
  85. success: function (res) {
  86. if (res.confirm) {
  87. // uni.setStorageSync('address',item)
  88. let object = {
  89. addressid: id,
  90. };
  91. var pages = getCurrentPages();
  92. var prevPage = pages[pages.length - 2];
  93. if (prevPage.$vm.otherFun) {
  94. prevPage.$vm.otherFun(object);
  95. }
  96. uni.navigateBack({
  97. delta: 1,
  98. });
  99. // uni.navigateTo({
  100. // url:'/pages/product/surePay/surePay?addressid='+id
  101. // })
  102. console.log("用户点击确定");
  103. } else if (res.cancel) {
  104. console.log("用户点击取消");
  105. }
  106. },
  107. });
  108. };
  109. // 跳转添加编辑地址
  110. const goAddEditAddress = () => {
  111. uni.navigateTo({
  112. url: "addEditAddress",
  113. });
  114. };
  115. // 设为默认
  116. const isDefault = (id) => {
  117. uni.showModal({
  118. title: "提示",
  119. content: "确认更换默认收货地址吗?",
  120. success: (result) => {
  121. if (result.confirm) {
  122. uni.showLoading({
  123. title: "加载中",
  124. mask: true,
  125. });
  126. useraddressSetDefaultStatus_Api(id)
  127. .then(async (res) => {
  128. uni.hideLoading();
  129. if (res && res.code == 200) {
  130. uni.showToast({
  131. title: "修改成功",
  132. icon: "none",
  133. duration: 3000,
  134. success() {
  135. addressList.value = [];
  136. getAddressList();
  137. },
  138. });
  139. }
  140. })
  141. .catch((err) => {
  142. // uni.hideLoading();
  143. });
  144. console.log("用户点击确定");
  145. } else if (result.cancel) {
  146. console.log("用户点击取消");
  147. }
  148. },
  149. });
  150. };
  151. // 编辑
  152. const edit = (id) => {
  153. uni.navigateTo({
  154. url: "addEditAddress?id=" + id,
  155. });
  156. };
  157. // 删除
  158. const del = async (id) => {
  159. uni.showModal({
  160. title: "温馨提示",
  161. content: "是否删除这条地址",
  162. success: (res) => {
  163. if (res.confirm) {
  164. uni.showLoading({
  165. title: "加载中",
  166. mask: true,
  167. });
  168. useraddressDel_Api(id)
  169. .then(async (res) => {
  170. uni.hideLoading();
  171. if (res.code == 200) {
  172. uni.showToast({
  173. title: "删除成功",
  174. icon: "none",
  175. duration: 3000,
  176. success() {
  177. getAddressList();
  178. },
  179. });
  180. }
  181. })
  182. .catch((err) => {
  183. // uni.hideLoading();
  184. });
  185. }
  186. },
  187. });
  188. };
  189. onLoad((options) => {
  190. if (options.formType) {
  191. formType.value = options.formType;
  192. }
  193. });
  194. onShow(() => {
  195. addressList.value = [];
  196. getAddressList();
  197. });
  198. </script>
  199. <style lang="scss" scoped>
  200. page {
  201. background-color: #f5f5f5;
  202. }
  203. .kuang {
  204. display: flex;
  205. align-items: center;
  206. }
  207. .container {
  208. padding-bottom: 160rpx;
  209. }
  210. .list {
  211. // margin-bottom: 160rpx;
  212. }
  213. .item {
  214. margin-top: 30rpx;
  215. padding: 46rpx 30rpx;
  216. .userInfo {
  217. padding-bottom: 36rpx;
  218. }
  219. .operation {
  220. border-top: 2rpx solid #f5f5f5;
  221. padding-top: 42rpx;
  222. }
  223. }
  224. .add-btn {
  225. width: 100%;
  226. position: fixed;
  227. bottom: 45rpx;
  228. button {
  229. width: 100%;
  230. }
  231. }
  232. </style>