address.vue 8.4 KB

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