se_bonus.js 21 KB

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