user_address.vue 12 KB

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