installation.js 51 KB

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