index.vue 10 KB

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