ration.js 41 KB

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