index.vue 13 KB

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