evaluationCourse.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. console.log(e);
  214. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  215. for (let i = 0, len = items.length; i < len; ++i) {
  216. items[i].checked = items[i].value === e.detail.value
  217. }
  218. let json = {};
  219. json.currentAnswer = e.detail.value;
  220. json.id = e.currentTarget.dataset.idx;
  221. json.questType = e.currentTarget.dataset.questtypes;
  222. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  223. this.setData({
  224. questionList: this.data.questionList
  225. })
  226. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  227. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  228. console.log(this.data.questionList);
  229. },
  230. checkboxChange(e) {
  231. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  232. const values = e.detail.value
  233. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  234. items[i].checked = false
  235. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  236. if (items[i].value === values[j]) {
  237. items[i].checked = true
  238. break
  239. }
  240. }
  241. }
  242. let json = {};
  243. let aa = e.detail.value.join("||")
  244. json.currentAnswer = aa;
  245. json.id = e.currentTarget.dataset.idx;
  246. json.questType = e.currentTarget.dataset.questtypes;
  247. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  248. this.setData({
  249. questionList: this.data.questionList
  250. })
  251. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  252. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  253. },
  254. bindTextAreaBlur(e) {
  255. console.log(e, "hhhhh");
  256. console.log(e.detail.value);
  257. let json = {};
  258. json.currentAnswer = e.detail.value;
  259. json.id = e.currentTarget.dataset.idx;
  260. json.questType = e.currentTarget.dataset.questtypes;
  261. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  262. this.data.questionList[e.currentTarget.dataset.index].QuestAnswer = e.detail.value;
  263. this.setData({
  264. questionList: this.data.questionList
  265. })
  266. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  267. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  268. },
  269. share() {
  270. this.setData({
  271. show: true
  272. });
  273. },
  274. onClose() {
  275. this.setData({
  276. ['postshow[' + this.data.timeIndex + ']']: false,
  277. });
  278. },
  279. onClose1() {
  280. console.log("11111111111111");
  281. this.setData({
  282. postshow1: false
  283. });
  284. },
  285. onInput(event) {
  286. console.log(event, "8888888");
  287. console.log("点击了");
  288. this.setData({
  289. currentDate: event.detail,
  290. });
  291. },
  292. onInput1(event) {
  293. console.log("000");
  294. this.setData({
  295. currentDate1: event.detail,
  296. });
  297. },
  298. formatDate(date) {
  299. date = new Date(date);
  300. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  301. },
  302. share1(e) {
  303. console.log(e);
  304. console.log(e.currentTarget.dataset.index);
  305. console.log(e.currentTarget.dataset.names, "8520852085208520");
  306. console.log(this.data.postshow[e.currentTarget.dataset.index]);
  307. this.data.postshow[e.currentTarget.dataset.index] = true;
  308. this.data.names[e.currentTarget.dataset.index] = e.currentTarget.dataset.names;
  309. this.setData({
  310. postshow: this.data.postshow,
  311. timeIndex: e.currentTarget.dataset.index
  312. })
  313. console.log(this.data.postshow, "打印下锕啊啊啊啊锕锕锕");
  314. },
  315. share() {
  316. this.setData({
  317. postshow1: true
  318. });
  319. },
  320. formatDate(date) {
  321. date = new Date(date);
  322. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  323. },
  324. onConfirm(event) {
  325. console.log(event, "1111111");
  326. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  327. let json = {};
  328. json.currentAnswer = timeValue;
  329. json.id = event.currentTarget.dataset.idx;
  330. json.questType = event.currentTarget.dataset.questtypes;
  331. let aa = this.data.chooseValue[event.currentTarget.dataset.index] = json;
  332. this.data.questionList[event.currentTarget.dataset.index].QuestAnswer = timeValue;
  333. this.setData({
  334. questionList: this.data.questionList,
  335. ['chooseValue[' + event.currentTarget.dataset.index + ']']: aa,
  336. ['postshow[' + this.data.timeIndex + ']']: false,
  337. ['headmasterText[' + this.data.timeIndex + ']']: '',
  338. });
  339. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  340. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  341. console.log(this.data.chooseValue, "确定后的值锕");
  342. console.log(this.data.questionList, "789789798789");
  343. },
  344. onConfirm1(event) {
  345. console.log(event, "0000");
  346. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  347. this.setData({
  348. peixunTime: timeValue,
  349. postshow1: false,
  350. peixunText: ''
  351. });
  352. },
  353. parameterTap: function (e) { //e是获取e.currentTarget.dataset.id所以是必备的,跟前端的data-id获取的方式差不多
  354. let that = this
  355. let this_checked = e.currentTarget.dataset.id
  356. let parameterList = this.data.parameter //获取Json数组
  357. for (let i = 0; i < parameterList.length; i++) {
  358. if (parameterList[i].id == this_checked) {
  359. parameterList[i].checked = true; //当前点击的位置为true即选中
  360. } else {
  361. parameterList[i].checked = false; //其他的位置为false
  362. }
  363. }
  364. that.setData({
  365. parameter: parameterList
  366. })
  367. },
  368. // submitForm() {
  369. // //let arr1 = this.data.chooseValue.filter(d => d);
  370. // //console.log(arr1,"打印下提交");
  371. // console.log(this.data.chooseValue, "打印下提交");
  372. // let isTrue = false;
  373. // this.data.chooseValue.forEach(item => {
  374. // console.log(item, "123123");
  375. // if (item.currentAnswer) {
  376. // isTrue = true;
  377. // } else {
  378. // wx.showModal({
  379. // showCancel: false,
  380. // content: item.QuestStem + "不能为空",
  381. // success(res) {}
  382. // })
  383. // }
  384. // })
  385. // if (isTrue) {
  386. // console.log("提交了");
  387. // wx.request({
  388. // url: app.globalData.publicUrl + '/wx/paper/commit',
  389. // method: "post",
  390. // data: {
  391. // sessionKey: this.data.sessionKey,
  392. // currentAnswerTemp: this.data.chooseValue,
  393. // answersId: wx.getStorageSync('answersId')
  394. // },
  395. // success: (res) => {
  396. // console.log(res);
  397. // }
  398. // })
  399. // }
  400. // },
  401. submitForm() {
  402. console.log(this.data.chooseValue, "打印下提交");
  403. wx.request({
  404. url: app.globalData.publicUrl + '/wx/paper/commit',
  405. method: "post",
  406. data: {
  407. sessionKey: this.data.sessionKey,
  408. currentAnswerTemp: this.data.chooseValue,
  409. answersId: wx.getStorageSync('answersId')
  410. },
  411. success: (res) => {
  412. console.log(res);
  413. if(res.data.msg == "请勿重复提交"){
  414. wx.showModal({
  415. showCancel: false,
  416. content: res.data.msg,
  417. success(res) {}
  418. })
  419. }else{
  420. wx.showModal({
  421. showCancel: false,
  422. content: '评价成功',
  423. success() {
  424. wx.navigateBack({
  425. delta: 1
  426. })
  427. }
  428. })
  429. }
  430. }
  431. })
  432. // let isTrue = false;
  433. // this.data.chooseValue.forEach(item => {
  434. // console.log(item, "123123");
  435. // if (item.currentAnswer) {
  436. // isTrue = true;
  437. // } else {
  438. // wx.showModal({
  439. // showCancel: false,
  440. // content: item.QuestStem + "不能为空",
  441. // success(res) {}
  442. // })
  443. // }
  444. // })
  445. // if (isTrue) {
  446. // console.log("提交了");
  447. // wx.request({
  448. // url: app.globalData.publicUrl + '/wx/paper/commit',
  449. // method: "post",
  450. // data: {
  451. // sessionKey: this.data.sessionKey,
  452. // currentAnswerTemp: this.data.chooseValue,
  453. // answersId: wx.getStorageSync('answersId')
  454. // },
  455. // success: (res) => {
  456. // console.log(res);
  457. // if(res.data.msg == "请勿重复提交"){
  458. // wx.showModal({
  459. // showCancel: false,
  460. // content: res.data.msg,
  461. // success(res) {}
  462. // })
  463. // }else{
  464. // wx.navigateTo({
  465. // url: '/pages/myClass/myClass',
  466. // })
  467. // }
  468. // }
  469. // })
  470. // }
  471. },
  472. timeFormat(date, fmt) {
  473. let o = {
  474. "M+": date.getMonth() + 1, //月份   
  475. "d+": date.getDate(), //日
  476. "h+": date.getHours(), //小时   
  477. "m+": date.getMinutes(), //分   
  478. "s+": date.getSeconds(), //秒   
  479. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  480. "S": date.getMilliseconds() //毫秒   
  481. };
  482. if (/(y+)/.test(fmt))
  483. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  484. for (let k in o)
  485. if (new RegExp("(" + k + ")").test(fmt))
  486. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  487. return fmt;
  488. },
  489. onReady: function () {},
  490. async onLoad (options) {
  491. //const sessionKey = 'BqQROCKCxn7R2NXdQLud9Q==';
  492. console.log("onloading.....................");
  493. const sessionKey = await tools.checkSessionAndLogin();
  494. console.log(sessionKey,"对接下");
  495. wx.setStorageSync('answersId', options.answersId);
  496. this.setData({
  497. sessionKey: sessionKey,
  498. paperId: options.paperId,
  499. answersId: options.answersId,
  500. id: options.id,
  501. })
  502. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  503. console.log("缓村了锕");
  504. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  505. this.setData({
  506. questionList: questionList,
  507. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  508. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  509. })
  510. console.log(this.data.questionList, "show 缓存的数据");
  511. } else {
  512. console.log("无缓存");
  513. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  514. }
  515. },
  516. allShi(id, paperId, sessionKey) {
  517. wx.request({
  518. url: app.globalData.publicUrl + '/wx/paper/detail',
  519. method: "post",
  520. data: {
  521. sessionKey: sessionKey,
  522. id: id,
  523. paperId: paperId
  524. },
  525. success: (res) => {
  526. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  527. let json = {};
  528. json.QuestType = item.QuestType;
  529. json.Id = item.Id;
  530. json.QuestAnswer = item.QuestAnswer;
  531. json.QuestStem = item.QuestStem;
  532. if (item.QuestType == '1' || item.QuestType == '0') {
  533. let arr = item.QuestChoice.split('||');
  534. let arrJson = arr.map(item => {
  535. let json1 = {};
  536. json1.name = item;
  537. json1.value = item;
  538. json1.checked = false;
  539. return json1
  540. });
  541. json.QuestChoice = arrJson;
  542. }
  543. return json;
  544. })
  545. // 答案锕
  546. let chooceArr = jsonArr.map(item => {
  547. let json = {};
  548. json.currentAnswer = '';
  549. json.questType = '';
  550. json.id = item.Id;
  551. json.QuestStem = item.QuestStem;
  552. return json
  553. })
  554. this.setData({
  555. questionList: jsonArr,
  556. chooseValue: chooceArr
  557. })
  558. console.log(this.data.questionList, "00000");
  559. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  560. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  561. }
  562. })
  563. },
  564. })