studentRegistration.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. //index.js
  2. //获取应用实例
  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. "QuestType": "6",
  40. "Id": 11,
  41. name: 'ccccc',
  42. QuestStem: '时间选择',
  43. QuestAnswer: ''
  44. },
  45. {
  46. "QuestType": "5",
  47. "Id": 11,
  48. name: 'dddd',
  49. QuestStem: '姓名输入',
  50. QuestAnswer: ''
  51. },
  52. {
  53. "QuestType": "6",
  54. "Id": 11,
  55. name: 'username111',
  56. QuestStem: '时间2',
  57. QuestAnswer: ''
  58. },
  59. {
  60. "QuestType": "5",
  61. "Id": 11,
  62. name: 'address',
  63. QuestStem: '姓名输入',
  64. QuestAnswer: ''
  65. },
  66. {
  67. "QuestType": "0",
  68. "QuestChoice": [{
  69. value: 'USA',
  70. name: '美国'
  71. },
  72. {
  73. value: 'CHN',
  74. name: '中国',
  75. checked: 'true'
  76. },
  77. {
  78. value: 'BRA',
  79. name: '巴西'
  80. },
  81. {
  82. value: 'JPN',
  83. name: '日本'
  84. },
  85. {
  86. value: 'ENG',
  87. name: '英国'
  88. },
  89. {
  90. value: 'FRA',
  91. name: '法国'
  92. },
  93. ],
  94. "Id": 36,
  95. name: 'sex',
  96. QuestStem: '性别单选'
  97. },
  98. {
  99. "QuestType": "0",
  100. "QuestChoice": [{
  101. value: '男',
  102. name: '男',
  103. checked: false,
  104. },
  105. {
  106. value: '女',
  107. name: '女',
  108. checked: false,
  109. },
  110. ],
  111. "Id": 36,
  112. name: 'sex111',
  113. QuestStem: '性别单选2222'
  114. },
  115. {
  116. "QuestType": "1",
  117. "QuestAnswer": "equals ()||\nhashCode()||",
  118. "QuestChoice": [{
  119. value: 'USA',
  120. name: '美国'
  121. },
  122. {
  123. value: 'CHN',
  124. name: '中国',
  125. checked: false
  126. },
  127. {
  128. value: 'FRA',
  129. name: '法国'
  130. }
  131. ],
  132. "Id": 38,
  133. name: 'alls',
  134. QuestStem: '多选'
  135. },
  136. {
  137. "QuestType": "2",
  138. "QuestStem": "1+1=2",
  139. "QuestAnswer": "是",
  140. "QuestChoice": [{
  141. value: 'USA',
  142. name: '是'
  143. },
  144. {
  145. value: 'CHN',
  146. name: '中国',
  147. checked: false
  148. },
  149. ],
  150. "Id": 42,
  151. name: 'lllll',
  152. QuestStem: '判断1'
  153. },
  154. {
  155. "QuestType": "2",
  156. "QuestStem": "1+1=2",
  157. "QuestAnswer": "是",
  158. "QuestChoice": [{
  159. value: 'USA',
  160. name: '是'
  161. },
  162. {
  163. value: 'CHN',
  164. name: '中国',
  165. checked: false
  166. },
  167. ],
  168. "Id": 42,
  169. name: 'lllll',
  170. QuestStem: '判断2'
  171. },
  172. {
  173. "QuestType": "2",
  174. "QuestStem": "1+1=2",
  175. "QuestAnswer": "是",
  176. "QuestChoice": [{
  177. value: 'USA',
  178. name: '是'
  179. },
  180. {
  181. value: 'CHN',
  182. name: '中国',
  183. checked: false
  184. },
  185. ],
  186. "Id": 42,
  187. name: 'lllll',
  188. QuestStem: '判断3'
  189. },
  190. {
  191. "QuestType": "3",
  192. "QuestStem": "世纪大厦的萨科技的哈市(解答)",
  193. "QuestAnswer": "",
  194. "QuestChoice": "",
  195. "Id": 39,
  196. name: 'textarea',
  197. },
  198. ],
  199. answersId: '', // 提交答案用到
  200. sessionKey: '',
  201. paperId: '',
  202. answersId: '',
  203. id: '',
  204. },
  205. onChange(event) {
  206. this.setData({
  207. radio: event.detail,
  208. });
  209. },
  210. radioChange(e) {
  211. console.log(e);
  212. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  213. for (let i = 0, len = items.length; i < len; ++i) {
  214. items[i].checked = items[i].value === e.detail.value
  215. }
  216. let json = {};
  217. json.currentAnswer = e.detail.value;
  218. json.id = e.currentTarget.dataset.idx;
  219. json.questType = e.currentTarget.dataset.questtypes;
  220. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  221. this.setData({
  222. questionList: this.data.questionList
  223. })
  224. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  225. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  226. console.log(this.data.questionList);
  227. // this.data.questionList[this.data.index].checked = e.detail.value;
  228. // this.setData({
  229. // questionList: this.data.questionList
  230. // })
  231. // const items = this.data.items
  232. // for (let i = 0, len = items.length; i < len; ++i) {
  233. // items[i].checked = items[i].value === e.detail.value
  234. // }
  235. // this.setData({
  236. // items
  237. // })
  238. },
  239. checkboxChange(e) {
  240. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  241. const values = e.detail.value
  242. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  243. items[i].checked = false
  244. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  245. if (items[i].value === values[j]) {
  246. items[i].checked = true
  247. break
  248. }
  249. }
  250. }
  251. let json = {};
  252. let aa = e.detail.value.join("||")
  253. json.currentAnswer = aa;
  254. json.id = e.currentTarget.dataset.idx;
  255. json.questType = e.currentTarget.dataset.questtypes;
  256. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  257. this.setData({
  258. questionList: this.data.questionList
  259. })
  260. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  261. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  262. },
  263. bindTextAreaBlur(e) {
  264. console.log(e, "hhhhh");
  265. console.log(e.detail.value);
  266. let json = {};
  267. json.currentAnswer = e.detail.value;
  268. json.id = e.currentTarget.dataset.idx;
  269. json.questType = e.currentTarget.dataset.questtypes;
  270. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  271. this.data.questionList[e.currentTarget.dataset.index].QuestAnswer = e.detail.value;
  272. this.setData({
  273. questionList: this.data.questionList
  274. })
  275. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  276. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  277. },
  278. share() {
  279. this.setData({
  280. show: true
  281. });
  282. },
  283. onClose() {
  284. this.setData({
  285. ['postshow[' + this.data.timeIndex + ']']: false,
  286. });
  287. },
  288. onClose1() {
  289. console.log("11111111111111");
  290. this.setData({
  291. postshow1: false
  292. });
  293. },
  294. onInput(event) {
  295. console.log(event, "8888888");
  296. console.log("点击了");
  297. this.setData({
  298. currentDate: event.detail,
  299. });
  300. },
  301. onInput1(event) {
  302. console.log("000");
  303. this.setData({
  304. currentDate1: event.detail,
  305. });
  306. },
  307. formatDate(date) {
  308. date = new Date(date);
  309. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  310. },
  311. share1(e) {
  312. console.log(e);
  313. console.log(e.currentTarget.dataset.index);
  314. console.log(e.currentTarget.dataset.names, "8520852085208520");
  315. console.log(this.data.postshow[e.currentTarget.dataset.index]);
  316. this.data.postshow[e.currentTarget.dataset.index] = true;
  317. this.data.names[e.currentTarget.dataset.index] = e.currentTarget.dataset.names;
  318. this.setData({
  319. postshow: this.data.postshow,
  320. timeIndex: e.currentTarget.dataset.index
  321. })
  322. console.log(this.data.postshow, "打印下锕啊啊啊啊锕锕锕");
  323. // this.setData({
  324. // postshow: true
  325. // });
  326. },
  327. share() {
  328. this.setData({
  329. postshow1: true
  330. });
  331. },
  332. formatDate(date) {
  333. date = new Date(date);
  334. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  335. },
  336. onConfirm(event) {
  337. console.log(event, "1111111");
  338. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  339. let json = {};
  340. json.currentAnswer = timeValue;
  341. json.id = event.currentTarget.dataset.idx;
  342. json.questType = event.currentTarget.dataset.questtypes;
  343. let aa = this.data.chooseValue[event.currentTarget.dataset.index] = json;
  344. this.data.questionList[event.currentTarget.dataset.index].QuestAnswer = timeValue;
  345. this.setData({
  346. questionList: this.data.questionList,
  347. ['chooseValue[' + event.currentTarget.dataset.index + ']']: aa,
  348. ['postshow[' + this.data.timeIndex + ']']: false,
  349. ['headmasterText[' + this.data.timeIndex + ']']: '',
  350. });
  351. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  352. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  353. console.log(this.data.chooseValue, "确定后的值锕");
  354. console.log( this.data.questionList,"789789798789");
  355. },
  356. onConfirm1(event) {
  357. console.log(event, "0000");
  358. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  359. this.setData({
  360. peixunTime: timeValue,
  361. postshow1: false,
  362. peixunText: ''
  363. });
  364. },
  365. parameterTap: function (e) { //e是获取e.currentTarget.dataset.id所以是必备的,跟前端的data-id获取的方式差不多
  366. let that = this
  367. let this_checked = e.currentTarget.dataset.id
  368. let parameterList = this.data.parameter //获取Json数组
  369. for (let i = 0; i < parameterList.length; i++) {
  370. if (parameterList[i].id == this_checked) {
  371. parameterList[i].checked = true; //当前点击的位置为true即选中
  372. } else {
  373. parameterList[i].checked = false; //其他的位置为false
  374. }
  375. }
  376. that.setData({
  377. parameter: parameterList
  378. })
  379. },
  380. submitForm() {
  381. // let arr1 = this.data.chooseValue.filter(d => d);
  382. //console.log(arr1,"打印下提交");
  383. console.log(this.data.chooseValue, "打印下提交");
  384. this.data.chooseValue.forEach(item => {
  385. console.log(item,"123123");
  386. if (item.currentAnswer) {
  387. } else {
  388. console.log(item.QuestStem);
  389. wx.showModal({
  390. showCancel: false,
  391. content: item.QuestStem + "不能为空",
  392. success(res) {}
  393. })
  394. }
  395. })
  396. // wx.request({
  397. // url: app.globalData.publicUrl + '/wx/paper/commit',
  398. // method: "post",
  399. // data: {
  400. // sessionKey: this.data.sessionKey,
  401. // currentAnswerTemp: arr1,
  402. // answersId: wx.getStorageSync('answersId')
  403. // },
  404. // success: (res) => {
  405. // console.log(res);
  406. // }
  407. // })
  408. },
  409. formSubmit(e) {
  410. console.log(e.detail.value, "000000000000000");
  411. let arr1 = this.data.zaizhiTime.filter(d => d);
  412. let arr = this.data.names.filter(d => d);
  413. var activeSubjectsArr = [];
  414. for (var i = 0; i < arr.length; i++) {
  415. var activeSubjectsObject = {};
  416. for (var j = 0; j < arr1.length; j++) {
  417. if (i == j) {
  418. activeSubjectsObject[arr[i]] = arr1[j];
  419. activeSubjectsArr.push(activeSubjectsObject);
  420. }
  421. }
  422. }
  423. console.log(activeSubjectsArr, "7777777");
  424. let count = 0;
  425. let data = {};
  426. for (let a in e.detail.value) {
  427. count += 1;
  428. if (count = 1) {
  429. data[a] = e.detail.value[a]
  430. }
  431. }
  432. activeSubjectsArr.forEach(item => {
  433. Object.assign(data, item)
  434. })
  435. console.log(data, "888888888888888888888888");
  436. // Object.keys(data).forEach(function (key) {
  437. // if (!data[key]) {
  438. // wx.showModal({
  439. // showCancel: false,
  440. // content: key + "不能为空"
  441. // })
  442. // return;
  443. // }
  444. // });
  445. // if (!e.detail.value.username) {
  446. // this.setData({
  447. // nameIsTrue: true
  448. // })
  449. // } else {
  450. // this.setData({
  451. // nameIsTrue: false
  452. // })
  453. // }
  454. // let sex = '';
  455. // if (this.data.parameter[0].checked) {
  456. // sex = this.data.parameter[0].name
  457. // this.setData({
  458. // errorIsTrue: false
  459. // })
  460. // } else if (this.data.parameter[1].checked) {
  461. // sex = this.data.parameter[1].name
  462. // this.setData({
  463. // errorIsTrue: false
  464. // })
  465. // } else {
  466. // this.setData({
  467. // errorIsTrue: true
  468. // })
  469. // }
  470. // if (!e.detail.value.work) {
  471. // this.setData({
  472. // workIsTrue: true
  473. // })
  474. // } else {
  475. // this.setData({
  476. // workIsTrue: false
  477. // })
  478. // }
  479. // if (!e.detail.value.culture) {
  480. // this.setData({
  481. // cultureIsTrue: true
  482. // })
  483. // } else {
  484. // this.setData({
  485. // cultureIsTrue: false
  486. // })
  487. // }
  488. // if (!e.detail.value.graduation) {
  489. // this.setData({
  490. // graduationIsTrue: true
  491. // })
  492. // } else {
  493. // this.setData({
  494. // graduationIsTrue: false
  495. // })
  496. // }
  497. // if (!e.detail.value.major) {
  498. // this.setData({
  499. // majorIsTrue: true
  500. // })
  501. // } else {
  502. // this.setData({
  503. // majorIsTrue: false
  504. // })
  505. // }
  506. // if (!e.detail.value.post) {
  507. // this.setData({
  508. // postIsTrue: true
  509. // })
  510. // } else {
  511. // this.setData({
  512. // postIsTrue: false
  513. // })
  514. // }
  515. // if (!e.detail.value.phone) {
  516. // this.setData({
  517. // phoneIsTrue: true
  518. // })
  519. // } else {
  520. // this.setData({
  521. // phoneIsTrue: false
  522. // })
  523. // }
  524. // if (!this.data.zaizhiTime) {
  525. // this.setData({
  526. // renzhishijianIsTrue: true
  527. // })
  528. // } else {
  529. // this.setData({
  530. // renzhishijianIsTrue: false
  531. // })
  532. // }
  533. // if (!this.data.peixunTime) {
  534. // this.setData({
  535. // peixunshijianTrue: true
  536. // })
  537. // } else {
  538. // this.setData({
  539. // peixunshijianTrue: false
  540. // })
  541. // }
  542. // console.log(this.data.zaizhiTime, "在职时间000");
  543. // console.log(this.data.peixunTime, "培训时间000");
  544. // console.log(sex, "性别的");
  545. // e.detail.value.zaizhiTime = this.data.zaizhiTime;
  546. // e.detail.value.peixunTime = this.data.peixunTime;
  547. // e.detail.value.sex = sex;
  548. // console.log(e.detail.value, "我是合并后的锕");
  549. },
  550. timeFormat(date, fmt) {
  551. let o = {
  552. "M+": date.getMonth() + 1, //月份   
  553. "d+": date.getDate(), //日
  554. "h+": date.getHours(), //小时   
  555. "m+": date.getMinutes(), //分   
  556. "s+": date.getSeconds(), //秒   
  557. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  558. "S": date.getMilliseconds() //毫秒   
  559. };
  560. if (/(y+)/.test(fmt))
  561. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  562. for (let k in o)
  563. if (new RegExp("(" + k + ")").test(fmt))
  564. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  565. return fmt;
  566. },
  567. onReady: function () {},
  568. onLoad: function (options) {
  569. //const sessionKey = await tools.checkSessionAndLogin();
  570. const sessionKey = 'yoa0rZTt2bAiTVDsiRjysw==';
  571. console.log("onloading.....................");
  572. let chooceArr = this.data.questionList.map(item => {
  573. let json = {};
  574. json.currentAnswer = '';
  575. json.questType = '';
  576. json.id = item.Id;
  577. json.QuestStem = item.QuestStem;
  578. return json
  579. })
  580. console.log(chooceArr);
  581. this.setData({
  582. chooseValue: chooceArr
  583. })
  584. wx.setStorageSync('answersId', options.paperId);
  585. this.setData({
  586. sessionKey: sessionKey,
  587. paperId: options.paperId,
  588. answersId: options.answersId,
  589. id: options.id,
  590. })
  591. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  592. console.log("缓村了锕");
  593. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  594. this.setData({
  595. questionList: questionList,
  596. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  597. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  598. })
  599. console.log(this.data.questionList, "show 缓存的数据");
  600. } else {
  601. console.log("无缓存");
  602. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  603. }
  604. },
  605. allShi(id, paperId, sessionKey) {
  606. wx.request({
  607. url: app.globalData.publicUrl + '/wx/paper/detail',
  608. method: "post",
  609. data: {
  610. sessionKey: sessionKey,
  611. id: id,
  612. paperId: paperId
  613. },
  614. success: (res) => {
  615. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  616. let json = {};
  617. json.QuestType = item.QuestType;
  618. json.Id = item.Id;
  619. json.QuestAnswer = item.QuestAnswer;
  620. json.QuestStem = item.QuestStem;
  621. // if (item.QuestChoice) {
  622. // let arr = item.QuestChoice.split('||');
  623. // json.QuestChoice = arr;
  624. // }
  625. if (item.QuestType == '1' || item.QuestType == '0') {
  626. let arr = item.QuestChoice.split('||');
  627. let arrJson = arr.map(item => {
  628. let json1 = {};
  629. json1.name = item;
  630. json1.value = item;
  631. json1.checked = false;
  632. return json1
  633. });
  634. json.QuestChoice = arrJson;
  635. }
  636. return json;
  637. })
  638. // for(let i = 0 ; i<jsonArr.length; i++){
  639. // let json = {};
  640. // json.currentAnswer = '';
  641. // json.questType = '';
  642. // json.id = '';
  643. // }
  644. // 答案锕
  645. let chooceArr = jsonArr.map(item => {
  646. let json = {};
  647. json.currentAnswer = '';
  648. json.questType = '';
  649. json.id = item.Id;
  650. json.QuestStem = item.QuestStem;
  651. return json
  652. })
  653. this.setData({
  654. questionList: jsonArr,
  655. chooseValue: chooceArr
  656. })
  657. console.log(this.data.questionList, "00000");
  658. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  659. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  660. }
  661. })
  662. },
  663. })