ration.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. $("#gongliao").click(function(){
  5. $(this).attr('href', "/rationRepository/lmm" + "?repository=" + getQueryString("repository"))
  6. });
  7. $("#fuzhu").click(function(){
  8. $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
  9. });
  10. $("#anzhuang").click(function(){
  11. $(this).attr('href', "/rationRepository/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. setting: {
  25. header:[
  26. {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
  27. {headerName:"名称",headerWidth:280,dataCode:"name", dataType: "String"},
  28. {headerName:"计量单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
  29. {headerName:"人工费",headerWidth:120,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  30. {headerName:"材料费",headerWidth:120,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  31. {headerName:"机械费",headerWidth:120,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  32. {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  33. {headerName:"显示名称(以%s表示参数)",headerWidth:280,dataCode:"caption", dataType: "String"},
  34. {headerName:"取费专业",headerWidth:100,dataCode:"feeType", dataType: "Number", hAlign: "center"}
  35. ],
  36. view:{
  37. comboBox:[
  38. {row:-1,col:2,rowCount:-1,colCount:1}
  39. ],
  40. lockedCells:[
  41. {row:-1,col:3,rowCount:-1, colCount:1}
  42. ],
  43. lockColumns: [
  44. 3, 4, 5, 6
  45. ]
  46. }
  47. },
  48. buildSheet: function(container) {
  49. let rationRepId = getQueryString("repository");
  50. let me = rationOprObj;
  51. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  52. me.getRationsCodes(rationRepId);
  53. me.onContextmenuOpr();
  54. me.rationDelOpr();
  55. me.setCombo(me.workBook.getSheet(0), 'dynamic');
  56. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  57. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  58. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  59. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  60. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  61. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  62. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  63. },
  64. setCombo: function (sheet, combo) {
  65. let me = rationOprObj;
  66. sheet.suspendPaint();
  67. sheet.suspendEvent();
  68. if(combo){
  69. combo = sheetCommonObj.getDynamicCombo();
  70. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  71. }
  72. sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
  73. sheet.resumePaint();
  74. sheet.resumeEvent();
  75. },
  76. onSelectionChanged: function (sender, info) {
  77. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  78. let row = info.newSelections[0].row;
  79. let me = rationOprObj,
  80. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  81. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  82. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  83. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  84. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  85. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  86. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  87. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  88. let cacheSection = me.getCache();
  89. if (cacheSection && row < cacheSection.length) {
  90. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  91. me.workBook.focus(true);
  92. });
  93. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  94. me.workBook.focus(true);
  95. });
  96. rationAssistOprObj.getAssItems(cacheSection[row]);
  97. rationInstObj.getInstItems(cacheSection[row], function () {
  98. me.workBook.focus(true);
  99. });
  100. }
  101. else {
  102. rationGLJOprObj.currentRationItem = null;
  103. }
  104. me.workBook.focus(true);
  105. }
  106. },
  107. isInt: function (num) {
  108. return !isNaN(num) && num % 1 === 0;
  109. },
  110. getCache: function() {
  111. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  112. if (!(rst)) {
  113. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  114. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  115. }
  116. return rst;
  117. },
  118. updateCache: function(addArr, updateArr, removeIds, result) {
  119. let me = this, cacheSection = me.getCache();
  120. if (addArr.length > 0) {
  121. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  122. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  123. }
  124. for (let i = removeIds.length - 1; i >= 0; i--) {
  125. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  126. if (cacheSection[j]["ID"] == removeIds[i]) {
  127. cacheSection.splice(j,1);
  128. }
  129. }
  130. }
  131. if (result && result.data.ops && result.data.ops.length > 0) {
  132. for (let i = 0; i < result.data.ops.length; i++) {
  133. for (let j = 0; j < cacheSection.length; j++) {
  134. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  135. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  136. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  137. cacheSection[j]["rationCoeList"] = result.data.ops[i]["rationCoeList"];
  138. cacheSection[j]["rationAssList"] = result.data.ops[i]["rationAssList"];
  139. cacheSection[j]["rationInstList"] = result.data.ops[i]["rationInstList"];
  140. }
  141. }
  142. }
  143. }
  144. for (let i = 0; i < updateArr.length; i++) {
  145. for (let j = 0; j < cacheSection.length; j++) {
  146. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  147. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  148. cacheSection[j] = updateArr[i];
  149. }
  150. } else {
  151. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  152. cacheSection[j] = updateArr[i];
  153. }
  154. }
  155. }
  156. }
  157. return cacheSection;
  158. },
  159. onContextmenuOpr: function () {//右键菜单
  160. let me = this;
  161. $.contextMenu({
  162. selector: '#rationItemsSheet',
  163. build: function($triggerElement, e){
  164. //控制允许右键菜单在哪个位置出现
  165. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  166. let sheet = me.workBook.getSheet(0);
  167. let delDis = false;
  168. let cacheSection = me.getCache();
  169. let ration = cacheSection[target.row];
  170. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  171. if(typeof target.row !== 'undefined'){
  172. //控制按钮是否可用
  173. sheet.setActiveCell(target.row, target.col);
  174. if(!cacheSection ||target.row >= cacheSection.length){//右键定位在有数据的行,删除键才显示可用
  175. delDis = true;
  176. }
  177. else{//有数据
  178. if(typeof target.col === 'undefined'){//定位不在表格内
  179. delDis = true;
  180. }
  181. }
  182. }
  183. else{
  184. delDis = true;
  185. }
  186. return {
  187. callback: function(){},
  188. items: {
  189. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  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){
  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){
  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){
  235. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  236. }
  237. }
  238. }
  239. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  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. if(!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1){
  300. args.cancel = true;
  301. }
  302. else{
  303. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  304. me.currentEditingRation = rObj;
  305. let cacheSection = me.getCache();
  306. if (cacheSection) {
  307. for (let j = 0; j < cacheSection.length; j++) {
  308. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  309. rObj["ID"] = cacheSection[j]["ID"];
  310. break;
  311. }
  312. }
  313. }
  314. }
  315. },
  316. onCellEditEnd: function(sender, args) {
  317. let edV = args.sheet.getValue(args.row, args.col);
  318. if(edV){
  319. args.sheet.setValue(args.row, args.col, edV.toString().trim());
  320. }
  321. let me = rationOprObj, rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  322. updateArr = [], addArr = [];
  323. let dataCode = me.setting.header[args.col].dataCode;
  324. me.editingRowIdx = args.row;
  325. if (me.currentEditingRation["ID"]) {
  326. if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
  327. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  328. }
  329. else {
  330. rObj["ID"] = me.currentEditingRation["ID"];
  331. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  332. me.addRationItem = rObj;
  333. if(dataCode === 'code'){
  334. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  335. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code.toString()), 1);
  336. me.rationsCodes.push(rObj.code.toString());
  337. updateArr.push(rObj);
  338. }
  339. else{
  340. alert("编码已存在!");
  341. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  342. }
  343. }
  344. else if(dataCode === 'feeType'){//取费专业控制为整数
  345. if(me.isInt(rObj[dataCode])){
  346. updateArr.push(rObj);
  347. }
  348. else {
  349. rObj[dataCode] = '';
  350. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  351. }
  352. }
  353. else{
  354. updateArr.push(rObj);
  355. }
  356. }
  357. }
  358. }
  359. else if(!me.currentEditingRation["ID"]) {
  360. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  361. //addArr.push(rObj);
  362. me.addRationItem = rObj;
  363. if(rObj.code && rObj.code.toString().trim().length > 0){
  364. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  365. //jobContent
  366. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  367. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  368. }
  369. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  370. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  371. }
  372. me.setInitPrc(rObj);
  373. addArr.push(rObj);
  374. me.rationsCodes.push(rObj.code.toString());
  375. me.addRationItem = null;
  376. }
  377. else{
  378. alert('编码已存在!');
  379. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  380. }
  381. }
  382. else if(rObj.code && rObj.code.toString.trim().length === 0){
  383. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  384. }
  385. }
  386. }
  387. if (updateArr.length > 0 || addArr.length > 0) {
  388. me.currentEditingRation = null;
  389. me.mixUpdate = 1;
  390. me.mixUpdateRequest(updateArr, addArr, []);
  391. }
  392. },
  393. canPasted: function (beginCol, maxCol) {
  394. let rst = false;
  395. if(maxCol < 3 || beginCol > 6){
  396. rst = true;
  397. }
  398. return rst;
  399. },
  400. onClipboardPasting: function(sender, args) {
  401. let me = rationOprObj;
  402. let maxCol = args.cellRange.col + args.cellRange.colCount -1;
  403. if(!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1){
  404. args.cancel = true;
  405. }
  406. },
  407. //todo: overwrite?
  408. onClipboardPasted: function(e, info) {
  409. let me = rationOprObj;
  410. let cacheSection = me.getCache();
  411. let updateArr = [], addArr = [];
  412. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  413. for (let i = 0; i < items.length; i++) {
  414. let rowIdx = info.cellRange.row + i;
  415. if (cacheSection) {
  416. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  417. items[i].unit = rowIdx < cacheSection.length && typeof cacheSection[rowIdx].unit !== 'undefined' ? cacheSection[rowIdx].unit : '';
  418. }*/
  419. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  420. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  421. //jobConten
  422. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  423. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  424. }
  425. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  426. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  427. }
  428. me.setInitPrc(items[i]);
  429. addArr.push(items[i]);
  430. me.rationsCodes.push(items[i].code.toString());
  431. }
  432. else{
  433. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  434. }
  435. }
  436. else if(cacheSection[rowIdx]){
  437. for(let col = 0; col < me.setting.header.length; col++){
  438. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  439. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  440. }
  441. }
  442. if(items[i].feeType && !me.isInt(items[i].feeType)){
  443. items[i].feeType = '';
  444. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  445. }
  446. if(info.cellRange.col === 0){
  447. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  448. items[i].ID = cacheSection[rowIdx].ID;
  449. updateArr.push(items[i]);
  450. }
  451. else{
  452. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  453. }
  454. }
  455. else{
  456. items[i].ID = cacheSection[rowIdx].ID;
  457. updateArr.push(items[i]);
  458. }
  459. }
  460. } else {
  461. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  462. items[i].unit = '';
  463. }*/
  464. //add
  465. if(info.cellRange.col === 0){
  466. //是否含有已存在的编号
  467. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  468. //jobConten
  469. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  470. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  471. }
  472. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  473. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  474. }
  475. me.setInitPrc(items[i]);
  476. addArr.push(items[i]);
  477. }
  478. }
  479. }
  480. };
  481. if (updateArr.length > 0 || addArr.length > 0) {
  482. me.mixUpdate = 1;
  483. me.mixUpdateRequest(updateArr, addArr, []);
  484. }
  485. else{
  486. me.getRationItems(me.currentSectionId);
  487. }
  488. },
  489. setInitPrc: function (obj) {
  490. obj.labourPrice = 0;
  491. obj.materialPrice = 0;
  492. obj.machinePrice = 0;
  493. obj.basePrice = 0;
  494. },
  495. isValidUnit: function (rationObj, validUnits) {
  496. let rst = true;
  497. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  498. rst = false;
  499. }
  500. return rst;
  501. },
  502. getRationsCodes: function (repId) {
  503. let me = rationOprObj;
  504. $.ajax({
  505. type: 'post',
  506. url: 'api/getRationsCodes',
  507. data: {data: JSON.stringify({repId: repId})},
  508. dataType: 'json',
  509. success: function (result) {
  510. if(!result.error){
  511. me.rationsCodes = result.data;
  512. }
  513. }
  514. })
  515. },
  516. mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
  517. let me = rationOprObj;
  518. me.saveInString(updateArr);
  519. $.ajax({
  520. type:"POST",
  521. url:"api/mixUpdateRationItems",
  522. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  523. dataType:"json",
  524. cache:false,
  525. timeout:20000,
  526. success:function(result){
  527. if (result.error) {
  528. alert('error');
  529. me.getRationItems(me.currentSectionId);
  530. } else {
  531. let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  532. cacheSection.sort(function(a, b){
  533. let rst = 0;
  534. if (a.code > b.code) rst = 1
  535. else if (a.code < b.code) rst = -1;
  536. return rst;
  537. });
  538. //jobContent
  539. if(jobContentOprObj ){
  540. jobContentOprObj.currentRationItems = cacheSection;
  541. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  542. if(cacheSection.length === 0){
  543. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  544. }
  545. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  546. if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  547. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  548. }
  549. }
  550. if(annotationOprObj ){
  551. annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
  552. if(cacheSection.length === 0){
  553. annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  554. }
  555. annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
  556. if(annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL){
  557. annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
  558. }
  559. }
  560. me.showRationItems(me.currentSectionId);
  561. me.mixUpdate = 0;
  562. me.mixDel = 0;
  563. }
  564. if(callback) callback();
  565. },
  566. error:function(){
  567. }
  568. });
  569. },
  570. getRationItems: function(sectionID){
  571. if (sectionID != -1) {
  572. let me = rationOprObj;
  573. me.mixUpdate = 0;
  574. me.currentSectionId = sectionID;
  575. if (me.currentRations["_SEC_ID_" + sectionID]) {
  576. //jobContent--
  577. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  578. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  579. //annotation
  580. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  581. me.showRationItems(sectionID);
  582. } else {
  583. $.ajax({
  584. type:"POST",
  585. url:"api/getRationItems",
  586. data:{"rationRepId": pageOprObj.rationLibId, "sectionID": sectionID},
  587. dataType:"json",
  588. cache:false,
  589. timeout:10000,
  590. success:function(result){
  591. if (result) {
  592. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  593. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  594. //job--
  595. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  596. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  597. //annotation
  598. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  599. me.showRationItems(sectionID);
  600. }
  601. },
  602. error:function(err){
  603. alert(err);
  604. }
  605. })
  606. }
  607. }
  608. },
  609. showRationItems: function(sectionID){
  610. let me = rationOprObj,
  611. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  612. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  613. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  614. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  615. if (me.workBook) {
  616. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  617. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  618. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  619. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  620. //combo
  621. //sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
  622. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  623. if(me.mixDel === 1){
  624. let row = me.workBook.getSheet(0).getSelections()[0].row;
  625. if (cacheSection && row < cacheSection.length) {
  626. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  627. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  628. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  629. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  630. rationGLJOprObj.getGljItems(cacheSection[row]);
  631. rationCoeOprObj.getCoeItems(cacheSection[row]);
  632. rationAssistOprObj.getAssItems(cacheSection[row]);
  633. rationInstObj.getInstItems(cacheSection[row]);
  634. }
  635. else {
  636. rationGLJOprObj.currentRationItem = null;
  637. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  638. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  639. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  640. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  641. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  642. }
  643. }
  644. } else {
  645. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  646. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  647. //清除ration数据及工料机数据
  648. rationGLJOprObj.currentRationItem = null;
  649. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  650. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  651. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  652. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  653. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  654. }
  655. //--- me.workBook.focus(true);
  656. }
  657. sectionTreeObj.workBook.focus(true);
  658. },
  659. sortByCode: function(arr){
  660. function compare(){
  661. return function (a, b) {
  662. let rst = 0;
  663. if (a.code > b.code) {
  664. rst = 1;
  665. }
  666. else if (a.code < b.code) {
  667. rst = -1;
  668. }
  669. return rst;
  670. }
  671. }
  672. arr.sort(compare());
  673. },
  674. saveInString(datas){
  675. for(let i = 0, len = datas.length; i < len; i++){
  676. let data = datas[i];
  677. if(data.labourPrice !== undefined && data.labourPrice){
  678. data.labourPrice = data.labourPrice.toString();
  679. }
  680. if(data.materialPrice !== undefined && data.materialPrice){
  681. data.materialPrice = data.materialPrice.toString();
  682. }
  683. if(data.machinePrice !== undefined && data.machinePrice){
  684. data.machinePrice = data.machinePrice.toString();
  685. }
  686. if(data.basePrice !== undefined && data.basePrice){
  687. data.basePrice = data.basePrice.toString();
  688. }
  689. if(data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0){
  690. for(let j = 0, jLen = data.rationGljList.length; j < jLen; j++){
  691. let raGljObj = data.rationGljList[j];
  692. if(raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt){
  693. raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
  694. }
  695. }
  696. }
  697. }
  698. }
  699. }