installation.js 48 KB

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