feedBack.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. nameIsTrue: false, //名字是否填写
  6. cultureIsTrue: false, //文化是否填写
  7. graduationIsTrue: false, //毕业学校
  8. majorIsTrue: false, //所有专业
  9. postIsTrue: false, //现任职务
  10. renzhishijianIsTrue: false,
  11. phoneIsTrue: false, //电话
  12. peixunshijianTrue: false, // 培训时间
  13. nameMessage: '',
  14. zaizhiTime: [], //在线时间
  15. peixunTime: '', //培训时间
  16. headmasterText: [], //
  17. names: [],
  18. timeIndex: '',
  19. chooseValue: [], // 选择的答案序列
  20. radio: '1',
  21. renzhiDate: '',
  22. postshow: [],
  23. postshow1: false,
  24. errorIsTrue: false,
  25. currentDate: new Date().getTime(),
  26. currentDate1: new Date().getTime(),
  27. minDate: new Date().getTime,
  28. formatter(type, value) {
  29. if (type === 'year') {
  30. return `${value}年`;
  31. } else if (type === 'month') {
  32. return `${value}月`;
  33. }
  34. return value;
  35. },
  36. questionList: [],
  37. answersId: '', // 提交答案用到
  38. sessionKey: '',
  39. paperId: '',
  40. answersId: '',
  41. id: '',
  42. status: ''
  43. },
  44. onChange(event) {
  45. this.setData({
  46. radio: event.detail,
  47. });
  48. },
  49. radioChange(e) {
  50. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  51. for (let i = 0, len = items.length; i < len; ++i) {
  52. items[i].checked = items[i].value === e.detail.value
  53. }
  54. let json = {};
  55. json.currentAnswer = e.detail.value;
  56. json.id = e.currentTarget.dataset.idx;
  57. json.questType = e.currentTarget.dataset.questtypes;
  58. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  59. this.setData({
  60. questionList: this.data.questionList
  61. })
  62. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  63. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  64. },
  65. checkboxChange(e) {
  66. const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice
  67. const values = e.detail.value
  68. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  69. items[i].checked = false
  70. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  71. if (items[i].value === values[j]) {
  72. items[i].checked = true
  73. break
  74. }
  75. }
  76. }
  77. let json = {};
  78. let aa = e.detail.value.join("||")
  79. json.currentAnswer = aa;
  80. json.id = e.currentTarget.dataset.idx;
  81. json.questType = e.currentTarget.dataset.questtypes;
  82. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  83. this.setData({
  84. questionList: this.data.questionList
  85. })
  86. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  87. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  88. },
  89. bindTextAreaBlur(e) {
  90. let json = {};
  91. json.currentAnswer = e.detail.value;
  92. json.id = e.currentTarget.dataset.idx;
  93. json.questType = e.currentTarget.dataset.questtypes;
  94. this.data.chooseValue[e.currentTarget.dataset.index] = json;
  95. this.data.questionList[e.currentTarget.dataset.index].QuestAnswer = e.detail.value;
  96. this.setData({
  97. questionList: this.data.questionList
  98. })
  99. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  100. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  101. },
  102. share() {
  103. this.setData({
  104. show: true
  105. });
  106. },
  107. onClose() {
  108. this.setData({
  109. ['postshow[' + this.data.timeIndex + ']']: false,
  110. });
  111. },
  112. onClose1() {
  113. this.setData({
  114. postshow1: false
  115. });
  116. },
  117. onInput(event) {
  118. this.setData({
  119. currentDate: event.detail,
  120. });
  121. },
  122. onInput1(event) {
  123. this.setData({
  124. currentDate1: event.detail,
  125. });
  126. },
  127. formatDate(date) {
  128. date = new Date(date);
  129. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  130. },
  131. share1(e) {
  132. this.data.postshow[e.currentTarget.dataset.index] = true;
  133. this.data.names[e.currentTarget.dataset.index] = e.currentTarget.dataset.names;
  134. this.setData({
  135. postshow: this.data.postshow,
  136. timeIndex: e.currentTarget.dataset.index
  137. })
  138. },
  139. share() {
  140. this.setData({
  141. postshow1: true
  142. });
  143. },
  144. formatDate(date) {
  145. date = new Date(date);
  146. return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`;
  147. },
  148. onConfirm(event) {
  149. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  150. let json = {};
  151. json.currentAnswer = timeValue;
  152. json.id = event.currentTarget.dataset.idx;
  153. json.questType = event.currentTarget.dataset.questtypes;
  154. let aa = this.data.chooseValue[event.currentTarget.dataset.index] = json;
  155. this.data.questionList[event.currentTarget.dataset.index].QuestAnswer = timeValue;
  156. this.setData({
  157. questionList: this.data.questionList,
  158. ['chooseValue[' + event.currentTarget.dataset.index + ']']: aa,
  159. ['postshow[' + this.data.timeIndex + ']']: false,
  160. ['headmasterText[' + this.data.timeIndex + ']']: '',
  161. });
  162. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  163. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  164. },
  165. onConfirm1(event) {
  166. let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd");
  167. this.setData({
  168. peixunTime: timeValue,
  169. postshow1: false,
  170. peixunText: ''
  171. });
  172. },
  173. parameterTap: function (e) { //e是获取e.currentTarget.dataset.id所以是必备的,跟前端的data-id获取的方式差不多
  174. let that = this
  175. let this_checked = e.currentTarget.dataset.id
  176. let parameterList = this.data.parameter //获取Json数组
  177. for (let i = 0; i < parameterList.length; i++) {
  178. if (parameterList[i].id == this_checked) {
  179. parameterList[i].checked = true; //当前点击的位置为true即选中
  180. } else {
  181. parameterList[i].checked = false; //其他的位置为false
  182. }
  183. }
  184. that.setData({
  185. parameter: parameterList
  186. })
  187. },
  188. submitForm() {
  189. wx.request({
  190. url: app.globalData.publicUrl + '/wx/paper/commit',
  191. method: "post",
  192. data: {
  193. sessionKey: this.data.sessionKey,
  194. currentAnswerTemp: this.data.chooseValue,
  195. answersId: wx.getStorageSync('answersId')
  196. },
  197. success: (res) => {
  198. if (res.data.code == 0) {
  199. wx.showModal({
  200. showCancel: false,
  201. content: '提交成功',
  202. success() {
  203. wx.navigateBack({
  204. delta: 1
  205. })
  206. }
  207. })
  208. } else {
  209. wx.showModal({
  210. showCancel: false,
  211. content: res.data.msg
  212. })
  213. }
  214. }
  215. })
  216. },
  217. formSubmit(e) {
  218. let arr1 = this.data.zaizhiTime.filter(d => d);
  219. let arr = this.data.names.filter(d => d);
  220. var activeSubjectsArr = [];
  221. for (var i = 0; i < arr.length; i++) {
  222. var activeSubjectsObject = {};
  223. for (var j = 0; j < arr1.length; j++) {
  224. if (i == j) {
  225. activeSubjectsObject[arr[i]] = arr1[j];
  226. activeSubjectsArr.push(activeSubjectsObject);
  227. }
  228. }
  229. }
  230. let count = 0;
  231. let data = {};
  232. for (let a in e.detail.value) {
  233. count += 1;
  234. if (count = 1) {
  235. data[a] = e.detail.value[a]
  236. }
  237. }
  238. activeSubjectsArr.forEach(item => {
  239. Object.assign(data, item)
  240. })
  241. },
  242. timeFormat(date, fmt) {
  243. let o = {
  244. "M+": date.getMonth() + 1, //月份   
  245. "d+": date.getDate(), //日
  246. "h+": date.getHours(), //小时   
  247. "m+": date.getMinutes(), //分   
  248. "s+": date.getSeconds(), //秒   
  249. "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
  250. "S": date.getMilliseconds() //毫秒   
  251. };
  252. if (/(y+)/.test(fmt))
  253. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  254. for (let k in o)
  255. if (new RegExp("(" + k + ")").test(fmt))
  256. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  257. return fmt;
  258. },
  259. async onLoad(options) {
  260. const sessionKey = await tools.checkSessionAndLogin();
  261. wx.setStorageSync('answersId', options.answersId);
  262. this.setData({
  263. sessionKey: sessionKey,
  264. paperId: options.paperId,
  265. answersId: options.answersId,
  266. id: options.id,
  267. })
  268. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  269. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  270. this.setData({
  271. questionList: questionList,
  272. answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')),
  273. chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')),
  274. })
  275. } else {
  276. this.allShi(this.data.id, this.data.paperId, this.data.sessionKey);
  277. }
  278. },
  279. allShi(id, paperId, sessionKey) {
  280. wx.request({
  281. url: app.globalData.publicUrl + '/wx/paper/detail',
  282. method: "post",
  283. data: {
  284. sessionKey: sessionKey,
  285. id: id,
  286. paperId: paperId
  287. },
  288. success: (res) => {
  289. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  290. let json = {};
  291. json.QuestType = item.QuestType;
  292. json.Id = item.Id;
  293. json.QuestAnswer = item.QuestAnswer;
  294. json.QuestStem = item.QuestStem;
  295. if (item.QuestType == '1' || item.QuestType == '0') {
  296. let arr = item.QuestChoice.split('||');
  297. let arrJson = arr.map(item => {
  298. let json1 = {};
  299. json1.name = item;
  300. json1.value = item;
  301. json1.checked = false;
  302. return json1
  303. });
  304. json.QuestChoice = arrJson;
  305. }
  306. return json;
  307. })
  308. let chooceArr = jsonArr.map(item => {
  309. let json = {};
  310. json.currentAnswer = '';
  311. json.questType = '';
  312. json.id = item.Id;
  313. json.QuestStem = item.QuestStem;
  314. return json
  315. })
  316. this.setData({
  317. questionList: jsonArr,
  318. chooseValue: chooceArr
  319. })
  320. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  321. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  322. }
  323. })
  324. },
  325. })