questionnaire.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // components/questionnaire/questionnaire.js
  2. import $ from '../../utils/Tool';
  3. import {
  4. queryQuestion,
  5. submitAnswer,
  6. notShowQuestion
  7. } from "../../requests/api";
  8. Component({
  9. /**
  10. * 组件的属性列表
  11. */
  12. options: {
  13. styleIsolation: 'shared',
  14. },
  15. properties: {
  16. },
  17. lifetimes: {
  18. attached: function() {
  19. this.queryDate();
  20. // 在组件实例进入页面节点树时执行
  21. },
  22. detached: function() {
  23. // 在组件实例被从页面节点树移除时执行
  24. },
  25. },
  26. /**
  27. * 组件的初始数据
  28. */
  29. data: {
  30. startValue:0,
  31. checked:[],
  32. tipsshow:false,
  33. dialogRadio:'2',
  34. answer:false,
  35. questionDate:[],
  36. firstDate:{},
  37. otherDate:[],
  38. submitFlag:false,
  39. },
  40. /**
  41. * 组件的方法列表
  42. */
  43. methods: {
  44. preventTouchMove(){
  45. },
  46. emitClose(value){
  47. this.triggerEvent('surveyClose',value?{good:true}:{good:false})
  48. },
  49. queryDate(){
  50. let data={
  51. "criteria":{
  52. "type":0
  53. }
  54. }
  55. queryQuestion(data).then(res=>{
  56. const [firstDate,...otherDate]= res.content;
  57. otherDate.forEach(v=>{
  58. v.checked=[];
  59. v.remark=false;
  60. v.remarkTxt="";
  61. })
  62. this.setData({
  63. firstDate:firstDate||{},
  64. otherDate:otherDate||[],
  65. questionDate:res.content||[]
  66. })
  67. })
  68. },
  69. inputChange(e){
  70. let {index} = e.currentTarget.dataset;
  71. let mText = 'otherDate['+ index +'].remarkTxt';
  72. let {value} = e.detail;
  73. this.setData({
  74. [mText]:value
  75. })
  76. },
  77. closePage(){
  78. this.setData({
  79. tipsshow:true
  80. })
  81. },
  82. starChange(event){
  83. let that =this;
  84. if(event.detail!==5){
  85. this.setData({
  86. startValue: event.detail,
  87. answer:true
  88. });
  89. }else{
  90. this.setData({
  91. startValue: event.detail,
  92. submitFlag:true
  93. },()=>{
  94. that.submitFeed();
  95. });
  96. // this.emitClose(true);
  97. }
  98. },
  99. selectChange(event){
  100. let {index} = event.currentTarget.dataset;
  101. let mText = 'otherDate['+ index +'].checked';
  102. let remark = 'otherDate['+ index +'].remark';
  103. let flag = event.detail.includes("12");
  104. let that =this;
  105. this.setData({
  106. [mText]: event.detail,
  107. [remark]:flag
  108. },()=>{
  109. if(flag){
  110. wx.createSelectorQuery().in(that).select('#qus_listbox').boundingClientRect(function(rect){
  111. that.setData({
  112. textScroll:rect.height
  113. })
  114.     }).exec()   
  115. }
  116. let falg = that.data.otherDate.filter((item)=>{
  117. return !item.checked.length
  118. });
  119. !falg.length?that.setData({submitFlag:true}):that.setData({submitFlag:false});
  120. });
  121. },
  122. radioChange(event){
  123. this.setData({
  124. dialogRadio: event.detail,
  125. });
  126. },
  127. closeDialog(){
  128. this.setData({
  129. tipsshow:false
  130. })
  131. },
  132. async submitMsg(){
  133. if(this.data.dialogRadio==1){
  134. let {id} = $.store.get('userInfo');
  135. let tenantId = $.store.get('tenantId');
  136. let projectId = $.store.get('projectId');
  137. let data={
  138. "projectId":projectId,
  139. "tenantId":tenantId,
  140. "userId":id,
  141. "startTime":this.data.firstDate.startTime,
  142. "endTime":this.data.firstDate.endTime,
  143. "isDisplay": false,
  144. "seasonType":this.data.firstDate.seasonType
  145. }
  146. await notShowQuestion(data)
  147. }else{
  148. $.storage.set('nextRemind',true);
  149. }
  150. this.setData({
  151. tipsshow:false
  152. })
  153. this.data.dialogRadio==1?this.emitClose(true):this.emitClose();
  154. },
  155. submitFeed(){
  156. if(!this.data.submitFlag){
  157. return
  158. }
  159. let falgRemark=true;
  160. let {id,nickname,phone,userName}= $.store.get('userInfo');
  161. let startTime = this.data.firstDate.startTime;
  162. let endTime = this.data.firstDate.endTime;
  163. let projectId= $.store.get('projectId');
  164. let tenantId= $.store.get('tenantId');
  165. let dateTemplate={
  166. "projectId":projectId,//项目id
  167. "tenantId":tenantId,
  168. "seasonType":this.data.firstDate.seasonType||'Warm',//季节类型
  169. "userId":id,//用户id
  170. "nickName":nickname,//微信昵称
  171. "phone":phone,//手机号
  172. "userName":userName,//手机号
  173. "type":"0",//类型 0 小程序
  174. "startTime":startTime,//调查问卷开始时间
  175. "endTime":endTime,//调查问卷结束时间
  176. }
  177. let firstDate={...dateTemplate};
  178. let startIndex=5-this.data.startValue;
  179. firstDate.questionId=this.data.firstDate.questionId;
  180. firstDate.questionAnswerList=[{answerId: this.data.firstDate.questionAnswerList[startIndex].answerId}];
  181. let data=[firstDate];
  182. if(this.data.answer){
  183. this.data.otherDate.forEach(item=>{
  184. let otherdate={...dateTemplate};
  185. otherdate.questionId=item.questionId;
  186. otherdate.questionAnswerList=[];
  187. item.checked.forEach(v=>{
  188. let obj={};
  189. obj.answerId=v;
  190. if(item.remark&&v==12){
  191. item.remarkTxt?(obj.remark=item.remarkTxt):(falgRemark=false);
  192. }
  193. otherdate.questionAnswerList.push(obj);
  194. })
  195. data.push(otherdate);
  196. })
  197. }
  198. if(!falgRemark){
  199. wx.showToast({
  200. title:"其他选项不能为空",
  201. icon:"none",
  202. duration: 1000
  203. })
  204. return
  205. }
  206. submitAnswer(data).then(res=>{
  207. let that =this;
  208. this.setData({dialogRadio:1},()=>{
  209. that.submitMsg();
  210. })
  211. })
  212. }
  213. }
  214. })