index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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.avatar" mode="square" :show-sex="true"
  16. :sex-icon="item.sex === 1 ? 'man':'woman'"
  17. :sex-bg-color="item.sex === 1 ? 'man-primary' : 'woman-error'"></u-avatar>
  18. <view class='address' @click='goIndex(item.id,item.deviceCode,item.nickName)'>
  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. console.log(res.data,'7777777777777777777777')
  199. if(res.data.length>0){
  200. this.$set(this, 'equipmentList', res.data);
  201. }else{
  202. this.$store.commit("DEVICE_CODE", '')
  203. this.$store.commit("DEVICE_NAME", '')
  204. }
  205. this.loadTitle = '我也是有底线的';
  206. this.loading = false;
  207. }).catch(err => {
  208. this.loading = false;
  209. this.loadTitle = '加载更多';
  210. });
  211. },
  212. /**
  213. * 设置默认地址
  214. */
  215. radioChange: function(e) {
  216. const index = parseInt(e.detail.value);
  217. const item = this.equipmentList[index];
  218. if (item === undefined) {
  219. return this.$util.Tips({
  220. title: '您设置的默认地址不存在!'
  221. });
  222. }
  223. infoApi.bindDefaultEqu({
  224. memberId: this.uid,
  225. id: item.id
  226. }).then(res => {
  227. if (res.code === 0 && res.data.bindCount === 1) {
  228. for (let i = 0, len = this.equipmentList.length; i < len; i++) {
  229. if (i === index) {
  230. this.equipmentList[i].status = true;
  231. } else {
  232. this.equipmentList[i].status = false;
  233. }
  234. }
  235. this.$util.Tips({
  236. title: '设置成功',
  237. icon: 'success'
  238. }, () => {
  239. this.$store.commit("DEVICE_ID", res.data.deviceId);
  240. // this.$set(this, 'equipmentList', this.equipmentList);
  241. this.getEquipmentList()
  242. });
  243. }
  244. }).catch(err => {
  245. return this.$util.Tips({
  246. title: err
  247. });
  248. });
  249. },
  250. /**
  251. * 编辑地址
  252. */
  253. editAddress: function(id) {
  254. let cartId = this.cartId,
  255. pinkId = this.pinkId,
  256. couponId = this.couponId;
  257. this.cartId = '';
  258. this.pinkId = '';
  259. this.couponId = '';
  260. uni.navigateTo({
  261. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' +
  262. pinkId + '&couponId=' +
  263. couponId + '&secKill' + this.secKill + '&combination=' + this.combination +
  264. '&bargain=' + this.bargain
  265. })
  266. },
  267. /**
  268. * 删除设备
  269. */
  270. delEquipment(item, index) {
  271. const address = this.equipmentList[index];
  272. if (address === undefined) {
  273. return this.$util.Tips({
  274. title: '您删除的地址不存在!'
  275. });
  276. }
  277. console.log('点击了')
  278. // #ifdef APP-PLUS || H5
  279. uni.showModal({
  280. title: '提示',
  281. content: '是否确认删除此设备?',
  282. success: res => {
  283. if (res.confirm) {
  284. let params = {
  285. memberId: this.uid,
  286. id: item.id
  287. }
  288. infoApi.bindDelete(params).then(res => {
  289. this.$util.Tips({
  290. title: '删除成功',
  291. icon: 'success'
  292. }, () => {
  293. this.equipmentList.splice(index, 1);
  294. this.getEquipmentList()
  295. });
  296. }).catch(err => {
  297. return this.$util.Tips({
  298. title: err
  299. });
  300. });
  301. }
  302. }
  303. });
  304. // #endif
  305. // #ifdef MP
  306. Dialog.confirm({
  307. title: '',
  308. message: '是否确认删除此设备?',
  309. context: this,
  310. })
  311. .then(() => {
  312. let params = {
  313. memberId: this.uid,
  314. id: item.id
  315. }
  316. infoApi.bindDelete(params).then(res => {
  317. this.$util.Tips({
  318. title: '删除成功',
  319. icon: 'success'
  320. }, () => {
  321. this.equipmentList.splice(index, 1);
  322. this.getEquipmentList()
  323. });
  324. }).catch(err => {
  325. return this.$util.Tips({
  326. title: err
  327. });
  328. });
  329. })
  330. .catch(() => {
  331. // on cancel
  332. });
  333. // #endif
  334. },
  335. /**
  336. * 新增地址
  337. */
  338. addAddress: function() {
  339. this.cartId = '';
  340. this.pinkId = '';
  341. this.couponId = '';
  342. uni.navigateTo({
  343. url: '/pages/users/user_address/index?preOrderNo=' + this.preOrderNo
  344. })
  345. },
  346. // TODO 芋艿:微信导入;
  347. /**
  348. * 导入微信地址(小程序)
  349. */
  350. getWxAddress: function() {
  351. let that = this;
  352. uni.authorize({
  353. scope: 'scope.address',
  354. success: function(res) {
  355. uni.chooseAddress({
  356. success: function(res) {
  357. let addressP = {};
  358. addressP.province = res.provinceName;
  359. addressP.city = res.cityName;
  360. addressP.district = res.countyName;
  361. addressP.cityId = 0;
  362. editAddress({
  363. address: addressP,
  364. status: true,
  365. realName: res.userName,
  366. postCode: res.postalCode,
  367. phone: res.telNumber,
  368. detail: res.detailInfo,
  369. id: 0
  370. //type: 1//区别城市id(导入微信地址无城市id需要后台自己查找);
  371. }).then(res => {
  372. that.$util.Tips({
  373. title: "添加成功",
  374. icon: 'success'
  375. }, function() {
  376. that.getEquipmentList(true);
  377. });
  378. }).catch(err => {
  379. return that.$util.Tips({
  380. title: err
  381. });
  382. });
  383. },
  384. fail: function(res) {
  385. if (res.errMsg == 'chooseAddress:cancel') return that.$util
  386. .Tips({
  387. title: '取消选择'
  388. });
  389. },
  390. })
  391. },
  392. fail: function(res) {
  393. uni.showModal({
  394. title: '您已拒绝导入微信地址权限',
  395. content: '是否进入权限管理,调整授权?',
  396. success(res) {
  397. if (res.confirm) {
  398. uni.openSetting({
  399. success: function(res) {
  400. console.log(res.authSetting)
  401. }
  402. });
  403. } else if (res.cancel) {
  404. return that.$util.Tips({
  405. title: '已取消!'
  406. });
  407. }
  408. }
  409. })
  410. }
  411. })
  412. },
  413. getAddress() {
  414. let that = this;
  415. that.$wechat.openAddress().then(userInfo => {
  416. // open();
  417. editAddress({
  418. realName: userInfo.userName,
  419. phone: userInfo.telNumber,
  420. address: {
  421. province: userInfo.provinceName,
  422. city: userInfo.cityName,
  423. district: userInfo.countryName,
  424. cityId: 0
  425. },
  426. detail: userInfo.detailInfo,
  427. postCode: userInfo.postalCode,
  428. status: true
  429. })
  430. .then(() => {
  431. that.$util.Tips({
  432. title: "添加成功",
  433. icon: 'success'
  434. }, function() {
  435. // close();
  436. that.getEquipmentList();
  437. });
  438. })
  439. .catch(err => {
  440. // close();
  441. return that.$util.Tips({
  442. title: err || "添加失败"
  443. });
  444. });
  445. });
  446. },
  447. goIndex(id,code,name) {
  448. infoApi.bindDefaultEqu({
  449. memberId: this.uid,
  450. id: id
  451. }).then(res => {
  452. // this.$store.commit("DEVICE_ID", res.data.AddressApi
  453. // uni.setStorageSync('deviceCode',code)
  454. this.$store.commit("DEVICE_CODE", code)
  455. this.$store.commit("DEVICE_NAME", name)
  456. uni.switchTab({
  457. url: '/pages/index/index'
  458. })
  459. }).catch(err => {
  460. return this.$util.Tips({
  461. title: err
  462. });
  463. });
  464. },
  465. addEqu() {
  466. uni.navigateTo({
  467. url: '/pages/equ_list/add_equ'
  468. })
  469. }
  470. }
  471. }
  472. </script>
  473. <style lang="scss" scoped>
  474. .swiper{
  475. height: 100vh;
  476. swiper{
  477. height: 100%;
  478. image{
  479. width: 100%;
  480. height: 100%;
  481. }
  482. }
  483. }
  484. .address-management {
  485. padding: 20rpx 0;
  486. // margin-top: var(--status-bar-height);
  487. }
  488. .address-management.fff {
  489. background-color: #F7F7F7;
  490. height: 1300rpx
  491. }
  492. .line {
  493. width: 100%;
  494. height: 3rpx;
  495. image {
  496. width: 100%;
  497. height: 100%;
  498. display: block;
  499. }
  500. }
  501. .address-management .item {
  502. background-color: #fff;
  503. padding: 0 20rpx;
  504. margin-bottom: 20rpx;
  505. }
  506. .address-management .content_box_top {
  507. display: flex;
  508. // justify-content: space-between;
  509. align-items: center;
  510. }
  511. .address-management .content_box_top .avatar {
  512. width: 96rpx;
  513. height: 96rpx;
  514. }
  515. .address-management .item .content_box_top .address {
  516. flex: 1;
  517. padding: 35rpx 0;
  518. border-bottom: 1rpx solid #eee;
  519. font-size: 28rpx;
  520. color: #282828;
  521. display: flex;
  522. justify-content: space-between;
  523. align-items: center;
  524. margin-left: 32rpx;
  525. }
  526. .address-management .item .content_box_top .address-left {
  527. width: 90%;
  528. }
  529. .address-management .item .content_box_top .address image {
  530. width: 32rpx;
  531. height: 32rpx;
  532. }
  533. .address-management .item .address .consignee {
  534. font-size: 28rpx;
  535. font-weight: bold;
  536. margin-bottom: 8rpx;
  537. display: flex;
  538. align-items: center;
  539. }
  540. .address-management .item .address .consignee .online-box {
  541. margin-left: 25rpx;
  542. width: 50rpx;
  543. height: 30rpx;
  544. }
  545. .address-management .item .address .consignee .online-box image {
  546. width: 100%;
  547. height: 100%;
  548. }
  549. .address-management .item .operation {
  550. height: 83rpx;
  551. font-size: 28rpx;
  552. color: #282828;
  553. }
  554. .address-management .item .operation .radio text {
  555. margin-left: 13rpx;
  556. }
  557. .address-management .item .operation .iconfont {
  558. color: #2c2c2c;
  559. font-size: 35rpx;
  560. vertical-align: -2rpx;
  561. margin-right: 10rpx;
  562. }
  563. .address-management .item .operation .iconfont.icon-shanchu {
  564. margin-left: 35rpx;
  565. font-size: 38rpx;
  566. }
  567. .footer {
  568. display: flex;
  569. align-items: center;
  570. justify-content: center;
  571. position: fixed;
  572. bottom: 44rpx;
  573. width: 100%;
  574. height: 98rpx;
  575. line-height: 98rpx;
  576. text-align: center;
  577. background-color: #fff;
  578. }
  579. .footer image {
  580. width: 32rpx;
  581. height: 32rpx;
  582. margin-right: 16rpx;
  583. }
  584. </style>