se_bonus.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. 'use strict';
  2. /**
  3. * 奖罚金
  4. *
  5. * @author Mai
  6. * @date 2020/2/12
  7. * @version
  8. */
  9. const isPre = function (data) {
  10. return data && data.sid !== stageId;
  11. };
  12. $(document).ready(() => {
  13. autoFlashHeight();
  14. const fileObj = {
  15. generateFilesHtml(data) {
  16. const id = data.id, files = data.proof_file;
  17. let html = [];
  18. if (files !== null && files !== undefined) {
  19. for (const [i, f] of files.entries()) {
  20. html.push('<tr>');
  21. html.push('<td style="width: 200px">', f.filename + f.fileext, '</td>');
  22. html.push('<td>', f.username, '</td>');
  23. html.push('<td>', f.in_time, '</td>');
  24. html.push('<td>');
  25. // 下载
  26. html.push('<a href="' + window.location.pathname + '/file/download?id=' + id + '&index=' + i + ' title="下载><i class="fa fa-download "></i></a>');
  27. // 删除
  28. if (!readOnly && uploadPermission && !isPre(data)) {
  29. html.push('<a class="delete-att text-danger" href="javascript:void(0);" data-id ="' + id + '"file-index="' + i + '" title="删除"><i class="fa fa-remove "></i></a>');
  30. }
  31. html.push('</td>');
  32. html.push('</tr>');
  33. }
  34. }
  35. $('#file-list').html(html.join(''));
  36. },
  37. };
  38. let datepicker;
  39. const spreadSetting = {
  40. cols: [
  41. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 235, formatter: '@', readOnly: isPre, },
  42. {title: '类型', colSpan: '1', rowSpan: '1', field: 'b_type', hAlign: 0, width: 40, formatter: '@', readOnly: isPre, },
  43. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 100, type: 'Number', readOnly: isPre, },
  44. {
  45. title: '时间', colSpan: '1', rowSpan: '1', field: 'real_time', hAlign: 2, width: 150, readOnly: true,
  46. formatter: 'yyyy-MM-dd', cellType: 'activeImageBtn', normalImg: '#ellipsis-icon', indent: 5,
  47. showImage: function (data) {
  48. return data !== undefined && data !== null;
  49. },
  50. },
  51. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: isPre, },
  52. {title: '发文单位', colSpan: '1', rowSpan: '1', field: 'doc_co', hAlign: 0, width: 150, formatter: '@', readOnly: isPre},
  53. {
  54. title: '依据材料证明', colSpan: '1', rowSpan: '1', field: 'proof_file', hAlign: 1, width: 80, formatter: '@',
  55. readOnly: true, cellType: 'imageBtn', normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover',
  56. getValue: function (data) {
  57. return data.proof_file ? data.proof_file.length : 0;
  58. },
  59. showImage: function (data) {
  60. return data !== undefined && data !== null;
  61. },
  62. },
  63. // {title: '依据材料证明', colSpan: '1', rowSpan: '1', field: 'proof', hAlign: 0, width: 150, formatter: '@', readOnly: isPre},
  64. {
  65. title: '计量期', colSpan: '1', rowSpan: '1', field: 'sorder', hAlign: 1, width: 100, formatter: '@',
  66. getValue: function (data) {
  67. return '第' + data.sorder + '期';
  68. }, readOnly: true,
  69. },
  70. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 180, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: isPre, }
  71. ],
  72. emptyRows: readOnly ? 0 : 3,
  73. headRows: 1,
  74. headRowHeight: [32],
  75. defaultRowHeight: 21,
  76. headerFont: '12px 微软雅黑',
  77. font: '12px 微软雅黑',
  78. readOnly: readOnly,
  79. imageClick: function (data, hitinfo) {
  80. if (!data || readOnly) return;
  81. const setting = hitinfo.sheet.zh_setting;
  82. if (!setting) return;
  83. const col = setting.cols[hitinfo.col];
  84. if (!col) return;
  85. if (col.field === 'proof_file') {
  86. fileObj.generateFilesHtml(data);
  87. $('#file').modal('show');
  88. }
  89. if (col.field === 'real_time') {
  90. const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
  91. if (!datepicker) {
  92. datepicker = $('.datepicker-here').datepicker({
  93. language: 'zh',
  94. dateFormat: 'yyyy-MM-dd',
  95. autoClose: true,
  96. onSelect: function (formattedDate, date, inst) {
  97. if (!inst.visible) return;
  98. const sels = hitinfo.sheet.getSelections();
  99. if (!sels || !sels[0]) return;
  100. const node = SpreadJsObj.getSelectObject(hitinfo.sheet);
  101. const uData = { update: {id: node.id, real_time: date} };
  102. postData(window.location.pathname + '/update', uData, function (result) {
  103. bonusObj.loadUpdateData(result);
  104. SpreadJsObj.reLoadRowData(hitinfo.sheet, sels[0].row);
  105. }, function () {
  106. SpreadJsObj.reLoadRowData(hitinfo.sheet, sels[0].row);
  107. });
  108. }
  109. }).data('datepicker');
  110. }
  111. const value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  112. if (value) {
  113. datepicker.selectDate(value);
  114. } else {
  115. datepicker.clear();
  116. }
  117. datepicker.show();
  118. $('#datepickers-container').css('top', hitinfo.cellRect.y + pos.y).css('left', hitinfo.cellRect.x + pos.x);
  119. }
  120. }
  121. };
  122. const bonusSpread = SpreadJsObj.createNewSpread($('#bonus-spread')[0]);
  123. const bonusSheet = bonusSpread.getActiveSheet();
  124. spreadSetting.readOnly = readOnly;
  125. SpreadJsObj.initSheet(bonusSheet, spreadSetting);
  126. $.subMenu({
  127. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  128. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  129. key: 'menu.1.0.0',
  130. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  131. callback: function (info) {
  132. if (info.mini) {
  133. $('.panel-title').addClass('fluid');
  134. $('#sub-menu').removeClass('panel-sidebar');
  135. } else {
  136. $('.panel-title').removeClass('fluid');
  137. $('#sub-menu').addClass('panel-sidebar');
  138. }
  139. autoFlashHeight();
  140. bonusSpread.refresh();
  141. }
  142. });
  143. class Bonus {
  144. constructor () {
  145. this.data = [];
  146. }
  147. resortData() {
  148. this.data.sort(function (a, b) {
  149. return a.sorder !== b.sorder ? a.sorder - b.sorder : a.order - b.order;
  150. });
  151. }
  152. loadDatas(datas) {
  153. this.data = datas;
  154. this.resortData();
  155. }
  156. loadUpdateData(updateData) {
  157. if (updateData.add) {
  158. for (const a of updateData.add) {
  159. this.data.push(a);
  160. }
  161. }
  162. if (updateData.update) {
  163. for (const u of updateData.update) {
  164. const d = this.data.find(function (x) {
  165. return u.id === x.id;
  166. });
  167. if (d) {
  168. _.assign(d, u);
  169. } else {
  170. this.data.push(d);
  171. }
  172. }
  173. }
  174. if (updateData.del) {
  175. _.remove(this.data, function (d) {
  176. return updateData.del.indexOf(d.id) >= 0;
  177. });
  178. }
  179. this.resortData();
  180. }
  181. getCurStageNewOrder() {
  182. const cur = this.data.filter(function (x) {
  183. return x.sid === stageId;
  184. });
  185. return cur && cur.length > 0 ? cur.length + 1 : 1;
  186. }
  187. checkCurFirst(bonusData) {
  188. const cur = this.data.filter(function (x) {
  189. return x.sid === stageId;
  190. });
  191. return cur.indexOf(bonusData) === 0;
  192. }
  193. checkCurLast(bonusData) {
  194. const cur = this.data.filter(function (x) {
  195. return x.sid === stageId;
  196. });
  197. return cur.indexOf(bonusData) === cur.length - 1;
  198. }
  199. }
  200. const bonusObj = new Bonus();
  201. postData(window.location.pathname + '/load', null, function (result) {
  202. bonusObj.loadDatas(result);
  203. SpreadJsObj.loadSheetData(bonusSheet, SpreadJsObj.DataType.Data, bonusObj.data);
  204. });
  205. if (!readOnly) {
  206. const bonusOprObj = {
  207. /**
  208. * 删除按钮响应事件
  209. * @param sheet
  210. */
  211. deletePress: function (sheet) {
  212. if (!sheet.zh_setting || readOnly) return;
  213. const sortData = sheet.zh_data;
  214. const datas = [];
  215. const sels = sheet.getSelections();
  216. if (!sels || !sels[0]) return;
  217. const hint = {
  218. name: {type: 'warning', msg: '名称不能为空,如需删除甲供材料请使用右键删除'},
  219. };
  220. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  221. let bDel = false;
  222. const node = sortData[iRow];
  223. if (node) {
  224. const data = {id: node.id};
  225. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  226. const colSetting = sheet.zh_setting.cols[iCol];
  227. if (colSetting.field === 'name') {
  228. toastMessageUniq(hint.name);
  229. return;
  230. }
  231. const style = sheet.getStyle(iRow, iCol);
  232. if (!style.locked) {
  233. const colSetting = sheet.zh_setting.cols[iCol];
  234. data[colSetting.field] = null;
  235. bDel = true;
  236. }
  237. }
  238. if (bDel) {
  239. datas.push(data);
  240. }
  241. }
  242. }
  243. if (datas.length > 0) {
  244. postData(window.location.pathname + '/update', {update: datas}, function (result) {
  245. bonusObj.loadUpdateData(result);
  246. SpreadJsObj.reLoadSheetData(bonusSheet);
  247. }, function () {
  248. SpreadJsObj.reLoadSheetData(bonusSheet);
  249. });
  250. }
  251. },
  252. delete: function () {
  253. const sheet = bonusSheet;
  254. if (!sheet.zh_setting || readOnly) return;
  255. const sortData = sheet.zh_data;
  256. const datas = [];
  257. const sels = sheet.getSelections();
  258. if (!sels || !sels[0]) return;
  259. const hint = {
  260. isOld: {type: 'warning', msg: '本项为往期数据,不可删除'},
  261. invalidDel: {type: 'warning', msg: '本项不是您新增的,只有原报和新增人可删除'},
  262. };
  263. for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
  264. const node = sortData[iRow];
  265. if (node.sid !== stageId) {
  266. toastMessageUniq(hint.isOld);
  267. continue;
  268. } else {
  269. if (node.uid !== userID && stageUserId !== userID) {
  270. toastMessageUniq(hint.invalidDel);
  271. continue;
  272. }
  273. datas.push(node.id);
  274. }
  275. }
  276. if (datas.length > 0) {
  277. postData(window.location.pathname + '/update', {del: datas}, function (result) {
  278. bonusObj.loadUpdateData(result);
  279. SpreadJsObj.reLoadSheetData(sheet);
  280. }, function () {
  281. SpreadJsObj.reLoadSheetData(sheet);
  282. });
  283. }
  284. },
  285. editEnded: function (e, info) {
  286. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  287. const node = info.sheet.zh_data[info.row];
  288. const col = info.sheet.zh_setting.cols[info.col];
  289. const data = {};
  290. if (node) {
  291. data.update = {};
  292. data.update.id = node.id;
  293. const oldValue = node ? node[col.field] : null;
  294. const newValue = trimInvalidChar(info.editingText);
  295. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  296. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  297. return;
  298. }
  299. data.update[col.field] = newValue;
  300. } else {
  301. if (col.field !== 'name') {
  302. toastr.warning('新增奖罚金,请先输入名称');
  303. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  304. return;
  305. }
  306. data.add = {};
  307. data.add.order = bonusObj.getCurStageNewOrder();
  308. data.add.name = trimInvalidChar(info.editingText);
  309. }
  310. postData(window.location.pathname + '/update', data, function (result) {
  311. bonusObj.loadUpdateData(result);
  312. SpreadJsObj.reLoadSheetData(info.sheet);
  313. }, function () {
  314. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  315. });
  316. },
  317. clipboardPasting(e, info) {
  318. const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
  319. info.cancel = true;
  320. if (!setting || !sortData) return;
  321. const pasteData = info.pasteData.html
  322. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  323. : (info.pasteData.text === ''
  324. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  325. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  326. const hint = {
  327. name: {type: 'warning', msg: '奖罚金名称不可为空,已过滤'},
  328. tp: {type: 'warning', msg: '输入的 金额 非法,已过滤'},
  329. };
  330. const uDatas = [], iDatas = [], maxOrder = bonusObj.getCurStageNewOrder();
  331. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  332. const curRow = info.cellRange.row + iRow;
  333. const node = sortData[curRow];
  334. let bPaste = false;
  335. const data = {};
  336. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  337. const curCol = info.cellRange.col + iCol;
  338. const colSetting = setting.cols[curCol];
  339. const value = trimInvalidChar(pasteData[iRow][iCol]);
  340. if (colSetting.field === 'name' && (!value || value === '')) {
  341. toastMessageUniq(hint.name);
  342. break;
  343. }
  344. if (colSetting.type === 'Number') {
  345. const num = _.toNumber(value);
  346. if (num) {
  347. data[colSetting.field] = num;
  348. bPaste = true;
  349. }
  350. } else {
  351. data[colSetting.field] = value;
  352. bPaste = true;
  353. }
  354. }
  355. if (bPaste) {
  356. if (node) {
  357. data.id = node.id;
  358. uDatas.push(data);
  359. } else {
  360. data.order = maxOrder + iRow;
  361. iDatas.push(data);
  362. }
  363. }
  364. }
  365. const updateData = {};
  366. if (uDatas.length > 0) updateData.update = uDatas;
  367. if (iDatas.length > 0) updateData.add = iDatas;
  368. if (uDatas.length > 0 || iDatas.length > 0) {
  369. postData(window.location.pathname + '/update', updateData, function (result) {
  370. bonusObj.loadUpdateData(result);
  371. SpreadJsObj.reLoadSheetData(info.sheet);
  372. });
  373. } else {
  374. SpreadJsObj.reLoadSheetData(info.sheet);
  375. }
  376. },
  377. upMove: function () {
  378. const sheet = bonusSheet;
  379. const sels = sheet.getSelections(), sortData = sheet.zh_data;
  380. const node = sortData[sels[0].row];
  381. const preNode = sortData[sels[0].row - 1];
  382. const data = [
  383. {id: node.id, order: preNode.order},
  384. {id: preNode.id, order: node.order}
  385. ];
  386. postData(window.location.pathname + '/update', {update: data}, function (result) {
  387. bonusObj.loadUpdateData(result);
  388. SpreadJsObj.reLoadRowsData(sheet, [sels[0].row, sels[0].row - 1]);
  389. sheet.setSelection(sels[0].row - 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
  390. });
  391. },
  392. downMove: function () {
  393. const sheet = bonusSheet;
  394. const sels = sheet.getSelections(), sortData = sheet.zh_data;
  395. const node = sortData[sels[0].row];
  396. const nextNode = sortData[sels[0].row + 1];
  397. const data = [
  398. {id: node.id, order: nextNode.order},
  399. {id: nextNode.id, order: node.order}
  400. ];
  401. postData(window.location.pathname + '/update', {update: data}, function (result) {
  402. bonusObj.loadUpdateData(result);
  403. SpreadJsObj.reLoadRowsData(sheet, [sels[0].row, sels[0].row + 1]);
  404. sheet.setSelection(sels[0].row + 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
  405. });
  406. }
  407. };
  408. bonusSheet.bind(spreadNS.Events.EditEnded, bonusOprObj.editEnded);
  409. bonusSheet.bind(spreadNS.Events.ClipboardPasting, bonusOprObj.clipboardPasting);
  410. SpreadJsObj.addDeleteBind(bonusSpread, bonusOprObj.deletePress);
  411. $.contextMenu({
  412. selector: '#bonus-spread',
  413. build: function ($trigger, e) {
  414. const target = SpreadJsObj.safeRightClickSelection($trigger, e, bonusSpread);
  415. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  416. },
  417. items: {
  418. del: {
  419. name: '删除',
  420. icon: 'fa-remove',
  421. callback: function (key, opt) {
  422. bonusOprObj.delete();
  423. },
  424. disabled: function (key, opt) {
  425. const sels = bonusSheet.getSelections();
  426. if (!sels || !sels[0]) return true;
  427. const row = sels[0].row;
  428. const node = bonusObj.data[row];
  429. return node === undefined || node === null || node.sid !== stageId;
  430. },
  431. visible: function (key, opt) {
  432. return !readOnly;
  433. }
  434. },
  435. sprDel: '------------',
  436. upMove: {
  437. name: '上移',
  438. icon: 'fa-arrow-up',
  439. callback: function (key, opt) {
  440. bonusOprObj.upMove();
  441. },
  442. disabled: function (key, opt) {
  443. const sels = bonusSheet.getSelections();
  444. if (!sels || !sels[0] || sels[0].row === 0) return true;
  445. const row = sels[0].row;
  446. const node = bonusObj.data[row];
  447. return node === undefined || node === null || node.sid !== stageId || bonusObj.checkCurFirst(node);
  448. },
  449. visible: function (key, opt) {
  450. return !readOnly;
  451. }
  452. },
  453. downMove: {
  454. name: '下移',
  455. icon: 'fa-arrow-down',
  456. callback: function (key, opt) {
  457. bonusOprObj.downMove();
  458. },
  459. disabled: function (key, opt) {
  460. const sels = bonusSheet.getSelections();
  461. if (!sels || !sels[0] || sels[0].row >= bonusObj.data.length - 1) return true;
  462. const row = sels[0].row;
  463. const node = bonusObj.data[row];
  464. return node === undefined || node === null || node.sid !== stageId || bonusObj.checkCurLast(node);
  465. },
  466. visible: function (key, opt) {
  467. return !readOnly;
  468. }
  469. }
  470. },
  471. });
  472. }
  473. $('#exportExcel').click(function () {
  474. SpreadExcelObj.exportSimpleXlsxSheet(spreadSetting, bonusObj.data, $('h2')[0].innerHTML + "-奖罚金.xlsx");
  475. });
  476. });