investigation.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // pages/member/investigation/investigation.js
  2. import { get, post } from '../../../utils/http'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. questions: [],
  9. isFinished: 0,
  10. loading: 1
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. this.getInvestigationData()
  17. },
  18. /**
  19. * 生命周期函数--监听页面初次渲染完成
  20. */
  21. onReady: function () {},
  22. /**
  23. * 生命周期函数--监听页面显示
  24. */
  25. onShow: function () {},
  26. /**
  27. * 生命周期函数--监听页面隐藏
  28. */
  29. onHide: function () {},
  30. /**
  31. * 生命周期函数--监听页面卸载
  32. */
  33. onUnload: function () {},
  34. /**
  35. * 页面相关事件处理函数--监听用户下拉动作
  36. */
  37. onPullDownRefresh: function () {},
  38. /**
  39. * 页面上拉触底事件的处理函数
  40. */
  41. onReachBottom: function () {},
  42. /**
  43. * 用户点击右上角分享
  44. */
  45. onShareAppMessage: function () {},
  46. /**
  47. * 操作loading
  48. */
  49. operLoading: function (flag = 0) {
  50. this.setData({ loading: flag })
  51. },
  52. /**
  53. * 获取问诊信息
  54. */
  55. getInvestigationData: function () {
  56. get(
  57. 'api/user/investigation',
  58. {},
  59. (res) => {
  60. this.setData({
  61. questions: res.data.list,
  62. isFinished: res.data.is_finished
  63. })
  64. this.operLoading()
  65. },
  66. (err) => {
  67. this.operLoading()
  68. }
  69. )
  70. },
  71. /**
  72. * 点击切换问诊卡问题
  73. */
  74. onChangeStatus(e) {
  75. let index = e.currentTarget.dataset.index
  76. let value = e.currentTarget.dataset.value
  77. this.setData({
  78. ['questions[' + index + '].value']: value
  79. })
  80. },
  81. /**
  82. * 保存用户问诊信息
  83. */
  84. submit() {
  85. let { questions } = this.data
  86. let checkFlag = true
  87. let ids = []
  88. let values = []
  89. questions.forEach((item) => {
  90. if (['1', '2'].indexOf(String(item.value)) == -1) {
  91. checkFlag = false
  92. }
  93. ids.push(item.id)
  94. values.push(item.value)
  95. })
  96. if (!checkFlag) {
  97. wx.showToast({
  98. title: '请选择完所有选项',
  99. icon: 'none'
  100. })
  101. return
  102. }
  103. post(
  104. 'api/user/investigation',
  105. {
  106. ids: ids.toString(),
  107. values: values.toString()
  108. },
  109. (res) => {
  110. wx.showToast({
  111. title: '提交成功',
  112. icon: 'none'
  113. })
  114. setTimeout(() => {
  115. wx.navigateBack()
  116. }, 1500)
  117. },
  118. () => {}
  119. )
  120. }
  121. })