ration.js 39 KB

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