ration.js 36 KB

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