index.vue 13 KB

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