address.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. <text v-if="item.defaultFlag == 1" class="default-tags">默认</text>
  17. </view>
  18. <view class="u-box b-b">
  19. <text class="address"><text class="label">收货地址:</text>{{item.province}}{{item.city}}{{item.town}}{{item.address}}</text>
  20. </view>
  21. <view class="u-box b-t">
  22. <view v-if="item.defaultFlag == 1" class="tag-left">
  23. <view class="tag"><text class="iconfont icon-xuanze"></text><text>已设为默认地址</text></view>
  24. </view>
  25. <view v-else class="tag-left">
  26. <view class="tag"><text class="iconfont icon-weixuanze"></text><text>设为默认地址</text></view>
  27. </view>
  28. <view class="tag-right">
  29. <view class="t-b" @click.stop="deleteAddress(item.addressID)">
  30. <text class="iconfont icon-shanchu"></text>
  31. <text class="txt">删除</text>
  32. </view>
  33. <view class="t-b" @click.stop="addAddress('edit',item)">
  34. <text class="iconfont icon-bianji"></text>
  35. <text class="txt">编辑</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. <view class="add-btn" @click="addAddress('add')">添加新地址</view>
  43. </view>
  44. <tui-modal :show="modal" @click="handleClick" @cancel="hideMobel" :content="contentModalText" color="#333" :size="32" shape="circle" :maskClosable="false"></tui-modal>
  45. </view>
  46. </template>
  47. <script>
  48. import authorize from '@/common/config/authorize.js'
  49. import modelAlert from '@/components/cm-module/modelAlert/modelAlert.vue'
  50. import { addressList } from '@/common/json/data.json.js' //本地数据
  51. export default {
  52. components:{
  53. modelAlert
  54. },
  55. data() {
  56. return {
  57. isSelect:false,
  58. isEmpty:false,
  59. isLoadMore:false,
  60. userID:'',
  61. pageNum:1,
  62. pageSize:10,
  63. addressList: addressList,
  64. hasNextPage:false,
  65. allowDataStatus:true,
  66. wrapperHeight:'100%',
  67. scrollHeight:'',
  68. currPage:'',//当前页面
  69. prevPage:'',//上一个页面
  70. modal:false,
  71. contentModalText:''
  72. }
  73. },
  74. onLoad(option){
  75. if(option.type=='select'){this.isSelect = true;}
  76. this.setScrollHeight();
  77. console.log(this.addressList)
  78. },
  79. onReachBottom() {
  80. if(this.isLoadMore) {
  81. this.initAddressList();
  82. }
  83. },
  84. methods: {
  85. setScrollHeight() { // 窗口高度 - 底部距离
  86. setTimeout(()=> {
  87. const query = wx.createSelectorQuery().in(this);
  88. query.selectAll('.add-btn').boundingClientRect();
  89. query.exec(res => {
  90. if(res[0][0]){
  91. let winHeight = this.$api.getWindowHeight(),
  92. eleTop = res[0][0].top - 1;
  93. this.scrollHeight = eleTop;
  94. }
  95. })
  96. }, 500)
  97. },
  98. initAddressList(){
  99. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  100. this.userID = resolve.userID
  101. let params = {pageNum:this.pageNum,pageSize:this.pageSize,userID:this.userID}
  102. this.UserService.QueryAddressList(params).then(response =>{
  103. if(response.data.results == ''){
  104. this.isEmpty = true
  105. }else{
  106. this.isEmpty = false
  107. let results =[];
  108. results = response.data.results;
  109. this.addressList = this.addressList.concat(results);
  110. this.pageNum = response.index +1;
  111. if(this.pageNum === response.totalPage + 1 ){
  112. this.isLoadMore = false;
  113. } else {
  114. this.isLoadMore = true;
  115. }
  116. }
  117. }).catch(error =>{
  118. this.$util.msg(error.msg,2000)
  119. })
  120. })
  121. },
  122. //选择地址
  123. checkAddress(item){
  124. //是否需要返回地址(从订单确认页跳过来选收货地址)
  125. if(!this.isSelect){return ;}
  126. uni.setStorageSync('selectAddress',item)
  127. var pages = getCurrentPages();
  128. var prevPage = pages[pages.length - 2]; //上一个页面
  129. prevPage.setData({select:'select'})
  130. uni.navigateBack();
  131. },
  132. addAddress(type,item){
  133. uni.navigateTo({
  134. url: `/pages/user/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  135. })
  136. },
  137. handleClick(e) {//用户操作订单
  138. let index = e.index;
  139. if(index == 1){
  140. this.UserService.DeleteNewAddress({addressID:id,userID:this.userID}).then(response =>{
  141. this.$util.msg('删除成功',2000,true,'success')
  142. setTimeout(() =>{
  143. this.pageNum = 1;
  144. this.addressList = [];
  145. this.initAddressList();
  146. },2000)
  147. }).catch(error =>{
  148. this.$util.msg(error.msg,2000);
  149. setTimeout(function(){
  150. uni.switchTab({
  151. url:'/seller/pages/home/home'
  152. })
  153. },1000)
  154. })
  155. }
  156. this.modal = false;
  157. },
  158. hideMobel(){
  159. this.modal = false;
  160. },
  161. //删除收货地址
  162. deleteAddress(id){
  163. this.modal = true;
  164. this.contentModalText = '确认删除该地址吗?';
  165. }
  166. },
  167. onShow() {
  168. // this.$api.getStorage().then((resolve) =>{
  169. // this.userID = resolve.userID
  170. // this.pageNum = 1;
  171. // this.addressList = [];
  172. // // this.initAddressList();
  173. // var pages = getCurrentPages();
  174. // var prevPage = pages[pages.length - 2]; //上一个页面
  175. // // prevPage.setData({select:''})
  176. // })
  177. }
  178. }
  179. </script>
  180. <style lang='scss'>
  181. page {
  182. height: auto;
  183. }
  184. page,.container{
  185. /* padding-bottom: 120upx; */
  186. background: #F7F7F7;
  187. border-top: 1px solid #EBEBEB;
  188. }
  189. .container{
  190. position: relative;
  191. }
  192. .list{
  193. display: flex;
  194. align-items: center;
  195. width: 702rpx;
  196. height: auto;
  197. padding: 24rpx;
  198. background: #FFFFFF;
  199. position: relative;
  200. margin-bottom: 20rpx;
  201. }
  202. .wrapper{
  203. display: flex;
  204. flex-direction: column;
  205. flex: 1;
  206. }
  207. .u-box .label{
  208. color: #999999;
  209. }
  210. .u-box.b-b{
  211. margin-bottom:24rpx;
  212. }
  213. .u-box.b-t{
  214. margin-bottom:0;
  215. }
  216. .u-box{
  217. display: flex;
  218. align-items: center;
  219. font-size: $font-size-28;
  220. color: $text-color;
  221. line-height: 40rpx;
  222. margin-bottom: 12rpx;
  223. .name{
  224. margin-right: 40rpx;
  225. font-weight: bold;
  226. }
  227. .mobile{
  228. font-weight: bold;
  229. }
  230. .default-tags{
  231. margin-left: 10rpx;
  232. display: block;
  233. width: 72rpx;
  234. height: 32rpx;
  235. border-radius: 16rpx;
  236. background-color: #fff3e2;
  237. color: #c4761f;
  238. line-height: 32rpx;
  239. text-align: center;
  240. font-size: 22rpx;
  241. }
  242. .tag-left{
  243. flex: 6;
  244. .tag{
  245. width: 280rpx;
  246. height: 40rpx;
  247. font-size: $font-size-26;
  248. color: #999999;
  249. line-height: 40rpx;
  250. .icon-xuanze{
  251. color: #333333;
  252. font-size: 38rpx;
  253. margin-right: 10rpx;
  254. }
  255. .icon-weixuanze{
  256. color: #999999;
  257. font-size: 38rpx;
  258. margin-right: 10rpx;
  259. }
  260. }
  261. }
  262. .tag-right{
  263. flex: 4;
  264. display: flex;
  265. text-align: right;
  266. .t-b{
  267. flex: 1;
  268. line-height: 40rpx;
  269. .txt{
  270. font-size: $font-size-24;
  271. color: $text-color;
  272. line-height: 40rpx;
  273. }
  274. }
  275. .icon-shanchu{
  276. color:#333333 ;
  277. margin-right: 8rpx;
  278. }
  279. .icon-bianji{
  280. color: #333333;
  281. margin-right: 8rpx;
  282. }
  283. }
  284. .address{
  285. font-size: $font-size-28;
  286. color: $text-color;
  287. line-height: 40rpx;
  288. -o-text-overflow: ellipsis;
  289. text-overflow: ellipsis;
  290. display: -webkit-box;
  291. word-break: break-all;
  292. -webkit-box-orient: vertical;
  293. -webkit-line-clamp: 2;
  294. overflow: hidden;
  295. }
  296. }
  297. .add-btn{
  298. position: fixed;
  299. left: 24rpx;
  300. right: 24rpx;
  301. bottom: 34rpx;
  302. z-index: 95;
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. width: 702rpx;
  307. height: 88rpx;
  308. font-size: $font-size-28;
  309. line-height: 88rpx;
  310. color: #FFFFFF;
  311. text-align: center;
  312. background: $btn-confirm;
  313. border-radius: 45rpx;
  314. }
  315. .adds-btn{
  316. width: 702rpx;
  317. height: 88rpx;
  318. font-size: 28rpx;
  319. line-height: 88rpx;
  320. color: #FFFFFF;
  321. margin: 0 auto;
  322. text-align: center;
  323. background: #000000;
  324. border-radius: 14rpx;
  325. }
  326. </style>