ration.js 37 KB

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