ration.js 41 KB

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