ration.js 35 KB

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