coe.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  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. headerName: "显示编办",
  349. headerWidth: 180,
  350. dataCode: "displayCompilation",
  351. dataType: "String",
  352. hAlign: "left",
  353. vAlign: "center",
  354. readOnly: false,
  355. },
  356. ],
  357. },
  358. buildSheet: function (container) {
  359. let me = coeOprObj;
  360. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  361. sheetCommonObj.bindEscKey(me.workBook, [
  362. {
  363. sheet: me.workBook.getSheet(0),
  364. editStarting: null,
  365. editEnded: me.onEditEnded,
  366. },
  367. ]);
  368. me.workSheet = me.workBook.getSheet(0);
  369. me.workSheet.options.isProtected = true;
  370. me.onDelOpr(me.workBook, me.setting);
  371. me.initContextMenu();
  372. me.workSheet.bind(
  373. GC.Spread.Sheets.Events.SelectionChanged,
  374. me.onSelectionChanged
  375. );
  376. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  377. me.workBook.bind(
  378. GC.Spread.Sheets.Events.ClipboardPasting,
  379. me.onClipboardPasting
  380. );
  381. me.workBook.bind(
  382. GC.Spread.Sheets.Events.ClipboardPasted,
  383. me.onClipboardPasted
  384. );
  385. },
  386. onSelectionChanged: function (sender, info) {
  387. if (
  388. (info.oldSelections.length === 0 && info.newSelections.length > 0) ||
  389. info.oldSelections[0].row !== info.newSelections[0].row
  390. ) {
  391. const row = info.newSelections[0].row;
  392. coeOprObj.coeSelInit(row);
  393. }
  394. },
  395. coeSelInit: function (row) {
  396. const me = coeOprObj;
  397. const adj = gljAdjOprObj;
  398. if (row < me.currentCoeList.length) {
  399. me.currentCoe = me.currentCoeList[row];
  400. adj.currentGljAdjList = me.currentCoe.coes;
  401. adj.buildDynamicComboBox(adj.workSheet);
  402. } else {
  403. me.currentCoe = null;
  404. adj.currentGljAdjList = [];
  405. adj.buildBaseCell(adj.workSheet);
  406. }
  407. //refresh & show coes
  408. sheetCommonObj.cleanSheet(adj.workSheet, adj.setting, -1);
  409. me.workBook.focus(true);
  410. adj.show(adj.currentGljAdjList);
  411. },
  412. onEditEnded: function (sender, args) {
  413. let me = coeOprObj,
  414. addArr = [],
  415. updateArr = [],
  416. dataCode = me.setting.header[args.col].dataCode;
  417. if (args.editingText && args.editingText.toString().trim().length > 0) {
  418. let inputT = args.editingText.toString().trim();
  419. //update
  420. if (args.row < me.currentCoeList.length) {
  421. let updateObj = me.currentCoeList[args.row];
  422. if (updateObj[dataCode] != inputT) {
  423. if (dataCode === "serialNo") {
  424. if (me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)) {
  425. me.currentMaxNo =
  426. me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  427. updateObj[dataCode] = inputT;
  428. updateArr.push(updateObj);
  429. me.save([], updateArr, [], true);
  430. } else if (!me.isInt(inputT)) {
  431. alert("编号只能为整数!");
  432. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + "");
  433. } else if (me.hasTisNo(me.currentCoeList, inputT)) {
  434. alert("该编号已存在!");
  435. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + "");
  436. }
  437. } else if (
  438. ["actualVal", "maxVal", "minVal"].includes(dataCode) &&
  439. isNaN(inputT)
  440. ) {
  441. alert("只能输入数值!");
  442. args.sheet.setValue(args.row, args.col, updateObj[dataCode] || "");
  443. } else {
  444. updateObj[dataCode] = inputT;
  445. me.setOptionList(dataCode, inputT, updateObj);
  446. updateArr.push(updateObj);
  447. me.save([], updateArr, [], true);
  448. }
  449. }
  450. }
  451. //insert
  452. else {
  453. let newCoe = {};
  454. newCoe.libID = pageOprObj.rationLibId;
  455. if (dataCode === "serialNo") {
  456. if (me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)) {
  457. me.currentMaxNo =
  458. me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  459. newCoe[dataCode] = inputT;
  460. addArr.push(newCoe);
  461. me.save(addArr, [], [], true, function (result) {
  462. me.updateCurrentCoeList(result);
  463. });
  464. } else if (!me.isInt(inputT)) {
  465. args.sheet.setValue(args.row, args.col, "");
  466. alert("编号只能为整数!");
  467. } else if (me.hasTisNo(me.currentCoeList, inputT)) {
  468. args.sheet.setValue(args.row, args.col, "");
  469. alert("该编号已存在!");
  470. }
  471. } else if (
  472. ["actualVal", "maxVal", "minVal"].includes(dataCode) &&
  473. isNaN(inputT)
  474. ) {
  475. alert("只能输入数值!");
  476. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + "");
  477. } else {
  478. newCoe.serialNo = ++me.currentMaxNo;
  479. newCoe[dataCode] = inputT;
  480. me.setOptionList(dataCode, inputT, newCoe);
  481. addArr.push(newCoe);
  482. me.save(addArr, [], [], true, function (result) {
  483. me.updateCurrentCoeList(result);
  484. });
  485. }
  486. }
  487. }
  488. },
  489. setOptionList: function (dataCode, inputT, obj) {
  490. if (dataCode == "option_codes") {
  491. //所选人材的情况,要获取人材机下拉列表
  492. inputT = inputT.replace(/[\s\r\n]/g, ""); //去掉空格换行等字符
  493. let optionList = [];
  494. let options = inputT.split("|");
  495. for (let code of options) {
  496. let name = gljAdjOprObj.getGljName(code, gljAdjOprObj.gljList, true);
  497. if (name) optionList.push({ text: name, value: code });
  498. }
  499. obj.option_list = optionList;
  500. }
  501. },
  502. onClipboardPasting: function (sender, info) {
  503. let me = coeOprObj,
  504. maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  505. if (maxCol > me.setting.header.length) {
  506. info.cancel = true;
  507. }
  508. },
  509. onClipboardPasted: function (sender, info) {
  510. let me = coeOprObj,
  511. addArr = [],
  512. updateArr = [];
  513. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  514. let uniqItems = me.makeUniqItems(items);
  515. for (let i = 0, len = uniqItems.length; i < len; i++) {
  516. for (let attr in uniqItems[i]) {
  517. if (
  518. ["actualVal", "maxVal", "minVal"].includes(attr) &&
  519. isNaN(uniqItems[i][attr])
  520. ) {
  521. uniqItems[i][attr] = undefined;
  522. }
  523. }
  524. let row = i + info.cellRange.row;
  525. //update
  526. if (row < me.currentCoeList.length) {
  527. let updateObj = me.currentCoeList[row];
  528. for (let attr in uniqItems[i]) {
  529. if (attr === "serialNo") {
  530. if (
  531. me.isInt(uniqItems[i][attr]) &&
  532. !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])
  533. ) {
  534. me.currentMaxNo =
  535. me.currentMaxNo >= uniqItems[i][attr]
  536. ? me.currentMaxNo
  537. : uniqItems[i][attr];
  538. updateObj[attr] = uniqItems[i][attr];
  539. }
  540. } else {
  541. updateObj[attr] = uniqItems[i][attr];
  542. }
  543. }
  544. updateArr.push(updateObj);
  545. }
  546. //insert
  547. else {
  548. if (
  549. typeof uniqItems[i].serialNo !== "undefined" &&
  550. uniqItems[i] &&
  551. me.isInt(uniqItems[i].serialNo) &&
  552. !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)
  553. ) {
  554. me.currentMaxNo =
  555. me.currentMaxNo >= uniqItems[i].serialNo
  556. ? me.currentMaxNo
  557. : uniqItems[i].serialNo;
  558. } else {
  559. uniqItems[i].serialNo = ++me.currentMaxNo;
  560. }
  561. uniqItems[i].libID = pageOprObj.rationLibId;
  562. addArr.push(uniqItems[i]);
  563. }
  564. }
  565. if (addArr.length > 0 || updateArr.length > 0) {
  566. me.save(addArr, updateArr, [], true, function (result) {
  567. me.updateCurrentCoeList(result);
  568. });
  569. }
  570. },
  571. onDelOpr: function (workBook, setting) {
  572. let me = coeOprObj,
  573. that = gljAdjOprObj;
  574. workBook.commandManager().register("coeListDel", function () {
  575. let deleteArr = [];
  576. let sheet = workBook.getSheet(0);
  577. let sels = sheet.getSelections();
  578. let idx = sels[0].row;
  579. for (let i = 0, len = sels.length; i < len; i++) {
  580. if (idx > sels[i].row) {
  581. idx = sels[i].row;
  582. }
  583. if (sels[i].colCount === setting.header.length) {
  584. //can del
  585. for (let r = 0, rLen = sels[i].rowCount; r < rLen; r++) {
  586. let row = sels[i].row + r;
  587. if (row < me.currentCoeList.length) {
  588. deleteArr.push({
  589. libID: me.currentCoeList[row].libID,
  590. ID: me.currentCoeList[row].ID,
  591. });
  592. }
  593. }
  594. me.currentCoeList.splice(sels[i].row, sels[i].rowCount);
  595. }
  596. }
  597. if (deleteArr.length > 0) {
  598. let coeID = deleteArr[0].ID;
  599. me.referenceCheck(coeID, function (info) {
  600. if (info.length > 0) {
  601. alert("该子目换算已被引用,不能删除!");
  602. } else {
  603. me.save([], [], deleteArr, true);
  604. me.currentCoe =
  605. typeof me.currentCoeList[idx] !== "undefined"
  606. ? me.currentCoeList[idx]
  607. : null;
  608. that.currentGljAdjList = me.currentCoe ? me.currentCoe.coes : [];
  609. gljAdjOprObj.show(that.currentGljAdjList);
  610. }
  611. });
  612. }
  613. });
  614. workBook
  615. .commandManager()
  616. .setShortcutKey(
  617. null,
  618. GC.Spread.Commands.Key.del,
  619. false,
  620. false,
  621. false,
  622. false
  623. );
  624. workBook
  625. .commandManager()
  626. .setShortcutKey(
  627. "coeListDel",
  628. GC.Spread.Commands.Key.del,
  629. false,
  630. false,
  631. false,
  632. false
  633. );
  634. },
  635. initContextMenu: function () {
  636. const me = this;
  637. $.contextMenu({
  638. selector: "#mainSpread",
  639. build: function ($triggerElement, e) {
  640. //控制允许右键菜单在哪个位置出现
  641. const target = SheetDataHelper.safeRightClickSelection(
  642. $triggerElement,
  643. e,
  644. me.workBook
  645. );
  646. const sheet = me.workBook.getSheet(0);
  647. if (target.hitTestType === 3) {
  648. //在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  649. if (typeof target.row !== "undefined") {
  650. //控制按钮是否可用
  651. sheet.setActiveCell(target.row, target.col);
  652. me.coeSelInit(target.row);
  653. }
  654. return {
  655. callback: function () { },
  656. items: {
  657. getReference: {
  658. name: "查找引用",
  659. disabled: function () {
  660. return !me.currentCoeList || !me.currentCoeList[target.row];
  661. },
  662. icon: "fa-search",
  663. callback: function () {
  664. const coe = me.currentCoeList[target.row];
  665. me.getReference(coe.ID);
  666. },
  667. },
  668. },
  669. };
  670. } else {
  671. return false;
  672. }
  673. },
  674. });
  675. },
  676. referenceCheck: function (coeID, callback) {
  677. $.bootstrapLoading.start();
  678. CommonAjax.post(
  679. "/rationRepository/api/getCoeReference",
  680. { rationRepId: pageOprObj.rationLibId, coeID },
  681. function (info) {
  682. callback(info);
  683. $.bootstrapLoading.end();
  684. },
  685. function () {
  686. $.bootstrapLoading.end();
  687. }
  688. );
  689. },
  690. getReference: function (coeID) {
  691. const $info = $("#info");
  692. const $infoBody = $("#infoBody");
  693. const me = this;
  694. me.referenceCheck(coeID, function (info) {
  695. let htmlArr = [];
  696. if (!info || !info.length) {
  697. htmlArr.push("<li>无引用数据</li>");
  698. } else {
  699. htmlArr = info.map((ration) => {
  700. return `<li>
  701. <span>${ration.code}</span>
  702. <a data-dismiss="modal" href="javascript:;" onclick="sectionTreeObj.locateToSection('${ration.code}')">定位</a>
  703. </li>`;
  704. });
  705. }
  706. $infoBody.html(htmlArr.join(""));
  707. $info.modal("show");
  708. });
  709. },
  710. //粘贴的数据,编号唯一化,去除编号重复的项
  711. makeUniqItems: function (items) {
  712. let rst = [];
  713. for (let i = 0, len = items.length; i < len; i++) {
  714. if (typeof items[i].serialNo !== "undefined" && items[i].serialNo) {
  715. if (rst.length === 0) {
  716. rst.push(items[i]);
  717. } else {
  718. let isExist = false;
  719. for (let j = 0, jLen = rst.length; j < jLen; j++) {
  720. if (items[i].serialNo === rst[j].serialNo) {
  721. isExist = true;
  722. break;
  723. }
  724. }
  725. if (!isExist) {
  726. rst.push(items[i]);
  727. }
  728. }
  729. } else {
  730. rst.push(items[i]);
  731. }
  732. }
  733. return rst;
  734. },
  735. isInt: function (num) {
  736. return !isNaN(num) && num % 1 === 0;
  737. },
  738. hasTisNo: function (coeList, newSerialNo) {
  739. let rst = false;
  740. for (let i = 0, len = coeList.length; i < len; i++) {
  741. if (coeList[i].serialNo == newSerialNo) {
  742. rst = true;
  743. break;
  744. }
  745. }
  746. return rst;
  747. },
  748. updateCurrentCoeList: function (newCoeList) {
  749. let me = coeOprObj;
  750. if (newCoeList) {
  751. me.currentCoeList = me.currentCoeList.concat(newCoeList);
  752. }
  753. },
  754. sortCoeList: function (coeList) {
  755. coeList.sort(function (a, b) {
  756. let rst = 0;
  757. if (a.serialNo > b.serialNo) rst = 1;
  758. else if (a.serialNo < b.serialNo) rst = -1;
  759. return rst;
  760. });
  761. },
  762. getCoeList: function () {
  763. let me = coeOprObj;
  764. $.ajax({
  765. type: "post",
  766. url: "/rationRepository/api/getCoeList",
  767. data: { libID: pageOprObj.rationLibId },
  768. dataType: "json",
  769. timeout: 20000,
  770. success: function (result) {
  771. if (!result.error) {
  772. me.currentCoeList = result.data;
  773. me.sortCoeList(me.currentCoeList);
  774. me.currentMaxNo =
  775. me.currentCoeList.length > 0
  776. ? me.currentCoeList[me.currentCoeList.length - 1].serialNo
  777. : 0;
  778. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  779. me.workSheet.clearSelection();
  780. }
  781. },
  782. error: function (err) {
  783. alert("内部程序错误!");
  784. },
  785. });
  786. },
  787. keepNumber: function (arr) {
  788. arr.forEach((item) => {
  789. Object.keys(item).forEach((key) => {
  790. if (["actualVal", "maxVal", "minVal"].includes(key)) {
  791. item[key] = +item[key];
  792. }
  793. });
  794. });
  795. },
  796. save: function (addArr, updateArr, deleteArr, refresh, callback) {
  797. let me = coeOprObj;
  798. // me.keepNumber(updateArr);
  799. $.ajax({
  800. type: "POST",
  801. url: "api/saveCoeList",
  802. data: {
  803. data: JSON.stringify({
  804. addArr: addArr,
  805. updateArr: updateArr,
  806. deleteArr: deleteArr,
  807. }),
  808. },
  809. dataType: "json",
  810. timeout: 5000,
  811. success: function (result) {
  812. if (result.error) {
  813. alert(result.message);
  814. } else {
  815. if (callback) {
  816. if (result.message === "mixed") {
  817. for (let i = 0, len = result.data.length; i < len; i++) {
  818. if (result.data[i][0] === "addSc") {
  819. result.data = result.data[i][1];
  820. break;
  821. }
  822. }
  823. }
  824. callback(result.data);
  825. }
  826. if (refresh) {
  827. me.sortCoeList(me.currentCoeList);
  828. me.currentMaxNo =
  829. me.currentCoeList.length > 0
  830. ? me.currentCoeList[me.currentCoeList.length - 1].serialNo
  831. : 0;
  832. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  833. }
  834. }
  835. },
  836. error: function (err) {
  837. alert("内部程序错误!");
  838. },
  839. });
  840. },
  841. };
  842. // 验证数量的有效性:可以输入数值,也可以输入表达式,eg: [人材机编码]*1.5+1,1+([v]-50)/100。 [v]代表前台调用时,子目换算实际值
  843. const validateAmount = (amountStr) => {
  844. if (!amountStr) {
  845. return true;
  846. }
  847. let str = amountStr.replace(/\s/g, "");
  848. if (!str) {
  849. return true;
  850. }
  851. try {
  852. debugger;
  853. str = amountStr
  854. .replace(/\s/g, "")
  855. .replace(/\[v\]/g, "0")
  856. .replace(/\[\d+\]/g, "0");
  857. eval(str);
  858. } catch (error) {
  859. return false;
  860. }
  861. return true;
  862. };
  863. let gljAdjOprObj = {
  864. workBook: null,
  865. workSheet: null,
  866. currentGljAdjList: [],
  867. gljList: [], //只含编号和名称的总工料机列表
  868. setting: {
  869. header: [
  870. {
  871. headerName: "调整类型",
  872. headerWidth: 80,
  873. dataCode: "coeType",
  874. dataType: "String",
  875. hAlign: "center",
  876. vAlign: "center",
  877. readOnly: false,
  878. },
  879. {
  880. headerName: "人材机编码",
  881. headerWidth: 80,
  882. dataCode: "gljCode",
  883. dataType: "String",
  884. formatter: "@",
  885. hAlign: "center",
  886. vAlign: "center",
  887. readOnly: false,
  888. },
  889. // readOnly: true --> false,需要兼容粘贴列包含只读项
  890. {
  891. headerName: "名称",
  892. headerWidth: 100,
  893. dataCode: "gljName",
  894. dataType: "String",
  895. hAlign: "center",
  896. vAlign: "center",
  897. readOnly: false,
  898. },
  899. {
  900. headerName: "操作符",
  901. headerWidth: 60,
  902. dataCode: "operator",
  903. dataType: "String",
  904. hAlign: "center",
  905. vAlign: "center",
  906. readOnly: false,
  907. },
  908. {
  909. headerName: "数量",
  910. headerWidth: 80,
  911. dataCode: "amount",
  912. dataType: "String",
  913. hAlign: "center",
  914. vAlign: "center",
  915. readOnly: false,
  916. },
  917. {
  918. headerName: "替换为编码",
  919. headerWidth: 80,
  920. dataCode: "replaceCode",
  921. dataType: "String",
  922. formatter: "@",
  923. hAlign: "center",
  924. vAlign: "center",
  925. readOnly: false,
  926. },
  927. // readOnly: true --> false
  928. {
  929. headerName: "替换为名称",
  930. headerWidth: 100,
  931. dataCode: "replaceName",
  932. dataType: "String",
  933. hAlign: "center",
  934. vAlign: "center",
  935. readOnly: false,
  936. },
  937. ],
  938. comboItems: {
  939. //调整类型下拉菜单
  940. coeType: [
  941. "定额",
  942. "人工",
  943. "材料",
  944. "机械",
  945. "主材",
  946. "设备",
  947. "单个工料机",
  948. "替换人材机",
  949. "所选人材机",
  950. ],
  951. //操作符下拉菜单
  952. operator: ["+", "-", "*", "/", "=", "+*", "-*"],
  953. },
  954. },
  955. buildSheet: function (container) {
  956. let me = gljAdjOprObj;
  957. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  958. me.workSheet = me.workBook.getSheet(0);
  959. sheetCommonObj.bindEscKey(me.workBook, [
  960. {
  961. sheet: me.workBook.getSheet(0),
  962. editStarting: me.onEditStart,
  963. editEnded: me.onEditEnded,
  964. },
  965. ]);
  966. me.workSheet.options.isProtected = true;
  967. me.onDelOpr(me.workBook, me.setting);
  968. me.workSheet.clearSelection();
  969. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
  970. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  971. me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  972. me.workSheet.bind(
  973. GC.Spread.Sheets.Events.ClipboardPasted,
  974. me.onClipboardPasted
  975. );
  976. },
  977. buildBaseCell: function (sheet) {
  978. let me = gljAdjOprObj;
  979. sheet.suspendPaint();
  980. sheet.suspendEvent();
  981. let baseCell = GC.Spread.Sheets.CellTypes.Base();
  982. sheet.getCell(-1, 0).cellType(baseCell);
  983. sheet.getCell(-1, 3).cellType(baseCell);
  984. sheet.resumePaint();
  985. sheet.resumeEvent();
  986. },
  987. buildDynamicComboBox: function (sheet) {
  988. let me = gljAdjOprObj;
  989. sheet.suspendPaint();
  990. sheet.suspendEvent();
  991. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  992. dynamicCombo.items(me.setting.comboItems.coeType);
  993. let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
  994. dynamicOprCombo.items(me.setting.comboItems.operator);
  995. sheet.getCell(-1, 0).cellType(dynamicCombo);
  996. sheet.getCell(-1, 3).cellType(dynamicOprCombo);
  997. sheet.resumePaint();
  998. sheet.resumeEvent();
  999. },
  1000. onEnterCell: function (sender, args) {
  1001. args.sheet.repaint();
  1002. },
  1003. onEditStart: function (sender, args) {
  1004. let me = gljAdjOprObj;
  1005. let dataCode = me.setting.header[args.col].dataCode;
  1006. // 超出范围-没有选中的调整主项
  1007. if (!coeOprObj.currentCoe) {
  1008. args.cancel = true;
  1009. return;
  1010. }
  1011. // 名称、替换为名称总是不可编辑(表头设置readOnly没有设置为true,因为需要粘贴)
  1012. let alwaysNotEditable = ["gljName", "replaceName"];
  1013. if (alwaysNotEditable.includes(dataCode)) {
  1014. args.cancel = true;
  1015. return;
  1016. }
  1017. // 新一行编辑时,除了总是可编辑的单元格:调整类型、操作符、数量,其他不可编辑
  1018. let alwaysEditable = ["coeType", "operator", "amount"];
  1019. if (
  1020. args.row > me.currentGljAdjList.length - 1 &&
  1021. !alwaysEditable.includes(dataCode)
  1022. ) {
  1023. args.cancel = true;
  1024. return;
  1025. }
  1026. let curSubCoe = me.currentGljAdjList[args.row];
  1027. if (!curSubCoe) {
  1028. return;
  1029. }
  1030. // 调整类型不为“单个工料机”和“替换人材机”时,人材机编码不可编辑
  1031. if (
  1032. !["单个工料机", "替换人材机"].includes(curSubCoe.coeType) &&
  1033. dataCode === "gljCode"
  1034. ) {
  1035. args.cancel = true;
  1036. return;
  1037. }
  1038. // 调整类型不为“替换人材机”时,替换为编码不可编辑
  1039. if (curSubCoe.coeType !== "替换人材机" && dataCode === "replaceCode") {
  1040. args.cancel = true;
  1041. return;
  1042. }
  1043. },
  1044. onEditEnded: function (sender, args) {
  1045. let me = gljAdjOprObj,
  1046. isUpdate = false,
  1047. dataCode = me.setting.header[args.col].dataCode;
  1048. if (args.editingText && args.editingText.toString().trim().length > 0) {
  1049. if (dataCode === "amount" && !validateAmount(args.editingText)) {
  1050. alert("请输入数值或者表达式,如:[人材机编码]*0.3+1、1+([v]-50)/100");
  1051. args.sheet.setValue(
  1052. args.row,
  1053. args.col,
  1054. typeof me.currentGljAdjList[args.row] !== "undefined" &&
  1055. typeof me.currentGljAdjList[args.row][dataCode] !== "undefined"
  1056. ? me.currentGljAdjList[args.row][dataCode] + ""
  1057. : ""
  1058. );
  1059. } else {
  1060. //update
  1061. if (
  1062. args.row < me.currentGljAdjList.length &&
  1063. args.editingText.toString().trim() !==
  1064. me.currentGljAdjList[args.row][dataCode]
  1065. ) {
  1066. let updateObj = me.currentGljAdjList[args.row];
  1067. if (
  1068. dataCode === "gljCode" &&
  1069. typeof updateObj.coeType !== "undefined" &&
  1070. (updateObj.coeType === "单个工料机" ||
  1071. updateObj.coeType === "替换人材机")
  1072. ) {
  1073. let gljName = me.getGljName(args.editingText, me.gljList);
  1074. if (gljName) {
  1075. updateObj.gljCode = args.editingText;
  1076. updateObj.gljName = gljName;
  1077. isUpdate = true;
  1078. } else {
  1079. alert("不存在编号为" + args.editingText + "的工料机");
  1080. }
  1081. } else if (
  1082. dataCode === "replaceCode" &&
  1083. typeof updateObj.coeType !== "undefined" &&
  1084. updateObj.coeType === "替换人材机"
  1085. ) {
  1086. let gljName = me.getGljName(args.editingText, me.gljList);
  1087. if (gljName) {
  1088. updateObj.replaceCode = args.editingText;
  1089. updateObj.replaceName = gljName;
  1090. isUpdate = true;
  1091. } else {
  1092. alert("不存在编号为" + args.editingText + "的工料机");
  1093. }
  1094. } else if (dataCode === "coeType") {
  1095. isUpdate = true;
  1096. updateObj[dataCode] = args.editingText;
  1097. updateObj.gljCode = "";
  1098. updateObj.gljName = "";
  1099. updateObj.replaceCode = "";
  1100. updateObj.replaceName = "";
  1101. } else if (dataCode !== "gljCode") {
  1102. isUpdate = true;
  1103. updateObj[dataCode] = args.editingText;
  1104. }
  1105. }
  1106. //insert
  1107. else if (args.row >= me.currentGljAdjList.length) {
  1108. isUpdate = true;
  1109. let newAdjGlj = {};
  1110. newAdjGlj[dataCode] = args.editingText;
  1111. me.currentGljAdjList.push(newAdjGlj);
  1112. }
  1113. if (isUpdate) {
  1114. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  1115. console.log(me.currentGljAdjList);
  1116. me.show(me.currentGljAdjList);
  1117. });
  1118. } else {
  1119. args.sheet.setValue(
  1120. args.row,
  1121. args.col,
  1122. typeof me.currentGljAdjList[args.row] !== "undefined" &&
  1123. typeof me.currentGljAdjList[args.row][dataCode] !== "undefined"
  1124. ? me.currentGljAdjList[args.row][dataCode] + ""
  1125. : ""
  1126. );
  1127. }
  1128. }
  1129. }
  1130. },
  1131. getValidPasteData: function (pasteItems, info) {
  1132. let me = gljAdjOprObj;
  1133. function isDef(v) {
  1134. return v !== undefined && v !== null;
  1135. }
  1136. // 粘贴项匹配处理
  1137. let rules = {
  1138. coeType: function (v, cur, tar) {
  1139. if (v === "") {
  1140. tar.coeType = v;
  1141. tar.gljCode = v;
  1142. tar.gljName = v;
  1143. tar.replaceCode = v;
  1144. tar.replaceName = v;
  1145. } else if (me.setting.comboItems.coeType.includes(v)) {
  1146. tar.coeType = v;
  1147. }
  1148. },
  1149. gljCode: function (v, cur, tar) {
  1150. if (v === "") {
  1151. tar.gljCode = v;
  1152. tar.gljName = v;
  1153. } else if (
  1154. ["单个工料机", "替换人材机"].includes(tar.coeType) ||
  1155. (!isDef(tar.coeType) &&
  1156. isDef(cur) &&
  1157. ["单个工料机", "替换人材机"].includes(cur.coeType))
  1158. ) {
  1159. let gljName = me.getGljName(v, me.gljList);
  1160. if (gljName) {
  1161. tar.gljCode = v;
  1162. tar.gljName = gljName;
  1163. }
  1164. }
  1165. },
  1166. amount: function (v, cur, tar) {
  1167. /* if (!isNaN(v)) {
  1168. tar.amount = v;
  1169. } */
  1170. if (validateAmount(v)) {
  1171. tar.amount = v;
  1172. }
  1173. },
  1174. operator: function (v, cur, tar) {
  1175. if (v === "" || me.setting.comboItems.operator.includes(v)) {
  1176. tar.operator = v;
  1177. }
  1178. },
  1179. replaceCode: function (v, cur, tar) {
  1180. if (v === "") {
  1181. tar.replaceCode = v;
  1182. tar.replaceName = v;
  1183. } else if (
  1184. tar.coeType === "替换人材机" ||
  1185. (!isDef(tar.coeType) && isDef(cur) && cur.coeType === "替换人材机")
  1186. ) {
  1187. let replaceName = me.getGljName(v, me.gljList);
  1188. if (replaceName) {
  1189. tar.replaceCode = v;
  1190. tar.replaceName = replaceName;
  1191. }
  1192. }
  1193. },
  1194. };
  1195. let rst = [];
  1196. for (let i = 0, len = pasteItems.length; i < len; i++) {
  1197. let row = i + info.cellRange.row;
  1198. let target = {},
  1199. curObj = me.currentGljAdjList[row],
  1200. pasteItem = pasteItems[i];
  1201. if (row < me.currentGljAdjList.length) {
  1202. target.index = row; //要有下标做为匹配的依据,不然在复制多行并且某个单元格是只读的情况下,这里返回的updateList个数会比选中的行数少,造成更新行和实际不匹配的情况
  1203. }
  1204. for (let pasteKey in pasteItem) {
  1205. if (rules[pasteKey]) {
  1206. rules[pasteKey](pasteItem[pasteKey], curObj, target);
  1207. }
  1208. }
  1209. if (Object.keys(target).length > 0) {
  1210. rst.push(target);
  1211. }
  1212. }
  1213. return rst;
  1214. },
  1215. onClipboardPasted: function (sender, info) {
  1216. let me = gljAdjOprObj,
  1217. row;
  1218. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  1219. let validData = me.getValidPasteData(items, info);
  1220. for (let i = 0, len = validData.length; i < len; i++) {
  1221. row = i + info.cellRange.row;
  1222. //update
  1223. if (
  1224. row < me.currentGljAdjList.length &&
  1225. typeof validData[i].index !== "undefined"
  1226. ) {
  1227. let updateObj = me.currentGljAdjList[validData[i].index]; //这里改成读取下标
  1228. delete validData[i].index; //清除下标
  1229. Object.assign(updateObj, validData[i]);
  1230. }
  1231. //insert
  1232. else {
  1233. me.currentGljAdjList.push(validData[i]);
  1234. }
  1235. }
  1236. if (validData.length > 0) {
  1237. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  1238. me.show(me.currentGljAdjList);
  1239. });
  1240. } else {
  1241. me.show(me.currentGljAdjList);
  1242. }
  1243. },
  1244. onDelOpr: function (workBook, setting) {
  1245. let me = gljAdjOprObj;
  1246. workBook.commandManager().register("gljAdjDel", function () {
  1247. debugger;
  1248. let sheet = workBook.getSheet(0);
  1249. let sels = sheet.getSelections();
  1250. let isUpdate = false;
  1251. for (let i = 0, len = sels.length; i < len; i++) {
  1252. if (sels[i].colCount === setting.header.length) {
  1253. //can del
  1254. if (sels[i].row < me.currentGljAdjList.length) {
  1255. isUpdate = true;
  1256. me.currentGljAdjList.splice(sels[i].row, sels[i].rowCount);
  1257. }
  1258. }
  1259. }
  1260. if (isUpdate) {
  1261. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  1262. me.show(me.currentGljAdjList);
  1263. });
  1264. }
  1265. });
  1266. workBook
  1267. .commandManager()
  1268. .setShortcutKey(
  1269. null,
  1270. GC.Spread.Commands.Key.del,
  1271. false,
  1272. false,
  1273. false,
  1274. false
  1275. );
  1276. workBook
  1277. .commandManager()
  1278. .setShortcutKey(
  1279. "gljAdjDel",
  1280. GC.Spread.Commands.Key.del,
  1281. false,
  1282. false,
  1283. false,
  1284. false
  1285. );
  1286. },
  1287. getGljName: function (gljCode, gljList, withSpecs) {
  1288. //withSpecs 是否带上规格型号
  1289. let rst = null;
  1290. for (let i = 0, len = gljList.length; i < len; i++) {
  1291. if (gljCode === gljList[i].code) {
  1292. rst =
  1293. withSpecs == true
  1294. ? gljList[i].name + " - " + gljList[i].specs
  1295. : gljList[i].name;
  1296. break;
  1297. }
  1298. }
  1299. return rst;
  1300. },
  1301. show: function (coes) {
  1302. let me = gljAdjOprObj;
  1303. pageObj.showData(me.workSheet, me.setting, coes);
  1304. },
  1305. getGljItemsOcc: function () {
  1306. let me = gljAdjOprObj;
  1307. $.ajax({
  1308. type: "post",
  1309. url: "/stdGljRepository/api/getGljItemsOccupied",
  1310. data: { repId: pageOprObj.gljLibId, occupation: "-_id code name specs" },
  1311. dataType: "json",
  1312. timeout: 5000,
  1313. success: function (result) {
  1314. if (result.error) {
  1315. alert(result.message);
  1316. } else {
  1317. me.gljList = result.data;
  1318. }
  1319. },
  1320. error: function (err) {
  1321. alert("内部程序错误!");
  1322. },
  1323. });
  1324. },
  1325. };