home.js 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. import {
  2. get,
  3. post
  4. } from '../../utils/http'
  5. import {
  6. formatActivity
  7. } from '../../utils/time'
  8. import {
  9. throttle,
  10. debounce,
  11. trackUserEvent
  12. } from '../../utils/util'
  13. var WxParse = require('../../components/local/wxParse/wxParse.js')
  14. const app = getApp()
  15. Page({
  16. /**
  17. * 页面的初始数据
  18. */
  19. jsData: {
  20. columnsHeight: [0, 0],
  21. isListLoading: false
  22. },
  23. data: {
  24. list: [],
  25. page: 1,
  26. total: 0,
  27. coupon: null,
  28. homeData: null,
  29. visible: false,
  30. posterPopup: false,
  31. isLoading: true,
  32. btmToast: true,
  33. activity: {},
  34. needReqActivity: true,
  35. topBannerCurrentSwiper: 0, // 顶部轮播图当前滑动位置
  36. cardBannerCurrentSwiper: 0, // 开卡轮播图当前滑动位置
  37. navBarData: app.globalData.navBarData,
  38. navBarBgClass: '',
  39. currentNewAcount: 0,
  40. guildMessage: false, // 顶部导航栏背景
  41. allow_invite: 0, //是否展示邀请入口,1是,0否
  42. allow_receive: 0, //是否展示再次领取奖励入口,1是,0否
  43. newAcountImage: ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220609/newAcount.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220609/vFace.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220609/showLike.png'],
  44. inviteImg: 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220811/%E4%BA%8C%E5%9B%BE/%E5%9B%BE%E7%89%87/%E9%82%80%E8%AF%B7%E8%80%85banner%402x.png', //邀请
  45. beInvitedImg: 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220811/%E4%BA%8C%E5%9B%BE/%E5%9B%BE%E7%89%87/%E7%BC%96%E7%BB%84%2010%402x.png', //被邀请
  46. matching: false,
  47. PopShow: true, //十月一弹窗显示
  48. swiperIndex: 0, //推荐项目轮播图下标
  49. classify: [], //美丽秘籍分类
  50. current: 0, //美丽秘籍下标
  51. value: '',
  52. columns: [
  53. [],
  54. []
  55. ],
  56. tempPics: [], //美丽秘籍内容列表
  57. tabClass: '', //美丽秘籍滑到顶部类名
  58. messageList: [], //消息列表
  59. notMessageTotal: 0, //未读消息数量
  60. skinInfo: "", //测服详情概要
  61. skin_type: ['干性肌肤', '中性肌肤', '油性肌肤', '混合型肌肤', '敏感肌肤', '痤疮肌肤'], //肤质:1-干性肌肤 2-中性肌肤 3-油性肌肤 4-混合型肌肤,5敏感肌肤,6 痤疮肌肤
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad: function (options) {
  67. // 获取美丽秘籍分类
  68. this.getClassify()
  69. console.log(options, 'options');
  70. if (options.fromAuthOrder && JSON.parse(options.fromAuthOrder)) {
  71. // 弹出订单确认等待loading层,用户也可主动关闭loading层
  72. this.setData({
  73. matching: true
  74. })
  75. }
  76. if (wx.getStorageSync('userInfo')) {
  77. // 调方法实时收取服务端推送过来的订单确认消息
  78. this.createSocketToReceiveMessage()
  79. }
  80. this.getInviteStatus()
  81. this.setData({
  82. visible: app.globalData.couponPopup,
  83. coupon: app.globalData.coupon,
  84. navBarHeight: app.globalData.navBarData.navBarHeight
  85. })
  86. this.getHomeData()
  87. this.check_new_record()
  88. if (wx.getStorageSync('day') != new Date().getDate()) {
  89. this.setData({
  90. posterPopup: true
  91. })
  92. }
  93. this.activityProgress()
  94. this.activityRules()
  95. wx.setStorageSync('day', new Date().getDate())
  96. if (options.click) {
  97. trackUserEvent(options.click)
  98. }
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {},
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function (e) {
  108. if (wx.getStorageSync('token') && this.data.needReqActivity) {
  109. this.getUserActivity()
  110. }
  111. this.getVersion()
  112. // 当切换了店铺时,重新请求一次数据
  113. let storeData = getApp().globalData.storeData
  114. let storeId = storeData.id || wx.getStorageSync('store_id')
  115. if (this.data.homeData && storeId != this.data.homeData.store.id && this.data.homeData.store.id) {
  116. this.getStoreInfo(storeId)
  117. }
  118. if (wx.getStorageSync('userInfo')) {
  119. // 获取消息列表
  120. this.getMessageList()
  121. // 获取未读消息数量
  122. this.getNotMessageTotal()
  123. }
  124. // 获取测服详情概要
  125. this.getSkinInfo()
  126. },
  127. //获取当前用户邀请状态
  128. getInviteStatus() {
  129. get('/api/user/power', {}, res => {
  130. this.setData({
  131. allow_invite: res.data.allow_invite,
  132. allow_receive: res.data.allow_receive,
  133. invite_id: res.data.invite_id
  134. })
  135. })
  136. },
  137. onInvite() {
  138. if (this.data.allow_receive != 1 && this.data.allow_invite != 1) {
  139. wx.showToast({
  140. title: '您还没有体验过项目,不满足参与活动条件',
  141. icon: "none"
  142. })
  143. return
  144. }
  145. wx.navigateTo({
  146. url: this.data.allow_invite == 1 ? '/pages/invitationDetails/invitationDetails' : `/pages/invitees/invitees?invite_id=${this.data.invite_id}`,
  147. })
  148. },
  149. createSocketToReceiveMessage() {
  150. if (!wx.getStorageSync('token')) {
  151. return
  152. }
  153. let token = wx.getStorageSync('token')
  154. let timer = null
  155. console.log('开始连接...')
  156. wx.connectSocket({
  157. url: `wss://ws.ijolijoli.com?access_token=${token}`,
  158. header: {
  159. 'content-type': 'application/json'
  160. },
  161. method: "GET",
  162. success: (res) => {
  163. console.log('连接成功', res)
  164. },
  165. fail: (err) => {
  166. console.log('连接失败', err)
  167. },
  168. complete: (e) => {
  169. console.log('连接完成', e)
  170. }
  171. })
  172. wx.onSocketOpen((e) => {
  173. //当WebSocket创建成功时,触发onSocketOpen事件
  174. console.log("连接已打开", e);
  175. timer = setInterval(() => {
  176. wx.sendSocketMessage({
  177. data: JSON.stringify({
  178. type: 'ping'
  179. })
  180. });
  181. }, 30000);
  182. })
  183. wx.onSocketMessage((e) => {
  184. //当客户端收到服务端发来的消息时,触发onSocketMessage事件,参数e.data包含server传递过来的数据
  185. // console.log('收到服务端消息', e.data)
  186. let data = JSON.parse(e.data);
  187. // console.log(data)
  188. // 收到服务端订单添加消息后,若订单确认loading层未关闭,则直接跳转订单确认页;否则,对服务端推送消息不做任何逻辑处理
  189. if (this.data.matching && data.data.type === 'order_add') {
  190. // console.log('关闭loading层并跳转订单确认')
  191. this.orderConfirmOnclose()
  192. wx.redirectTo({
  193. url: '/pages/confirmProjectOrder/confirmProjectOrder?id=' + data.data.order_id,
  194. })
  195. }
  196. // 收到消息通知
  197. if (data.data.type === 'instation') {
  198. // 重新获取消息列表
  199. this.getMessageList()
  200. // 重新获取未读数量
  201. this.getNotMessageTotal()
  202. }
  203. })
  204. wx.onSocketClose((e) => {
  205. //当客户端收到服务端发送的关闭连接请求时,触发onSocketClose事件
  206. console.log("连接已关闭", e);
  207. })
  208. wx.onSocketError((e) => {
  209. //如果出现连接、处理、接收、发送数据失败的时候触发onSocketError事件
  210. console.log(e);
  211. })
  212. },
  213. orderConfirmOnclose() {
  214. this.setData({
  215. matching: false
  216. })
  217. },
  218. // 获取是否需要更新
  219. getVersion() {
  220. get('api/app/version', {}, (res) => {
  221. let version = wx.getStorageSync('versionIn')
  222. if (!version || res.data.op_version != version || version == null) {
  223. wx.setStorageSync('version1', '0')
  224. wx.setStorageSync('version2', '0')
  225. wx.setStorageSync('version3', '0')
  226. wx.setStorageSync('version4', '0')
  227. wx.setStorageSync('versionIn', res.data.op_version)
  228. }
  229. })
  230. },
  231. /**
  232. * 生命周期函数--监听页面隐藏
  233. */
  234. onHide: function () {},
  235. /**
  236. * 生命周期函数--监听页面卸载
  237. */
  238. onUnload: function () {
  239. if (this.timer_) {
  240. clearInterval(this.timer_)
  241. }
  242. wx.onSocketClose((e) => {
  243. console.log('WebSocket 已关闭!')
  244. })
  245. },
  246. /**
  247. * 页面相关事件处理函数--监听用户下拉动作
  248. */
  249. onPullDownRefresh: function () {},
  250. /**
  251. * 页面上拉触底事件的处理函数
  252. */
  253. onReachBottom: function () {
  254. if (this.data.page * 10 < this.data.total) {
  255. this.getArticleList(++this.data.page)
  256. }
  257. },
  258. /**
  259. * 用户点击右上角分享
  260. */
  261. onShareAppMessage: function () {},
  262. /**
  263. * 监听页面滚动事件
  264. */
  265. onPageScroll: function (e) {
  266. let top = 6 // 超过多少像素开始显示导航栏背景
  267. let tabScrollTop = 782 //超过多少像素固定美丽秘籍tab到顶部
  268. let scrollTop = e.scrollTop
  269. let {
  270. navBarBgClass,
  271. tabClass
  272. } = this.data
  273. if (scrollTop > tabScrollTop && !tabClass) {
  274. tabClass = 'articleFixed'
  275. } else if (scrollTop < tabScrollTop && tabClass) {
  276. tabClass = ''
  277. }
  278. this.setData({
  279. tabClass
  280. })
  281. if (scrollTop >= top && !navBarBgClass) {
  282. navBarBgClass = ' navbar-bg-white '
  283. app.globalData.navBarData.navBarBgClass = navBarBgClass
  284. this.setData({
  285. navBarBgClass
  286. })
  287. }
  288. if (scrollTop < top && navBarBgClass) {
  289. navBarBgClass = ''
  290. this.setData({
  291. navBarBgClass
  292. })
  293. app.globalData.navBarData.navBarBgClass = navBarBgClass
  294. }
  295. },
  296. // 去测肤
  297. goSkin() {
  298. wx.navigateTo({
  299. url: '/pages/plan/plan',
  300. })
  301. },
  302. goOrder(e) {
  303. let index = e.currentTarget.dataset.index
  304. app.globalData.toViewIndex = index
  305. wx.switchTab({
  306. url: '/pages/orderBy/orderBy',
  307. success: function () {
  308. var page = getCurrentPages().pop();
  309. page.onPullDownRefresh();
  310. }
  311. })
  312. },
  313. // 轮播图改变
  314. changeSwiper(e) {
  315. this.setData({
  316. swiperIndex: e.detail.current
  317. })
  318. },
  319. /**
  320. * 切换状态
  321. */
  322. onTabsChange(e) {
  323. let current = e.currentTarget.dataset.index
  324. if (current == this.data.current) {
  325. return;
  326. }
  327. this.setData({
  328. current,
  329. page: 1,
  330. }, () => {
  331. this.getArticleList(1)
  332. })
  333. },
  334. /**
  335. * 获取美丽秘籍分类
  336. * /api/info/classify
  337. */
  338. getClassify() {
  339. get('api/info/classify', {}, (res) => {
  340. this.setData({
  341. classify: res.data.list
  342. }, () => {
  343. this.getArticleList()
  344. })
  345. })
  346. },
  347. /**
  348. * 获取美丽秘籍列表
  349. * /api/info
  350. */
  351. getArticleList(_page) {
  352. this.setData({
  353. spinning: true
  354. })
  355. let {
  356. tempPics,
  357. classify,
  358. page,
  359. value,
  360. current
  361. } = this.data;
  362. get('api/info', {
  363. page: _page || page,
  364. limit: 10,
  365. keyword: value,
  366. classify_id: classify[current].id,
  367. }, (res) => {
  368. res.data.list.map(item => {
  369. item.create_time = item.create_time.substring(0, 10)
  370. })
  371. if (_page == 1 || page == 1) {
  372. tempPics = []
  373. this.data.page = 1
  374. }
  375. tempPics.push(...res.data.list)
  376. this.setData({
  377. tempPics,
  378. total: res.data.total,
  379. spinning: false
  380. })
  381. this.jsData.isListLoading = true
  382. })
  383. },
  384. //获取图片尺寸数据
  385. loadPic: function (e) {
  386. var that = this,
  387. data = that.data,
  388. tempPics = data.tempPics,
  389. index = e.currentTarget.dataset.index
  390. if (tempPics[index]) {
  391. //以750为宽度算出相对应的高度
  392. tempPics[index].height = e.detail.height * 750 / e.detail.width
  393. tempPics[index].isLoad = true
  394. }
  395. that.setData({
  396. tempPics: tempPics
  397. }, function () {
  398. that.finLoadPic()
  399. })
  400. },
  401. //图片加载错误处理
  402. loadPicError: function (e) {
  403. var that = this,
  404. data = that.data,
  405. tempPics = data.tempPics,
  406. index = e.currentTarget.dataset.index
  407. if (tempPics[index]) {
  408. //图片加载错误时高度固定750,展示为正方形
  409. tempPics[index].height = 750
  410. tempPics[index].isLoad = true
  411. }
  412. that.setData({
  413. tempPics: tempPics
  414. }, function () {
  415. that.finLoadPic()
  416. })
  417. },
  418. //判断图片是否加载完成
  419. finLoadPic: function () {
  420. var that = this,
  421. data = that.data,
  422. tempPics = data.tempPics,
  423. length = tempPics.length,
  424. fin = true
  425. for (var i = 0; i < length; i++) {
  426. if (!tempPics[i].isLoad) {
  427. fin = false
  428. break
  429. }
  430. }
  431. if (fin) {
  432. if (that.jsData.isListLoading) {
  433. that.jsData.isListLoading = false
  434. that.renderPage()
  435. }
  436. }
  437. },
  438. //渲染到瀑布流
  439. renderPage: function () {
  440. var that = this,
  441. data = that.data,
  442. columns = data.columns,
  443. tempPics = data.tempPics,
  444. length = tempPics.length,
  445. columnsHeight = that.jsData.columnsHeight,
  446. index = 0
  447. if (this.data.page == 1) {
  448. columns = [
  449. [],
  450. []
  451. ]
  452. }
  453. for (var i = 0; i < length; i++) {
  454. index = columnsHeight[1] < columnsHeight[0] ? 1 : 0
  455. columns[index].push(tempPics[i])
  456. columnsHeight[index] += tempPics[i].height
  457. }
  458. that.setData({
  459. columns: columns,
  460. tempPics: []
  461. })
  462. that.jsData.columnsHeight = columnsHeight
  463. },
  464. /**
  465. * swiper滚动事件
  466. * @param {*} e
  467. */
  468. swiperChange: function (e) {
  469. let currentSource = e.currentTarget.dataset.currentSource
  470. if (currentSource == 'topBanner') {
  471. this.setData({
  472. topBannerCurrentSwiper: e.detail.current
  473. })
  474. }
  475. if (currentSource == 'cardBanner') {
  476. this.setData({
  477. cardBannerCurrentSwiper: e.detail.current
  478. })
  479. }
  480. },
  481. /**
  482. * 关闭弹框
  483. */
  484. onClose(e, _bool) {
  485. let key = _bool ? e : e.currentTarget.dataset.key
  486. this.setData({
  487. [key]: false
  488. })
  489. getApp().globalData.couponPopup = false
  490. },
  491. bindchanges(e) {
  492. this.setData({
  493. currentNewAcount: e.detail.current
  494. })
  495. },
  496. /**
  497. * 确认领取
  498. */
  499. onConfirm() {
  500. wx.showToast({
  501. title: '领取成功',
  502. icon: 'none'
  503. })
  504. getApp().globalData.couponPopup = false
  505. this.onClose('visible', true)
  506. // this.setData({ visible: false })
  507. },
  508. /**
  509. * 两点之间距离计算
  510. * @param {*} lat1
  511. * @param {*} lng1
  512. * @param {*} lat2
  513. * @param {*} lng2
  514. */
  515. getDistance(lat1, lng1, lat2, lng2) {
  516. lat1 = lat1 || 0;
  517. lng1 = lng1 || 0;
  518. lat2 = lat2 || 0;
  519. lng2 = lng2 || 0;
  520. var rad1 = lat1 * Math.PI / 180.0;
  521. var rad2 = lat2 * Math.PI / 180.0;
  522. var a = rad1 - rad2;
  523. var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
  524. var r = 6378137;
  525. var distance = r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2)));
  526. return distance;
  527. },
  528. /**
  529. * 获取店铺接口
  530. * /api/store
  531. */
  532. getStore() {
  533. get(
  534. 'api/store', {
  535. page: 1,
  536. limit: 100,
  537. keyword: ""
  538. },
  539. (res) => {
  540. let lat1 = app.address.latitude,
  541. lng1 = app.address.longitude,
  542. storeList = res.data.list,
  543. distanceList = []
  544. //循环遍历计算获取当前定位到各门店的距离
  545. storeList.forEach(item => {
  546. let distanceInfo = {}
  547. distanceInfo["id"] = item.id
  548. distanceInfo["dist"] = this.getDistance(lat1, lng1, item.latitude, item.longitude)
  549. distanceList.push(distanceInfo)
  550. })
  551. //近到远排序
  552. let _distanceList = distanceList.sort(function (a, b) {
  553. return a.dist - b.dist
  554. })
  555. //切换门店
  556. this.getStoreInfo(String(_distanceList[0].id))
  557. wx.setStorageSync('store_id', String(_distanceList[0].id))
  558. }
  559. )
  560. },
  561. /**
  562. * 获取当前定位
  563. * @param {*} obj
  564. */
  565. getPermission: function (obj) {
  566. let that = this
  567. // wx.getLocation({
  568. // success: function (res) {
  569. // that.getStore()
  570. // app.address = res
  571. // let lat1 = app.address.latitude
  572. // let lng1 = app.address.longitude
  573. // that.setData({
  574. // lat1,
  575. // lng1,
  576. // })
  577. // },
  578. // fail: function () {
  579. // wx.getSetting({
  580. // success: function (res) {
  581. // var statu = res.authSetting;
  582. // if (!statu['scope.userLocation']) {
  583. // wx.showModal({
  584. // title: '是否授权当前位置',
  585. // content: '需要获取您的地理位置,请确认授权,否则无法定位最近店铺',
  586. // success: function (tip) {
  587. // if (tip.confirm) {
  588. // wx.openSetting({
  589. // success: function (data) {
  590. // if (data.authSetting["scope.userLocation"] === true) {
  591. // wx.showToast({
  592. // title: '授权成功',
  593. // icon: 'success',
  594. // duration: 1000
  595. // })
  596. // //授权成功之后,再调用chooseLocation选择地方
  597. // wx.getLocation({
  598. // success: function (res) {
  599. // that.getStore()
  600. // app.address = res
  601. // let lat1 = app.address.latitude
  602. // let lng1 = app.address.longitude
  603. // that.setData({
  604. // lat1,
  605. // lng1,
  606. // })
  607. // },
  608. // })
  609. // } else {
  610. // wx.showToast({
  611. // title: '授权失败',
  612. // icon: 'success',
  613. // duration: 1000
  614. // })
  615. // }
  616. // }
  617. // })
  618. // }
  619. // }
  620. // })
  621. // }
  622. // },
  623. // fail: function (res) {
  624. // wx.showToast({
  625. // title: '调用授权窗口失败',
  626. // icon: 'success',
  627. // duration: 1000
  628. // })
  629. // }
  630. // })
  631. // }
  632. // })
  633. },
  634. /**
  635. * 首页数据
  636. */
  637. getHomeData() {
  638. let that = this;
  639. this.getPermission(that); //获取当前定位
  640. get('api/home', {}, (res) => {
  641. let nowDate = Math.round(new Date().getTime() / 1000).toString();
  642. // 判断推荐项目展示时间
  643. let referrals = []
  644. res.data.referrals.forEach(item => {
  645. if (nowDate.toString() > item.start_time.toString() && nowDate.toString() < item.end_time.toString()) {
  646. referrals.push(item)
  647. }
  648. })
  649. res.data.referrals = referrals
  650. // 判断推荐项目为两个的话添加进行展示
  651. if (res.data.referrals.length < 3 && res.data.referrals.length != 1) {
  652. res.data.referrals.forEach(item => {
  653. res.data.referrals.push(item)
  654. })
  655. }
  656. this.setData({
  657. homeData: res.data
  658. },
  659. () => {
  660. // this.getProjectList(1)
  661. this.setData({
  662. isLoading: false
  663. })
  664. }
  665. )
  666. })
  667. },
  668. /**
  669. * 首页数据
  670. */
  671. activityProgress() {
  672. get('api/activity/progress', {}, (res) => {
  673. this.setData({
  674. progressList: res.data.list
  675. })
  676. })
  677. },
  678. /**
  679. * 首页数据
  680. */
  681. check_new_record() {
  682. let that = this
  683. get('api/user/plan/check_new_record', {}, (res) => {
  684. if (res.data.status == 1) {
  685. wx.showModal({
  686. title: '提示',
  687. content: '检测到新的美容计划,是否替换现有计划',
  688. success(res1) {
  689. if (res1.confirm) {
  690. console.log('用户点击确定', res.data.analysis_id)
  691. that.planReplace('yes', res.data.analysis_id)
  692. } else if (res1.cancel) {
  693. console.log('用户点击取消', res.data.analysis_id)
  694. that.planReplace('no', res.data.analysis_id)
  695. }
  696. }
  697. })
  698. }
  699. })
  700. },
  701. /**
  702. * 首页数据
  703. */
  704. planReplace(op_type, analysis_id) {
  705. post('api/user/plan/replace', {
  706. op_type: op_type,
  707. analysis_id: analysis_id
  708. }, (res) => {
  709. this.getHomeData()
  710. })
  711. },
  712. cardingCatchTap() {
  713. wx.navigateTo({
  714. url: '../guildMessage/index',
  715. })
  716. },
  717. /**
  718. * 首页数据
  719. */
  720. activityRules() {
  721. let that = this
  722. get('api/activity/rules', {}, (res) => {
  723. WxParse.wxParse('article', 'html', res.data.content, that, 5)
  724. // this.setData({
  725. // activityRules: res.data.content
  726. // })
  727. })
  728. },
  729. guildMessage() {
  730. this.setData({
  731. guildMessage: true
  732. })
  733. },
  734. onCloseLandscape() {
  735. this.setData({
  736. guildMessage: false
  737. })
  738. },
  739. /**
  740. * 首页列表
  741. */
  742. getProjectList(_page) {
  743. return
  744. let {
  745. list,
  746. page
  747. } = this.data
  748. get(
  749. 'api/project', {
  750. store_id: this.data.homeData.store.id,
  751. page: _page || page,
  752. limit: 10
  753. },
  754. (res) => {
  755. if (_page == 1 || page == 1) {
  756. list = []
  757. this.data.page = 1
  758. }
  759. list.push(...res.data.list)
  760. this.setData({
  761. list,
  762. isLoading: false,
  763. total: res.data.total
  764. })
  765. }
  766. )
  767. },
  768. /**
  769. * 店铺信息
  770. * /api/store/info
  771. */
  772. getStoreInfo(store_id) {
  773. get(
  774. 'api/store/info', {
  775. store_id
  776. },
  777. (res) => {
  778. this.setData({
  779. ['homeData.store']: res.data
  780. },
  781. () => {
  782. wx.setStorageSync('store_id', String(store_id))
  783. app.globalData.storeData = res.data
  784. this.getProjectList(1)
  785. }
  786. )
  787. }
  788. )
  789. },
  790. /**
  791. * 首页广告跳转
  792. */
  793. goToUrl(e) {
  794. console.log(e);
  795. if (e.currentTarget.dataset.url) {
  796. if (e.currentTarget.dataset.url == '/pages/orderBy/orderBy') {
  797. wx.switchTab({
  798. url: '/pages/orderBy/orderBy'
  799. })
  800. } else if (e.currentTarget.dataset.url == '/pages/shoppingMall/shoppingMall') {
  801. wx,
  802. switchTab({
  803. url: '/pages/shoppingMall/shoppingMall'
  804. })
  805. }
  806. else {
  807. wx.navigateTo({
  808. url: e.currentTarget.dataset.url
  809. })
  810. trackUserEvent(e.currentTarget?.dataset?.source?.type)
  811. }
  812. }
  813. this.setData({
  814. posterPopup: false
  815. })
  816. },
  817. /**
  818. * 跳转店铺列表
  819. */
  820. goToStore() {
  821. wx.navigateTo({
  822. url: '/pages/store/store?defaultStore=' +
  823. JSON.stringify(this.data.homeData.store)
  824. })
  825. },
  826. /**
  827. * 跳转项目详情
  828. */
  829. goToProject(e) {
  830. let item = e.currentTarget.dataset.item || {}
  831. let projectId = item.project_id || item.id
  832. let storeId = item.store_id || this.data.homeData.store.id
  833. wx.navigateTo({
  834. url: `/pages/projectDetail/projectDetail?project_id=${projectId}&store_id=${storeId}`
  835. })
  836. },
  837. /**
  838. * 跳转变美计划
  839. */
  840. goToBeautyPlan(e) {
  841. let analysisId = e.currentTarget.dataset.analysisId
  842. wx.navigateTo({
  843. url: `/pages/beautyPlan/beautyPlan?analysis_id=${analysisId}`
  844. })
  845. },
  846. /**
  847. * 获取首次开卡优惠
  848. * api/user/activity
  849. */
  850. getUserActivity() {
  851. if (this.timer) {
  852. clearInterval(this.timer_)
  853. }
  854. get('api/user/activity', {}, (res) => {
  855. this.data.needReqActivity = false
  856. if (res.data) {
  857. res.data.currentTime = formatActivity(res.data.expire_time_seconds)
  858. this.setData({
  859. activity: res.data
  860. })
  861. this.timer_ = setInterval(() => {
  862. if (res.data.expire_time_seconds <= 0) {
  863. clearInterval(this.timer_)
  864. }
  865. res.data.expire_time_seconds--
  866. res.data.currentTime = formatActivity(res.data.expire_time_seconds)
  867. this.setData({
  868. activity: res.data
  869. })
  870. }, 1000)
  871. }
  872. })
  873. },
  874. /**
  875. * 开卡优惠关闭
  876. */
  877. onCloseToast() {
  878. this.setData({
  879. btmToast: false
  880. })
  881. },
  882. /**
  883. * 肤质检测结果
  884. */
  885. goToAnalysisResult(e) {
  886. if (!this.data.homeData.analysis.score > 0) {
  887. wx.navigateTo({
  888. url: '/pages/plan/plan?defaultStore=' +
  889. JSON.stringify(this.data.homeData.store)
  890. })
  891. return
  892. }
  893. let analysis = e.currentTarget.dataset.analysis || {}
  894. let analysisId = analysis.analysis_id
  895. let url = `/pages/skinRecord/skinRecord?id=${analysisId}`
  896. if (!analysisId) {
  897. this.gotoOrderBy()
  898. return
  899. }
  900. wx.navigateTo({
  901. url: url
  902. })
  903. },
  904. /**
  905. * 根据Url类型跳转
  906. */
  907. jumpByUrlType(e) {
  908. let item = e.currentTarget.dataset.item || {}
  909. let urlType = item.url_type || 0
  910. let url = item.url || ''
  911. // 跳转类型,0不跳转,1内部地址,2外部地址
  912. switch (urlType) {
  913. case 1:
  914. url && wx.navigateTo({
  915. url: url
  916. })
  917. break
  918. default:
  919. break
  920. }
  921. },
  922. //获取当前推荐原则
  923. recommendRule() {
  924. if (!this.data.homeData.analysis.score > 0) {
  925. wx.navigateTo({
  926. url: '/pages/plan/plan?defaultStore=' +
  927. JSON.stringify(this.data.homeData.store)
  928. })
  929. return
  930. }
  931. let url = `/pages/orderBy/orderBy`
  932. wx.switchTab({
  933. url: url
  934. })
  935. },
  936. /**
  937. * 预约下单tab
  938. */
  939. gotoOrderBy() {
  940. if (this.data.homeData.analysis_check == 1) {
  941. get('/v2/api/user/recommend_rule', {}, res => {
  942. if (res.data.status == 0) {
  943. wx.navigateTo({
  944. url: '/pages/recommendRule/recommendRule',
  945. })
  946. } else {
  947. wx.navigateTo({
  948. url: '/pages/faceDetectionDetails/faceDetectionDetails',
  949. })
  950. }
  951. })
  952. } else {
  953. if (!this.data.homeData.analysis.score > 0) {
  954. wx.navigateTo({
  955. url: '/pages/plan/plan?defaultStore=' +
  956. JSON.stringify(this.data.homeData.store)
  957. })
  958. return
  959. }
  960. let url = `/pages/orderBy/orderBy`
  961. wx.switchTab({
  962. url: url
  963. })
  964. }
  965. },
  966. onOderBy() {
  967. let url = `/pages/orderBy/orderBy`
  968. wx.switchTab({
  969. url: url
  970. })
  971. },
  972. // 跳转到领券详情
  973. getCoupon() {
  974. wx.navigateTo({
  975. url: '/pages/couponCenter/couponCenter',
  976. })
  977. },
  978. // 十月一活动
  979. onClosePop() {
  980. this.setData({
  981. PopShow: false,
  982. })
  983. },
  984. gotoActive() {
  985. wx.navigateTo({
  986. url: '/pages/activePage2/activePage2',
  987. })
  988. this.setData({
  989. PopShow: false
  990. })
  991. },
  992. // 点击跳转美丽秘籍
  993. goArticleDetail(e) {
  994. let id = e.currentTarget.dataset.id
  995. wx.navigateTo({
  996. url: `/pages/articleDetail/articleDetail?id=${id}`,
  997. })
  998. },
  999. // 点击推荐项目跳转到项目
  1000. goOtherUrl(e) {
  1001. let url = e.currentTarget.dataset.url
  1002. let type = e.currentTarget.dataset.type
  1003. if (url == '/pages/orderBy/orderBy') {
  1004. wx.switchTab({
  1005. url: '/pages/orderBy/orderBy'
  1006. })
  1007. } else if (url == '/pages/shoppingMall/shoppingMall') {
  1008. wx.switchTab({
  1009. url: '/pages/shoppingMall/shoppingMall'
  1010. })
  1011. } else {
  1012. wx.navigateTo({
  1013. url: url,
  1014. })
  1015. }
  1016. // if(type==1){
  1017. // wx.navigateTo({
  1018. // url:url,
  1019. // })
  1020. // }else if(type==2){
  1021. // wx.navigateTo({
  1022. // url: `/pages/projectDetail/projectDetail?source=goods&id=${id}&store_id=${this.data.storeId}`,
  1023. // })
  1024. // }else if(type==3){
  1025. // wx.navigateTo({
  1026. // url: `/pages/projectDetail/projectDetail?source=project&id=${id}&store_id=${this.data.storeId}`,
  1027. // })
  1028. // }else{
  1029. // return
  1030. // }
  1031. },
  1032. //获取消息列表
  1033. getMessageList() {
  1034. get('v2/api/message/list', {
  1035. page: 1,
  1036. limit: 3,
  1037. }, (res) => {
  1038. if (res.code == 200) {
  1039. // 是否首页通知 1是 0不是
  1040. let list = res.data.list.filter(item => {
  1041. return item.notice != 0
  1042. })
  1043. this.setData({
  1044. messageList: list
  1045. })
  1046. this.getWorkMessageList()
  1047. }
  1048. })
  1049. },
  1050. // 获取业务消息列表
  1051. getWorkMessageList() {
  1052. let that = this
  1053. get('v2/api/message/notice', {
  1054. page: 1,
  1055. limit: 3,
  1056. }, (res) => {
  1057. if (res.code == 200) {
  1058. let workMessageList = that.data.messageList
  1059. workMessageList.push(...res.data.list)
  1060. // 对通知和业务消息的集合做排序 最新的在上面
  1061. workMessageList.sort((a, b) => {
  1062. return new Date(b.create_time) - new Date(a.create_time)
  1063. });
  1064. // 截取前三个
  1065. workMessageList = workMessageList.slice(0, 3)
  1066. this.setData({
  1067. messageList: workMessageList,
  1068. })
  1069. }
  1070. })
  1071. },
  1072. // 获取未读消息数量
  1073. getNotMessageTotal() {
  1074. get('v2/api/message/total', {}, (res) => {
  1075. if (res.code == 200) {
  1076. this.getWorkMessage(res.data)
  1077. }
  1078. })
  1079. },
  1080. // 获取未读业务消息数量
  1081. getWorkMessage(total) {
  1082. get('v2/api/message/all', {}, (res) => {
  1083. if (res.code == 200) {
  1084. this.setData({
  1085. notMessageTotal: Number(total) + Number(res.data)
  1086. })
  1087. }
  1088. })
  1089. },
  1090. // 跳转到消息详情
  1091. goMessageDetail(e) {
  1092. let id = e.currentTarget.dataset.id
  1093. let notice = e.currentTarget.dataset.notice
  1094. // 是否是业务消息 是业务消息就跳转到消息中心
  1095. if (notice) {
  1096. wx.navigateTo({
  1097. url: `/subPackagesC/pages/messageDetail/messageDetail?id=${id}`,
  1098. })
  1099. } else {
  1100. wx.navigateTo({
  1101. url: '/subPackagesC/pages/messageCenter/messageCenter',
  1102. })
  1103. }
  1104. },
  1105. // 跳转到消息列表
  1106. goMessageCenter() {
  1107. wx.navigateTo({
  1108. url: '/subPackagesC/pages/messageCenter/messageCenter',
  1109. })
  1110. },
  1111. // 获取测肤概要信息
  1112. getSkinInfo() {
  1113. get('v2/api/home/analysis', {}, (res) => {
  1114. if (res.code == 200) {
  1115. this.setData({
  1116. skinInfo: res.data
  1117. })
  1118. }
  1119. })
  1120. },
  1121. // 跳转到测肤记录详情
  1122. goTestSkin() {
  1123. wx.navigateTo({
  1124. url: '/subPackagesD/pages/testSkin/testSkin?isRadio=true',
  1125. })
  1126. },
  1127. })