address.vue 8.5 KB

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