installation.js 52 KB

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