ration.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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: "String", 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') {//取费专业控制为整数 20200928 改为文本
  464. updateArr.push(rObj);
  465. /* if(me.isInt(rObj[dataCode])){
  466. updateArr.push(rObj);
  467. }
  468. else {
  469. rObj[dataCode] = '';
  470. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  471. } */
  472. }
  473. else{
  474. updateArr.push(rObj);
  475. }
  476. }
  477. }
  478. }
  479. else if(!me.currentEditingRation["ID"]) {
  480. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  481. //addArr.push(rObj);
  482. me.addRationItem = rObj;
  483. if(rObj.code && rObj.code.toString().trim().length > 0){
  484. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  485. //jobContent
  486. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  487. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  488. }
  489. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  490. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  491. }
  492. me.setInitPrc(rObj);
  493. addArr.push(rObj);
  494. me.rationsCodes.push(rObj.code.toString());
  495. me.addRationItem = null;
  496. }
  497. else{
  498. alert('编码已存在!');
  499. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  500. }
  501. }
  502. else if(rObj.code && rObj.code.toString.trim().length === 0){
  503. me.workBook.getSheet(0).setValue(args.row, args.col, '');
  504. }
  505. }
  506. }
  507. if (updateArr.length > 0 || addArr.length > 0) {
  508. me.currentEditingRation = null;
  509. me.mixUpdate = 1;
  510. me.mixUpdateRequest(updateArr, addArr, []);
  511. }
  512. },
  513. canPasted: function (beginCol, maxCol) {
  514. let rst = false;
  515. if(maxCol < 3 || beginCol > 6){
  516. rst = true;
  517. }
  518. return rst;
  519. },
  520. onClipboardPasting: function(sender, args) {
  521. let me = rationOprObj;
  522. let maxCol = args.cellRange.col + args.cellRange.colCount -1;
  523. if(!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1){
  524. args.cancel = true;
  525. }
  526. },
  527. //todo: overwrite?
  528. onClipboardPasted: function(e, info) {
  529. console.log('cp');
  530. let me = rationOprObj;
  531. let cacheSection = me.getCache();
  532. let updateArr = [], addArr = [];
  533. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  534. for (let i = 0; i < items.length; i++) {
  535. let rowIdx = info.cellRange.row + i;
  536. if (cacheSection) {
  537. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  538. items[i].unit = rowIdx < cacheSection.length && typeof cacheSection[rowIdx].unit !== 'undefined' ? cacheSection[rowIdx].unit : '';
  539. }*/
  540. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  541. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  542. //jobConten
  543. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  544. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  545. }
  546. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  547. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  548. }
  549. me.setInitPrc(items[i]);
  550. addArr.push(items[i]);
  551. me.rationsCodes.push(items[i].code.toString());
  552. }
  553. else{
  554. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  555. }
  556. }
  557. else if(cacheSection[rowIdx]){
  558. for(let col = 0; col < me.setting.header.length; col++){
  559. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  560. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  561. }
  562. }
  563. if(items[i].feeType && !me.isInt(items[i].feeType)){
  564. items[i].feeType = '';
  565. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  566. }
  567. if(info.cellRange.col === 0){
  568. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  569. items[i].ID = cacheSection[rowIdx].ID;
  570. updateArr.push(items[i]);
  571. }
  572. else{
  573. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  574. }
  575. }
  576. else{
  577. items[i].ID = cacheSection[rowIdx].ID;
  578. updateArr.push(items[i]);
  579. }
  580. }
  581. } else {
  582. /* if(!me.isValidUnit(items[i], rationUnits)){//无效单位
  583. items[i].unit = '';
  584. }*/
  585. //add
  586. if(info.cellRange.col === 0){
  587. //是否含有已存在的编号
  588. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  589. //jobConten
  590. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  591. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  592. }
  593. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  594. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  595. }
  596. me.setInitPrc(items[i]);
  597. addArr.push(items[i]);
  598. }
  599. }
  600. }
  601. };
  602. if (updateArr.length > 0 || addArr.length > 0) {
  603. console.log(updateArr);
  604. me.mixUpdate = 1;
  605. me.mixUpdateRequest(updateArr, addArr, []);
  606. }
  607. else{
  608. me.getRationItems(me.currentSectionId);
  609. }
  610. },
  611. setInitPrc: function (obj) {
  612. obj.labourPrice = 0;
  613. obj.materialPrice = 0;
  614. obj.machinePrice = 0;
  615. obj.basePrice = 0;
  616. },
  617. isValidUnit: function (rationObj, validUnits) {
  618. let rst = true;
  619. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  620. rst = false;
  621. }
  622. return rst;
  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. if (!locked) {
  721. sectionTreeObj.removeBtn.removeClass('disabled');
  722. }
  723. if(callback) {
  724. callback(result.data);
  725. }
  726. },
  727. error:function(err){
  728. sectionTreeObj.removeBtn.removeClass('disabled');
  729. alert(err);
  730. }
  731. })
  732. }
  733. }
  734. },
  735. showRationItems: function(sectionID){
  736. let me = rationOprObj,
  737. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  738. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  739. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  740. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  741. if (me.workBook) {
  742. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  743. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID]) {
  744. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  745. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  746. if(me.mixDel === 1){
  747. let row = me.workBook.getSheet(0).getSelections()[0].row;
  748. if (cacheSection && row < cacheSection.length) {
  749. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  750. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  751. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  752. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  753. rationGLJOprObj.getGljItems(cacheSection[row]);
  754. rationCoeOprObj.getCoeItems(cacheSection[row]);
  755. rationAssistOprObj.getAssItems(cacheSection[row]);
  756. rationInstObj.getInstItems(cacheSection[row]);
  757. }
  758. else {
  759. rationGLJOprObj.currentRationItem = null;
  760. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  761. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  762. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  763. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  764. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  765. }
  766. }
  767. } else {
  768. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  769. //清除ration数据及工料机数据
  770. rationGLJOprObj.currentRationItem = null;
  771. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  772. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  773. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  774. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  775. }
  776. //--- me.workBook.focus(true);
  777. }
  778. sectionTreeObj.workBook.focus(true);
  779. },
  780. sortByCode: function(arr){
  781. function recurCompare(a, b, index){
  782. if (a[index] && !b[index]) {
  783. return 1;
  784. } else if (!a[index] && b[index]) {
  785. return -1;
  786. } else if (a[index] && b[index]) {
  787. let aV = a[index],
  788. bV = b[index];
  789. if (!isNaN(aV) && !isNaN(bV)) {
  790. aV = parseFloat(a[index]);
  791. bV = parseFloat(b[index]);
  792. }
  793. if (aV > bV) {
  794. return 1;
  795. } else if (aV < bV) {
  796. return -1;
  797. } else {
  798. return recurCompare(a, b, index + 1);
  799. }
  800. }
  801. return 0;
  802. }
  803. arr.sort(function (a, b) {
  804. if (!commonUtil.isDef(a.code) || !commonUtil.isDef(b.code)) {
  805. return 0;
  806. }
  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. }