user_address.vue 11 KB

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