installation.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  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.update, 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" },
  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. },
  498. };
  499. } else {
  500. return false;
  501. }
  502. },
  503. });
  504. },
  505. onSelectionChanged: function (sender, info) {
  506. let me = sectionObj;
  507. if ((info.oldSelections && info.oldSelections.length === 0 && info.newSelections.length > 0) || info.oldSelections[0].row !== info.newSelections[0].row) {
  508. let row = info.newSelections[0].row;
  509. let section = me.cache[row];
  510. me.initSelection(section);
  511. }
  512. },
  513. onEditStarting: function (sender, args) {
  514. let me = sectionObj,
  515. fi = feeItemObj;
  516. if (!me.isDef(fi.currentFeeItem)) {
  517. args.cancel = true;
  518. }
  519. },
  520. onEditEnded: function (sender, args) {
  521. let me = sectionObj,
  522. fi = feeItemObj,
  523. fr = feeRuleObj;
  524. let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : "";
  525. let section = me.cache[args.row];
  526. let updateObj = { updateType: "", updateData: {} };
  527. //update
  528. if (me.isDef(section)) {
  529. debugger;
  530. updateObj.updateType = me.updateType.update;
  531. updateObj.updateData.ID = section.ID;
  532. if (args.col === 0) {
  533. section.name = !me.isDef(section.name) ? "" : section.name;
  534. if (section.name === v) {
  535. return;
  536. }
  537. if (v === "") {
  538. me.sheet.setValue(args.row, args.col, section.name);
  539. return;
  540. }
  541. section.name = v;
  542. updateObj.updateData.name = v;
  543. } else if (args.col === 1) {
  544. section.seq = !me.isDef(section.seq) ? "" : section.seq;
  545. if (section.seq === v) {
  546. return;
  547. }
  548. if (v === "") {
  549. me.sheet.setValue(args.row, args.col, section.seq);
  550. return;
  551. }
  552. section.seq = v;
  553. updateObj.updateData.seq = v;
  554. }
  555. }
  556. //insert
  557. else {
  558. if (v === "") {
  559. return;
  560. }
  561. updateObj.updateType = me.updateType.new;
  562. updateObj.updateData.ID = uuid.v1();
  563. updateObj.updateData.rationRepId = fi.rationRepId;
  564. updateObj.updateData.name = v;
  565. updateObj.updateData.feeItemId = fi.currentFeeItem.ID;
  566. updateObj.updateData.feeRule = [];
  567. me.cache.push(updateObj.updateData);
  568. me.currentSection = updateObj.updateData;
  569. fr.cache = me.currentSection.feeRule;
  570. }
  571. me.sheet.setRowCount(me.cache.length + 5);
  572. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  573. me.updateSection([updateObj]);
  574. fi.updateFeeItem([{ updateType: fi.updateType.update, updateData: { ID: fi.currentFeeItem.ID, $addToSet: { section: { ID: updateObj.updateData.ID } } } }]);
  575. },
  576. onClipboardPasting: function (sender, info) {
  577. let me = sectionObj,
  578. fi = feeItemObj;
  579. if (info.cellRange.col + info.cellRange.colCount > me.setting.header.length || !me.isDef(fi.currentFeeItem)) {
  580. info.cancel = true;
  581. }
  582. },
  583. onClipboardPasted: function (sender, info) {
  584. let me = sectionObj,
  585. fi = feeItemObj,
  586. fr = feeRuleObj;
  587. let sePostData = [],
  588. fiPostData = [];
  589. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  590. for (let i = 0, len = items.length; i < len; i++) {
  591. let row = info.cellRange.row + i;
  592. let section = me.cache[row];
  593. //update
  594. if (me.isDef(section)) {
  595. section.name = items[i].name;
  596. let updateObj = { updateType: me.updateType.update, updateData: { ID: section.ID, name: items[i].name } };
  597. sePostData.push(updateObj);
  598. }
  599. //insert
  600. else {
  601. let updateObj = {
  602. updateType: me.updateType.new,
  603. updateData: { ID: uuid.v1(), rationRepId: fi.rationRepId, name: items[i].name, feeItemId: fi.currentFeeItem.ID, feeRule: [] },
  604. };
  605. sePostData.push(updateObj);
  606. me.cache.push(updateObj.updateData);
  607. fiPostData.push({
  608. updateType: fi.updateType.update,
  609. updateData: { ID: fi.currentFeeItem.ID, $addToSet: { section: { ID: updateObj.updateData.ID } } },
  610. });
  611. }
  612. }
  613. //update currentSection
  614. me.currentSection = fi.getCurrentData(me.sheet, me.cache);
  615. fr.cache = me.currentSection.feeRule;
  616. me.sheet.setRowCount(me.cache.length + 5);
  617. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  618. if (sePostData.length > 0) {
  619. me.updateSection(sePostData);
  620. if (fiPostData.length > 0) {
  621. fi.updateFeeItem(fiPostData);
  622. }
  623. }
  624. },
  625. sectionDelOpr: function () {
  626. if (locked) {
  627. return;
  628. }
  629. let me = this;
  630. me.workBook.commandManager().register("sectionDel", function () {
  631. curDeleteType = me.deleteType;
  632. let sels = me.workBook.getSheet(0).getSelections();
  633. for (let i = 0, len = sels.length; i < len; i++) {
  634. let sel = sels[i];
  635. //delete
  636. if (sel.colCount === me.setting.header.length) {
  637. $("#delAlert").modal("show");
  638. break;
  639. }
  640. }
  641. });
  642. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  643. me.workBook.commandManager().setShortcutKey("sectionDel", GC.Spread.Commands.Key.del, false, false, false, false);
  644. },
  645. updateSection: function (updateData, callback) {
  646. CommonAjax.post("/rationRepository/api/updateSection", { updateData: updateData }, function (rstData) {
  647. if (callback) {
  648. callback();
  649. }
  650. });
  651. },
  652. };
  653. //费用规则
  654. let feeRuleObj = {
  655. workBook: null,
  656. sheet: null,
  657. addObj: null,
  658. updateObj: null,
  659. avtiveCell: { row: 0, col: 0 },
  660. cache: [],
  661. base: { RCJ: "分别按人材机乘系数", RG: "人工", CL: "材料", JX: "机械" },
  662. setting: {
  663. header: [
  664. {
  665. headerName: "编码",
  666. headerWidth: 80,
  667. dataCode: "code",
  668. dataType: "String",
  669. formatter: "@",
  670. hAlign: "left",
  671. vAlign: "center",
  672. span: { row: 0, rowCount: 2, colCount: 1 },
  673. },
  674. {
  675. headerName: "费用规则",
  676. headerWidth: 280,
  677. dataCode: "rule",
  678. dataType: "String",
  679. formatter: "@",
  680. hAlign: "left",
  681. vAlign: "center",
  682. span: { row: 0, rowCount: 2, colCount: 1 },
  683. },
  684. {
  685. headerName: "基数",
  686. headerWidth: 140,
  687. dataCode: "base",
  688. dataType: "String",
  689. formatter: "@",
  690. hAlign: "left",
  691. vAlign: "center",
  692. span: { row: 0, rowCount: 2, colCount: 1 },
  693. },
  694. {
  695. headerName: "费率(%)",
  696. headerWidth: 70,
  697. dataCode: "feeRate",
  698. dataType: "String",
  699. formatter: "@",
  700. hAlign: "center",
  701. vAlign: "center",
  702. span: { row: 0, rowCount: 2, colCount: 1 },
  703. },
  704. {
  705. headerName: "人工(%)",
  706. headerWidth: 70,
  707. dataCode: "labour",
  708. dataType: "String",
  709. formatter: "@",
  710. hAlign: "center",
  711. vAlign: "center",
  712. span: { row: 1, rowCount: 1, colCount: 1 },
  713. },
  714. {
  715. headerName: "材料(%)",
  716. headerWidth: 70,
  717. dataCode: "material",
  718. dataType: "String",
  719. formatter: "@",
  720. hAlign: "center",
  721. vAlign: "center",
  722. span: { row: 1, rowCount: 1, colCount: 1 },
  723. },
  724. {
  725. headerName: "机械(%)",
  726. headerWidth: 70,
  727. dataCode: "machine",
  728. dataType: "String",
  729. formatter: "@",
  730. hAlign: "center",
  731. vAlign: "center",
  732. span: { row: 1, rowCount: 1, colCount: 1 },
  733. },
  734. ],
  735. view: { lockColumns: [] },
  736. comboItems: { base: ["分别按人材机乘系数", "人工", "材料", "机械"] },
  737. options: {
  738. tabStripVisible: false,
  739. allowCopyPasteExcelStyle: false,
  740. allowExtendPasteRange: true,
  741. allowUserDragDrop: false,
  742. allowUserDragFill: false,
  743. scrollbarMaxAlign: true,
  744. },
  745. },
  746. isDef: function (v) {
  747. return v !== undefined && v !== null;
  748. },
  749. //sheet things
  750. setOptions: function (workbook, opts) {
  751. for (let opt in opts) {
  752. workbook.options[opt] = opts[opt];
  753. }
  754. },
  755. buildHeader: function () {
  756. if (!this.sheet) {
  757. return;
  758. }
  759. this.sheet.suspendPaint();
  760. this.sheet.suspendEvent();
  761. let ch = GC.Spread.Sheets.SheetArea.colHeader;
  762. this.sheet.setRowCount(2, ch);
  763. for (let i = 0; i < this.setting.header.length; i++) {
  764. let header = this.setting.header[i];
  765. this.sheet.addSpan(header.span.row, i, header.span.rowCount, header.span.colCount, ch);
  766. this.sheet.setValue(header.span.row, i, header.headerName, ch);
  767. if (header.dataCode === "feeRate") {
  768. this.sheet.addSpan(header.span.row, i + 1, 1, 3, ch);
  769. this.sheet.setValue(header.span.row, i + 1, "其中", ch);
  770. }
  771. }
  772. this.sheet.resumePaint();
  773. this.sheet.resumeEvent();
  774. },
  775. buildSheet: function () {
  776. let fi = feeItemObj;
  777. if (!this.isDef(this.workBook)) {
  778. this.workBook = sheetCommonObj.buildSheet($("#instFeeRuleSpread")[0], this.setting, 10);
  779. this.sheet = this.workBook.getActiveSheet();
  780. this.buildHeader();
  781. this.sheet.setRowCount();
  782. this.sheet.options.allowCellOverflow = false;
  783. sheetCommonObj.bindEscKey(this.workBook, [{ sheet: this.sheet, editStarting: this.onEditStarting, editEnded: this.onEditEnded }]);
  784. this.setOptions(this.workBook, this.setting.options);
  785. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  786. this.bindEvents(this.sheet);
  787. //init combo
  788. fi.setCombo(this.sheet, 2, this.setting.comboItems.base);
  789. }
  790. },
  791. bindEvents: function (sheet) {
  792. let me = feeRuleObj;
  793. const Events = GC.Spread.Sheets.Events;
  794. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  795. sheet.bind(Events.EnterCell, me.onEnterCell);
  796. sheet.bind(Events.EditStarting, me.onEditStarting);
  797. sheet.bind(Events.EditEnded, me.onEditEnded);
  798. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  799. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  800. me.feeRuleDelOpr();
  801. },
  802. canSave: function (addObj) {
  803. return this.isDef(addObj.code) && addObj.code !== "" && !this.hasCode(addObj) && this.validRCJ(addObj);
  804. },
  805. hasCode: function (obj) {
  806. let fi = feeItemObj;
  807. for (let feeItem of fi.cache) {
  808. for (let section of feeItem.section) {
  809. for (let feeRule of section.feeRule) {
  810. if (obj.code == feeRule.code && ((this.isDef(obj.ID) && obj.ID !== feeRule.ID) || !this.isDef(obj.ID))) {
  811. return true;
  812. }
  813. }
  814. }
  815. }
  816. return false;
  817. },
  818. //费用类型为人、材、机时人材机总和一定要为100
  819. validRCJ: function (feeRule) {
  820. if (!this.isDef(feeRule.base) || feeRule.base === this.base.RCJ) {
  821. return true;
  822. }
  823. let sum = 0;
  824. if (this.isDef(feeRule.labour)) {
  825. sum = parseFloat(sum + feeRule.labour).toDecimal(2);
  826. }
  827. if (this.isDef(feeRule.material)) {
  828. sum = parseFloat(sum + feeRule.material).toDecimal(2);
  829. }
  830. if (this.isDef(feeRule.machine)) {
  831. sum = parseFloat(sum + feeRule.machine).toDecimal(2);
  832. }
  833. return sum == 100;
  834. },
  835. validPasteData: function (data) {
  836. //插入须有编码
  837. if (!this.isDef(data.code)) {
  838. alert("粘贴时,编码不能为空,或者粘贴的数据中需包含编码");
  839. return false;
  840. }
  841. //编码须唯一
  842. if (this.isDef(data.code) && this.hasCode(data)) {
  843. alert("编码须唯一!");
  844. return false;
  845. }
  846. //基数要合法
  847. if (this.isDef(data.base) && this.setting.comboItems.base.indexOf(data.base) < 0) {
  848. alert("基数不正确!");
  849. return false;
  850. }
  851. //费率、人工、材料、机械,须数字
  852. if (this.isDef(data.feeRate) && isNaN(data.feeRate)) {
  853. alert("费率须为数字!");
  854. return false;
  855. }
  856. if (this.isDef(data.labour) && isNaN(data.labour)) {
  857. alert("人工须为数字!");
  858. return false;
  859. }
  860. if (this.isDef(data.material) && isNaN(data.material)) {
  861. alert("材料须为数字!");
  862. return false;
  863. }
  864. if (this.isDef(data.machine) && isNaN(data.machine)) {
  865. alert("机械须为数字!");
  866. return false;
  867. }
  868. //基数为分别按人材机时,费率须为空
  869. if (this.isDef(data.base) && data.base === this.base.RCJ && this.isDef(data.feeRate) && data.feeRate !== "") {
  870. alert("基数为分别按人材机时,费率须为空!");
  871. return false;
  872. }
  873. //基数为 人工、材料、机械时 三者之和须为100
  874. if (this.isDef(data.base) && data.base !== this.base.RCJ && this.validRCJ(data)) {
  875. alert("基数为 人工、材料、机械时 三者之和须为100");
  876. return false;
  877. }
  878. return true;
  879. },
  880. decimalPasteData: function (data) {
  881. if (this.isDef(data.feeRate) && isNaN(data.feeRate)) {
  882. data.feeRate = parseFloat(data.feeRate).toDecimal(2);
  883. }
  884. if (this.isDef(data.labour) && isNaN(data.labour)) {
  885. data.labour = parseFloat(data.labour).toDecimal(2);
  886. }
  887. if (this.isDef(data.material) && isNaN(data.material)) {
  888. data.material = parseFloat(data.material).toDecimal(2);
  889. }
  890. if (this.isDef(data.machine) && isNaN(data.machine)) {
  891. data.machine = parseFloat(data.machine).toDecimal(2);
  892. }
  893. },
  894. getFocusToCol: function (feeRule) {
  895. if (!this.isDef(feeRule.labour) || feeRule.labour === "" || feeRule.labour > 100 || feeRule.labour == 0) {
  896. return 4;
  897. }
  898. if (!this.isDef(feeRule.material) || feeRule.material === "" || feeRule.material > 100 || feeRule.material == 0) {
  899. return 5;
  900. }
  901. if (!this.isDef(feeRule.machine) || feeRule.machine === "" || feeRule.machine > 100 || feeRule.machine == 0) {
  902. return 6;
  903. }
  904. return 4;
  905. },
  906. onSelectionChanged: function (sender, info) {
  907. let me = feeRuleObj,
  908. se = sectionObj;
  909. if ((info.oldSelections && info.oldSelections.length === 0 && info.newSelections.length > 0) || info.oldSelections[0].row !== info.newSelections[0].row) {
  910. if (me.isDef(me.updateObj) && !me.validRCJ(me.updateObj)) {
  911. $("#rcjAlert").modal("show");
  912. $("#aleCanceBtn").bind("click", function () {
  913. me.updateObj.base = me.base.RCJ;
  914. me.updateObj.labour = 0;
  915. me.updateObj.material = 0;
  916. me.updateObj.machine = 0;
  917. me.sheet.setRowCount(me.cache.length + 5);
  918. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  919. se.updateSection([{ updateType: se.updateType.update, updateData: se.currentSection }]);
  920. $(this).unbind();
  921. });
  922. $("#aleConfBtn").bind("click", function () {
  923. me.sheet.setActiveCell(me.avtiveCell.row, me.getFocusToCol(me.updateObj));
  924. $(this).unbind();
  925. });
  926. }
  927. if (me.isDef(me.addObj)) {
  928. if (!me.isDef(me.addObj.code) || me.addObj.code === "") {
  929. $("#alertText").text("请输入编码");
  930. $("#codeAlert").modal("show");
  931. $("#codAleClose").click(function () {
  932. me.addObj.code = "";
  933. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  934. $(this).unbind();
  935. });
  936. $("#codAlertQR").click(function () {
  937. me.addObj.code = "";
  938. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  939. $(this).unbind();
  940. });
  941. //取消插入
  942. $("#codAlertQX").click(function () {
  943. me.addObj = null;
  944. me.sheet.setRowCount(me.cache.length + 5);
  945. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  946. $(this).unbind();
  947. });
  948. } else if (me.isDef(me.addObj.code) && me.hasCode(me.addObj)) {
  949. $("#alertText").text("输入的编号已存在,请重新输入");
  950. $("#codeAlert").modal("show");
  951. $("#codAleClose").click(function () {
  952. me.addObj.code = "";
  953. me.sheet.setValue(me.avtiveCell.row, 0, "");
  954. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  955. $(this).unbind();
  956. });
  957. $("#codAlertQR").click(function () {
  958. me.addObj.code = "";
  959. me.sheet.setValue(me.avtiveCell.row, 0, "");
  960. me.sheet.setActiveCell(me.avtiveCell.row, 0);
  961. $(this).unbind();
  962. });
  963. //取消插入
  964. $("#codAlertQX").click(function () {
  965. me.addObj = null;
  966. me.sheet.setRowCount(me.cache.length + 5);
  967. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  968. $(this).unbind();
  969. });
  970. } else if (!me.validRCJ(me.addObj)) {
  971. $("#rcjAlert").modal("show");
  972. $("#aleCanceBtn").bind("click", function () {
  973. me.addObj = null;
  974. me.sheet.setRowCount(me.cache.length + 5);
  975. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  976. $(this).unbind();
  977. });
  978. $("#aleConfBtn").bind("click", function () {
  979. me.sheet.setActiveCell(me.avtiveCell.row, me.getFocusToCol(me.addObj));
  980. $(this).unbind();
  981. });
  982. }
  983. }
  984. }
  985. },
  986. onEnterCell: function (sender, args) {
  987. let me = feeRuleObj;
  988. me.sheet.repaint();
  989. },
  990. onEditStarting: function (sender, args) {
  991. let me = feeRuleObj,
  992. se = sectionObj;
  993. let feeRule = me.cache[args.row];
  994. let rcjCols = [4, 5, 6];
  995. if (!me.isDef(se.currentSection)) {
  996. args.cancel = true;
  997. }
  998. if (me.isDef(feeRule) && me.isDef(feeRule.base) && feeRule.base === me.base.RCJ && args.col === 3) {
  999. args.cancel = true;
  1000. } else if (!me.isDef(feeRule) && rcjCols.indexOf(args.col) > 0) {
  1001. args.cancel = true;
  1002. }
  1003. },
  1004. onEditEnded: function (sender, args) {
  1005. let me = feeRuleObj,
  1006. se = sectionObj;
  1007. let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : "";
  1008. let updateObj = { updateType: "", updateData: {} };
  1009. let feeRule = me.cache[args.row];
  1010. let field = me.setting.header[args.col]["dataCode"];
  1011. let orgV = me.isDef(feeRule) && me.isDef(feeRule[field]) ? feeRule[field] : "";
  1012. me.updateObj = feeRule;
  1013. me.avtiveCell.row = args.row;
  1014. me.avtiveCell.col = args.col;
  1015. //update
  1016. if (me.isDef(feeRule)) {
  1017. feeRule[field] = me.isDef(feeRule[field]) ? feeRule[field] : "";
  1018. if (v === feeRule[field]) {
  1019. return;
  1020. }
  1021. if (field === "base" && v === me.base.RCJ) {
  1022. //基数为人材机时,费率清空
  1023. feeRule.feeRate = "";
  1024. me.sheet.setValue(args.row, 3, "");
  1025. } else if (field === "base" && (v === me.base.RG || v === me.base.CL || v === me.base.JX)) {
  1026. if (!me.validRCJ(feeRule)) {
  1027. //基数变为人工、材料、机械时,若人材机之和不为100,则清空
  1028. feeRule.labour = 0;
  1029. feeRule.material = 0;
  1030. feeRule.machine = 0;
  1031. }
  1032. } else if (field === "labour" || field === "material" || field === "machine" || field === "feeRate") {
  1033. if (isNaN(v)) {
  1034. alert("只能输入数值");
  1035. me.sheet.setValue(args.row, args.col, orgV);
  1036. return;
  1037. }
  1038. v = parseFloat(v).toDecimal(2);
  1039. me.sheet.setValue(args.row, args.col, v);
  1040. }
  1041. feeRule[field] = v;
  1042. //编码重复,不可更新
  1043. if (field === "code") {
  1044. if (v == "") {
  1045. me.sheet.setValue(args.row, args.col, orgV);
  1046. return;
  1047. feeRule[field] = orgV;
  1048. }
  1049. if (me.hasCode(feeRule)) {
  1050. $("#codeAlert").modal("show");
  1051. $("#codAleClose").bind("click", function () {
  1052. me.sheet.setActiveCell(args.row, 0);
  1053. me.sheet.setValue(args.row, args.col, orgV);
  1054. });
  1055. $("#codAlertQR").bind("click", function () {
  1056. me.sheet.setActiveCell(args.row, 0);
  1057. me.sheet.setValue(args.row, args.col, orgV);
  1058. });
  1059. feeRule[field] = orgV;
  1060. return;
  1061. }
  1062. }
  1063. //是否能更新
  1064. //人材机之和不为100,不解决之和为100取消操作的话,则基数自动换成分别按人材机
  1065. if (!me.validRCJ(feeRule)) {
  1066. return;
  1067. }
  1068. updateObj.updateType = se.updateType.update;
  1069. updateObj.updateData.ID = se.currentSection.ID;
  1070. updateObj.updateData.feeRule = me.cache;
  1071. me.updateObj = null;
  1072. se.updateSection([{ updateType: se.updateType.update, updateData: se.currentSection }]);
  1073. }
  1074. //insert
  1075. else {
  1076. if (v === "") {
  1077. return;
  1078. }
  1079. if (!me.isDef(me.addObj)) {
  1080. me.addObj = Object.create(null);
  1081. }
  1082. me.addObj[me.setting.header[args.col]["dataCode"]] = v;
  1083. if (me.canSave(me.addObj)) {
  1084. me.addObj.ID = uuid.v1();
  1085. me.cache.push(me.addObj);
  1086. updateObj.updateType = se.updateType.update;
  1087. updateObj.updateData.ID = se.currentSection.ID;
  1088. updateObj.updateData.feeRule = me.cache;
  1089. me.sheet.setRowCount(me.cache.length + 5);
  1090. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1091. se.updateSection([{ updateType: se.updateType.update, updateData: se.currentSection }]);
  1092. me.addObj = null;
  1093. }
  1094. }
  1095. },
  1096. onClipboardPasting: function (sender, info) {
  1097. let me = feeRuleObj,
  1098. se = sectionObj;
  1099. if (info.cellRange.col + info.cellRange.colCount > me.setting.header.length) {
  1100. info.cancel = true;
  1101. }
  1102. if (!me.isDef(se.currentSection)) {
  1103. info.cancel = true;
  1104. }
  1105. },
  1106. onClipboardPasted: function (sender, info) {
  1107. let me = feeRuleObj,
  1108. se = sectionObj,
  1109. fi = feeItemObj;
  1110. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  1111. me.toUpdate = false;
  1112. for (let i = 0, len = items.length; i < len; i++) {
  1113. let row = info.cellRange.row + i;
  1114. let feeRule = me.cache[row];
  1115. //update
  1116. if (me.isDef(feeRule)) {
  1117. let tempObj = {};
  1118. for (let attr in feeRule) {
  1119. tempObj[attr] = feeRule[attr];
  1120. }
  1121. for (let attr in items[i]) {
  1122. tempObj[attr] = items[i][attr];
  1123. }
  1124. if (me.validPasteData(tempObj)) {
  1125. me.decimalPasteData(tempObj);
  1126. //front
  1127. me.cache[row] = tempObj;
  1128. me.toUpdate = true;
  1129. }
  1130. } else {
  1131. // //insert
  1132. if (me.validPasteData(items[i])) {
  1133. me.decimalPasteData(items[i]);
  1134. items[i].ID = uuid.v1();
  1135. //front
  1136. me.cache.push(items[i]);
  1137. me.toUpdate = true;
  1138. }
  1139. }
  1140. }
  1141. me.sheet.setRowCount(me.cache.length + 5);
  1142. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1143. if (me.toUpdate) {
  1144. se.updateSection([{ updateType: se.updateType.update, updateData: se.currentSection }]);
  1145. }
  1146. },
  1147. feeRuleDelOpr: function () {
  1148. if (locked) {
  1149. return;
  1150. }
  1151. let me = feeRuleObj,
  1152. se = sectionObj;
  1153. me.workBook.commandManager().register("feeRuleDel", function () {
  1154. me.toUpdate = false;
  1155. let sels = me.workBook.getSheet(0).getSelections();
  1156. for (let i = 0, len = sels.length; i < len; i++) {
  1157. let sel = sels[i];
  1158. //delete
  1159. if (sel.colCount === me.setting.header.length) {
  1160. for (let j = 0, jLen = sel.rowCount; j < jLen; j++) {
  1161. let row = sel.row + j;
  1162. let feeRule = me.cache[row];
  1163. //有数据,删除数据
  1164. if (me.isDef(feeRule)) {
  1165. me.toUpdate = true;
  1166. }
  1167. }
  1168. //front delete
  1169. me.cache.splice(sel.row, sel.rowCount);
  1170. }
  1171. }
  1172. if (me.toUpdate) {
  1173. se.updateSection([{ updateType: se.updateType.update, updateData: se.currentSection }], function () {
  1174. me.sheet.setRowCount(me.cache.length + 5);
  1175. sheetCommonObj.showData(me.sheet, me.setting, me.cache);
  1176. });
  1177. }
  1178. });
  1179. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  1180. me.workBook.commandManager().setShortcutKey("feeRuleDel", GC.Spread.Commands.Key.del, false, false, false, false);
  1181. },
  1182. };
  1183. let batchSectionObj = {
  1184. cache: null,
  1185. tree: null,
  1186. controller: null,
  1187. workBook: null,
  1188. sheet: null,
  1189. IDRowMapping: null, //树节点ID与行号映射
  1190. setting: {
  1191. sheet: {
  1192. cols: [
  1193. {
  1194. head: {
  1195. titleNames: ["选择"],
  1196. spanCols: [1],
  1197. spanRows: [2],
  1198. vAlign: [1, 1],
  1199. hAlign: [1, 1],
  1200. font: "Arial",
  1201. },
  1202. data: {
  1203. field: "select",
  1204. vAlign: 1,
  1205. hAlign: 0,
  1206. font: "Arial",
  1207. },
  1208. width: 50,
  1209. },
  1210. {
  1211. head: {
  1212. titleNames: ["名称"],
  1213. spanCols: [1],
  1214. spanRows: [2],
  1215. vAlign: [1, 1],
  1216. hAlign: [1, 1],
  1217. font: "Arial",
  1218. },
  1219. data: {
  1220. field: "name",
  1221. vAlign: 1,
  1222. hAlign: 0,
  1223. font: "Arial",
  1224. },
  1225. width: 400,
  1226. },
  1227. ],
  1228. headRows: 1,
  1229. headRowHeight: [47],
  1230. emptyRows: 0,
  1231. treeCol: 1,
  1232. },
  1233. tree: {
  1234. id: "ID",
  1235. pid: "ParentID",
  1236. nid: "NextSiblingID",
  1237. rootId: -1,
  1238. },
  1239. options: {
  1240. tabStripVisible: false,
  1241. allowCopyPasteExcelStyle: false,
  1242. allowExtendPasteRange: true,
  1243. allowUserDragDrop: false,
  1244. allowUserDragFill: false,
  1245. scrollbarMaxAlign: true,
  1246. },
  1247. },
  1248. isDef: function (v) {
  1249. return v !== undefined && v !== null;
  1250. },
  1251. renderFunc: function (sheet, func) {
  1252. sheet.suspendPaint();
  1253. sheet.suspendEvent();
  1254. if (func) {
  1255. func();
  1256. }
  1257. sheet.resumePaint();
  1258. sheet.resumeEvent();
  1259. },
  1260. setOptions: function (workbook, opts) {
  1261. for (let opt in opts) {
  1262. workbook.options[opt] = opts[opt];
  1263. }
  1264. },
  1265. buildSheet: function () {
  1266. if (!this.isDef(this.workBook)) {
  1267. this.workBook = new GC.Spread.Sheets.Workbook($("#batchSectionSpread")[0], { sheetCount: 1 });
  1268. this.sheet = this.workBook.getActiveSheet();
  1269. this.setOptions(this.workBook, this.setting.options);
  1270. this.bindEvents(this.sheet);
  1271. }
  1272. },
  1273. bindEvents: function (sheet) {
  1274. let me = this;
  1275. const Events = GC.Spread.Sheets.Events;
  1276. sheet.bind(Events.EditStarting, me.onEditStarting);
  1277. sheet.bind(Events.EditEnded, me.onEditEnded);
  1278. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  1279. me.workBook.bind(Events.ButtonClicked, me.onButtonClicked); //复选框点击事件
  1280. },
  1281. getSectionTree: function (repId) {
  1282. let me = this;
  1283. let url = "api/getRationTree";
  1284. let postData = { rationLibId: repId };
  1285. let sucFunc = function (rstData) {
  1286. //init
  1287. me.buildSheet();
  1288. me.initTree(rstData);
  1289. me.buildMapping(me.tree.items);
  1290. me.cache = me.tree.items;
  1291. me.initController(me.tree, me.sheet, me.setting.sheet);
  1292. me.controller.showTreeData();
  1293. me.sheet.setFormatter(-1, 1, "@");
  1294. //init checkBox
  1295. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  1296. me.sheet.getRange(-1, 0, -1, 1).cellType(checkBox);
  1297. me.sheet.getRange(-1, 0, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  1298. };
  1299. let errFunc = function () {};
  1300. CommonAjax.post(url, postData, sucFunc, errFunc);
  1301. },
  1302. buildMapping: function (items) {
  1303. this.IDRowMapping = {};
  1304. for (let i = 0, len = items.length; i < len; i++) {
  1305. this.IDRowMapping[items[i].data.ID] = i;
  1306. }
  1307. },
  1308. initTree: function (datas) {
  1309. this.tree = idTree.createNew(this.setting.tree);
  1310. this.tree.loadDatas(datas);
  1311. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  1312. },
  1313. initController: function (tree, sheet, setting) {
  1314. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  1315. },
  1316. onEditStarting: function (sender, args) {
  1317. args.cancel = true;
  1318. },
  1319. onButtonClicked: function (sender, args) {
  1320. let me = batchSectionObj;
  1321. if (args.sheet.isEditing()) {
  1322. args.sheet.endEdit(true);
  1323. }
  1324. let node = me.cache[args.row];
  1325. let checked = args.sheet.getValue(args.row, args.col);
  1326. if (!me.isDef(node)) {
  1327. return;
  1328. }
  1329. let rows = me.getChildRows(node);
  1330. me.setChecked(rows, checked);
  1331. },
  1332. onClipboardPasting: function (sender, info) {
  1333. info.cancel = true;
  1334. },
  1335. getChildRows: function (node) {
  1336. let rst = [],
  1337. ids = [];
  1338. getChildIds(node);
  1339. for (id of ids) {
  1340. let row = this.IDRowMapping[id];
  1341. if (this.isDef(row)) {
  1342. rst.push(row);
  1343. }
  1344. }
  1345. return rst;
  1346. function getChildIds(node) {
  1347. ids.push(node.data.ID);
  1348. for (let child of node.children) {
  1349. getChildIds(child);
  1350. }
  1351. }
  1352. },
  1353. //设置勾选,跟随父节点
  1354. setChecked: function (rows, checked) {
  1355. let me = this;
  1356. this.renderFunc(this.sheet, function () {
  1357. for (let row of rows) {
  1358. me.sheet.setValue(row, 0, checked);
  1359. }
  1360. });
  1361. },
  1362. //获得勾选的章节ID
  1363. getCheckedSection: function (sheet) {
  1364. let rst = [];
  1365. let rowCount = sheet.getRowCount();
  1366. for (let i = 0, len = rowCount; i < len; i++) {
  1367. let checked = sheet.getValue(i, 0);
  1368. //只返回叶子节点
  1369. if (this.isDef(checked) && checked == true && this.isDef(this.cache[i]) && this.isDef(this.cache[i].data.ID) && this.cache[i].children.length === 0) {
  1370. rst.push(this.cache[i].data.ID);
  1371. }
  1372. }
  1373. return Array.from(new Set(rst));
  1374. },
  1375. clearChecked: function () {
  1376. let me = this;
  1377. this.renderFunc(this.sheet, function () {
  1378. let rowCount = me.sheet.getRowCount();
  1379. for (let i = 0, len = rowCount; i < len; i++) {
  1380. me.sheet.setValue(i, 0, false);
  1381. }
  1382. });
  1383. },
  1384. onConfirmBtn: function () {
  1385. let me = this,
  1386. fi = feeItemObj,
  1387. se = sectionObj;
  1388. $("#bsTree_conf").bind("click", function () {
  1389. let feeItemId = fi.currentFeeItem.ID;
  1390. let sectionId = se.currentSection.ID;
  1391. let rationSection = me.getCheckedSection(me.sheet);
  1392. me.batchUpdate(feeItemId, sectionId, rationSection);
  1393. $(this).unbind();
  1394. });
  1395. },
  1396. //inst: 定额安装费用, rationSection: 定额章节树IDs
  1397. batchUpdate: function (feeItemId, sectionId, rationSection) {
  1398. CommonAjax.post(
  1399. "/rationRepository/api/batchUpdateInst",
  1400. { inst: { feeItemId: feeItemId, sectionId: sectionId }, rationSection: rationSection },
  1401. function (rstData) {
  1402. $("#sectionTreeModal").modal("hide");
  1403. }
  1404. );
  1405. },
  1406. };