ration.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. $(document).ready(function () {
  5. //定额表与下方子表上下拖动
  6. let rationSubResize = getRationSubResize();
  7. SlideResize.verticalSlide(rationSubResize.eleObj, rationSubResize.limit, function () {
  8. if (rationOprObj.workBook) {
  9. rationOprObj.workBook.refresh();
  10. }
  11. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  12. rationGLJOprObj.sheet.getParent().refresh();
  13. }
  14. });
  15. SlideResize.loadVerticalHeight(rationSubResize.eleObj.module, rationSubResize.eleObj, rationSubResize.limit, function () {
  16. if (rationOprObj.workBook) {
  17. rationOprObj.workBook.refresh();
  18. }
  19. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  20. rationGLJOprObj.sheet.getParent().refresh();
  21. }
  22. });
  23. });
  24. function getRationSubResize() {
  25. let rationSubResize = {};
  26. rationSubResize.eleObj = {
  27. module: moduleName,
  28. resize: $('#rationSubResize'),
  29. top: $('#rationItemsSheet'),
  30. topSpread: $('#rationItemsSheet'),
  31. bottom: $('#subContent'),
  32. bottomSpread: $('#rdSpread')
  33. };
  34. rationSubResize.limit = {
  35. min: 150,
  36. max: `$(window).height()-$('.header').height()-$('.tools-bar').height()-150-verticalResize`,
  37. totalHeight: `$(window).height()-$('.header').height()-$('.tools-bar').height()-verticalResize`,
  38. notTopSpread: 0,
  39. notBottomSpread: $('#subContent ul').height(),
  40. };
  41. return rationSubResize;
  42. }
  43. function loadRationSubSize(resizeObj) {
  44. if (!resizeObj) {
  45. resizeObj = getRationSubResize();
  46. }
  47. SlideResize.loadVerticalHeight(resizeObj.eleObj.module, resizeObj.eleObj, resizeObj.limit, function () {
  48. if (rationOprObj.workBook) {
  49. rationOprObj.workBook.refresh();
  50. }
  51. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  52. rationGLJOprObj.sheet.getParent().refresh();
  53. }
  54. });
  55. }
  56. const digital = {
  57. gljPrc: -3,//计算定额基价时单个工料机价格取三位
  58. rationBasePrc: -2,
  59. consumeAmt: -3
  60. };
  61. let rationOprObj = {
  62. workBook: null,
  63. currentRations: {},
  64. currentEditingRation: null,
  65. currentSectionId: -1,
  66. rationsCodes: [],
  67. setting: {
  68. header:[
  69. {headerName:"编码",headerWidth:70,dataCode:"code", dataType: "String", formatter: "@"},
  70. {headerName:"名称",headerWidth:240,dataCode:"name", dataType: "String"},
  71. {headerName:"计量单位",headerWidth:70,dataCode:"unit", dataType: "String", hAlign: "center"},
  72. /*{headerName:"人工费",headerWidth:80,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  73. {headerName:"材料费",headerWidth:80,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
  74. {headerName:"机械费",headerWidth:80,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},*/
  75. {headerName:"基价",headerWidth:80,dataCode:"basePrice", dataType: "Number", 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. RationTemplate.rationInitSel(cacheSection[row]);
  137. if (cacheSection && row < cacheSection.length) {
  138. rationGLJOprObj.getGljItems(cacheSection[row], function () {
  139. if (focusOnSection){
  140. sectionTreeObj.workBook.focus(true);
  141. } else {
  142. me.workBook.focus(true);
  143. }
  144. });
  145. rationCoeOprObj.getCoeItems(cacheSection[row], function () {
  146. if (focusOnSection){
  147. sectionTreeObj.workBook.focus(true);
  148. } else {
  149. me.workBook.focus(true);
  150. }
  151. });
  152. rationAssistOprObj.getAssItems(cacheSection[row]);
  153. rationInstObj.getInstItems(cacheSection[row], function () {
  154. if (focusOnSection){
  155. sectionTreeObj.workBook.focus(true);
  156. } else {
  157. me.workBook.focus(true);
  158. }
  159. });
  160. }
  161. else {
  162. rationGLJOprObj.currentRationItem = null;
  163. }
  164. if (!focusOnSection) {
  165. me.workBook.focus(true);
  166. }
  167. },
  168. isInt: function (num) {
  169. return !isNaN(num) && num % 1 === 0;
  170. },
  171. getCache: function() {
  172. let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  173. if (!(rst)) {
  174. me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
  175. rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
  176. }
  177. return rst;
  178. },
  179. updateCache: function(addArr, updateArr, removeIds, result) {
  180. let me = this, cacheSection = me.getCache();
  181. if (addArr.length > 0) {
  182. me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
  183. cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
  184. }
  185. for (let i = removeIds.length - 1; i >= 0; i--) {
  186. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  187. if (cacheSection[j].rationTemplateList) {
  188. //清除模板关联
  189. _.remove(cacheSection[j].rationTemplateList, function (data) {
  190. return removeIds.includes(data.rationID);
  191. });
  192. }
  193. if (cacheSection[j]["ID"] == removeIds[i]) {
  194. cacheSection.splice(j,1);
  195. }
  196. }
  197. }
  198. if (result && result.data.ops && result.data.ops.length > 0) {
  199. for (let i = 0; i < result.data.ops.length; i++) {
  200. for (let j = 0; j < cacheSection.length; j++) {
  201. if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
  202. cacheSection[j]["ID"] = result.data.ops[i]["ID"];
  203. cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
  204. cacheSection[j]["rationCoeList"] = result.data.ops[i]["rationCoeList"];
  205. cacheSection[j]["rationAssList"] = result.data.ops[i]["rationAssList"];
  206. cacheSection[j]["rationInstList"] = result.data.ops[i]["rationInstList"];
  207. }
  208. }
  209. }
  210. }
  211. for (let i = 0; i < updateArr.length; i++) {
  212. for (let j = 0; j < cacheSection.length; j++) {
  213. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  214. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  215. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  216. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  217. cacheSection[j]['rationGljList'] ?
  218. cacheSection[j]['rationGljList'] : [];
  219. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  220. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  221. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  222. updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
  223. cacheSection[j] = updateArr[i];
  224. }
  225. } else {
  226. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  227. updateArr[i]['rationGljList'] = rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] ?
  228. rationGLJOprObj.cache['_GLJ_' + cacheSection[j]['ID']] :
  229. cacheSection[j]['rationGljList'] ?
  230. cacheSection[j]['rationGljList'] : [];
  231. updateArr[i]['rationCoeList'] = cacheSection[j]['rationCoeList'] ? cacheSection[j]['rationCoeList'] : [];
  232. updateArr[i]['rationAssList'] = cacheSection[j]['rationAssList'];
  233. updateArr[i]['rationInstList'] = cacheSection[j]['rationInstList'];
  234. updateArr[i]['rationTemplateList'] = cacheSection[j]['rationTemplateList'];
  235. cacheSection[j] = updateArr[i];
  236. }
  237. }
  238. }
  239. }
  240. return cacheSection;
  241. },
  242. onContextmenuOpr: function () {//右键菜单
  243. let me = this;
  244. $.contextMenu({
  245. selector: '#rationItemsSheet',
  246. build: function($triggerElement, e){
  247. //控制允许右键菜单在哪个位置出现
  248. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  249. let sheet = me.workBook.getSheet(0);
  250. let delDis = false;
  251. let cacheSection = me.getCache();
  252. let ration = cacheSection[target.row];
  253. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  254. if(typeof target.row !== 'undefined'){
  255. //控制按钮是否可用
  256. sheet.setActiveCell(target.row, target.col);
  257. if(!cacheSection ||target.row >= cacheSection.length){//右键定位在有数据的行,删除键才显示可用
  258. delDis = true;
  259. }
  260. else{//有数据
  261. if(typeof target.col === 'undefined'){//定位不在表格内
  262. delDis = true;
  263. }
  264. }
  265. }
  266. else{
  267. delDis = true;
  268. }
  269. return {
  270. callback: function(){},
  271. items: {
  272. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  273. let removeInfo = `确定要删除定额 “${ration.code}” 及其下的所有数据吗?`;
  274. $('#delRationAlert').find('.modal-body h5').text(removeInfo);
  275. $('#delRationAlert').modal('show');
  276. $('#delRationConfirm').bind('click', function () {
  277. me.rationsCodes.splice(me.rationsCodes.indexOf(ration.code.toString()), 1);
  278. me.mixDel = 1;
  279. me.mixUpdateRequest([], [], [ration.ID]);
  280. $('#delRationConfirm').unbind('click');
  281. $('#delRationAlert').modal('hide');
  282. });
  283. }}
  284. }
  285. };
  286. }
  287. else{
  288. return false;
  289. }
  290. }
  291. });
  292. },
  293. rationDelOpr: function () {
  294. let me = rationOprObj;
  295. me.workBook.commandManager().register('rationDelete', function () {
  296. let rationSheet = me.workBook.getActiveSheet();
  297. let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  298. let removeCodes = [];
  299. let cacheSection = me.getCache();
  300. if(sels.length > 0){
  301. for(let sel = 0; sel < sels.length; sel++){
  302. if(sels[sel].colCount === me.setting.header.length){
  303. if(cacheSection){
  304. for(let i = 0; i < sels[sel].rowCount; i++){
  305. if(sels[sel].row + i < cacheSection.length){
  306. removeArr.push(cacheSection[sels[sel].row + i].ID);
  307. removeCodes.push(cacheSection[sels[sel].row + i].code);
  308. me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code.toString()), 1);
  309. }
  310. }
  311. }
  312. }
  313. else{
  314. if(sels[sel].col === 0){
  315. $('#alertText').text("编号不能为空,修改失败!");
  316. $('#alertModalBtn').click();
  317. $('#alertModalCls').click(function () {
  318. });
  319. $('#alertModalCof').click(function () {
  320. })
  321. }
  322. else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
  323. if(cacheSection){
  324. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  325. if(sels[sel].row + i < cacheSection.length){
  326. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  327. if(lockCols.indexOf(col) === -1){
  328. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
  329. }
  330. }
  331. }
  332. if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
  333. updateArr.push(cacheSection[sels[sel].row + i]);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. /* if(updateArr.length > 0 || removeArr.length > 0){
  342. me.mixUpdate = 1;
  343. me.mixDel = removeArr.length > 0 ? 1 : 0;
  344. me.mixUpdateRequest(updateArr, [], removeArr);
  345. }*/
  346. if(updateArr.length > 0){
  347. me.mixUpdate = 1;
  348. me.mixUpdateRequest(updateArr, [], []);
  349. }
  350. if(removeArr.length > 0){
  351. let removeInfo = `确定要删除定额 “${removeCodes.join(',')}” 及其下的所有数据吗?`;
  352. $('#delRationAlert').find('.modal-body h5').text(removeInfo);
  353. $('#delRationAlert').modal('show');
  354. $('#delRationConfirm').bind('click', function () {
  355. me.mixDel = 1;
  356. me.mixUpdateRequest([], [], removeArr);
  357. $('#delRationConfirm').unbind('click');
  358. $('#delRationAlert').modal('hide');
  359. });
  360. }
  361. });
  362. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  363. me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  364. },
  365. onLeaveCell: function (sender, args) {
  366. let me = rationOprObj;
  367. me.lastCol = me.setting.header[args.col];
  368. },
  369. onEnterCell: function (sender, args) {
  370. let me = rationOprObj;
  371. if(me.setting.header[args.col]['dataCode'] === 'unit' || me.lastCol.dataCode === 'unit'){
  372. args.sheet.repaint();
  373. }
  374. me.cellRowIdx = args.row;
  375. let isHasData = false;
  376. if(me.addRationItem){
  377. for(let i=0; i<me.setting.header.length; i++){
  378. if(me.addRationItem[me.setting.header[i].dataCode]){
  379. isHasData = true;
  380. break;
  381. }
  382. }
  383. }
  384. if(isHasData){
  385. if(me.editingRowIdx !== me.cellRowIdx) {
  386. let focusToCol = !me.addRationItem.code ? 0 : -1;
  387. if(focusToCol !== -1){
  388. $('#rationAlertBtn').click();
  389. $('#rationAlertCac').click(function () {
  390. me.addRationItem = null;
  391. for(let col=0; col<me.setting.header.length; col++){
  392. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  393. }
  394. });
  395. $('#rationAlertCls').click(function () {
  396. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  397. });
  398. $('#rationAlertCof').click(function () {
  399. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  400. });
  401. }
  402. }
  403. }
  404. },
  405. onCellEditStart: function(sender, args) {
  406. let me = rationOprObj;
  407. if(!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1){
  408. args.cancel = true;
  409. }
  410. else{
  411. let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
  412. me.currentEditingRation = rObj;
  413. let cacheSection = me.getCache();
  414. if (cacheSection) {
  415. for (let j = 0; j < cacheSection.length; j++) {
  416. if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
  417. rObj["ID"] = cacheSection[j]["ID"];
  418. break;
  419. }
  420. }
  421. }
  422. }
  423. },
  424. onCellEditEnd: function(sender, args) {
  425. let edV = args.sheet.getValue(args.row, args.col);
  426. if(edV){
  427. args.sheet.setValue(args.row, args.col, edV.toString().trim());
  428. }
  429. let me = rationOprObj, rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
  430. updateArr = [], addArr = [];
  431. let dataCode = me.setting.header[args.col].dataCode;
  432. me.editingRowIdx = args.row;
  433. if (me.currentEditingRation["ID"]) {
  434. if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
  435. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
  436. }
  437. else {
  438. rObj["ID"] = me.currentEditingRation["ID"];
  439. if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
  440. me.addRationItem = rObj;
  441. if(dataCode === 'code'){
  442. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  443. me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code.toString()), 1);
  444. me.rationsCodes.push(rObj.code.toString());
  445. updateArr.push(rObj);
  446. }
  447. else{
  448. alert("编码已存在!");
  449. args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
  450. }
  451. }
  452. else if(dataCode === 'feeType'){//取费专业控制为整数
  453. if(me.isInt(rObj[dataCode])){
  454. updateArr.push(rObj);
  455. }
  456. else {
  457. rObj[dataCode] = '';
  458. args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
  459. }
  460. }
  461. else{
  462. updateArr.push(rObj);
  463. }
  464. }
  465. }
  466. }
  467. else if(!me.currentEditingRation["ID"]) {
  468. if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
  469. //addArr.push(rObj);
  470. me.addRationItem = rObj;
  471. if(rObj.code && rObj.code.toString().trim().length > 0){
  472. if(me.rationsCodes.indexOf(rObj.code.toString()) === -1){
  473. //jobContent
  474. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  475. rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  476. }
  477. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  478. rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  479. }
  480. me.setInitPrc(rObj);
  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 rst = false;
  503. if(maxCol < 3 || beginCol > 6){
  504. rst = true;
  505. }
  506. return rst;
  507. },
  508. onClipboardPasting: function(sender, args) {
  509. let me = rationOprObj;
  510. let maxCol = args.cellRange.col + args.cellRange.colCount -1;
  511. if(!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1){
  512. args.cancel = true;
  513. }
  514. },
  515. onClipboardPasted: function(e, info) {
  516. let me = rationOprObj;
  517. let cacheSection = me.getCache();
  518. let updateArr = [], addArr = [];
  519. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  520. for (let i = 0; i < items.length; i++) {
  521. let rowIdx = info.cellRange.row + i;
  522. if (cacheSection) {
  523. if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
  524. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  525. //jobConten
  526. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  527. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  528. }
  529. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  530. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  531. }
  532. me.setInitPrc(items[i]);
  533. addArr.push(items[i]);
  534. me.rationsCodes.push(items[i].code.toString());
  535. }
  536. else{
  537. me.workBook.getSheet(0).setValue(rowIdx, 0, '');
  538. }
  539. }
  540. else if(cacheSection[rowIdx]){
  541. for(let col = 0; col < me.setting.header.length; col++){
  542. if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
  543. items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
  544. }
  545. }
  546. if(items[i].feeType && !me.isInt(items[i].feeType)){
  547. items[i].feeType = '';
  548. me.workBook.getSheet(0).setValue(rowIdx, 8, '');
  549. }
  550. if(info.cellRange.col === 0){
  551. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  552. items[i].ID = cacheSection[rowIdx].ID;
  553. updateArr.push(items[i]);
  554. }
  555. else{
  556. me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
  557. }
  558. }
  559. else{
  560. items[i].ID = cacheSection[rowIdx].ID;
  561. updateArr.push(items[i]);
  562. }
  563. }
  564. } else {
  565. //add
  566. if(info.cellRange.col === 0){
  567. //是否含有已存在的编号
  568. if(me.rationsCodes.indexOf(items[i].code.toString()) === -1){
  569. //jobConten
  570. if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
  571. items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
  572. }
  573. if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
  574. items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
  575. }
  576. me.setInitPrc(items[i]);
  577. addArr.push(items[i]);
  578. }
  579. }
  580. }
  581. };
  582. if (updateArr.length > 0 || addArr.length > 0) {
  583. me.mixUpdate = 1;
  584. me.mixUpdateRequest(updateArr, addArr, []);
  585. }
  586. else{
  587. me.getRationItems(me.currentSectionId);
  588. }
  589. },
  590. setInitPrc: function (obj) {
  591. obj.labourPrice = 0;
  592. obj.materialPrice = 0;
  593. obj.machinePrice = 0;
  594. obj.basePrice = 0;
  595. },
  596. isValidUnit: function (rationObj, validUnits) {
  597. let rst = true;
  598. if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
  599. rst = false;
  600. }
  601. return rst;
  602. },
  603. getRationsCodes: function (repId) {
  604. let me = rationOprObj;
  605. $.ajax({
  606. type: 'post',
  607. url: 'api/getRationsCodes',
  608. data: {data: JSON.stringify({repId: repId})},
  609. dataType: 'json',
  610. success: function (result) {
  611. if(!result.error){
  612. me.rationsCodes = result.data;
  613. }
  614. }
  615. })
  616. },
  617. mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
  618. let me = rationOprObj;
  619. me.saveInString(updateArr);
  620. $.ajax({
  621. type:"POST",
  622. url:"api/mixUpdateRationItems",
  623. data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
  624. dataType:"json",
  625. cache:false,
  626. timeout:20000,
  627. success:function(result){
  628. if (result.error) {
  629. alert('error');
  630. me.getRationItems(me.currentSectionId);
  631. } else {
  632. let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
  633. me.sortByCode(cacheSection);
  634. /*cacheSection.sort(function(a, b){
  635. let rst = 0;
  636. if (a.code > b.code) rst = 1
  637. else if (a.code < b.code) rst = -1;
  638. return rst;
  639. });*/
  640. //add
  641. let curRow = me.workBook.getActiveSheet().getActiveRowIndex();
  642. me.rationSelInit(curRow);
  643. //add
  644. //jobContent
  645. if(jobContentOprObj ){
  646. jobContentOprObj.currentRationItems = cacheSection;
  647. jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
  648. if(cacheSection.length === 0){
  649. jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  650. }
  651. jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
  652. if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
  653. jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
  654. }
  655. }
  656. if(annotationOprObj ){
  657. annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
  658. if(cacheSection.length === 0){
  659. annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
  660. }
  661. annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
  662. if(annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL){
  663. annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
  664. }
  665. }
  666. me.showRationItems(me.currentSectionId);
  667. me.mixUpdate = 0;
  668. me.mixDel = 0;
  669. }
  670. me.workBook.focus(true);
  671. if(callback) callback();
  672. },
  673. error:function(){
  674. }
  675. });
  676. },
  677. doAfterGetRation: null,
  678. getRationItems: function(sectionID, callback = null){
  679. if (sectionID != -1) {
  680. let me = rationOprObj;
  681. me.mixUpdate = 0;
  682. me.currentSectionId = sectionID;
  683. /*if (me.currentRations["_SEC_ID_" + sectionID]) {
  684. //jobContent--
  685. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  686. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  687. //annotation
  688. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  689. me.showRationItems(sectionID);
  690. sectionTreeObj.removeBtn.removeClass('disabled');
  691. if(callback){
  692. callback();
  693. }
  694. } else */{
  695. $.ajax({
  696. type:"POST",
  697. url:"api/getRationItems",
  698. data:{"rationRepId": pageOprObj.rationLibId, "sectionID": sectionID},
  699. dataType:"json",
  700. cache:false,
  701. timeout:10000,
  702. success:function(result){
  703. if (result) {
  704. me.currentRations["_SEC_ID_" + sectionID] = result.data;
  705. me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
  706. //job--
  707. jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
  708. jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
  709. //annotation
  710. annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
  711. me.showRationItems(sectionID);
  712. }
  713. sectionTreeObj.removeBtn.removeClass('disabled');
  714. if(callback) {
  715. callback(result.data);
  716. }
  717. },
  718. error:function(err){
  719. sectionTreeObj.removeBtn.removeClass('disabled');
  720. alert(err);
  721. }
  722. })
  723. }
  724. }
  725. },
  726. showRationItems: function(sectionID){
  727. let me = rationOprObj,
  728. sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
  729. sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
  730. sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting,
  731. sheetInst = rationInstObj.sheet, settingInst = rationInstObj.setting;
  732. if (me.workBook) {
  733. if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
  734. let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
  735. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  736. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
  737. //combo
  738. //sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
  739. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  740. if(me.mixDel === 1){
  741. let row = me.workBook.getSheet(0).getSelections()[0].row;
  742. if (cacheSection && row < cacheSection.length) {
  743. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  744. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  745. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  746. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  747. rationGLJOprObj.getGljItems(cacheSection[row]);
  748. rationCoeOprObj.getCoeItems(cacheSection[row]);
  749. rationAssistOprObj.getAssItems(cacheSection[row]);
  750. rationInstObj.getInstItems(cacheSection[row]);
  751. }
  752. else {
  753. rationGLJOprObj.currentRationItem = null;
  754. sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
  755. sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
  756. sheetCommonObj.cleanData(sheetAss, settingAss, -1);
  757. sheetCommonObj.cleanData(sheetInst, settingInst, -1);
  758. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  759. }
  760. }
  761. } else {
  762. sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
  763. //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
  764. //清除ration数据及工料机数据
  765. rationGLJOprObj.currentRationItem = null;
  766. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  767. sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
  768. sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
  769. sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
  770. sheetCommonObj.cleanSheet(sheetInst, settingInst, -1);
  771. }
  772. //--- me.workBook.focus(true);
  773. }
  774. sectionTreeObj.workBook.focus(true);
  775. },
  776. sortByCode: function(arr){
  777. function recurCompare(a, b, index){
  778. if (a[index] && !b[index]) {
  779. return 1;
  780. } else if (!a[index] && b[index]) {
  781. return -1;
  782. } else if (a[index] && b[index]) {
  783. let aV = a[index],
  784. bV = b[index];
  785. if (!isNaN(aV) && !isNaN(bV)) {
  786. aV = parseFloat(a[index]);
  787. bV = parseFloat(b[index]);
  788. }
  789. if (aV > bV) {
  790. return 1;
  791. } else if (aV < bV) {
  792. return -1;
  793. } else {
  794. return recurCompare(a, b, index + 1);
  795. }
  796. }
  797. return 0;
  798. }
  799. arr.sort(function (a, b) {
  800. let aArr = a.code.split('-'),
  801. bArr = b.code.split('-');
  802. return recurCompare(aArr, bArr, 0);
  803. });
  804. },
  805. saveInString(datas){
  806. for(let i = 0, len = datas.length; i < len; i++){
  807. let data = datas[i];
  808. if(data.labourPrice !== undefined && data.labourPrice){
  809. data.labourPrice = data.labourPrice.toString();
  810. }
  811. if(data.materialPrice !== undefined && data.materialPrice){
  812. data.materialPrice = data.materialPrice.toString();
  813. }
  814. if(data.machinePrice !== undefined && data.machinePrice){
  815. data.machinePrice = data.machinePrice.toString();
  816. }
  817. if(data.basePrice !== undefined && data.basePrice){
  818. data.basePrice = data.basePrice.toString();
  819. }
  820. if(data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0){
  821. for(let j = 0, jLen = data.rationGljList.length; j < jLen; j++){
  822. let raGljObj = data.rationGljList[j];
  823. if(raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt){
  824. raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
  825. }
  826. }
  827. }
  828. }
  829. }
  830. }