ration.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. $(document).ready(function () {
  5. //定额表与下方子表上下拖动
  6. let rationSubResize = getRationSubResize();
  7. SlideResize.verticalSlide(rationSubResize.eleObj, rationSubResize.limit, function () {
  8. if (rationOprObj.workBook) {
  9. rationOprObj.workBook.refresh();
  10. }
  11. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  12. rationGLJOprObj.sheet.getParent().refresh();
  13. }
  14. });
  15. SlideResize.loadVerticalHeight(rationSubResize.eleObj.module, rationSubResize.eleObj, rationSubResize.limit, function () {
  16. if (rationOprObj.workBook) {
  17. rationOprObj.workBook.refresh();
  18. }
  19. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  20. rationGLJOprObj.sheet.getParent().refresh();
  21. }
  22. });
  23. });
  24. function getRationSubResize() {
  25. let rationSubResize = {};
  26. rationSubResize.eleObj = {
  27. module: moduleName,
  28. resize: $('#rationSubResize'),
  29. top: $('#rationItemsSheet'),
  30. topSpread: $('#rationItemsSheet'),
  31. bottom: $('#subContent'),
  32. bottomSpread: $('#rdSpread')
  33. };
  34. rationSubResize.limit = {
  35. min: 150,
  36. max: `$(window).height()-$('.header').height()-$('.tools-bar').height()-150-verticalResize`,
  37. totalHeight: `$(window).height()-$('.header').height()-$('.tools-bar').height()-verticalResize`,
  38. notTopSpread: 0,
  39. notBottomSpread: $('#subContent ul').height(),
  40. };
  41. return rationSubResize;
  42. }
  43. function loadRationSubSize(resizeObj) {
  44. if (!resizeObj) {
  45. resizeObj = getRationSubResize();
  46. }
  47. SlideResize.loadVerticalHeight(resizeObj.eleObj.module, resizeObj.eleObj, resizeObj.limit, function () {
  48. if (rationOprObj.workBook) {
  49. rationOprObj.workBook.refresh();
  50. }
  51. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  52. rationGLJOprObj.sheet.getParent().refresh();
  53. }
  54. });
  55. }
  56. const digital = {
  57. gljPrc: -3,//计算定额基价时单个工料机价格取三位
  58. rationBasePrc: -2,
  59. consumeAmt: -3
  60. };
  61. let rationOprObj = {
  62. workBook: null,
  63. currentRations: {},
  64. currentEditingRation: null,
  65. currentSectionId: -1,
  66. rationsCodes: [],
  67. setting: {
  68. header: [
  69. { headerName: "编码", headerWidth: 70, dataCode: "code", dataType: "String", formatter: "@" },
  70. { headerName: "名称", headerWidth: 240, dataCode: "name", dataType: "String" },
  71. { headerName: "计量单位", headerWidth: 70, dataCode: "unit", dataType: "String", hAlign: "center" },
  72. { headerName: "人工费", headerWidth: 80, dataCode: "labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right" },
  73. { headerName: "材料费", headerWidth: 80, dataCode: "materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right" },
  74. { headerName: "机械费", headerWidth: 80, dataCode: "machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right" },
  75. { headerName: "基价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right" },
  76. { headerName: "显示名称(以%s表示参数)", headerWidth: 240, dataCode: "caption", dataType: "String" },
  77. { headerName: "取费专业", headerWidth: 70, dataCode: "feeType", dataType: "String", hAlign: "center" },
  78. { headerName: "管理费费率(%)", headerWidth: 100, dataCode: "manageFeeRate", dataType: "String", hAlign: "center" },
  79. { headerName: "一类地区管理费", headerWidth: 100, dataCode: "manageFee1", dataType: "Number", hAlign: "right" },
  80. { headerName: "二类地区管理费", headerWidth: 100, dataCode: "manageFee2", dataType: "Number", hAlign: "right" },
  81. { headerName: "三类地区管理费", headerWidth: 100, dataCode: "manageFee3", dataType: "Number", hAlign: "right" },
  82. { headerName: "四类地区管理费", headerWidth: 100, dataCode: "manageFee4", dataType: "Number", hAlign: "right" },
  83. { headerName: "工作内容", headerWidth: 130, dataCode: "jobContentText", dataType: "String" },
  84. ],
  85. view: {
  86. comboBox: [
  87. { row: -1, col: 2, rowCount: -1, colCount: 1 }
  88. ],
  89. lockedCells: [
  90. { row: -1, col: 3, rowCount: -1, colCount: 1 }
  91. ],
  92. lockColumns: [
  93. 3, 4, 5, 6
  94. ]
  95. }
  96. },
  97. buildSheet: function (container) {
  98. let rationRepId = getQueryString("repository");
  99. let me = rationOprObj;
  100. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  101. sheetCommonObj.bindEscKey(me.workBook, [{ sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd }]);
  102. me.onContextmenuOpr();
  103. me.rationDelOpr();
  104. me.setCombo(me.workBook.getSheet(0), 'dynamic');
  105. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  106. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  107. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  108. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  109. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  110. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  111. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  112. },
  113. setCombo: function (sheet, combo) {
  114. let me = rationOprObj;
  115. sheet.suspendPaint();
  116. sheet.suspendEvent();
  117. if (combo) {
  118. combo = sheetCommonObj.getDynamicCombo();
  119. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  120. }
  121. sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
  122. sheet.resumePaint();
  123. sheet.resumeEvent();
  124. },
  125. // TODO info.oldSelections is null
  126. onSelectionChanged: function (sender, info) {
  127. console.log(info);
  128. if (info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row) {
  129. let row = info.newSelections[0].row;
  130. let me = rationOprObj;
  131. me.rationSelInit(row);
  132. }
  133. },
  134. //focusOnSection将工作簿焦点移到章节表上
  135. rationSelInit: function (row, focusOnSection = null) {
  136. let me = rationOprObj,
  137. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  138. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  139. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  140. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  141. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  142. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  143. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  144. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  145. let cacheSection = me.getCache();
  146. RationTemplate.rationInitSel(cacheSection[row]);
  147. if (cacheSection && row < cacheSection.length) {
  148. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  149. if (focusOnSection) {
  150. sectionTreeObj.workBook.focus(true);
  151. } else {
  152. me.workBook.focus(true);
  153. }
  154. });
  155. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  156. if (focusOnSection) {
  157. sectionTreeObj.workBook.focus(true);
  158. } else {
  159. me.workBook.focus(true);
  160. }
  161. });
  162. rationAssistOprObj.getAssItems(cacheSection[row]);
  163. rationInstObj.getInstItems(cacheSection[row], function () {
  164. if (focusOnSection) {
  165. sectionTreeObj.workBook.focus(true);
  166. } else {
  167. me.workBook.focus(true);
  168. }
  169. });
  170. }
  171. else {
  172. rationGLJOprObj.currentRationItem = null;
  173. }
  174. if (!focusOnSection) {
  175. me.workBook.focus(true);
  176. }
  177. },
  178. isInt: function (num) {
  179. return !isNaN(num) && num % 1 === 0;
  180. },
  181. getCache: function () {
  182. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  183. if (!(rst)) {
  184. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  185. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  186. }
  187. return rst;
  188. },
  189. updateCache: function (addArr, updateArr, removeIds, result) {
  190. let me = this, cacheSection = me.getCache();
  191. if (addArr.length > 0) {
  192. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  193. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  194. }
  195. for (let i = removeIds.length - 1; i >= 0; i--) {
  196. for (let j = cacheSection.length - 1; j >= 0; j--) {
  197. if (cacheSection[j].rationTemplateList) {
  198. //清除模板关联
  199. _.remove(cacheSection[j].rationTemplateList, function (data) {
  200. return removeIds.includes(data.rationID);
  201. });
  202. }
  203. if (cacheSection[j]["ID"] == removeIds[i]) {
  204. cacheSection.splice(j, 1);
  205. }
  206. }
  207. }
  208. if (result && result.data.ops && result.data.ops.length > 0) {
  209. for (let i = 0; i < result.data.ops.length; i++) {
  210. for (let j = 0; j < cacheSection.length; j++) {
  211. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  212. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  213. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  214. cacheSection[j]["rationCoeList"] = result.data.ops[i]["rationCoeList"];
  215. cacheSection[j]["rationAssList"] = result.data.ops[i]["rationAssList"];
  216. cacheSection[j]["rationInstList"] = result.data.ops[i]["rationInstList"];
  217. }
  218. }
  219. }
  220. }
  221. for (let i = 0; i < updateArr.length; i++) {
  222. for (let j = 0; j < cacheSection.length; j++) {
  223. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  224. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  225. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  226. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  227. cacheSection[j]['rationGljList'] ?
  228. cacheSection[j]['rationGljList'] : [];
  229. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  230. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  231. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  232. updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
  233. cacheSection[j] = updateArr[i];
  234. }
  235. } else {
  236. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  237. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  238. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  239. cacheSection[j]['rationGljList'] ?
  240. cacheSection[j]['rationGljList'] : [];
  241. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  242. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  243. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  244. updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
  245. cacheSection[j] = updateArr[i];
  246. }
  247. }
  248. }
  249. }
  250. return cacheSection;
  251. },
  252. onContextmenuOpr: function () {//右键菜单
  253. let me = this;
  254. $.contextMenu({
  255. selector: '#rationItemsSheet',
  256. build: function ($triggerElement, e) {
  257. //控制允许右键菜单在哪个位置出现
  258. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  259. let sheet = me.workBook.getSheet(0);
  260. let cacheSection = me.getCache();
  261. let ration = cacheSection[target.row];
  262. if (target.hitTestType === 3) {//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  263. if (typeof target.row !== 'undefined') {
  264. //控制按钮是否可用
  265. sheet.setActiveCell(target.row, target.col);
  266. }
  267. return {
  268. callback: function () { },
  269. items: {
  270. "delete": {
  271. name: "删除",
  272. disabled: function () {
  273. const inValidCell = !commonUtil.isDef(target.row) || !commonUtil.isDef(target.col);
  274. const inValidData = !cacheSection || target.row >= cacheSection.length;
  275. return locked || inValidCell || inValidData;
  276. },
  277. icon: "fa-remove",
  278. callback: function (key, opt) {
  279. let removeInfo = `确定要删除定额 “${ration.code}” 及其下的所有数据吗?`;
  280. $('#delRationAlert').find('.modal-body h5').text(removeInfo);
  281. $('#delRationAlert').modal('show');
  282. $('#delRationConfirm').bind('click', function () {
  283. me.rationsCodes.splice(me.rationsCodes.indexOf(ration.code.toString()), 1);
  284. me.mixDel = 1;
  285. me.mixUpdateRequest([], [], [ration.ID]);
  286. $('#delRationConfirm').unbind('click');
  287. $('#delRationAlert').modal('hide');
  288. });
  289. }
  290. }
  291. }
  292. };
  293. }
  294. else {
  295. return false;
  296. }
  297. }
  298. });
  299. },
  300. rationDelOpr: function () {
  301. if (locked) {
  302. return;
  303. }
  304. let me = rationOprObj;
  305. me.workBook.commandManager().register('rationDelete', function () {
  306. let rationSheet = me.workBook.getActiveSheet();
  307. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  308. let removeCodes = [];
  309. let cacheSection = me.getCache();
  310. if (sels.length > 0) {
  311. for (let sel = 0; sel < sels.length; sel++) {
  312. if (sels[sel].colCount === me.setting.header.length) {
  313. if (cacheSection) {
  314. for (let i = 0; i < sels[sel].rowCount; i++) {
  315. if (sels[sel].row + i < cacheSection.length) {
  316. removeArr.push(cacheSection[sels[sel].row + i].ID);
  317. removeCodes.push(cacheSection[sels[sel].row + i].code);
  318. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code.toString()), 1);
  319. }
  320. }
  321. }
  322. }
  323. else {
  324. if (sels[sel].col === 0) {
  325. $('#alertText').text("编号不能为空,修改失败!");
  326. $('#alertModalBtn').click();
  327. $('#alertModalCls').click(function () {
  328. });
  329. $('#alertModalCof').click(function () {
  330. })
  331. }
  332. else if (sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount - 1 === 6)) {
  333. if (cacheSection) {
  334. for (let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++) {
  335. if (sels[sel].row + i < cacheSection.length) {
  336. for (let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++) {
  337. if (lockCols.indexOf(col) === -1) {
  338. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  339. }
  340. }
  341. }
  342. if (cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined') {
  343. updateArr.push(cacheSection[sels[sel].row + i]);
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. /* if(updateArr.length > 0 || removeArr.length > 0){
  352. me.mixUpdate = 1;
  353. me.mixDel = removeArr.length > 0 ? 1 : 0;
  354. me.mixUpdateRequest(updateArr, [], removeArr);
  355. }*/
  356. if (updateArr.length > 0) {
  357. me.mixUpdate = 1;
  358. me.mixUpdateRequest(updateArr, [], []);
  359. }
  360. if (removeArr.length > 0) {
  361. let removeInfo = `确定要删除定额 “${removeCodes.join(',')}” 及其下的所有数据吗?`;
  362. $('#delRationAlert').find('.modal-body h5').text(removeInfo);
  363. $('#delRationAlert').modal('show');
  364. $('#delRationConfirm').bind('click', function () {
  365. me.mixDel = 1;
  366. me.mixUpdateRequest([], [], removeArr);
  367. $('#delRationConfirm').unbind('click');
  368. $('#delRationAlert').modal('hide');
  369. });
  370. }
  371. });
  372. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  373. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  374. },
  375. isDef: function (v) {
  376. return v !== undefined && v !== null;
  377. },
  378. onLeaveCell: function (sender, args) {
  379. let me = rationOprObj;
  380. me.lastCol = me.setting.header[args.col];
  381. },
  382. onEnterCell: function (sender, args) {
  383. let me = rationOprObj;
  384. if (me.setting.header[args.col]['dataCode'] === 'unit' || me.lastCol.dataCode === 'unit') {
  385. args.sheet.repaint();
  386. }
  387. me.cellRowIdx = args.row;
  388. let isHasData = false;
  389. if (me.addRationItem) {
  390. for (let i = 0; i < me.setting.header.length; i++) {
  391. if (me.addRationItem[me.setting.header[i].dataCode]) {
  392. isHasData = true;
  393. break;
  394. }
  395. }
  396. }
  397. if (isHasData) {
  398. if (me.editingRowIdx !== me.cellRowIdx) {
  399. let focusToCol = !me.addRationItem.code ? 0 : -1;
  400. if (focusToCol !== -1) {
  401. $('#rationAlertBtn').click();
  402. $('#rationAlertCac').click(function () {
  403. me.addRationItem = null;
  404. for (let col = 0; col < me.setting.header.length; col++) {
  405. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  406. }
  407. });
  408. $('#rationAlertCls').click(function () {
  409. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  410. });
  411. $('#rationAlertCof').click(function () {
  412. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  413. });
  414. }
  415. }
  416. }
  417. },
  418. onCellEditStart: function (sender, args) {
  419. let me = rationOprObj;
  420. if (!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1) {
  421. args.cancel = true;
  422. }
  423. else {
  424. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  425. me.currentEditingRation = rObj;
  426. let cacheSection = me.getCache();
  427. if (cacheSection) {
  428. for (let j = 0; j < cacheSection.length; j++) {
  429. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  430. rObj["ID"] = cacheSection[j]["ID"];
  431. break;
  432. }
  433. }
  434. }
  435. }
  436. },
  437. onCellEditEnd: function (sender, args) {
  438. let me = rationOprObj;
  439. // 输入编号、名称、单位时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  440. let dataCode = me.setting.header[args.col].dataCode;
  441. let deESCFields = ['code', 'name', 'unit'];
  442. if (deESCFields.includes(dataCode)) {
  443. args.editingText = me.isDef(args.editingText) ? args.editingText.toString().replace(/[\r\n]/g, ' ') : '';
  444. args.sheet.setValue(args.row, args.col, args.editingText);
  445. }
  446. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  447. updateArr = [],
  448. addArr = [];
  449. me.editingRowIdx = args.row;
  450. if (me.currentEditingRation["ID"]) {
  451. if ((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0) {
  452. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  453. }
  454. else {
  455. rObj["ID"] = me.currentEditingRation["ID"];
  456. if (me.currentEditingRation[dataCode] !== rObj[dataCode]) {
  457. me.addRationItem = rObj;
  458. if (dataCode === 'code') {
  459. if (me.rationsCodes.indexOf(rObj.code.toString()) === -1) {
  460. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code.toString()), 1);
  461. me.rationsCodes.push(rObj.code.toString());
  462. updateArr.push(rObj);
  463. }
  464. else {
  465. alert("编码已存在!");
  466. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  467. }
  468. }
  469. else if (dataCode === 'feeType') {
  470. updateArr.push(rObj);
  471. /* if (me.isInt(rObj[dataCode])) {
  472. updateArr.push(rObj);
  473. }
  474. else {
  475. rObj[dataCode] = '';
  476. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  477. } */
  478. }
  479. else {
  480. updateArr.push(rObj);
  481. }
  482. }
  483. }
  484. }
  485. else if (!me.currentEditingRation["ID"]) {
  486. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  487. //addArr.push(rObj);
  488. me.addRationItem = rObj;
  489. if (rObj.code && rObj.code.toString().trim().length > 0) {
  490. if (me.rationsCodes.indexOf(rObj.code.toString()) === -1) {
  491. //jobContent
  492. if (jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL) {
  493. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  494. }
  495. if (annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL) {
  496. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  497. }
  498. me.setInitPrc(rObj);
  499. addArr.push(rObj);
  500. me.rationsCodes.push(rObj.code.toString());
  501. me.addRationItem = null;
  502. }
  503. else {
  504. alert('编码已存在!');
  505. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  506. }
  507. }
  508. else if (rObj.code && rObj.code.toString.trim().length === 0) {
  509. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  510. }
  511. }
  512. }
  513. if (updateArr.length > 0 || addArr.length > 0) {
  514. me.currentEditingRation = null;
  515. me.mixUpdate = 1;
  516. me.mixUpdateRequest(updateArr, addArr, []);
  517. }
  518. },
  519. canPasted: function (beginCol, maxCol) {
  520. let rst = false;
  521. if (maxCol < 3 || beginCol > 6) {
  522. rst = true;
  523. }
  524. return rst;
  525. },
  526. onClipboardPasting: function (sender, args) {
  527. let me = rationOprObj;
  528. let maxCol = args.cellRange.col + args.cellRange.colCount - 1;
  529. if (!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1) {
  530. args.cancel = true;
  531. }
  532. },
  533. //todo: overwrite?
  534. onClipboardPasted: function (e, info) {
  535. console.log('cp');
  536. let me = rationOprObj;
  537. let cacheSection = me.getCache();
  538. let updateArr = [], addArr = [];
  539. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  540. for (let i = 0; i < items.length; i++) {
  541. let rowIdx = info.cellRange.row + i;
  542. if (cacheSection) {
  543. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  544. items[i].unit = rowIdx < cacheSection.length && typeof cacheSection[rowIdx].unit !== 'undefined' ? cacheSection[rowIdx].unit : '';
  545. }*/
  546. if (!cacheSection[rowIdx] && info.cellRange.col === 0) {
  547. if (me.rationsCodes.indexOf(items[i].code.toString()) === -1) {
  548. //jobConten
  549. if (jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL) {
  550. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  551. }
  552. if (annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL) {
  553. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  554. }
  555. me.setInitPrc(items[i]);
  556. addArr.push(items[i]);
  557. me.rationsCodes.push(items[i].code.toString());
  558. }
  559. else {
  560. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  561. }
  562. }
  563. else if (cacheSection[rowIdx]) {
  564. for (let col = 0; col < me.setting.header.length; col++) {
  565. if (!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined') {
  566. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  567. }
  568. }
  569. if (items[i].feeType && !me.isInt(items[i].feeType)) {
  570. items[i].feeType = '';
  571. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  572. }
  573. if (info.cellRange.col === 0) {
  574. if (me.rationsCodes.indexOf(items[i].code.toString()) === -1) {
  575. items[i].ID = cacheSection[rowIdx].ID;
  576. updateArr.push(items[i]);
  577. }
  578. else {
  579. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  580. }
  581. }
  582. else {
  583. items[i].ID = cacheSection[rowIdx].ID;
  584. updateArr.push(items[i]);
  585. }
  586. }
  587. } else {
  588. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  589. items[i].unit = '';
  590. }*/
  591. //add
  592. if (info.cellRange.col === 0) {
  593. //是否含有已存在的编号
  594. if (me.rationsCodes.indexOf(items[i].code.toString()) === -1) {
  595. //jobConten
  596. if (jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL) {
  597. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  598. }
  599. if (annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL) {
  600. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  601. }
  602. me.setInitPrc(items[i]);
  603. addArr.push(items[i]);
  604. }
  605. }
  606. }
  607. };
  608. if (updateArr.length > 0 || addArr.length > 0) {
  609. console.log(updateArr);
  610. me.mixUpdate = 1;
  611. me.mixUpdateRequest(updateArr, addArr, []);
  612. }
  613. else {
  614. me.getRationItems(me.currentSectionId);
  615. }
  616. },
  617. setInitPrc: function (obj) {
  618. obj.labourPrice = 0;
  619. obj.materialPrice = 0;
  620. obj.machinePrice = 0;
  621. obj.basePrice = 0;
  622. },
  623. isValidUnit: function (rationObj, validUnits) {
  624. let rst = true;
  625. if (typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1) {//无效
  626. rst = false;
  627. }
  628. return rst;
  629. },
  630. mixUpdateRequest: function (updateArr, addArr, removeIds, callback) {
  631. let me = rationOprObj;
  632. me.saveInString(updateArr);
  633. $.ajax({
  634. type: "POST",
  635. url: "api/mixUpdateRationItems",
  636. data: { "rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds) },
  637. dataType: "json",
  638. cache: false,
  639. timeout: 20000,
  640. success: function (result) {
  641. if (result.error) {
  642. alert('error');
  643. me.getRationItems(me.currentSectionId);
  644. } else {
  645. let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  646. me.sortByCode(cacheSection);
  647. /*cacheSection.sort(function(a, b){
  648. let rst = 0;
  649. if (a.code > b.code) rst = 1
  650. else if (a.code < b.code) rst = -1;
  651. return rst;
  652. });*/
  653. //add
  654. let curRow = me.workBook.getActiveSheet().getActiveRowIndex();
  655. me.rationSelInit(curRow);
  656. //add
  657. //jobContent
  658. if (jobContentOprObj) {
  659. jobContentOprObj.currentRationItems = cacheSection;
  660. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  661. if (cacheSection.length === 0) {
  662. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  663. }
  664. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  665. if (jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL) {
  666. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  667. }
  668. }
  669. if (annotationOprObj) {
  670. annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
  671. if (cacheSection.length === 0) {
  672. annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  673. }
  674. annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
  675. if (annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL) {
  676. annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
  677. }
  678. }
  679. me.showRationItems(me.currentSectionId);
  680. me.mixUpdate = 0;
  681. me.mixDel = 0;
  682. }
  683. me.workBook.focus(true);
  684. if (callback) callback();
  685. },
  686. error: function () {
  687. }
  688. });
  689. },
  690. doAfterGetRation: null,
  691. getRationItems: function (sectionID, callback = null) {
  692. if (sectionID != -1) {
  693. let me = rationOprObj;
  694. me.mixUpdate = 0;
  695. me.currentSectionId = sectionID;
  696. /*if (me.currentRations["_SEC_ID_" + sectionID]) {
  697. //jobContent--
  698. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  699. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  700. //annotation
  701. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  702. me.showRationItems(sectionID);
  703. sectionTreeObj.removeBtn.removeClass('disabled');
  704. if(callback){
  705. callback();
  706. }
  707. } else */{
  708. $.ajax({
  709. type: "POST",
  710. url: "api/getRationItems",
  711. data: { "rationRepId": pageOprObj.rationLibId, "sectionID": sectionID },
  712. dataType: "json",
  713. cache: false,
  714. timeout: 10000,
  715. success: function (result) {
  716. if (result) {
  717. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  718. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  719. //job--
  720. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  721. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  722. //annotation
  723. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  724. me.showRationItems(sectionID);
  725. }
  726. if (!locked) {
  727. sectionTreeObj.removeBtn.removeClass('disabled');
  728. }
  729. if (callback) {
  730. callback(result.data);
  731. }
  732. },
  733. error: function (err) {
  734. sectionTreeObj.removeBtn.removeClass('disabled');
  735. alert(err);
  736. }
  737. })
  738. }
  739. }
  740. },
  741. showRationItems: function (sectionID) {
  742. let me = rationOprObj,
  743. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  744. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  745. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  746. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  747. if (me.workBook) {
  748. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  749. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID]) {
  750. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  751. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  752. if (me.mixDel === 1) {
  753. let row = me.workBook.getSheet(0).getSelections()[0].row;
  754. if (cacheSection && row < cacheSection.length) {
  755. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  756. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  757. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  758. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  759. rationGLJOprObj.getGljItems(cacheSection[row]);
  760. rationCoeOprObj.getCoeItems(cacheSection[row]);
  761. rationAssistOprObj.getAssItems(cacheSection[row]);
  762. rationInstObj.getInstItems(cacheSection[row]);
  763. }
  764. else {
  765. rationGLJOprObj.currentRationItem = null;
  766. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  767. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  768. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  769. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  770. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  771. }
  772. }
  773. } else {
  774. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  775. //清除ration数据及工料机数据
  776. rationGLJOprObj.currentRationItem = null;
  777. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  778. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  779. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  780. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  781. }
  782. //--- me.workBook.focus(true);
  783. }
  784. sectionTreeObj.workBook.focus(true);
  785. },
  786. sortByCode: function (arr) {
  787. function recurCompare(a, b, index) {
  788. if (a[index] && !b[index]) {
  789. return 1;
  790. } else if (!a[index] && b[index]) {
  791. return -1;
  792. } else if (a[index] && b[index]) {
  793. let aV = a[index],
  794. bV = b[index];
  795. if (!isNaN(aV) && !isNaN(bV)) {
  796. aV = parseFloat(a[index]);
  797. bV = parseFloat(b[index]);
  798. }
  799. if (aV > bV) {
  800. return 1;
  801. } else if (aV < bV) {
  802. return -1;
  803. } else {
  804. return recurCompare(a, b, index + 1);
  805. }
  806. }
  807. return 0;
  808. }
  809. arr.sort(function (a, b) {
  810. if (!commonUtil.isDef(a.code) || !commonUtil.isDef(b.code)) {
  811. return 0;
  812. }
  813. let aArr = a.code.split('-'),
  814. bArr = b.code.split('-');
  815. return recurCompare(aArr, bArr, 0);
  816. });
  817. },
  818. saveInString(datas) {
  819. for (let i = 0, len = datas.length; i < len; i++) {
  820. let data = datas[i];
  821. if (data.labourPrice !== undefined && data.labourPrice) {
  822. data.labourPrice = data.labourPrice.toString();
  823. }
  824. if (data.materialPrice !== undefined && data.materialPrice) {
  825. data.materialPrice = data.materialPrice.toString();
  826. }
  827. if (data.machinePrice !== undefined && data.machinePrice) {
  828. data.machinePrice = data.machinePrice.toString();
  829. }
  830. if (data.basePrice !== undefined && data.basePrice) {
  831. data.basePrice = data.basePrice.toString();
  832. }
  833. if (data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0) {
  834. for (let j = 0, jLen = data.rationGljList.length; j < jLen; j++) {
  835. let raGljObj = data.rationGljList[j];
  836. if (raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt) {
  837. raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
  838. }
  839. }
  840. }
  841. }
  842. }
  843. }