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: "Number", hAlign: "center"},
  78. {headerName:"管理费费率(%)",headerWidth:100,dataCode:"manageFeeRate", dataType: "String", hAlign: "center"},
  79. {headerName:"工作内容",headerWidth:130,dataCode:"jobContentText", dataType: "String"},
  80. ],
  81. view:{
  82. comboBox:[
  83. {row:-1,col:2,rowCount:-1,colCount:1}
  84. ],
  85. lockedCells:[
  86. {row:-1,col:3,rowCount:-1, colCount:1}
  87. ],
  88. lockColumns: [
  89. 3, 4, 5, 6
  90. ]
  91. }
  92. },
  93. buildSheet: function(container) {
  94. let rationRepId = getQueryString("repository");
  95. let me = rationOprObj;
  96. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  97. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
  98. me.onContextmenuOpr();
  99. me.rationDelOpr();
  100. me.setCombo(me.workBook.getSheet(0), 'dynamic');
  101. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  102. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  103. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  104. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  105. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  106. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  107. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  108. },
  109. setCombo: function (sheet, combo) {
  110. let me = rationOprObj;
  111. sheet.suspendPaint();
  112. sheet.suspendEvent();
  113. if(combo){
  114. combo = sheetCommonObj.getDynamicCombo();
  115. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  116. }
  117. sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
  118. sheet.resumePaint();
  119. sheet.resumeEvent();
  120. },
  121. // TODO info.oldSelections is null
  122. onSelectionChanged: function (sender, info) {
  123. console.log(info);
  124. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  125. let row = info.newSelections[0].row;
  126. let me = rationOprObj;
  127. me.rationSelInit(row);
  128. }
  129. },
  130. //focusOnSection将工作簿焦点移到章节表上
  131. rationSelInit: function (row, focusOnSection = null) {
  132. let me = rationOprObj,
  133. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  134. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  135. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  136. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  137. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  138. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  139. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  140. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  141. let cacheSection = me.getCache();
  142. RationTemplate.rationInitSel(cacheSection[row]);
  143. if (cacheSection && row < cacheSection.length) {
  144. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  145. if (focusOnSection){
  146. sectionTreeObj.workBook.focus(true);
  147. } else {
  148. me.workBook.focus(true);
  149. }
  150. });
  151. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  152. if (focusOnSection){
  153. sectionTreeObj.workBook.focus(true);
  154. } else {
  155. me.workBook.focus(true);
  156. }
  157. });
  158. rationAssistOprObj.getAssItems(cacheSection[row]);
  159. rationInstObj.getInstItems(cacheSection[row], function () {
  160. if (focusOnSection){
  161. sectionTreeObj.workBook.focus(true);
  162. } else {
  163. me.workBook.focus(true);
  164. }
  165. });
  166. }
  167. else {
  168. rationGLJOprObj.currentRationItem = null;
  169. }
  170. if (!focusOnSection) {
  171. me.workBook.focus(true);
  172. }
  173. },
  174. isInt: function (num) {
  175. return !isNaN(num) && num % 1 === 0;
  176. },
  177. getCache: function() {
  178. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  179. if (!(rst)) {
  180. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  181. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  182. }
  183. return rst;
  184. },
  185. updateCache: function(addArr, updateArr, removeIds, result) {
  186. let me = this, cacheSection = me.getCache();
  187. if (addArr.length > 0) {
  188. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  189. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  190. }
  191. for (let i = removeIds.length - 1; i >= 0; i--) {
  192. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  193. if (cacheSection[j].rationTemplateList) {
  194. //清除模板关联
  195. _.remove(cacheSection[j].rationTemplateList, function (data) {
  196. return removeIds.includes(data.rationID);
  197. });
  198. }
  199. if (cacheSection[j]["ID"] == removeIds[i]) {
  200. cacheSection.splice(j,1);
  201. }
  202. }
  203. }
  204. if (result && result.data.ops && result.data.ops.length > 0) {
  205. for (let i = 0; i < result.data.ops.length; i++) {
  206. for (let j = 0; j < cacheSection.length; j++) {
  207. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  208. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  209. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  210. cacheSection[j]["rationCoeList"] = result.data.ops[i]["rationCoeList"];
  211. cacheSection[j]["rationAssList"] = result.data.ops[i]["rationAssList"];
  212. cacheSection[j]["rationInstList"] = result.data.ops[i]["rationInstList"];
  213. }
  214. }
  215. }
  216. }
  217. for (let i = 0; i < updateArr.length; i++) {
  218. for (let j = 0; j < cacheSection.length; j++) {
  219. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  220. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  221. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  222. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  223. cacheSection[j]['rationGljList'] ?
  224. cacheSection[j]['rationGljList'] : [];
  225. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  226. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  227. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  228. updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
  229. cacheSection[j] = updateArr[i];
  230. }
  231. } else {
  232. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  233. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  234. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  235. cacheSection[j]['rationGljList'] ?
  236. cacheSection[j]['rationGljList'] : [];
  237. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  238. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  239. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  240. updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
  241. cacheSection[j] = updateArr[i];
  242. }
  243. }
  244. }
  245. }
  246. return cacheSection;
  247. },
  248. onContextmenuOpr: function () {//右键菜单
  249. let me = this;
  250. $.contextMenu({
  251. selector: '#rationItemsSheet',
  252. build: function($triggerElement, e){
  253. //控制允许右键菜单在哪个位置出现
  254. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  255. let sheet = me.workBook.getSheet(0);
  256. let cacheSection = me.getCache();
  257. let ration = cacheSection[target.row];
  258. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  259. if(typeof target.row !== 'undefined'){
  260. //控制按钮是否可用
  261. sheet.setActiveCell(target.row, target.col);
  262. }
  263. return {
  264. callback: function(){},
  265. items: {
  266. "delete": {
  267. name: "删除",
  268. disabled: function () {
  269. const inValidCell = !commonUtil.isDef(target.row) || !commonUtil.isDef(target.col);
  270. const inValidData = !cacheSection ||target.row >= cacheSection.length;
  271. return locked || inValidCell || inValidData;
  272. },
  273. icon: "fa-remove",
  274. 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. if (locked) {
  297. return;
  298. }
  299. let me = rationOprObj;
  300. me.workBook.commandManager().register('rationDelete', function () {
  301. let rationSheet = me.workBook.getActiveSheet();
  302. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  303. let removeCodes = [];
  304. let cacheSection = me.getCache();
  305. if(sels.length > 0){
  306. for(let sel = 0; sel < sels.length; sel++){
  307. if(sels[sel].colCount === me.setting.header.length){
  308. if(cacheSection){
  309. for(let i = 0; i < sels[sel].rowCount; i++){
  310. if(sels[sel].row + i < cacheSection.length){
  311. removeArr.push(cacheSection[sels[sel].row + i].ID);
  312. removeCodes.push(cacheSection[sels[sel].row + i].code);
  313. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code.toString()), 1);
  314. }
  315. }
  316. }
  317. }
  318. else{
  319. if(sels[sel].col === 0){
  320. $('#alertText').text("编号不能为空,修改失败!");
  321. $('#alertModalBtn').click();
  322. $('#alertModalCls').click(function () {
  323. });
  324. $('#alertModalCof').click(function () {
  325. })
  326. }
  327. else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
  328. if(cacheSection){
  329. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  330. if(sels[sel].row + i < cacheSection.length){
  331. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  332. if(lockCols.indexOf(col) === -1){
  333. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  334. }
  335. }
  336. }
  337. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  338. updateArr.push(cacheSection[sels[sel].row + i]);
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. /* if(updateArr.length > 0 || removeArr.length > 0){
  347. me.mixUpdate = 1;
  348. me.mixDel = removeArr.length > 0 ? 1 : 0;
  349. me.mixUpdateRequest(updateArr, [], removeArr);
  350. }*/
  351. if(updateArr.length > 0){
  352. me.mixUpdate = 1;
  353. me.mixUpdateRequest(updateArr, [], []);
  354. }
  355. if(removeArr.length > 0){
  356. let removeInfo = `确定要删除定额 “${removeCodes.join(',')}” 及其下的所有数据吗?`;
  357. $('#delRationAlert').find('.modal-body h5').text(removeInfo);
  358. $('#delRationAlert').modal('show');
  359. $('#delRationConfirm').bind('click', function () {
  360. me.mixDel = 1;
  361. me.mixUpdateRequest([], [], removeArr);
  362. $('#delRationConfirm').unbind('click');
  363. $('#delRationAlert').modal('hide');
  364. });
  365. }
  366. });
  367. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  368. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  369. },
  370. isDef: function (v) {
  371. return v !== undefined && v !== null;
  372. },
  373. onLeaveCell: function (sender, args) {
  374. let me = rationOprObj;
  375. me.lastCol = me.setting.header[args.col];
  376. },
  377. onEnterCell: function (sender, args) {
  378. let me = rationOprObj;
  379. if(me.setting.header[args.col]['dataCode'] === 'unit' || me.lastCol.dataCode === 'unit'){
  380. args.sheet.repaint();
  381. }
  382. me.cellRowIdx = args.row;
  383. let isHasData = false;
  384. if(me.addRationItem){
  385. for(let i=0; i<me.setting.header.length; i++){
  386. if(me.addRationItem[me.setting.header[i].dataCode]){
  387. isHasData = true;
  388. break;
  389. }
  390. }
  391. }
  392. if(isHasData){
  393. if(me.editingRowIdx !== me.cellRowIdx) {
  394. let focusToCol = !me.addRationItem.code ? 0 : -1;
  395. if(focusToCol !== -1){
  396. $('#rationAlertBtn').click();
  397. $('#rationAlertCac').click(function () {
  398. me.addRationItem = null;
  399. for(let col=0; col<me.setting.header.length; col++){
  400. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  401. }
  402. });
  403. $('#rationAlertCls').click(function () {
  404. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  405. });
  406. $('#rationAlertCof').click(function () {
  407. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  408. });
  409. }
  410. }
  411. }
  412. },
  413. onCellEditStart: function(sender, args) {
  414. let me = rationOprObj;
  415. if(!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1){
  416. args.cancel = true;
  417. }
  418. else{
  419. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  420. me.currentEditingRation = rObj;
  421. let cacheSection = me.getCache();
  422. if (cacheSection) {
  423. for (let j = 0; j < cacheSection.length; j++) {
  424. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  425. rObj["ID"] = cacheSection[j]["ID"];
  426. break;
  427. }
  428. }
  429. }
  430. }
  431. },
  432. onCellEditEnd: function(sender, args) {
  433. let me = rationOprObj;
  434. // 输入编号、名称、单位时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  435. let dataCode = me.setting.header[args.col].dataCode;
  436. let deESCFields = ['code', 'name', 'unit'];
  437. if(deESCFields.includes(dataCode)){
  438. args.editingText = me.isDef(args.editingText) ? args.editingText.toString().replace(/[\r\n]/g, ' ') : '';
  439. args.sheet.setValue(args.row, args.col, args.editingText);
  440. }
  441. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  442. updateArr = [],
  443. addArr = [];
  444. me.editingRowIdx = args.row;
  445. if (me.currentEditingRation["ID"]) {
  446. if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
  447. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  448. }
  449. else {
  450. rObj["ID"] = me.currentEditingRation["ID"];
  451. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  452. me.addRationItem = rObj;
  453. if(dataCode === 'code'){
  454. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  455. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code.toString()), 1);
  456. me.rationsCodes.push(rObj.code.toString());
  457. updateArr.push(rObj);
  458. }
  459. else{
  460. alert("编码已存在!");
  461. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  462. }
  463. }
  464. else if (dataCode === 'feeType') {//取费专业控制为整数
  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. }