coe.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. /**
  2. * Created by CSL on 2017-05-18.
  3. */
  4. function refreshALlWorkBook() {
  5. if (sectionTreeObj.workBook) {
  6. sectionTreeObj.workBook.refresh();
  7. }
  8. if (rationOprObj.workBook) {
  9. rationOprObj.workBook.refresh();
  10. }
  11. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  12. rationGLJOprObj.sheet.getParent().refresh();
  13. }
  14. if (coeOprObj.workBook) {
  15. coeOprObj.workBook.refresh();
  16. }
  17. if (gljAdjOprObj.workBook) {
  18. gljAdjOprObj.workBook.refresh();
  19. }
  20. if (typeof lossObj !== "undefined" && lossObj.workBook) {
  21. lossObj.workBook.refresh();
  22. }
  23. }
  24. $(document).ready(function () {
  25. //定额章节树与定额表
  26. let leftElesObj = {};
  27. leftElesObj.module = moduleName;
  28. leftElesObj.resize = $("#slideResizeLeft");
  29. leftElesObj.parent = $("#dataRow");
  30. leftElesObj.left = $("#leftContent");
  31. leftElesObj.right = $("#mainContent");
  32. let maxEval = `$('#rightContent').is(':visible') ? $('#dataRow').width() - $('#rightContent').width() - 300 : $('#dataRow').width() - 300`;
  33. SlideResize.horizontalSlide(
  34. leftElesObj,
  35. { min: 300, max: maxEval },
  36. function () {
  37. refreshALlWorkBook();
  38. sectionTreeObj.loadRateWidth();
  39. }
  40. );
  41. SlideResize.loadHorizonWidth(
  42. moduleName,
  43. [$("#slideResizeLeft")],
  44. [$("#leftContent"), $("#mainContent")],
  45. function () {
  46. //refreshAfterZmhs(false);
  47. let leftContentWidth = parseFloat(
  48. $("#leftContent")[0].style.width.replace("%", "")
  49. ),
  50. mainContentWidth = parseFloat(
  51. $("#mainContent")[0].style.width.replace("%", "")
  52. );
  53. let surplus = 100 - leftContentWidth - mainContentWidth;
  54. $("#leftContent").css("width", `${leftContentWidth + surplus / 2}%`);
  55. $("#mainContent").css("width", `${mainContentWidth + surplus / 2}%`);
  56. refreshALlWorkBook();
  57. }
  58. );
  59. //定额表与子目换算表
  60. let rightElesObj = {};
  61. rightElesObj.module = moduleName;
  62. rightElesObj.resize = $("#slideResizeRight");
  63. rightElesObj.parent = $("#dataRow");
  64. rightElesObj.left = $("#mainContent");
  65. rightElesObj.right = $("#rightContent");
  66. let maxEvalRight = `$('#dataRow').width() - $('#leftContent').width() - 200`;
  67. rightElesObj.getOtherFunc = (index) => {
  68. return index ? 0 : $("#zmhs").hasClass("active") ? 1 : 2;
  69. };
  70. SlideResize.horizontalSlide(
  71. rightElesObj,
  72. { min: 200, max: maxEvalRight },
  73. function () {
  74. refreshALlWorkBook();
  75. }
  76. );
  77. //设置水平拖动条的宽度
  78. //@param {Object dom}resize滚动条
  79. function setResizeWidth(resize) {
  80. const fixedWidth = 10;
  81. //跟滚动条同层的其他节点
  82. let bros = resize.parent().children();
  83. //滚动条节点 及 同层非滚动条节点的索引
  84. let index = bros.index(resize),
  85. otherIndex = index ? 0 : 1;
  86. const other = resize.parent().children(`:eq(${otherIndex})`);
  87. let resizeParentWidth = resize.parent().width();
  88. let resizeDecimalWidth = fixedWidth / resizeParentWidth,
  89. otherDecimalWidth = 1 - resizeDecimalWidth;
  90. let resizePercentWidth = resizeDecimalWidth * 100 + "%",
  91. otherPercentWidth = otherDecimalWidth * 100 + "%";
  92. resize.css("width", resizePercentWidth);
  93. other.css("width", otherPercentWidth);
  94. }
  95. function refreshAfterZmhs(visible) {
  96. const min = 20;
  97. //宽度比例localstorage key
  98. let leftContentKey = `${moduleName}${$("#leftContent").attr("id")}Width`,
  99. mainContentKey = `${moduleName}${$("#mainContent").attr("id")}Width`,
  100. zmhsContentKey = `${moduleName}${$("#rightContent").attr("id")}Width`;
  101. let zmhsWidth = getLocalCache(zmhsContentKey)
  102. ? getLocalCache(zmhsContentKey)
  103. : $("#rightContent")[0].style.width,
  104. mainContentWidth = $("#mainContent")[0].style.width,
  105. leftContentWidth;
  106. zmhsWidth = parseFloat(zmhsWidth.replace("%", ""));
  107. mainContentWidth = parseFloat(mainContentWidth.replace("%", ""));
  108. if (visible) {
  109. mainContentWidth =
  110. mainContentWidth - zmhsWidth / 2 < min
  111. ? min
  112. : mainContentWidth - zmhsWidth / 2;
  113. if (100 - mainContentWidth - zmhsWidth < min) {
  114. leftContentWidth = min;
  115. zmhsWidth = 100 - mainContentWidth - leftContentWidth;
  116. } else {
  117. leftContentWidth = 100 - mainContentWidth - zmhsWidth;
  118. }
  119. } else {
  120. mainContentWidth += zmhsWidth / 2;
  121. leftContentWidth = 100 - mainContentWidth;
  122. }
  123. $("#leftContent").css("width", `${leftContentWidth}%`);
  124. setLocalCache(leftContentKey, `${leftContentWidth}%`);
  125. $("#mainContent").css("width", `${mainContentWidth}%`);
  126. setLocalCache(mainContentKey, `${mainContentWidth}%`);
  127. $("#rightContent").css("width", `${zmhsWidth}%`);
  128. setLocalCache(zmhsContentKey, `${zmhsWidth}%`);
  129. let resizes = [$("#slideResizeLeft"), $("#slideResizeRight")];
  130. for (let resize of resizes) {
  131. setResizeWidth(resize);
  132. }
  133. sectionTreeObj.loadRateWidth();
  134. }
  135. $("#zmhs").click(function () {
  136. if (!$(this).hasClass("active")) {
  137. $("#loss").removeClass("active");
  138. $(this).addClass("active");
  139. refreshAfterZmhs(true);
  140. $("#zmhsWrap").show();
  141. $("#lossWrap").hide();
  142. $("#rightContent").show();
  143. if (!coeOprObj.workBook) {
  144. pageObj.initPage();
  145. }
  146. refreshALlWorkBook();
  147. } else {
  148. $(this).removeClass("active");
  149. refreshAfterZmhs(false);
  150. $("#rightContent").hide();
  151. $("#zmhsWrap").hide();
  152. $("#lossWrap").hide();
  153. refreshALlWorkBook();
  154. }
  155. });
  156. //子目换算和调整表上下拖动
  157. let zmhsAdjResize = getZmhsAdjResize();
  158. SlideResize.verticalSlide(
  159. zmhsAdjResize.eleObj,
  160. zmhsAdjResize.limit,
  161. function () {
  162. if (coeOprObj.workBook) {
  163. coeOprObj.workBook.refresh();
  164. }
  165. if (gljAdjOprObj.workBook) {
  166. gljAdjOprObj.workBook.refresh();
  167. }
  168. }
  169. );
  170. loadZmhsAdjSize(zmhsAdjResize);
  171. });
  172. function getZmhsAdjResize() {
  173. let zmhsAdjResize = {};
  174. zmhsAdjResize.eleObj = {
  175. module: moduleName,
  176. resize: $("#zmhsAdjResize"),
  177. top: $("#mainSpread"),
  178. topSpread: $("#mainSpread"),
  179. bottom: $("#contentSpread"),
  180. bottomSpread: $("#contentSpread"),
  181. };
  182. zmhsAdjResize.limit = {
  183. min: 150,
  184. max: `$(window).height()-$('.header').height()-150-verticalResize`,
  185. totalHeight: `$(window).height()-$('.header').height()-verticalResize`,
  186. notTopSpread: 0,
  187. notBottomSpread: 0,
  188. };
  189. return zmhsAdjResize;
  190. }
  191. function loadZmhsAdjSize(resizeObj) {
  192. if (!resizeObj) {
  193. resizeObj = getZmhsAdjResize();
  194. }
  195. SlideResize.loadVerticalHeight(
  196. resizeObj.eleObj.module,
  197. resizeObj.eleObj,
  198. resizeObj.limit,
  199. function () {
  200. if (coeOprObj.workBook) {
  201. coeOprObj.workBook.refresh();
  202. }
  203. if (gljAdjOprObj.workBook) {
  204. gljAdjOprObj.workBook.refresh();
  205. }
  206. }
  207. );
  208. }
  209. var pageObj = {
  210. initPage: function () {
  211. coeOprObj.buildSheet($("#mainSpread")[0]);
  212. gljAdjOprObj.buildSheet($("#contentSpread")[0]);
  213. coeOprObj.getCoeList();
  214. gljAdjOprObj.getGljItemsOcc();
  215. lockUtil.lockSpreads([coeOprObj.workBook, gljAdjOprObj.workBook], locked);
  216. },
  217. showData: function (sheet, setting, data) {
  218. let me = pageObj,
  219. ch = GC.Spread.Sheets.SheetArea.viewport;
  220. sheet.suspendPaint();
  221. sheet.suspendEvent();
  222. sheet.clear(
  223. 0,
  224. 0,
  225. sheet.getRowCount(),
  226. sheet.getColumnCount(),
  227. GC.Spread.Sheets.SheetArea.viewport,
  228. GC.Spread.Sheets.StorageType.data
  229. );
  230. sheet.setRowCount(data.length + 3);
  231. for (let col = 0; col < setting.header.length; col++) {
  232. var hAlign = "left",
  233. vAlign = "center";
  234. if (setting.header[col].hAlign) {
  235. hAlign = setting.header[col].hAlign;
  236. } else if (setting.header[col].dataType !== "String") {
  237. hAlign = "right";
  238. }
  239. if (setting.header[col].readOnly) {
  240. sheet.getRange(-1, col, -1, 1).locked(true);
  241. } else {
  242. sheet.getRange(-1, col, -1, 1).locked(false);
  243. }
  244. vAlign = setting.header[col].vAlign ? setting.header[col].vAlign : vAlign;
  245. sheetCommonObj.setAreaAlign(
  246. sheet.getRange(-1, col, -1, 1),
  247. hAlign,
  248. vAlign
  249. );
  250. if (setting.header[col].formatter) {
  251. sheet.setFormatter(
  252. -1,
  253. col,
  254. setting.header[col].formatter,
  255. GC.Spread.Sheets.SheetArea.viewport
  256. );
  257. }
  258. for (let row = 0; row < data.length; row++) {
  259. let val = data[row][setting.header[col].dataCode];
  260. sheet.setValue(row, col, val, ch);
  261. }
  262. }
  263. sheet.resumeEvent();
  264. sheet.resumePaint();
  265. },
  266. };
  267. let coeOprObj = {
  268. workBook: null,
  269. workSheet: null,
  270. currentCoeList: [],
  271. currentCoe: null,
  272. currentMaxNo: null,
  273. setting: {
  274. header: [
  275. {
  276. headerName: "编号",
  277. headerWidth: 50,
  278. dataCode: "serialNo",
  279. dataType: "String",
  280. hAlign: "center",
  281. vAlign: "center",
  282. readOnly: false,
  283. },
  284. {
  285. headerName: "名称",
  286. headerWidth: 200,
  287. dataCode: "name",
  288. dataType: "String",
  289. hAlign: "left",
  290. vAlign: "center",
  291. readOnly: false,
  292. },
  293. {
  294. headerName: "内容",
  295. headerWidth: 150,
  296. dataCode: "content",
  297. dataType: "String",
  298. hAlign: "left",
  299. vAlign: "center",
  300. readOnly: false,
  301. },
  302. {
  303. headerName: "原人材机编码",
  304. headerWidth: 90,
  305. dataCode: "original_code",
  306. dataType: "String",
  307. hAlign: "center",
  308. vAlign: "center",
  309. readOnly: false,
  310. },
  311. {
  312. headerName: "可选人材机编码",
  313. headerWidth: 150,
  314. dataCode: "option_codes",
  315. dataType: "String",
  316. hAlign: "center",
  317. vAlign: "center",
  318. readOnly: false,
  319. },
  320. {
  321. headerName: "实际值",
  322. headerWidth: 60,
  323. dataCode: "actualVal",
  324. dataType: "String",
  325. hAlign: "center",
  326. vAlign: "center",
  327. readOnly: false,
  328. },
  329. {
  330. headerName: "最大值",
  331. headerWidth: 60,
  332. dataCode: "maxVal",
  333. dataType: "String",
  334. hAlign: "center",
  335. vAlign: "center",
  336. readOnly: false,
  337. },
  338. {
  339. headerName: "最小值",
  340. headerWidth: 60,
  341. dataCode: "minVal",
  342. dataType: "String",
  343. hAlign: "center",
  344. vAlign: "center",
  345. readOnly: false,
  346. },
  347. ],
  348. },
  349. buildSheet: function (container) {
  350. let me = coeOprObj;
  351. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  352. sheetCommonObj.bindEscKey(me.workBook, [
  353. {
  354. sheet: me.workBook.getSheet(0),
  355. editStarting: null,
  356. editEnded: me.onEditEnded,
  357. },
  358. ]);
  359. me.workSheet = me.workBook.getSheet(0);
  360. me.workSheet.options.isProtected = true;
  361. me.onDelOpr(me.workBook, me.setting);
  362. me.initContextMenu();
  363. me.workSheet.bind(
  364. GC.Spread.Sheets.Events.SelectionChanged,
  365. me.onSelectionChanged
  366. );
  367. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  368. me.workBook.bind(
  369. GC.Spread.Sheets.Events.ClipboardPasting,
  370. me.onClipboardPasting
  371. );
  372. me.workBook.bind(
  373. GC.Spread.Sheets.Events.ClipboardPasted,
  374. me.onClipboardPasted
  375. );
  376. },
  377. onSelectionChanged: function (sender, info) {
  378. if (
  379. (info.oldSelections.length === 0 && info.newSelections.length > 0) ||
  380. info.oldSelections[0].row !== info.newSelections[0].row
  381. ) {
  382. const row = info.newSelections[0].row;
  383. coeOprObj.coeSelInit(row);
  384. }
  385. },
  386. coeSelInit: function (row) {
  387. const me = coeOprObj;
  388. const adj = gljAdjOprObj;
  389. if (row < me.currentCoeList.length) {
  390. me.currentCoe = me.currentCoeList[row];
  391. adj.currentGljAdjList = me.currentCoe.coes;
  392. adj.buildDynamicComboBox(adj.workSheet);
  393. } else {
  394. me.currentCoe = null;
  395. adj.currentGljAdjList = [];
  396. adj.buildBaseCell(adj.workSheet);
  397. }
  398. //refresh & show coes
  399. sheetCommonObj.cleanSheet(adj.workSheet, adj.setting, -1);
  400. me.workBook.focus(true);
  401. adj.show(adj.currentGljAdjList);
  402. },
  403. onEditEnded: function (sender, args) {
  404. let me = coeOprObj,
  405. addArr = [],
  406. updateArr = [],
  407. dataCode = me.setting.header[args.col].dataCode;
  408. if (args.editingText && args.editingText.toString().trim().length > 0) {
  409. let inputT = args.editingText.toString().trim();
  410. //update
  411. if (args.row < me.currentCoeList.length) {
  412. let updateObj = me.currentCoeList[args.row];
  413. if (updateObj[dataCode] != inputT) {
  414. if (dataCode === "serialNo") {
  415. if (me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)) {
  416. me.currentMaxNo =
  417. me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  418. updateObj[dataCode] = inputT;
  419. updateArr.push(updateObj);
  420. me.save([], updateArr, [], true);
  421. } else if (!me.isInt(inputT)) {
  422. alert("编号只能为整数!");
  423. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + "");
  424. } else if (me.hasTisNo(me.currentCoeList, inputT)) {
  425. alert("该编号已存在!");
  426. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + "");
  427. }
  428. } else if (
  429. ["actualVal", "maxVal", "minVal"].includes(dataCode) &&
  430. isNaN(inputT)
  431. ) {
  432. alert("只能输入数值!");
  433. args.sheet.setValue(args.row, args.col, updateObj[dataCode] || "");
  434. } else {
  435. updateObj[dataCode] = inputT;
  436. me.setOptionList(dataCode, inputT, updateObj);
  437. updateArr.push(updateObj);
  438. me.save([], updateArr, [], true);
  439. }
  440. }
  441. }
  442. //insert
  443. else {
  444. let newCoe = {};
  445. newCoe.libID = pageOprObj.rationLibId;
  446. if (dataCode === "serialNo") {
  447. if (me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)) {
  448. me.currentMaxNo =
  449. me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  450. newCoe[dataCode] = inputT;
  451. addArr.push(newCoe);
  452. me.save(addArr, [], [], true, function (result) {
  453. me.updateCurrentCoeList(result);
  454. });
  455. } else if (!me.isInt(inputT)) {
  456. args.sheet.setValue(args.row, args.col, "");
  457. alert("编号只能为整数!");
  458. } else if (me.hasTisNo(me.currentCoeList, inputT)) {
  459. args.sheet.setValue(args.row, args.col, "");
  460. alert("该编号已存在!");
  461. }
  462. } else if (
  463. ["actualVal", "maxVal", "minVal"].includes(dataCode) &&
  464. isNaN(inputT)
  465. ) {
  466. alert("只能输入数值!");
  467. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + "");
  468. } else {
  469. newCoe.serialNo = ++me.currentMaxNo;
  470. newCoe[dataCode] = inputT;
  471. me.setOptionList(dataCode, inputT, newCoe);
  472. addArr.push(newCoe);
  473. me.save(addArr, [], [], true, function (result) {
  474. me.updateCurrentCoeList(result);
  475. });
  476. }
  477. }
  478. }
  479. },
  480. setOptionList: function (dataCode, inputT, obj) {
  481. if (dataCode == "option_codes") {
  482. //所选人材的情况,要获取人材机下拉列表
  483. inputT = inputT.replace(/[\s\r\n]/g, ""); //去掉空格换行等字符
  484. let optionList = [];
  485. let options = inputT.split("|");
  486. for (let code of options) {
  487. let name = gljAdjOprObj.getGljName(code, gljAdjOprObj.gljList, true);
  488. if (name) optionList.push({ text: name, value: code });
  489. }
  490. obj.option_list = optionList;
  491. }
  492. },
  493. onClipboardPasting: function (sender, info) {
  494. let me = coeOprObj,
  495. maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  496. if (maxCol > me.setting.header.length) {
  497. info.cancel = true;
  498. }
  499. },
  500. onClipboardPasted: function (sender, info) {
  501. let me = coeOprObj,
  502. addArr = [],
  503. updateArr = [];
  504. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  505. let uniqItems = me.makeUniqItems(items);
  506. for (let i = 0, len = uniqItems.length; i < len; i++) {
  507. for (let attr in uniqItems[i]) {
  508. if (
  509. ["actualVal", "maxVal", "minVal"].includes(attr) &&
  510. isNaN(uniqItems[i][attr])
  511. ) {
  512. uniqItems[i][attr] = undefined;
  513. }
  514. }
  515. let row = i + info.cellRange.row;
  516. //update
  517. if (row < me.currentCoeList.length) {
  518. let updateObj = me.currentCoeList[row];
  519. for (let attr in uniqItems[i]) {
  520. if (attr === "serialNo") {
  521. if (
  522. me.isInt(uniqItems[i][attr]) &&
  523. !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])
  524. ) {
  525. me.currentMaxNo =
  526. me.currentMaxNo >= uniqItems[i][attr]
  527. ? me.currentMaxNo
  528. : uniqItems[i][attr];
  529. updateObj[attr] = uniqItems[i][attr];
  530. }
  531. } else {
  532. updateObj[attr] = uniqItems[i][attr];
  533. }
  534. }
  535. updateArr.push(updateObj);
  536. }
  537. //insert
  538. else {
  539. if (
  540. typeof uniqItems[i].serialNo !== "undefined" &&
  541. uniqItems[i] &&
  542. me.isInt(uniqItems[i].serialNo) &&
  543. !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)
  544. ) {
  545. me.currentMaxNo =
  546. me.currentMaxNo >= uniqItems[i].serialNo
  547. ? me.currentMaxNo
  548. : uniqItems[i].serialNo;
  549. } else {
  550. uniqItems[i].serialNo = ++me.currentMaxNo;
  551. }
  552. uniqItems[i].libID = pageOprObj.rationLibId;
  553. addArr.push(uniqItems[i]);
  554. }
  555. }
  556. if (addArr.length > 0 || updateArr.length > 0) {
  557. me.save(addArr, updateArr, [], true, function (result) {
  558. me.updateCurrentCoeList(result);
  559. });
  560. }
  561. },
  562. onDelOpr: function (workBook, setting) {
  563. let me = coeOprObj,
  564. that = gljAdjOprObj;
  565. workBook.commandManager().register("coeListDel", function () {
  566. let deleteArr = [];
  567. let sheet = workBook.getSheet(0);
  568. let sels = sheet.getSelections();
  569. let idx = sels[0].row;
  570. for (let i = 0, len = sels.length; i < len; i++) {
  571. if (idx > sels[i].row) {
  572. idx = sels[i].row;
  573. }
  574. if (sels[i].colCount === setting.header.length) {
  575. //can del
  576. for (let r = 0, rLen = sels[i].rowCount; r < rLen; r++) {
  577. let row = sels[i].row + r;
  578. if (row < me.currentCoeList.length) {
  579. deleteArr.push({
  580. libID: me.currentCoeList[row].libID,
  581. ID: me.currentCoeList[row].ID,
  582. });
  583. }
  584. }
  585. me.currentCoeList.splice(sels[i].row, sels[i].rowCount);
  586. }
  587. }
  588. if (deleteArr.length > 0) {
  589. let coeID = deleteArr[0].ID;
  590. me.referenceCheck(coeID, function (info) {
  591. if (info.length > 0) {
  592. alert("该子目换算已被引用,不能删除!");
  593. } else {
  594. me.save([], [], deleteArr, true);
  595. me.currentCoe =
  596. typeof me.currentCoeList[idx] !== "undefined"
  597. ? me.currentCoeList[idx]
  598. : null;
  599. that.currentGljAdjList = me.currentCoe ? me.currentCoe.coes : [];
  600. gljAdjOprObj.show(that.currentGljAdjList);
  601. }
  602. });
  603. }
  604. });
  605. workBook
  606. .commandManager()
  607. .setShortcutKey(
  608. null,
  609. GC.Spread.Commands.Key.del,
  610. false,
  611. false,
  612. false,
  613. false
  614. );
  615. workBook
  616. .commandManager()
  617. .setShortcutKey(
  618. "coeListDel",
  619. GC.Spread.Commands.Key.del,
  620. false,
  621. false,
  622. false,
  623. false
  624. );
  625. },
  626. initContextMenu: function () {
  627. const me = this;
  628. $.contextMenu({
  629. selector: "#mainSpread",
  630. build: function ($triggerElement, e) {
  631. //控制允许右键菜单在哪个位置出现
  632. const target = SheetDataHelper.safeRightClickSelection(
  633. $triggerElement,
  634. e,
  635. me.workBook
  636. );
  637. const sheet = me.workBook.getSheet(0);
  638. if (target.hitTestType === 3) {
  639. //在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  640. if (typeof target.row !== "undefined") {
  641. //控制按钮是否可用
  642. sheet.setActiveCell(target.row, target.col);
  643. me.coeSelInit(target.row);
  644. }
  645. return {
  646. callback: function () {},
  647. items: {
  648. getReference: {
  649. name: "查找引用",
  650. disabled: function () {
  651. return !me.currentCoeList || !me.currentCoeList[target.row];
  652. },
  653. icon: "fa-search",
  654. callback: function () {
  655. const coe = me.currentCoeList[target.row];
  656. me.getReference(coe.ID);
  657. },
  658. },
  659. },
  660. };
  661. } else {
  662. return false;
  663. }
  664. },
  665. });
  666. },
  667. referenceCheck: function (coeID, callback) {
  668. $.bootstrapLoading.start();
  669. CommonAjax.post(
  670. "/rationRepository/api/getCoeReference",
  671. { rationRepId: pageOprObj.rationLibId, coeID },
  672. function (info) {
  673. callback(info);
  674. $.bootstrapLoading.end();
  675. },
  676. function () {
  677. $.bootstrapLoading.end();
  678. }
  679. );
  680. },
  681. getReference: function (coeID) {
  682. const $info = $("#info");
  683. const $infoBody = $("#infoBody");
  684. const me = this;
  685. me.referenceCheck(coeID, function (info) {
  686. let htmlArr = [];
  687. if (!info || !info.length) {
  688. htmlArr.push("<li>无引用数据</li>");
  689. } else {
  690. htmlArr = info.map((ration) => {
  691. return `<li>
  692. <span>${ration.code}</span>
  693. <a data-dismiss="modal" href="javascript:;" onclick="sectionTreeObj.locateToSection('${ration.code}')">定位</a>
  694. </li>`;
  695. });
  696. }
  697. $infoBody.html(htmlArr.join(""));
  698. $info.modal("show");
  699. });
  700. },
  701. //粘贴的数据,编号唯一化,去除编号重复的项
  702. makeUniqItems: function (items) {
  703. let rst = [];
  704. for (let i = 0, len = items.length; i < len; i++) {
  705. if (typeof items[i].serialNo !== "undefined" && items[i].serialNo) {
  706. if (rst.length === 0) {
  707. rst.push(items[i]);
  708. } else {
  709. let isExist = false;
  710. for (let j = 0, jLen = rst.length; j < jLen; j++) {
  711. if (items[i].serialNo === rst[j].serialNo) {
  712. isExist = true;
  713. break;
  714. }
  715. }
  716. if (!isExist) {
  717. rst.push(items[i]);
  718. }
  719. }
  720. } else {
  721. rst.push(items[i]);
  722. }
  723. }
  724. return rst;
  725. },
  726. isInt: function (num) {
  727. return !isNaN(num) && num % 1 === 0;
  728. },
  729. hasTisNo: function (coeList, newSerialNo) {
  730. let rst = false;
  731. for (let i = 0, len = coeList.length; i < len; i++) {
  732. if (coeList[i].serialNo == newSerialNo) {
  733. rst = true;
  734. break;
  735. }
  736. }
  737. return rst;
  738. },
  739. updateCurrentCoeList: function (newCoeList) {
  740. let me = coeOprObj;
  741. if (newCoeList) {
  742. me.currentCoeList = me.currentCoeList.concat(newCoeList);
  743. }
  744. },
  745. sortCoeList: function (coeList) {
  746. coeList.sort(function (a, b) {
  747. let rst = 0;
  748. if (a.serialNo > b.serialNo) rst = 1;
  749. else if (a.serialNo < b.serialNo) rst = -1;
  750. return rst;
  751. });
  752. },
  753. getCoeList: function () {
  754. let me = coeOprObj;
  755. $.ajax({
  756. type: "post",
  757. url: "/rationRepository/api/getCoeList",
  758. data: { libID: pageOprObj.rationLibId },
  759. dataType: "json",
  760. timeout: 20000,
  761. success: function (result) {
  762. if (!result.error) {
  763. me.currentCoeList = result.data;
  764. me.sortCoeList(me.currentCoeList);
  765. me.currentMaxNo =
  766. me.currentCoeList.length > 0
  767. ? me.currentCoeList[me.currentCoeList.length - 1].serialNo
  768. : 0;
  769. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  770. me.workSheet.clearSelection();
  771. }
  772. },
  773. error: function (err) {
  774. alert("内部程序错误!");
  775. },
  776. });
  777. },
  778. keepNumber: function (arr) {
  779. arr.forEach((item) => {
  780. Object.keys(item).forEach((key) => {
  781. if (["actualVal", "maxVal", "minVal"].includes(key)) {
  782. item[key] = +item[key];
  783. }
  784. });
  785. });
  786. },
  787. save: function (addArr, updateArr, deleteArr, refresh, callback) {
  788. let me = coeOprObj;
  789. // me.keepNumber(updateArr);
  790. $.ajax({
  791. type: "POST",
  792. url: "api/saveCoeList",
  793. data: {
  794. data: JSON.stringify({
  795. addArr: addArr,
  796. updateArr: updateArr,
  797. deleteArr: deleteArr,
  798. }),
  799. },
  800. dataType: "json",
  801. timeout: 5000,
  802. success: function (result) {
  803. if (result.error) {
  804. alert(result.message);
  805. } else {
  806. if (callback) {
  807. if (result.message === "mixed") {
  808. for (let i = 0, len = result.data.length; i < len; i++) {
  809. if (result.data[i][0] === "addSc") {
  810. result.data = result.data[i][1];
  811. break;
  812. }
  813. }
  814. }
  815. callback(result.data);
  816. }
  817. if (refresh) {
  818. me.sortCoeList(me.currentCoeList);
  819. me.currentMaxNo =
  820. me.currentCoeList.length > 0
  821. ? me.currentCoeList[me.currentCoeList.length - 1].serialNo
  822. : 0;
  823. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  824. }
  825. }
  826. },
  827. error: function (err) {
  828. alert("内部程序错误!");
  829. },
  830. });
  831. },
  832. };
  833. // 验证数量的有效性:可以输入数值,也可以输入表达式,eg: [人材机编码]*1.5+1,1+([v]-50)/100。 [v]代表前台调用时,子目换算实际值
  834. const validateAmount = (amountStr) => {
  835. if (!amountStr) {
  836. return true;
  837. }
  838. let str = amountStr.replace(/\s/g, "");
  839. if (!str) {
  840. return true;
  841. }
  842. try {
  843. debugger;
  844. str = amountStr
  845. .replace(/\s/g, "")
  846. .replace(/\[v\]/g, "0")
  847. .replace(/\[\d+\]/g, "0");
  848. eval(str);
  849. } catch (error) {
  850. return false;
  851. }
  852. return true;
  853. };
  854. let gljAdjOprObj = {
  855. workBook: null,
  856. workSheet: null,
  857. currentGljAdjList: [],
  858. gljList: [], //只含编号和名称的总工料机列表
  859. setting: {
  860. header: [
  861. {
  862. headerName: "调整类型",
  863. headerWidth: 80,
  864. dataCode: "coeType",
  865. dataType: "String",
  866. hAlign: "center",
  867. vAlign: "center",
  868. readOnly: false,
  869. },
  870. {
  871. headerName: "人材机编码",
  872. headerWidth: 80,
  873. dataCode: "gljCode",
  874. dataType: "String",
  875. formatter: "@",
  876. hAlign: "center",
  877. vAlign: "center",
  878. readOnly: false,
  879. },
  880. // readOnly: true --> false,需要兼容粘贴列包含只读项
  881. {
  882. headerName: "名称",
  883. headerWidth: 100,
  884. dataCode: "gljName",
  885. dataType: "String",
  886. hAlign: "center",
  887. vAlign: "center",
  888. readOnly: false,
  889. },
  890. {
  891. headerName: "操作符",
  892. headerWidth: 60,
  893. dataCode: "operator",
  894. dataType: "String",
  895. hAlign: "center",
  896. vAlign: "center",
  897. readOnly: false,
  898. },
  899. {
  900. headerName: "数量",
  901. headerWidth: 80,
  902. dataCode: "amount",
  903. dataType: "String",
  904. hAlign: "center",
  905. vAlign: "center",
  906. readOnly: false,
  907. },
  908. {
  909. headerName: "替换为编码",
  910. headerWidth: 80,
  911. dataCode: "replaceCode",
  912. dataType: "String",
  913. formatter: "@",
  914. hAlign: "center",
  915. vAlign: "center",
  916. readOnly: false,
  917. },
  918. // readOnly: true --> false
  919. {
  920. headerName: "替换为名称",
  921. headerWidth: 100,
  922. dataCode: "replaceName",
  923. dataType: "String",
  924. hAlign: "center",
  925. vAlign: "center",
  926. readOnly: false,
  927. },
  928. ],
  929. comboItems: {
  930. //调整类型下拉菜单
  931. coeType: [
  932. "定额",
  933. "人工",
  934. "材料",
  935. "机械",
  936. "主材",
  937. "设备",
  938. "单个工料机",
  939. "替换人材机",
  940. "所选人材机",
  941. ],
  942. //操作符下拉菜单
  943. operator: ["+", "-", "*", "/", "=", "+*", "-*"],
  944. },
  945. },
  946. buildSheet: function (container) {
  947. let me = gljAdjOprObj;
  948. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  949. me.workSheet = me.workBook.getSheet(0);
  950. sheetCommonObj.bindEscKey(me.workBook, [
  951. {
  952. sheet: me.workBook.getSheet(0),
  953. editStarting: me.onEditStart,
  954. editEnded: me.onEditEnded,
  955. },
  956. ]);
  957. me.workSheet.options.isProtected = true;
  958. me.onDelOpr(me.workBook, me.setting);
  959. me.workSheet.clearSelection();
  960. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
  961. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  962. me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  963. me.workSheet.bind(
  964. GC.Spread.Sheets.Events.ClipboardPasted,
  965. me.onClipboardPasted
  966. );
  967. },
  968. buildBaseCell: function (sheet) {
  969. let me = gljAdjOprObj;
  970. sheet.suspendPaint();
  971. sheet.suspendEvent();
  972. let baseCell = GC.Spread.Sheets.CellTypes.Base();
  973. sheet.getCell(-1, 0).cellType(baseCell);
  974. sheet.getCell(-1, 3).cellType(baseCell);
  975. sheet.resumePaint();
  976. sheet.resumeEvent();
  977. },
  978. buildDynamicComboBox: function (sheet) {
  979. let me = gljAdjOprObj;
  980. sheet.suspendPaint();
  981. sheet.suspendEvent();
  982. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  983. dynamicCombo.items(me.setting.comboItems.coeType);
  984. let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
  985. dynamicOprCombo.items(me.setting.comboItems.operator);
  986. sheet.getCell(-1, 0).cellType(dynamicCombo);
  987. sheet.getCell(-1, 3).cellType(dynamicOprCombo);
  988. sheet.resumePaint();
  989. sheet.resumeEvent();
  990. },
  991. onEnterCell: function (sender, args) {
  992. args.sheet.repaint();
  993. },
  994. onEditStart: function (sender, args) {
  995. let me = gljAdjOprObj;
  996. let dataCode = me.setting.header[args.col].dataCode;
  997. // 超出范围-没有选中的调整主项
  998. if (!coeOprObj.currentCoe) {
  999. args.cancel = true;
  1000. return;
  1001. }
  1002. // 名称、替换为名称总是不可编辑(表头设置readOnly没有设置为true,因为需要粘贴)
  1003. let alwaysNotEditable = ["gljName", "replaceName"];
  1004. if (alwaysNotEditable.includes(dataCode)) {
  1005. args.cancel = true;
  1006. return;
  1007. }
  1008. // 新一行编辑时,除了总是可编辑的单元格:调整类型、操作符、数量,其他不可编辑
  1009. let alwaysEditable = ["coeType", "operator", "amount"];
  1010. if (
  1011. args.row > me.currentGljAdjList.length - 1 &&
  1012. !alwaysEditable.includes(dataCode)
  1013. ) {
  1014. args.cancel = true;
  1015. return;
  1016. }
  1017. let curSubCoe = me.currentGljAdjList[args.row];
  1018. if (!curSubCoe) {
  1019. return;
  1020. }
  1021. // 调整类型不为“单个工料机”和“替换人材机”时,人材机编码不可编辑
  1022. if (
  1023. !["单个工料机", "替换人材机"].includes(curSubCoe.coeType) &&
  1024. dataCode === "gljCode"
  1025. ) {
  1026. args.cancel = true;
  1027. return;
  1028. }
  1029. // 调整类型不为“替换人材机”时,替换为编码不可编辑
  1030. if (curSubCoe.coeType !== "替换人材机" && dataCode === "replaceCode") {
  1031. args.cancel = true;
  1032. return;
  1033. }
  1034. },
  1035. onEditEnded: function (sender, args) {
  1036. let me = gljAdjOprObj,
  1037. isUpdate = false,
  1038. dataCode = me.setting.header[args.col].dataCode;
  1039. if (args.editingText && args.editingText.toString().trim().length > 0) {
  1040. if (dataCode === "amount" && !validateAmount(args.editingText)) {
  1041. alert("请输入数值或者表达式,如:[人材机编码]*0.3+1、1+([v]-50)/100");
  1042. args.sheet.setValue(
  1043. args.row,
  1044. args.col,
  1045. typeof me.currentGljAdjList[args.row] !== "undefined" &&
  1046. typeof me.currentGljAdjList[args.row][dataCode] !== "undefined"
  1047. ? me.currentGljAdjList[args.row][dataCode] + ""
  1048. : ""
  1049. );
  1050. } else {
  1051. //update
  1052. if (
  1053. args.row < me.currentGljAdjList.length &&
  1054. args.editingText.toString().trim() !==
  1055. me.currentGljAdjList[args.row][dataCode]
  1056. ) {
  1057. let updateObj = me.currentGljAdjList[args.row];
  1058. if (
  1059. dataCode === "gljCode" &&
  1060. typeof updateObj.coeType !== "undefined" &&
  1061. (updateObj.coeType === "单个工料机" ||
  1062. updateObj.coeType === "替换人材机")
  1063. ) {
  1064. let gljName = me.getGljName(args.editingText, me.gljList);
  1065. if (gljName) {
  1066. updateObj.gljCode = args.editingText;
  1067. updateObj.gljName = gljName;
  1068. isUpdate = true;
  1069. } else {
  1070. alert("不存在编号为" + args.editingText + "的工料机");
  1071. }
  1072. } else if (
  1073. dataCode === "replaceCode" &&
  1074. typeof updateObj.coeType !== "undefined" &&
  1075. updateObj.coeType === "替换人材机"
  1076. ) {
  1077. let gljName = me.getGljName(args.editingText, me.gljList);
  1078. if (gljName) {
  1079. updateObj.replaceCode = args.editingText;
  1080. updateObj.replaceName = gljName;
  1081. isUpdate = true;
  1082. } else {
  1083. alert("不存在编号为" + args.editingText + "的工料机");
  1084. }
  1085. } else if (dataCode === "coeType") {
  1086. isUpdate = true;
  1087. updateObj[dataCode] = args.editingText;
  1088. updateObj.gljCode = "";
  1089. updateObj.gljName = "";
  1090. updateObj.replaceCode = "";
  1091. updateObj.replaceName = "";
  1092. } else if (dataCode !== "gljCode") {
  1093. isUpdate = true;
  1094. updateObj[dataCode] = args.editingText;
  1095. }
  1096. }
  1097. //insert
  1098. else if (args.row >= me.currentGljAdjList.length) {
  1099. isUpdate = true;
  1100. let newAdjGlj = {};
  1101. newAdjGlj[dataCode] = args.editingText;
  1102. me.currentGljAdjList.push(newAdjGlj);
  1103. }
  1104. if (isUpdate) {
  1105. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  1106. console.log(me.currentGljAdjList);
  1107. me.show(me.currentGljAdjList);
  1108. });
  1109. } else {
  1110. args.sheet.setValue(
  1111. args.row,
  1112. args.col,
  1113. typeof me.currentGljAdjList[args.row] !== "undefined" &&
  1114. typeof me.currentGljAdjList[args.row][dataCode] !== "undefined"
  1115. ? me.currentGljAdjList[args.row][dataCode] + ""
  1116. : ""
  1117. );
  1118. }
  1119. }
  1120. }
  1121. },
  1122. getValidPasteData: function (pasteItems, info) {
  1123. let me = gljAdjOprObj;
  1124. function isDef(v) {
  1125. return v !== undefined && v !== null;
  1126. }
  1127. // 粘贴项匹配处理
  1128. let rules = {
  1129. coeType: function (v, cur, tar) {
  1130. if (v === "") {
  1131. tar.coeType = v;
  1132. tar.gljCode = v;
  1133. tar.gljName = v;
  1134. tar.replaceCode = v;
  1135. tar.replaceName = v;
  1136. } else if (me.setting.comboItems.coeType.includes(v)) {
  1137. tar.coeType = v;
  1138. }
  1139. },
  1140. gljCode: function (v, cur, tar) {
  1141. if (v === "") {
  1142. tar.gljCode = v;
  1143. tar.gljName = v;
  1144. } else if (
  1145. ["单个工料机", "替换人材机"].includes(tar.coeType) ||
  1146. (!isDef(tar.coeType) &&
  1147. isDef(cur) &&
  1148. ["单个工料机", "替换人材机"].includes(cur.coeType))
  1149. ) {
  1150. let gljName = me.getGljName(v, me.gljList);
  1151. if (gljName) {
  1152. tar.gljCode = v;
  1153. tar.gljName = gljName;
  1154. }
  1155. }
  1156. },
  1157. amount: function (v, cur, tar) {
  1158. /* if (!isNaN(v)) {
  1159. tar.amount = v;
  1160. } */
  1161. if (validateAmount(v)) {
  1162. tar.amount = v;
  1163. }
  1164. },
  1165. operator: function (v, cur, tar) {
  1166. if (v === "" || me.setting.comboItems.operator.includes(v)) {
  1167. tar.operator = v;
  1168. }
  1169. },
  1170. replaceCode: function (v, cur, tar) {
  1171. if (v === "") {
  1172. tar.replaceCode = v;
  1173. tar.replaceName = v;
  1174. } else if (
  1175. tar.coeType === "替换人材机" ||
  1176. (!isDef(tar.coeType) && isDef(cur) && cur.coeType === "替换人材机")
  1177. ) {
  1178. let replaceName = me.getGljName(v, me.gljList);
  1179. if (replaceName) {
  1180. tar.replaceCode = v;
  1181. tar.replaceName = replaceName;
  1182. }
  1183. }
  1184. },
  1185. };
  1186. let rst = [];
  1187. for (let i = 0, len = pasteItems.length; i < len; i++) {
  1188. let row = i + info.cellRange.row;
  1189. let target = {},
  1190. curObj = me.currentGljAdjList[row],
  1191. pasteItem = pasteItems[i];
  1192. if (row < me.currentGljAdjList.length) {
  1193. target.index = row; //要有下标做为匹配的依据,不然在复制多行并且某个单元格是只读的情况下,这里返回的updateList个数会比选中的行数少,造成更新行和实际不匹配的情况
  1194. }
  1195. for (let pasteKey in pasteItem) {
  1196. if (rules[pasteKey]) {
  1197. rules[pasteKey](pasteItem[pasteKey], curObj, target);
  1198. }
  1199. }
  1200. if (Object.keys(target).length > 0) {
  1201. rst.push(target);
  1202. }
  1203. }
  1204. return rst;
  1205. },
  1206. onClipboardPasted: function (sender, info) {
  1207. let me = gljAdjOprObj,
  1208. row;
  1209. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  1210. let validData = me.getValidPasteData(items, info);
  1211. for (let i = 0, len = validData.length; i < len; i++) {
  1212. row = i + info.cellRange.row;
  1213. //update
  1214. if (
  1215. row < me.currentGljAdjList.length &&
  1216. typeof validData[i].index !== "undefined"
  1217. ) {
  1218. let updateObj = me.currentGljAdjList[validData[i].index]; //这里改成读取下标
  1219. delete validData[i].index; //清除下标
  1220. Object.assign(updateObj, validData[i]);
  1221. }
  1222. //insert
  1223. else {
  1224. me.currentGljAdjList.push(validData[i]);
  1225. }
  1226. }
  1227. if (validData.length > 0) {
  1228. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  1229. me.show(me.currentGljAdjList);
  1230. });
  1231. } else {
  1232. me.show(me.currentGljAdjList);
  1233. }
  1234. },
  1235. onDelOpr: function (workBook, setting) {
  1236. let me = gljAdjOprObj;
  1237. workBook.commandManager().register("gljAdjDel", function () {
  1238. debugger;
  1239. let sheet = workBook.getSheet(0);
  1240. let sels = sheet.getSelections();
  1241. let isUpdate = false;
  1242. for (let i = 0, len = sels.length; i < len; i++) {
  1243. if (sels[i].colCount === setting.header.length) {
  1244. //can del
  1245. if (sels[i].row < me.currentGljAdjList.length) {
  1246. isUpdate = true;
  1247. me.currentGljAdjList.splice(sels[i].row, sels[i].rowCount);
  1248. }
  1249. }
  1250. }
  1251. if (isUpdate) {
  1252. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  1253. me.show(me.currentGljAdjList);
  1254. });
  1255. }
  1256. });
  1257. workBook
  1258. .commandManager()
  1259. .setShortcutKey(
  1260. null,
  1261. GC.Spread.Commands.Key.del,
  1262. false,
  1263. false,
  1264. false,
  1265. false
  1266. );
  1267. workBook
  1268. .commandManager()
  1269. .setShortcutKey(
  1270. "gljAdjDel",
  1271. GC.Spread.Commands.Key.del,
  1272. false,
  1273. false,
  1274. false,
  1275. false
  1276. );
  1277. },
  1278. getGljName: function (gljCode, gljList, withSpecs) {
  1279. //withSpecs 是否带上规格型号
  1280. let rst = null;
  1281. for (let i = 0, len = gljList.length; i < len; i++) {
  1282. if (gljCode === gljList[i].code) {
  1283. rst =
  1284. withSpecs == true
  1285. ? gljList[i].name + " - " + gljList[i].specs
  1286. : gljList[i].name;
  1287. break;
  1288. }
  1289. }
  1290. return rst;
  1291. },
  1292. show: function (coes) {
  1293. let me = gljAdjOprObj;
  1294. pageObj.showData(me.workSheet, me.setting, coes);
  1295. },
  1296. getGljItemsOcc: function () {
  1297. let me = gljAdjOprObj;
  1298. $.ajax({
  1299. type: "post",
  1300. url: "/stdGljRepository/api/getGljItemsOccupied",
  1301. data: { repId: pageOprObj.gljLibId, occupation: "-_id code name specs" },
  1302. dataType: "json",
  1303. timeout: 5000,
  1304. success: function (result) {
  1305. if (result.error) {
  1306. alert(result.message);
  1307. } else {
  1308. me.gljList = result.data;
  1309. }
  1310. },
  1311. error: function (err) {
  1312. alert("内部程序错误!");
  1313. },
  1314. });
  1315. },
  1316. };