user_address.vue 11 KB

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