ration.js 35 KB

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