index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. toLogin();
  114. }
  115. },
  116. onShow: function() {
  117. uni.removeStorageSync('form_type_cart');
  118. },
  119. methods: {
  120. onLoadFun(){
  121. this.getAddressList(true);
  122. this.isShowAuth = false
  123. },
  124. // 授权关闭
  125. authColse: function(e) {
  126. this.isShowAuth = e
  127. },
  128. /*
  129. * 导入微信地址(小程序)
  130. */
  131. getWxAddress: function() {
  132. let that = this;
  133. uni.authorize({
  134. scope: 'scope.address',
  135. success: function(res) {
  136. uni.chooseAddress({
  137. success: function(res) {
  138. let addressP = {};
  139. addressP.province = res.provinceName;
  140. addressP.city = res.cityName;
  141. addressP.district = res.countyName;
  142. editAddress({
  143. address: addressP,
  144. is_default: 1,
  145. real_name: res.userName,
  146. post_code: res.postalCode,
  147. phone: res.telNumber,
  148. detail: res.detailInfo,
  149. id: 0,
  150. type: 1
  151. }).then(res => {
  152. that.$util.Tips({
  153. title: "添加成功",
  154. icon: 'success'
  155. }, function() {
  156. that.getAddressList(true);
  157. });
  158. }).catch(err => {
  159. return that.$util.Tips({
  160. title: err
  161. });
  162. });
  163. },
  164. fail: function(res) {
  165. if (res.errMsg == 'chooseAddress:cancel') return that.$util
  166. .Tips({
  167. title: '取消选择'
  168. });
  169. },
  170. })
  171. },
  172. fail: function(res) {
  173. uni.showModal({
  174. title: '您已拒绝导入微信地址权限',
  175. content: '是否进入权限管理,调整授权?',
  176. success(res) {
  177. if (res.confirm) {
  178. uni.openSetting({
  179. success: function(res) {}
  180. });
  181. } else if (res.cancel) {
  182. return that.$util.Tips({
  183. title: '已取消!'
  184. });
  185. }
  186. }
  187. })
  188. }
  189. })
  190. },
  191. /*
  192. * 导入微信地址(公众号)
  193. */
  194. getAddress() {
  195. let that = this;
  196. that.$wechat.openAddress().then(userInfo => {
  197. // open();
  198. editAddress({
  199. real_name: userInfo.userName,
  200. phone: userInfo.telNumber,
  201. address: {
  202. province: userInfo.provinceName,
  203. city: userInfo.cityName,
  204. district: userInfo.countryName
  205. },
  206. detail: userInfo.detailInfo,
  207. post_code: userInfo.postalCode,
  208. is_default: 1,
  209. type: 1
  210. })
  211. .then(() => {
  212. that.$util.Tips({
  213. title: "添加成功",
  214. icon: 'success'
  215. }, function() {
  216. // close();
  217. that.getAddressList(true);
  218. });
  219. })
  220. .catch(err => {
  221. // close();
  222. return that.$util.Tips({
  223. title: err || "添加失败"
  224. });
  225. });
  226. });
  227. },
  228. /**
  229. * 获取地址列表
  230. *
  231. */
  232. getAddressList: function(isPage) {
  233. let that = this;
  234. if (isPage) {
  235. that.loadend = false;
  236. that.page = 1;
  237. that.$set(that, 'addressList', []);
  238. };
  239. if (that.loading) return;
  240. if (that.loadend) return;
  241. that.loading = true;
  242. that.loadTitle = '';
  243. getAddressList({
  244. page: that.page,
  245. limit: that.limit
  246. }).then(res => {
  247. let list = res.data;
  248. let loadend = list.length < that.limit;
  249. that.addressList = that.$util.SplitArray(list, that.addressList);
  250. that.$set(that, 'addressList', that.addressList);
  251. that.loadend = loadend;
  252. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  253. that.page = that.page + 1;
  254. that.loading = false;
  255. }).catch(err => {
  256. that.loading = false;
  257. that.loadTitle = '加载更多';
  258. });
  259. },
  260. /**
  261. * 设置默认地址
  262. */
  263. radioChange: function(e) {
  264. let index = parseInt(e.detail.value),
  265. that = this;
  266. let address = this.addressList[index];
  267. if (address == undefined) return that.$util.Tips({
  268. title: '您设置的默认地址不存在!'
  269. });
  270. setAddressDefault(address.id).then(res => {
  271. for (let i = 0, len = that.addressList.length; i < len; i++) {
  272. if (i == index) that.addressList[i].is_default = true;
  273. else that.addressList[i].is_default = false;
  274. }
  275. that.$util.Tips({
  276. title: '设置成功',
  277. icon: 'success'
  278. }, function() {
  279. that.$set(that, 'addressList', that.addressList);
  280. });
  281. }).catch(err => {
  282. return that.$util.Tips({
  283. title: err
  284. });
  285. });
  286. },
  287. /**
  288. * 编辑地址
  289. */
  290. editAddress: function(id) {
  291. let cartId = this.cartId,
  292. pinkId = this.pinkId,
  293. couponId = this.couponId;
  294. this.cartId = '';
  295. this.pinkId = '';
  296. this.couponId = '';
  297. uni.navigateTo({
  298. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' +
  299. pinkId + '&couponId=' +
  300. 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
  301. })
  302. },
  303. /**
  304. * 删除地址
  305. */
  306. delAddress: function(index) {
  307. let that = this,
  308. address = this.addressList[index];
  309. if (address == undefined) return that.$util.Tips({
  310. title: '您删除的地址不存在!'
  311. });
  312. delAddress(address.id).then(res => {
  313. that.$util.Tips({
  314. title: '删除成功',
  315. icon: 'success'
  316. }, function() {
  317. that.addressList.splice(index, 1);
  318. that.$set(that, 'addressList', that.addressList);
  319. });
  320. }).catch(err => {
  321. return that.$util.Tips({
  322. title: err
  323. });
  324. });
  325. },
  326. /**
  327. * 新增地址
  328. */
  329. addAddress: function() {
  330. let cartId = this.cartId,
  331. pinkId = this.pinkId,
  332. couponId = this.couponId;
  333. this.cartId = '';
  334. this.pinkId = '';
  335. this.couponId = '';
  336. uni.navigateTo({
  337. url: '/pages/users/user_address/index?cartId=' + cartId + '&pinkId=' + pinkId +
  338. '&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
  339. })
  340. },
  341. goOrder: function(id, item) {
  342. let cartId = '';
  343. let pinkId = '';
  344. let couponId = '';
  345. if (this.cartId && id) {
  346. cartId = this.cartId;
  347. pinkId = this.pinkId;
  348. couponId = this.couponId;
  349. this.cartId = '';
  350. this.pinkId = '';
  351. this.couponId = '';
  352. uni.redirectTo({
  353. url: '/pages/goods/order_confirm/index?is_address=1&new=' + this.news + '&cartId=' +
  354. cartId + '&addressId=' + id + '&pinkId=' +
  355. pinkId + '&couponId=' + couponId +
  356. '&noCoupon=' + this.noCoupon+'&delivery_type='+this.deliveryType+'&store_id='+this.storeId+'&store_name='+ this.store_name+'&product_id='+this.product_id
  357. })
  358. }
  359. if (this.isCollage) {
  360. let pages = getCurrentPages();
  361. isWithin({
  362. store_id: this.storeId,
  363. address_id: id
  364. }).then(res => {
  365. for (let i = 0; i < pages.length; i++) {
  366. if (pages[i].route.includes('store_cate')) {
  367. uni.$emit('addressChange', item);
  368. uni.navigateBack({ delta: pages.length - i });
  369. break
  370. }
  371. }
  372. }).catch(err => {
  373. this.$util.Tips({
  374. title: err
  375. });
  376. });
  377. }
  378. }
  379. },
  380. onReachBottom: function() {
  381. this.getAddressList();
  382. }
  383. }
  384. </script>
  385. <style>
  386. .height-add {
  387. height:120rpx;
  388. }
  389. .noCommodity{
  390. height: calc(100vh - 123rpx);
  391. background-color: #fff;
  392. }
  393. .address-management{
  394. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  395. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  396. }
  397. .address-management.fff {
  398. background-color: #fff;
  399. height: 1300rpx
  400. }
  401. .address-management .line {
  402. width: 100%;
  403. height: 3rpx;
  404. }
  405. .address-management .line image {
  406. width: 100%;
  407. height: 100%;
  408. display: block;
  409. }
  410. .address-management .item {
  411. background-color: #fff;
  412. padding: 0 30rpx;
  413. margin-bottom: 12rpx;
  414. }
  415. .address-management .item .address {
  416. padding: 30rpx 0;
  417. border-bottom: 1rpx solid #eee;
  418. font-size: 28rpx;
  419. color: #282828;
  420. }
  421. .address-management .item .address .consignee {
  422. font-size: 28rpx;
  423. font-weight: bold;
  424. margin-bottom: 8rpx;
  425. }
  426. .address-management .item .address .consignee .phone {
  427. margin-left: 25rpx;
  428. }
  429. .address-management .item .operation {
  430. height: 83rpx;
  431. font-size: 28rpx;
  432. color: #282828;
  433. }
  434. .address-management .item .operation .radio text {
  435. margin-left: 13rpx;
  436. }
  437. .address-management .item .operation .iconfont {
  438. color: #2c2c2c;
  439. font-size: 35rpx;
  440. vertical-align: -2rpx;
  441. margin-right: 10rpx;
  442. }
  443. .address-management .item .operation .iconfont.icon-shanchu {
  444. margin-left: 40rpx;
  445. font-size: 38rpx;
  446. }
  447. .address-management .footer {
  448. position: fixed;
  449. width: 100%;
  450. bottom: 0;
  451. height: 106rpx;
  452. padding: 0 30rpx;
  453. box-sizing: border-box;
  454. height: calc(106rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  455. height: calc(106rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  456. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  457. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  458. }
  459. .address-management .footer .addressBnt {
  460. width: 330rpx;
  461. height: 76rpx;
  462. border-radius: 50rpx;
  463. text-align: center;
  464. line-height: 76rpx;
  465. font-size: 30rpx;
  466. color: #fff;
  467. background-color: var(--view-theme);
  468. }
  469. .address-management .footer .addressBnt.on {
  470. width: 690rpx;
  471. margin: 0 auto;
  472. }
  473. .address-management .footer .addressBnt .iconfont {
  474. font-size: 35rpx;
  475. margin-right: 8rpx;
  476. vertical-align: -1rpx;
  477. }
  478. .address-management .footer .addressBnt.wxbnt {
  479. background-color: #FE960F;
  480. }
  481. </style>