index.vue 14 KB

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