index.vue 14 KB

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