tender_cert.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. $(function () {
  2. autoFlashHeight();
  3. $.subMenu({
  4. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  5. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  6. key: 'menu.1.0.0',
  7. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  8. callback: function (info) {
  9. if (info.mini) {
  10. $('.panel-title').addClass('fluid');
  11. $('#sub-menu').removeClass('panel-sidebar');
  12. } else {
  13. $('.panel-title').removeClass('fluid');
  14. $('#sub-menu').addClass('panel-sidebar');
  15. }
  16. autoFlashHeight();
  17. }
  18. });
  19. // 打开添加用户加载数据
  20. $('#import').on('show.bs.modal', function (e) {
  21. let html = '';
  22. for (const tc of tenderCertList) {
  23. let certHtml = '';
  24. for (const c of tc.account_info.certs) {
  25. certHtml += `<option value="${c.id}" ${c.id === tc.cert_id ? 'selected': ''}>${showCol4ObjArray(certSourceConst, c.name, 'value', 'name')}</option>`;
  26. }
  27. html += `<tr class="text-center" data-insert="0" data-id="${tc.id}" data-certid="${tc.cert_id}" data-remove="0">
  28. <td>${tc.account_info.name}</td>
  29. <td>${tc.account_info.role}</td>
  30. <td>
  31. <select class="form-control form-control-sm">
  32. ${certHtml}
  33. </select>
  34. </td>
  35. <td class="text-danger">移除</td>
  36. </tr>`;
  37. }
  38. $('#select-certs-table').html(html);
  39. });
  40. let timer = null
  41. let oldSearchVal = null
  42. $('#gr-search').bind('input propertychange', function (e) {
  43. oldSearchVal = e.target.value
  44. timer && clearTimeout(timer)
  45. timer = setTimeout(() => {
  46. const newVal = $('#gr-search').val()
  47. let html = ''
  48. if (newVal && newVal === oldSearchVal) {
  49. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  50. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  51. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  52. class="ml-auto">${item.mobile || ''}</span></p>
  53. <span class="text-muted">${item.role || ''}</span>
  54. </dd>`
  55. })
  56. $('.book-list').empty()
  57. $('.book-list').append(html)
  58. } else {
  59. if (!$('.acc-btn').length) {
  60. accountGroup.forEach((group, idx) => {
  61. if (!group) return
  62. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  63. </a> ${group.groupName}</dt>
  64. <div class="dd-content" data-toggleid="${idx}">`
  65. group.groupList.forEach(item => {
  66. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  67. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  68. class="ml-auto">${item.mobile || ''}</span></p>
  69. <span class="text-muted">${item.role || ''}</span>
  70. </dd>`
  71. });
  72. html += '</div>'
  73. })
  74. $('.book-list').empty()
  75. $('.book-list').append(html)
  76. }
  77. }
  78. }, 400);
  79. });
  80. // 添加到成员中
  81. $('.book-list').on('click', 'dt', function () {
  82. const idx = $(this).find('.acc-btn').attr('data-groupid')
  83. const type = $(this).find('.acc-btn').attr('data-type')
  84. if (type === 'hide') {
  85. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  86. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  87. $(this).find('.acc-btn').attr('data-type', 'show')
  88. })
  89. } else {
  90. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  91. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  92. $(this).find('.acc-btn').attr('data-type', 'hide')
  93. })
  94. }
  95. return false
  96. });
  97. // 添加到审批流程中
  98. $('dl').on('click', 'dd', function () {
  99. const auditorId = parseInt($(this).data('id'))
  100. if (auditorId) {
  101. const userInfo = _.find(accountList, { id: auditorId });
  102. const certList = _.filter(allCertList, { uid: parseInt(auditorId) });
  103. let certHtml = '';
  104. for (const c of certList) {
  105. certHtml += `<option value="${c.id}">${showCol4ObjArray(certSourceConst, c.name, 'value', 'name')}</option>`;
  106. }
  107. const html = `<tr class="text-center" data-insert="1" data-remove="0" data-uid="${userInfo.id}" data-certid="${certList.length > 0 ? certList[0].id : 0}">
  108. <td>${userInfo.name}</td>
  109. <td>${userInfo.role}</td>
  110. <td>
  111. <select class="form-control form-control-sm">
  112. ${certHtml}
  113. </select>
  114. </td>
  115. <td class="text-danger">移除</td>
  116. </tr>`;
  117. $('#select-certs-table').append(html);
  118. }
  119. });
  120. $('body').on('click', '#select-certs-table .text-danger', function () {
  121. $(this).parent().addClass('bg-gray').attr('data-remove', 1);
  122. $(this).siblings('td').find('select').prop('disabled', true);
  123. $(this).removeClass('text-danger').text('已移除');
  124. });
  125. $('body').on('change', '#select-certs-table select', function () {
  126. $(this).parents('tr').attr('data-certid', $(this).val());
  127. });
  128. $('#add_cert_btn').click(function () {
  129. // 判断是否有重复项cert_id的,否则不允许提交
  130. const certIdList = [];
  131. let isRepeat = false;
  132. $('#select-certs-table tr[data-remove="0"]').each(function () {
  133. const certId = parseInt($(this).attr('data-certid'));
  134. if (certIdList.indexOf(certId) === -1) {
  135. certIdList.push(certId);
  136. } else {
  137. isRepeat = true;
  138. return;
  139. }
  140. });
  141. if (isRepeat) {
  142. toastr.error('用户不能添加重复的证书');
  143. return;
  144. }
  145. // 判断增删改
  146. const insertList = [];
  147. if ($('#select-certs-table tr[data-insert="1"][data-remove="0"]').length > 0) {
  148. $('#select-certs-table tr[data-insert="1"][data-remove="0"]').each(function () {
  149. insertList.push({
  150. uid: parseInt($(this).attr('data-uid')),
  151. cert_id: parseInt($(this).attr('data-certid'))
  152. });
  153. });
  154. }
  155. const removeList = [];
  156. if ($('#select-certs-table tr[data-insert="0"][data-remove="1"]').length > 0) {
  157. $('#select-certs-table tr[data-insert="0"][data-remove="1"]').each(function () {
  158. removeList.push(parseInt($(this).attr('data-id')));
  159. });
  160. }
  161. const updateList = [];
  162. if ($('#select-certs-table tr[data-insert="0"][data-remove="0"]').length > 0) {
  163. $('#select-certs-table tr[data-insert="0"][data-remove="0"]').each(function () {
  164. const cert_id = parseInt($(this).attr('data-certid'))
  165. const id = parseInt($(this).attr('data-id'));
  166. const tcInfo = _.find(tenderCertList, { id });
  167. if (tcInfo.cert_id !== cert_id) {
  168. updateList.push({
  169. id,
  170. cert_id
  171. });
  172. }
  173. });
  174. }
  175. console.log(insertList, removeList, updateList);
  176. postData('/tender/' + tid + '/cert/save', { type: 'save_user', list: { insertList, removeList, updateList} }, function (result) {
  177. tenderCertList = result;
  178. SpreadJsObj.loadSheetData(certSpread.getActiveSheet(), SpreadJsObj.DataType.Data, tenderCertList);
  179. $('#import').modal('hide');
  180. });
  181. });
  182. // sjs展示
  183. const certSpread = SpreadJsObj.createNewSpread($('#cert-spread')[0]);
  184. const certSpreadSetting = {
  185. emptyRows: 0,
  186. headRows: 2,
  187. headRowHeight: [25, 32],
  188. defaultRowHeight: 21,
  189. headerFont: '12px 微软雅黑',
  190. font: '12px 微软雅黑',
  191. };
  192. const certSpreadSettingCols = [
  193. {title: '姓名', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true, getValue: 'getValue.name'},
  194. {title: '技术职称', colSpan: '1', rowSpan: '2', field: 'job_title', hAlign: 0, width: 100, formatter: '@', readOnly: true, getValue: 'getValue.job_title'},
  195. {title: '所在部门', colSpan: '1', rowSpan: '2', field: 'department', hAlign: 0, width: 100, formatter: '@'},
  196. {title: '职务', colSpan: '1', rowSpan: '2', field: 'role', hAlign: 0, width: 80, formatter: '@', readOnly: true, getValue: 'getValue.role'},
  197. {title: '在岗时间', colSpan: '1', rowSpan: '2', field: 'job_time', hAlign: 0, width: 150, formatter: '@'},
  198. {title: '持证情况|证件名称', colSpan: '4|1', rowSpan: '1|1', field: 'cert_name', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.cert_name'},
  199. {title: '|证书编号', colSpan: '|1', rowSpan: '|1', field: 'cert_code', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.cert_code'},
  200. {title: '|注册单位', colSpan: '|1', rowSpan: '|1', field: 'reg_unit', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.reg_unit'},
  201. {title: '|证书附件', colSpan: '|1', rowSpan: '|1', field: 'file_path', hAlign: 1, width: 55, readOnly: true, cellType: 'imageBtn',
  202. normalImg: '#file_clip', hoverImg: '#file_clip_hover' , showImage: function (data) { return data && data.cert_info && data.cert_info.file_path; }},
  203. {title: '继续教育情况|培训时间', colSpan: '3|1', rowSpan: '1|1', field: 'jx_date', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.jx_date'},
  204. {title: '|培训单位', colSpan: '|1', rowSpan: '|1', field: 'jx_unit', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.jx_unit'},
  205. {title: '|培训证明', colSpan: '|1', rowSpan: '|1', field: 'jx_path', hAlign: 1, width: 55, readOnly: true, cellType: 'imageBtn',
  206. normalImg: '#file_clip', hoverImg: '#file_clip_hover', showImage: function (data) { return data && data.cert_info && data.cert_info.eduInfo && data.cert_info.eduInfo.file_path; }},
  207. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 100},
  208. ];
  209. certSpreadSetting.cols = certSpreadSettingCols;
  210. certSpreadSetting.imageClick = function (data, info) {
  211. const col = info.sheet.zh_setting.cols[info.col];
  212. if (col.field === 'file_path' && data && data.cert_info && data.cert_info.file_path) {
  213. window.open(fujianOssPath + data.cert_info.file_path);
  214. } else if (col.field === 'jx_path' && data && data.cert_info && data.cert_info.eduInfo && data.cert_info.eduInfo.file_path) {
  215. window.open(fujianOssPath + data.cert_info.eduInfo.file_path);
  216. }
  217. };
  218. const certCol = {
  219. getValue: {
  220. name: function (data) {
  221. return data.account_info ? data.account_info.name : '';
  222. },
  223. job_title: function (data) {
  224. return data.cert_info ? data.cert_info.job_title : '';
  225. },
  226. role: function (data) {
  227. return data.account_info ? data.account_info.role : '';
  228. },
  229. cert_name: function (data) {
  230. return data.cert_info ? showCol4ObjArray(certSourceConst, data.cert_info.name, 'value', 'name') : '';
  231. },
  232. cert_code: function (data) {
  233. return data.cert_info ? data.cert_info.code : '';
  234. },
  235. reg_unit: function (data) {
  236. return data.cert_info ? data.cert_info.reg_unit : '';
  237. },
  238. file_path: function (data) {
  239. // return data.cert_info ? fujianOssPath + data.cert_info.file_path : '';
  240. },
  241. jx_date: function (data) {
  242. return data.cert_info && data.cert_info.eduInfo ? data.cert_info.eduInfo.date : '';
  243. },
  244. jx_unit: function (data) {
  245. return data.cert_info && data.cert_info.eduInfo ? data.cert_info.eduInfo.unit : '';
  246. },
  247. jx_path: function (data) {
  248. // return data.cert_info && data.cert_info.eduInfo ? fujianOssPath + data.cert_info.eduInfo.file_path : '';
  249. }
  250. },
  251. readOnly: {
  252. },
  253. };
  254. SpreadJsObj.initSpreadSettingEvents(certSpreadSetting, certCol);
  255. SpreadJsObj.initSheet(certSpread.getActiveSheet(), certSpreadSetting);
  256. SpreadJsObj.loadSheetData(certSpread.getActiveSheet(), SpreadJsObj.DataType.Data, tenderCertList);
  257. const certSpreadObj = {
  258. certSheetReset: function (redo = false) {
  259. const newCertData = _.cloneDeep(tenderCertList);
  260. if (redo) {
  261. certSpread.getActiveSheet().reset();
  262. SpreadJsObj.initSpreadSettingEvents(certSpreadSetting, certCol);
  263. SpreadJsObj.initSheet(certSpread.getActiveSheet(), certSpreadSetting);
  264. }
  265. SpreadJsObj.loadSheetData(certSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newCertData);
  266. },
  267. editEnded: function (e, info) {
  268. if (info.sheet.zh_setting) {
  269. const select = SpreadJsObj.getSelectObject(info.sheet);
  270. const col = info.sheet.zh_setting.cols[info.col];
  271. // 未改变值则不提交
  272. let validText = col.type === 'Number' && is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  273. const orgValue = select[col.field];
  274. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  275. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  276. return;
  277. }
  278. const update_data = {
  279. id: select.id,
  280. }
  281. update_data[col.field] = validText;
  282. select[col.field] = validText;
  283. // delete select.waitingLoading;
  284. console.log(select);
  285. // 更新至服务器
  286. postData('/tender/' + tid + '/cert/save', { type: 'update_cert', update_data }, function (result) {
  287. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  288. }, function () {
  289. select[col.field] = orgValue;
  290. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  291. });
  292. }
  293. },
  294. deletePress: function (sheet) {
  295. return;
  296. },
  297. clipboardPasted(e, info) {
  298. const hint = {
  299. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  300. };
  301. const range = info.cellRange;
  302. const sortData = info.sheet.zh_data || [];
  303. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  304. toastMessageUniq(hint.cellError);
  305. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  306. SpreadJsObj.reLoadSheetHeader(certSpread.getActiveSheet());
  307. SpreadJsObj.reLoadSheetData(certSpread.getActiveSheet());
  308. return;
  309. }
  310. if (sortData.length > 0 && range.col + range.colCount > 13) {
  311. toastMessageUniq(hint.cellError);
  312. SpreadJsObj.reLoadSheetHeader(certSpread.getActiveSheet());
  313. SpreadJsObj.reLoadSheetData(certSpread.getActiveSheet());
  314. return;
  315. }
  316. const data = [];
  317. // const rowData = [];
  318. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  319. let bPaste = true;
  320. const curRow = range.row + iRow;
  321. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  322. const certData = { id: sortData[curRow].id };
  323. const hintRow = range.rowCount > 1 ? curRow : '';
  324. let sameCol = 0;
  325. for (let iCol = 0; iCol < range.colCount; iCol++) {
  326. const curCol = range.col + iCol;
  327. const colSetting = info.sheet.zh_setting.cols[curCol];
  328. if (!colSetting) continue;
  329. let validText = info.sheet.getText(curRow, curCol);
  330. validText = colSetting.type === 'Number' && is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  331. const orgValue = sortData[curRow][colSetting.field];
  332. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  333. sameCol++;
  334. if (range.colCount === sameCol) {
  335. bPaste = false;
  336. }
  337. continue;
  338. }
  339. certData[colSetting.field] = validText;
  340. sortData[curRow][colSetting.field] = validText;
  341. }
  342. if (bPaste) {
  343. data.push(certData);
  344. } else {
  345. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  346. }
  347. }
  348. if (data.length === 0) {
  349. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  350. return;
  351. }
  352. console.log(data);
  353. // 更新至服务器
  354. postData('/tender/' + tid + '/cert/save', { type: 'paste_cert', update_data: data }, function (result) {
  355. tenderCertList = result;
  356. certSpreadObj.certSheetReset();
  357. }, function () {
  358. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  359. return;
  360. });
  361. },
  362. }
  363. certSpread.bind(spreadNS.Events.ClipboardPasted, certSpreadObj.clipboardPasted);
  364. SpreadJsObj.addDeleteBind(certSpread, certSpreadObj.deletePress);
  365. certSpread.bind(spreadNS.Events.EditEnded, certSpreadObj.editEnded);
  366. function showCol4ObjArray(arr, col, key, showKey) {
  367. if (!col) return '';
  368. const obj = _.find(arr, { [key]: col });
  369. return obj ? obj[showKey] : '';
  370. }
  371. });