ration.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
  45. me.getRationsCodes(rationRepId);
  46. me.onContextmenuOpr();
  47. me.rationDelOpr();
  48. me.setCombo(me.workBook.getSheet(0), 'dynamic');
  49. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  50. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  51. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  52. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  53. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  54. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  55. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  56. },
  57. setCombo: function (sheet, combo) {
  58. let me = rationOprObj;
  59. sheet.suspendPaint();
  60. sheet.suspendEvent();
  61. if(combo){
  62. combo = sheetCommonObj.getDynamicCombo();
  63. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  64. }
  65. sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
  66. sheet.resumePaint();
  67. sheet.resumeEvent();
  68. },
  69. onSelectionChanged: function (sender, info) {
  70. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  71. let row = info.newSelections[0].row;
  72. let me = rationOprObj,
  73. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  74. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  75. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  76. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  77. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  78. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  79. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  80. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  81. let cacheSection = me.getCache();
  82. if (cacheSection && row < cacheSection.length) {
  83. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  84. me.workBook.focus(true);
  85. });
  86. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  87. me.workBook.focus(true);
  88. });
  89. rationAssistOprObj.getAssItems(cacheSection[row]);
  90. rationInstObj.getInstItems(cacheSection[row], function () {
  91. me.workBook.focus(true);
  92. });
  93. }
  94. else {
  95. rationGLJOprObj.currentRationItem = null;
  96. }
  97. me.workBook.focus(true);
  98. }
  99. },
  100. isDef: function (v) {
  101. return v !== undefined && v !== null;
  102. },
  103. isInt: function (num) {
  104. return !isNaN(num) && num % 1 === 0;
  105. },
  106. getCache: function() {
  107. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  108. if (!(rst)) {
  109. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  110. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  111. }
  112. return rst;
  113. },
  114. updateCache: function(addArr, updateArr, removeIds, rstData) {
  115. let me = this, cacheSection = me.getCache();
  116. if (addArr.length > 0) {
  117. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  118. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  119. }
  120. for (let i = removeIds.length - 1; i >= 0; i--) {
  121. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  122. if (cacheSection[j]["ID"] == removeIds[i]) {
  123. cacheSection.splice(j,1);
  124. }
  125. }
  126. }
  127. if (rstData && rstData.ops && rstData.ops.length > 0) {
  128. for (let i = 0; i < rstData.ops.length; i++) {
  129. for (let j = 0; j < cacheSection.length; j++) {
  130. if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
  131. cacheSection[j]["ID"] = rstData.ops[i]["ID"];
  132. cacheSection[j]["rationGljList"] = rstData.ops[i]["rationGljList"];
  133. cacheSection[j]["rationCoeList"] = rstData.ops[i]["rationCoeList"];
  134. cacheSection[j]["rationAssList"] = rstData.ops[i]["rationAssList"];
  135. }
  136. }
  137. }
  138. }
  139. for (let i = 0; i < updateArr.length; i++) {
  140. for (let j = 0; j < cacheSection.length; j++) {
  141. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  142. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  143. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ? rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] : [];
  144. updateArr[i]['rationCoeList'] = rationCoeOprObj.cache['_Coe_' + cacheSection[j]['ID']] ? rationCoeOprObj.cache['_Coe_' + cacheSection[j]['ID']] : [];
  145. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  146. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  147. cacheSection[j] = updateArr[i];
  148. cacheSection[j].type = me.type.complementary;
  149. }
  150. } else {
  151. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  152. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ? rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] : [];
  153. updateArr[i]['rationCoeList'] = rationCoeOprObj.cache['_Coe_' + cacheSection[j]['ID']] ? rationCoeOprObj.cache['_Coe_' + cacheSection[j]['ID']] : [];
  154. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  155. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  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. sectionTreeObj.workBook.focus(false);
  572. rationOprObj.workBook.focus(true);
  573. }, function () {
  574. me.getRationItems(me.currentSectionId);
  575. });
  576. },
  577. getRationItems: function(sectionID){
  578. if (sectionID != -1) {
  579. let me = rationOprObj;
  580. me.mixUpdate = 0;
  581. me.currentSectionId = sectionID;
  582. if (me.currentRations["_SEC_ID_" + sectionID]) {
  583. //jobContent--
  584. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  585. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  586. //annotation
  587. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  588. me.showRationItems(sectionID);
  589. } else {
  590. CommonAjax.post('/complementaryRation/api/getRationItems', {rationRepId: pageOprObj.rationLibId, sectionId: sectionID}, function (rstData) {
  591. me.currentRations["_SEC_ID_" + sectionID] = rstData;
  592. me.currentRations["_SEC_ID_" + sectionID] = me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  593. //job--
  594. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  595. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  596. //annotation
  597. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  598. me.showRationItems(sectionID);
  599. });
  600. }
  601. }
  602. },
  603. setColor: function (cache) {
  604. let me = this;
  605. let sheet = me.workBook.getSheet(0);
  606. sheet.suspendPaint();
  607. for(let i = 0, len = cache.length; i < len; i++){
  608. if(cache[i].type === me.type.complementary){
  609. sheet.getRange(i, -1, 1, -1).foreColor('gray');
  610. }
  611. else {
  612. sheet.getRange(i, -1, 1, -1).foreColor('');
  613. }
  614. }
  615. sheet.resumePaint();
  616. },
  617. showRationItems: function(sectionID){
  618. let me = rationOprObj,
  619. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  620. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  621. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  622. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  623. if (me.workBook) {
  624. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  625. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  626. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  627. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  628. me.setColor(cacheSection);
  629. //combo
  630. //sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
  631. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  632. if(me.mixDel === 1){
  633. let row = me.workBook.getSheet(0).getSelections()[0].row;
  634. if (cacheSection && row < cacheSection.length) {
  635. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  636. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  637. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  638. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  639. rationGLJOprObj.getGljItems(cacheSection[row]);
  640. rationCoeOprObj.getCoeItems(cacheSection[row]);
  641. rationAssistOprObj.getAssItems(cacheSection[row]);
  642. rationInstObj.getInstItems(cacheSection[row]);
  643. }
  644. else {
  645. rationGLJOprObj.currentRationItem = null;
  646. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  647. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  648. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  649. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  650. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  651. }
  652. }
  653. } else {
  654. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  655. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  656. //清除ration数据及工料机数据
  657. rationGLJOprObj.currentRationItem = null;
  658. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  659. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  660. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  661. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  662. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  663. }
  664. //--- me.workBook.focus(true);
  665. }
  666. sectionTreeObj.workBook.focus(true);
  667. },
  668. sortByCode: function(arr){
  669. let me = rationOprObj;
  670. //std complementary
  671. let stdArr = [], compleArr = [];
  672. for(let i = 0, len = arr.length; i < len; i++){
  673. if(arr[i].type === me.type.std){
  674. stdArr.push(arr[i]);
  675. }
  676. else if(arr[i].type === me.type.complementary){
  677. compleArr.push(arr[i]);
  678. }
  679. }
  680. stdArr.sort(compare());
  681. compleArr.sort(compare());
  682. return stdArr.concat(compleArr);
  683. function compare(){
  684. return function (a, b) {
  685. let rst = 0;
  686. if (a.code > b.code) {
  687. rst = 1;
  688. }
  689. else if (a.code < b.code) {
  690. rst = -1;
  691. }
  692. return rst;
  693. }
  694. }
  695. // arr.sort(compare());
  696. },
  697. saveInString(datas){
  698. for(let i = 0, len = datas.length; i < len; i++){
  699. let data = datas[i];
  700. if(data.labourPrice !== undefined && data.labourPrice){
  701. data.labourPrice = data.labourPrice.toString();
  702. }
  703. if(data.materialPrice !== undefined && data.materialPrice){
  704. data.materialPrice = data.materialPrice.toString();
  705. }
  706. if(data.machinePrice !== undefined && data.machinePrice){
  707. data.machinePrice = data.machinePrice.toString();
  708. }
  709. if(data.basePrice !== undefined && data.basePrice){
  710. data.basePrice = data.basePrice.toString();
  711. }
  712. if(data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0){
  713. for(let j = 0, jLen = data.rationGljList.length; j < jLen; j++){
  714. let raGljObj = data.rationGljList[j];
  715. if(raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt){
  716. raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
  717. }
  718. }
  719. }
  720. }
  721. }
  722. }