installation.js 47 KB

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