user_address.vue 11 KB

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