ration.js 38 KB

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