address.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <!-- <view class="top">
  5. <view class="del" @click="delAllAddress">清空地址</view>
  6. </view> -->
  7. <view v-for="(item,index) in address" :key="index" class="address-item">
  8. <view class="info" @click="selectAddress(item)">
  9. <view class="title">
  10. <view v-if="item.isDefault == 1" class="tag">默认</view>
  11. {{item.province}}{{item.city}}{{item.district}}{{item.detail}}
  12. </view>
  13. <view class="name-phone">
  14. <text class="text">{{item.realName}}</text>
  15. <text class="text">{{$parsePhone(item.phone)}}</text>
  16. </view>
  17. </view>
  18. <view class="operat-box">
  19. <image src="/static/images/del1.png" mode="" @click="delAddress(item)"></image>
  20. <image src="/static/images/edit.png" mode="" @click="editAddress(item)"></image>
  21. </view>
  22. </view>
  23. <view v-if="address.length == 0" class="no-data-box" @click="getAddressList()">
  24. <image src="/static/images/no_data.png" mode="aspectFit"></image>
  25. <view class="empty-title">暂无数据</view>
  26. </view>
  27. </view>
  28. <view class="btn-box">
  29. <view class="sub-btn" @click="addAdress">新建收货地址</view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. userAddr, // 获取用户收货地址
  36. delAddress ,// 删除地址
  37. } from "@/api/order.js"
  38. // import {getAddressList,delAddress,delAllAddress} from '@/api/address'
  39. export default {
  40. data() {
  41. return {
  42. address: [],
  43. }
  44. },
  45. onLoad() {
  46. this.getUserAddr()
  47. uni.$on('refreshAddress', () => {
  48. this.getUserAddr()
  49. })
  50. },
  51. // mounted() {
  52. // this.getUserAddr()
  53. // },
  54. methods: {
  55. // 获取用户收货地址
  56. getUserAddr() {
  57. this.userInfo = JSON.parse(uni.getStorageSync("userInfo"))
  58. userAddr(this.userInfo.userId).then(res => {
  59. if (res.code == 200) {
  60. console.log("用户收货地址>>>>", res.data)
  61. // this.userAddrLiat = res
  62. this.address = res.data;
  63. } else {
  64. uni.showToast({
  65. title: res.msg,
  66. icon: 'none'
  67. });
  68. }
  69. },
  70. rej => {}
  71. );
  72. },
  73. // 选地址
  74. selectAddress(item) {
  75. uni.$emit('updateAddress', item);
  76. uni.navigateBack({
  77. delta: 1
  78. });
  79. },
  80. // 编辑地址
  81. editAddress(item) {
  82. uni.navigateTo({
  83. url: './addAddress?type=edit&addressId=' + item.addressId
  84. })
  85. },
  86. // 删除所有地址(暂无)
  87. // delAllAddress(item) {
  88. // uni.showModal({
  89. // title: "提示",
  90. // content: "确认删除所有地址吗?",
  91. // showCancel: true,
  92. // cancelText: '取消',
  93. // confirmText: '确定',
  94. // success: res => {
  95. // if (res.confirm) {
  96. // var data = {}
  97. // delAllAddress(data).then(
  98. // res => {
  99. // if (res.code == 200) {
  100. // uni.showToast({
  101. // icon: 'success',
  102. // title: "操作成功",
  103. // });
  104. // this.getAddressList()
  105. // } else {
  106. // uni.showToast({
  107. // icon: 'none',
  108. // title: "请求失败",
  109. // });
  110. // }
  111. // },
  112. // rej => {}
  113. // );
  114. // } else {
  115. // // 否则点击了取消
  116. // }
  117. // }
  118. // })
  119. // },
  120. // 删除地址
  121. delAddress(item) {
  122. uni.showModal({
  123. title: "提示",
  124. content: "确认删除此地址吗?",
  125. showCancel: true,
  126. cancelText: '取消',
  127. confirmText: '确定',
  128. success: res => {
  129. if (res.confirm) {
  130. // 用户点击确定
  131. var data = {
  132. addressId: item.addressId
  133. }
  134. delAddress(data).then(
  135. res => {
  136. if (res.code == 200) {
  137. uni.showToast({
  138. icon: 'success',
  139. title: "操作成功",
  140. });
  141. this.getUserAddr()
  142. } else {
  143. uni.showToast({
  144. icon: 'none',
  145. title: "请求失败",
  146. });
  147. }
  148. },
  149. rej => {}
  150. );
  151. } else {
  152. // 否则点击了取消
  153. }
  154. }
  155. })
  156. },
  157. // getAddressList(){
  158. // uni.showLoading({
  159. // title:"正在加载中"
  160. // })
  161. // getAddressList().then(
  162. // res => {
  163. // uni.hideLoading()
  164. // if(res.code==200){
  165. // this.address=res.data;
  166. // }else{
  167. // uni.showToast({
  168. // icon:'none',
  169. // title: "请求失败",
  170. // });
  171. // }
  172. // },
  173. // rej => {}
  174. // );
  175. // },
  176. // 新建收货地址
  177. addAdress() {
  178. uni.navigateTo({
  179. url: './addAddress?type=add'
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss">
  186. page {
  187. height: 100%;
  188. }
  189. .content {
  190. height: 100%;
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: space-between;
  194. .inner {
  195. flex: 1;
  196. padding: 20upx 20upx 160upx;
  197. .top {
  198. padding: 0upx 20upx 20upx;
  199. text-align: right;
  200. .del {
  201. font-size: 28upx;
  202. font-family: PingFang SC;
  203. color: #999999;
  204. }
  205. }
  206. .address-item {
  207. background: #FFFFFF;
  208. border-radius: 16upx;
  209. padding: 46upx 40upx 50upx 24upx;
  210. display: flex;
  211. align-items: center;
  212. justify-content: space-between;
  213. margin-bottom: 20upx;
  214. .info {
  215. width: 75%;
  216. .title {
  217. font-size: 30upx;
  218. font-family: PingFang SC;
  219. font-weight: bold;
  220. color: #111111;
  221. line-height: 42upx;
  222. word-break: break-all;
  223. .tag {
  224. padding: 0 6upx;
  225. height: 32upx;
  226. line-height: 32upx;
  227. font-size: 22upx;
  228. font-family: PingFang SC;
  229. font-weight: 500;
  230. color: #FFFFFF;
  231. background: #0bb3f2;
  232. border-radius: 4upx;
  233. float: left;
  234. margin-right: 10upx;
  235. margin-top: 5upx;
  236. }
  237. }
  238. .name-phone {
  239. margin-top: 30upx;
  240. display: flex;
  241. align-items: center;
  242. .text {
  243. font-size: 26upx;
  244. font-family: PingFang SC;
  245. font-weight: 500;
  246. color: #999999;
  247. margin-right: 22upx;
  248. &:last-child {
  249. margin-right: 0;
  250. }
  251. }
  252. }
  253. }
  254. .operat-box {
  255. display: flex;
  256. align-items: center;
  257. image {
  258. width: 30upx;
  259. height: 30upx;
  260. margin-left: 38upx;
  261. &:first-child {
  262. margin-left: 0;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. .no-data-box {
  269. display: flex;
  270. flex-direction: column;
  271. align-items: center;
  272. }
  273. .btn-box {
  274. z-index: 9999;
  275. width: 100%;
  276. padding: 30upx;
  277. position: fixed;
  278. bottom: 0;
  279. left: 0;
  280. box-sizing: border-box;
  281. background: #FFFFFF;
  282. .sub-btn {
  283. height: 88upx;
  284. line-height: 88upx;
  285. text-align: center;
  286. font-size: 30upx;
  287. font-family: PingFang SC;
  288. font-weight: bold;
  289. color: #FFFFFF;
  290. background: #0bb3f2;
  291. border-radius: 44upx;
  292. }
  293. }
  294. }
  295. </style>