evaluationCourse.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. //index.js
  2. //获取应用实例 studentRegistration
  3. const app = require('../../utils/util.js');
  4. const tools = require('../../utils/tools.js');
  5. Page({
  6. data: {
  7. nameIsTrue: false, //名字是否填写
  8. cultureIsTrue: false, //文化是否填写
  9. graduationIsTrue: false, //毕业学校
  10. majorIsTrue: false, //所有专业
  11. postIsTrue: false, //现任职务
  12. renzhishijianIsTrue: false,
  13. phoneIsTrue: false, //电话
  14. peixunshijianTrue: false, // 培训时间
  15. nameMessage: '',
  16. zaizhiTime: [], //在线时间
  17. peixunTime: '', //培训时间
  18. headmasterText: [], //
  19. names: [],
  20. timeIndex: '',
  21. chooseValue: [], // 选择的答案序列
  22. radio: '1',
  23. renzhiDate: '',
  24. postshow: [],
  25. postshow1: false,
  26. errorIsTrue: false,
  27. currentDate: new Date().getTime(),
  28. currentDate1: new Date().getTime(),
  29. minDate: new Date().getTime,
  30. formatter(type, value) {
  31. if (type === 'year') {
  32. return `${value}年`;
  33. } else if (type === 'month') {
  34. return `${value}月`;
  35. }
  36. return value;
  37. },
  38. questionList: [
  39. // {
  40. // "QuestType": "6",
  41. // "Id": 11,
  42. // name: 'ccccc',
  43. // QuestStem: '时间选择',
  44. // QuestAnswer: ''
  45. // },
  46. // {
  47. // "QuestType": "5",
  48. // "Id": 11,
  49. // name: 'dddd',
  50. // QuestStem: '姓名输入',
  51. // QuestAnswer: ''
  52. // },
  53. // {
  54. // "QuestType": "6",
  55. // "Id": 11,
  56. // name: 'username111',
  57. // QuestStem: '时间2',
  58. // QuestAnswer: ''
  59. // },
  60. // {
  61. // "QuestType": "5",
  62. // "Id": 11,
  63. // name: 'address',
  64. // QuestStem: '姓名输入',
  65. // QuestAnswer: ''
  66. // },
  67. // {
  68. // "QuestType": "0",
  69. // "QuestChoice": [{
  70. // value: 'USA',
  71. // name: '美国'
  72. // },
  73. // {
  74. // value: 'CHN',
  75. // name: '中国',
  76. // checked: 'true'
  77. // },
  78. // {
  79. // value: 'BRA',
  80. // name: '巴西'
  81. // },
  82. // {
  83. // value: 'JPN',
  84. // name: '日本'
  85. // },
  86. // {
  87. // value: 'ENG',
  88. // name: '英国'
  89. // },
  90. // {
  91. // value: 'FRA',
  92. // name: '法国'
  93. // },
  94. // ],
  95. // "Id": 36,
  96. // name: 'sex',
  97. // QuestStem: '性别单选'
  98. // },
  99. // {
  100. // "QuestType": "0",
  101. // "QuestChoice": [{
  102. // value: '男',
  103. // name: '男',
  104. // checked: false,
  105. // },
  106. // {
  107. // value: '女',
  108. // name: '女',
  109. // checked: false,
  110. // },
  111. // ],
  112. // "Id": 36,
  113. // name: 'sex111',
  114. // QuestStem: '性别单选2222'
  115. // },
  116. // {
  117. // "QuestType": "1",
  118. // "QuestAnswer": "equals ()||\nhashCode()||",
  119. // "QuestChoice": [{
  120. // value: 'USA',
  121. // name: '美国'
  122. // },
  123. // {
  124. // value: 'CHN',
  125. // name: '中国',
  126. // checked: false
  127. // },
  128. // {
  129. // value: 'FRA',
  130. // name: '法国'
  131. // }
  132. // ],
  133. // "Id": 38,
  134. // name: 'alls',
  135. // QuestStem: '多选'
  136. // },
  137. // {
  138. // "QuestType": "2",
  139. // "QuestStem": "1+1=2",
  140. // "QuestAnswer": "是",
  141. // "QuestChoice": [{
  142. // value: 'USA',
  143. // name: '是'
  144. // },
  145. // {
  146. // value: 'CHN',
  147. // name: '中国',
  148. // checked: false
  149. // },
  150. // ],
  151. // "Id": 42,
  152. // name: 'lllll',
  153. // QuestStem: '判断1'
  154. // },
  155. // {
  156. // "QuestType": "2",
  157. // "QuestStem": "1+1=2",
  158. // "QuestAnswer": "是",
  159. // "QuestChoice": [{
  160. // value: 'USA',
  161. // name: '是'
  162. // },
  163. // {
  164. // value: 'CHN',
  165. // name: '中国',
  166. // checked: false
  167. // },
  168. // ],
  169. // "Id": 42,
  170. // name: 'lllll',
  171. // QuestStem: '判断2'
  172. // },
  173. // {
  174. // "QuestType": "2",
  175. // "QuestStem": "1+1=2",
  176. // "QuestAnswer": "是",
  177. // "QuestChoice": [{
  178. // value: 'USA',
  179. // name: '是'
  180. // },
  181. // {
  182. // value: 'CHN',
  183. // name: '中国',
  184. // checked: false
  185. // },
  186. // ],
  187. // "Id": 42,
  188. // name: 'lllll',
  189. // QuestStem: '判断3'
  190. // },
  191. // {
  192. // "QuestType": "3",
  193. // "QuestStem": "世纪大厦的萨科技的哈市(解答)",
  194. // "QuestAnswer": "",
  195. // "QuestChoice": "",
  196. // "Id": 39,
  197. // name: 'textarea',
  198. // },
  199. ],
  200. answersId: '', // 提交答案用到
  201. sessionKey: '',
  202. paperId: '',
  203. answersId: '',
  204. id: '',
  205. status: ''
  206. },
  207. onChange(event) {
  208. this.setData({
  209. radio: event.detail,
  210. });
  211. },
  212. radioChange(e) {
  213. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  214. for (let i = 0, len = items.length; i < len; ++i) {
  215. items[i].checked = items[i].value === e.detail.value
  216. }
  217. let json = {};
  218. json.currentAnswer = e.detail.value;
  219. json.id = e.currentTarget.dataset.idx;
  220. json.questType = e.currentTarget.dataset.questtypes;
  221. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  222. this.setData({
  223. questionList: this.data.questionList
  224. })
  225. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  226. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  227. },
  228. checkboxChange(e) {
  229. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  230. const values = e.detail.value
  231. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  232. items[i].checked = false
  233. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  234. if (items[i].value === values[j]) {
  235. items[i].checked = true
  236. break
  237. }
  238. }
  239. }
  240. let json = {};
  241. let aa = e.detail.value.join("||")
  242. json.currentAnswer = aa;
  243. json.id = e.currentTarget.dataset.idx;
  244. json.questType = e.currentTarget.dataset.questtypes;
  245. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  246. this.setData({
  247. questionList: this.data.questionList
  248. })
  249. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  250. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  251. },
  252. bindTextAreaBlur(e) {
  253. let json = {};
  254. json.currentAnswer = e.detail.value;
  255. json.id = e.currentTarget.dataset.idx;
  256. json.questType = e.currentTarget.dataset.questtypes;
  257. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  258. this.data.questionList[e.currentTarget.dataset.index].QuestAnswer = e.detail.value;
  259. this.setData({
  260. questionList: this.data.questionList
  261. })
  262. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  263. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  264. },
  265. share() {
  266. this.setData({
  267. show: true
  268. });
  269. },
  270. onClose() {
  271. this.setData({
  272. ['postshow[' + this.data.timeIndex + ']']: false,
  273. });
  274. },
  275. onClose1() {
  276. this.setData({
  277. postshow1: false
  278. });
  279. },
  280. onInput(event) {
  281. this.setData({
  282. currentDate: event.detail,
  283. });
  284. },
  285. onInput1(event) {
  286. this.setData({
  287. currentDate1: event.detail,
  288. });
  289. },
  290. formatDate(date) {
  291. date = new Date(date);
  292. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  293. },
  294. share1(e) {
  295. this.data.postshow[e.currentTarget.dataset.index] = true;
  296. this.data.names[e.currentTarget.dataset.index] = e.currentTarget.dataset.names;
  297. this.setData({
  298. postshow: this.data.postshow,
  299. timeIndex: e.currentTarget.dataset.index
  300. })
  301. },
  302. share() {
  303. this.setData({
  304. postshow1: true
  305. });
  306. },
  307. formatDate(date) {
  308. date = new Date(date);
  309. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  310. },
  311. onConfirm(event) {
  312. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  313. let json = {};
  314. json.currentAnswer = timeValue;
  315. json.id = event.currentTarget.dataset.idx;
  316. json.questType = event.currentTarget.dataset.questtypes;
  317. let aa = this.data.chooseValue[event.currentTarget.dataset.index] = json;
  318. this.data.questionList[event.currentTarget.dataset.index].QuestAnswer = timeValue;
  319. this.setData({
  320. questionList: this.data.questionList,
  321. ['chooseValue[' + event.currentTarget.dataset.index + ']']: aa,
  322. ['postshow[' + this.data.timeIndex + ']']: false,
  323. ['headmasterText[' + this.data.timeIndex + ']']: '',
  324. });
  325. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  326. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  327. },
  328. onConfirm1(event) {
  329. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  330. this.setData({
  331. peixunTime: timeValue,
  332. postshow1: false,
  333. peixunText: ''
  334. });
  335. },
  336. parameterTap: function (e) { //e是获取e.currentTarget.dataset.id所以是必备的,跟前端的data-id获取的方式差不多
  337. let that = this
  338. let this_checked = e.currentTarget.dataset.id
  339. let parameterList = this.data.parameter //获取Json数组
  340. for (let i = 0; i < parameterList.length; i++) {
  341. if (parameterList[i].id == this_checked) {
  342. parameterList[i].checked = true; //当前点击的位置为true即选中
  343. } else {
  344. parameterList[i].checked = false; //其他的位置为false
  345. }
  346. }
  347. that.setData({
  348. parameter: parameterList
  349. })
  350. },
  351. submitForm() {
  352. wx.showLoading({
  353. mask: true,
  354. title: '加载中',
  355. })
  356. wx.request({
  357. url: app.globalData.publicUrl + '/wx/paper/commit',
  358. method: "post",
  359. data: {
  360. sessionKey: this.data.sessionKey,
  361. currentAnswerTemp: this.data.chooseValue,
  362. answersId: wx.getStorageSync('answersId')
  363. },
  364. success: (res) => {
  365. wx.hideLoading();
  366. if (res.data.code == 0) {
  367. wx.showModal({
  368. showCancel: false,
  369. content: '评价成功',
  370. success() {
  371. wx.navigateBack({
  372. delta: 1
  373. })
  374. }
  375. })
  376. } else {
  377. wx.showModal({
  378. showCancel: false,
  379. content: res.data.msg,
  380. success() {
  381. wx.navigateBack({
  382. delta: 1
  383. })
  384. }
  385. })
  386. }
  387. }
  388. })
  389. },
  390. timeFormat(date, fmt) {
  391. let o = {
  392. "M+": date.getMonth() + 1, //月份   
  393. "d+": date.getDate(), //日
  394. "h+": date.getHours(), //小时   
  395. "m+": date.getMinutes(), //分   
  396. "s+": date.getSeconds(), //秒   
  397. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  398. "S": date.getMilliseconds() //毫秒   
  399. };
  400. if (/(y+)/.test(fmt))
  401. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  402. for (let k in o)
  403. if (new RegExp("(" + k + ")").test(fmt))
  404. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  405. return fmt;
  406. },
  407. async onLoad(options) {
  408. const sessionKey = await tools.checkSessionAndLogin();
  409. wx.setStorageSync('answersId', options.answersId);
  410. this.setData({
  411. sessionKey: sessionKey,
  412. paperId: options.paperId,
  413. answersId: options.answersId,
  414. id: options.id,
  415. })
  416. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  417. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  418. this.setData({
  419. questionList: questionList,
  420. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  421. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  422. })
  423. } else {
  424. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  425. }
  426. },
  427. allShi(id, paperId, sessionKey) {
  428. wx.request({
  429. url: app.globalData.publicUrl + '/wx/paper/detail',
  430. method: "post",
  431. data: {
  432. sessionKey: sessionKey,
  433. id: id,
  434. paperId: paperId
  435. },
  436. success: (res) => {
  437. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  438. let json = {};
  439. json.QuestType = item.QuestType;
  440. json.Id = item.Id;
  441. json.QuestAnswer = item.QuestAnswer;
  442. json.QuestStem = item.QuestStem;
  443. if (item.QuestType == '1' || item.QuestType == '0') {
  444. let arr = item.QuestChoice.split('||');
  445. let arrJson = arr.map(item => {
  446. let json1 = {};
  447. json1.name = item;
  448. json1.value = item;
  449. json1.checked = false;
  450. return json1
  451. });
  452. json.QuestChoice = arrJson;
  453. }
  454. return json;
  455. })
  456. // 答案锕
  457. let chooceArr = jsonArr.map(item => {
  458. let json = {};
  459. json.currentAnswer = '';
  460. json.questType = '';
  461. json.id = item.Id;
  462. json.QuestStem = item.QuestStem;
  463. return json
  464. })
  465. this.setData({
  466. questionList: jsonArr,
  467. chooseValue: chooceArr
  468. })
  469. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  470. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  471. }
  472. })
  473. },
  474. })