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.receiver}}</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. </view>
  42. </template>
  43. <script>
  44. import authorize from '@/common/config/authorize.js'
  45. export default {
  46. data() {
  47. return {
  48. isIphoneX:this.$store.state.isIphoneX,
  49. isSelect:false,
  50. isEmpty:false,
  51. listQuery:{
  52. userId:0,
  53. pageNum:1,
  54. pageSize:10
  55. },
  56. addressList: [],
  57. hasNextPage:false,
  58. allowDataStatus:true,
  59. wrapperHeight:'100%',
  60. scrollHeight:'',
  61. currPage:'',//当前页面
  62. prevPage:''//上一个页面
  63. }
  64. },
  65. onLoad(option){
  66. if(option.type=='select'){this.isSelect = true}
  67. this.setScrollHeight()
  68. },
  69. methods: {
  70. setScrollHeight() { // 窗口高度 - 底部距离
  71. setTimeout(()=> {
  72. const query = wx.createSelectorQuery().in(this)
  73. query.selectAll('.add-btn').boundingClientRect()
  74. query.exec(res => {
  75. if(res[0][0]){
  76. let winHeight = this.$api.getWindowHeight(),
  77. eleTop = res[0][0].top - 1
  78. this.scrollHeight = eleTop
  79. }
  80. })
  81. }, 500)
  82. },
  83. getQueryAddressList(){ //初始化地址列表数据
  84. this.UserService.QueryAddressList(this.listQuery).then(response =>{
  85. let data = response.data
  86. if(data.list&&data.list.length > 0){
  87. this.isEmpty = false
  88. this.hasNextPage = data.hasNextPage
  89. this.addressList = data.list
  90. }else{
  91. this.isEmpty = true
  92. }
  93. }).catch(error =>{
  94. this.$util.msg(error.msg,2000)
  95. })
  96. },
  97. getOnReachBottomData(){// 上滑加载分页
  98. this.listQuery.pageNum+=1
  99. this.UserService.QueryAddressList(this.listQuery).then(response =>{
  100. let data = response.data
  101. if(data.list&&data.list.length > 0){
  102. this.hasNextPage = data.hasNextPage
  103. this.addressList = this.addressList.concat(data.list)
  104. }
  105. })
  106. .catch(error =>{
  107. this.$util.msg(error.msg,2000)
  108. })
  109. },
  110. checkAddress(item){//选择地址
  111. //是否需要返回地址(从订单确认页跳过来选收货地址)
  112. if(!this.isSelect){return }
  113. uni.setStorageSync('selectAddress',item)
  114. var pages = getCurrentPages()
  115. var prevPage = pages[pages.length - 2] //上一个页面
  116. prevPage.setData({select:'select'})
  117. uni.navigateBack()
  118. },
  119. addAddress(type,item){
  120. uni.navigateTo({
  121. url: `/pages/seller/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  122. })
  123. },
  124. deleteAddress(addressId){//删除收货地址
  125. this.$util.modal('','确定要删除该地址?','确定','取消',true,() =>{
  126. this.UserService.DeleteAddress({addressId:addressId,userId:this.listQuery.userId}).then(response =>{
  127. this.$util.msg('删除成功',2000,true,'success')
  128. setTimeout(() =>{
  129. this.listQuery.pageNum = 1
  130. this.addressList = []
  131. this.getQueryAddressList()
  132. },2000)
  133. }).catch(error =>{
  134. this.$util.msg(error.msg,2000)
  135. })
  136. })
  137. }
  138. },
  139. onReachBottom() {
  140. if(this.hasNextPage) {
  141. this.getOnReachBottomData()
  142. }
  143. },
  144. onShow() {
  145. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  146. this.listQuery.userId = resolve.userId? resolve.userId : 0
  147. this.listQuery.pageNum = 1
  148. this.addressList = []
  149. this.getQueryAddressList()
  150. var pages = getCurrentPages()
  151. var prevPage = pages[pages.length - 2] //上一个页面
  152. // prevPage.setData({select:''})
  153. })
  154. }
  155. }
  156. </script>
  157. <style lang='scss'>
  158. page {
  159. height: auto;
  160. }
  161. page,.container{
  162. /* padding-bottom: 120upx; */
  163. background: #F7F7F7;
  164. border-top: 1px solid #EBEBEB;
  165. }
  166. .container{
  167. position: relative;
  168. }
  169. .address-list{
  170. width: 100%;
  171. box-sizing: border-box;
  172. padding: 24rpx;
  173. }
  174. .list{
  175. display: flex;
  176. align-items: center;
  177. width: 100%;
  178. height: auto;
  179. padding: 24rpx;
  180. background: #FFFFFF;
  181. position: relative;
  182. box-sizing: border-box;
  183. margin-bottom: 24rpx;
  184. border-radius: 16rpx;
  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>