address.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="page b-t">
  3. <!--
  4. <singleList ref="listRef" url="cang.mycollectionsecond" :sendData="reqData" @reqEnd="searchEnd">
  5. <template v-slot:items="{list}">
  6. -->
  7. <!-- -->
  8. <view class="list b-b" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  9. <image :src="item.checked? '/static/check-do.png' : '/static/check-un.png' " mode="aspectFill" class="check"></image>
  10. <view class="content flex-col">
  11. <view class="u-box align-center">
  12. <text class="name">{{item.name}}</text>
  13. <text class="mobile">{{item.mobile}}</text>
  14. <text v-if="item.is_default" class="tag">默认</text>
  15. <view class="ic-wrap del align-center justify-center">
  16. <image src="/static/addr-del.png" mode="aspectFill" class="ic" @click.stop="deleteAddress(item.id,index)"></image>
  17. </view>
  18. <view class="ic-wrap edit align-center justify-center">
  19. <image src="/static/addr-edit.png" mode="aspectFill" class="ic" @click.stop="addAddress('edit', item.id)"></image>
  20. </view>
  21. </view>
  22. <view class="address-box">
  23. <text class="address">{{item.addr+' '+item.desc}}</text>
  24. </view>
  25. </view>
  26. </view>
  27. <!--
  28. <empty v-else-if="sRes && sRes==='empty'"/>
  29. </template>
  30. </singleList>
  31. -->
  32. <button class="add-btn" @click="addAddress('add')">新增地址</button>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. source: 0,
  40. addressList: [
  41. {
  42. id:1,
  43. is_default:true,
  44. addr:'山东省临沂市河东区',
  45. desc:'山东省临沂市河东区山东省临沂市河东区山东省临沂市河东区山东省临沂市河东区山东省临沂市河东区',
  46. name:'mork',
  47. mobile:'15263970923',
  48. checked:true,
  49. },
  50. {
  51. id:1,
  52. is_default:false,
  53. addr:'山东省临沂市河东区',
  54. desc:'山东省临沂市河东区山东省临沂市河东区山东省临沂市河东区山东省临沂市河东区山东省临沂市河东区',
  55. name:'mork',
  56. mobile:'15263970923',
  57. checked:false,
  58. },
  59. ],
  60. reqData:{}, //请求数据
  61. sRes:'', //搜索结果 empty,noMore
  62. }
  63. },
  64. onLoad(option) {
  65. // console.log(option.source);
  66. this.source = option.source;
  67. // this.$nextTick(()=>{
  68. // this.reqData={
  69. // type: this.cats[this.curCatIdx].state,
  70. // }
  71. // })
  72. },
  73. onShow() {
  74. // this.refreshList();
  75. },
  76. methods: {
  77. //获取我的收货地址
  78. async getList() {
  79. let res = await this.$api.request('/addons/unishop/address/all', 'POST', {
  80. page: 1,
  81. pagesize: 50
  82. });
  83. let list = res.data;
  84. if (list) {
  85. this.addressList = list;
  86. }
  87. },
  88. //选择地址
  89. checkAddress(item) {
  90. if (this.source == 1) {
  91. //this.$api.prePage()获取上一页实例,在App.vue定义
  92. this.$api.prePage().addressData = item;
  93. uni.navigateBack()
  94. }
  95. },
  96. addAddress(type, id = 0) {
  97. uni.navigateTo({
  98. url: `/pages/address/addressManage?type=${type}&id=${id}`
  99. })
  100. },
  101. //添加或修改成功之后回调
  102. refreshList(data, type) {
  103. //添加或修改后事件,这里直接在最前面添加了一条数据,实际应用中直接刷新地址列表即可
  104. // this.addressList.unshift(data);
  105. this.addressList=[];
  106. this.getList();
  107. },
  108. async deleteAddress(id, index) {
  109. let [error, res] = await uni.showModal({
  110. title: '确定删除地址?',
  111. content: this.addressList[index].address
  112. })
  113. if (res.confirm) {
  114. let res = await this.$api.request('/addons/unishop/address/delete?id=' + id);
  115. let data = res.data;
  116. if (data) {
  117. if (this.$api.prePage().addressData && this.$api.prePage().addressData.id) {
  118. if (this.$api.prePage().addressData.id == this.addressList[index].id) {
  119. this.$api.prePage().addressData = {};
  120. }
  121. }
  122. this.addressList.splice(index, 1);
  123. }
  124. }
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang='scss'>
  130. page {
  131. background: #f8f8f8;
  132. }
  133. .page{
  134. padding: 30rpx 20rpx 0;
  135. min-height: 100vh;
  136. padding-bottom: calc(var(--safe-area-inset-bottom) / 2);
  137. position: relative;
  138. }
  139. .list {
  140. padding: 20upx 20upx 50rpx 73rpx;
  141. background: #fff;
  142. position: relative;
  143. border-radius: 10rpx;
  144. margin-bottom: 24rpx;
  145. .check{
  146. position: absolute;
  147. left: 17rpx;
  148. top: 60rpx;
  149. width: 34rpx;
  150. height: 34rpx;
  151. z-index: 2;
  152. }
  153. }
  154. .u-box {
  155. color: #999;
  156. height: 48rpx;
  157. .name{
  158. font-size: 30rpx;
  159. font-family: PingFang SC;
  160. font-weight: 500;
  161. color: #333333;
  162. margin-right: 20rpx;
  163. }
  164. .mobile{
  165. font-size: 30rpx;
  166. font-family: PingFang SC;
  167. font-weight: 500;
  168. color: #333333;
  169. margin-right: 12rpx;
  170. }
  171. .tag{
  172. width: 61rpx;
  173. height: 34rpx;
  174. background: #92B99C;
  175. border-radius: 4rpx;
  176. line-height: 34rpx;
  177. text-align: center;
  178. font-size: 22rpx;
  179. font-family: PingFang SC;
  180. font-weight: 500;
  181. color: #FFFFFF;
  182. }
  183. .ic-wrap{
  184. height: 48rpx;
  185. width: 64rpx;
  186. &.del{
  187. margin-left: auto;
  188. .ic{
  189. width: 28rpx;
  190. height: 28rpx;
  191. }
  192. }
  193. &.edit{
  194. margin-left: 8rpx;
  195. }
  196. .ic{
  197. width: 24rpx;
  198. height: 24rpx;
  199. }
  200. }
  201. }
  202. .address-box {
  203. margin-top: 13rpx;
  204. display: flex;
  205. align-items: flex-start;
  206. .address {
  207. font-size: 24upx;
  208. color: #999;
  209. max-width: 600rpx;
  210. line-height: 40rpx;
  211. }
  212. }
  213. .add-btn {
  214. display: flex;
  215. align-items: center;
  216. justify-content: center;
  217. width: 710upx;
  218. height: 80upx;
  219. margin: 240rpx auto 10rpx;
  220. font-size: 30upx;
  221. color: #fff;
  222. background-color: $base-color;
  223. border-radius: 38upx;
  224. }
  225. </style>