installation.js 52 KB

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