index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <view>
  3. <view >
  4. <!-- #ifdef APP-PLUS -->
  5. <!-- 状态栏占位 -->
  6. <view class="status_bar"></view>
  7. <!-- #endif -->
  8. <view class='address-management' :class='equipmentList.length === 0 ? "fff":""'>
  9. <radio-group class="radio-group" @change="radioChange" v-if="equipmentList.length">
  10. <view class='item borRadius14' v-for="(item,index) in equipmentList" :key="index">
  11. <view class="content_box_top">
  12. <u-avatar class="avatar" :src="item.relationVo.avatar" mode="square" :show-sex="true"
  13. :sex-icon="item.sex === 1 ? 'male':'female'"
  14. :icon-color="gender === 'male' ? '#409EFF' : '#F56C6C'"></u-avatar>
  15. <view class='address' @click='goIndex(item.id,item.deviceCode)'>
  16. <view class="address-left">
  17. <view class='consignee'>
  18. <view>昵称:{{ item.nickName }}</view>
  19. <view class="online-box">
  20. <image v-if="item.onlineForce||item.onlineStatus"
  21. src="/static/image/online.png" mode=""></image>
  22. <image v-if="!item.onlineForce&&!item.onlineStatus"
  23. src="/static/image/offline.png" mode=""></image>
  24. </view>
  25. <!-- <text class='phone'>ID:{{item.deviceCode}}</text> -->
  26. </view>
  27. <text class='phone'>ID:{{item.deviceCode}}</text>
  28. <!-- <view>收货地址:{{item.areaName}} {{item.detailAddress}}</view> -->
  29. </view>
  30. <image src="/static/image/arrow.png" mode=""></image>
  31. </view>
  32. </view>
  33. <view class='operation acea-row row-between-wrapper'>
  34. <!-- #ifndef MP -->
  35. <radio class="radio" :value="index.toString()" :checked="item.status">
  36. <text>设为默认</text>
  37. </radio>
  38. <!-- #endif -->
  39. <!-- #ifdef MP -->
  40. <radio class="radio" :value="index" :checked="item.status">
  41. <text>设为默认</text>
  42. </radio>
  43. <!-- #endif -->
  44. <view class='acea-row row-middle'>
  45. <!-- <view @click='editAddress(item.id)'>
  46. <text class='iconfont icon-bianji' />编辑
  47. </view> -->
  48. <view @click='delEquipment(item,index)'>
  49. <text class='iconfont icon-shanchu' />删除
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </radio-group>
  55. <view class='loadingicon acea-row row-center-wrapper' v-if="equipmentList.length">
  56. <text class='loading iconfont icon-jiazai' :hidden='!loading'></text>{{loadTitle}}
  57. </view>
  58. <view class='noCommodity' v-if="equipmentList.length < 1">
  59. <view class='pictrue'>
  60. <image src='/static/img/none.png'></image>
  61. </view>
  62. </view>
  63. <view style='height:120rpx;'></view>
  64. </view>
  65. <view class="footer" @click="addEqu">
  66. <image src="/static/img/addicon.png" mode=""></image>
  67. <view>
  68. 添加设备
  69. </view>
  70. </view>
  71. </view>
  72. <!-- <view class="swiper" v-if="undeviceId">
  73. <swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
  74. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff" @change="handleSwiperChange">
  75. <block v-for="(item,index) in imgUrls" :key="index">
  76. <swiper-item>
  77. <image :src="item.src" class="slide-image"></image>
  78. </swiper-item>
  79. </block>
  80. </swiper>
  81. </view> -->
  82. <van-dialog id="van-dialog" />
  83. <!-- <home></home> -->
  84. </view>
  85. </template>
  86. <script>
  87. // import Dialog from '../../wxcomponents/vant/dist/dialog/dialog';
  88. import Dialog from '@/wxcomponents/vant/dist/dialog/dialog';
  89. // import /wxcomponents/vant/dist/dialog/index
  90. import * as infoApi from '@/api/sleep/equ.js';
  91. import {
  92. editAddress
  93. } from '@/api/user.js';
  94. // import {
  95. // toLogin
  96. // } from '@/libs/login.js';
  97. import {
  98. mapGetters
  99. } from "vuex";
  100. import home from '@/components/home';
  101. import * as AddressApi from '@/api/member/address.js';
  102. export default {
  103. components: {
  104. home
  105. },
  106. data() {
  107. return {
  108. checked:false,
  109. // equipmentList: [{
  110. // id: 11,
  111. // name: '王艺涵',
  112. // mobile: 177
  113. // }, {
  114. // id: 11,
  115. // name: '王艺涵',
  116. // mobile: 177
  117. // }],
  118. equipmentList: [],
  119. loading: false,
  120. loadTitle: '加载更多',
  121. // TODO 芋艿:看看后面咋搞回来
  122. preOrderNo: '',
  123. cartId: '',
  124. pinkId: 0,
  125. couponId: 0,
  126. bargain: false, // 是否是砍价
  127. combination: false, // 是否是拼团
  128. secKill: false, // 是否是秒杀
  129. src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
  130. autoplay: false,
  131. circular: true,
  132. interval: 3000,
  133. duration: 500,
  134. undeviceId:false,
  135. imgUrls:[{src:'/static/image/0001.png'},{src:'/static/image/0002.png'},{src:'/static/image/0003.png'}]
  136. };
  137. },
  138. computed: mapGetters(['uid', 'deviceId']),
  139. watch: {
  140. // isLogin: {
  141. // handler: function(newV, oldV) {
  142. // if (newV) {
  143. // this.getUserAddress(true);
  144. // }
  145. // },
  146. // deep: true
  147. // }
  148. },
  149. onLoad(options) {
  150. if (!this.deviceId) {
  151. console.log('我没有deviceId');
  152. this.undeviceId=true
  153. }
  154. // if (!this.isLogin) {
  155. // toLogin();
  156. // return;
  157. // }
  158. this.preOrderNo = options.preOrderNo || 0;
  159. this.getEquipmentList();
  160. },
  161. onShow: function() {
  162. this.getEquipmentList();
  163. },
  164. methods: {
  165. // 轮播图改变事件
  166. handleSwiperChange :function(e) {
  167. console.log(e,666);
  168. if(e.detail.current==0){
  169. console.log('进来了等于0');
  170. this.undeviceId=false
  171. }
  172. // this.currentValChange = e.detail.current
  173. // console.log(this.currentValChange)
  174. // if (this.swiperChangeSelect) {
  175. // console.log("swiperChange")
  176. // console.log(e)
  177. // }
  178. },
  179. /**
  180. * 获取地址列表
  181. */
  182. getEquipmentList: function() {
  183. if (this.loading) {
  184. return;
  185. }
  186. this.loading = true;
  187. this.loadTitle = '';
  188. let params = {
  189. memberId: this.uid
  190. }
  191. infoApi.getEquList(params).then(res => {
  192. this.$set(this, 'equipmentList', res.data);
  193. this.loadTitle = '我也是有底线的';
  194. this.loading = false;
  195. }).catch(err => {
  196. this.loading = false;
  197. this.loadTitle = '加载更多';
  198. });
  199. },
  200. /**
  201. * 设置默认地址
  202. */
  203. radioChange: function(e) {
  204. const index = parseInt(e.detail.value);
  205. const item = this.equipmentList[index];
  206. if (item === undefined) {
  207. return this.$util.Tips({
  208. title: '您设置的默认地址不存在!'
  209. });
  210. }
  211. infoApi.bindDefaultEqu({
  212. memberId: this.uid,
  213. id: item.id
  214. }).then(res => {
  215. if (res.code === 0 && res.data.bindCount === 1) {
  216. for (let i = 0, len = this.equipmentList.length; i < len; i++) {
  217. if (i === index) {
  218. this.equipmentList[i].status = true;
  219. } else {
  220. this.equipmentList[i].status = false;
  221. }
  222. }
  223. this.$util.Tips({
  224. title: '设置成功',
  225. icon: 'success'
  226. }, () => {
  227. this.$store.commit("DEVICE_ID", res.data.deviceId);
  228. // this.$set(this, 'equipmentList', this.equipmentList);
  229. this.getEquipmentList()
  230. });
  231. }
  232. }).catch(err => {
  233. return this.$util.Tips({
  234. title: err
  235. });
  236. });
  237. },
  238. /**
  239. * 编辑地址
  240. */
  241. editAddress: function(id) {
  242. let cartId = this.cartId,
  243. pinkId = this.pinkId,
  244. couponId = this.couponId;
  245. this.cartId = '';
  246. this.pinkId = '';
  247. this.couponId = '';
  248. uni.navigateTo({
  249. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' +
  250. pinkId + '&couponId=' +
  251. couponId + '&secKill' + this.secKill + '&combination=' + this.combination +
  252. '&bargain=' + this.bargain
  253. })
  254. },
  255. /**
  256. * 删除设备
  257. */
  258. delEquipment(item, index) {
  259. const address = this.equipmentList[index];
  260. if (address === undefined) {
  261. return this.$util.Tips({
  262. title: '您删除的地址不存在!'
  263. });
  264. }
  265. Dialog.confirm({
  266. title: '',
  267. message: '是否确认删除此设备?',
  268. context: this,
  269. })
  270. .then(() => {
  271. let params = {
  272. memberId: this.uid,
  273. id: item.id
  274. }
  275. infoApi.bindDelete(params).then(res => {
  276. this.$util.Tips({
  277. title: '删除成功',
  278. icon: 'success'
  279. }, () => {
  280. this.equipmentList.splice(index, 1);
  281. this.getEquipmentList()
  282. });
  283. }).catch(err => {
  284. return this.$util.Tips({
  285. title: err
  286. });
  287. });
  288. })
  289. .catch(() => {
  290. // on cancel
  291. });
  292. },
  293. /**
  294. * 新增地址
  295. */
  296. addAddress: function() {
  297. this.cartId = '';
  298. this.pinkId = '';
  299. this.couponId = '';
  300. uni.navigateTo({
  301. url: '/pages/users/user_address/index?preOrderNo=' + this.preOrderNo
  302. })
  303. },
  304. // TODO 芋艿:微信导入;
  305. /**
  306. * 导入微信地址(小程序)
  307. */
  308. getWxAddress: function() {
  309. let that = this;
  310. uni.authorize({
  311. scope: 'scope.address',
  312. success: function(res) {
  313. uni.chooseAddress({
  314. success: function(res) {
  315. let addressP = {};
  316. addressP.province = res.provinceName;
  317. addressP.city = res.cityName;
  318. addressP.district = res.countyName;
  319. addressP.cityId = 0;
  320. editAddress({
  321. address: addressP,
  322. status: true,
  323. realName: res.userName,
  324. postCode: res.postalCode,
  325. phone: res.telNumber,
  326. detail: res.detailInfo,
  327. id: 0
  328. //type: 1//区别城市id(导入微信地址无城市id需要后台自己查找);
  329. }).then(res => {
  330. that.$util.Tips({
  331. title: "添加成功",
  332. icon: 'success'
  333. }, function() {
  334. that.getEquipmentList(true);
  335. });
  336. }).catch(err => {
  337. return that.$util.Tips({
  338. title: err
  339. });
  340. });
  341. },
  342. fail: function(res) {
  343. if (res.errMsg == 'chooseAddress:cancel') return that.$util
  344. .Tips({
  345. title: '取消选择'
  346. });
  347. },
  348. })
  349. },
  350. fail: function(res) {
  351. uni.showModal({
  352. title: '您已拒绝导入微信地址权限',
  353. content: '是否进入权限管理,调整授权?',
  354. success(res) {
  355. if (res.confirm) {
  356. uni.openSetting({
  357. success: function(res) {
  358. console.log(res.authSetting)
  359. }
  360. });
  361. } else if (res.cancel) {
  362. return that.$util.Tips({
  363. title: '已取消!'
  364. });
  365. }
  366. }
  367. })
  368. }
  369. })
  370. },
  371. getAddress() {
  372. let that = this;
  373. that.$wechat.openAddress().then(userInfo => {
  374. // open();
  375. editAddress({
  376. realName: userInfo.userName,
  377. phone: userInfo.telNumber,
  378. address: {
  379. province: userInfo.provinceName,
  380. city: userInfo.cityName,
  381. district: userInfo.countryName,
  382. cityId: 0
  383. },
  384. detail: userInfo.detailInfo,
  385. postCode: userInfo.postalCode,
  386. status: true
  387. })
  388. .then(() => {
  389. that.$util.Tips({
  390. title: "添加成功",
  391. icon: 'success'
  392. }, function() {
  393. // close();
  394. that.getEquipmentList();
  395. });
  396. })
  397. .catch(err => {
  398. // close();
  399. return that.$util.Tips({
  400. title: err || "添加失败"
  401. });
  402. });
  403. });
  404. },
  405. goIndex(id,code) {
  406. infoApi.bindDefaultEqu({
  407. memberId: this.uid,
  408. id: id
  409. }).then(res => {
  410. // this.$store.commit("DEVICE_ID", res.data.AddressApi
  411. // uni.setStorageSync('deviceCode',code)
  412. this.$store.commit("DEVICE_CODE", code)
  413. uni.switchTab({
  414. url: '/pages/index/index'
  415. })
  416. }).catch(err => {
  417. return this.$util.Tips({
  418. title: err
  419. });
  420. });
  421. },
  422. addEqu() {
  423. uni.navigateTo({
  424. url: '/pages/equ_list/add_equ'
  425. })
  426. }
  427. }
  428. }
  429. </script>
  430. <style lang="scss" scoped>
  431. .swiper{
  432. height: 100vh;
  433. swiper{
  434. height: 100%;
  435. image{
  436. width: 100%;
  437. height: 100%;
  438. }
  439. }
  440. }
  441. .address-management {
  442. padding: 20rpx 0;
  443. margin-top: var(--status-bar-height);
  444. }
  445. .address-management.fff {
  446. background-color: #F7F7F7;
  447. height: 1300rpx
  448. }
  449. .line {
  450. width: 100%;
  451. height: 3rpx;
  452. image {
  453. width: 100%;
  454. height: 100%;
  455. display: block;
  456. }
  457. }
  458. .address-management .item {
  459. background-color: #fff;
  460. padding: 0 20rpx;
  461. margin-bottom: 20rpx;
  462. }
  463. .address-management .content_box_top {
  464. display: flex;
  465. // justify-content: space-between;
  466. align-items: center;
  467. }
  468. .address-management .content_box_top .avatar {
  469. width: 96rpx;
  470. height: 96rpx;
  471. }
  472. .address-management .item .content_box_top .address {
  473. flex: 1;
  474. padding: 35rpx 0;
  475. border-bottom: 1rpx solid #eee;
  476. font-size: 28rpx;
  477. color: #282828;
  478. display: flex;
  479. justify-content: space-between;
  480. align-items: center;
  481. margin-left: 32rpx;
  482. }
  483. .address-management .item .content_box_top .address-left {
  484. width: 90%;
  485. }
  486. .address-management .item .content_box_top .address image {
  487. width: 32rpx;
  488. height: 32rpx;
  489. }
  490. .address-management .item .address .consignee {
  491. font-size: 28rpx;
  492. font-weight: bold;
  493. margin-bottom: 8rpx;
  494. display: flex;
  495. align-items: center;
  496. }
  497. .address-management .item .address .consignee .online-box {
  498. margin-left: 25rpx;
  499. width: 50rpx;
  500. height: 30rpx;
  501. }
  502. .address-management .item .address .consignee .online-box image {
  503. width: 100%;
  504. height: 100%;
  505. }
  506. .address-management .item .operation {
  507. height: 83rpx;
  508. font-size: 28rpx;
  509. color: #282828;
  510. }
  511. .address-management .item .operation .radio text {
  512. margin-left: 13rpx;
  513. }
  514. .address-management .item .operation .iconfont {
  515. color: #2c2c2c;
  516. font-size: 35rpx;
  517. vertical-align: -2rpx;
  518. margin-right: 10rpx;
  519. }
  520. .address-management .item .operation .iconfont.icon-shanchu {
  521. margin-left: 35rpx;
  522. font-size: 38rpx;
  523. }
  524. .footer {
  525. display: flex;
  526. align-items: center;
  527. justify-content: center;
  528. position: fixed;
  529. bottom: 44rpx;
  530. width: 100%;
  531. height: 98rpx;
  532. line-height: 98rpx;
  533. text-align: center;
  534. background-color: #fff;
  535. }
  536. .footer image {
  537. width: 32rpx;
  538. height: 32rpx;
  539. margin-right: 16rpx;
  540. }
  541. </style>