installation.js 49 KB

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