ration.js 36 KB

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