testSkin.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import {
  2. get,
  3. post
  4. } from "../../../utils/http"
  5. var WxParse = require('../../../components/local/wxParse/wxParse.js');
  6. // subPackagesD/pages/testSkin/testSkin.js
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. store_id: '', //店铺ID
  13. skin_type: ['干性肌肤', '中性肌肤', '油性肌肤', '混合型肌肤', '敏感肌肤', '痤疮肌肤'], //肤质:1-干性肌肤 2-中性肌肤 3-油性肌肤 4-混合型肌肤,5敏感肌肤,6 痤疮肌肤
  14. skinInfo: [], //测肤详情
  15. ageChange: 0, //比实际年龄
  16. ageStatus: "", //比实际年龄的变化(0:比实际年龄小,1比实际年龄大,2跟实际年龄相符)
  17. skinLevel: '', //皮肤问题(严重程度:0无问题,1轻度,2中度,3重度)
  18. skinLevelList: ['健康', '轻度', '中度', '重度'], //皮肤问题
  19. isRadio: true, //查看护理方案是否加载(第一次加载时跳转)
  20. scheme_id:'',//推荐方案ID
  21. analysis_id:' ',//检测ID
  22. isHistory:true,//从历史记录跳转的是否显示历史记录
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad(options) {
  28. console.log(options,'options');
  29. let isRadio = false
  30. let isHistory = true
  31. if (options.isRadio=='true') {
  32. isRadio = true
  33. }
  34. if(options.isHistory){
  35. isHistory=false
  36. }
  37. this.setData({
  38. store_id: wx.getStorageSync('store_id'), //店铺ID
  39. isRadio,
  40. analysis_id:options.analysis_id,
  41. isHistory
  42. })
  43. },
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady() {
  48. },
  49. /**
  50. * 生命周期函数--监听页面显示
  51. */
  52. onShow() {
  53. // 获取检测记录详情
  54. this.getSkinInfo()
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide() {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload() {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh() {
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom() {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage() {
  80. },
  81. // 获取检测记录详情
  82. getSkinInfo() {
  83. get('v2/api/analysis/info', {
  84. analysis_id:this.data.analysis_id?this.data.analysis_id:'', //检测id,不填写则获取最新的检测信息
  85. store_id: this.data.store_id || wx.getStorageSync('store_id'), //店铺ID
  86. }, (res) => {
  87. if (res.code == 200) {
  88. let age = res.data.age
  89. let skin_age = res.data.skin_age
  90. // 判断肤龄状态
  91. if (age > skin_age) {
  92. this.setData({
  93. ageStatus: 0,
  94. ageChange: Number(age) - Number(skin_age)
  95. })
  96. } else if (skin_age > age) {
  97. this.setData({
  98. ageStatus: 1,
  99. ageChange: Number(skin_age) - Number(age)
  100. })
  101. } else {
  102. this.setData({
  103. ageStatus: 2,
  104. })
  105. }
  106. let that = this
  107. let length = res.data.suggest_list.length
  108. res.data.suggest_list.forEach((item,index)=>{
  109. WxParse.wxParse('article' + index, 'html', item.content[0], that, 5);
  110. if (index === length - 1) {
  111. WxParse.wxParseTemArray("askItemsArr", 'article', length, that)
  112. }
  113. })
  114. that.setData({
  115. skinInfo: res.data,
  116. skinLevel: res.data.degree.level
  117. })
  118. }
  119. })
  120. },
  121. // 查看您的专属方案
  122. goPlan() {
  123. // 是否已创建方案,1是,0否
  124. if(this.data.skinInfo.has_scheme==0){
  125. this.createPlan()
  126. }else{
  127. wx.navigateTo({
  128. url: '/subPackagesD/pages/skinPlan/skinPlan',
  129. })
  130. }
  131. },
  132. // 创建推荐方案
  133. createPlan() {
  134. post('v2/api/scheme/add', {
  135. analysis_id: this.data.skinInfo.id
  136. }, (res) => {
  137. if(res.code==200){
  138. this.setData({
  139. scheme_id:res.data.scheme_id //推荐方案ID
  140. })
  141. wx.navigateTo({
  142. url: '/subPackagesD/pages/skinLoading/skinLoading',
  143. })
  144. }
  145. })
  146. },
  147. // 去历史报告
  148. goHistory() {
  149. wx.navigateTo({
  150. url: '/subPackagesD/pages/skinHistory/skinHistory',
  151. })
  152. },
  153. // 去商品详情
  154. goGoodsDetail(e) {
  155. let id = e.currentTarget.dataset.id
  156. wx.navigateTo({
  157. url: `/pages/projectDetail/projectDetail?source=goods&id=${id}&store_id=${this.data.store_id}`,
  158. })
  159. }
  160. })