index.vue 12 KB

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