skinRecord.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import {
  2. get, post,
  3. } from '../../utils/http';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: {},
  10. current: 0,
  11. detail: {},
  12. id: '',
  13. fromList: "",
  14. visible: false,
  15. spinning: true
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. console.log(options)
  22. let current = 0,fromList = "";
  23. if(options.fromList == "1") {
  24. current = 2
  25. fromList = options.fromList
  26. }
  27. this.setData({
  28. id: options.id,
  29. current,
  30. fromList,
  31. userInfo: wx.getStorageSync('userInfo')
  32. })
  33. this.getSkinInfo(options.id);
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面隐藏
  47. */
  48. onHide: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面卸载
  52. */
  53. onUnload: function () {
  54. },
  55. /**
  56. * 页面相关事件处理函数--监听用户下拉动作
  57. */
  58. onPullDownRefresh: function () {
  59. },
  60. /**
  61. * 页面上拉触底事件的处理函数
  62. */
  63. onReachBottom: function () {
  64. },
  65. /**
  66. * 用户点击右上角分享
  67. */
  68. onShareAppMessage: function () {
  69. },
  70. /**
  71. * 切换状态
  72. */
  73. onTabsChange(e) {
  74. let current = e.currentTarget.dataset.id
  75. if (current == this.data.current) {
  76. return;
  77. }
  78. this.setData({
  79. current,
  80. // page: 1,
  81. }, () => {
  82. // this.getCoupon()
  83. })
  84. },
  85. /**
  86. * 获取检测记录详情
  87. * /api/user/skin_log_info
  88. */
  89. getSkinInfo(id) {
  90. return new Promise((resolve,reject) => {
  91. get('api/user/skin_log_info',{
  92. id
  93. },(res) => {
  94. if(res.data) {
  95. res.data.question.forEach((item) => {
  96. item.status = 0
  97. })
  98. this.setData({
  99. spinning: false,
  100. detail: res.data
  101. })
  102. }
  103. resolve(res)
  104. })
  105. })
  106. },
  107. /**
  108. * 点击切换问诊卡问题
  109. */
  110. onChangeStatus(e) {
  111. let index = e.currentTarget.dataset.index
  112. let status = e.currentTarget.dataset.status
  113. this.setData({
  114. ['detail.question[' + index + '].status']: status
  115. })
  116. },
  117. /**
  118. * 问诊卡不提交
  119. */
  120. onCancelUse() {
  121. this.setData({
  122. visible: true
  123. })
  124. },
  125. /**
  126. * 问诊卡确认提交
  127. */
  128. onConfirmUse() {
  129. let detail = this.data.detail;
  130. let flag = true;
  131. let ids = [];
  132. let values = [];
  133. detail.question.forEach(item => {
  134. if(item.status === undefined || item.status == 'undefined') {
  135. console.log('空')
  136. flag = false
  137. }
  138. ids.push(item.id)
  139. values.push(item.status)
  140. });
  141. if(!flag) {
  142. wx.showToast({
  143. title: '请选择完所有选项',
  144. icon: 'none'
  145. })
  146. return;
  147. }
  148. post('api/user/save_investigation',{
  149. analysis_id: detail.analysis_id,
  150. ids: ids.toString(),
  151. values: values.toString()
  152. },(res) => {
  153. wx.showToast({
  154. title: '提交成功',
  155. icon: 'none'
  156. })
  157. this.setData({
  158. visible: true,
  159. spinning: true
  160. },() => {
  161. this.getSkinInfo(detail.analysis_id).then((res) => {
  162. // this.setData({
  163. // current: 2
  164. // })
  165. })
  166. })
  167. console.log(res)
  168. })
  169. }
  170. })