index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <view class="indexBox">
  3. <view class="navbox" v-if="userOn!=1">
  4. <view class="flex topIconBox">
  5. <image @click="navTo('/pages/index/shopTab?type=1')" class="topIcon" src="../../static/icon/shop.png"
  6. mode="widthFix"></image>
  7. <image @click="navTo('/pages/index/notice')" class="topIcon" src="../../static/icon/message.png"
  8. mode="widthFix">
  9. </image>
  10. <view class="topIconNum flex" v-if="notify>0">
  11. <text>
  12. {{notify}}
  13. </text>
  14. </view>
  15. </view>
  16. </view>
  17. <on-user :notify='notify' ref='onuser' v-if="userOn==1"></on-user>
  18. <no-user ref='nouser' v-if="userOn==2"></no-user>
  19. <!-- 引导图 -->
  20. <view class="alertMap" v-if='showAlertMap' @touchmove.stop.prevent="()=>{}">
  21. <swiper class="alertMapBox" :indicator-dots='true'>
  22. <swiper-item v-for="(item,index) in alertImgMapList">
  23. <image class="alertImgMap" :src="item.image" mode="heightFix">
  24. </image>
  25. </swiper-item>
  26. </swiper>
  27. <view class="postionbuttom" @click="alertClick">
  28. 关闭
  29. </view>
  30. </view>
  31. <!-- #ifndef APP -->
  32. <view class="follow flex" @click="navTo('./follow')" v-if="follow==2">
  33. <view class="">
  34. 请关注微信“绿津智能电动车”公众号
  35. </view>
  36. <view class="flex">
  37. <text>
  38. 前往关注
  39. </text>
  40. <image class="followIcon" src="../../static/icon/next2.png" mode="widthFix"></image>
  41. </view>
  42. </view>
  43. <!-- #endif -->
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. mapState,
  49. mapMutations
  50. } from 'vuex';
  51. import {
  52. share
  53. } from '@/api/wx';
  54. import {
  55. loadIndexs,
  56. articleList,
  57. notify,
  58. guide_map
  59. } from '@/api/index.js';
  60. import {
  61. storeList,
  62. } from '@/api/shop.js';
  63. import onUser from "./indexComponents/onUser.vue"
  64. import noUser from "./indexComponents/noUser.vue"
  65. // #ifdef MP-WEIXIN
  66. import {
  67. openGetAddress
  68. } from '@/utils/rocessor.js';
  69. // #endif
  70. export default {
  71. components: {
  72. onUser,
  73. noUser
  74. },
  75. data() {
  76. return {
  77. alertImgMapIndex: 0, //引导图流程次数
  78. showAlertMap: false, //是否显示引导图
  79. userOn: 0, //加载显示页面0不加载1加载已购买车辆页面2加载未购买商品页面
  80. articleNum: 0, //消息数
  81. notifyNum: 0, //警报数
  82. follow: 0, //0为未查询1为关注,2为未关注
  83. // #ifndef APP
  84. loadFollow: false, //判断是否已经提示过关注公众号
  85. // #endif
  86. loadShopData: false, //是否已经加载过商家信息
  87. alertImgMapList: [], //引导图列表
  88. notifyTime: '', //定时器获取消息
  89. shareData: {}, //分享数据
  90. };
  91. },
  92. computed: {
  93. ...mapState('user', ['hasLogin', 'userInfo']),
  94. ...mapState(['firstUse']),
  95. ...mapState('shop', ['shopDetail']),
  96. notify() {
  97. return this.notifyNum + this.articleNum
  98. }
  99. },
  100. // 切换或显示后变动tabbar颜色
  101. onHide() {
  102. console.log('隐藏');
  103. uni.setTabBarStyle({
  104. backgroundColor: '#FFFFFF'
  105. })
  106. if (this.userOn == 1) {
  107. this.$refs.onuser.outGetCartInfo()
  108. }
  109. // 关闭消息定时器
  110. clearInterval(this.notifyTime)
  111. },
  112. onLoad: function(option) {
  113. // #ifndef MP
  114. if (option.spread) {
  115. // 存储其他邀请人
  116. uni.setStorageSync('spread', option.spread);
  117. }
  118. // #endif
  119. // #ifdef MP
  120. if (option.scene) {
  121. // 存储小程序邀请人
  122. uni.setStorage({
  123. key: 'spread_code',
  124. data: option.scene
  125. });
  126. }
  127. // #endif
  128. // 初始化商家
  129. this.storeList({})
  130. // 获取定位数据
  131. this.getlocation();
  132. // 加载分享信息
  133. this.share()
  134. },
  135. onShow() {
  136. this.loadIndexs();
  137. // 判断是否有用户如果是则显示
  138. if (this.userOn == 1) {
  139. this.$refs.onuser.setTabbar()
  140. this.$refs.onuser.onStartGetCartInfo()
  141. }
  142. },
  143. onReady() {
  144. // 判断是否为用户首次加载
  145. if (!this.firstUse) {
  146. this.showAlertMap = true;
  147. this.guide_map();
  148. uni.hideTabBar();
  149. }
  150. },
  151. // #ifdef MP
  152. onShareAppMessage(options) {
  153. // 设置菜单中的转发按钮触发转发事件时的转发内容
  154. let pages = getCurrentPages(); //获取加载的页面
  155. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  156. let url = currentPage.route; //当前页面url
  157. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  158. let shareObj = {
  159. title: this.shareData.title, // 默认是小程序的名称(可以写slogan等)
  160. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  161. imageUrl: this.shareData.img,
  162. desc: this.shareData.synopsis,
  163. success: function(res) {
  164. // 转发成功之后的回调
  165. if (res.errMsg == 'shareAppMessage:ok') {}
  166. },
  167. fail: function() {
  168. // 转发失败之后的回调
  169. if (res.errMsg == 'shareAppMessage:fail cancel') {
  170. // 用户取消转发
  171. } else if (res.errMsg == 'shareAppMessage:fail') {
  172. // 转发失败,其中 detail message 为详细失败信息
  173. }
  174. }
  175. };
  176. // 判断是否可以邀请
  177. if (this.userInfo.uid) {
  178. shareObj.path += '&spread=' + this.userInfo.uid;
  179. }
  180. return shareObj;
  181. },
  182. // #endif
  183. methods: {
  184. ...mapMutations('user', ['setAddress']),
  185. // #ifdef APP
  186. ...mapMutations(['setFx']),
  187. // #endif
  188. ...mapMutations(['setFirstUse']),
  189. ...mapMutations('shop', ['setShopInfo']),
  190. share() {
  191. // console.log('加载分享');
  192. const that = this;
  193. // 请求获取默认数据
  194. share({}).then(({
  195. data
  196. }) => {
  197. // console.log('分享回调', data);
  198. that.shareData = data.data
  199. });
  200. },
  201. // 获取引导图
  202. guide_map() {
  203. guide_map().then((e) => {
  204. this.alertImgMapList = e.data;
  205. console.log(e);
  206. }).catch((e) => {
  207. console.log(e);
  208. })
  209. },
  210. showcartAlert() {
  211. console.log(this.myCartList[this.chickedMyCart]);
  212. },
  213. // 首次加载点击事件
  214. alertClick(e) {
  215. // 关闭弹窗
  216. this.showAlertMap = false
  217. uni.showTabBar()
  218. // 设置已经加载过引导图
  219. this.setFirstUse(true)
  220. },
  221. // 获取经纬度
  222. getlocation() {
  223. let obj = this;
  224. // #ifdef H5 || APP
  225. uni.getLocation({
  226. type: 'gcj02',
  227. success(e) {
  228. obj.getlocationSetInit(e)
  229. },
  230. fail(e) {
  231. if(e.errCode==22){
  232. uni.showModal({
  233. title: '定位开启错误',
  234. content: '请查看是否已经开启定位服务',
  235. showCancel: false,
  236. });
  237. }
  238. console.log(e, 'cw');
  239. }
  240. })
  241. // #endif
  242. // #ifdef MP-WEIXIN
  243. openGetAddress().then((e) => {
  244. console.log("授权");
  245. wx.startLocationUpdateBackground({
  246. type: 'gcj02',
  247. success: (e) => {
  248. console.log(e);
  249. // 调用鉴定位置变化事件
  250. wx.onLocationChange((data) => {
  251. obj.getlocationSetInit(data)
  252. })
  253. },
  254. fail() {
  255. // uni.getLocation({
  256. // type: 'gcj02',
  257. // success(e) {
  258. // obj.getlocationSetInit(e)
  259. // },
  260. // fail(e) {
  261. // console.log(e, 'cw');
  262. // }
  263. // })
  264. }
  265. })
  266. })
  267. // #endif
  268. },
  269. // 获取经纬度完毕后回调处理
  270. getlocationSetInit(data) {
  271. const obj = this;
  272. try {
  273. console.log(data, '位置数据');
  274. // 保存当前经纬度
  275. obj.setAddress({
  276. latitude: data.latitude,
  277. longitude: data.longitude
  278. })
  279. // 判断是否已经加载过最近商家信息
  280. if (!obj.loadShopData) {
  281. obj.storeList({
  282. latitude: data.latitude,
  283. longitude: data.longitude
  284. })
  285. obj.loadShopData = true;
  286. }
  287. } catch (e) {
  288. console.log(e, 'cww');
  289. }
  290. },
  291. // 初始化加载商家数据
  292. storeList(data) {
  293. let obj = this;
  294. storeList(data).then((e) => {
  295. // console.log(e.data.list, '商家数据列表');
  296. // console.log(e.data.list.length > 0, '商家数据结果');
  297. // 保存商店数据
  298. if (e.data.list.length > 0) {
  299. obj.setShopInfo(e.data.list[0]);
  300. obj.$nextTick(() => {
  301. if (obj.userOn == 2) {
  302. obj.$refs.nouser.init()
  303. }
  304. })
  305. }
  306. }).catch((e) => {
  307. console.log(e);
  308. })
  309. },
  310. // 首页初始化
  311. loadIndexs() {
  312. const that = this;
  313. // 获取首页数据
  314. loadIndexs({
  315. store_id: that.shopDetail.id
  316. }).then((e) => {
  317. // #ifdef APP
  318. if(+e.data.app_auth==0){
  319. that.setFx(true)
  320. }
  321. // #endif
  322. // #ifdef H5 || MP
  323. // 判断是否已经关注了公众号
  324. if (e.data.subscribe) {
  325. that.follow = 1
  326. } else {
  327. // 设置已经提示过
  328. that.follow = 2
  329. // 判断是否未提示过
  330. if (!that.loadFollow) {
  331. that.loadFollow = true;
  332. uni.showModal({
  333. title: '提示',
  334. content: '您未关注公众号是否马上关注',
  335. cancelText: '取消',
  336. confirmText: '关注',
  337. success: res => {
  338. if (res.confirm) {
  339. uni.navigateTo({
  340. url: './follow',
  341. });
  342. }
  343. },
  344. });
  345. }
  346. }
  347. // #endif
  348. // 用户车辆大于0则显示用户车辆信息
  349. if (e.data.is_car > 0) {
  350. that.userOn = 1;
  351. // 完成加载后再加载方法防止节点未渲染完成无法找到节点对象
  352. that.$nextTick(function() {
  353. // 刷新用户数据
  354. that.$refs.onuser.loadCard();
  355. that.$refs.onuser.setTabbar();
  356. })
  357. } else {
  358. that.userOn = 2;
  359. that.$nextTick(function() {
  360. // 刷新用户数据
  361. that.$refs.nouser.init()
  362. })
  363. }
  364. }).catch((e) => {
  365. console.log(e);
  366. })
  367. // 判断是否已经用户登录
  368. if (that.hasLogin) {
  369. if (that.notifyTime) {
  370. clearInterval(that.notifyTime)
  371. }
  372. that.getNotfyNum();
  373. that.notifyTime = setInterval(() => {
  374. that.getNotfyNum();
  375. }, 60000)
  376. }
  377. },
  378. getNotfyNum() {
  379. const that = this;
  380. // 查询消息数量
  381. articleList({}, 1).then((e) => {
  382. that.articleNum = +e.data.not_read_count
  383. })
  384. notify().then((e) => {
  385. that.notifyNum = +e.data.not_read_count
  386. })
  387. },
  388. navTo(url) {
  389. uni.navigateTo({
  390. url: url
  391. })
  392. }
  393. },
  394. };
  395. </script>
  396. <style lang="scss">
  397. $paddingJg:40rpx;
  398. page,
  399. .indexBox {
  400. height: 0;
  401. min-height: 100%;
  402. }
  403. .follow {
  404. z-index: 9999;
  405. font-size: $font-base;
  406. color: #FFFFFF;
  407. padding: 20rpx 30rpx;
  408. line-height: 1;
  409. position: fixed;
  410. bottom: 0;
  411. /* #ifdef H5 */
  412. bottom: 50px;
  413. /* #endif */
  414. left: 0;
  415. right: 0;
  416. text-align: center;
  417. background-color: rgba($color: #0BBB62, $alpha: 0.75);
  418. .followIcon {
  419. width: 36rpx;
  420. height: 36rpx;
  421. }
  422. }
  423. // 弹窗引导页
  424. .alertMap {
  425. position: fixed;
  426. top: 0;
  427. left: 0;
  428. right: 0;
  429. bottom: 0;
  430. background-color: rgba($color: #000000, $alpha: 0.75);
  431. text-align: center;
  432. z-index: 9999999;
  433. .postionbuttom {
  434. position: absolute;
  435. bottom: 20rpx;
  436. left: 150rpx;
  437. right: 150rpx;
  438. background-color: $color-green;
  439. border-radius: 99rpx;
  440. color: #FFFFFF;
  441. padding: 26rpx 0;
  442. }
  443. .alertMapBox {
  444. height: 100%;
  445. padding-top: 10rpx;
  446. padding-bottom: 120rpx;
  447. }
  448. .alertImgMap {
  449. height: 100%;
  450. }
  451. }
  452. /deep/ .itemTitleBox {
  453. padding: 30rpx $paddingJg;
  454. .itemTitle {
  455. font-size: 32rpx;
  456. }
  457. .itemIcon {
  458. width: 20rpx;
  459. margin-left: 10rpx;
  460. }
  461. .tager {
  462. font-size: 24rpx;
  463. font-weight: 400;
  464. }
  465. }
  466. .container {
  467. line-height: 1;
  468. font-weight: bold;
  469. }
  470. .navbox {
  471. /* #ifdef APP */
  472. padding-top: var(--status-bar-height);
  473. /* #endif */
  474. /* #ifdef H5 || MP */
  475. padding-top: 30rpx;
  476. /* #endif */
  477. padding-bottom: 30rpx;
  478. position: fixed;
  479. top: 0;
  480. left: 0;
  481. right: 0;
  482. background-color: #FFFFFF;
  483. z-index: 99;
  484. }
  485. .topIconBox {
  486. padding: 0 $paddingJg;
  487. position: relative;
  488. .topIconNum {
  489. position: absolute;
  490. top: -10rpx;
  491. right: 20rpx;
  492. font-size: $font-sm;
  493. color: #FFFFFF;
  494. min-width: 30rpx;
  495. min-height: 30rpx;
  496. border-radius: 100rpx;
  497. background-color: $color-red;
  498. padding: 5rpx;
  499. justify-content: center;
  500. }
  501. .topIcon {
  502. width: 45rpx;
  503. height: 45rpx;
  504. }
  505. }
  506. .greenText {
  507. color: $color-green;
  508. }
  509. </style>