address.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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.stop="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. console.log(option && option)
  107. this.setScrollHeight()
  108. // console.log(this.addressList)
  109. // this.initAddressList()
  110. },
  111. onShow() {
  112. this.pageNum = 1
  113. this.addressList = []
  114. this.initAddressList()
  115. }
  116. ,
  117. onReachBottom() {
  118. if (this.isLoadMore) {
  119. this.initAddressList()
  120. }
  121. },
  122. methods: {
  123. setScrollHeight() {
  124. // 窗口高度 - 底部距离
  125. setTimeout(() => {
  126. const query = wx.createSelectorQuery().in(this)
  127. query.selectAll('.add-btn').boundingClientRect()
  128. query.exec(res => {
  129. if (res[0][0]) {
  130. let winHeight = this.$api.getWindowHeight(),
  131. eleTop = res[0][0].top - 1
  132. this.scrollHeight = eleTop
  133. }
  134. })
  135. }, 500)
  136. },
  137. // 初始化地址列表
  138. initAddressList() {
  139. this.$api.getComStorage('clubInfo').then(resolve => {
  140. // this.userId = resolve.userId
  141. // 设置默认地址 测试使用
  142. // const clubInfo = uni.getStorageSync('clubInfo')
  143. this.userId = resolve.userId
  144. // this.userId = '13914'
  145. // console.log(this.userId)
  146. let params = { pageNum: this.pageNum, pageSize: this.pageSize, userId: this.userId }
  147. this.UserService.QueryAddressList(params)
  148. .then(response => {
  149. if (response.data.list == '') {
  150. this.isEmpty = true
  151. } else {
  152. this.isEmpty = false
  153. let results = []
  154. results = response.data.list
  155. this.addressList = this.addressList.concat(results)
  156. this.pageNum = response.data.pageNum + 1
  157. if (response.data.hasNextPage) {
  158. this.isLoadMore = false
  159. } else {
  160. this.isLoadMore = true
  161. }
  162. }
  163. })
  164. .catch(error => {
  165. this.$util.msg(error.msg, 2000)
  166. })
  167. })
  168. },
  169. //选择地址
  170. checkAddress(item) {
  171. //是否需要返回地址(从订单确认页跳过来选收货地址)
  172. if (!this.isSelect) {
  173. return
  174. }
  175. uni.setStorageSync('selectAddress', item)
  176. var pages = getCurrentPages()
  177. var prevPage = pages[pages.length - 2] //上一个页面
  178. prevPage.setData({ select: 'select' })
  179. uni.navigateBack()
  180. },
  181. // 跳转添加地址页面 type:添加或修改
  182. addAddress(type, item) {
  183. uni.navigateTo({
  184. url: `/pages/user/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  185. })
  186. },
  187. handleClick(e) {
  188. //用户操作订单
  189. let index = e.index
  190. if (index == 1) {
  191. this.UserService.DeleteNewAddress({
  192. addressId: this.deleteaddressId,
  193. userId: this.userId
  194. })
  195. .then(response => {
  196. this.$util.msg('删除成功', 2000, true, 'success')
  197. setTimeout(() => {
  198. this.pageNum = 1
  199. this.addressList = []
  200. this.initAddressList()
  201. }, 2000)
  202. })
  203. .catch(error => {
  204. this.$util.msg(error.msg, 2000)
  205. setTimeout(function() {
  206. uni.switchTab({
  207. url: '/seller/pages/home/home'
  208. })
  209. }, 1000)
  210. })
  211. }
  212. this.modal = false
  213. },
  214. hideMobel() {
  215. this.modal = false
  216. },
  217. //删除收货地址
  218. deleteAddress(id) {
  219. this.modal = true
  220. this.contentModalText = '确认删除该地址吗?'
  221. this.deleteaddressId = id
  222. },
  223. // 修改默认地址
  224. setDefaultAddress(id) {
  225. this.UserService.DefaultAddress({
  226. addressId: id,
  227. userId: this.userId
  228. })
  229. .then(res => {
  230. if (res.code === 0) {
  231. this.pageNum = 1
  232. this.addressList = []
  233. this.initAddressList()
  234. }
  235. })
  236. .catch(err => {
  237. this.pageNum = 1
  238. this.addressList = []
  239. this.initAddressList()
  240. })
  241. }
  242. }
  243. }
  244. </script>
  245. <style lang="scss">
  246. page {
  247. height: auto;
  248. }
  249. page,
  250. .container {
  251. /* padding-bottom: 120upx; */
  252. background: #f7f7f7;
  253. border-top: 1px solid #ebebeb;
  254. }
  255. .container {
  256. position: relative;
  257. }
  258. .list {
  259. display: flex;
  260. align-items: center;
  261. width: 702rpx;
  262. height: auto;
  263. padding: 24rpx;
  264. background: #ffffff;
  265. position: relative;
  266. margin-bottom: 20rpx;
  267. }
  268. .wrapper {
  269. display: flex;
  270. flex-direction: column;
  271. flex: 1;
  272. }
  273. .u-box .label {
  274. color: #999999;
  275. }
  276. .u-box.b-b {
  277. margin-bottom: 24rpx;
  278. }
  279. .u-box.b-t {
  280. margin-bottom: 0;
  281. }
  282. .u-box {
  283. display: flex;
  284. align-items: center;
  285. font-size: $font-size-26;
  286. color: $text-color;
  287. line-height: 40rpx;
  288. margin-bottom: 12rpx;
  289. .name {
  290. margin-right: 40rpx;
  291. font-weight: bold;
  292. }
  293. .mobile {
  294. font-weight: bold;
  295. }
  296. .default-tags {
  297. margin-left: 15rpx;
  298. display: block;
  299. width: 72rpx;
  300. height: 32rpx;
  301. border-radius: 16rpx;
  302. background-color: #fff3e2;
  303. color: #c4761f;
  304. line-height: 32rpx;
  305. text-align: center;
  306. font-size: 22rpx;
  307. }
  308. .tag-left {
  309. flex: 6;
  310. .tag {
  311. width: 280rpx;
  312. height: 40rpx;
  313. font-size: $font-size-26;
  314. color: #999999;
  315. line-height: 40rpx;
  316. .icon-xuanze {
  317. color: #333333;
  318. font-size: 38rpx;
  319. margin-right: 10rpx;
  320. }
  321. .icon-weixuanze {
  322. color: #999999;
  323. font-size: 38rpx;
  324. margin-right: 10rpx;
  325. }
  326. }
  327. }
  328. .tag-right {
  329. flex: 4;
  330. display: flex;
  331. text-align: right;
  332. .t-b {
  333. flex: 1;
  334. line-height: 40rpx;
  335. .txt {
  336. font-size: $font-size-24;
  337. color: $text-color;
  338. line-height: 40rpx;
  339. }
  340. }
  341. .icon-shanchu {
  342. color: #333333;
  343. margin-right: 8rpx;
  344. }
  345. .icon-bianji {
  346. color: #333333;
  347. margin-right: 8rpx;
  348. }
  349. }
  350. .address {
  351. font-size: $font-size-28;
  352. color: $text-color;
  353. line-height: 40rpx;
  354. -o-text-overflow: ellipsis;
  355. text-overflow: ellipsis;
  356. display: -webkit-box;
  357. word-break: break-all;
  358. -webkit-box-orient: vertical;
  359. -webkit-line-clamp: 2;
  360. overflow: hidden;
  361. }
  362. }
  363. .add-btn {
  364. position: fixed;
  365. left: 24rpx;
  366. right: 24rpx;
  367. bottom: 34rpx;
  368. z-index: 95;
  369. display: flex;
  370. align-items: center;
  371. justify-content: center;
  372. width: 702rpx;
  373. height: 88rpx;
  374. font-size: $font-size-28;
  375. line-height: 88rpx;
  376. color: #ffffff;
  377. text-align: center;
  378. background: $btn-confirm;
  379. border-radius: 45rpx;
  380. }
  381. .adds-btn {
  382. width: 702rpx;
  383. height: 88rpx;
  384. font-size: 28rpx;
  385. line-height: 88rpx;
  386. color: #ffffff;
  387. margin: 0 auto;
  388. text-align: center;
  389. background: #000000;
  390. border-radius: 14rpx;
  391. }
  392. </style>