phone.vue 7.6 KB

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