ration.js 40 KB

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