index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. <template>
  2. <view class="container">
  3. <view class="status_bar"></view>
  4. <!-- 轮播图 start -->
  5. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  6. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
  7. @click="bannerNavToUrl(item)">
  8. <image :src="item.pic" />
  9. </swiper-item>
  10. </swiper>
  11. <!-- 轮播图 end -->
  12. <!-- 认证提示 statr-->
  13. <view class="rznow flex">
  14. <view class="rztit">
  15. 您尚未完成身份认证,前往认证>>
  16. </view>
  17. <view class="rzbtn">
  18. 立即认证
  19. </view>
  20. </view>
  21. <!-- 认证提示 ed-->
  22. <!-- 功能区 start-->
  23. <view class="gn-wrap flex">
  24. <view class="gn-icon flex">
  25. <image src="../../static/icon/in1.png" mode="heightFix"></image>
  26. </view>
  27. <view class="gn-tit">
  28. <view class="">
  29. 租电
  30. </view>
  31. <view class="tit-jj">
  32. 以租代购 方便省钱
  33. </view>
  34. </view>
  35. <view class="gn-btn">
  36. 立即租电
  37. </view>
  38. </view>
  39. <view class="gn-wrap flex">
  40. <view class="gn-icon flex">
  41. <image src="../../static/icon/in2.png" mode="heightFix"></image>
  42. </view>
  43. <view class="gn-tit">
  44. <view class="">
  45. 配件购买
  46. </view>
  47. <view class="tit-jj">
  48. 扫码租电
  49. </view>
  50. </view>
  51. <view class="gn-btn">
  52. 立即购买
  53. </view>
  54. </view>
  55. <!-- 功能区 ed-->
  56. <!-- 附近门店 start -->
  57. <view class="fjmd">
  58. <image src="../../static/img/md.png" mode=""></image>
  59. </view>
  60. <!-- 附近门店 end -->
  61. <!-- 使用攻略 start -->
  62. <view class="sygl">
  63. <view class="sy-top">
  64. <image src="../../static/icon/gl-top.png" mode=""></image>
  65. <view class="top-tit">
  66. 使用攻略
  67. </view>
  68. </view>
  69. <view class="sy-content flex">
  70. <view class="content-item flex">
  71. <image src="../../static/icon/sy1.png" mode="" class="sy-icon"></image>
  72. <view class="">
  73. 注册账号
  74. </view>
  75. </view>
  76. <image src="../../static/icon/jt.png" mode="" class="jt"></image>
  77. <view class="content-item flex">
  78. <image src="../../static/icon/sy2.png" mode="" class="sy-icon"></image>
  79. <view class="">
  80. 实名认证
  81. </view>
  82. </view>
  83. <image src="../../static/icon/jt.png" mode="" class="jt"></image>
  84. <view class="content-item flex">
  85. <image src="../../static/icon/sy3.png" mode="" class="sy-icon"></image>
  86. <view class="">
  87. 购买租电
  88. </view>
  89. </view>
  90. <image src="../../static/icon/jt.png" mode="" class="jt"></image>
  91. <view class="content-item flex">
  92. <image src="../../static/icon/sy4.png" mode="" class="sy-icon"></image>
  93. <view class="">
  94. 开始使用
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. <!-- 使用攻略 ed-->
  100. </view>
  101. </template>
  102. <script>
  103. import {
  104. mapState,
  105. mapMutations
  106. } from 'vuex';
  107. import {
  108. share
  109. } from '@/api/wx';
  110. import {
  111. loadIndexs,
  112. articleList,
  113. notify,
  114. guide_map
  115. } from '@/api/index.js';
  116. import {
  117. storeList,
  118. } from '@/api/shop.js';
  119. import onUser from "./indexComponents/onUser.vue"
  120. import noUser from "./indexComponents/noUser.vue"
  121. // #ifdef MP-WEIXIN
  122. import {
  123. openGetAddress
  124. } from '@/utils/rocessor.js';
  125. // #endif
  126. export default {
  127. components: {
  128. onUser,
  129. noUser
  130. },
  131. data() {
  132. return {
  133. carouselList: [],//轮播图
  134. alertImgMapIndex: 0, //引导图流程次数
  135. showAlertMap: false, //是否显示引导图
  136. userOn: 0, //加载显示页面0不加载1加载已购买车辆页面2加载未购买商品页面
  137. articleNum: 0, //消息数
  138. notifyNum: 0, //警报数
  139. follow: 0, //0为未查询1为关注,2为未关注
  140. // #ifndef APP
  141. loadFollow: false, //判断是否已经提示过关注公众号
  142. // #endif
  143. loadShopData: false, //是否已经加载过商家信息
  144. alertImgMapList: [], //引导图列表
  145. notifyTime: '', //定时器获取消息
  146. shareData: {}, //分享数据
  147. };
  148. },
  149. computed: {
  150. ...mapState('user', ['hasLogin', 'userInfo']),
  151. ...mapState(['firstUse']),
  152. ...mapState('shop', ['shopDetail']),
  153. notify() {
  154. return this.notifyNum + this.articleNum
  155. }
  156. },
  157. // 切换或显示后变动tabbar颜色
  158. onHide() {
  159. console.log('隐藏');
  160. uni.setTabBarStyle({
  161. backgroundColor: '#FFFFFF'
  162. })
  163. if (this.userOn == 1) {
  164. this.$refs.onuser.outGetCartInfo()
  165. }
  166. // 关闭消息定时器
  167. clearInterval(this.notifyTime)
  168. },
  169. onLoad: function(option) {
  170. // #ifndef MP
  171. if (option.spread) {
  172. // 存储其他邀请人
  173. uni.setStorageSync('spread', option.spread);
  174. }
  175. // #endif
  176. // #ifdef MP
  177. if (option.scene) {
  178. // 存储小程序邀请人
  179. uni.setStorage({
  180. key: 'spread_code',
  181. data: option.scene
  182. });
  183. }
  184. // #endif
  185. // 初始化商家
  186. // this.storeList({})
  187. // 获取定位数据
  188. this.getlocation();
  189. // 加载分享信息
  190. // this.share()
  191. },
  192. onShow() {
  193. this.loadIndexs();
  194. // 判断是否有用户如果是则显示
  195. if (this.userOn == 1) {
  196. this.$refs.onuser.setTabbar()
  197. this.$refs.onuser.onStartGetCartInfo()
  198. }
  199. },
  200. onReady() {
  201. // 判断是否为用户首次加载
  202. if (!this.firstUse) {
  203. this.showAlertMap = true;
  204. this.guide_map();
  205. uni.hideTabBar();
  206. }
  207. },
  208. // #ifdef MP
  209. onShareAppMessage(options) {
  210. // 设置菜单中的转发按钮触发转发事件时的转发内容
  211. let pages = getCurrentPages(); //获取加载的页面
  212. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  213. let url = currentPage.route; //当前页面url
  214. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  215. let shareObj = {
  216. title: this.shareData.title, // 默认是小程序的名称(可以写slogan等)
  217. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  218. imageUrl: this.shareData.img,
  219. desc: this.shareData.synopsis,
  220. success: function(res) {
  221. // 转发成功之后的回调
  222. if (res.errMsg == 'shareAppMessage:ok') {}
  223. },
  224. fail: function() {
  225. // 转发失败之后的回调
  226. if (res.errMsg == 'shareAppMessage:fail cancel') {
  227. // 用户取消转发
  228. } else if (res.errMsg == 'shareAppMessage:fail') {
  229. // 转发失败,其中 detail message 为详细失败信息
  230. }
  231. }
  232. };
  233. // 判断是否可以邀请
  234. if (this.userInfo.uid) {
  235. shareObj.path += '&spread=' + this.userInfo.uid;
  236. }
  237. return shareObj;
  238. },
  239. // #endif
  240. methods: {
  241. ...mapMutations('user', ['setAddress']),
  242. // #ifdef APP
  243. ...mapMutations(['setFx']),
  244. // #endif
  245. ...mapMutations(['setFirstUse']),
  246. ...mapMutations('shop', ['setShopInfo']),
  247. // 获取引导图
  248. guide_map() {
  249. guide_map().then((e) => {
  250. this.alertImgMapList = e.data;
  251. console.log(e);
  252. }).catch((e) => {
  253. console.log(e);
  254. })
  255. },
  256. showcartAlert() {
  257. console.log(this.myCartList[this.chickedMyCart]);
  258. },
  259. // 首次加载点击事件
  260. alertClick(e) {
  261. // 关闭弹窗
  262. this.showAlertMap = false
  263. uni.showTabBar()
  264. // 设置已经加载过引导图
  265. this.setFirstUse(true)
  266. },
  267. // 获取经纬度
  268. getlocation() {
  269. let obj = this;
  270. // #ifdef H5 || APP
  271. uni.getLocation({
  272. type: 'gcj02',
  273. success(e) {
  274. obj.getlocationSetInit(e)
  275. },
  276. fail(e) {
  277. if(e.errCode==22){
  278. uni.showModal({
  279. title: '定位开启错误',
  280. content: '请查看是否已经开启定位服务',
  281. showCancel: false,
  282. });
  283. }
  284. console.log(e, 'cw');
  285. }
  286. })
  287. // #endif
  288. // #ifdef MP-WEIXIN
  289. openGetAddress().then((e) => {
  290. console.log("授权");
  291. wx.startLocationUpdateBackground({
  292. type: 'gcj02',
  293. success: (e) => {
  294. console.log(e);
  295. // 调用鉴定位置变化事件
  296. wx.onLocationChange((data) => {
  297. obj.getlocationSetInit(data)
  298. })
  299. },
  300. fail() {
  301. // uni.getLocation({
  302. // type: 'gcj02',
  303. // success(e) {
  304. // obj.getlocationSetInit(e)
  305. // },
  306. // fail(e) {
  307. // console.log(e, 'cw');
  308. // }
  309. // })
  310. }
  311. })
  312. })
  313. // #endif
  314. },
  315. // 获取经纬度完毕后回调处理
  316. getlocationSetInit(data) {
  317. const obj = this;
  318. try {
  319. console.log(data, '位置数据');
  320. // 保存当前经纬度
  321. obj.setAddress({
  322. latitude: data.latitude,
  323. longitude: data.longitude
  324. })
  325. // 判断是否已经加载过最近商家信息
  326. if (!obj.loadShopData) {
  327. obj.storeList({
  328. latitude: data.latitude,
  329. longitude: data.longitude
  330. })
  331. obj.loadShopData = true;
  332. }
  333. } catch (e) {
  334. console.log(e, 'cww');
  335. }
  336. },
  337. // 初始化加载商家数据
  338. storeList(data) {
  339. let obj = this;
  340. storeList(data).then((e) => {
  341. // console.log(e.data.list, '商家数据列表');
  342. // console.log(e.data.list.length > 0, '商家数据结果');
  343. // 保存商店数据
  344. if (e.data.list.length > 0) {
  345. obj.setShopInfo(e.data.list[0]);
  346. obj.$nextTick(() => {
  347. if (obj.userOn == 2) {
  348. obj.$refs.nouser.init()
  349. }
  350. })
  351. }
  352. }).catch((e) => {
  353. console.log(e);
  354. })
  355. },
  356. // 首页初始化
  357. loadIndexs() {
  358. const that = this;
  359. // 获取首页数据
  360. loadIndexs({
  361. store_id: that.shopDetail.id
  362. }).then((e) => {
  363. // #ifdef APP
  364. if(+e.data.app_auth==0){
  365. that.setFx(true)
  366. }
  367. // #endif
  368. // #ifdef H5 || MP
  369. // 判断是否已经关注了公众号
  370. if (e.data.subscribe) {
  371. that.follow = 1
  372. } else {
  373. // 设置已经提示过
  374. that.follow = 2
  375. // 判断是否未提示过
  376. if (!that.loadFollow) {
  377. that.loadFollow = true;
  378. uni.showModal({
  379. title: '提示',
  380. content: '您未关注公众号是否马上关注',
  381. cancelText: '取消',
  382. confirmText: '关注',
  383. success: res => {
  384. if (res.confirm) {
  385. uni.navigateTo({
  386. url: './follow',
  387. });
  388. }
  389. },
  390. });
  391. }
  392. }
  393. // #endif
  394. // 用户车辆大于0则显示用户车辆信息
  395. if (e.data.is_car > 0) {
  396. that.userOn = 1;
  397. // 完成加载后再加载方法防止节点未渲染完成无法找到节点对象
  398. that.$nextTick(function() {
  399. // 刷新用户数据
  400. that.$refs.onuser.loadCard();
  401. that.$refs.onuser.setTabbar();
  402. })
  403. } else {
  404. that.userOn = 2;
  405. that.$nextTick(function() {
  406. // 刷新用户数据
  407. that.$refs.nouser.init()
  408. })
  409. }
  410. }).catch((e) => {
  411. console.log(e);
  412. })
  413. // 判断是否已经用户登录
  414. if (that.hasLogin) {
  415. if (that.notifyTime) {
  416. clearInterval(that.notifyTime)
  417. }
  418. that.getNotfyNum();
  419. that.notifyTime = setInterval(() => {
  420. that.getNotfyNum();
  421. }, 60000)
  422. }
  423. },
  424. getNotfyNum() {
  425. const that = this;
  426. // 查询消息数量
  427. articleList({}, 1).then((e) => {
  428. that.articleNum = +e.data.not_read_count
  429. })
  430. notify().then((e) => {
  431. that.notifyNum = +e.data.not_read_count
  432. })
  433. },
  434. navTo(url) {
  435. uni.navigateTo({
  436. url: url
  437. })
  438. }
  439. },
  440. };
  441. </script>
  442. <style lang="scss">
  443. page {
  444. background: #ffff;
  445. min-height: 100%;
  446. height: auto;
  447. }
  448. // 顶部搜索
  449. .top-search {
  450. height: 80rpx;
  451. padding: 0 20rpx;
  452. background-color: #fff;
  453. .top-logo {
  454. width: 50rpx;
  455. // height: 50rpx;
  456. margin-right: 10rpx;
  457. image {
  458. width: 48rpx;
  459. }
  460. }
  461. .search-box {
  462. justify-content: center;
  463. width: 698rpx;
  464. height: 60rpx;
  465. background: #EEEEEE;
  466. // box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
  467. border-radius: 30rpx;
  468. .search {
  469. width: 34rpx;
  470. height: 34rpx;
  471. }
  472. .search-font {
  473. margin-left: 14rpx;
  474. font-size: 28rpx;
  475. font-family: PingFang SC;
  476. font-weight: 500;
  477. color: #CBCBCB;
  478. }
  479. }
  480. }
  481. // 顶部轮播图
  482. .top-swiper {
  483. width: 750rpx;
  484. height: 473rpx;
  485. // margin: 20rpx 0 0;
  486. image {
  487. width: 750rpx;
  488. height: 473rpx;
  489. }
  490. }
  491. .jg {
  492. height: 20rpx;
  493. background: #F8F8F8;
  494. }
  495. // 分类
  496. .cate-section {
  497. justify-content: space-around;
  498. background-color: #fff;
  499. padding: 0rpx 0 30rpx;
  500. .cate-item {
  501. flex-grow: 0;
  502. width: 20%;
  503. flex-direction: column;
  504. text-align: center;
  505. align-items: center;
  506. justify-content: center;
  507. .img-wrapper {
  508. width: 112rpx;
  509. height: 112rpx;
  510. border-radius: 20rpx;
  511. position: relative;
  512. image {
  513. width: 112rpx;
  514. height: 112rpx;
  515. position: absolute;
  516. left: 50%;
  517. top: 50%;
  518. transform: translate(-50%, -50%);
  519. }
  520. }
  521. .item-title {
  522. margin-top: 15rpx;
  523. font-size: 26rpx;
  524. font-weight: 500;
  525. color: #666666;
  526. }
  527. }
  528. }
  529. .rznow {
  530. font-weight: 500;
  531. font-size: 26rpx;
  532. color: #FFFFFF;
  533. background-color: #78797a;
  534. height: 74rpx;
  535. padding: 0 42rpx 0 52rpx;
  536. .rztit {
  537. line-height: 74rpx;
  538. }
  539. .rzbtn {
  540. width: 127rpx;
  541. height: 47rpx;
  542. text-align: center;
  543. line-height: 47rpx;
  544. background: #35d9b7;
  545. border-radius: 24rpx;
  546. font-size: 22rpx;
  547. }
  548. }
  549. .gn-wrap {
  550. margin: 45rpx auto;
  551. width: 670rpx;
  552. height: 219rpx;
  553. background: #FFFFFF;
  554. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50,50,52,0.06);
  555. border-radius: 30rpx;
  556. padding-right: 47rpx;
  557. .gn-icon {
  558. flex-shrink: 0;
  559. width: 210rpx;
  560. height: 100%;
  561. justify-content: center;
  562. image {
  563. height: 112rpx;
  564. }
  565. }
  566. .gn-tit {
  567. flex-grow: 1;
  568. font-weight: bold;
  569. color: #333333;
  570. font-size: 36rpx;
  571. flex-direction: column;
  572. justify-content: center;
  573. align-items: flex-start;
  574. .tit-jj {
  575. font-size: 25rpx;
  576. font-weight: 500;
  577. color: #666666;
  578. padding-top: 32rpx;
  579. }
  580. }
  581. .gn-btn {
  582. flex-shrink: 0;
  583. width: 127rpx;
  584. border: 1px solid $base-color;
  585. border-radius: 28rpx;
  586. font-size: 25rpx;
  587. font-weight: 500;
  588. color: $base-color;
  589. line-height: 55rpx;
  590. text-align: center;
  591. }
  592. }
  593. .fjmd {
  594. width: 708rpx;
  595. height: 288rpx;
  596. margin: 20rpx auto;
  597. image {
  598. width: 100%;
  599. height: 100%;
  600. }
  601. }
  602. .sygl {
  603. .sy-top {
  604. position: relative;
  605. height: 100rpx;
  606. image {
  607. width: 369rpx;
  608. height: 8rpx;
  609. position: absolute;
  610. top: 0;
  611. bottom: 0;
  612. left: 0;
  613. right: 0;
  614. margin: auto;
  615. }
  616. .top-tit {
  617. font-size: 32rpx;
  618. font-weight: bold;
  619. color: #4A2723;
  620. text-align: center;
  621. line-height: 100rpx;
  622. }
  623. }
  624. .sy-content {
  625. padding: 0 10rpx 65rpx ;
  626. .content-item {
  627. flex-grow: 1;
  628. flex-direction: column;
  629. justify-content: center;
  630. align-items: center;
  631. font-size: 22rpx;
  632. font-weight: 500;
  633. color: #4A2723;
  634. }
  635. .sy-icon {
  636. width: 90rpx;
  637. height: 90rpx;
  638. margin-bottom: 15rpx;
  639. }
  640. .jt {
  641. flex-shrink: 0;
  642. width: 14rpx;
  643. height: 15rpx;
  644. margin-top: 40rpx;
  645. align-self: flex-start;
  646. }
  647. }
  648. }
  649. </style>