index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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.realName }}<text class='phone'>{{ item.phone }}
  11. </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. <!-- #ifdef MP -->
  16. <radio class="radio" :value="index" :checked="item.defaultState == '2' ? true : false">
  17. <text>{{ $t(`默认地址`) }}</text>
  18. </radio>
  19. <!-- #endif -->
  20. <view class='acea-row row-middle'>
  21. <view @click='editAddress(item.id)'><text class='iconfont icon-bianji'></text>{{ $t(`编辑`) }}
  22. </view>
  23. <view @click='delAddress(index)'><text class='iconfont icon-shanchu'></text>{{ $t(`删除`) }}
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </radio-group>
  29. <view class='loadingicon acea-row row-center-wrapper' v-if="addressList.length">
  30. <text class='loading iconfont icon-jiazai' :hidden='loading == false'></text>{{ loadTitle }}
  31. </view>
  32. <view class='noCommodity' v-if="addressList.length < 1 && page > 1">
  33. <view class='pictrue'>
  34. <image :src="imgHost + '/statics/images/noAddress.png'"></image>
  35. </view>
  36. </view>
  37. <view style='height:120rpx;'></view>
  38. <view class='footer acea-row row-between-wrapper'>
  39. <!-- #ifdef APP-PLUS -->
  40. <view class='addressBnt on' @click='addAddress'><text
  41. class='iconfont icon-tianjiadizhi'></text>{{ $t(`添加新地址`) }}</view>
  42. <!-- #endif -->
  43. <!-- #ifdef MP-->
  44. <view class='addressBnt on' @click='addAddress'><text
  45. class='iconfont icon-tianjiadizhi'></text>{{ $t(`添加新地址`) }}</view>
  46. <!-- <view class='addressBnt' @click='getWxAddress'><text class='iconfont icon-weixin2'></text>{{$t(`导入微信地址`)}} -->
  47. </view>
  48. <!-- #endif -->
  49. <!-- #ifdef H5-->
  50. <view class='addressBnt' :class="this.$wechat.isWeixin() ? 'wxbnt' : 'on'" @click='addAddress'><text
  51. class='iconfont icon-tianjiadizhi'></text>{{ $t(`添加新地址`) }}</view>
  52. <view class=""></view>
  53. <view class='addressBnt' @click='getAddress' v-if="this.$wechat.isWeixin()"><text
  54. class='iconfont icon-weixin2'></text>{{ $t(`导入微信地址`) }}</view>
  55. <!-- #endif -->
  56. </view>
  57. </view>
  58. <!-- #ifdef MP -->
  59. <!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  60. <!-- #endif -->
  61. <!-- #ifndef MP -->
  62. <home></home>
  63. <!-- #endif -->
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. getUserAddressPage,
  69. postUserAddressUpdate,
  70. postUserAddressRemove
  71. } from '@/api/home.js';
  72. import {
  73. getAddressList,
  74. setAddressDefault,
  75. delAddress,
  76. editAddress,
  77. postAddress
  78. } from '@/api/user.js';
  79. import {
  80. toLogin
  81. } from '@/libs/login.js';
  82. import {
  83. mapGetters
  84. } from "vuex";
  85. // #ifdef MP
  86. import authorize from '@/components/Authorize';
  87. // #endif
  88. import home from '@/components/home';
  89. import colors from '@/mixins/color.js';
  90. import { HTTP_REQUEST_URL } from '@/config/app';
  91. export default {
  92. components: {
  93. // #ifdef MP
  94. authorize,
  95. // #endif
  96. home
  97. },
  98. mixins: [colors],
  99. data() {
  100. return {
  101. type: 0,
  102. imgHost: HTTP_REQUEST_URL,
  103. addressList: [],
  104. cartId: '',
  105. pinkId: 0,
  106. couponId: 0,
  107. loading: false,
  108. loadend: false,
  109. loadTitle: this.$t(`加载更多`),
  110. page: 1,
  111. limit: 20,
  112. isAuto: false, //没有授权的不会自动授权
  113. isShowAuth: false, //是否隐藏授权
  114. news: '',
  115. noCoupon: 0
  116. };
  117. },
  118. computed: mapGetters(['isLogin']),
  119. onLoad(options) {
  120. if (options.type) {
  121. this.type = options.type
  122. uni.setNavigationBarTitle({
  123. title: "选择地址"
  124. });
  125. }
  126. if (this.isLogin) {
  127. this.cartId = options.cartId || '';
  128. this.noCoupon = options.noCoupon || 0;
  129. this.pinkId = options.pinkId || 0;
  130. this.couponId = options.couponId || 0;
  131. this.news = options.news || 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. realName: 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 (res) {
  186. if (res.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. realName: 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. getUserAddressPage({
  265. userId: this.$store.state.app.uid,
  266. current: that.page,
  267. size: that.limit
  268. }).then(res => {
  269. let list = res.data;
  270. let loadend = list.length < that.limit;
  271. that.addressList = that.$util.SplitArray(list, that.addressList);
  272. that.$set(that, 'addressList', that.addressList);
  273. that.loadend = loadend;
  274. that.loadTitle = loadend ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
  275. that.page = that.page + 1;
  276. that.loading = false;
  277. }).catch(err => {
  278. that.loading = false;
  279. that.loadTitle = that.$t(`加载更多`);
  280. });
  281. },
  282. /**
  283. * 设置默认地址
  284. */
  285. radioChange: function (e) {
  286. let index = parseInt(e.detail.value),
  287. that = this;
  288. let address = this.addressList[index];
  289. if (address == undefined) return that.$util.Tips({
  290. title: that.$t(`您设置的默认地址不存在!`)
  291. });
  292. address.defaultState = 2
  293. postUserAddressUpdate(address).then(res => {
  294. for (let i = 0, len = that.addressList.length; i < len; i++) {
  295. if (i == index) that.addressList[i].is_default = true;
  296. else that.addressList[i].is_default = false;
  297. }
  298. that.$util.Tips({
  299. title: that.$t(`设置成功`),
  300. icon: 'success'
  301. }, function () {
  302. that.$set(that, 'addressList', that.addressList);
  303. });
  304. }).catch(err => {
  305. return that.$util.Tips({
  306. title: err
  307. });
  308. });
  309. },
  310. /**
  311. * 编辑地址
  312. */
  313. editAddress: function (id) {
  314. let cartId = this.cartId,
  315. pinkId = this.pinkId,
  316. couponId = this.couponId;
  317. this.cartId = '';
  318. this.pinkId = '';
  319. this.couponId = '';
  320. uni.navigateTo({
  321. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' +
  322. pinkId + '&couponId=' +
  323. couponId + '&new=' + this.news
  324. })
  325. },
  326. /**
  327. * 删除地址
  328. */
  329. delAddress: function (index) {
  330. let that = this,
  331. address = this.addressList[index];
  332. if (address == undefined) return that.$util.Tips({
  333. title: that.$t(`您删除的地址不存在!`)
  334. });
  335. postUserAddressRemove({ ids: address.id }).then(res => {
  336. that.$util.Tips({
  337. title: that.$t(`删除成功`),
  338. icon: 'success'
  339. }, function () {
  340. that.addressList.splice(index, 1);
  341. that.$set(that, 'addressList', that.addressList);
  342. });
  343. }).catch(err => {
  344. return that.$util.Tips({
  345. title: err
  346. });
  347. });
  348. },
  349. /**
  350. * 新增地址
  351. */
  352. addAddress: function () {
  353. let cartId = this.cartId,
  354. pinkId = this.pinkId,
  355. couponId = this.couponId;
  356. this.cartId = '';
  357. this.pinkId = '';
  358. this.couponId = '';
  359. uni.navigateTo({
  360. url: '/pages/users/user_address/index?cartId=' + cartId + '&pinkId=' + pinkId +
  361. '&couponId=' + couponId + '&new=' + this.news
  362. })
  363. },
  364. goOrder: function (id) {
  365. let cartId = '';
  366. let pinkId = '';
  367. let couponId = '';
  368. if (this.cartId && id) {
  369. cartId = this.cartId;
  370. pinkId = this.pinkId;
  371. couponId = this.couponId;
  372. this.cartId = '';
  373. this.pinkId = '';
  374. this.couponId = '';
  375. uni.redirectTo({
  376. url: '/pages/goods/order_confirm/index?is_address=1&new=' + this.news + '&cartId=' +
  377. cartId + '&addressId=' + id + '&pinkId=' +
  378. pinkId + '&couponId=' + couponId + '&noCoupon=' + this.noCoupon
  379. })
  380. }
  381. }
  382. },
  383. onReachBottom: function () {
  384. this.getAddressList();
  385. }
  386. }
  387. </script>
  388. <style>
  389. .address-management.fff {
  390. background-color: #fff;
  391. height: 1300rpx
  392. }
  393. .address-management .line {
  394. width: 100%;
  395. height: 3rpx;
  396. }
  397. .address-management .line image {
  398. width: 100%;
  399. height: 100%;
  400. display: block;
  401. }
  402. .address-management .item {
  403. background-color: #fff;
  404. padding: 0 30rpx;
  405. margin-bottom: 12rpx;
  406. }
  407. .address-management .item .address {
  408. padding: 30rpx 0;
  409. border-bottom: 1rpx solid #eee;
  410. font-size: 28rpx;
  411. color: #282828;
  412. }
  413. .address-management .item .address .consignee {
  414. font-size: 28rpx;
  415. font-weight: bold;
  416. margin-bottom: 8rpx;
  417. }
  418. .address-management .item .address .consignee .phone {
  419. margin-left: 25rpx;
  420. }
  421. .address-management .item .operation {
  422. height: 83rpx;
  423. font-size: 28rpx;
  424. color: #282828;
  425. }
  426. .address-management .item .operation .radio text {
  427. margin-left: 13rpx;
  428. }
  429. .address-management .item .operation .iconfont {
  430. color: #2c2c2c;
  431. font-size: 35rpx;
  432. vertical-align: -2rpx;
  433. margin-right: 10rpx;
  434. }
  435. .address-management .item .operation .iconfont.icon-shanchu {
  436. margin-left: 40rpx;
  437. font-size: 38rpx;
  438. }
  439. .address-management .footer {
  440. position: fixed;
  441. width: 100%;
  442. background-color: #fff;
  443. bottom: 0;
  444. height: 106rpx;
  445. padding: 0 30rpx;
  446. box-sizing: border-box;
  447. }
  448. .address-management .footer .addressBnt {
  449. width: 330rpx;
  450. height: 76rpx;
  451. border-radius: 50rpx;
  452. text-align: center;
  453. line-height: 76rpx;
  454. font-size: 30rpx;
  455. color: #fff;
  456. background-color: var(--view-theme);
  457. }
  458. .address-management .footer .addressBnt.on {
  459. width: 690rpx;
  460. margin: 0 auto;
  461. }
  462. .address-management .footer .addressBnt .iconfont {
  463. font-size: 35rpx;
  464. margin-right: 8rpx;
  465. vertical-align: -1rpx;
  466. }
  467. .address-management .footer .addressBnt.wxbnt {
  468. background-color: #FE960F;
  469. }
  470. </style>