ration.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. $(document).ready(function () {
  5. //定额表与下方子表上下拖动
  6. let rationSubResize = getRationSubResize();
  7. SlideResize.verticalSlide(rationSubResize.eleObj, rationSubResize.limit, function () {
  8. if (rationOprObj.workBook) {
  9. rationOprObj.workBook.refresh();
  10. }
  11. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  12. rationGLJOprObj.sheet.getParent().refresh();
  13. }
  14. });
  15. SlideResize.loadVerticalHeight(rationSubResize.eleObj.module, rationSubResize.eleObj, rationSubResize.limit, function () {
  16. if (rationOprObj.workBook) {
  17. rationOprObj.workBook.refresh();
  18. }
  19. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  20. rationGLJOprObj.sheet.getParent().refresh();
  21. }
  22. });
  23. });
  24. function getRationSubResize() {
  25. let rationSubResize = {};
  26. rationSubResize.eleObj = {
  27. module: 'compleRation',
  28. resize: $('#rationSubResize'),
  29. top: $('#rationItemsSheet'),
  30. topSpread: $('#rationItemsSheet'),
  31. bottom: $('#subContent'),
  32. bottomSpread: $('#rdSpread')
  33. };
  34. rationSubResize.limit = {
  35. min: 150,
  36. max: `$(window).height()-$('.header').height()-$('.tools-bar').height()-150-5`,
  37. totalHeight: `$(window).height()-$('.header').height()-$('.tools-bar').height()-5`,
  38. notTopSpread: 0,
  39. notBottomSpread: $('#subContent ul').height(),
  40. };
  41. return rationSubResize;
  42. }
  43. function loadRationSubSize(resizeObj) {
  44. if (!resizeObj) {
  45. resizeObj = getRationSubResize();
  46. }
  47. SlideResize.loadVerticalHeight(resizeObj.eleObj.module, resizeObj.eleObj, resizeObj.limit, function () {
  48. if (rationOprObj.workBook) {
  49. rationOprObj.workBook.refresh();
  50. }
  51. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  52. rationGLJOprObj.sheet.getParent().refresh();
  53. }
  54. });
  55. }
  56. const digital = {
  57. gljPrc: -3,//计算定额基价时单个工料机价格取三位
  58. rationBasePrc: -2,
  59. consumeAmt: -3
  60. };
  61. let rationOprObj = {
  62. workBook: null,
  63. currentRations: {},
  64. currentEditingRation: null,
  65. currentSectionId: -1,
  66. rationsCodes: [],
  67. setting: {
  68. header:[
  69. {headerName:"编码",headerWidth:70,dataCode:"code", dataType: "String", formatter: "@"},
  70. {headerName:"名称",headerWidth:240,dataCode:"name", dataType: "String"},
  71. {headerName:"计量单位",headerWidth:70,dataCode:"unit", dataType: "String", hAlign: "center"},
  72. {headerName:"人工费",headerWidth:80,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  73. {headerName:"材料费",headerWidth:80,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  74. {headerName:"机械费",headerWidth:80,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  75. {headerName:"基价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  76. {headerName:"显示名称(以%s表示参数)",headerWidth:240,dataCode:"caption", dataType: "String"},
  77. {headerName:"取费专业",headerWidth:70,dataCode:"feeType", dataType: "Number", hAlign: "center"}
  78. ],
  79. view:{
  80. comboBox:[
  81. {row:-1,col:2,rowCount:-1,colCount:1}
  82. ],
  83. lockedCells:[
  84. {row:-1,col:3,rowCount:-1, colCount:1}
  85. ],
  86. lockColumns: [
  87. 3, 4, 5, 6
  88. ]
  89. }
  90. },
  91. buildSheet: function(container) {
  92. let rationRepId = getQueryString("repository");
  93. let me = rationOprObj;
  94. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  95. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
  96. me.onContextmenuOpr();
  97. me.rationDelOpr();
  98. me.setCombo(me.workBook.getSheet(0), 'dynamic');
  99. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  100. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  101. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  102. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  103. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  104. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  105. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  106. },
  107. setCombo: function (sheet, combo) {
  108. let me = rationOprObj;
  109. sheet.suspendPaint();
  110. sheet.suspendEvent();
  111. if(combo){
  112. combo = sheetCommonObj.getDynamicCombo();
  113. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  114. }
  115. sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
  116. sheet.resumePaint();
  117. sheet.resumeEvent();
  118. },
  119. onSelectionChanged: function (sender, info) {
  120. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  121. let row = info.newSelections[0].row;
  122. let me = rationOprObj;
  123. me.rationSelInit(row);
  124. }
  125. },
  126. //focusOnSection将工作簿焦点移到章节表上
  127. rationSelInit: function (row, focusOnSection = null) {
  128. let me = rationOprObj,
  129. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  130. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  131. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  132. //sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  133. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  134. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  135. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  136. //sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  137. let cacheSection = me.getCache();
  138. if (cacheSection && row < cacheSection.length) {
  139. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  140. if (focusOnSection){
  141. sectionTreeObj.workBook.focus(true);
  142. } else {
  143. me.workBook.focus(true);
  144. }
  145. });
  146. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  147. if (focusOnSection){
  148. sectionTreeObj.workBook.focus(true);
  149. } else {
  150. me.workBook.focus(true);
  151. }
  152. });
  153. rationAssistOprObj.getAssItems(cacheSection[row]);
  154. /*rationInstObj.getInstItems(cacheSection[row], function () {
  155. if (focusOnSection){
  156. sectionTreeObj.workBook.focus(true);
  157. } else {
  158. me.workBook.focus(true);
  159. }
  160. });*/
  161. }
  162. else {
  163. rationGLJOprObj.currentRationItem = null;
  164. }
  165. if (!focusOnSection) {
  166. me.workBook.focus(true);
  167. }
  168. },
  169. isInt: function (num) {
  170. return !isNaN(num) && num % 1 === 0;
  171. },
  172. isDef: function (v) {
  173. return v !== undefined && v !== null;
  174. },
  175. getCache: function() {
  176. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  177. if (!(rst)) {
  178. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  179. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  180. }
  181. return rst;
  182. },
  183. updateCache: function(addArr, updateArr, removeIds, rstData) {
  184. let me = this, cacheSection = me.getCache();
  185. if (addArr.length > 0) {
  186. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  187. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  188. }
  189. for (let i = removeIds.length - 1; i >= 0; i--) {
  190. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  191. if (cacheSection[j]["ID"] == removeIds[i]) {
  192. cacheSection.splice(j,1);
  193. }
  194. }
  195. }
  196. if (rstData && rstData.ops && rstData.ops.length > 0) {
  197. for (let i = 0; i < rstData.ops.length; i++) {
  198. for (let j = 0; j < cacheSection.length; j++) {
  199. if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
  200. cacheSection[j]["ID"] = rstData.ops[i]["ID"];
  201. cacheSection[j]["rationGljList"] = rstData.ops[i]["rationGljList"];
  202. cacheSection[j]["rationCoeList"] = rstData.ops[i]["rationCoeList"];
  203. cacheSection[j]["rationAssList"] = rstData.ops[i]["rationAssList"];
  204. //cacheSection[j]["rationInstList"] = rstData.ops[i]["rationInstList"];
  205. }
  206. }
  207. }
  208. }
  209. for (let i = 0; i < updateArr.length; i++) {
  210. for (let j = 0; j < cacheSection.length; j++) {
  211. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  212. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  213. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  214. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  215. cacheSection[j]['rationGljList'] ?
  216. cacheSection[j]['rationGljList'] : [];
  217. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  218. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  219. //updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  220. cacheSection[j] = updateArr[i];
  221. }
  222. } else {
  223. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  224. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  225. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  226. cacheSection[j]['rationGljList'] ?
  227. cacheSection[j]['rationGljList'] : [];
  228. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  229. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  230. //updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  231. cacheSection[j] = updateArr[i];
  232. }
  233. }
  234. }
  235. }
  236. return cacheSection;
  237. },
  238. onContextmenuOpr: function () {//右键菜单
  239. let me = this;
  240. $.contextMenu({
  241. selector: '#rationItemsSheet',
  242. build: function($triggerElement, e){
  243. //控制允许右键菜单在哪个位置出现
  244. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  245. let sheet = me.workBook.getSheet(0);
  246. let delDis = false;
  247. let cacheSection = me.getCache();
  248. let ration = cacheSection[target.row];
  249. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  250. if(typeof target.row !== 'undefined'){
  251. //控制按钮是否可用
  252. sheet.setActiveCell(target.row, target.col);
  253. if(!cacheSection ||target.row >= cacheSection.length){//右键定位在有数据的行,删除键才显示可用
  254. delDis = true;
  255. }
  256. else{//有数据
  257. if(typeof target.col === 'undefined'){//定位不在表格内
  258. delDis = true;
  259. }
  260. }
  261. }
  262. else{
  263. delDis = true;
  264. }
  265. return {
  266. callback: function(){},
  267. items: {
  268. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  269. let removeInfo = `确定要删除定额 “${ration.code}” 及其下的所有数据吗?`;
  270. $('#delRationAlert').find('.modal-body h5').text(removeInfo);
  271. $('#delRationAlert').modal('show');
  272. $('#delRationConfirm').unbind('click');
  273. $('#delRationConfirm').bind('click', function () {
  274. me.rationsCodes.splice(me.rationsCodes.indexOf(ration.code.toString()), 1);
  275. me.mixDel = 1;
  276. me.mixUpdateRequest([], [], [ration.ID]);
  277. $('#delRationAlert').modal('hide');
  278. });
  279. }}
  280. }
  281. };
  282. }
  283. else{
  284. return false;
  285. }
  286. }
  287. });
  288. },
  289. rationDelOpr: function () {
  290. let me = rationOprObj;
  291. me.workBook.commandManager().register('rationDelete', function () {
  292. let rationSheet = me.workBook.getActiveSheet();
  293. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  294. let removeCodes = [];
  295. let cacheSection = me.getCache();
  296. if(sels.length > 0){
  297. for(let sel = 0; sel < sels.length; sel++){
  298. if(sels[sel].colCount === me.setting.header.length){
  299. if(cacheSection){
  300. for(let i = 0; i < sels[sel].rowCount; i++){
  301. if(sels[sel].row + i < cacheSection.length){
  302. removeArr.push(cacheSection[sels[sel].row + i].ID);
  303. removeCodes.push(cacheSection[sels[sel].row + i].code);
  304. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code.toString()), 1);
  305. }
  306. }
  307. }
  308. }
  309. else{
  310. if(sels[sel].col === 0){
  311. $('#alertText').text("编号不能为空,修改失败!");
  312. $('#alertModalBtn').click();
  313. $('#alertModalCls').click(function () {
  314. });
  315. $('#alertModalCof').click(function () {
  316. })
  317. }
  318. else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
  319. if(cacheSection){
  320. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  321. if(sels[sel].row + i < cacheSection.length){
  322. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  323. if(lockCols.indexOf(col) === -1){
  324. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  325. }
  326. }
  327. }
  328. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  329. updateArr.push(cacheSection[sels[sel].row + i]);
  330. }
  331. }
  332. }
  333. }
  334. }
  335. }
  336. }
  337. /* if(updateArr.length > 0 || removeArr.length > 0){
  338. me.mixUpdate = 1;
  339. me.mixDel = removeArr.length > 0 ? 1 : 0;
  340. me.mixUpdateRequest(updateArr, [], removeArr);
  341. }*/
  342. if(updateArr.length > 0){
  343. me.mixUpdate = 1;
  344. me.mixUpdateRequest(updateArr, [], []);
  345. }
  346. if(removeArr.length > 0){
  347. let removeInfo = `确定要删除定额 “${removeCodes.join(',')}” 及其下的所有数据吗?`;
  348. $('#delRationAlert').find('.modal-body h5').text(removeInfo);
  349. $('#delRationAlert').modal('show');
  350. $('#delRationConfirm').bind('click', function () {
  351. me.mixDel = 1;
  352. me.mixUpdateRequest([], [], removeArr);
  353. $('#delRationConfirm').unbind('click');
  354. $('#delRationAlert').modal('hide');
  355. });
  356. }
  357. });
  358. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  359. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  360. },
  361. onLeaveCell: function (sender, args) {
  362. let me = rationOprObj;
  363. me.lastCol = me.setting.header[args.col];
  364. },
  365. onEnterCell: function (sender, args) {
  366. let me = rationOprObj;
  367. if(me.setting.header[args.col]['dataCode'] === 'unit' || me.lastCol.dataCode === 'unit'){
  368. args.sheet.repaint();
  369. }
  370. me.cellRowIdx = args.row;
  371. let isHasData = false;
  372. if(me.addRationItem){
  373. for(let i=0; i<me.setting.header.length; i++){
  374. if(me.addRationItem[me.setting.header[i].dataCode]){
  375. isHasData = true;
  376. break;
  377. }
  378. }
  379. }
  380. if(isHasData){
  381. if(me.editingRowIdx !== me.cellRowIdx) {
  382. let focusToCol = !me.addRationItem.code ? 0 : -1;
  383. if(focusToCol !== -1){
  384. $('#rationAlertBtn').click();
  385. $('#rationAlertCac').click(function () {
  386. me.addRationItem = null;
  387. for(let col=0; col<me.setting.header.length; col++){
  388. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  389. }
  390. });
  391. $('#rationAlertCls').click(function () {
  392. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  393. });
  394. $('#rationAlertCof').click(function () {
  395. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  396. });
  397. }
  398. }
  399. }
  400. },
  401. onCellEditStart: function(sender, args) {
  402. let me = rationOprObj;
  403. if(!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1){
  404. args.cancel = true;
  405. }
  406. else{
  407. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  408. me.currentEditingRation = rObj;
  409. let cacheSection = me.getCache();
  410. if (cacheSection) {
  411. for (let j = 0; j < cacheSection.length; j++) {
  412. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  413. rObj["ID"] = cacheSection[j]["ID"];
  414. break;
  415. }
  416. }
  417. }
  418. }
  419. },
  420. onCellEditEnd: function(sender, args) {
  421. let me = rationOprObj;
  422. // 输入编号、名称、单位时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  423. let dataCode = me.setting.header[args.col].dataCode;
  424. let deESCFields = ['code', 'name', 'unit'];
  425. if(deESCFields.includes(dataCode)){
  426. args.editingText = me.isDef(args.editingText) ? args.editingText.toString().replace(/[\r\n]/g, ' ') : '';
  427. args.sheet.setValue(args.row, args.col, args.editingText);
  428. }
  429. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  430. updateArr = [],
  431. addArr = [];
  432. me.editingRowIdx = args.row;
  433. if (me.currentEditingRation["ID"]) {
  434. if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
  435. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  436. }
  437. else {
  438. rObj["ID"] = me.currentEditingRation["ID"];
  439. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  440. me.addRationItem = rObj;
  441. if(dataCode === 'code'){
  442. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  443. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code.toString()), 1);
  444. me.rationsCodes.push(rObj.code.toString());
  445. updateArr.push(rObj);
  446. }
  447. else{
  448. alert("编码已存在!");
  449. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  450. }
  451. }
  452. else if(dataCode === 'feeType'){//取费专业控制为整数
  453. if(me.isInt(rObj[dataCode])){
  454. updateArr.push(rObj);
  455. }
  456. else {
  457. rObj[dataCode] = '';
  458. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  459. }
  460. }
  461. else{
  462. updateArr.push(rObj);
  463. }
  464. }
  465. }
  466. }
  467. else if(!me.currentEditingRation["ID"]) {
  468. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  469. //addArr.push(rObj);
  470. me.addRationItem = rObj;
  471. if(rObj.code && rObj.code.toString().trim().length > 0){
  472. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  473. //jobContent
  474. /* if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  475. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  476. }
  477. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  478. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  479. }*/
  480. me.setInitPrc(rObj);
  481. if (rObj.code && rObj.code !== '') {
  482. rObj.code = rObj.code.toUpperCase();
  483. }
  484. addArr.push(rObj);
  485. me.rationsCodes.push(rObj.code.toString());
  486. me.addRationItem = null;
  487. }
  488. else{
  489. alert('编码已存在!');
  490. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  491. }
  492. }
  493. else if(rObj.code && rObj.code.toString.trim().length === 0){
  494. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  495. }
  496. }
  497. }
  498. if (updateArr.length > 0 || addArr.length > 0) {
  499. me.currentEditingRation = null;
  500. me.mixUpdate = 1;
  501. me.mixUpdateRequest(updateArr, addArr, []);
  502. }
  503. },
  504. canPasted: function (beginCol, maxCol) {
  505. let rst = false;
  506. if(maxCol < 3 || beginCol > 6){
  507. rst = true;
  508. }
  509. return rst;
  510. },
  511. onClipboardPasting: function(sender, args) {
  512. let me = rationOprObj;
  513. let maxCol = args.cellRange.col + args.cellRange.colCount -1;
  514. if(!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1){
  515. args.cancel = true;
  516. }
  517. },
  518. //todo: overwrite?
  519. onClipboardPasted: function(e, info) {
  520. console.log('cp');
  521. let me = rationOprObj;
  522. let cacheSection = me.getCache();
  523. let updateArr = [], addArr = [];
  524. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  525. for (let i = 0; i < items.length; i++) {
  526. if (items[i].code && items[i].code !== '') {
  527. items[i].code = items[i].code.toUpperCase();
  528. }
  529. let rowIdx = info.cellRange.row + i;
  530. if (cacheSection) {
  531. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  532. items[i].unit = rowIdx < cacheSection.length && typeof cacheSection[rowIdx].unit !== 'undefined' ? cacheSection[rowIdx].unit : '';
  533. }*/
  534. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  535. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  536. //jobConten
  537. /*if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  538. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  539. }
  540. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  541. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  542. }*/
  543. me.setInitPrc(items[i]);
  544. addArr.push(items[i]);
  545. me.rationsCodes.push(items[i].code.toString());
  546. }
  547. else{
  548. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  549. }
  550. }
  551. else if(cacheSection[rowIdx]){
  552. for(let col = 0; col < me.setting.header.length; col++){
  553. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  554. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  555. }
  556. }
  557. if(items[i].feeType && !me.isInt(items[i].feeType)){
  558. items[i].feeType = '';
  559. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  560. }
  561. if(info.cellRange.col === 0){
  562. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  563. items[i].ID = cacheSection[rowIdx].ID;
  564. updateArr.push(items[i]);
  565. }
  566. else{
  567. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  568. }
  569. }
  570. else{
  571. items[i].ID = cacheSection[rowIdx].ID;
  572. updateArr.push(items[i]);
  573. }
  574. }
  575. } else {
  576. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  577. items[i].unit = '';
  578. }*/
  579. //add
  580. if(info.cellRange.col === 0){
  581. //是否含有已存在的编号
  582. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  583. //jobConten
  584. /* if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  585. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  586. }
  587. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  588. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  589. }*/
  590. me.setInitPrc(items[i]);
  591. addArr.push(items[i]);
  592. }
  593. }
  594. }
  595. };
  596. if (updateArr.length > 0 || addArr.length > 0) {
  597. console.log(updateArr);
  598. me.mixUpdate = 1;
  599. me.mixUpdateRequest(updateArr, addArr, []);
  600. }
  601. else{
  602. me.getRationItems(me.currentSectionId);
  603. }
  604. },
  605. setInitPrc: function (obj) {
  606. obj.labourPrice = 0;
  607. obj.materialPrice = 0;
  608. obj.machinePrice = 0;
  609. obj.basePrice = 0;
  610. },
  611. mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
  612. let me = rationOprObj;
  613. me.saveInString(updateArr);
  614. CommonAjax.post('/complementaryRation/api/mixUpdateRationItems', {sectionId: me.currentSectionId, updateItems: updateArr, addItems: addArr, removeIds: removeIds}, function (rstData) {
  615. let cacheSection = me.updateCache(addArr, updateArr, removeIds, rstData);
  616. me.sortByCode(cacheSection);
  617. /*cacheSection.sort(function(a, b){
  618. let rst = 0;
  619. if (a.code > b.code) rst = 1
  620. else if (a.code < b.code) rst = -1;
  621. return rst;
  622. });*/
  623. //add
  624. let curRow = me.workBook.getActiveSheet().getActiveRowIndex();
  625. me.rationSelInit(curRow);
  626. //add
  627. //jobContent
  628. /*if(jobContentOprObj ){
  629. jobContentOprObj.currentRationItems = cacheSection;
  630. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  631. if(cacheSection.length === 0){
  632. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  633. }
  634. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  635. if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  636. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  637. }
  638. }
  639. if(annotationOprObj ){
  640. annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
  641. if(cacheSection.length === 0){
  642. annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  643. }
  644. annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
  645. if(annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL){
  646. annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
  647. }
  648. }*/
  649. me.showRationItems(me.currentSectionId);
  650. me.mixUpdate = 0;
  651. me.mixDel = 0;
  652. me.workBook.focus(true);
  653. if(callback) callback();
  654. }, function () {
  655. me.getRationItems(me.currentSectionId);
  656. });
  657. },
  658. getRationItems: function(sectionID, callback = null){
  659. if (sectionID != -1) {
  660. let me = rationOprObj;
  661. me.mixUpdate = 0;
  662. me.currentSectionId = sectionID;
  663. if (me.currentRations["_SEC_ID_" + sectionID]) {
  664. //jobContent--
  665. /* jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  666. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);*/
  667. //annotation
  668. //annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  669. me.showRationItems(sectionID);
  670. if (!isReadOnly) {
  671. sectionTreeObj.removeBtn.removeClass('disabled');
  672. }
  673. if(callback){
  674. callback();
  675. }
  676. } else {
  677. CommonAjax.post('/complementaryRation/api/getRationItems', {sectionId: sectionID}, function (rstData) {
  678. me.currentRations["_SEC_ID_" + sectionID] = rstData;
  679. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  680. //job--
  681. /*jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  682. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);*/
  683. //annotation
  684. //annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  685. me.showRationItems(sectionID);
  686. if (!isReadOnly) {
  687. sectionTreeObj.removeBtn.removeClass('disabled');
  688. }
  689. if(callback) {
  690. callback();
  691. }
  692. }, function () {
  693. if (!isReadOnly) {
  694. sectionTreeObj.removeBtn.removeClass('disabled');
  695. }
  696. });
  697. }
  698. }
  699. },
  700. showRationItems: function(sectionID){
  701. let me = rationOprObj,
  702. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  703. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  704. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
  705. if (me.workBook) {
  706. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  707. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID]) {
  708. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  709. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  710. if(me.mixDel === 1){
  711. let row = me.workBook.getSheet(0).getSelections()[0].row;
  712. if (cacheSection && row < cacheSection.length) {
  713. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  714. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  715. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  716. rationGLJOprObj.getGljItems(cacheSection[row]);
  717. rationCoeOprObj.getCoeItems(cacheSection[row]);
  718. rationAssistOprObj.getAssItems(cacheSection[row]);
  719. }
  720. else {
  721. rationGLJOprObj.currentRationItem = null;
  722. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  723. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  724. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  725. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  726. }
  727. }
  728. } else {
  729. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  730. //清除ration数据及工料机数据
  731. rationGLJOprObj.currentRationItem = null;
  732. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  733. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  734. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  735. }
  736. }
  737. sectionTreeObj.workBook.focus(true);
  738. },
  739. sortByCode: function(arr){
  740. function recurCompare(a, b, index){
  741. if (a[index] && !b[index]) {
  742. return 1;
  743. } else if (!a[index] && b[index]) {
  744. return -1;
  745. } else if (a[index] && b[index]) {
  746. let aV = a[index],
  747. bV = b[index];
  748. if (!isNaN(aV) && !isNaN(bV)) {
  749. aV = parseFloat(a[index]);
  750. bV = parseFloat(b[index]);
  751. }
  752. if (aV > bV) {
  753. return 1;
  754. } else if (aV < bV) {
  755. return -1;
  756. } else {
  757. return recurCompare(a, b, index + 1);
  758. }
  759. }
  760. return 0;
  761. }
  762. arr.sort(function (a, b) {
  763. let aArr = a.code.split('-'),
  764. bArr = b.code.split('-');
  765. return recurCompare(aArr, bArr, 0);
  766. });
  767. },
  768. saveInString(datas){
  769. for(let i = 0, len = datas.length; i < len; i++){
  770. let data = datas[i];
  771. if(data.labourPrice !== undefined && data.labourPrice){
  772. data.labourPrice = data.labourPrice.toString();
  773. }
  774. if(data.materialPrice !== undefined && data.materialPrice){
  775. data.materialPrice = data.materialPrice.toString();
  776. }
  777. if(data.machinePrice !== undefined && data.machinePrice){
  778. data.machinePrice = data.machinePrice.toString();
  779. }
  780. if(data.basePrice !== undefined && data.basePrice){
  781. data.basePrice = data.basePrice.toString();
  782. }
  783. if(data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0){
  784. for(let j = 0, jLen = data.rationGljList.length; j < jLen; j++){
  785. let raGljObj = data.rationGljList[j];
  786. if(raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt){
  787. raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
  788. }
  789. }
  790. }
  791. }
  792. }
  793. }