ration.js 39 KB

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