address.vue 8.9 KB

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