testpaper.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. var util = require("../../utils/util.js")
  2. const app = getApp()
  3. Page({
  4. data: {
  5. question: [],
  6. },
  7. onLoad: function(options) {
  8. this._getQuestion();
  9. this.setData({
  10. navH: app.globalData.navHeight
  11. })
  12. },
  13. // 获取题目信息
  14. _getQuestion: function() {
  15. util.getData('/getWXMMSearchQuestion')
  16. .then(res => {
  17. this.setData({
  18. question: res
  19. })
  20. })
  21. .catch(err => {
  22. console.log(err);
  23. })
  24. },
  25. // 选择题选择
  26. _selectItem: function(e) {
  27. let index = e.currentTarget.dataset.index;
  28. let subid = e.currentTarget.dataset.subid;
  29. this.editQuestion(index, subid);
  30. },
  31. // 输入框输入or日期选择
  32. _bindKeyInput: function(e) {
  33. let index = e.currentTarget.dataset.index;
  34. let subid = e.currentTarget.dataset.subid;
  35. let txt = e.detail.value;
  36. this.editQuestion(index, subid, txt);
  37. },
  38. // 输入or选择 信息录入
  39. editQuestion: function(index, subid, txt) {
  40. let type = this.data.question[index].wsq_type;
  41. let question = this.data.question;
  42. this.data.question[index].wxmmSearchAnswerList.forEach((item, itemInd) => {
  43. if (type == 2) {
  44. item.id == subid ? item.is_select = 1 : item.is_select = 0;
  45. } else {
  46. item.id == subid ? item.is_select = txt : '';
  47. }
  48. let attr = `question[${index}].wxmmSearchAnswerList[${itemInd}]`;
  49. this.setData({
  50. [attr]: item
  51. })
  52. })
  53. },
  54. // 获取时间
  55. formatDate: function() {
  56. let date = new Date();
  57. let year = date.getFullYear().toString().padStart(2, '0');
  58. let month = (date.getMonth() + 1).toString().padStart(2, '0');
  59. let day = date.getDate().toString().padStart(2, '0');
  60. return `${year}-${month}-${day}`
  61. },
  62. // 提交信息
  63. _clickBtn: function() {
  64. let question = this.data.question;
  65. let stopRun = false;
  66. let branche_code = wx.getStorageSync('branche_code');
  67. let params = {
  68. wmu_openid: app.globalData.openid,
  69. wmu_phone: app.globalData.userphone,
  70. wmu_city: branche_code,
  71. wmu_date: this.formatDate(),
  72. wxMMUserSearchDetails: []
  73. }
  74. question.some((item, index) => {
  75. let isstop = false;
  76. let selectBool = item.wsq_type == 2 ? false : true;
  77. item.wxmmSearchAnswerList.some((itemAns, indAns) => {
  78. let tempObj = {
  79. wmud_qid: itemAns.wma_question_id,
  80. wmud_aid: itemAns.id
  81. }
  82. if (item.wsq_type == 2) {
  83. // 选择题处理
  84. if (itemAns.is_select) {
  85. tempObj.wmud_value = itemAns.wma_value;
  86. params.wxMMUserSearchDetails.push(tempObj);
  87. selectBool = true;
  88. }
  89. } else {
  90. // 非选择题
  91. if(item.id!==10){
  92. if (!itemAns.is_select) {
  93. isstop = true;
  94. return true;
  95. } else {
  96. tempObj.wmud_value = itemAns.is_select;
  97. params.wxMMUserSearchDetails.push(tempObj);
  98. }
  99. }else{
  100. tempObj.wmud_value = itemAns.is_select;
  101. params.wxMMUserSearchDetails.push(tempObj);
  102. }
  103. }
  104. })
  105. if (!selectBool || isstop) {
  106. wx.showToast({
  107. title: '为了更好的为您推荐月嫂,请填写完整',
  108. icon: 'none',
  109. duration: 2000
  110. })
  111. stopRun = true;
  112. return true;
  113. }
  114. })
  115. if (!stopRun) {
  116. wx.request({
  117. url: app.globalData.url + '/queryUserMMSearch',
  118. data: params,
  119. header: {
  120. "Content-Type": "application/json"
  121. },
  122. method: "POST",
  123. success: function(res) {
  124. wx.setStorageSync('MMSearch', JSON.stringify(res));
  125. wx.setStorageSync(
  126. 'yslist', res.data
  127. )
  128. wx.navigateTo({
  129. url: '/pages/monthmama/monthmama'
  130. })
  131. }
  132. })
  133. }
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function() {}
  139. })