ration.js 37 KB

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