feedBack.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. // {
  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.request({
  353. url: app.globalData.publicUrl + '/wx/paper/commit',
  354. method: "post",
  355. data: {
  356. sessionKey: this.data.sessionKey,
  357. currentAnswerTemp: this.data.chooseValue,
  358. answersId: wx.getStorageSync('answersId')
  359. },
  360. success: (res) => {
  361. if (res.data.code == 0) {
  362. wx.showModal({
  363. showCancel: false,
  364. content: '提交成功',
  365. success() {
  366. wx.navigateBack({
  367. delta: 1
  368. })
  369. }
  370. })
  371. } else {
  372. wx.showModal({
  373. showCancel: false,
  374. content: res.data.msg
  375. })
  376. }
  377. }
  378. })
  379. },
  380. formSubmit(e) {
  381. let arr1 = this.data.zaizhiTime.filter(d => d);
  382. let arr = this.data.names.filter(d => d);
  383. var activeSubjectsArr = [];
  384. for (var i = 0; i < arr.length; i++) {
  385. var activeSubjectsObject = {};
  386. for (var j = 0; j < arr1.length; j++) {
  387. if (i == j) {
  388. activeSubjectsObject[arr[i]] = arr1[j];
  389. activeSubjectsArr.push(activeSubjectsObject);
  390. }
  391. }
  392. }
  393. let count = 0;
  394. let data = {};
  395. for (let a in e.detail.value) {
  396. count += 1;
  397. if (count = 1) {
  398. data[a] = e.detail.value[a]
  399. }
  400. }
  401. activeSubjectsArr.forEach(item => {
  402. Object.assign(data, item)
  403. })
  404. },
  405. timeFormat(date, fmt) {
  406. let o = {
  407. "M+": date.getMonth() + 1, //月份   
  408. "d+": date.getDate(), //日
  409. "h+": date.getHours(), //小时   
  410. "m+": date.getMinutes(), //分   
  411. "s+": date.getSeconds(), //秒   
  412. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  413. "S": date.getMilliseconds() //毫秒   
  414. };
  415. if (/(y+)/.test(fmt))
  416. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  417. for (let k in o)
  418. if (new RegExp("(" + k + ")").test(fmt))
  419. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  420. return fmt;
  421. },
  422. onReady: function () {},
  423. async onLoad(options) {
  424. const sessionKey = await tools.checkSessionAndLogin();
  425. wx.setStorageSync('answersId', options.answersId);
  426. this.setData({
  427. sessionKey: sessionKey,
  428. paperId: options.paperId,
  429. answersId: options.answersId,
  430. id: options.id,
  431. })
  432. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  433. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  434. this.setData({
  435. questionList: questionList,
  436. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  437. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  438. })
  439. } else {
  440. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  441. }
  442. },
  443. allShi(id, paperId, sessionKey) {
  444. wx.request({
  445. url: app.globalData.publicUrl + '/wx/paper/detail',
  446. method: "post",
  447. data: {
  448. sessionKey: sessionKey,
  449. id: id,
  450. paperId: paperId
  451. },
  452. success: (res) => {
  453. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  454. let json = {};
  455. json.QuestType = item.QuestType;
  456. json.Id = item.Id;
  457. json.QuestAnswer = item.QuestAnswer;
  458. json.QuestStem = item.QuestStem;
  459. if (item.QuestType == '1' || item.QuestType == '0') {
  460. let arr = item.QuestChoice.split('||');
  461. let arrJson = arr.map(item => {
  462. let json1 = {};
  463. json1.name = item;
  464. json1.value = item;
  465. json1.checked = false;
  466. return json1
  467. });
  468. json.QuestChoice = arrJson;
  469. }
  470. return json;
  471. })
  472. let chooceArr = jsonArr.map(item => {
  473. let json = {};
  474. json.currentAnswer = '';
  475. json.questType = '';
  476. json.id = item.Id;
  477. json.QuestStem = item.QuestStem;
  478. return json
  479. })
  480. this.setData({
  481. questionList: jsonArr,
  482. chooseValue: chooceArr
  483. })
  484. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  485. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  486. }
  487. })
  488. },
  489. })