address.vue 8.9 KB

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