lastdetail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. answersId: '', // 提交答案用到
  40. sessionKey: '',
  41. paperId: '',
  42. answersId: '',
  43. id: '',
  44. status: ''
  45. },
  46. onChange(event) {
  47. this.setData({
  48. radio: event.detail,
  49. });
  50. },
  51. radioChange(e) {
  52. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  53. for (let i = 0, len = items.length; i < len; ++i) {
  54. items[i].checked = items[i].value === e.detail.value
  55. }
  56. let json = {};
  57. json.currentAnswer = e.detail.value;
  58. json.id = e.currentTarget.dataset.idx;
  59. json.questType = e.currentTarget.dataset.questtypes;
  60. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  61. this.setData({
  62. questionList: this.data.questionList
  63. })
  64. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  65. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  66. },
  67. checkboxChange(e) {
  68. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  69. const values = e.detail.value
  70. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  71. items[i].checked = false
  72. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  73. if (items[i].value === values[j]) {
  74. items[i].checked = true
  75. break
  76. }
  77. }
  78. }
  79. let json = {};
  80. let aa = e.detail.value.join("||")
  81. json.currentAnswer = aa;
  82. json.id = e.currentTarget.dataset.idx;
  83. json.questType = e.currentTarget.dataset.questtypes;
  84. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  85. this.setData({
  86. questionList: this.data.questionList
  87. })
  88. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  89. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  90. },
  91. bindTextAreaBlur(e) {
  92. let json = {};
  93. json.currentAnswer = e.detail.value;
  94. json.id = e.currentTarget.dataset.idx;
  95. json.questType = e.currentTarget.dataset.questtypes;
  96. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  97. this.data.questionList[e.currentTarget.dataset.index].QuestAnswer = e.detail.value;
  98. this.setData({
  99. questionList: this.data.questionList
  100. })
  101. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  102. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  103. },
  104. share() {
  105. this.setData({
  106. show: true
  107. });
  108. },
  109. onClose() {
  110. this.setData({
  111. ['postshow[' + this.data.timeIndex + ']']: false,
  112. });
  113. },
  114. onClose1() {
  115. this.setData({
  116. postshow1: false
  117. });
  118. },
  119. onInput(event) {
  120. this.setData({
  121. currentDate: event.detail,
  122. });
  123. },
  124. onInput1(event) {
  125. this.setData({
  126. currentDate1: event.detail,
  127. });
  128. },
  129. formatDate(date) {
  130. date = new Date(date);
  131. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  132. },
  133. share1(e) {
  134. this.data.postshow[e.currentTarget.dataset.index] = true;
  135. this.data.names[e.currentTarget.dataset.index] = e.currentTarget.dataset.names;
  136. this.setData({
  137. postshow: this.data.postshow,
  138. timeIndex: e.currentTarget.dataset.index
  139. })
  140. },
  141. share() {
  142. this.setData({
  143. postshow1: true
  144. });
  145. },
  146. formatDate(date) {
  147. date = new Date(date);
  148. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  149. },
  150. onConfirm(event) {
  151. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  152. let json = {};
  153. json.currentAnswer = timeValue;
  154. json.id = event.currentTarget.dataset.idx;
  155. json.questType = event.currentTarget.dataset.questtypes;
  156. let aa = this.data.chooseValue[event.currentTarget.dataset.index] = json;
  157. this.data.questionList[event.currentTarget.dataset.index].QuestAnswer = timeValue;
  158. this.setData({
  159. questionList: this.data.questionList,
  160. ['chooseValue[' + event.currentTarget.dataset.index + ']']: aa,
  161. ['postshow[' + this.data.timeIndex + ']']: false,
  162. ['headmasterText[' + this.data.timeIndex + ']']: '',
  163. });
  164. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  165. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  166. },
  167. onConfirm1(event) {
  168. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  169. this.setData({
  170. peixunTime: timeValue,
  171. postshow1: false,
  172. peixunText: ''
  173. });
  174. },
  175. parameterTap: function (e) { //e是获取e.currentTarget.dataset.id所以是必备的,跟前端的data-id获取的方式差不多
  176. let that = this
  177. let this_checked = e.currentTarget.dataset.id
  178. let parameterList = this.data.parameter //获取Json数组
  179. for (let i = 0; i < parameterList.length; i++) {
  180. if (parameterList[i].id == this_checked) {
  181. parameterList[i].checked = true; //当前点击的位置为true即选中
  182. } else {
  183. parameterList[i].checked = false; //其他的位置为false
  184. }
  185. }
  186. that.setData({
  187. parameter: parameterList
  188. })
  189. },
  190. submitForm() {
  191. let obj = this.data.chooseValue.find(item => !item.currentAnswer)
  192. if (!obj) {
  193. wx.request({
  194. url: app.globalData.publicUrl + '/wx/paper/commit',
  195. method: "post",
  196. data: {
  197. sessionKey: this.data.sessionKey,
  198. currentAnswerTemp: this.data.chooseValue,
  199. answersId: wx.getStorageSync('answersId')
  200. },
  201. success: (res) => {
  202. if (res.data.code == 0) {
  203. wx.showModal({
  204. showCancel: false,
  205. content: '提交成功啦',
  206. success() {
  207. wx.switchTab({
  208. url: '/pages/personInfo/personInfo',
  209. })
  210. // wx.navigateTo({
  211. // url: '/pages/last/last',
  212. // })
  213. }
  214. })
  215. } else {
  216. wx.showModal({
  217. showCancel: false,
  218. content: res.data.msg,
  219. success() {
  220. wx.navigateBack({
  221. delta: 1
  222. })
  223. }
  224. })
  225. }
  226. // if (res.data.msg == "请勿重复提交") {
  227. // wx.showModal({
  228. // showCancel: false,
  229. // content: res.data.msg
  230. // })
  231. // } else {
  232. // wx.showModal({
  233. // showCancel: false,
  234. // content: "提交成功",
  235. // success() {
  236. // wx.navigateTo({
  237. // url: '/pages/last/last',
  238. // })
  239. // }
  240. // })
  241. // }
  242. }
  243. })
  244. } else {
  245. wx.showModal({
  246. showCancel: false,
  247. content: '请补全提交信息哦',
  248. success() {}
  249. })
  250. }
  251. },
  252. formSubmit(e) {
  253. let arr1 = this.data.zaizhiTime.filter(d => d);
  254. let arr = this.data.names.filter(d => d);
  255. var activeSubjectsArr = [];
  256. for (var i = 0; i < arr.length; i++) {
  257. var activeSubjectsObject = {};
  258. for (var j = 0; j < arr1.length; j++) {
  259. if (i == j) {
  260. activeSubjectsObject[arr[i]] = arr1[j];
  261. activeSubjectsArr.push(activeSubjectsObject);
  262. }
  263. }
  264. }
  265. let count = 0;
  266. let data = {};
  267. for (let a in e.detail.value) {
  268. count += 1;
  269. if (count = 1) {
  270. data[a] = e.detail.value[a]
  271. }
  272. }
  273. activeSubjectsArr.forEach(item => {
  274. Object.assign(data, item)
  275. })
  276. },
  277. timeFormat(date, fmt) {
  278. let o = {
  279. "M+": date.getMonth() + 1, //月份   
  280. "d+": date.getDate(), //日
  281. "h+": date.getHours(), //小时   
  282. "m+": date.getMinutes(), //分   
  283. "s+": date.getSeconds(), //秒   
  284. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  285. "S": date.getMilliseconds() //毫秒   
  286. };
  287. if (/(y+)/.test(fmt))
  288. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  289. for (let k in o)
  290. if (new RegExp("(" + k + ")").test(fmt))
  291. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  292. return fmt;
  293. },
  294. async onLoad(options) {
  295. wx.showLoading({
  296. title: '加载中',
  297. mask: true
  298. })
  299. const sessionKey = await tools.checkSessionAndLogin();
  300. wx.setStorageSync('answersId', options.answersId);
  301. this.setData({
  302. sessionKey: sessionKey,
  303. paperId: options.paperId,
  304. answersId: options.answersId,
  305. id: options.id,
  306. })
  307. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  308. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  309. this.setData({
  310. questionList: questionList,
  311. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  312. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  313. })
  314. wx.hideLoading();
  315. } else {
  316. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  317. }
  318. },
  319. allShi(id, paperId, sessionKey) {
  320. wx.hideLoading();
  321. wx.request({
  322. url: app.globalData.publicUrl + '/wx/paper/detail',
  323. method: "post",
  324. data: {
  325. sessionKey: sessionKey,
  326. id: id,
  327. paperId: paperId
  328. },
  329. success: (res) => {
  330. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  331. let json = {};
  332. json.QuestType = item.QuestType;
  333. json.Id = item.Id;
  334. json.QuestAnswer = item.QuestAnswer;
  335. json.QuestStem = item.QuestStem;
  336. if (item.QuestType == '1' || item.QuestType == '0') {
  337. // console.log(item.QuestChoice,"aaaaa");
  338. // console.log(item.QuestType,"ccccc");
  339. let arr = item.QuestChoice.split('||');
  340. let arrJson = arr.map(item => {
  341. let json1 = {};
  342. json1.name = item;
  343. json1.value = item;
  344. json1.checked = false;
  345. return json1
  346. });
  347. json.QuestChoice = arrJson;
  348. }
  349. return json;
  350. })
  351. let chooceArr = jsonArr.map(item => {
  352. let json = {};
  353. json.currentAnswer = '';
  354. json.questType = '';
  355. json.id = item.Id;
  356. json.QuestStem = item.QuestStem;
  357. return json
  358. })
  359. this.setData({
  360. questionList: jsonArr,
  361. chooseValue: chooceArr
  362. })
  363. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  364. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  365. },
  366. fail:()=>{
  367. wx.hideLoading();
  368. }
  369. })
  370. },
  371. })