testSkin.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.data==null){
  88. wx.redirectTo({
  89. url: '/pages/plan/plan',
  90. })
  91. }
  92. if (res.code == 200) {
  93. let age = res.data.age
  94. let skin_age = res.data.skin_age
  95. // 判断肤龄状态
  96. if (age > skin_age) {
  97. this.setData({
  98. ageStatus: 0,
  99. ageChange: Number(age) - Number(skin_age)
  100. })
  101. } else if (skin_age > age) {
  102. this.setData({
  103. ageStatus: 1,
  104. ageChange: Number(skin_age) - Number(age)
  105. })
  106. } else {
  107. this.setData({
  108. ageStatus: 2,
  109. })
  110. }
  111. let that = this
  112. let length = res.data.suggest_list.length
  113. res.data.suggest_list.forEach((item,index)=>{
  114. WxParse.wxParse('article' + index, 'html', item.content[0], that, 5);
  115. if (index === length - 1) {
  116. WxParse.wxParseTemArray("askItemsArr", 'article', length, that)
  117. }
  118. })
  119. that.setData({
  120. skinInfo: res.data,
  121. skinLevel: res.data.degree.level
  122. })
  123. }
  124. })
  125. },
  126. // 查看您的专属方案
  127. goPlan() {
  128. // 是否已创建方案,1是,0否
  129. if(this.data.skinInfo.has_scheme==0){
  130. this.createPlan()
  131. }else{
  132. wx.navigateTo({
  133. url: '/subPackagesD/pages/skinPlan/skinPlan?isTestSkin=true',
  134. })
  135. }
  136. },
  137. // 创建推荐方案
  138. createPlan() {
  139. post('v2/api/scheme/add', {
  140. analysis_id: this.data.skinInfo.id
  141. }, (res) => {
  142. if(res.code==200){
  143. this.setData({
  144. scheme_id:res.data.scheme_id //推荐方案ID
  145. })
  146. wx.navigateTo({
  147. url: '/subPackagesD/pages/skinLoading/skinLoading',
  148. })
  149. }
  150. })
  151. },
  152. // 去历史报告
  153. goHistory() {
  154. wx.navigateTo({
  155. url: '/subPackagesD/pages/skinHistory/skinHistory',
  156. })
  157. },
  158. // 去商品详情
  159. goGoodsDetail(e) {
  160. let id = e.currentTarget.dataset.id
  161. wx.navigateTo({
  162. url: `/pages/projectDetail/projectDetail?source=goods&id=${id}&store_id=${this.data.store_id}`,
  163. })
  164. }
  165. })