address.vue 7.3 KB

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