ration.js 40 KB

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