address.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  98. this.userID = resolve.userID
  99. let params = {pageNum:this.pageNum,pageSize:this.pageSize,userID:this.userID}
  100. queryAddressList(params).then(response =>{
  101. if(response.data.results == ''){
  102. this.isEmpty = true
  103. }else{
  104. this.isEmpty = false
  105. let results =[];
  106. results = response.data.results;
  107. this.addressList = this.addressList.concat(results);
  108. this.pageNum = response.index +1;
  109. if(this.pageNum === response.totalPage + 1 ){
  110. this.isLoadMore = false;
  111. } else {
  112. this.isLoadMore = true;
  113. }
  114. }
  115. }).catch(response =>{
  116. this.$util.msg(res.msg,2000)
  117. })
  118. })
  119. },
  120. //选择地址
  121. checkAddress(item){
  122. //是否需要返回地址(从订单确认页跳过来选收货地址)
  123. if(!this.isSelect){return ;}
  124. uni.setStorageSync('selectAddress',item)
  125. var pages = getCurrentPages();
  126. var prevPage = pages[pages.length - 2]; //上一个页面
  127. prevPage.setData({select:'select'})
  128. uni.navigateBack();
  129. },
  130. addAddress(type,item){
  131. uni.navigateTo({
  132. url: `/market/pages/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  133. })
  134. },
  135. //删除收货地址
  136. deleteAddress(id){
  137. this.$util.modal('','确定要删除该地址?','确定','取消',true,() =>{
  138. deleteNewAddress({addressID:id,userID:this.userID}).then(response =>{
  139. this.$util.msg('删除成功',2000,true,'success')
  140. setTimeout(() =>{
  141. this.pageNum = 1;
  142. this.addressList = [];
  143. this.initAddressList();
  144. },2000)
  145. }).catch(response =>{
  146. this.$util.msg(response.msg,2000);
  147. setTimeout(function(){
  148. uni.switchTab({
  149. url:'/market/pages/home/home'
  150. })
  151. },1000)
  152. })
  153. })
  154. }
  155. },
  156. onShow() {
  157. this.$api.getStorage().then((resolve) =>{
  158. this.userID = resolve.userID
  159. this.pageNum = 1;
  160. this.addressList = [];
  161. this.initAddressList();
  162. var pages = getCurrentPages();
  163. var prevPage = pages[pages.length - 2]; //上一个页面
  164. // prevPage.setData({select:''})
  165. })
  166. }
  167. }
  168. </script>
  169. <style lang='scss'>
  170. page {
  171. height: auto;
  172. }
  173. page,.container{
  174. /* padding-bottom: 120upx; */
  175. background: #F7F7F7;
  176. border-top: 1px solid #EBEBEB;
  177. }
  178. .container{
  179. position: relative;
  180. }
  181. .list{
  182. display: flex;
  183. align-items: center;
  184. width: 702rpx;
  185. height: auto;
  186. padding: 24rpx;
  187. background: #FFFFFF;
  188. position: relative;
  189. border-bottom: 1px solid #EBEBEB;
  190. }
  191. .wrapper{
  192. display: flex;
  193. flex-direction: column;
  194. flex: 1;
  195. }
  196. .u-box.b-b{
  197. }
  198. .u-box.b-b{
  199. margin-bottom:24rpx;
  200. }
  201. .u-box.b-t{
  202. margin-bottom:0;
  203. }
  204. .u-box{
  205. display: flex;
  206. align-items: center;
  207. font-size: $font-size-28;
  208. color: $text-color;
  209. line-height: 40rpx;
  210. margin-bottom: 12rpx;
  211. .name{
  212. margin-right: 40rpx;
  213. font-weight: bold;
  214. }
  215. .mobile{
  216. font-weight: bold;
  217. }
  218. .tag-left{
  219. flex: 6;
  220. .tag{
  221. width: 120rpx;
  222. height: 40rpx;
  223. background: $color-system;
  224. border-radius: 20rpx;
  225. font-size: $font-size-24;
  226. color: #FFFFFF;
  227. line-height: 40rpx;
  228. text-align: center;
  229. padding: 0 6rpx;
  230. }
  231. }
  232. .tag-right{
  233. flex: 4;
  234. display: flex;
  235. text-align: right;
  236. .t-b{
  237. flex: 1;
  238. line-height: 40rpx;
  239. .txt{
  240. font-size: $font-size-24;
  241. color: $text-color;
  242. line-height: 40rpx;
  243. }
  244. }
  245. .icon-shanchu{
  246. color:#FF2A2A ;
  247. margin-right: 8rpx;
  248. }
  249. .icon-bianji{
  250. color: #2A7AFF;
  251. margin-right: 8rpx;
  252. }
  253. }
  254. .address{
  255. font-size: $font-size-28;
  256. color: $text-color;
  257. line-height: 40rpx;
  258. -o-text-overflow: ellipsis;
  259. text-overflow: ellipsis;
  260. display: -webkit-box;
  261. word-break: break-all;
  262. -webkit-box-orient: vertical;
  263. -webkit-line-clamp: 2;
  264. overflow: hidden;
  265. }
  266. }
  267. .add-btn{
  268. position: fixed;
  269. left: 24rpx;
  270. right: 24rpx;
  271. bottom: 34rpx;
  272. z-index: 95;
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. width: 702rpx;
  277. height: 88rpx;
  278. font-size: $font-size-28;
  279. line-height: 88rpx;
  280. color: #FFFFFF;
  281. text-align: center;
  282. background: $btn-confirm;
  283. border-radius: 14rpx;
  284. }
  285. .adds-btn{
  286. width: 702rpx;
  287. height: 88rpx;
  288. font-size: 28rpx;
  289. line-height: 88rpx;
  290. color: #FFFFFF;
  291. margin: 0 auto;
  292. text-align: center;
  293. background: #000000;
  294. border-radius: 14rpx;
  295. }
  296. </style>