user_address.vue 11 KB

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