index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <!-- 地址管理 -->
  3. <view :style="colorStyle">
  4. <view class='address-management' :class='addressList.length < 1 && page > 1 ? "fff":""'>
  5. <!-- <view class='line'>
  6. <image src='../../../static/images/line.jpg' v-if="addressList.length"></image>
  7. </view> -->
  8. <!-- <radio-group class="radio-group" @change="radioChange" v-if="addressList.length"> -->
  9. <!-- <view class='item' v-for="(item,index) in addressList" :key="index"> -->
  10. <view class="swipe-action-wrapper">
  11. <tui-swipe-action v-for="(item, index) in addressList" :key="item.id" :operateWidth="128" class="item">
  12. <template v-slot:content>
  13. <view class="content acea-row row-middle">
  14. <view class="address" @click='goOrder(item.id)'>
  15. <view class="consignee acea-row row-middle">{{item.real_name}}<text class='phone'>{{item.phone}}</text><text v-if="item.is_default" class="badge">默认</text></view>
  16. <view>{{item.province}}{{item.city}}{{item.district}}{{item.street}}{{item.detail}}</view>
  17. </view>
  18. <view class="ml-10" @click="editAddress(item.id)"><text class="iconfont icon-ic_edit"></text></view>
  19. </view>
  20. <!-- <view class='operation acea-row row-between-wrapper'> -->
  21. <!-- #ifndef MP -->
  22. <!-- <radio class="radio" :value="index.toString()" :checked="item.is_default ? true : false">
  23. <text>设为默认</text>
  24. </radio> -->
  25. <!-- #endif -->
  26. <!-- #ifdef MP -->
  27. <!-- <radio class="radio" :value="index" :checked="item.is_default ? true : false">
  28. <text>设为默认</text>
  29. </radio> -->
  30. <!-- #endif -->
  31. <!-- <view class='acea-row row-middle'>
  32. <view @click='editAddress(item.id)'><text class='iconfont icon-bianji'></text>编辑</view>
  33. <view @click='delAddress(index)'><text class='iconfont icon-shanchu'></text>删除</view>
  34. </view> -->
  35. <!-- </view> -->
  36. </template>
  37. <template v-slot:button>
  38. <!-- <view @click='editAddress(item.id)'><text class='iconfont icon-bianji'></text>编辑</view> -->
  39. <view class="button acea-row row-center-wrapper" @click="radioChange(index)">设为默认</view>
  40. <view class="button delete acea-row row-center-wrapper" @click="delAddress(index)">删除</view>
  41. </template>
  42. </tui-swipe-action>
  43. </view>
  44. <!-- </view> -->
  45. <!-- </radio-group> -->
  46. <view class='loadingicon acea-row row-center-wrapper' v-if="addressList.length">
  47. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  48. </view>
  49. <view v-if="!addressList.length">
  50. <emptyPage title="暂无地址信息~" src="/statics/images/noAddress.gif"></emptyPage>
  51. </view>
  52. <view class="height-add"></view>
  53. <view class='footer acea-row row-between-wrapper'>
  54. <view class='addressBnt on' @click='addAddress'>新增收货地址</view>
  55. <view class=""></view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. getAddressList,
  63. setAddressDefault,
  64. delAddress,
  65. editAddress,
  66. postAddress
  67. } from '@/api/user.js';
  68. import {
  69. toLogin
  70. } from '@/libs/login.js';
  71. import {
  72. mapGetters
  73. } from "vuex";
  74. import home from '@/components/home';
  75. import colors from '@/mixins/color.js';
  76. import {HTTP_REQUEST_URL} from '@/config/app';
  77. import tuiSwipeAction from '@/components/tui-swipe-action/index.vue';
  78. import emptyPage from '@/components/emptyPage.vue';
  79. export default {
  80. components: {
  81. tuiSwipeAction,
  82. emptyPage
  83. },
  84. mixins: [colors],
  85. data() {
  86. return {
  87. addressList: [],
  88. cartId: '',
  89. pinkId: 0,
  90. couponId: 0,
  91. loading: false,
  92. loadend: false,
  93. loadTitle: '加载更多',
  94. page: 1,
  95. limit: 20,
  96. isAuto: false, //没有授权的不会自动授权
  97. isShowAuth: false, //是否隐藏授权
  98. news: '',
  99. noCoupon: 0,
  100. imgHost: HTTP_REQUEST_URL,
  101. deliveryType: 1, //配送方式
  102. store_name: '', //门店名称
  103. storeId: 0, //门店id
  104. product_id: 0 //商品id
  105. };
  106. },
  107. computed: mapGetters(['isLogin']),
  108. onLoad(options) {
  109. this.cartId = options.cartId || '';
  110. this.noCoupon = options.noCoupon || 0;
  111. this.pinkId = options.pinkId || 0;
  112. this.couponId = options.couponId || 0;
  113. this.news = options.news || 0;
  114. this.deliveryType = options.delivery_type || 1;
  115. this.store_name = options.store_name;
  116. this.storeId = options.store_id;
  117. this.product_id = options.product_id;
  118. if (this.isLogin) {
  119. this.getAddressList(true);
  120. } else {
  121. toLogin()
  122. }
  123. },
  124. onShow: function() {
  125. uni.removeStorageSync('form_type_cart');
  126. },
  127. methods: {
  128. onLoadFun() {
  129. this.getAddressList(true);
  130. this.isShowAuth = false
  131. },
  132. // 授权关闭
  133. authColse: function(e) {
  134. this.isShowAuth = e
  135. },
  136. /*
  137. * 导入微信地址(小程序)
  138. */
  139. getWxAddress: function() {
  140. let that = this;
  141. uni.authorize({
  142. scope: 'scope.address',
  143. success: function(res) {
  144. uni.chooseAddress({
  145. success: function(res) {
  146. let addressP = {};
  147. addressP.province = res.provinceName;
  148. addressP.city = res.cityName;
  149. addressP.district = res.countyName;
  150. editAddress({
  151. address: addressP,
  152. is_default: 1,
  153. real_name: res.userName,
  154. post_code: res.postalCode,
  155. phone: res.telNumber,
  156. detail: res.detailInfo,
  157. id: 0,
  158. type: 1
  159. }).then(res => {
  160. that.$util.Tips({
  161. title: "添加成功",
  162. icon: 'success'
  163. }, function() {
  164. that.getAddressList(true);
  165. });
  166. }).catch(err => {
  167. return that.$util.Tips({
  168. title: err
  169. });
  170. });
  171. },
  172. fail: function(res) {
  173. if (res.errMsg == 'chooseAddress:cancel') return that.$util
  174. .Tips({
  175. title: '取消选择'
  176. });
  177. },
  178. })
  179. },
  180. fail: function(res) {
  181. uni.showModal({
  182. title: '您已拒绝导入微信地址权限',
  183. content: '是否进入权限管理,调整授权?',
  184. success(res) {
  185. if (res.confirm) {
  186. uni.openSetting({
  187. success: function(res) {}
  188. });
  189. } else if (res.cancel) {
  190. return that.$util.Tips({
  191. title: '已取消!'
  192. });
  193. }
  194. }
  195. })
  196. }
  197. })
  198. },
  199. /*
  200. * 导入微信地址(公众号)
  201. */
  202. getAddress() {
  203. let that = this;
  204. that.$wechat.openAddress().then(userInfo => {
  205. // open();
  206. editAddress({
  207. real_name: userInfo.userName,
  208. phone: userInfo.telNumber,
  209. address: {
  210. province: userInfo.provinceName,
  211. city: userInfo.cityName,
  212. district: userInfo.countryName
  213. },
  214. detail: userInfo.detailInfo,
  215. post_code: userInfo.postalCode,
  216. is_default: 1,
  217. type: 1
  218. })
  219. .then(() => {
  220. that.$util.Tips({
  221. title: "添加成功",
  222. icon: 'success'
  223. }, function() {
  224. // close();
  225. that.getAddressList(true);
  226. });
  227. })
  228. .catch(err => {
  229. // close();
  230. return that.$util.Tips({
  231. title: err || "添加失败"
  232. });
  233. });
  234. });
  235. },
  236. /**
  237. * 获取地址列表
  238. *
  239. */
  240. getAddressList: function(isPage) {
  241. let that = this;
  242. if (isPage) {
  243. that.loadend = false;
  244. that.page = 1;
  245. that.$set(that, 'addressList', []);
  246. };
  247. if (that.loading) return;
  248. if (that.loadend) return;
  249. that.loading = true;
  250. that.loadTitle = '';
  251. getAddressList({
  252. page: that.page,
  253. limit: that.limit
  254. }).then(res => {
  255. let list = res.data;
  256. let loadend = list.length < that.limit;
  257. that.addressList = that.$util.SplitArray(list, that.addressList);
  258. that.$set(that, 'addressList', that.addressList);
  259. that.loadend = loadend;
  260. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  261. that.page = that.page + 1;
  262. that.loading = false;
  263. }).catch(err => {
  264. that.loading = false;
  265. that.loadTitle = '加载更多';
  266. });
  267. },
  268. /**
  269. * 设置默认地址
  270. */
  271. radioChange: function(index) {
  272. let that = this;
  273. let address = this.addressList[index];
  274. if (address == undefined) return that.$util.Tips({
  275. title: '您设置的默认地址不存在!'
  276. });
  277. setAddressDefault(address.id).then(res => {
  278. for (let i = 0, len = that.addressList.length; i < len; i++) {
  279. if (i == index) that.addressList[i].is_default = true;
  280. else that.addressList[i].is_default = false;
  281. }
  282. that.$util.Tips({
  283. title: '设置成功',
  284. icon: 'success'
  285. }, function() {
  286. that.$set(that, 'addressList', that.addressList);
  287. });
  288. }).catch(err => {
  289. return that.$util.Tips({
  290. title: err
  291. });
  292. });
  293. },
  294. /**
  295. * 编辑地址
  296. */
  297. editAddress: function(id) {
  298. let cartId = this.cartId,
  299. pinkId = this.pinkId,
  300. couponId = this.couponId;
  301. this.cartId = '';
  302. this.pinkId = '';
  303. this.couponId = '';
  304. uni.navigateTo({
  305. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' +
  306. pinkId + '&couponId=' +
  307. couponId + '&new=' + this.news + '&delivery_type=' + this.deliveryType + '&store_id=' + this.storeId + '&store_name=' + this.store_name + '&product_id=' + this
  308. .product_id
  309. })
  310. },
  311. /**
  312. * 删除地址
  313. */
  314. delAddress: function(index) {
  315. let that = this,
  316. address = this.addressList[index];
  317. if (address == undefined) return that.$util.Tips({
  318. title: '您删除的地址不存在!'
  319. });
  320. delAddress(address.id).then(res => {
  321. that.$util.Tips({
  322. title: '删除成功',
  323. icon: 'success'
  324. }, function() {
  325. that.addressList.splice(index, 1);
  326. that.$set(that, 'addressList', that.addressList);
  327. });
  328. }).catch(err => {
  329. return that.$util.Tips({
  330. title: err
  331. });
  332. });
  333. },
  334. /**
  335. * 新增地址
  336. */
  337. addAddress: function() {
  338. let cartId = this.cartId,
  339. pinkId = this.pinkId,
  340. couponId = this.couponId;
  341. this.cartId = '';
  342. this.pinkId = '';
  343. this.couponId = '';
  344. uni.navigateTo({
  345. url: '/pages/users/user_address/index?cartId=' + cartId + '&pinkId=' + pinkId +
  346. '&couponId=' + couponId + '&new=' + this.news + '&delivery_type=' + this.deliveryType + '&store_id=' + this.storeId + '&store_name=' + this.store_name +
  347. '&product_id=' + this.product_id
  348. })
  349. },
  350. goOrder: function(id) {
  351. let cartId = '';
  352. let pinkId = '';
  353. let couponId = '';
  354. if (this.cartId && id) {
  355. cartId = this.cartId;
  356. pinkId = this.pinkId;
  357. couponId = this.couponId;
  358. this.cartId = '';
  359. this.pinkId = '';
  360. this.couponId = '';
  361. uni.redirectTo({
  362. url: '/pages/goods/order_confirm/index?is_address=1&new=' + this.news + '&cartId=' +
  363. cartId + '&addressId=' + id + '&pinkId=' +
  364. pinkId + '&couponId=' + couponId +
  365. '&noCoupon=' + this.noCoupon + '&delivery_type=' + this.deliveryType + '&store_id=' + this.storeId + '&store_name=' + this.store_name + '&product_id=' + this
  366. .product_id
  367. })
  368. }
  369. }
  370. },
  371. onReachBottom: function() {
  372. this.getAddressList();
  373. }
  374. }
  375. </script>
  376. <style lang="scss" scoped>
  377. .height-add {
  378. height: 120rpx;
  379. }
  380. .noCommodity {
  381. height: calc(100vh - 123rpx);
  382. background-color: #fff;
  383. }
  384. .address-management {
  385. padding: 24rpx 20rpx;
  386. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  387. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  388. }
  389. .address-management.fff {
  390. background-color: #fff;
  391. height: 1300rpx
  392. }
  393. .address-management .wechat {
  394. height: 100rpx;
  395. padding: 0 32rpx;
  396. border-radius: 24rpx;
  397. background-color: #FFFFFF;
  398. font-weight: 500;
  399. font-size: 30rpx;
  400. color: #3D3D3D;
  401. }
  402. .address-management .line {
  403. width: 100%;
  404. height: 3rpx;
  405. }
  406. .address-management .line image {
  407. width: 100%;
  408. height: 100%;
  409. display: block;
  410. }
  411. .address-management .item::before {
  412. content: "";
  413. position: absolute;
  414. top: 0;
  415. right: 24rpx;
  416. left: 24rpx;
  417. height: 1rpx;
  418. background-color: #F5F5F5;
  419. }
  420. .address-management .item:first-child::before {
  421. display: none;
  422. }
  423. .address-management .item .content {
  424. padding: 32rpx 32rpx 24rpx;
  425. }
  426. .address-management .item .address {
  427. flex: 1;
  428. min-width: 0;
  429. white-space: normal;
  430. font-size: 24rpx;
  431. line-height: 34rpx;
  432. color: #999999;
  433. }
  434. .address-management .item .address .consignee {
  435. font-size: 30rpx;
  436. line-height: 42rpx;
  437. font-weight: bold;
  438. margin-bottom: 12rpx;
  439. color: #333333;
  440. }
  441. .address-management .item .address .consignee .phone {
  442. font-weight: normal;
  443. margin-left: 22rpx;
  444. }
  445. .address-management .item .address .consignee .badge {
  446. height: 34rpx;
  447. padding: 0 8rpx;
  448. border-radius: 8rpx;
  449. margin-left: 20rpx;
  450. background-color: var(--view-minorColorT);
  451. font-weight: normal;
  452. font-size: 22rpx;
  453. line-height: 34rpx;
  454. color: var(--view-theme);
  455. }
  456. .address-management .item .operation {
  457. height: 83rpx;
  458. font-size: 28rpx;
  459. color: #282828;
  460. }
  461. .address-management .item .operation .radio text {
  462. margin-left: 13rpx;
  463. }
  464. .address-management .item .iconfont {
  465. font-size: 32rpx;
  466. color: #333333;
  467. }
  468. .address-management .item .button {
  469. position: absolute;
  470. top: 0;
  471. left: 0;
  472. bottom: 0;
  473. display: inline-flex;
  474. width: 64px;
  475. // height: 100%;
  476. background: var(--view-bntColor);
  477. font-size: 24rpx;
  478. color: #fff;
  479. }
  480. .address-management .item .delete {
  481. left: 64px;
  482. background-color: var(--view-theme);
  483. color: #FFFFFF;
  484. }
  485. .address-management .footer {
  486. position: fixed;
  487. width: 100%;
  488. bottom: 0;
  489. left: 0;
  490. height: 120rpx;
  491. padding: 0 20rpx;
  492. box-sizing: border-box;
  493. height: calc(106rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  494. height: calc(106rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  495. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  496. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  497. }
  498. .address-management .footer .addressBnt {
  499. width: 330rpx;
  500. height: 80rpx;
  501. border-radius: 40rpx;
  502. text-align: center;
  503. line-height: 80rpx;
  504. font-weight: 500;
  505. font-size: 28rpx;
  506. color: #fff;
  507. background-color: var(--view-theme);
  508. }
  509. .address-management .footer .addressBnt.on {
  510. width: 710rpx;
  511. margin: 0 auto;
  512. }
  513. .address-management .footer .addressBnt .iconfont {
  514. font-size: 35rpx;
  515. margin-right: 8rpx;
  516. vertical-align: -1rpx;
  517. }
  518. .address-management .footer .addressBnt.wxbnt {
  519. background-color: #FE960F;
  520. }
  521. .wechat+.swipe-action-wrapper {
  522. margin-top: 20rpx;
  523. }
  524. .swipe-action-wrapper {
  525. border-radius: 24rpx;
  526. background-color: #FFFFFF;
  527. overflow: hidden;
  528. }
  529. </style>