ration.js 39 KB

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