evaluationCourse.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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. wx.showLoading({
  403. mask: true,
  404. title: '加载中',
  405. })
  406. console.log(this.data.chooseValue, "打印下提交");
  407. wx.request({
  408. url: app.globalData.publicUrl + '/wx/paper/commit',
  409. method: "post",
  410. data: {
  411. sessionKey: this.data.sessionKey,
  412. currentAnswerTemp: this.data.chooseValue,
  413. answersId: wx.getStorageSync('answersId')
  414. },
  415. success: (res) => {
  416. wx.hideLoading();
  417. console.log(res);
  418. if(res.data.msg == "请勿重复提交"){
  419. wx.showModal({
  420. showCancel: false,
  421. content: res.data.msg,
  422. success(res) {}
  423. })
  424. }else{
  425. wx.showModal({
  426. showCancel: false,
  427. content: '评价成功',
  428. success() {
  429. wx.navigateBack({
  430. delta: 1
  431. })
  432. }
  433. })
  434. }
  435. }
  436. })
  437. // let isTrue = false;
  438. // this.data.chooseValue.forEach(item => {
  439. // console.log(item, "123123");
  440. // if (item.currentAnswer) {
  441. // isTrue = true;
  442. // } else {
  443. // wx.showModal({
  444. // showCancel: false,
  445. // content: item.QuestStem + "不能为空",
  446. // success(res) {}
  447. // })
  448. // }
  449. // })
  450. // if (isTrue) {
  451. // console.log("提交了");
  452. // wx.request({
  453. // url: app.globalData.publicUrl + '/wx/paper/commit',
  454. // method: "post",
  455. // data: {
  456. // sessionKey: this.data.sessionKey,
  457. // currentAnswerTemp: this.data.chooseValue,
  458. // answersId: wx.getStorageSync('answersId')
  459. // },
  460. // success: (res) => {
  461. // console.log(res);
  462. // if(res.data.msg == "请勿重复提交"){
  463. // wx.showModal({
  464. // showCancel: false,
  465. // content: res.data.msg,
  466. // success(res) {}
  467. // })
  468. // }else{
  469. // wx.navigateTo({
  470. // url: '/pages/myClass/myClass',
  471. // })
  472. // }
  473. // }
  474. // })
  475. // }
  476. },
  477. timeFormat(date, fmt) {
  478. let o = {
  479. "M+": date.getMonth() + 1, //月份   
  480. "d+": date.getDate(), //日
  481. "h+": date.getHours(), //小时   
  482. "m+": date.getMinutes(), //分   
  483. "s+": date.getSeconds(), //秒   
  484. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  485. "S": date.getMilliseconds() //毫秒   
  486. };
  487. if (/(y+)/.test(fmt))
  488. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  489. for (let k in o)
  490. if (new RegExp("(" + k + ")").test(fmt))
  491. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  492. return fmt;
  493. },
  494. onReady: function () {},
  495. async onLoad (options) {
  496. //const sessionKey = 'BqQROCKCxn7R2NXdQLud9Q==';
  497. console.log("onloading.....................");
  498. const sessionKey = await tools.checkSessionAndLogin();
  499. console.log(sessionKey,"对接下");
  500. wx.setStorageSync('answersId', options.answersId);
  501. this.setData({
  502. sessionKey: sessionKey,
  503. paperId: options.paperId,
  504. answersId: options.answersId,
  505. id: options.id,
  506. })
  507. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  508. console.log("缓村了锕");
  509. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  510. this.setData({
  511. questionList: questionList,
  512. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  513. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  514. })
  515. console.log(this.data.questionList, "show 缓存的数据");
  516. } else {
  517. console.log("无缓存");
  518. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  519. }
  520. },
  521. allShi(id, paperId, sessionKey) {
  522. wx.request({
  523. url: app.globalData.publicUrl + '/wx/paper/detail',
  524. method: "post",
  525. data: {
  526. sessionKey: sessionKey,
  527. id: id,
  528. paperId: paperId
  529. },
  530. success: (res) => {
  531. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  532. let json = {};
  533. json.QuestType = item.QuestType;
  534. json.Id = item.Id;
  535. json.QuestAnswer = item.QuestAnswer;
  536. json.QuestStem = item.QuestStem;
  537. if (item.QuestType == '1' || item.QuestType == '0') {
  538. let arr = item.QuestChoice.split('||');
  539. let arrJson = arr.map(item => {
  540. let json1 = {};
  541. json1.name = item;
  542. json1.value = item;
  543. json1.checked = false;
  544. return json1
  545. });
  546. json.QuestChoice = arrJson;
  547. }
  548. return json;
  549. })
  550. // 答案锕
  551. let chooceArr = jsonArr.map(item => {
  552. let json = {};
  553. json.currentAnswer = '';
  554. json.questType = '';
  555. json.id = item.Id;
  556. json.QuestStem = item.QuestStem;
  557. return json
  558. })
  559. this.setData({
  560. questionList: jsonArr,
  561. chooseValue: chooceArr
  562. })
  563. console.log(this.data.questionList, "00000");
  564. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  565. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  566. }
  567. })
  568. },
  569. })