ration.js 41 KB

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