installation.js 51 KB

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