installation.js 48 KB

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