installation.js 52 KB

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