ration.js 38 KB

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