address.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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.shouHuoRen}}</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')">添加新地址</view>
  40. </view>
  41. <!-- 删除弹窗 -->
  42. <model-alert v-if="isShowDelModal"
  43. :alertText='alertText'
  44. @btnConfirm ='confirmDetele'>
  45. </model-alert>
  46. </view>
  47. </template>
  48. <script>
  49. import authorize from '@/common/config/authorize.js'
  50. import modelAlert from '@/components/module/modelAlert/modelAlert.vue'
  51. import { queryAddressList , deleteNewAddress } from '@/api/cart.js'
  52. export default {
  53. components:{
  54. modelAlert
  55. },
  56. data() {
  57. return {
  58. isSelect:false,
  59. isEmpty:false,
  60. isLoadMore:false,
  61. userID:'',
  62. pageNum:1,
  63. pageSize:10,
  64. addressList: [],
  65. hasNextPage:false,
  66. allowDataStatus:true,
  67. wrapperHeight:'100%',
  68. scrollHeight:'',
  69. currPage:'',//当前页面
  70. prevPage:''//上一个页面
  71. }
  72. },
  73. onLoad(option){
  74. if(option.type=='select'){this.isSelect = true;}
  75. this.setScrollHeight();
  76. },
  77. onReachBottom() {
  78. if(this.isLoadMore) {
  79. this.initAddressList();
  80. }
  81. },
  82. methods: {
  83. setScrollHeight() { // 窗口高度 - 底部距离
  84. setTimeout(()=> {
  85. const query = wx.createSelectorQuery().in(this);
  86. query.selectAll('.add-btn').boundingClientRect();
  87. query.exec(res => {
  88. if(res[0][0]){
  89. let winHeight = this.$api.getWindowHeight(),
  90. eleTop = res[0][0].top - 1;
  91. this.scrollHeight = eleTop;
  92. }
  93. })
  94. }, 500)
  95. },
  96. initAddressList(){
  97. let params = {pageNum:this.pageNum,pageSize:this.pageSize,userID:this.userID}
  98. queryAddressList(params).then(response =>{
  99. if(response.data.results == ''){
  100. this.isEmpty = true
  101. }else{
  102. this.isEmpty = false
  103. let results =[];
  104. results = response.data.results;
  105. this.addressList = this.addressList.concat(results);
  106. this.pageNum = response.index +1;
  107. if(this.pageNum === response.totalPage + 1 ){
  108. this.isLoadMore = false;
  109. } else {
  110. this.isLoadMore = true;
  111. }
  112. }
  113. }).catch(response =>{
  114. this.$util.msg(res.msg,2000)
  115. })
  116. },
  117. //选择地址
  118. checkAddress(item){
  119. //是否需要返回地址(从订单确认页跳过来选收货地址)
  120. if(!this.isSelect){return ;}
  121. uni.setStorageSync('selectAddress',item)
  122. var pages = getCurrentPages();
  123. var prevPage = pages[pages.length - 2]; //上一个页面
  124. prevPage.setData({select:'select'})
  125. uni.navigateBack();
  126. },
  127. addAddress(type,item){
  128. uni.navigateTo({
  129. url: `/pages/user/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  130. })
  131. },
  132. //删除收货地址
  133. deleteAddress(id){
  134. this.$util.modal('','确定要删除该地址?','确定','取消',true,() =>{
  135. deleteNewAddress({addressID:id,userID:this.userID}).then(response =>{
  136. this.$util.msg('删除成功',2000,true,'success')
  137. setTimeout(() =>{
  138. this.pageNum = 1;
  139. this.addressList = [];
  140. this.initAddressList();
  141. },2000)
  142. }).catch(response =>{
  143. this.$util.msg(response.msg,2000);
  144. setTimeout(function(){
  145. uni.switchTab({
  146. url:'/pages/tabBar/home/home'
  147. })
  148. },1000)
  149. })
  150. })
  151. }
  152. },
  153. onShow() {
  154. this.$api.getStorage().then((resolve) =>{
  155. this.userID = resolve.userID
  156. this.pageNum = 1;
  157. this.addressList = [];
  158. this.initAddressList();
  159. var pages = getCurrentPages();
  160. var prevPage = pages[pages.length - 2]; //上一个页面
  161. // prevPage.setData({select:''})
  162. })
  163. }
  164. }
  165. </script>
  166. <style lang='scss'>
  167. page {
  168. height: auto;
  169. }
  170. page,.container{
  171. /* padding-bottom: 120upx; */
  172. background: #F7F7F7;
  173. border-top: 1px solid #EBEBEB;
  174. }
  175. .container{
  176. position: relative;
  177. }
  178. .list{
  179. display: flex;
  180. align-items: center;
  181. width: 702rpx;
  182. height: auto;
  183. padding: 24rpx;
  184. background: #FFFFFF;
  185. position: relative;
  186. border-bottom: 1px solid #EBEBEB;
  187. }
  188. .wrapper{
  189. display: flex;
  190. flex-direction: column;
  191. flex: 1;
  192. }
  193. .u-box.b-b{
  194. }
  195. .u-box.b-b{
  196. margin-bottom:24rpx;
  197. }
  198. .u-box.b-t{
  199. margin-bottom:0;
  200. }
  201. .u-box{
  202. display: flex;
  203. align-items: center;
  204. font-size: $font-size-28;
  205. color: $text-color;
  206. line-height: 40rpx;
  207. margin-bottom: 12rpx;
  208. .name{
  209. margin-right: 40rpx;
  210. font-weight: bold;
  211. }
  212. .mobile{
  213. font-weight: bold;
  214. }
  215. .tag-left{
  216. flex: 6;
  217. .tag{
  218. width: 120rpx;
  219. height: 40rpx;
  220. background: $color-system;
  221. border-radius: 20rpx;
  222. font-size: $font-size-24;
  223. color: #FFFFFF;
  224. line-height: 40rpx;
  225. text-align: center;
  226. padding: 0 6rpx;
  227. }
  228. }
  229. .tag-right{
  230. flex: 4;
  231. display: flex;
  232. text-align: right;
  233. .t-b{
  234. flex: 1;
  235. line-height: 40rpx;
  236. .txt{
  237. font-size: $font-size-24;
  238. color: $text-color;
  239. line-height: 40rpx;
  240. }
  241. }
  242. .icon-shanchu{
  243. color:#FF2A2A ;
  244. margin-right: 8rpx;
  245. }
  246. .icon-bianji{
  247. color: #2A7AFF;
  248. margin-right: 8rpx;
  249. }
  250. }
  251. .address{
  252. font-size: $font-size-28;
  253. color: $text-color;
  254. line-height: 40rpx;
  255. -o-text-overflow: ellipsis;
  256. text-overflow: ellipsis;
  257. display: -webkit-box;
  258. word-break: break-all;
  259. -webkit-box-orient: vertical;
  260. -webkit-line-clamp: 2;
  261. overflow: hidden;
  262. }
  263. }
  264. .add-btn{
  265. position: fixed;
  266. left: 24rpx;
  267. right: 24rpx;
  268. bottom: 34rpx;
  269. z-index: 95;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. width: 702rpx;
  274. height: 88rpx;
  275. font-size: $font-size-28;
  276. line-height: 88rpx;
  277. color: #FFFFFF;
  278. text-align: center;
  279. background: $btn-confirm;
  280. border-radius: 14rpx;
  281. }
  282. .adds-btn{
  283. width: 702rpx;
  284. height: 88rpx;
  285. font-size: 28rpx;
  286. line-height: 88rpx;
  287. color: #FFFFFF;
  288. margin: 0 auto;
  289. text-align: center;
  290. background: #000000;
  291. border-radius: 14rpx;
  292. }
  293. </style>