installation.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. /**
  2. * Created by Zhong on 2018/1/19.
  3. **/
  4. const locked = lockUtil.getLocked();
  5. $(document).ready(function () {
  6. feeItemObj.buildSheet();
  7. const lockedSpreads = [
  8. feeItemObj.workBook,
  9. sectionObj.workBook,
  10. feeRuleObj.workBook,
  11. ];
  12. lockUtil.lockSpreads(lockedSpreads, locked);
  13. $("#sectionTreeModal").on("shown.bs.modal", function (e) {
  14. batchSectionObj.workBook.refresh();
  15. //bind confirm btn
  16. batchSectionObj.onConfirmBtn();
  17. });
  18. $("#sectionTreeModal").on("hidden.bs.modal", function () {
  19. batchSectionObj.clearChecked();
  20. });
  21. $("#delConfirm").click(function () {
  22. if (curDeleteType === feeItemObj.deleteType) {
  23. let me = feeItemObj,
  24. se = sectionObj,
  25. fr = feeRuleObj;
  26. let fiPostData = [],
  27. sePostData = [];
  28. let sels = me.workBook.getSheet(0).getSelections();
  29. for (let i = 0, len = sels.length; i < len; i++) {
  30. let sel = sels[i];
  31. //delete
  32. if (sel.colCount === me.setting.header.length) {
  33. for (let j = 0, jLen = sel.rowCount; j < jLen; j++) {
  34. let row = sel.row + j;
  35. let feeItem = me.cache[row];
  36. //有数据,删除数据
  37. if (me.isDef(feeItem)) {
  38. fiPostData.push({
  39. updateType: me.updateType.update,
  40. updateData: { ID: feeItem.ID, deleted: true },
  41. });
  42. //delete feeItem section
  43. for (let section of feeItem.section) {
  44. sePostData.push({
  45. updateType: me.updateType.update,
  46. updateData: { ID: section.ID, deleted: true },
  47. });
  48. }
  49. }
  50. }
  51. //front delete
  52. me.cache.splice(sel.row, sel.rowCount);
  53. }
  54. }
  55. //update currentFeeItem
  56. me.currentFeeItem = me.getCurrentData(me.sheet, me.cache);
  57. se.cache = me.isDef(me.currentFeeItem) ? me.currentFeeItem.section : [];
  58. if (fiPostData.length > 0) {
  59. me.updateFeeItem(fiPostData, function () {
  60. me.sheet.setRowCount(me.cache.length + 10);
  61. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  62. $("#delAlert").modal("hide");
  63. });
  64. if (sePostData.length > 0) {
  65. se.updateSection(sePostData);
  66. }
  67. sheetCommonObj.cleanData(se.sheet, se.setting, 10);
  68. sheetCommonObj.cleanData(fr.sheet, fr.setting, 10);
  69. } else {
  70. $("#delAlert").modal("hide");
  71. }
  72. } else if (curDeleteType === sectionObj.deleteType) {
  73. let me = sectionObj,
  74. fi = feeItemObj,
  75. fr = feeRuleObj;
  76. let sePostData = [],
  77. fiPostData = [];
  78. let sels = me.workBook.getSheet(0).getSelections();
  79. for (let i = 0, len = sels.length; i < len; i++) {
  80. let sel = sels[i];
  81. //delete
  82. // if (sel.colCount === me.setting.header.length) {
  83. for (let j = 0, jLen = sel.rowCount; j < jLen; j++) {
  84. let row = sel.row + j;
  85. let section = me.cache[row];
  86. //有数据,删除数据
  87. if (me.isDef(section)) {
  88. sePostData.push({
  89. updateType: me.updateType.del,
  90. updateData: { ID: section.ID, deleted: true },
  91. });
  92. fiPostData.push({
  93. updateType: me.updateType.update,
  94. updateData: {
  95. ID: fi.currentFeeItem.ID,
  96. $pull: { section: { ID: section.ID } },
  97. },
  98. });
  99. }
  100. }
  101. //front delete
  102. me.cache.splice(sel.row, sel.rowCount);
  103. // }
  104. }
  105. //update currentSection
  106. me.currentSection = fi.getCurrentData(me.sheet, me.cache);
  107. fr.cache = me.isDef(me.currentSection) ? me.currentSection.feeRule : [];
  108. if (sePostData.length > 0) {
  109. me.updateSection(sePostData, function () {
  110. me.sheet.setRowCount(me.cache.length + 5);
  111. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  112. $("#delAlert").modal("hide");
  113. });
  114. if (fiPostData.length > 0) {
  115. fi.updateFeeItem(fiPostData);
  116. }
  117. sheetCommonObj.cleanData(fr.sheet, fr.setting, 10);
  118. } else {
  119. $("#delAlert").modal("hide");
  120. }
  121. }
  122. });
  123. });
  124. let curDeleteType = null;
  125. //费用项
  126. let feeItemObj = {
  127. rationRepId: null,
  128. workBook: null,
  129. sheet: null,
  130. cache: [],
  131. currentFeeItem: null,
  132. feeType: { ZM: "子目费用", FX: "分项费用", CS: "措施费用" },
  133. updateType: { update: "update", new: "new" },
  134. deleteType: "feeItem",
  135. setting: {
  136. header: [
  137. {
  138. headerName: "费用项",
  139. headerWidth: 200,
  140. dataCode: "feeItem",
  141. dataType: "String",
  142. formatter: "@",
  143. hAlign: "left",
  144. vAlign: "center",
  145. },
  146. {
  147. headerName: "费用类型",
  148. headerWidth: 80,
  149. dataCode: "feeType",
  150. dataType: "String",
  151. hAlign: "center",
  152. vAlign: "center",
  153. },
  154. {
  155. headerName: "记取位置",
  156. headerWidth: 100,
  157. dataCode: "position",
  158. dataType: "String",
  159. formatter: "@",
  160. hAlign: "left",
  161. vAlign: "center",
  162. },
  163. {
  164. headerName: "序号",
  165. headerWidth: 50,
  166. dataCode: "seq",
  167. dataType: "Number",
  168. hAlign: "center",
  169. vAlign: "center",
  170. },
  171. {
  172. headerName: "降效比例(%)",
  173. headerWidth: 100,
  174. dataCode: "reductionRate",
  175. dataType: "Number",
  176. hAlign: "right",
  177. vAlign: "center",
  178. },
  179. {
  180. headerName: "措施比例(%)",
  181. headerWidth: 100,
  182. dataCode: "measureRate",
  183. dataType: "Number",
  184. hAlign: "right",
  185. vAlign: "center",
  186. },
  187. {
  188. headerName: "24记取位置",
  189. headerWidth: 100,
  190. dataCode: "position24",
  191. dataType: "String",
  192. formatter: "@",
  193. hAlign: "left",
  194. vAlign: "center",
  195. },
  196. {
  197. headerName: "24显示",
  198. headerWidth: 50,
  199. dataCode: "showIn24",
  200. dataType: "CheckBox",
  201. hAlign: "center",
  202. vAlign: "center",
  203. },
  204. ],
  205. view: { lockColumns: [] },
  206. comboItems: { feeType: ["子目费用", "分项费用", "措施费用"] },
  207. options: {
  208. tabStripVisible: false,
  209. allowCopyPasteExcelStyle: false,
  210. allowExtendPasteRange: true,
  211. allowUserDragDrop: false,
  212. allowUserDragFill: false,
  213. scrollbarMaxAlign: true,
  214. },
  215. },
  216. isDef: function (v) {
  217. return v !== undefined && v !== null;
  218. },
  219. //sheet things
  220. setOptions: function (workbook, opts) {
  221. for (let opt in opts) {
  222. workbook.options[opt] = opts[opt];
  223. }
  224. },
  225. setCombo: function (sheet, col, comboItems) {
  226. let combo = sheetCommonObj.getDynamicCombo();
  227. combo.items(comboItems).editable = false;
  228. sheet.getRange(-1, col, -1, 1).cellType(combo);
  229. },
  230. getCurrentData: function (sheet, cache) {
  231. let acRow = sheet.getActiveRowIndex();
  232. return this.isDef(cache[acRow]) ? cache[acRow] : null;
  233. },
  234. buildSheet: function () {
  235. let me = this,
  236. se = sectionObj,
  237. fr = feeRuleObj,
  238. bs = batchSectionObj;
  239. if (!this.isDef(this.workBook)) {
  240. this.workBook = sheetCommonObj.buildSheet(
  241. $("#feeItemSpread")[0],
  242. this.setting,
  243. 10
  244. );
  245. this.sheet = this.workBook.getActiveSheet();
  246. sheetCommonObj.bindEscKey(this.workBook, [
  247. {
  248. sheet: this.sheet,
  249. editStarting: me.onEditStarting,
  250. editEnded: me.onEditEnded,
  251. },
  252. ]);
  253. this.setOptions(this.workBook, this.setting.options);
  254. this.sheet.options.clipBoardOptions =
  255. GC.Spread.Sheets.ClipboardPasteOptions.values;
  256. this.bindEvents(this.sheet);
  257. this.rationRepId = parseInt(getQueryString("repository"));
  258. //init combo
  259. this.setCombo(this.sheet, 1, this.setting.comboItems.feeType);
  260. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  261. this.sheet.getRange(-1, 7, -1, 1).cellType(checkBox);
  262. this.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onEditEnded); //复选框点击事件
  263. //init sectionSpread
  264. se.buildSheet();
  265. //init feeRuleSpread
  266. fr.buildSheet();
  267. //init installation
  268. this.getInstallation(this.rationRepId, function (rstData) {
  269. me.cache = rstData;
  270. me.sheet.setRowCount(me.cache.length + 10);
  271. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  272. me.initSelection(me.cache[0]);
  273. });
  274. //init batchSectionSpread
  275. bs.getSectionTree(this.rationRepId);
  276. }
  277. },
  278. bindEvents: function (sheet) {
  279. let me = this;
  280. const Events = GC.Spread.Sheets.Events;
  281. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  282. sheet.bind(Events.EnterCell, me.onEnterCell);
  283. sheet.bind(Events.EditStarting, me.onEditStarting);
  284. sheet.bind(Events.EditEnded, me.onEditEnded);
  285. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  286. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  287. me.feeItemDelOpr();
  288. },
  289. initSelection: function (feeItem) {
  290. let me = this,
  291. se = sectionObj,
  292. fr = feeRuleObj;
  293. sheetCommonObj.cleanSheet(se.sheet, se.setting, -1);
  294. sheetCommonObj.cleanSheet(fr.sheet, fr.setting, -1);
  295. if (!me.isDef(feeItem)) {
  296. me.workBook.focus(true);
  297. me.currentFeeItem = null;
  298. se.cache = [];
  299. return;
  300. }
  301. fr.addObj = null;
  302. fr.updateObj = null;
  303. me.currentFeeItem = feeItem;
  304. se.cache = me.currentFeeItem.section;
  305. se.sheet.setRowCount(se.cache.length + 5);
  306. sheetCommonObj.showData(se.sheet, se.setting, se.cache);
  307. se.initSelection(se.cache[0]);
  308. me.workBook.focus(true);
  309. },
  310. onSelectionChanged: function (sender, info) {
  311. let me = feeItemObj;
  312. if (
  313. !info.oldSelections ||
  314. (info.oldSelections.length === 0 && info.newSelections.length > 0) ||
  315. info.oldSelections[0].row !== info.newSelections[0].row
  316. ) {
  317. let row = info.newSelections[0].row;
  318. let node = me.cache[row];
  319. me.initSelection(node);
  320. }
  321. },
  322. onEnterCell: function (sender, args) {
  323. let me = feeItemObj;
  324. me.sheet.repaint();
  325. },
  326. onEditStarting: function (sender, args) {
  327. let me = feeItemObj;
  328. //费用类型为子目时,记取位置不可编辑
  329. let feeItem = me.cache[args.row];
  330. if (
  331. me.isDef(feeItem) &&
  332. (feeItem.feeType === me.feeType.ZM ||
  333. !me.isDef(feeItem.feeType) ||
  334. feeItem.feeType == "") &&
  335. args.col === 2
  336. ) {
  337. args.cancel = true;
  338. }
  339. },
  340. onEditEnded: function (sender, args) {
  341. debugger;
  342. let me = feeItemObj,
  343. se = sectionObj;
  344. let v = me.isDef(args.editingText)
  345. ? args.editingText.toString().trim()
  346. : "";
  347. let feeItem = me.cache[args.row];
  348. let updateObj = { updateType: "", updateData: {} };
  349. let field = me.setting.header[args.col]["dataCode"];
  350. if (field === "showIn24") {
  351. v = args.sheet.getValue(args.row, args.col) || false;
  352. }
  353. //update
  354. if (me.isDef(feeItem)) {
  355. feeItem[field] = !me.isDef(feeItem[field]) ? "" : feeItem[field];
  356. if (v == feeItem[field]) {
  357. return;
  358. }
  359. let orgV = feeItem[field] || "";
  360. if (field === "reductionRate" || field === "measureRate") {
  361. if (isNaN(v)) {
  362. alert("只能输入数值");
  363. me.sheet.setValue(args.row, args.col, orgV);
  364. return;
  365. }
  366. v = parseFloat(v).toDecimal(2);
  367. me.sheet.setValue(args.row, args.col, v);
  368. }
  369. updateObj.updateType = me.updateType.update;
  370. //当费用类型切换为子目费用时,自动清空记取位置
  371. if (args.col === 1 && v === me.feeType.ZM) {
  372. feeItem.position = "";
  373. args.sheet.setValue(args.row, 2, "");
  374. updateObj.updateData.position = "";
  375. }
  376. feeItem[me.setting.header[args.col]["dataCode"]] = v;
  377. updateObj.updateData.ID = feeItem.ID;
  378. updateObj.updateData[me.setting.header[args.col]["dataCode"]] = v;
  379. }
  380. //insert
  381. else {
  382. if (v === "") {
  383. return;
  384. }
  385. updateObj.updateType = me.updateType.new;
  386. updateObj.updateData[me.setting.header[args.col]["dataCode"]] = v;
  387. updateObj.updateData.rationRepId = me.rationRepId;
  388. updateObj.updateData.ID = uuid.v1();
  389. updateObj.updateData.section = [];
  390. me.cache.push(updateObj.updateData);
  391. me.currentFeeItem = updateObj.updateData;
  392. se.cache = me.currentFeeItem.section;
  393. }
  394. me.sheet.setRowCount(me.cache.length + 10);
  395. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  396. //ajax
  397. me.updateFeeItem([updateObj]);
  398. },
  399. onClipboardPasting: function (sender, info) {
  400. let me = feeItemObj;
  401. if (
  402. info.cellRange.col + info.cellRange.colCount >
  403. me.setting.header.length
  404. ) {
  405. info.cancel = true;
  406. }
  407. },
  408. onClipboardPasted: function (sender, info) {
  409. let me = feeItemObj,
  410. se = sectionObj;
  411. let postData = [];
  412. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  413. for (let i = 0, len = items.length; i < len; i++) {
  414. let row = info.cellRange.row + i;
  415. let feeItem = me.cache[row];
  416. //update
  417. if (me.isDef(feeItem)) {
  418. if (me.validData(items[i])) {
  419. for (let attr in items[i]) {
  420. feeItem[attr] = items[i][attr];
  421. }
  422. postData.push(me.getUpdateObj(me.updateType.update, feeItem));
  423. }
  424. }
  425. //insert
  426. else {
  427. if (me.validData(items[i])) {
  428. items[i].ID = uuid.v1();
  429. items[i].rationRepId = me.rationRepId;
  430. items[i].section = [];
  431. postData.push(me.getUpdateObj(me.updateType.new, items[i]));
  432. me.cache.push(items[i]);
  433. }
  434. }
  435. }
  436. //update currentFeeItem
  437. me.currentFeeItem = me.getCurrentData(me.sheet, me.cache);
  438. se.cache = me.currentFeeItem.section;
  439. me.sheet.setRowCount(me.cache.length + 10);
  440. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  441. if (postData.length > 0) {
  442. //ajax then refresh
  443. me.updateFeeItem(postData);
  444. }
  445. },
  446. feeItemDelOpr: function () {
  447. if (locked) {
  448. return;
  449. }
  450. let me = this;
  451. me.workBook.commandManager().register("feeItemDel", function () {
  452. curDeleteType = me.deleteType;
  453. let sels = me.workBook.getSheet(0).getSelections();
  454. for (let i = 0, len = sels.length; i < len; i++) {
  455. let sel = sels[i];
  456. //delete
  457. if (sel.colCount === me.setting.header.length) {
  458. $("#delAlert").modal("show");
  459. break;
  460. }
  461. }
  462. });
  463. me.workBook
  464. .commandManager()
  465. .setShortcutKey(
  466. null,
  467. GC.Spread.Commands.Key.del,
  468. false,
  469. false,
  470. false,
  471. false
  472. );
  473. me.workBook
  474. .commandManager()
  475. .setShortcutKey(
  476. "feeItemDel",
  477. GC.Spread.Commands.Key.del,
  478. false,
  479. false,
  480. false,
  481. false
  482. );
  483. },
  484. getUpdateObj: function (updateType, data) {
  485. let rst = { updateType: "", updateData: {} };
  486. rst.updateType = updateType;
  487. for (let attr in data) {
  488. rst.updateData[attr] = data[attr];
  489. }
  490. return rst;
  491. },
  492. validData: function (pasteData) {
  493. if (this.isDef(pasteData.feeType)) {
  494. if (this.setting.comboItems.feeType.indexOf(pasteData.feeType) < 0) {
  495. return false;
  496. }
  497. //费用类型为子目时,不可有记取位置
  498. if (
  499. pasteData.feeType === this.feeType.ZM &&
  500. this.isDef(pasteData.position) &&
  501. pasteData.position !== ""
  502. ) {
  503. return false;
  504. }
  505. }
  506. return true;
  507. },
  508. getInstallation: function (rationRepId, callback) {
  509. let me = this;
  510. CommonAjax.post(
  511. "/rationRepository/api/getInstallation",
  512. { rationRepId: rationRepId },
  513. function (rstData) {
  514. // 数据排序 CSL
  515. console.log(rstData);
  516. rstData.sort((a, b) => a.seq - b.seq);
  517. for (const item of rstData) {
  518. const section = item.section;
  519. section.sort((a, b) => a.seq - b.seq);
  520. }
  521. console.log(rstData);
  522. me.cache = rstData;
  523. if (callback) {
  524. callback(rstData);
  525. }
  526. }
  527. );
  528. },
  529. updateFeeItem: function (updateData, callback) {
  530. let me = this;
  531. CommonAjax.post(
  532. "/rationRepository/api/updateFeeItem",
  533. { updateData: updateData },
  534. function (rstData) {
  535. if (callback) {
  536. callback();
  537. }
  538. }
  539. );
  540. },
  541. };
  542. //分册章节
  543. let sectionObj = {
  544. workBook: null,
  545. sheet: null,
  546. cache: [],
  547. currentSection: null,
  548. updateType: { update: "update", new: "new", del: "delete" },
  549. deleteType: "section",
  550. setting: {
  551. header: [
  552. {
  553. headerName: "分册章节",
  554. headerWidth: 330,
  555. dataCode: "name",
  556. dataType: "String",
  557. formatter: "@",
  558. hAlign: "left",
  559. vAlign: "center",
  560. },
  561. {
  562. headerName: "序号",
  563. headerWidth: 50,
  564. dataCode: "seq",
  565. dataType: "Number",
  566. hAlign: "center",
  567. vAlign: "center",
  568. },
  569. ],
  570. view: { lockColumns: [] },
  571. options: {
  572. tabStripVisible: false,
  573. allowCopyPasteExcelStyle: false,
  574. allowExtendPasteRange: true,
  575. allowUserDragDrop: false,
  576. allowUserDragFill: false,
  577. scrollbarMaxAlign: true,
  578. },
  579. },
  580. isDef: function (v) {
  581. return v !== undefined && v !== null;
  582. },
  583. //sheet things
  584. setOptions: function (workbook, opts) {
  585. for (let opt in opts) {
  586. workbook.options[opt] = opts[opt];
  587. }
  588. },
  589. renderFunc: function (sheet, func) {
  590. sheet.suspendPaint();
  591. sheet.suspendEvent();
  592. if (this.isFunc(func)) {
  593. func();
  594. }
  595. sheet.resumePaint();
  596. sheet.resumeEvent();
  597. },
  598. buildSheet: function () {
  599. if (!this.isDef(this.workBook)) {
  600. this.workBook = sheetCommonObj.buildSheet(
  601. $("#instSectionSpread")[0],
  602. this.setting,
  603. 10
  604. );
  605. this.sheet = this.workBook.getActiveSheet();
  606. sheetCommonObj.bindEscKey(this.workBook, [
  607. {
  608. sheet: this.sheet,
  609. editStarting: this.onEditStarting,
  610. editEnded: this.onEditEnded,
  611. },
  612. ]);
  613. this.setOptions(this.workBook, this.setting.options);
  614. this.sheet.options.clipBoardOptions =
  615. GC.Spread.Sheets.ClipboardPasteOptions.values;
  616. this.bindEvents(this.sheet);
  617. }
  618. },
  619. bindEvents: function (sheet) {
  620. let me = sectionObj;
  621. const Events = GC.Spread.Sheets.Events;
  622. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  623. sheet.bind(Events.EditStarting, me.onEditStarting);
  624. sheet.bind(Events.EditEnded, me.onEditEnded);
  625. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  626. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  627. me.sectionDelOpr();
  628. me.onContextmenuOpr();
  629. },
  630. initSelection: function (section) {
  631. let me = sectionObj,
  632. fr = feeRuleObj;
  633. sheetCommonObj.cleanSheet(fr.sheet, fr.setting, -1);
  634. this.workBook.focus(true);
  635. if (!this.isDef(section)) {
  636. me.currentSection = null;
  637. return;
  638. }
  639. me.currentSection = section;
  640. fr.addObj = null;
  641. fr.updateObj = null;
  642. fr.cache = section.feeRule;
  643. fr.sheet.setRowCount(fr.cache.length + 5);
  644. sheetCommonObj.showData(fr.sheet, fr.setting, fr.cache);
  645. },
  646. onContextmenuOpr: function () {
  647. let me = this;
  648. $.contextMenu({
  649. selector: "#instSectionSpread",
  650. build: function ($triggerElement, e) {
  651. //控制允许右键菜单在哪个位置出现
  652. let sheet = me.sheet;
  653. let offset = $("#instSectionSpread").offset(),
  654. x = e.pageX - offset.left,
  655. y = e.pageY - offset.top;
  656. let target = sheet.hitTest(x, y);
  657. if (
  658. target.hitTestType === 3 &&
  659. me.isDef(target.row) &&
  660. me.isDef(target.col)
  661. ) {
  662. //在表格内
  663. sheet.setActiveCell(target.row, target.col);
  664. me.initSelection(me.cache[target.row]);
  665. return {
  666. callback: function () {},
  667. items: {
  668. ref: {
  669. name: "批量关联至定额",
  670. disabled: function () {
  671. const inValidCell =
  672. !commonUtil.isDef(target.row) ||
  673. !commonUtil.isDef(target.col);
  674. const inValidData = target.row >= me.cache.length;
  675. return locked || inValidCell || inValidData;
  676. },
  677. icon: "fa-arrow-left",
  678. callback: function (key, opt) {
  679. $("#sectionTreeModal").modal("show");
  680. },
  681. },
  682. del: {
  683. name: "删除章节",
  684. disabled: function () {
  685. const inValidCell =
  686. !commonUtil.isDef(target.row) ||
  687. !commonUtil.isDef(target.col);
  688. const inValidData = target.row >= me.cache.length;
  689. return locked || inValidCell || inValidData;
  690. },
  691. icon: "fa-times",
  692. callback: function (key, opt) {
  693. curDeleteType = me.deleteType;
  694. $("#delAlert").modal("show");
  695. },
  696. },
  697. },
  698. };
  699. } else {
  700. return false;
  701. }
  702. },
  703. });
  704. },
  705. onSelectionChanged: function (sender, info) {
  706. let me = sectionObj;
  707. if (
  708. (info.oldSelections &&
  709. info.oldSelections.length === 0 &&
  710. info.newSelections.length > 0) ||
  711. info.oldSelections[0].row !== info.newSelections[0].row
  712. ) {
  713. let row = info.newSelections[0].row;
  714. let section = me.cache[row];
  715. me.initSelection(section);
  716. }
  717. },
  718. onEditStarting: function (sender, args) {
  719. let me = sectionObj,
  720. fi = feeItemObj;
  721. if (!me.isDef(fi.currentFeeItem)) {
  722. args.cancel = true;
  723. }
  724. },
  725. onEditEnded: function (sender, args) {
  726. let me = sectionObj,
  727. fi = feeItemObj,
  728. fr = feeRuleObj;
  729. let v = me.isDef(args.editingText)
  730. ? args.editingText.toString().trim()
  731. : "";
  732. let section = me.cache[args.row];
  733. let updateObj = { updateType: "", updateData: {} };
  734. //update
  735. if (me.isDef(section)) {
  736. debugger;
  737. updateObj.updateType = me.updateType.update;
  738. updateObj.updateData.ID = section.ID;
  739. if (args.col === 0) {
  740. section.name = !me.isDef(section.name) ? "" : section.name;
  741. if (section.name === v) {
  742. return;
  743. }
  744. if (v === "") {
  745. me.sheet.setValue(args.row, args.col, section.name);
  746. return;
  747. }
  748. section.name = v;
  749. updateObj.updateData.name = v;
  750. } else if (args.col === 1) {
  751. section.seq = !me.isDef(section.seq) ? "" : section.seq;
  752. if (section.seq === v) {
  753. return;
  754. }
  755. if (v === "") {
  756. me.sheet.setValue(args.row, args.col, section.seq);
  757. return;
  758. }
  759. section.seq = v;
  760. updateObj.updateData.seq = v;
  761. }
  762. }
  763. //insert
  764. else {
  765. if (v === "") {
  766. return;
  767. }
  768. updateObj.updateType = me.updateType.new;
  769. updateObj.updateData.ID = uuid.v1();
  770. updateObj.updateData.rationRepId = fi.rationRepId;
  771. updateObj.updateData.name = v;
  772. updateObj.updateData.feeItemId = fi.currentFeeItem.ID;
  773. updateObj.updateData.feeRule = [];
  774. me.cache.push(updateObj.updateData);
  775. me.currentSection = updateObj.updateData;
  776. fr.cache = me.currentSection.feeRule;
  777. }
  778. me.sheet.setRowCount(me.cache.length + 5);
  779. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  780. me.updateSection([updateObj]);
  781. fi.updateFeeItem([
  782. {
  783. updateType: fi.updateType.update,
  784. updateData: {
  785. ID: fi.currentFeeItem.ID,
  786. $addToSet: { section: { ID: updateObj.updateData.ID } },
  787. },
  788. },
  789. ]);
  790. },
  791. onClipboardPasting: function (sender, info) {
  792. let me = sectionObj,
  793. fi = feeItemObj;
  794. if (
  795. info.cellRange.col + info.cellRange.colCount > me.setting.header.length ||
  796. !me.isDef(fi.currentFeeItem)
  797. ) {
  798. info.cancel = true;
  799. }
  800. },
  801. onClipboardPasted: function (sender, info) {
  802. let me = sectionObj,
  803. fi = feeItemObj,
  804. fr = feeRuleObj;
  805. let sePostData = [],
  806. fiPostData = [];
  807. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  808. for (let i = 0, len = items.length; i < len; i++) {
  809. let row = info.cellRange.row + i;
  810. let section = me.cache[row];
  811. //update
  812. if (me.isDef(section)) {
  813. section.name = items[i].name;
  814. let updateObj = {
  815. updateType: me.updateType.update,
  816. updateData: { ID: section.ID, name: items[i].name },
  817. };
  818. sePostData.push(updateObj);
  819. }
  820. //insert
  821. else {
  822. let updateObj = {
  823. updateType: me.updateType.new,
  824. updateData: {
  825. ID: uuid.v1(),
  826. rationRepId: fi.rationRepId,
  827. name: items[i].name,
  828. feeItemId: fi.currentFeeItem.ID,
  829. feeRule: [],
  830. },
  831. };
  832. sePostData.push(updateObj);
  833. me.cache.push(updateObj.updateData);
  834. fiPostData.push({
  835. updateType: fi.updateType.update,
  836. updateData: {
  837. ID: fi.currentFeeItem.ID,
  838. $addToSet: { section: { ID: updateObj.updateData.ID } },
  839. },
  840. });
  841. }
  842. }
  843. //update currentSection
  844. me.currentSection = fi.getCurrentData(me.sheet, me.cache);
  845. fr.cache = me.currentSection.feeRule;
  846. me.sheet.setRowCount(me.cache.length + 5);
  847. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  848. if (sePostData.length > 0) {
  849. me.updateSection(sePostData);
  850. if (fiPostData.length > 0) {
  851. fi.updateFeeItem(fiPostData);
  852. }
  853. }
  854. },
  855. sectionDelOpr: function () {
  856. if (locked) {
  857. return;
  858. }
  859. let me = this;
  860. me.workBook.commandManager().register("sectionDel", function () {
  861. curDeleteType = me.deleteType;
  862. let sels = me.workBook.getSheet(0).getSelections();
  863. for (let i = 0, len = sels.length; i < len; i++) {
  864. let sel = sels[i];
  865. //delete
  866. if (sel.colCount === me.setting.header.length) {
  867. $("#delAlert").modal("show");
  868. break;
  869. }
  870. }
  871. });
  872. me.workBook
  873. .commandManager()
  874. .setShortcutKey(
  875. null,
  876. GC.Spread.Commands.Key.del,
  877. false,
  878. false,
  879. false,
  880. false
  881. );
  882. me.workBook
  883. .commandManager()
  884. .setShortcutKey(
  885. "sectionDel",
  886. GC.Spread.Commands.Key.del,
  887. false,
  888. false,
  889. false,
  890. false
  891. );
  892. },
  893. updateSection: function (updateData, callback) {
  894. CommonAjax.post(
  895. "/rationRepository/api/updateSection",
  896. { updateData: updateData, libID: feeItemObj.rationRepId },
  897. function (rstData) {
  898. if (callback) {
  899. callback();
  900. }
  901. }
  902. );
  903. },
  904. };
  905. //费用规则
  906. let feeRuleObj = {
  907. workBook: null,
  908. sheet: null,
  909. addObj: null,
  910. updateObj: null,
  911. avtiveCell: { row: 0, col: 0 },
  912. cache: [],
  913. base: { RCJ: "分别按人材机乘系数", RG: "人工", CL: "材料", JX: "机械" },
  914. setting: {
  915. header: [
  916. {
  917. headerName: "编码",
  918. headerWidth: 80,
  919. dataCode: "code",
  920. dataType: "String",
  921. formatter: "@",
  922. hAlign: "left",
  923. vAlign: "center",
  924. span: { row: 0, rowCount: 2, colCount: 1 },
  925. },
  926. {
  927. headerName: "费用规则",
  928. headerWidth: 280,
  929. dataCode: "rule",
  930. dataType: "String",
  931. formatter: "@",
  932. hAlign: "left",
  933. vAlign: "center",
  934. span: { row: 0, rowCount: 2, colCount: 1 },
  935. },
  936. {
  937. headerName: "基数",
  938. headerWidth: 140,
  939. dataCode: "base",
  940. dataType: "String",
  941. formatter: "@",
  942. hAlign: "left",
  943. vAlign: "center",
  944. span: { row: 0, rowCount: 2, colCount: 1 },
  945. },
  946. {
  947. headerName: "费率(%)",
  948. headerWidth: 70,
  949. dataCode: "feeRate",
  950. dataType: "String",
  951. formatter: "@",
  952. hAlign: "center",
  953. vAlign: "center",
  954. span: { row: 0, rowCount: 2, colCount: 1 },
  955. },
  956. {
  957. headerName: "人工(%)",
  958. headerWidth: 70,
  959. dataCode: "labour",
  960. dataType: "String",
  961. formatter: "@",
  962. hAlign: "center",
  963. vAlign: "center",
  964. span: { row: 1, rowCount: 1, colCount: 1 },
  965. },
  966. {
  967. headerName: "材料(%)",
  968. headerWidth: 70,
  969. dataCode: "material",
  970. dataType: "String",
  971. formatter: "@",
  972. hAlign: "center",
  973. vAlign: "center",
  974. span: { row: 1, rowCount: 1, colCount: 1 },
  975. },
  976. {
  977. headerName: "机械(%)",
  978. headerWidth: 70,
  979. dataCode: "machine",
  980. dataType: "String",
  981. formatter: "@",
  982. hAlign: "center",
  983. vAlign: "center",
  984. span: { row: 1, rowCount: 1, colCount: 1 },
  985. },
  986. ],
  987. view: { lockColumns: [] },
  988. comboItems: { base: ["分别按人材机乘系数", "人工", "材料", "机械"] },
  989. options: {
  990. tabStripVisible: false,
  991. allowCopyPasteExcelStyle: false,
  992. allowExtendPasteRange: true,
  993. allowUserDragDrop: false,
  994. allowUserDragFill: false,
  995. scrollbarMaxAlign: true,
  996. },
  997. },
  998. isDef: function (v) {
  999. return v !== undefined && v !== null;
  1000. },
  1001. //sheet things
  1002. setOptions: function (workbook, opts) {
  1003. for (let opt in opts) {
  1004. workbook.options[opt] = opts[opt];
  1005. }
  1006. },
  1007. buildHeader: function () {
  1008. if (!this.sheet) {
  1009. return;
  1010. }
  1011. this.sheet.suspendPaint();
  1012. this.sheet.suspendEvent();
  1013. let ch = GC.Spread.Sheets.SheetArea.colHeader;
  1014. this.sheet.setRowCount(2, ch);
  1015. for (let i = 0; i < this.setting.header.length; i++) {
  1016. let header = this.setting.header[i];
  1017. this.sheet.addSpan(
  1018. header.span.row,
  1019. i,
  1020. header.span.rowCount,
  1021. header.span.colCount,
  1022. ch
  1023. );
  1024. this.sheet.setValue(header.span.row, i, header.headerName, ch);
  1025. if (header.dataCode === "feeRate") {
  1026. this.sheet.addSpan(header.span.row, i + 1, 1, 3, ch);
  1027. this.sheet.setValue(header.span.row, i + 1, "其中", ch);
  1028. }
  1029. }
  1030. this.sheet.resumePaint();
  1031. this.sheet.resumeEvent();
  1032. },
  1033. buildSheet: function () {
  1034. let fi = feeItemObj;
  1035. if (!this.isDef(this.workBook)) {
  1036. this.workBook = sheetCommonObj.buildSheet(
  1037. $("#instFeeRuleSpread")[0],
  1038. this.setting,
  1039. 10
  1040. );
  1041. this.sheet = this.workBook.getActiveSheet();
  1042. this.buildHeader();
  1043. this.sheet.setRowCount();
  1044. this.sheet.options.allowCellOverflow = false;
  1045. sheetCommonObj.bindEscKey(this.workBook, [
  1046. {
  1047. sheet: this.sheet,
  1048. editStarting: this.onEditStarting,
  1049. editEnded: this.onEditEnded,
  1050. },
  1051. ]);
  1052. this.setOptions(this.workBook, this.setting.options);
  1053. this.sheet.options.clipBoardOptions =
  1054. GC.Spread.Sheets.ClipboardPasteOptions.values;
  1055. this.bindEvents(this.sheet);
  1056. //init combo
  1057. fi.setCombo(this.sheet, 2, this.setting.comboItems.base);
  1058. }
  1059. },
  1060. bindEvents: function (sheet) {
  1061. let me = feeRuleObj;
  1062. const Events = GC.Spread.Sheets.Events;
  1063. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  1064. sheet.bind(Events.EnterCell, me.onEnterCell);
  1065. sheet.bind(Events.EditStarting, me.onEditStarting);
  1066. sheet.bind(Events.EditEnded, me.onEditEnded);
  1067. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  1068. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  1069. me.feeRuleDelOpr();
  1070. },
  1071. canSave: function (addObj) {
  1072. return (
  1073. this.isDef(addObj.code) &&
  1074. addObj.code !== "" &&
  1075. !this.hasCode(addObj) &&
  1076. this.validRCJ(addObj)
  1077. );
  1078. },
  1079. hasCode: function (obj) {
  1080. let fi = feeItemObj;
  1081. for (let feeItem of fi.cache) {
  1082. for (let section of feeItem.section) {
  1083. for (let feeRule of section.feeRule) {
  1084. if (
  1085. obj.code == feeRule.code &&
  1086. ((this.isDef(obj.ID) && obj.ID !== feeRule.ID) ||
  1087. !this.isDef(obj.ID))
  1088. ) {
  1089. return true;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. return false;
  1095. },
  1096. //费用类型为人、材、机时人材机总和一定要为100
  1097. validRCJ: function (feeRule) {
  1098. if (!this.isDef(feeRule.base) || feeRule.base === this.base.RCJ) {
  1099. return true;
  1100. }
  1101. let sum = 0;
  1102. if (this.isDef(feeRule.labour)) {
  1103. sum = parseFloat(sum + feeRule.labour).toDecimal(2);
  1104. }
  1105. if (this.isDef(feeRule.material)) {
  1106. sum = parseFloat(sum + feeRule.material).toDecimal(2);
  1107. }
  1108. if (this.isDef(feeRule.machine)) {
  1109. sum = parseFloat(sum + feeRule.machine).toDecimal(2);
  1110. }
  1111. return sum == 100;
  1112. },
  1113. validPasteData: function (data) {
  1114. //插入须有编码
  1115. if (!this.isDef(data.code)) {
  1116. alert("粘贴时,编码不能为空,或者粘贴的数据中需包含编码");
  1117. return false;
  1118. }
  1119. //编码须唯一
  1120. if (this.isDef(data.code) && this.hasCode(data)) {
  1121. alert("编码须唯一!");
  1122. return false;
  1123. }
  1124. //基数要合法
  1125. if (
  1126. this.isDef(data.base) &&
  1127. this.setting.comboItems.base.indexOf(data.base) < 0
  1128. ) {
  1129. alert("基数不正确!");
  1130. return false;
  1131. }
  1132. //费率、人工、材料、机械,须数字
  1133. if (this.isDef(data.feeRate) && isNaN(data.feeRate)) {
  1134. alert("费率须为数字!");
  1135. return false;
  1136. }
  1137. if (this.isDef(data.labour) && isNaN(data.labour)) {
  1138. alert("人工须为数字!");
  1139. return false;
  1140. }
  1141. if (this.isDef(data.material) && isNaN(data.material)) {
  1142. alert("材料须为数字!");
  1143. return false;
  1144. }
  1145. if (this.isDef(data.machine) && isNaN(data.machine)) {
  1146. alert("机械须为数字!");
  1147. return false;
  1148. }
  1149. //基数为分别按人材机时,费率须为空
  1150. if (
  1151. this.isDef(data.base) &&
  1152. data.base === this.base.RCJ &&
  1153. this.isDef(data.feeRate) &&
  1154. data.feeRate !== ""
  1155. ) {
  1156. alert("基数为分别按人材机时,费率须为空!");
  1157. return false;
  1158. }
  1159. //基数为 人工、材料、机械时 三者之和须为100
  1160. if (
  1161. this.isDef(data.base) &&
  1162. data.base !== this.base.RCJ &&
  1163. this.validRCJ(data)
  1164. ) {
  1165. alert("基数为 人工、材料、机械时 三者之和须为100");
  1166. return false;
  1167. }
  1168. return true;
  1169. },
  1170. decimalPasteData: function (data) {
  1171. if (this.isDef(data.feeRate) && isNaN(data.feeRate)) {
  1172. data.feeRate = parseFloat(data.feeRate).toDecimal(2);
  1173. }
  1174. if (this.isDef(data.labour) && isNaN(data.labour)) {
  1175. data.labour = parseFloat(data.labour).toDecimal(2);
  1176. }
  1177. if (this.isDef(data.material) && isNaN(data.material)) {
  1178. data.material = parseFloat(data.material).toDecimal(2);
  1179. }
  1180. if (this.isDef(data.machine) && isNaN(data.machine)) {
  1181. data.machine = parseFloat(data.machine).toDecimal(2);
  1182. }
  1183. },
  1184. getFocusToCol: function (feeRule) {
  1185. if (
  1186. !this.isDef(feeRule.labour) ||
  1187. feeRule.labour === "" ||
  1188. feeRule.labour > 100 ||
  1189. feeRule.labour == 0
  1190. ) {
  1191. return 4;
  1192. }
  1193. if (
  1194. !this.isDef(feeRule.material) ||
  1195. feeRule.material === "" ||
  1196. feeRule.material > 100 ||
  1197. feeRule.material == 0
  1198. ) {
  1199. return 5;
  1200. }
  1201. if (
  1202. !this.isDef(feeRule.machine) ||
  1203. feeRule.machine === "" ||
  1204. feeRule.machine > 100 ||
  1205. feeRule.machine == 0
  1206. ) {
  1207. return 6;
  1208. }
  1209. return 4;
  1210. },
  1211. onSelectionChanged: function (sender, info) {
  1212. let me = feeRuleObj,
  1213. se = sectionObj;
  1214. if (
  1215. (info.oldSelections &&
  1216. info.oldSelections.length === 0 &&
  1217. info.newSelections.length > 0) ||
  1218. info.oldSelections[0].row !== info.newSelections[0].row
  1219. ) {
  1220. if (me.isDef(me.updateObj) && !me.validRCJ(me.updateObj)) {
  1221. $("#rcjAlert").modal("show");
  1222. $("#aleCanceBtn").bind("click", function () {
  1223. me.updateObj.base = me.base.RCJ;
  1224. me.updateObj.labour = 0;
  1225. me.updateObj.material = 0;
  1226. me.updateObj.machine = 0;
  1227. me.sheet.setRowCount(me.cache.length + 5);
  1228. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1229. se.updateSection([
  1230. { updateType: se.updateType.update, updateData: se.currentSection },
  1231. ]);
  1232. $(this).unbind();
  1233. });
  1234. $("#aleConfBtn").bind("click", function () {
  1235. me.sheet.setActiveCell(
  1236. me.avtiveCell.row,
  1237. me.getFocusToCol(me.updateObj)
  1238. );
  1239. $(this).unbind();
  1240. });
  1241. }
  1242. if (me.isDef(me.addObj)) {
  1243. if (!me.isDef(me.addObj.code) || me.addObj.code === "") {
  1244. $("#alertText").text("请输入编码");
  1245. $("#codeAlert").modal("show");
  1246. $("#codAleClose").click(function () {
  1247. me.addObj.code = "";
  1248. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  1249. $(this).unbind();
  1250. });
  1251. $("#codAlertQR").click(function () {
  1252. me.addObj.code = "";
  1253. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  1254. $(this).unbind();
  1255. });
  1256. //取消插入
  1257. $("#codAlertQX").click(function () {
  1258. me.addObj = null;
  1259. me.sheet.setRowCount(me.cache.length + 5);
  1260. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1261. $(this).unbind();
  1262. });
  1263. } else if (me.isDef(me.addObj.code) && me.hasCode(me.addObj)) {
  1264. $("#alertText").text("输入的编号已存在,请重新输入");
  1265. $("#codeAlert").modal("show");
  1266. $("#codAleClose").click(function () {
  1267. me.addObj.code = "";
  1268. me.sheet.setValue(me.avtiveCell.row, 0, "");
  1269. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  1270. $(this).unbind();
  1271. });
  1272. $("#codAlertQR").click(function () {
  1273. me.addObj.code = "";
  1274. me.sheet.setValue(me.avtiveCell.row, 0, "");
  1275. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  1276. $(this).unbind();
  1277. });
  1278. //取消插入
  1279. $("#codAlertQX").click(function () {
  1280. me.addObj = null;
  1281. me.sheet.setRowCount(me.cache.length + 5);
  1282. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1283. $(this).unbind();
  1284. });
  1285. } else if (!me.validRCJ(me.addObj)) {
  1286. $("#rcjAlert").modal("show");
  1287. $("#aleCanceBtn").bind("click", function () {
  1288. me.addObj = null;
  1289. me.sheet.setRowCount(me.cache.length + 5);
  1290. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1291. $(this).unbind();
  1292. });
  1293. $("#aleConfBtn").bind("click", function () {
  1294. me.sheet.setActiveCell(
  1295. me.avtiveCell.row,
  1296. me.getFocusToCol(me.addObj)
  1297. );
  1298. $(this).unbind();
  1299. });
  1300. }
  1301. }
  1302. }
  1303. },
  1304. onEnterCell: function (sender, args) {
  1305. let me = feeRuleObj;
  1306. me.sheet.repaint();
  1307. },
  1308. onEditStarting: function (sender, args) {
  1309. let me = feeRuleObj,
  1310. se = sectionObj;
  1311. let feeRule = me.cache[args.row];
  1312. let rcjCols = [4, 5, 6];
  1313. if (!me.isDef(se.currentSection)) {
  1314. args.cancel = true;
  1315. }
  1316. if (
  1317. me.isDef(feeRule) &&
  1318. me.isDef(feeRule.base) &&
  1319. feeRule.base === me.base.RCJ &&
  1320. args.col === 3
  1321. ) {
  1322. args.cancel = true;
  1323. } else if (!me.isDef(feeRule) && rcjCols.indexOf(args.col) > 0) {
  1324. args.cancel = true;
  1325. }
  1326. },
  1327. onEditEnded: function (sender, args) {
  1328. let me = feeRuleObj,
  1329. se = sectionObj;
  1330. let v = me.isDef(args.editingText)
  1331. ? args.editingText.toString().trim()
  1332. : "";
  1333. let updateObj = { updateType: "", updateData: {} };
  1334. let feeRule = me.cache[args.row];
  1335. let field = me.setting.header[args.col]["dataCode"];
  1336. let orgV =
  1337. me.isDef(feeRule) && me.isDef(feeRule[field]) ? feeRule[field] : "";
  1338. me.updateObj = feeRule;
  1339. me.avtiveCell.row = args.row;
  1340. me.avtiveCell.col = args.col;
  1341. //update
  1342. if (me.isDef(feeRule)) {
  1343. feeRule[field] = me.isDef(feeRule[field]) ? feeRule[field] : "";
  1344. if (v === feeRule[field]) {
  1345. return;
  1346. }
  1347. if (field === "base" && v === me.base.RCJ) {
  1348. //基数为人材机时,费率清空
  1349. feeRule.feeRate = "";
  1350. me.sheet.setValue(args.row, 3, "");
  1351. } else if (
  1352. field === "base" &&
  1353. (v === me.base.RG || v === me.base.CL || v === me.base.JX)
  1354. ) {
  1355. if (!me.validRCJ(feeRule)) {
  1356. //基数变为人工、材料、机械时,若人材机之和不为100,则清空
  1357. feeRule.labour = 0;
  1358. feeRule.material = 0;
  1359. feeRule.machine = 0;
  1360. }
  1361. } else if (
  1362. field === "labour" ||
  1363. field === "material" ||
  1364. field === "machine" ||
  1365. field === "feeRate"
  1366. ) {
  1367. if (isNaN(v)) {
  1368. alert("只能输入数值");
  1369. me.sheet.setValue(args.row, args.col, orgV);
  1370. return;
  1371. }
  1372. v = parseFloat(v).toDecimal(2);
  1373. me.sheet.setValue(args.row, args.col, v);
  1374. }
  1375. feeRule[field] = v;
  1376. //编码重复,不可更新
  1377. if (field === "code") {
  1378. if (v == "") {
  1379. me.sheet.setValue(args.row, args.col, orgV);
  1380. return;
  1381. feeRule[field] = orgV;
  1382. }
  1383. if (me.hasCode(feeRule)) {
  1384. $("#codeAlert").modal("show");
  1385. $("#codAleClose").bind("click", function () {
  1386. me.sheet.setActiveCell(args.row, 0);
  1387. me.sheet.setValue(args.row, args.col, orgV);
  1388. });
  1389. $("#codAlertQR").bind("click", function () {
  1390. me.sheet.setActiveCell(args.row, 0);
  1391. me.sheet.setValue(args.row, args.col, orgV);
  1392. });
  1393. feeRule[field] = orgV;
  1394. return;
  1395. }
  1396. }
  1397. //是否能更新
  1398. //人材机之和不为100,不解决之和为100取消操作的话,则基数自动换成分别按人材机
  1399. if (!me.validRCJ(feeRule)) {
  1400. return;
  1401. }
  1402. updateObj.updateType = se.updateType.update;
  1403. updateObj.updateData.ID = se.currentSection.ID;
  1404. updateObj.updateData.feeRule = me.cache;
  1405. me.updateObj = null;
  1406. se.updateSection([
  1407. { updateType: se.updateType.update, updateData: se.currentSection },
  1408. ]);
  1409. }
  1410. //insert
  1411. else {
  1412. if (v === "") {
  1413. return;
  1414. }
  1415. if (!me.isDef(me.addObj)) {
  1416. me.addObj = Object.create(null);
  1417. }
  1418. me.addObj[me.setting.header[args.col]["dataCode"]] = v;
  1419. if (me.canSave(me.addObj)) {
  1420. me.addObj.ID = uuid.v1();
  1421. me.cache.push(me.addObj);
  1422. updateObj.updateType = se.updateType.update;
  1423. updateObj.updateData.ID = se.currentSection.ID;
  1424. updateObj.updateData.feeRule = me.cache;
  1425. me.sheet.setRowCount(me.cache.length + 5);
  1426. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1427. se.updateSection([
  1428. { updateType: se.updateType.update, updateData: se.currentSection },
  1429. ]);
  1430. me.addObj = null;
  1431. }
  1432. }
  1433. },
  1434. onClipboardPasting: function (sender, info) {
  1435. let me = feeRuleObj,
  1436. se = sectionObj;
  1437. if (
  1438. info.cellRange.col + info.cellRange.colCount >
  1439. me.setting.header.length
  1440. ) {
  1441. info.cancel = true;
  1442. }
  1443. if (!me.isDef(se.currentSection)) {
  1444. info.cancel = true;
  1445. }
  1446. },
  1447. onClipboardPasted: function (sender, info) {
  1448. let me = feeRuleObj,
  1449. se = sectionObj,
  1450. fi = feeItemObj;
  1451. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  1452. me.toUpdate = false;
  1453. for (let i = 0, len = items.length; i < len; i++) {
  1454. let row = info.cellRange.row + i;
  1455. let feeRule = me.cache[row];
  1456. //update
  1457. if (me.isDef(feeRule)) {
  1458. let tempObj = {};
  1459. for (let attr in feeRule) {
  1460. tempObj[attr] = feeRule[attr];
  1461. }
  1462. for (let attr in items[i]) {
  1463. tempObj[attr] = items[i][attr];
  1464. }
  1465. if (me.validPasteData(tempObj)) {
  1466. me.decimalPasteData(tempObj);
  1467. //front
  1468. me.cache[row] = tempObj;
  1469. me.toUpdate = true;
  1470. }
  1471. } else {
  1472. // //insert
  1473. if (me.validPasteData(items[i])) {
  1474. me.decimalPasteData(items[i]);
  1475. items[i].ID = uuid.v1();
  1476. //front
  1477. me.cache.push(items[i]);
  1478. me.toUpdate = true;
  1479. }
  1480. }
  1481. }
  1482. me.sheet.setRowCount(me.cache.length + 5);
  1483. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1484. if (me.toUpdate) {
  1485. se.updateSection([
  1486. { updateType: se.updateType.update, updateData: se.currentSection },
  1487. ]);
  1488. }
  1489. },
  1490. feeRuleDelOpr: function () {
  1491. if (locked) {
  1492. return;
  1493. }
  1494. let me = feeRuleObj,
  1495. se = sectionObj;
  1496. me.workBook.commandManager().register("feeRuleDel", function () {
  1497. me.toUpdate = false;
  1498. let sels = me.workBook.getSheet(0).getSelections();
  1499. for (let i = 0, len = sels.length; i < len; i++) {
  1500. let sel = sels[i];
  1501. //delete
  1502. if (sel.colCount === me.setting.header.length) {
  1503. for (let j = 0, jLen = sel.rowCount; j < jLen; j++) {
  1504. let row = sel.row + j;
  1505. let feeRule = me.cache[row];
  1506. //有数据,删除数据
  1507. if (me.isDef(feeRule)) {
  1508. me.toUpdate = true;
  1509. }
  1510. }
  1511. //front delete
  1512. me.cache.splice(sel.row, sel.rowCount);
  1513. }
  1514. }
  1515. if (me.toUpdate) {
  1516. se.updateSection(
  1517. [{ updateType: se.updateType.update, updateData: se.currentSection }],
  1518. function () {
  1519. me.sheet.setRowCount(me.cache.length + 5);
  1520. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1521. }
  1522. );
  1523. }
  1524. });
  1525. me.workBook
  1526. .commandManager()
  1527. .setShortcutKey(
  1528. null,
  1529. GC.Spread.Commands.Key.del,
  1530. false,
  1531. false,
  1532. false,
  1533. false
  1534. );
  1535. me.workBook
  1536. .commandManager()
  1537. .setShortcutKey(
  1538. "feeRuleDel",
  1539. GC.Spread.Commands.Key.del,
  1540. false,
  1541. false,
  1542. false,
  1543. false
  1544. );
  1545. },
  1546. };
  1547. let batchSectionObj = {
  1548. cache: null,
  1549. tree: null,
  1550. controller: null,
  1551. workBook: null,
  1552. sheet: null,
  1553. IDRowMapping: null, //树节点ID与行号映射
  1554. setting: {
  1555. sheet: {
  1556. cols: [
  1557. {
  1558. head: {
  1559. titleNames: ["选择"],
  1560. spanCols: [1],
  1561. spanRows: [2],
  1562. vAlign: [1, 1],
  1563. hAlign: [1, 1],
  1564. font: "Arial",
  1565. },
  1566. data: {
  1567. field: "select",
  1568. vAlign: 1,
  1569. hAlign: 0,
  1570. font: "Arial",
  1571. },
  1572. width: 50,
  1573. },
  1574. {
  1575. head: {
  1576. titleNames: ["名称"],
  1577. spanCols: [1],
  1578. spanRows: [2],
  1579. vAlign: [1, 1],
  1580. hAlign: [1, 1],
  1581. font: "Arial",
  1582. },
  1583. data: {
  1584. field: "name",
  1585. vAlign: 1,
  1586. hAlign: 0,
  1587. font: "Arial",
  1588. },
  1589. width: 400,
  1590. },
  1591. ],
  1592. headRows: 1,
  1593. headRowHeight: [47],
  1594. emptyRows: 0,
  1595. treeCol: 1,
  1596. },
  1597. tree: {
  1598. id: "ID",
  1599. pid: "ParentID",
  1600. nid: "NextSiblingID",
  1601. rootId: -1,
  1602. },
  1603. options: {
  1604. tabStripVisible: false,
  1605. allowCopyPasteExcelStyle: false,
  1606. allowExtendPasteRange: true,
  1607. allowUserDragDrop: false,
  1608. allowUserDragFill: false,
  1609. scrollbarMaxAlign: true,
  1610. },
  1611. },
  1612. isDef: function (v) {
  1613. return v !== undefined && v !== null;
  1614. },
  1615. renderFunc: function (sheet, func) {
  1616. sheet.suspendPaint();
  1617. sheet.suspendEvent();
  1618. if (func) {
  1619. func();
  1620. }
  1621. sheet.resumePaint();
  1622. sheet.resumeEvent();
  1623. },
  1624. setOptions: function (workbook, opts) {
  1625. for (let opt in opts) {
  1626. workbook.options[opt] = opts[opt];
  1627. }
  1628. },
  1629. buildSheet: function () {
  1630. if (!this.isDef(this.workBook)) {
  1631. this.workBook = new GC.Spread.Sheets.Workbook(
  1632. $("#batchSectionSpread")[0],
  1633. { sheetCount: 1 }
  1634. );
  1635. this.sheet = this.workBook.getActiveSheet();
  1636. this.setOptions(this.workBook, this.setting.options);
  1637. this.bindEvents(this.sheet);
  1638. }
  1639. },
  1640. bindEvents: function (sheet) {
  1641. let me = this;
  1642. const Events = GC.Spread.Sheets.Events;
  1643. sheet.bind(Events.EditStarting, me.onEditStarting);
  1644. sheet.bind(Events.EditEnded, me.onEditEnded);
  1645. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  1646. me.workBook.bind(Events.ButtonClicked, me.onButtonClicked); //复选框点击事件
  1647. },
  1648. getSectionTree: function (repId) {
  1649. let me = this;
  1650. let url = "api/getRationTree";
  1651. let postData = { rationLibId: repId };
  1652. let sucFunc = function (rstData) {
  1653. //init
  1654. me.buildSheet();
  1655. me.initTree(rstData);
  1656. me.buildMapping(me.tree.items);
  1657. me.cache = me.tree.items;
  1658. me.initController(me.tree, me.sheet, me.setting.sheet);
  1659. me.controller.showTreeData();
  1660. me.sheet.setFormatter(-1, 1, "@");
  1661. //init checkBox
  1662. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  1663. me.sheet.getRange(-1, 0, -1, 1).cellType(checkBox);
  1664. me.sheet
  1665. .getRange(-1, 0, -1, 1)
  1666. .hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  1667. };
  1668. let errFunc = function () {};
  1669. CommonAjax.post(url, postData, sucFunc, errFunc);
  1670. },
  1671. buildMapping: function (items) {
  1672. this.IDRowMapping = {};
  1673. for (let i = 0, len = items.length; i < len; i++) {
  1674. this.IDRowMapping[items[i].data.ID] = i;
  1675. }
  1676. },
  1677. initTree: function (datas) {
  1678. this.tree = idTree.createNew(this.setting.tree);
  1679. this.tree.loadDatas(datas);
  1680. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  1681. },
  1682. initController: function (tree, sheet, setting) {
  1683. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  1684. },
  1685. onEditStarting: function (sender, args) {
  1686. args.cancel = true;
  1687. },
  1688. onButtonClicked: function (sender, args) {
  1689. let me = batchSectionObj;
  1690. if (args.sheet.isEditing()) {
  1691. args.sheet.endEdit(true);
  1692. }
  1693. let node = me.cache[args.row];
  1694. let checked = args.sheet.getValue(args.row, args.col);
  1695. if (!me.isDef(node)) {
  1696. return;
  1697. }
  1698. let rows = me.getChildRows(node);
  1699. me.setChecked(rows, checked);
  1700. },
  1701. onClipboardPasting: function (sender, info) {
  1702. info.cancel = true;
  1703. },
  1704. getChildRows: function (node) {
  1705. let rst = [],
  1706. ids = [];
  1707. getChildIds(node);
  1708. for (id of ids) {
  1709. let row = this.IDRowMapping[id];
  1710. if (this.isDef(row)) {
  1711. rst.push(row);
  1712. }
  1713. }
  1714. return rst;
  1715. function getChildIds(node) {
  1716. ids.push(node.data.ID);
  1717. for (let child of node.children) {
  1718. getChildIds(child);
  1719. }
  1720. }
  1721. },
  1722. //设置勾选,跟随父节点
  1723. setChecked: function (rows, checked) {
  1724. let me = this;
  1725. this.renderFunc(this.sheet, function () {
  1726. for (let row of rows) {
  1727. me.sheet.setValue(row, 0, checked);
  1728. }
  1729. });
  1730. },
  1731. //获得勾选的章节ID
  1732. getCheckedSection: function (sheet) {
  1733. let rst = [];
  1734. let rowCount = sheet.getRowCount();
  1735. for (let i = 0, len = rowCount; i < len; i++) {
  1736. let checked = sheet.getValue(i, 0);
  1737. //只返回叶子节点
  1738. if (
  1739. this.isDef(checked) &&
  1740. checked == true &&
  1741. this.isDef(this.cache[i]) &&
  1742. this.isDef(this.cache[i].data.ID) &&
  1743. this.cache[i].children.length === 0
  1744. ) {
  1745. rst.push(this.cache[i].data.ID);
  1746. }
  1747. }
  1748. return Array.from(new Set(rst));
  1749. },
  1750. clearChecked: function () {
  1751. let me = this;
  1752. this.renderFunc(this.sheet, function () {
  1753. let rowCount = me.sheet.getRowCount();
  1754. for (let i = 0, len = rowCount; i < len; i++) {
  1755. me.sheet.setValue(i, 0, false);
  1756. }
  1757. });
  1758. },
  1759. onConfirmBtn: function () {
  1760. let me = this,
  1761. fi = feeItemObj,
  1762. se = sectionObj;
  1763. $("#bsTree_conf").bind("click", function () {
  1764. let feeItemId = fi.currentFeeItem.ID;
  1765. let sectionId = se.currentSection.ID;
  1766. let rationSection = me.getCheckedSection(me.sheet);
  1767. me.batchUpdate(feeItemId, sectionId, rationSection);
  1768. $(this).unbind();
  1769. });
  1770. },
  1771. //inst: 定额安装费用, rationSection: 定额章节树IDs
  1772. batchUpdate: function (feeItemId, sectionId, rationSection) {
  1773. CommonAjax.post(
  1774. "/rationRepository/api/batchUpdateInst",
  1775. {
  1776. inst: { feeItemId: feeItemId, sectionId: sectionId },
  1777. rationSection: rationSection,
  1778. },
  1779. function (rstData) {
  1780. $("#sectionTreeModal").modal("hide");
  1781. }
  1782. );
  1783. },
  1784. };