address.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view class="container clearfix">
  3. <view v-if="isEmpty" class="empty-container">
  4. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AFmO1AAGxLZjSeDg040.png" mode="aspectFit"></image>
  5. <view class="txt">您还没有收货地址</view>
  6. <view class="txt">点击底部按钮添加收货地址吧~~</view>
  7. <view class="login-btn" @click="addAddress('add')">添加新地址</view>
  8. </view>
  9. <view v-else class="address-list" :style="{'height': scrollHeight + 'px'}">
  10. <scroll-view scroll-y="true" :style="{'height': scrollHeight + 'px'}">
  11. <view class="list" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  12. <view class="wrapper">
  13. <view class="u-box">
  14. <text class="name">{{item.receiver}}</text>
  15. <text class="mobile">{{item.mobile}}</text>
  16. </view>
  17. <view class="u-box b-b">
  18. <text class="address">收货地址:{{item.province}}{{item.city}}{{item.town}}{{item.address}}</text>
  19. </view>
  20. <view class="u-box b-t">
  21. <view v-if="item.defaultFlag == 1" class="tag-left">
  22. <view class="tag">默认地址</view>
  23. </view>
  24. <view v-else class="tag-left"></view>
  25. <view class="tag-right">
  26. <view class="t-b" @click.stop="deleteAddress(item.addressId)">
  27. <text class="iconfont icon-shanchu"></text>
  28. <text class="txt">删除</text>
  29. </view>
  30. <view class="t-b" @click.stop="addAddress('edit',item)">
  31. <text class="iconfont icon-bianji"></text>
  32. <text class="txt">编辑</text>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. <view class="add-btn" @click="addAddress('add')" :style="{bottom :isIphoneX ? '68rpx' : '34rpx'}">添加新地址</view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import authorize from '@/common/config/authorize.js'
  45. export default {
  46. data() {
  47. return {
  48. isIphoneX:this.$store.state.isIphoneX,
  49. isSelect:false,
  50. isEmpty:false,
  51. listQuery:{
  52. userId:0,
  53. pageNum:1,
  54. pageSize:10
  55. },
  56. addressList: [],
  57. hasNextPage:false,
  58. allowDataStatus:true,
  59. wrapperHeight:'100%',
  60. scrollHeight:'',
  61. currPage:'',//当前页面
  62. prevPage:''//上一个页面
  63. }
  64. },
  65. onLoad(option){
  66. if(option.type=='select'){this.isSelect = true;}
  67. this.setScrollHeight();
  68. },
  69. methods: {
  70. setScrollHeight() { // 窗口高度 - 底部距离
  71. setTimeout(()=> {
  72. const query = wx.createSelectorQuery().in(this);
  73. query.selectAll('.add-btn').boundingClientRect();
  74. query.exec(res => {
  75. if(res[0][0]){
  76. let winHeight = this.$api.getWindowHeight(),
  77. eleTop = res[0][0].top - 1;
  78. this.scrollHeight = eleTop;
  79. }
  80. })
  81. }, 500)
  82. },
  83. getQueryAddressList(){ //初始化地址列表数据
  84. this.UserService.QueryAddressList(this.listQuery).then(response =>{
  85. let data = response.data
  86. if(data.list&&data.list.length > 0){
  87. this.isEmpty = false
  88. this.hasNextPage = data.hasNextPage
  89. this.addressList = data.list
  90. }else{
  91. this.isEmpty = true
  92. }
  93. }).catch(error =>{
  94. this.$util.msg(error.msg,2000)
  95. })
  96. },
  97. getOnReachBottomData(){// 上滑加载分页
  98. this.listQuery.pageNum+=1
  99. this.UserService.QueryAddressList(this.listQuery).then(response =>{
  100. let data = response.data
  101. if(data.list&&data.list.length > 0){
  102. this.hasNextPage = data.hasNextPage
  103. this.addressList = this.addressList.concat(data.list)
  104. }
  105. })
  106. .catch(error =>{
  107. this.$util.msg(error.msg,2000)
  108. })
  109. },
  110. checkAddress(item){//选择地址
  111. //是否需要返回地址(从订单确认页跳过来选收货地址)
  112. if(!this.isSelect){return ;}
  113. uni.setStorageSync('selectAddress',item)
  114. var pages = getCurrentPages();
  115. var prevPage = pages[pages.length - 2]; //上一个页面
  116. prevPage.setData({select:'select'})
  117. uni.navigateBack();
  118. },
  119. addAddress(type,item){
  120. uni.navigateTo({
  121. url: `/pages/user/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  122. })
  123. },
  124. deleteAddress(addressId){//删除收货地址
  125. this.$util.modal('','确定要删除该地址?','确定','取消',true,() =>{
  126. this.UserService.DeleteAddress({addressId:addressId,userId:this.listQuery.userId}).then(response =>{
  127. this.$util.msg('删除成功',2000,true,'success')
  128. setTimeout(() =>{
  129. this.listQuery.pageNum = 1;
  130. this.addressList = [];
  131. this.getQueryAddressList();
  132. },2000)
  133. }).catch(error =>{
  134. this.$util.msg(error.msg,2000);
  135. })
  136. })
  137. }
  138. },
  139. onReachBottom() {
  140. if(this.hasNextPage) {
  141. this.getOnReachBottomData();
  142. }
  143. },
  144. onShow() {
  145. this.$api.getStorage().then((resolve) =>{
  146. this.listQuery.userId = resolve.userId ? resolve.userId : 0
  147. this.listQuery.pageNum = 1;
  148. this.addressList = [];
  149. this.getQueryAddressList();
  150. var pages = getCurrentPages();
  151. var prevPage = pages[pages.length - 2]; //上一个页面
  152. // prevPage.setData({select:''})
  153. })
  154. }
  155. }
  156. </script>
  157. <style lang='scss'>
  158. page {
  159. height: auto;
  160. }
  161. page,.container{
  162. /* padding-bottom: 120upx; */
  163. background: #F7F7F7;
  164. border-top: 1px solid #EBEBEB;
  165. }
  166. .container{
  167. position: relative;
  168. }
  169. .list{
  170. display: flex;
  171. align-items: center;
  172. width: 702rpx;
  173. height: auto;
  174. padding: 24rpx;
  175. background: #FFFFFF;
  176. position: relative;
  177. border-bottom: 1px solid #EBEBEB;
  178. }
  179. .wrapper{
  180. display: flex;
  181. flex-direction: column;
  182. flex: 1;
  183. }
  184. .u-box.b-b{
  185. }
  186. .u-box.b-b{
  187. margin-bottom:24rpx;
  188. }
  189. .u-box.b-t{
  190. margin-bottom:0;
  191. }
  192. .u-box{
  193. display: flex;
  194. align-items: center;
  195. font-size: $font-size-28;
  196. color: $text-color;
  197. line-height: 40rpx;
  198. margin-bottom: 12rpx;
  199. .name{
  200. margin-right: 40rpx;
  201. font-weight: bold;
  202. }
  203. .mobile{
  204. font-weight: bold;
  205. }
  206. .tag-left{
  207. flex: 6;
  208. .tag{
  209. width: 120rpx;
  210. height: 40rpx;
  211. background: $color-system;
  212. border-radius: 20rpx;
  213. font-size: $font-size-24;
  214. color: #FFFFFF;
  215. line-height: 40rpx;
  216. text-align: center;
  217. padding: 0 6rpx;
  218. }
  219. }
  220. .tag-right{
  221. flex: 4;
  222. display: flex;
  223. text-align: right;
  224. .t-b{
  225. flex: 1;
  226. line-height: 40rpx;
  227. .txt{
  228. font-size: $font-size-24;
  229. color: $text-color;
  230. line-height: 40rpx;
  231. }
  232. }
  233. .icon-shanchu{
  234. color:#FF2A2A ;
  235. margin-right: 8rpx;
  236. }
  237. .icon-bianji{
  238. color: #2A7AFF;
  239. margin-right: 8rpx;
  240. }
  241. }
  242. .address{
  243. font-size: $font-size-28;
  244. color: $text-color;
  245. line-height: 40rpx;
  246. -o-text-overflow: ellipsis;
  247. text-overflow: ellipsis;
  248. display: -webkit-box;
  249. word-break: break-all;
  250. -webkit-box-orient: vertical;
  251. -webkit-line-clamp: 2;
  252. overflow: hidden;
  253. }
  254. }
  255. .add-btn{
  256. position: fixed;
  257. left: 75rpx;
  258. right: 75rpx;
  259. bottom: 34rpx;
  260. z-index: 95;
  261. display: flex;
  262. align-items: center;
  263. justify-content: center;
  264. width: 600rpx;
  265. height: 88rpx;
  266. font-size: $font-size-28;
  267. line-height: 88rpx;
  268. color: #FFFFFF;
  269. text-align: center;
  270. background: $btn-confirm;
  271. border-radius: 44rpx;
  272. }
  273. .adds-btn{
  274. width: 600rpx;
  275. height: 88rpx;
  276. font-size: 28rpx;
  277. line-height: 88rpx;
  278. color: #FFFFFF;
  279. margin: 0 auto;
  280. text-align: center;
  281. background: #000000;
  282. border-radius: 44rpx;
  283. }
  284. </style>