ration.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. $("#gongliao").click(function(){
  5. $(this).attr('href', "/complementaryRation/glj" + "?repository=" + getQueryString("repository"))
  6. });
  7. $("#fuzhu").click(function(){
  8. $(this).attr('href', "/complementaryRation/coe" + "?repository=" + getQueryString("repository"))
  9. });
  10. $("#anzhuang").click(function(){
  11. $(this).attr('href', "/complementaryRation/installation" + "?repository=" + getQueryString("repository"))
  12. });
  13. const digital = {
  14. gljPrc: -3,//计算定额基价时单个工料机价格取三位
  15. rationBasePrc: -2,
  16. consumeAmt: -3
  17. };
  18. let rationOprObj = {
  19. workBook: null,
  20. currentRations: {},
  21. currentEditingRation: null,
  22. currentSectionId: -1,
  23. rationsCodes: [],
  24. type: {std: 'std', complementary: 'complementary'},
  25. setting: {
  26. header:[
  27. {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
  28. {headerName:"名称",headerWidth:280,dataCode:"name", dataType: "String"},
  29. {headerName:"计量单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
  30. {headerName:"人工费",headerWidth:120,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  31. {headerName:"材料费",headerWidth:120,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  32. {headerName:"机械费",headerWidth:120,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  33. {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  34. {headerName:"显示名称(以%s表示参数)",headerWidth:280,dataCode:"caption", dataType: "String"},
  35. {headerName:"取费专业",headerWidth:100,dataCode:"feeType", dataType: "Number", hAlign: "center"}
  36. ],
  37. view:{
  38. comboBox:[
  39. {row:-1,col:2,rowCount:-1,colCount:1}
  40. ],
  41. lockedCells:[
  42. {row:-1,col:3,rowCount:-1, colCount:1}
  43. ],
  44. lockColumns: [
  45. 3, 4, 5, 6
  46. ]
  47. }
  48. },
  49. buildSheet: function(container) {
  50. let rationRepId = getQueryString("repository");
  51. let me = rationOprObj;
  52. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  53. me.getRationsCodes(rationRepId);
  54. me.onContextmenuOpr();
  55. me.rationDelOpr();
  56. me.setCombo(me.workBook.getSheet(0), 'dynamic');
  57. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  58. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  59. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  60. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  61. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  62. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  63. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  64. },
  65. setCombo: function (sheet, combo) {
  66. let me = rationOprObj;
  67. sheet.suspendPaint();
  68. sheet.suspendEvent();
  69. if(combo){
  70. combo = sheetCommonObj.getDynamicCombo();
  71. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  72. }
  73. sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
  74. sheet.resumePaint();
  75. sheet.resumeEvent();
  76. },
  77. onSelectionChanged: function (sender, info) {
  78. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  79. let row = info.newSelections[0].row;
  80. let me = rationOprObj,
  81. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  82. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  83. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  84. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  85. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  86. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  87. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  88. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  89. let cacheSection = me.getCache();
  90. if (cacheSection && row < cacheSection.length) {
  91. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  92. me.workBook.focus(true);
  93. });
  94. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  95. me.workBook.focus(true);
  96. });
  97. rationAssistOprObj.getAssItems(cacheSection[row]);
  98. rationInstObj.getInstItems(cacheSection[row], function () {
  99. me.workBook.focus(true);
  100. });
  101. }
  102. else {
  103. rationGLJOprObj.currentRationItem = null;
  104. }
  105. me.workBook.focus(true);
  106. }
  107. },
  108. isDef: function (v) {
  109. return v !== undefined && v !== null;
  110. },
  111. isInt: function (num) {
  112. return !isNaN(num) && num % 1 === 0;
  113. },
  114. getCache: function() {
  115. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  116. if (!(rst)) {
  117. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  118. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  119. }
  120. return rst;
  121. },
  122. updateCache: function(addArr, updateArr, removeIds, rstData) {
  123. let me = this, cacheSection = me.getCache();
  124. if (addArr.length > 0) {
  125. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  126. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  127. }
  128. for (let i = removeIds.length - 1; i >= 0; i--) {
  129. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  130. if (cacheSection[j]["ID"] == removeIds[i]) {
  131. cacheSection.splice(j,1);
  132. }
  133. }
  134. }
  135. if (rstData && rstData.ops && rstData.ops.length > 0) {
  136. for (let i = 0; i < rstData.ops.length; i++) {
  137. for (let j = 0; j < cacheSection.length; j++) {
  138. if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
  139. cacheSection[j]["ID"] = rstData.ops[i]["ID"];
  140. cacheSection[j]["rationGljList"] = rstData.ops[i]["rationGljList"];
  141. cacheSection[j]["rationCoeList"] = rstData.ops[i]["rationCoeList"];
  142. cacheSection[j]["rationAssList"] = rstData.ops[i]["rationAssList"];
  143. }
  144. }
  145. }
  146. }
  147. for (let i = 0; i < updateArr.length; i++) {
  148. for (let j = 0; j < cacheSection.length; j++) {
  149. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  150. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  151. cacheSection[j] = updateArr[i];
  152. cacheSection[j].type = me.type.complementary;
  153. }
  154. } else {
  155. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  156. cacheSection[j] = updateArr[i];
  157. cacheSection[j].type = me.type.complementary;
  158. }
  159. }
  160. }
  161. }
  162. return cacheSection;
  163. },
  164. onContextmenuOpr: function () {//右键菜单
  165. let me = this;
  166. $.contextMenu({
  167. selector: '#rationItemsSheet',
  168. build: function($triggerElement, e){
  169. //控制允许右键菜单在哪个位置出现
  170. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  171. let sheet = me.workBook.getSheet(0);
  172. let delDis = false;
  173. let cacheSection = me.getCache();
  174. let ration = cacheSection[target.row];
  175. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  176. if(typeof target.row !== 'undefined'){
  177. //控制按钮是否可用
  178. sheet.setActiveCell(target.row, target.col);
  179. if(!cacheSection ||target.row >= cacheSection.length){//右键定位在有数据的行,删除键才显示可用
  180. delDis = true;
  181. }
  182. else{//有数据
  183. if(typeof target.col === 'undefined'){//定位不在表格内
  184. delDis = true;
  185. }
  186. else {
  187. delDis = ration.type === 'std' ? true : false;
  188. }
  189. }
  190. }
  191. else{
  192. delDis = true;
  193. }
  194. return {
  195. callback: function(){},
  196. items: {
  197. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  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. }, function () {
  571. me.getRationItems(me.currentSectionId);
  572. });
  573. },
  574. getRationItems: function(sectionID){
  575. if (sectionID != -1) {
  576. let me = rationOprObj;
  577. me.mixUpdate = 0;
  578. me.currentSectionId = sectionID;
  579. if (me.currentRations["_SEC_ID_" + sectionID]) {
  580. //jobContent--
  581. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  582. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  583. //annotation
  584. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  585. me.showRationItems(sectionID);
  586. } else {
  587. CommonAjax.post('/complementaryRation/api/getRationItems', {rationRepId: pageOprObj.rationLibId, sectionId: sectionID}, function (rstData) {
  588. me.currentRations["_SEC_ID_" + sectionID] = rstData;
  589. me.currentRations["_SEC_ID_" + sectionID] = me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  590. //job--
  591. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  592. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  593. //annotation
  594. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  595. me.showRationItems(sectionID);
  596. });
  597. }
  598. }
  599. },
  600. setColor: function (cache) {
  601. let me = this;
  602. let sheet = me.workBook.getSheet(0);
  603. sheet.suspendPaint();
  604. for(let i = 0, len = cache.length; i < len; i++){
  605. if(cache[i].type === me.type.complementary){
  606. sheet.getRange(i, -1, 1, -1).foreColor('gray');
  607. }
  608. else {
  609. sheet.getRange(i, -1, 1, -1).foreColor('');
  610. }
  611. }
  612. sheet.resumePaint();
  613. },
  614. showRationItems: function(sectionID){
  615. let me = rationOprObj,
  616. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  617. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  618. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  619. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  620. if (me.workBook) {
  621. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  622. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  623. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  624. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  625. me.setColor(cacheSection);
  626. //combo
  627. //sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
  628. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  629. if(me.mixDel === 1){
  630. let row = me.workBook.getSheet(0).getSelections()[0].row;
  631. if (cacheSection && row < cacheSection.length) {
  632. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  633. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  634. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  635. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  636. rationGLJOprObj.getGljItems(cacheSection[row]);
  637. rationCoeOprObj.getCoeItems(cacheSection[row]);
  638. rationAssistOprObj.getAssItems(cacheSection[row]);
  639. rationInstObj.getInstItems(cacheSection[row]);
  640. }
  641. else {
  642. rationGLJOprObj.currentRationItem = null;
  643. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  644. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  645. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  646. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  647. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  648. }
  649. }
  650. } else {
  651. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  652. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  653. //清除ration数据及工料机数据
  654. rationGLJOprObj.currentRationItem = null;
  655. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  656. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  657. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  658. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  659. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  660. }
  661. //--- me.workBook.focus(true);
  662. }
  663. sectionTreeObj.workBook.focus(true);
  664. },
  665. sortByCode: function(arr){
  666. let me = rationOprObj;
  667. //std complementary
  668. let stdArr = [], compleArr = [];
  669. for(let i = 0, len = arr.length; i < len; i++){
  670. if(arr[i].type === me.type.std){
  671. stdArr.push(arr[i]);
  672. }
  673. else if(arr[i].type === me.type.complementary){
  674. compleArr.push(arr[i]);
  675. }
  676. }
  677. stdArr.sort(compare());
  678. compleArr.sort(compare());
  679. return stdArr.concat(compleArr);
  680. function compare(){
  681. return function (a, b) {
  682. let rst = 0;
  683. if (a.code > b.code) {
  684. rst = 1;
  685. }
  686. else if (a.code < b.code) {
  687. rst = -1;
  688. }
  689. return rst;
  690. }
  691. }
  692. // arr.sort(compare());
  693. },
  694. saveInString(datas){
  695. for(let i = 0, len = datas.length; i < len; i++){
  696. let data = datas[i];
  697. if(data.labourPrice !== undefined && data.labourPrice){
  698. data.labourPrice = data.labourPrice.toString();
  699. }
  700. if(data.materialPrice !== undefined && data.materialPrice){
  701. data.materialPrice = data.materialPrice.toString();
  702. }
  703. if(data.machinePrice !== undefined && data.machinePrice){
  704. data.machinePrice = data.machinePrice.toString();
  705. }
  706. if(data.basePrice !== undefined && data.basePrice){
  707. data.basePrice = data.basePrice.toString();
  708. }
  709. if(data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0){
  710. for(let j = 0, jLen = data.rationGljList.length; j < jLen; j++){
  711. let raGljObj = data.rationGljList[j];
  712. if(raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt){
  713. raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
  714. }
  715. }
  716. }
  717. }
  718. }
  719. }