index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <view :style="viewColor">
  3. <view class='address-management' :class='addressList.length < 1 && page > 1 ? "fff":""'>
  4. <view class='line'>
  5. <image :src="`${domain}/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.address_id)'>
  10. <view class='consignee'>收货人:{{item.real_name}}<text class='phone'>{{item.phone}}</text></view>
  11. <view>收货地址:{{item.province || ''}}{{item.city || ''}}{{item.district || ''}}{{item.street || ''}}{{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.address_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="`${domain}/static/images/noAddress.png`"></image>
  37. </view>
  38. <view>暂无地址</view>
  39. </view>
  40. <view class='footer acea-row row-between-wrapper'>
  41. <view class='addressBnt b-color on' @click='addAddress'><text class='iconfont icon-tianjiadizhi'></text>添加新地址</view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. // +----------------------------------------------------------------------
  48. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  49. // +----------------------------------------------------------------------
  50. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  51. // +----------------------------------------------------------------------
  52. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  53. // +----------------------------------------------------------------------
  54. // | Author: CRMEB Team <admin@crmeb.com>
  55. // +----------------------------------------------------------------------
  56. import {
  57. getAddressList,
  58. setAddressDefault,
  59. delAddress,
  60. editAddress,
  61. } from '@/api/user.js';
  62. import { mapGetters } from "vuex";
  63. import { HTTP_REQUEST_URL } from '@/config/app';
  64. import { toLogin } from '@/libs/login.js';
  65. export default {
  66. components: {},
  67. data() {
  68. return {
  69. addressList: [],
  70. cartId: '',
  71. pinkId: 0,
  72. couponId: 0,
  73. loading: false,
  74. loadend: false,
  75. loadTitle: '加载更多',
  76. page: 1,
  77. limit: 20,
  78. domain: HTTP_REQUEST_URL,
  79. };
  80. },
  81. computed: mapGetters(['isLogin', 'viewColor']),
  82. onLoad(options) {
  83. if (this.isLogin) {
  84. this.cartId = options.cartId || '';
  85. this.pinkId = options.pinkId || 0;
  86. this.couponId = options.couponId || 0;
  87. this.getAddressList(true);
  88. } else {
  89. toLogin()
  90. }
  91. },
  92. onReady() {
  93. },
  94. onShow: function() {
  95. let that = this;
  96. that.getAddressList(true);
  97. },
  98. methods: {
  99. /*
  100. * 导入微信地址(小程序)
  101. */
  102. getWxAddress: function() {
  103. let that = this;
  104. uni.authorize({
  105. scope: 'scope.address',
  106. success: function(res) {
  107. uni.chooseAddress({
  108. success: function(res) {
  109. console.log(res,'res')
  110. let addressP = {};
  111. addressP.province = res.provinceName;
  112. addressP.city = res.cityName;
  113. addressP.district = res.countyName;
  114. editAddress({
  115. // address: addressP,
  116. is_default: 1,
  117. real_name: res.userName,
  118. // post_code: res.postalCode,
  119. phone: res.telNumber,
  120. detail: res.detailInfo,
  121. province:res.provinceName,
  122. district:res.countyName,
  123. city:res.cityName,
  124. city_id:''
  125. }).then(res => {
  126. that.$util.Tips({
  127. title: "添加成功",
  128. icon: 'success'
  129. }, function() {
  130. that.getAddressList(true);
  131. });
  132. }).catch(err => {
  133. return that.$util.Tips({
  134. title: err
  135. });
  136. });
  137. },
  138. fail: function(res) {
  139. if (res.errMsg == 'chooseAddress:cancel') return that.$util.Tips({
  140. title: '取消选择'
  141. });
  142. },
  143. })
  144. },
  145. fail: function(res) {
  146. uni.showModal({
  147. title: '您已拒绝导入微信地址权限',
  148. content: '是否进入权限管理,调整授权?',
  149. success(res) {
  150. if (res.confirm) {
  151. uni.openSetting({
  152. success: function(res) {
  153. console.log(res.authSetting)
  154. }
  155. });
  156. } else if (res.cancel) {
  157. return that.$util.Tips({
  158. title: '已取消!'
  159. });
  160. }
  161. }
  162. })
  163. }
  164. })
  165. },
  166. /*
  167. * 导入微信地址(公众号)
  168. */
  169. getAddress() {
  170. let that = this;
  171. that.$wechat.openAddress().then(res => {
  172. editAddress({
  173. real_name: res.userName,
  174. phone: res.telNumber,
  175. province: res.provinceName,
  176. city: res.cityName,
  177. district: res.countryName,
  178. detail: res.detailInfo,
  179. post_code: res.postalCode,
  180. is_default: 1,
  181. city_id:""
  182. })
  183. .then(() => {
  184. that.$util.Tips({
  185. title: "添加成功",
  186. icon: 'success'
  187. }, function() {
  188. that.getAddressList(true);
  189. });
  190. })
  191. .catch(err => {
  192. return that.$util.Tips({
  193. title: err || "添加失败"
  194. });
  195. });
  196. });
  197. },
  198. /**
  199. * 获取地址列表
  200. *
  201. */
  202. getAddressList: function(isPage) {
  203. let that = this;
  204. if (isPage) {
  205. that.loadend = false;
  206. that.page = 1;
  207. that.$set(that, 'addressList', []);
  208. };
  209. if (that.loading) return;
  210. if (that.loadend) return;
  211. that.loading = true;
  212. that.loadTitle = '';
  213. getAddressList({
  214. page: that.page,
  215. limit: that.limit
  216. }).then(res => {
  217. let list = res.data.list;
  218. let loadend = list.length < that.limit;
  219. that.addressList = that.$util.SplitArray(list, that.addressList);
  220. that.$set(that, 'addressList', that.addressList);
  221. that.loadend = loadend;
  222. that.loadTitle = loadend ? '我也是有底线的' : '加载更多';
  223. that.page = that.page + 1;
  224. that.loading = false;
  225. }).catch(err => {
  226. that.loading = false;
  227. that.loadTitle = '加载更多';
  228. });
  229. },
  230. /**
  231. * 设置默认地址
  232. */
  233. radioChange: function(e) {
  234. let index = parseInt(e.detail.value),
  235. that = this;
  236. let address = this.addressList[index];
  237. if (address == undefined) return that.$util.Tips({
  238. title: '您设置的默认地址不存在!'
  239. });
  240. setAddressDefault(address.address_id).then(res => {
  241. for (let i = 0, len = that.addressList.length; i < len; i++) {
  242. if (i == index) that.addressList[i].is_default = true;
  243. else that.addressList[i].is_default = false;
  244. }
  245. that.$util.Tips({
  246. title: '设置成功',
  247. icon: 'success'
  248. }, function() {
  249. that.$set(that, 'addressList', that.addressList);
  250. });
  251. }).catch(err => {
  252. return that.$util.Tips({
  253. title: err
  254. });
  255. });
  256. },
  257. /**
  258. * 编辑地址
  259. */
  260. editAddress: function(id) {
  261. let cartId = this.cartId,
  262. pinkId = this.pinkId,
  263. couponId = this.couponId;
  264. this.cartId = '';
  265. this.pinkId = '';
  266. this.couponId = '';
  267. uni.navigateTo({
  268. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' + pinkId + '&couponId=' +couponId
  269. })
  270. },
  271. /**
  272. * 删除地址
  273. */
  274. delAddress: function(index) {
  275. let that = this,
  276. address = this.addressList[index];
  277. if (address == undefined) return that.$util.Tips({
  278. title: '您删除的地址不存在!'
  279. });
  280. delAddress(address.address_id).then(res => {
  281. that.$util.Tips({
  282. title: '删除成功',
  283. icon: 'success'
  284. }, function() {
  285. that.addressList.splice(index, 1);
  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. addAddress: function() {
  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?cartId=' + cartId
  306. })
  307. },
  308. goOrder: function(id) {
  309. let cartId = '';
  310. let pinkId = '';
  311. let couponId = '';
  312. if (this.cartId && id) {
  313. cartId = this.cartId;
  314. pinkId = this.pinkId;
  315. couponId = this.couponId;
  316. this.cartId = '';
  317. this.pinkId = '';
  318. this.couponId = '';
  319. uni.redirectTo({
  320. url: '/pages/users/order_confirm/index?is_address=1&cartId=' + cartId + '&addressId=' + id + '&pinkId=' +
  321. pinkId + '&couponId=' + couponId
  322. })
  323. }
  324. }
  325. },
  326. onReachBottom: function() {
  327. this.getAddressList();
  328. }
  329. }
  330. </script>
  331. <style lang="scss" scoped>
  332. /deep/radio .wx-radio-input.wx-radio-input-checked,
  333. /deep/uni-radio .uni-radio-input.uni-radio-input-checked {
  334. border: 1px solid var(--view-theme)!important;
  335. background-color: var(--view-theme)!important;
  336. }
  337. .address-management.fff {
  338. background-color: #fff;
  339. height: 100vh;
  340. }
  341. .address-management .line {
  342. width: 100%;
  343. height: 3rpx;
  344. }
  345. .address-management .line image {
  346. width: 100%;
  347. height: 100%;
  348. display: block;
  349. }
  350. .address-management .item {
  351. background-color: #fff;
  352. padding: 0 30rpx;
  353. margin-bottom: 12rpx;
  354. }
  355. .address-management .item .address {
  356. padding: 30rpx 0;
  357. border-bottom: 1px solid #eee;
  358. font-size: 28rpx;
  359. color: #282828;
  360. }
  361. .address-management .item .address .consignee {
  362. font-size: 28rpx;
  363. font-weight: bold;
  364. margin-bottom: 8rpx;
  365. }
  366. .address-management .item .address .consignee .phone {
  367. margin-left: 25rpx;
  368. }
  369. .address-management .item .operation {
  370. height: 83rpx;
  371. font-size: 28rpx;
  372. color: #282828;
  373. }
  374. .b-color {
  375. background-color: var(--view-theme);
  376. }
  377. .address-management .item .operation .radio text {
  378. margin-left: 13rpx;
  379. }
  380. .address-management .item .operation .iconfont {
  381. color: #2c2c2c;
  382. font-size: 35rpx;
  383. vertical-align: -2rpx;
  384. margin-right: 10rpx;
  385. }
  386. .address-management .item .operation .iconfont.icon-shanchu {
  387. margin-left: 40rpx;
  388. font-size: 38rpx;
  389. }
  390. .address-management .footer {
  391. position: fixed;
  392. width: 100%;
  393. background-color: #fff;
  394. bottom: 0;
  395. bottom: calc(0rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  396. bottom: calc(0rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  397. height: 106rpx;
  398. padding: 0 30rpx;
  399. box-sizing: border-box;
  400. }
  401. .address-management .footer .addressBnt {
  402. width: 330rpx;
  403. height: 76rpx;
  404. border-radius: 50rpx;
  405. text-align: center;
  406. line-height: 76rpx;
  407. font-size: 30rpx;
  408. color: #fff;
  409. }
  410. .address-management .footer .addressBnt.on {
  411. width: 690rpx;
  412. margin: 0 auto;
  413. }
  414. .address-management .footer .addressBnt .iconfont {
  415. font-size: 35rpx;
  416. margin-right: 8rpx;
  417. vertical-align: -1rpx;
  418. }
  419. .address-management .footer .addressBnt.wxbnt {
  420. background-color: #fe960f;
  421. }
  422. .noCommodity{
  423. text-align: center;
  424. border-top: none;
  425. margin-top: 15vh;
  426. }
  427. .noCommodity .pictrue{
  428. height: 305rpx;
  429. }
  430. .noCommodity view{
  431. color: #999;
  432. }
  433. </style>