ration.js 37 KB

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