tender_cert.js 18 KB

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