index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <view class="wrap">
  5. <view class="address_list">
  6. <view class="address_item" v-for="(item, index) in dataList" :key="index">
  7. <view class="item_t">
  8. <view class="item_l" @tap="selecteAddress" :data-item="item">
  9. <view class="item_l_t">
  10. <text class="item_tag" v-if="item.is_default">默认</text>
  11. <text class="item_title">{{ item.area_address + item.address }}</text>
  12. </view>
  13. <view class="item_l_b">
  14. <text class="user_name">{{ item.name }}</text>
  15. <text class="user_phone">{{ item.phone }}</text>
  16. </view>
  17. </view>
  18. <view class="item_r">
  19. <image src="/static/statics/img/icon_edit.png" class="edit_icon" @tap="goAddressDetail" :data-item="item"></image>
  20. </view>
  21. </view>
  22. <!-- style="{{ item.is_default ? 'justify-content: space-between' : 'justify-content: flex-end' }}" -->
  23. <view class="item_b" style="justify-content: flex-end">
  24. <!-- <van-checkbox value="{{ item.is_default ? true : false}}" wx:if="{{ item.is_default }}" checked-color="#FFD102" bind:tap="goAddressDetail" data-item="{{ item }}">默认地址</van-checkbox> -->
  25. <view @tap="doDeleteAddress" :data-id="item.id">删除</view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="btn_wrap">
  30. <view class="btn wechat" @tap="getAddressFromWechat">
  31. <van-icon name="wechat" size="26" color="#FFFFFF" />
  32. <view class="wenzi">微信导入</view>
  33. </view>
  34. <view class="btn" @tap="goAddressDetail">
  35. <van-icon name="plus" size="20" color="#333333" />
  36. <view class="wenzi">添加地址</view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 确认地址 -->
  41. <van-overlay :z-index="1" class-style="background: rgba(0,0,0,.3);" :show="showConfirmAdd">
  42. <view class="add_pop">
  43. <view class="add_pop_t">请确定您的收货信息</view>
  44. <view class="add_pop_nr">
  45. <view class="add_wenzi">{{ checkedAddress.area_address + checkedAddress.address }}</view>
  46. <view class="add_wenzi grey">{{ checkedAddress.name + ' ' + checkedAddress.phone }}</view>
  47. </view>
  48. <view class="add_btns">
  49. <view class="btn cancel" @tap="cancelCheck">更换地址</view>
  50. <view class="btn" @tap="confirmCheck">确认无误</view>
  51. </view>
  52. </view>
  53. </van-overlay>
  54. <!-- 确认删除 -->
  55. <van-dialog class="custom_dialog" title="确定要删除该地址吗?" :show="showDelDialog" showCancelButton @cancel="onCloseDel" @confirm="onConfirmDel"></van-dialog>
  56. <!-- loading -->
  57. <!-- <van-overlay show="{{ loading }}" z-index="100">
  58. <van-loading custom-class="custom_loading" />
  59. </van-overlay> -->
  60. </view>
  61. </template>
  62. <script>
  63. // index.js
  64. let myPro = require('../../../../utils/wxRequest.js');
  65. let util = require('../../../../utils/util.js');
  66. export default {
  67. data() {
  68. return {
  69. showConfirmAdd: false,
  70. // 确认地址弹层
  71. page: 1,
  72. size: 10,
  73. dataList: [],
  74. finished: false,
  75. // 加载完毕
  76. loading: false,
  77. // 全局loading
  78. checkedAddress: null,
  79. // 选中地址
  80. showDelDialog: false,
  81. // 删除确认框
  82. // 当用户主动切换地址时,支持回退
  83. is_back: null,
  84. id: ''
  85. };
  86. },
  87. onLoad: function (options) {
  88. // Do some initialize when page load.
  89. let that = this; // 路由回退标识
  90. if (options.is_back) {
  91. that.setData({
  92. is_back: options.is_back
  93. });
  94. }
  95. },
  96. onShow: function () {
  97. // Do something when page show.
  98. let that = this;
  99. that.setData({
  100. page: 1,
  101. size: 10,
  102. dataList: [],
  103. finished: false
  104. });
  105. that.getData();
  106. },
  107. onReady: function () {
  108. // Do something when page ready.
  109. },
  110. onHide: function () {
  111. // Do something when page hide.
  112. },
  113. onUnload: function () {
  114. // Do something when page close.
  115. },
  116. onPullDownRefresh: function () {
  117. // Do something when pull down.
  118. },
  119. onReachBottom: function () {
  120. // Do something when page reach bottom.
  121. let that = this;
  122. if (!that.finished) {
  123. that.getData();
  124. }
  125. },
  126. onPageScroll: function () {
  127. // Do something when page scroll
  128. },
  129. onResize: function () {
  130. // Do something when page resize
  131. },
  132. methods: {
  133. // 获取地址列表
  134. getData() {
  135. let that = this;
  136. let params = {
  137. page: that.page,
  138. size: that.size
  139. };
  140. myPro
  141. .wxRequest('user/address/list', 'GET', params)
  142. .then((res) => {
  143. let list = res.result; // 无数据
  144. if (list.length == 0) {
  145. uni.showToast({
  146. title: '暂无更多数据',
  147. icon: 'none'
  148. });
  149. that.setData({
  150. finished: true
  151. });
  152. } else {
  153. // 有数据
  154. that.setData({
  155. dataList: that.dataList.concat(list),
  156. page: that.page + 1
  157. });
  158. }
  159. })
  160. .catch((err) => {
  161. console.log('报错信息', err);
  162. uni.showToast({
  163. title: err,
  164. icon: 'none'
  165. });
  166. });
  167. },
  168. // 去详情
  169. goAddressDetail(event) {
  170. let that = this;
  171. let url = '';
  172. if (event.currentTarget.dataset.item) {
  173. let item = event.currentTarget.dataset.item;
  174. url = '/pages/user/address/detail/index?id=' + item.id;
  175. } else {
  176. url = '/pages/user/address/detail/index';
  177. }
  178. uni.navigateTo({
  179. url: url
  180. });
  181. },
  182. // 获取微信地址
  183. getAddressFromWechat() {
  184. let that = this;
  185. uni.chooseAddress({
  186. success: function (res) {
  187. console.log('获取成功', res);
  188. let obj = {
  189. name: res.userName,
  190. phone: res.telNumber,
  191. area: res.provinceName + res.cityName + res.countyName,
  192. address: res.detailInfo
  193. }; // 让用户主动选一遍位置
  194. uni.navigateTo({
  195. url: '/pages/user/address/detail/index?type=wechat'
  196. }); // 存一下
  197. uni.setStorage({
  198. key: 'wechatAddress',
  199. data: JSON.stringify(obj)
  200. });
  201. },
  202. fail: function (res) {
  203. console.log('获取失败', res);
  204. }
  205. });
  206. },
  207. // 选择地址
  208. selecteAddress(event) {
  209. let that = this; // 先把上一次的值置空(避免出问题)
  210. that.setData({
  211. checkedAddress: null
  212. }); // 重新赋值
  213. let checkedAddress = event.currentTarget.dataset.item;
  214. that.setData({
  215. showConfirmAdd: true,
  216. checkedAddress: checkedAddress
  217. });
  218. },
  219. // 更换地址
  220. cancelCheck() {
  221. let that = this;
  222. that.setData({
  223. showConfirmAdd: false
  224. });
  225. },
  226. // 确认地址
  227. confirmCheck() {
  228. let that = this;
  229. that.setData({
  230. showConfirmAdd: false
  231. }); // 拿地址,匹配下门店,如果未返回,就是超距离了
  232. let params = {
  233. lat: that.checkedAddress.lat,
  234. lng: that.checkedAddress.lnt,
  235. page: 1,
  236. size: 10
  237. };
  238. myPro
  239. .wxRequest('user/store/list', 'GET', params)
  240. .then((res) => {
  241. let storeList = res.result;
  242. if (storeList.length != 0) {
  243. uni.setStorage({
  244. key: 'checkedAddress',
  245. data: JSON.stringify(that.checkedAddress),
  246. success: function () {
  247. if (that.is_back) {
  248. uni.navigateBack();
  249. } else {
  250. // 去购商品
  251. uni.redirectTo({
  252. url: '/pages/goods/index'
  253. });
  254. }
  255. }
  256. });
  257. } else {
  258. // 超配送距离
  259. uni.showToast({
  260. title: '门店尚未营业',
  261. // 单店改为门店尚未营业 多店已超配送距离,请更换地址
  262. icon: 'none'
  263. });
  264. }
  265. })
  266. .catch((err) => {
  267. console.log('报错信息', err);
  268. uni.showToast({
  269. title: err,
  270. icon: 'none'
  271. });
  272. });
  273. },
  274. // 打开删除确认框
  275. doDeleteAddress(event) {
  276. let that = this;
  277. that.setData({
  278. id: event.currentTarget.dataset.id,
  279. showDelDialog: true
  280. });
  281. },
  282. // 取消删除地址
  283. onCloseDel() {
  284. let that = this;
  285. that.setData({
  286. showDelDialog: false
  287. });
  288. },
  289. // 确认删除
  290. onConfirmDel: function () {
  291. let that = this;
  292. let params = {
  293. id: that.id
  294. };
  295. myPro
  296. .wxRequest('user/address/remove', 'POST', params)
  297. .then((res) => {
  298. uni.showToast({
  299. title: res.msg,
  300. icon: 'none'
  301. });
  302. that.setData({
  303. showDelDialog: false,
  304. page: 1,
  305. dataList: [],
  306. finished: false
  307. });
  308. that.getData();
  309. })
  310. .catch((err) => {
  311. that.setData({
  312. showDelDialog: false
  313. });
  314. console.log('报错信息', err);
  315. uni.showToast({
  316. title: err,
  317. icon: 'none'
  318. });
  319. });
  320. }
  321. }
  322. };
  323. </script>
  324. <style>
  325. /**index.wxss**/
  326. .wrap {
  327. min-height: 100vh;
  328. background: #f6f6f6;
  329. }
  330. .address_list {
  331. padding: 30rpx 0 160rpx;
  332. }
  333. .address_item {
  334. margin-top: 30rpx;
  335. padding: 30rpx;
  336. background: #ffffff;
  337. }
  338. .address_item:first-child {
  339. margin-top: 0;
  340. }
  341. .address_item .item_t {
  342. display: flex;
  343. align-items: center;
  344. justify-content: space-between;
  345. }
  346. .address_item .item_l {
  347. /* width: 465rpx; */
  348. flex: 1;
  349. padding-right: 20rpx;
  350. }
  351. .address_item .item_tag {
  352. font-size: 24rpx;
  353. color: #ffffff;
  354. padding: 6rpx 8rpx;
  355. background: #295c56;
  356. border-radius: 5rpx;
  357. margin-right: 20rpx;
  358. }
  359. .address_item .item_title {
  360. font-size: 28rpx;
  361. color: #0c0c0c;
  362. line-height: 40rpx;
  363. }
  364. .address_item .item_l_b {
  365. margin-top: 20rpx;
  366. font-size: 26rpx;
  367. color: rgba(12, 12, 12, 0.54);
  368. }
  369. .address_item .user_phone {
  370. padding-left: 10rpx;
  371. }
  372. .address_item .edit_icon {
  373. width: 35rpx;
  374. height: 35rpx;
  375. }
  376. .address_item .item_b {
  377. display: flex;
  378. align-items: center;
  379. justify-content: space-between;
  380. font-size: 26rpx;
  381. color: rgba(12, 12, 12, 0.54);
  382. margin-top: 20rpx;
  383. border-top: 1px solid rgba(35, 36, 40, 0.12);
  384. padding-top: 20rpx;
  385. }
  386. /* 底部按钮 */
  387. .btn_wrap {
  388. width: 100%;
  389. position: fixed;
  390. bottom: 60rpx;
  391. left: 0;
  392. display: flex;
  393. align-items: center;
  394. justify-content: space-around;
  395. }
  396. .btn_wrap .btn {
  397. width: 322rpx;
  398. height: 98rpx;
  399. background: #ffffff;
  400. border: 1px solid #e0e0e0;
  401. border-radius: 10rpx;
  402. display: flex;
  403. align-items: center;
  404. justify-content: center;
  405. font-size: 28rpx;
  406. color: #333333;
  407. }
  408. .btn_wrap .btn .wenzi {
  409. padding-left: 18rpx;
  410. }
  411. .btn_wrap .btn.wechat {
  412. background: #295c56;
  413. border: 0 none;
  414. color: #ffffff;
  415. }
  416. /* 确认地址 */
  417. .add_pop {
  418. width: 650rpx;
  419. background: #ffffff;
  420. border-radius: 10rpx;
  421. padding: 50rpx 40rpx;
  422. position: fixed;
  423. top: 50%;
  424. left: 50%;
  425. transform: translate(-50%, -50%);
  426. }
  427. .add_pop .pop_tu {
  428. width: 137rpx;
  429. height: 186rpx;
  430. position: absolute;
  431. top: -166rpx;
  432. right: 20rpx;
  433. }
  434. .add_pop .add_pop_t {
  435. font-size: 30rpx;
  436. font-weight: 500;
  437. color: #000000;
  438. text-align: center;
  439. }
  440. .add_pop .add_pop_nr {
  441. margin-top: 30rpx;
  442. width: 570rpx;
  443. background: #f6f6f6;
  444. border-radius: 10rpx;
  445. padding: 30rpx;
  446. font-size: 30rpx;
  447. color: #000000;
  448. }
  449. .add_pop .add_wenzi.grey {
  450. padding-top: 24rpx;
  451. font-size: 28rpx;
  452. color: rgba(0, 0, 0, 0.87);
  453. }
  454. .add_pop .add_btns {
  455. margin-top: 40rpx;
  456. display: flex;
  457. align-items: center;
  458. justify-content: space-between;
  459. }
  460. .add_pop .add_btns .btn {
  461. width: 270rpx;
  462. height: 72rpx;
  463. background: #295c56;
  464. border-radius: 10rpx;
  465. font-size: 30rpx;
  466. font-weight: 500;
  467. color: #ffffff;
  468. display: flex;
  469. align-items: center;
  470. justify-content: center;
  471. }
  472. .add_pop .add_btns .btn.cancel {
  473. background: #eeecef;
  474. color: #333333;
  475. }
  476. </style>