tender_cert.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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(certRegConst, c.registration, '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. console.log(auditorId);
  102. const userInfo = _.find(accountList, { id: auditorId });
  103. const certList = _.filter(allCertList, { uid: parseInt(auditorId) });
  104. console.log(certList);
  105. let certHtml = '';
  106. for (const c of certList) {
  107. certHtml += `<option value="${c.id}">${showCol4ObjArray(certRegConst, c.registration, 'value', 'name')}</option>`;
  108. }
  109. 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}">
  110. <td>${userInfo.name}</td>
  111. <td>${userInfo.role}</td>
  112. <td>
  113. <select class="form-control form-control-sm">
  114. ${certHtml}
  115. </select>
  116. </td>
  117. <td class="text-danger">移除</td>
  118. </tr>`;
  119. $('#select-certs-table').append(html);
  120. }
  121. });
  122. $('body').on('click', '#select-certs-table .text-danger', function () {
  123. $(this).parent().addClass('bg-gray').attr('data-remove', 1);
  124. $(this).siblings('td').find('select').prop('disabled', true);
  125. $(this).removeClass('text-danger').text('已移除');
  126. });
  127. $('body').on('change', '#select-certs-table select', function () {
  128. $(this).parents('tr').attr('data-certid', $(this).val());
  129. });
  130. $('#add_cert_btn').click(function () {
  131. // 判断增删改
  132. const insertList = [];
  133. if ($('#select-certs-table tr[data-insert="1"][data-remove="0"]').length > 0) {
  134. $('#select-certs-table tr[data-insert="1"][data-remove="0"]').each(function () {
  135. insertList.push({
  136. uid: parseInt($(this).attr('data-uid')),
  137. cert_id: parseInt($(this).attr('data-certid'))
  138. });
  139. });
  140. }
  141. const removeList = [];
  142. if ($('#select-certs-table tr[data-insert="0"][data-remove="1"]').length > 0) {
  143. $('#select-certs-table tr[data-insert="0"][data-remove="1"]').each(function () {
  144. removeList.push(parseInt($(this).attr('data-id')));
  145. });
  146. }
  147. const updateList = [];
  148. if ($('#select-certs-table tr[data-insert="0"][data-remove="0"]').length > 0) {
  149. $('#select-certs-table tr[data-insert="0"][data-remove="0"]').each(function () {
  150. const cert_id = parseInt($(this).attr('data-certid'))
  151. const id = parseInt($(this).attr('data-id'));
  152. const tcInfo = _.find(tenderCertList, { id });
  153. if (tcInfo.cert_id !== cert_id) {
  154. updateList.push({
  155. id,
  156. cert_id
  157. });
  158. }
  159. });
  160. }
  161. console.log(insertList, removeList, updateList);
  162. postData('/tender/' + tid + '/cert/save', { type: 'save_user', list: { insertList, removeList, updateList} }, function (result) {
  163. tenderCertList = result;
  164. SpreadJsObj.loadSheetData(certSpread.getActiveSheet(), SpreadJsObj.DataType.Data, tenderCertList);
  165. $('#import').modal('hide');
  166. });
  167. });
  168. // sjs展示
  169. const certSpread = SpreadJsObj.createNewSpread($('#cert-spread')[0]);
  170. const certSpreadSetting = {
  171. emptyRows: 0,
  172. headRows: 2,
  173. headRowHeight: [25, 32],
  174. defaultRowHeight: 21,
  175. headerFont: '12px 微软雅黑',
  176. font: '12px 微软雅黑',
  177. };
  178. const certSpreadSettingCols = [
  179. {title: '姓名', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true, getValue: 'getValue.name'},
  180. {title: '技术职称', colSpan: '1', rowSpan: '2', field: 'job_title', hAlign: 0, width: 100, formatter: '@', readOnly: true, getValue: 'getValue.job_title'},
  181. {title: '所在部门', colSpan: '1', rowSpan: '2', field: 'department', hAlign: 0, width: 100, formatter: '@'},
  182. {title: '职务', colSpan: '1', rowSpan: '2', field: 'role', hAlign: 0, width: 80, formatter: '@', readOnly: true, getValue: 'getValue.role'},
  183. {title: '在岗时间', colSpan: '1', rowSpan: '2', field: 'job_time', hAlign: 0, width: 150, formatter: '@'},
  184. {title: '持证情况|证件名称', colSpan: '4|1', rowSpan: '1|1', field: 'cert_reg', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.cert_reg'},
  185. {title: '|证书编号', colSpan: '|1', rowSpan: '|1', field: 'cert_code', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.cert_code'},
  186. {title: '|注册单位', colSpan: '|1', rowSpan: '|1', field: 'reg_unit', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.reg_unit'},
  187. {title: '|证书附件', colSpan: '|1', rowSpan: '|1', field: 'file_path', hAlign: 1, width: 55, readOnly: true, cellType: 'imageBtn',
  188. normalImg: '#file_clip', hoverImg: '#file_clip_hover' , showImage: function (data) { return data && data.cert_info && data.cert_info.file_path; }},
  189. {title: '继续教育情况|培训时间', colSpan: '3|1', rowSpan: '1|1', field: 'jx_date', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.jx_date'},
  190. {title: '|培训单位', colSpan: '|1', rowSpan: '|1', field: 'jx_unit', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.jx_unit'},
  191. {title: '|培训证明', colSpan: '|1', rowSpan: '|1', field: 'jx_path', hAlign: 1, width: 55, readOnly: true, cellType: 'imageBtn',
  192. 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; }},
  193. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 100},
  194. ];
  195. certSpreadSetting.cols = certSpreadSettingCols;
  196. certSpreadSetting.imageClick = function (data, info) {
  197. const col = info.sheet.zh_setting.cols[info.col];
  198. if (col.field === 'file_path' && data && data.cert_info && data.cert_info.file_path) {
  199. window.open(fujianOssPath + data.cert_info.file_path);
  200. } else if (col.field === 'jx_path' && data && data.cert_info && data.cert_info.eduInfo && data.cert_info.eduInfo.file_path) {
  201. window.open(fujianOssPath + data.cert_info.eduInfo.file_path);
  202. }
  203. };
  204. const certCol = {
  205. getValue: {
  206. name: function (data) {
  207. return data.account_info ? data.account_info.name : '';
  208. },
  209. job_title: function (data) {
  210. return data.cert_info ? data.cert_info.job_title : '';
  211. },
  212. role: function (data) {
  213. return data.account_info ? data.account_info.role : '';
  214. },
  215. cert_reg: function (data) {
  216. return data.cert_info ? showCol4ObjArray(certRegConst, data.cert_info.registration, 'value', 'name') : '';
  217. },
  218. cert_code: function (data) {
  219. return data.cert_info ? data.cert_info.code : '';
  220. },
  221. reg_unit: function (data) {
  222. return data.cert_info ? data.cert_info.reg_unit : '';
  223. },
  224. file_path: function (data) {
  225. // return data.cert_info ? fujianOssPath + data.cert_info.file_path : '';
  226. },
  227. jx_date: function (data) {
  228. return data.cert_info && data.cert_info.eduInfo ? data.cert_info.eduInfo.date : '';
  229. },
  230. jx_unit: function (data) {
  231. return data.cert_info && data.cert_info.eduInfo ? data.cert_info.eduInfo.unit : '';
  232. },
  233. jx_path: function (data) {
  234. // return data.cert_info && data.cert_info.eduInfo ? fujianOssPath + data.cert_info.eduInfo.file_path : '';
  235. }
  236. },
  237. readOnly: {
  238. },
  239. };
  240. SpreadJsObj.initSpreadSettingEvents(certSpreadSetting, certCol);
  241. SpreadJsObj.initSheet(certSpread.getActiveSheet(), certSpreadSetting);
  242. SpreadJsObj.loadSheetData(certSpread.getActiveSheet(), SpreadJsObj.DataType.Data, tenderCertList);
  243. const certSpreadObj = {
  244. certSheetReset: function (redo = false) {
  245. const newCertData = _.cloneDeep(tenderCertList);
  246. if (redo) {
  247. certSpread.getActiveSheet().reset();
  248. SpreadJsObj.initSpreadSettingEvents(certSpreadSetting, certCol);
  249. SpreadJsObj.initSheet(certSpread.getActiveSheet(), certSpreadSetting);
  250. }
  251. SpreadJsObj.loadSheetData(certSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newCertData);
  252. },
  253. editEnded: function (e, info) {
  254. if (info.sheet.zh_setting) {
  255. const select = SpreadJsObj.getSelectObject(info.sheet);
  256. const col = info.sheet.zh_setting.cols[info.col];
  257. // 未改变值则不提交
  258. let validText = col.type === 'Number' && is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  259. const orgValue = select[col.field];
  260. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  261. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  262. return;
  263. }
  264. const update_data = {
  265. id: select.id,
  266. }
  267. update_data[col.field] = validText;
  268. select[col.field] = validText;
  269. // delete select.waitingLoading;
  270. console.log(select);
  271. // 更新至服务器
  272. postData('/tender/' + tid + '/cert/save', { type: 'update_cert', update_data }, function (result) {
  273. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  274. }, function () {
  275. select[col.field] = orgValue;
  276. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  277. });
  278. }
  279. },
  280. deletePress: function (sheet) {
  281. return;
  282. },
  283. clipboardPasted(e, info) {
  284. const hint = {
  285. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  286. };
  287. const range = info.cellRange;
  288. const sortData = info.sheet.zh_data || [];
  289. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  290. toastMessageUniq(hint.cellError);
  291. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  292. SpreadJsObj.reLoadSheetHeader(certSpread.getActiveSheet());
  293. SpreadJsObj.reLoadSheetData(certSpread.getActiveSheet());
  294. return;
  295. }
  296. if (sortData.length > 0 && range.col + range.colCount > 13) {
  297. toastMessageUniq(hint.cellError);
  298. SpreadJsObj.reLoadSheetHeader(certSpread.getActiveSheet());
  299. SpreadJsObj.reLoadSheetData(certSpread.getActiveSheet());
  300. return;
  301. }
  302. const data = [];
  303. // const rowData = [];
  304. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  305. let bPaste = true;
  306. const curRow = range.row + iRow;
  307. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  308. const certData = { id: sortData[curRow].id };
  309. const hintRow = range.rowCount > 1 ? curRow : '';
  310. let sameCol = 0;
  311. for (let iCol = 0; iCol < range.colCount; iCol++) {
  312. const curCol = range.col + iCol;
  313. const colSetting = info.sheet.zh_setting.cols[curCol];
  314. if (!colSetting) continue;
  315. let validText = info.sheet.getText(curRow, curCol);
  316. validText = colSetting.type === 'Number' && is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  317. const orgValue = sortData[curRow][colSetting.field];
  318. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  319. sameCol++;
  320. if (range.colCount === sameCol) {
  321. bPaste = false;
  322. }
  323. continue;
  324. }
  325. certData[colSetting.field] = validText;
  326. sortData[curRow][colSetting.field] = validText;
  327. }
  328. if (bPaste) {
  329. data.push(certData);
  330. } else {
  331. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  332. }
  333. }
  334. if (data.length === 0) {
  335. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  336. return;
  337. }
  338. console.log(data);
  339. // 更新至服务器
  340. postData('/tender/' + tid + '/cert/save', { type: 'paste_cert', update_data: data }, function (result) {
  341. tenderCertList = result;
  342. certSpreadObj.certSheetReset();
  343. }, function () {
  344. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  345. return;
  346. });
  347. },
  348. }
  349. certSpread.bind(spreadNS.Events.ClipboardPasted, certSpreadObj.clipboardPasted);
  350. SpreadJsObj.addDeleteBind(certSpread, certSpreadObj.deletePress);
  351. certSpread.bind(spreadNS.Events.EditEnded, certSpreadObj.editEnded);
  352. function showCol4ObjArray(arr, col, key, showKey) {
  353. const obj = _.find(arr, { [key]: col });
  354. return obj ? obj[showKey] : '';
  355. }
  356. });