installation.js 49 KB

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