index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <view>
  3. <view class='line'>
  4. <image src='../../../static/images/line.jpg' v-if="addressList.length"></image>
  5. </view>
  6. <view class='address-management' :class='addressList.length === 0 ? "fff":""'>
  7. <radio-group class="radio-group" @change="radioChange" v-if="addressList.length">
  8. <view class='item borRadius14' v-for="(item,index) in addressList" :key="index">
  9. <view class='address' @click='goOrder(item.id)'>
  10. <view class='consignee'>收货人:{{ item.name }}
  11. <text class='phone'>{{item.mobile}}</text>
  12. </view>
  13. <view>收货地址:{{item.areaName}} {{item.detailAddress}}</view>
  14. </view>
  15. <view class='operation acea-row row-between-wrapper'>
  16. <!-- #ifndef MP -->
  17. <radio class="radio" :value="index.toString()" :checked="item.defaultStatus">
  18. <text>设为默认</text>
  19. </radio>
  20. <!-- #endif -->
  21. <!-- #ifdef MP -->
  22. <radio class="radio" :value="index" :checked="item.defaultStatus">
  23. <text>设为默认</text>
  24. </radio>
  25. <!-- #endif -->
  26. <view class='acea-row row-middle'>
  27. <view @click='editAddress(item.id)'>
  28. <text class='iconfont icon-bianji' />编辑
  29. </view>
  30. <view @click='delAddress(index)'>
  31. <text class='iconfont icon-shanchu' />删除
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </radio-group>
  37. <view class='loadingicon acea-row row-center-wrapper' v-if="addressList.length">
  38. <text class='loading iconfont icon-jiazai' :hidden='!loading'></text>{{loadTitle}}
  39. </view>
  40. <view class='noCommodity' v-if="addressList.length < 1">
  41. <view class='pictrue'>
  42. <image src='../../../static/images/noAddress.png'></image>
  43. </view>
  44. </view>
  45. <view style='height:120rpx;'></view>
  46. </view>
  47. <view class='footer acea-row row-between-wrapper'>
  48. <!-- #ifdef MP-->
  49. <view class='addressBnt bg-color' @click='addAddress'>
  50. <text class='iconfont icon-tianjiadizhi' />添加新地址
  51. </view>
  52. <view class='addressBnt wxbnt' @click='getWxAddress'>
  53. <text class='iconfont icon-weixin2' />导入微信地址
  54. </view>
  55. <!-- #endif -->
  56. <!-- #ifdef H5-->
  57. <view class='addressBnt bg-color' :class="this.$wechat.isWeixin()?'':'on'" @click='addAddress'>
  58. <text class='iconfont icon-tianjiadizhi' />添加新地址
  59. </view>
  60. <view v-if="this.$wechat.isWeixin()" class='addressBnt wxbnt' @click='getAddress'>
  61. <text class='iconfont icon-weixin2' />导入微信地址
  62. </view>
  63. <!-- #endif -->
  64. </view>
  65. <home></home>
  66. </view>
  67. </template>
  68. <script>
  69. import { editAddress } from '@/api/user.js';
  70. import { toLogin } from '@/libs/login.js';
  71. import { mapGetters } from "vuex";
  72. import home from '@/components/home';
  73. import * as AddressApi from '@/api/member/address.js';
  74. export default {
  75. components: {
  76. home
  77. },
  78. data() {
  79. return {
  80. addressList: [],
  81. loading: false,
  82. loadTitle: '加载更多',
  83. // TODO 芋艿:看看后面咋搞回来
  84. preOrderNo: '',
  85. cartId: '',
  86. pinkId: 0,
  87. couponId: 0,
  88. bargain: false, // 是否是砍价
  89. combination: false, // 是否是拼团
  90. secKill: false, // 是否是秒杀
  91. };
  92. },
  93. computed: mapGetters(['isLogin']),
  94. watch:{
  95. isLogin:{
  96. handler: function(newV, oldV) {
  97. if (newV) {
  98. this.getUserAddress(true);
  99. }
  100. },
  101. deep:true
  102. }
  103. },
  104. onLoad(options) {
  105. if (!this.isLogin) {
  106. toLogin();
  107. return;
  108. }
  109. this.preOrderNo = options.preOrderNo || 0;
  110. this.getAddressList();
  111. },
  112. onShow: function() {
  113. this.getAddressList();
  114. },
  115. methods: {
  116. /**
  117. * 获取地址列表
  118. */
  119. getAddressList: function() {
  120. if (this.loading) {
  121. return;
  122. }
  123. this.loading = true;
  124. this.loadTitle = '';
  125. AddressApi.getAddressList().then(res => {
  126. this.$set(this, 'addressList', res.data);
  127. this.loadTitle = '我也是有底线的';
  128. this.loading = false;
  129. }).catch(err => {
  130. this.loading = false;
  131. this.loadTitle = '加载更多';
  132. });
  133. },
  134. /**
  135. * 设置默认地址
  136. */
  137. radioChange: function(e) {
  138. const index = parseInt(e.detail.value);
  139. const address = this.addressList[index];
  140. if (address === undefined) {
  141. return this.$util.Tips({
  142. title: '您设置的默认地址不存在!'
  143. });
  144. }
  145. AddressApi.updateAddress({
  146. ...address,
  147. defaultStatus: true
  148. }).then(res => {
  149. for (let i = 0, len = this.addressList.length; i < len; i++) {
  150. if (i === index) {
  151. this.addressList[i].defaultStatus = true;
  152. } else {
  153. this.addressList[i].defaultStatus = false;
  154. }
  155. }
  156. this.$util.Tips({
  157. title: '设置成功',
  158. icon: 'success'
  159. }, () => {
  160. this.$set(this, 'addressList', this.addressList);
  161. });
  162. }).catch(err => {
  163. return this.$util.Tips({
  164. title: err
  165. });
  166. });
  167. },
  168. /**
  169. * 编辑地址
  170. */
  171. editAddress: function(id) {
  172. let cartId = this.cartId,
  173. pinkId = this.pinkId,
  174. couponId = this.couponId;
  175. this.cartId = '';
  176. this.pinkId = '';
  177. this.couponId = '';
  178. uni.navigateTo({
  179. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' + pinkId + '&couponId=' +
  180. couponId + '&secKill' + this.secKill + '&combination=' + this.combination + '&bargain=' + this.bargain
  181. })
  182. },
  183. /**
  184. * 删除地址
  185. */
  186. delAddress: function(index) {
  187. const address = this.addressList[index];
  188. if (address === undefined) {
  189. return this.$util.Tips({
  190. title: '您删除的地址不存在!'
  191. });
  192. }
  193. AddressApi.deleteAddress(address.id).then(res => {
  194. this.$util.Tips({
  195. title: '删除成功',
  196. icon: 'success'
  197. }, () => {
  198. this.addressList.splice(index, 1);
  199. this.$set(this, 'addressList', this.addressList);
  200. });
  201. }).catch(err => {
  202. return this.$util.Tips({
  203. title: err
  204. });
  205. });
  206. },
  207. /**
  208. * 新增地址
  209. */
  210. addAddress: function() {
  211. this.cartId = '';
  212. this.pinkId = '';
  213. this.couponId = '';
  214. uni.navigateTo({
  215. url: '/pages/users/user_address/index?preOrderNo=' + this.preOrderNo
  216. })
  217. },
  218. // TODO 芋艿:微信导入;
  219. /**
  220. * 导入微信地址(小程序)
  221. */
  222. getWxAddress: function() {
  223. let that = this;
  224. uni.authorize({
  225. scope: 'scope.address',
  226. success: function(res) {
  227. uni.chooseAddress({
  228. success: function(res) {
  229. let addressP = {};
  230. addressP.province = res.provinceName;
  231. addressP.city = res.cityName;
  232. addressP.district = res.countyName;
  233. addressP.cityId = 0;
  234. editAddress({
  235. address: addressP,
  236. defaultStatus: true,
  237. realName: res.userName,
  238. postCode: res.postalCode,
  239. phone: res.telNumber,
  240. detail: res.detailInfo,
  241. id: 0
  242. //type: 1//区别城市id(导入微信地址无城市id需要后台自己查找);
  243. }).then(res => {
  244. that.$util.Tips({
  245. title: "添加成功",
  246. icon: 'success'
  247. }, function() {
  248. that.getAddressList(true);
  249. });
  250. }).catch(err => {
  251. return that.$util.Tips({
  252. title: err
  253. });
  254. });
  255. },
  256. fail: function(res) {
  257. if (res.errMsg == 'chooseAddress:cancel') return that.$util.Tips({
  258. title: '取消选择'
  259. });
  260. },
  261. })
  262. },
  263. fail: function(res) {
  264. uni.showModal({
  265. title: '您已拒绝导入微信地址权限',
  266. content: '是否进入权限管理,调整授权?',
  267. success(res) {
  268. if (res.confirm) {
  269. uni.openSetting({
  270. success: function(res) {
  271. console.log(res.authSetting)
  272. }
  273. });
  274. } else if (res.cancel) {
  275. return that.$util.Tips({
  276. title: '已取消!'
  277. });
  278. }
  279. }
  280. })
  281. }
  282. })
  283. },
  284. // TODO 芋艿:微信导入;
  285. /**
  286. * 导入微信地址(公众号)
  287. */
  288. getAddress() {
  289. let that = this;
  290. that.$wechat.openAddress().then(userInfo => {
  291. // open();
  292. editAddress({
  293. realName: userInfo.userName,
  294. phone: userInfo.telNumber,
  295. address: {
  296. province: userInfo.provinceName,
  297. city: userInfo.cityName,
  298. district: userInfo.countryName,
  299. cityId: 0
  300. },
  301. detail: userInfo.detailInfo,
  302. postCode: userInfo.postalCode,
  303. defaultStatus: true
  304. })
  305. .then(() => {
  306. that.$util.Tips({
  307. title: "添加成功",
  308. icon: 'success'
  309. }, function() {
  310. // close();
  311. that.getAddressList();
  312. });
  313. })
  314. .catch(err => {
  315. // close();
  316. return that.$util.Tips({
  317. title: err || "添加失败"
  318. });
  319. });
  320. });
  321. },
  322. goOrder: function(id) {
  323. if(this.preOrderNo){
  324. uni.redirectTo({
  325. url: '/pages/users/order_confirm/index?is_address=1&preOrderNo=' + this.preOrderNo + '&addressId=' + id
  326. })
  327. }
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="scss" scoped>
  333. .address-management{
  334. padding: 20rpx 30rpx;
  335. }
  336. .address-management.fff {
  337. background-color: #fff;
  338. height: 1300rpx
  339. }
  340. .line {
  341. width: 100%;
  342. height: 3rpx;
  343. image {
  344. width: 100%;
  345. height: 100%;
  346. display: block;
  347. }
  348. }
  349. .address-management .item {
  350. background-color: #fff;
  351. padding: 0 20rpx;
  352. margin-bottom: 20rpx;
  353. }
  354. .address-management .item .address {
  355. padding: 35rpx 0;
  356. border-bottom: 1rpx solid #eee;
  357. font-size: 28rpx;
  358. color: #282828;
  359. }
  360. .address-management .item .address .consignee {
  361. font-size: 28rpx;
  362. font-weight: bold;
  363. margin-bottom: 8rpx;
  364. }
  365. .address-management .item .address .consignee .phone {
  366. margin-left: 25rpx;
  367. }
  368. .address-management .item .operation {
  369. height: 83rpx;
  370. font-size: 28rpx;
  371. color: #282828;
  372. }
  373. .address-management .item .operation .radio text {
  374. margin-left: 13rpx;
  375. }
  376. .address-management .item .operation .iconfont {
  377. color: #2c2c2c;
  378. font-size: 35rpx;
  379. vertical-align: -2rpx;
  380. margin-right: 10rpx;
  381. }
  382. .address-management .item .operation .iconfont.icon-shanchu {
  383. margin-left: 35rpx;
  384. font-size: 38rpx;
  385. }
  386. .footer {
  387. position: fixed;
  388. width: 100%;
  389. background-color: #fff;
  390. bottom: 0;
  391. height: 106rpx;
  392. padding: 0 30rpx;
  393. box-sizing: border-box;
  394. }
  395. .footer .addressBnt {
  396. width: 330rpx;
  397. height: 76rpx;
  398. border-radius: 50rpx;
  399. text-align: center;
  400. line-height: 76rpx;
  401. font-size: 30rpx;
  402. color: #fff;
  403. }
  404. .footer .addressBnt.on {
  405. width: 690rpx;
  406. margin: 0 auto;
  407. }
  408. .footer .addressBnt .iconfont {
  409. font-size: 35rpx;
  410. margin-right: 8rpx;
  411. vertical-align: -1rpx;
  412. }
  413. .footer .addressBnt.wxbnt {
  414. background-color: #fe960f;
  415. }
  416. </style>