installation.js 50 KB

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