lastdetail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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.navigateTo({
  208. url: '/pages/last/last',
  209. })
  210. }
  211. })
  212. } else {
  213. wx.showModal({
  214. showCancel: false,
  215. content: res.data.msg,
  216. success() {
  217. wx.navigateBack({
  218. delta: 1
  219. })
  220. }
  221. })
  222. }
  223. // if (res.data.msg == "请勿重复提交") {
  224. // wx.showModal({
  225. // showCancel: false,
  226. // content: res.data.msg
  227. // })
  228. // } else {
  229. // wx.showModal({
  230. // showCancel: false,
  231. // content: "提交成功",
  232. // success() {
  233. // wx.navigateTo({
  234. // url: '/pages/last/last',
  235. // })
  236. // }
  237. // })
  238. // }
  239. }
  240. })
  241. }else{
  242. wx.showModal({
  243. showCancel: false,
  244. content: '333333',
  245. success() {
  246. }
  247. })
  248. }
  249. },
  250. formSubmit(e) {
  251. let arr1 = this.data.zaizhiTime.filter(d => d);
  252. let arr = this.data.names.filter(d => d);
  253. var activeSubjectsArr = [];
  254. for (var i = 0; i < arr.length; i++) {
  255. var activeSubjectsObject = {};
  256. for (var j = 0; j < arr1.length; j++) {
  257. if (i == j) {
  258. activeSubjectsObject[arr[i]] = arr1[j];
  259. activeSubjectsArr.push(activeSubjectsObject);
  260. }
  261. }
  262. }
  263. let count = 0;
  264. let data = {};
  265. for (let a in e.detail.value) {
  266. count += 1;
  267. if (count = 1) {
  268. data[a] = e.detail.value[a]
  269. }
  270. }
  271. activeSubjectsArr.forEach(item => {
  272. Object.assign(data, item)
  273. })
  274. },
  275. timeFormat(date, fmt) {
  276. let o = {
  277. "M+": date.getMonth() + 1, //月份   
  278. "d+": date.getDate(), //日
  279. "h+": date.getHours(), //小时   
  280. "m+": date.getMinutes(), //分   
  281. "s+": date.getSeconds(), //秒   
  282. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  283. "S": date.getMilliseconds() //毫秒   
  284. };
  285. if (/(y+)/.test(fmt))
  286. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  287. for (let k in o)
  288. if (new RegExp("(" + k + ")").test(fmt))
  289. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  290. return fmt;
  291. },
  292. async onLoad(options) {
  293. const sessionKey = await tools.checkSessionAndLogin();
  294. wx.setStorageSync('answersId', options.answersId);
  295. this.setData({
  296. sessionKey: sessionKey,
  297. paperId: options.paperId,
  298. answersId: options.answersId,
  299. id: options.id,
  300. })
  301. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  302. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  303. this.setData({
  304. questionList: questionList,
  305. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  306. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  307. })
  308. } else {
  309. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  310. }
  311. },
  312. allShi(id, paperId, sessionKey) {
  313. wx.request({
  314. url: app.globalData.publicUrl + '/wx/paper/detail',
  315. method: "post",
  316. data: {
  317. sessionKey: sessionKey,
  318. id: id,
  319. paperId: paperId
  320. },
  321. success: (res) => {
  322. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  323. let json = {};
  324. json.QuestType = item.QuestType;
  325. json.Id = item.Id;
  326. json.QuestAnswer = item.QuestAnswer;
  327. json.QuestStem = item.QuestStem;
  328. if (item.QuestType == '1' || item.QuestType == '0') {
  329. let arr = item.QuestChoice.split('||');
  330. let arrJson = arr.map(item => {
  331. let json1 = {};
  332. json1.name = item;
  333. json1.value = item;
  334. json1.checked = false;
  335. return json1
  336. });
  337. json.QuestChoice = arrJson;
  338. }
  339. return json;
  340. })
  341. let chooceArr = jsonArr.map(item => {
  342. let json = {};
  343. json.currentAnswer = '';
  344. json.questType = '';
  345. json.id = item.Id;
  346. json.QuestStem = item.QuestStem;
  347. return json
  348. })
  349. this.setData({
  350. questionList: jsonArr,
  351. chooseValue: chooceArr
  352. })
  353. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  354. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  355. }
  356. })
  357. },
  358. })