index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-ALIPAY -->
  4. <u-navbar title="我的地址" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" leftIconSize="0" />
  5. <!-- #endif -->
  6. <!-- #ifndef MP-ALIPAY -->
  7. <u-navbar title="我的地址" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  8. <!-- #endif -->
  9. <view class="addres-list">
  10. <view class="address-item" v-for="(item, index) in list" :key="index">
  11. <view class="contacts">
  12. <text class="name">{{ item.receiver }}</text>
  13. <text class="phone">{{ item.mobile }}</text>
  14. </view>
  15. <view class="address">
  16. <text class="region">{{ `${ item.province }-${ item.city }-${ item.area }` }}</text>
  17. <text class="detail">{{ item.addr }}</text>
  18. </view>
  19. <view class="line"></view>
  20. <view class="item-option">
  21. <view class="_left" @click.stop="handleSetDefault(item.addrId)">
  22. <label class="item-radio">
  23. <view :class="item.addrId == defaultId? 'radioon' : 'radiooff' ">√</view>
  24. <text class="text">{{ item.addrId == defaultId ? '默认' : '选择' }}</text>
  25. </label>
  26. </view>
  27. <view class="_right">
  28. <view class="events">
  29. <view class="event-item" @click="handleUpdate(item.addrId)">
  30. <text class="iconfont icon-edit"></text>
  31. <text class="title">编辑</text>
  32. </view>
  33. <view class="event-item" @click="handleRemove(item.addrId)">
  34. <text class="iconfont icon-delete"></text>
  35. <text class="title">删除</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="flex empty" v-if="!list.length">
  43. <view class="center">
  44. <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_5.png" mode="scaleToFill"></image>
  45. <view class="center-font">暂无收货地址</view>
  46. </view>
  47. </view>
  48. <!-- 底部操作按钮 -->
  49. <view class="footer-fixed">
  50. <view class="btn-wrapper">
  51. <button type="default" @click="handleCreate">添加地址</button>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import $http from '@/utils/request.js'
  58. export default {
  59. data() {
  60. return {
  61. //当前页面参数
  62. options: {},
  63. // 正在加载
  64. isLoading: true,
  65. // 收货地址列表
  66. list: [],
  67. // 默认收货地址
  68. defaultId: null
  69. }
  70. },
  71. onLoad(options) {
  72. // 当前页面参数
  73. this.options = options
  74. },
  75. onShow() {
  76. // 获取页面数据
  77. this.getPageData()
  78. },
  79. methods: {
  80. // 获取页面数据
  81. getPageData() {
  82. uni.showLoading({
  83. title: '加载中'
  84. });
  85. const app = this
  86. app.isLoading = true
  87. Promise.all([app.getDefaultId(), app.getAddressList()])
  88. .then(() => {
  89. uni.hideLoading();
  90. // 列表排序把默认收货地址放到最前
  91. // app.onReorder()
  92. }).catch(() => {
  93. uni.hideLoading();
  94. })
  95. },
  96. // 获取收货地址列表
  97. getAddressList() {
  98. $http.post('/api/v1/mp/user/addr/list', {}).then(res => {
  99. if (res.code == 0) {
  100. this.list = res.data
  101. }
  102. })
  103. },
  104. // 获取默认的收货地址
  105. getDefaultId() {
  106. $http.post('/api/v1/mp/user/addr/queryDefault', {}).then(res => {
  107. if (res.code == 0) {
  108. this.defaultId = res && res.data && res.data.addrId
  109. }
  110. })
  111. },
  112. // 列表排序把默认收货地址放到最前
  113. onReorder() {
  114. const app = this
  115. app.list.sort(item => {
  116. return item.addrId == app.defaultId ? -1 : 1
  117. })
  118. },
  119. // 添加地址
  120. handleCreate() {
  121. uni.navigateTo({
  122. url: "/packageOperate/address/create"
  123. })
  124. },
  125. // 编辑地址
  126. handleUpdate(addressId) {
  127. uni.navigateTo({
  128. url: `/packageOperate/address/create?addrId=${ addressId }`
  129. })
  130. },
  131. // 删除地址
  132. handleRemove(addressId) {
  133. const _this = this
  134. uni.showModal({
  135. title: "提示",
  136. content: "您确定要删除当前收货地址吗?",
  137. success(res) {
  138. if (res.confirm) {
  139. $http.post('/api/v1/mp/user/addr/remove', {
  140. addrId: addressId
  141. }).then(res => {
  142. if (res.code == 0) {
  143. _this.getPageData()
  144. uni.$u.toast('删除成功');
  145. }
  146. })
  147. }
  148. }
  149. });
  150. },
  151. // 设置默认地址
  152. handleSetDefault(addressId) {
  153. $http.post('/api/v1/mp/user/addr/setDefault', {
  154. addrId: addressId
  155. }).then(res => {
  156. this.getPageData()
  157. })
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .addres-list {
  164. padding-bottom: calc(constant(safe-area-inset-bottom) + 120rpx);
  165. padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  166. }
  167. .address-item {
  168. margin: 20rpx auto 20rpx auto;
  169. padding: 30rpx 40rpx;
  170. width: 95%;
  171. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  172. border-radius: 10rpx;
  173. background: #fff;
  174. }
  175. .contacts {
  176. font-size: 30rpx;
  177. margin-bottom: 16rpx;
  178. .name {
  179. margin-right: 16rpx;
  180. }
  181. }
  182. .address {
  183. font-size: 28rpx;
  184. .region {
  185. margin-right: 10rpx;
  186. }
  187. }
  188. .line {
  189. margin: 20rpx 0;
  190. border-bottom: 1rpx solid #f3f3f3;
  191. }
  192. .item-option {
  193. display: flex;
  194. justify-content: space-between;
  195. height: 48rpx;
  196. // 单选框
  197. .item-radio {
  198. font-size: 28rpx;
  199. .radiooff {
  200. display: inline-block;
  201. vertical-align: middle;
  202. height: 35rpx;
  203. width: 35rpx;
  204. border-radius: 50%;
  205. border:1px solid #888;
  206. font-size: 24rpx;
  207. color: #fff;
  208. text-align: center;
  209. line-height: 38rpx;
  210. }
  211. .radioon {
  212. display: inline-block;
  213. vertical-align: middle;
  214. height: 35rpx;
  215. width: 35rpx;
  216. background-color: red;
  217. border-radius: 50%;
  218. border: red;
  219. font-size: 24rpx;
  220. font-weight: bold;
  221. color: #fff;
  222. text-align: center;
  223. line-height: 38rpx;
  224. }
  225. .text {
  226. padding-left: 20rpx;
  227. vertical-align: middle;
  228. }
  229. }
  230. // 操作
  231. .events {
  232. display: flex;
  233. align-items: center;
  234. line-height: 48rpx;
  235. .event-item {
  236. font-size: 28rpx;
  237. margin-right: 26rpx;
  238. color: #4c4c4c;
  239. &:last-child {
  240. margin-right: 0;
  241. }
  242. .title {
  243. margin-left: 8rpx;
  244. }
  245. }
  246. }
  247. }
  248. // 底部操作栏
  249. .footer-fixed {
  250. position: fixed;
  251. bottom: var(--window-bottom);
  252. left: 0;
  253. right: 0;
  254. min-height: 120rpx;
  255. z-index: 11;
  256. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  257. background: #fff;
  258. // 设置ios刘海屏底部横线安全区域
  259. padding-bottom: constant(safe-area-inset-bottom);
  260. padding-bottom: env(safe-area-inset-bottom);
  261. .btn-wrapper {
  262. display: flex;
  263. align-items: center;
  264. padding: 20rpx 0;
  265. }
  266. ::v-deep button {
  267. width: 441rpx;
  268. height: 88rpx;
  269. line-height: 88rpx;
  270. font-size: 36rpx;
  271. color: #fff;
  272. background-color: #F9822C;
  273. border: none;
  274. border-radius: 44rpx;
  275. margin: 0 auto;
  276. }
  277. }
  278. .empty {
  279. height: 60vh;
  280. .center {
  281. text-align: center;
  282. &-img {
  283. width: 228rpx;
  284. height: 320rpx;
  285. }
  286. &-font {
  287. font-size: 30rpx;
  288. font-weight: 400;
  289. color: #999999;
  290. margin-bottom: 250rpx;
  291. }
  292. }
  293. }
  294. </style>