ration.js 36 KB

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