ration.js 36 KB

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