installation.js 50 KB

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