evaluationCourse.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. nameIsTrue: false, //名字是否填写
  6. cultureIsTrue: false, //文化是否填写
  7. graduationIsTrue: false, //毕业学校
  8. majorIsTrue: false, //所有专业
  9. postIsTrue: false, //现任职务
  10. renzhishijianIsTrue: false,
  11. phoneIsTrue: false, //电话
  12. peixunshijianTrue: false, // 培训时间
  13. nameMessage: '',
  14. zaizhiTime: [], //在线时间
  15. peixunTime: '', //培训时间
  16. headmasterText: [], //
  17. names: [],
  18. timeIndex: '',
  19. chooseValue: [], // 选择的答案序列
  20. radio: '1',
  21. renzhiDate: '',
  22. postshow: [],
  23. postshow1: false,
  24. errorIsTrue: false,
  25. currentDate: new Date().getTime(),
  26. currentDate1: new Date().getTime(),
  27. minDate: new Date().getTime,
  28. formatter(type, value) {
  29. if (type === 'year') {
  30. return `${value}年`;
  31. } else if (type === 'month') {
  32. return `${value}月`;
  33. }
  34. return value;
  35. },
  36. questionList: [],
  37. answersId: '', // 提交答案用到
  38. sessionKey: '',
  39. paperId: '',
  40. answersId: '',
  41. id: '',
  42. status: ''
  43. },
  44. onChange(event) {
  45. this.setData({
  46. radio: event.detail,
  47. });
  48. },
  49. radioChange(e) {
  50. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  51. for (let i = 0, len = items.length; i < len; ++i) {
  52. items[i].checked = items[i].value === e.detail.value
  53. }
  54. let json = {};
  55. json.currentAnswer = e.detail.value;
  56. json.id = e.currentTarget.dataset.idx;
  57. json.questType = e.currentTarget.dataset.questtypes;
  58. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  59. this.setData({
  60. questionList: this.data.questionList
  61. })
  62. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  63. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  64. },
  65. checkboxChange(e) {
  66. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  67. const values = e.detail.value
  68. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  69. items[i].checked = false
  70. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  71. if (items[i].value === values[j]) {
  72. items[i].checked = true
  73. break
  74. }
  75. }
  76. }
  77. let json = {};
  78. let aa = e.detail.value.join("||")
  79. json.currentAnswer = aa;
  80. json.id = e.currentTarget.dataset.idx;
  81. json.questType = e.currentTarget.dataset.questtypes;
  82. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  83. this.setData({
  84. questionList: this.data.questionList
  85. })
  86. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  87. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  88. },
  89. bindTextAreaBlur(e) {
  90. let json = {};
  91. json.currentAnswer = e.detail.value;
  92. json.id = e.currentTarget.dataset.idx;
  93. json.questType = e.currentTarget.dataset.questtypes;
  94. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  95. this.data.questionList[e.currentTarget.dataset.index].QuestAnswer = e.detail.value;
  96. this.setData({
  97. questionList: this.data.questionList
  98. })
  99. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  100. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  101. },
  102. share() {
  103. this.setData({
  104. show: true
  105. });
  106. },
  107. onClose() {
  108. this.setData({
  109. ['postshow[' + this.data.timeIndex + ']']: false,
  110. });
  111. },
  112. onClose1() {
  113. this.setData({
  114. postshow1: false
  115. });
  116. },
  117. onInput(event) {
  118. this.setData({
  119. currentDate: event.detail,
  120. });
  121. },
  122. onInput1(event) {
  123. this.setData({
  124. currentDate1: event.detail,
  125. });
  126. },
  127. formatDate(date) {
  128. date = new Date(date);
  129. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  130. },
  131. share1(e) {
  132. this.data.postshow[e.currentTarget.dataset.index] = true;
  133. this.data.names[e.currentTarget.dataset.index] = e.currentTarget.dataset.names;
  134. this.setData({
  135. postshow: this.data.postshow,
  136. timeIndex: e.currentTarget.dataset.index
  137. })
  138. },
  139. share() {
  140. this.setData({
  141. postshow1: true
  142. });
  143. },
  144. formatDate(date) {
  145. date = new Date(date);
  146. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  147. },
  148. onConfirm(event) {
  149. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  150. let json = {};
  151. json.currentAnswer = timeValue;
  152. json.id = event.currentTarget.dataset.idx;
  153. json.questType = event.currentTarget.dataset.questtypes;
  154. let aa = this.data.chooseValue[event.currentTarget.dataset.index] = json;
  155. this.data.questionList[event.currentTarget.dataset.index].QuestAnswer = timeValue;
  156. this.setData({
  157. questionList: this.data.questionList,
  158. ['chooseValue[' + event.currentTarget.dataset.index + ']']: aa,
  159. ['postshow[' + this.data.timeIndex + ']']: false,
  160. ['headmasterText[' + this.data.timeIndex + ']']: '',
  161. });
  162. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  163. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  164. },
  165. onConfirm1(event) {
  166. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  167. this.setData({
  168. peixunTime: timeValue,
  169. postshow1: false,
  170. peixunText: ''
  171. });
  172. },
  173. parameterTap: function (e) { //e是获取e.currentTarget.dataset.id所以是必备的,跟前端的data-id获取的方式差不多
  174. let that = this
  175. let this_checked = e.currentTarget.dataset.id
  176. let parameterList = this.data.parameter //获取Json数组
  177. for (let i = 0; i < parameterList.length; i++) {
  178. if (parameterList[i].id == this_checked) {
  179. parameterList[i].checked = true; //当前点击的位置为true即选中
  180. } else {
  181. parameterList[i].checked = false; //其他的位置为false
  182. }
  183. }
  184. that.setData({
  185. parameter: parameterList
  186. })
  187. },
  188. submitForm() {
  189. let obj = this.data.chooseValue.find(item=>!item.currentAnswer)
  190. if(!obj){
  191. wx.showLoading({
  192. mask: true,
  193. title: '加载中',
  194. })
  195. wx.request({
  196. url: app.globalData.publicUrl + '/wx/paper/commit',
  197. method: "post",
  198. data: {
  199. sessionKey: this.data.sessionKey,
  200. currentAnswerTemp: this.data.chooseValue,
  201. answersId: wx.getStorageSync('answersId')
  202. },
  203. success: (res) => {
  204. console.log("提交上去可");
  205. wx.hideLoading();
  206. if (res.data.code == 0) {
  207. wx.showModal({
  208. showCancel: false,
  209. content: '评价成功',
  210. success() {
  211. wx.navigateBack({
  212. delta: 1
  213. })
  214. }
  215. })
  216. } else {
  217. wx.showModal({
  218. showCancel: false,
  219. content: res.data.msg,
  220. success() {
  221. wx.navigateBack({
  222. delta: 1
  223. })
  224. }
  225. })
  226. }
  227. }
  228. })
  229. }else{
  230. wx.showModal({
  231. showCancel: false,
  232. content: '333333',
  233. success() {
  234. }
  235. })
  236. }
  237. },
  238. timeFormat(date, fmt) {
  239. let o = {
  240. "M+": date.getMonth() + 1, //月份   
  241. "d+": date.getDate(), //日
  242. "h+": date.getHours(), //小时   
  243. "m+": date.getMinutes(), //分   
  244. "s+": date.getSeconds(), //秒   
  245. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  246. "S": date.getMilliseconds() //毫秒   
  247. };
  248. if (/(y+)/.test(fmt))
  249. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  250. for (let k in o)
  251. if (new RegExp("(" + k + ")").test(fmt))
  252. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  253. return fmt;
  254. },
  255. async onLoad(options) {
  256. const sessionKey = await tools.checkSessionAndLogin();
  257. wx.setStorageSync('answersId', options.answersId);
  258. this.setData({
  259. sessionKey: sessionKey,
  260. paperId: options.paperId,
  261. answersId: options.answersId,
  262. id: options.id,
  263. })
  264. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  265. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  266. this.setData({
  267. questionList: questionList,
  268. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  269. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  270. })
  271. } else {
  272. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  273. }
  274. },
  275. allShi(id, paperId, sessionKey) {
  276. wx.request({
  277. url: app.globalData.publicUrl + '/wx/paper/detail',
  278. method: "post",
  279. data: {
  280. sessionKey: sessionKey,
  281. id: id,
  282. paperId: paperId
  283. },
  284. success: (res) => {
  285. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  286. let json = {};
  287. json.QuestType = item.QuestType;
  288. json.Id = item.Id;
  289. json.QuestAnswer = item.QuestAnswer;
  290. json.QuestStem = item.QuestStem;
  291. if (item.QuestType == '1' || item.QuestType == '0') {
  292. let arr = item.QuestChoice.split('||');
  293. let arrJson = arr.map(item => {
  294. let json1 = {};
  295. json1.name = item;
  296. json1.value = item;
  297. json1.checked = false;
  298. return json1
  299. });
  300. json.QuestChoice = arrJson;
  301. }
  302. return json;
  303. })
  304. // 答案锕
  305. let chooceArr = jsonArr.map(item => {
  306. let json = {};
  307. json.currentAnswer = '';
  308. json.questType = '';
  309. json.id = item.Id;
  310. json.QuestStem = item.QuestStem;
  311. return json
  312. })
  313. this.setData({
  314. questionList: jsonArr,
  315. chooseValue: chooceArr
  316. })
  317. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  318. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  319. }
  320. })
  321. },
  322. })