zmhs_view.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /**
  2. * Created by zhang on 2018/5/30.
  3. */
  4. let zmhs_obj = {
  5. module: 'subZmhs',
  6. coeSpread:null,
  7. coeSheet:null,
  8. coeSheetData:[],
  9. coeSetting: {
  10. header: [
  11. {headerName: "调整", headerWidth: 35, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"},
  12. {headerName: "条件", headerWidth: 180, dataCode: "name", dataType: "String", cellType: "button",getText:'forName'},
  13. {headerName: "内容", headerWidth: 70, dataCode: "content", dataType: "String", hAlign: "left",getText:'forContent',cellType:'tipsCell'}
  14. ],
  15. view: {
  16. lockColumns:[0,1,2],
  17. rowHeaderWidth:25
  18. },
  19. getText:{
  20. forContent:function (item) {//所选人材机,内容和条件互换位置
  21. if(gljUtil.isDef(item.option_codes)&&item.option_codes!=""){
  22. return item.name;
  23. }else if(item.assistCode &&item.assistCode!="" ){//是辅助定额行,显示实际值
  24. return item.actualValue;
  25. } else {
  26. return item.content;
  27. }
  28. },
  29. forName:function (item) {
  30. if(gljUtil.isDef(item.select_code)&&item.select_code!=""){
  31. let option = _.find(item.option_list,{"value":item.select_code})
  32. return option?option.text:item.select_code;
  33. }else {
  34. return item.name;
  35. }
  36. }
  37. },
  38. emptyRowHeader: true,
  39. autoFit:true,
  40. fitRow:['name']
  41. },
  42. cusSpread:null,
  43. cusSheet:null,
  44. cusSheetData:null,
  45. cusSetting:{
  46. header: [
  47. {headerName: "类型", headerWidth: 100, dataCode: "coeType", dataType: "String",hAlign: "left"},
  48. {headerName: "系数", headerWidth: 80, dataCode: "amount", dataType: "String", hAlign: "right",validator:"number"}
  49. ],
  50. view: {
  51. lockColumns:["coeType"],
  52. rowHeaderWidth:25
  53. },
  54. emptyRowHeader: true
  55. },
  56. assSpread:null,
  57. assSheet:null,
  58. assSheetData: [],
  59. assFirstIndex:0,
  60. assSetting: {
  61. header: [
  62. {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  63. {headerName: "定额值", headerWidth: 80, dataCode: "stdValue", hAlign: "right", dataType: "String"},
  64. {headerName: "实际值", headerWidth: 80, dataCode: "actualValue", hAlign: "right", dataType: "String"}
  65. ],
  66. view: {
  67. lockColumns: [0, 1],
  68. rowHeaderWidth:25
  69. },
  70. emptyRowHeader: true
  71. },
  72. stableSpread:null,
  73. stableSheet:null,
  74. stableSheetData:null,
  75. stableSetting:{
  76. header: [
  77. {headerName: "材料编号", headerWidth: 100, dataCode: "code", dataType: "String"},
  78. {headerName: "材料名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  79. {headerName: "调整配合比", headerWidth: 80, dataCode: "adjustProportion", dataType: "String", hAlign: "right", validator:"number", precision: 2}
  80. ],
  81. view: {
  82. lockColumns:["code", "name"],
  83. rowHeaderWidth:25
  84. },
  85. emptyRowHeader: true
  86. },
  87. initSpread:function () {
  88. this.initCoeSpread();
  89. this.initAssSpread();
  90. },
  91. initCoeSpread:function () {
  92. let pre = $('#divide_subSpread').is(':visible')?"divide_":"";
  93. if(zmhs_obj[pre+"coeSpread"] == null){
  94. this[pre+"coeSpread"] = SheetDataHelper.createNewSpread($("#"+pre+"coeSpread")[0]);
  95. sheetCommonObj.spreadDefaultStyle(this[pre+"coeSpread"]);
  96. this[pre+"coeSheet"] = this[pre+"coeSpread"].getSheet(0);
  97. sheetCommonObj.initSheet(this[pre+"coeSheet"], this.coeSetting, 30);
  98. this[pre+"coeSheet"].name(pre+'ration_coe');
  99. //this.coeSheet.bind(GC.Spread.Sheets.Events.CellClick, this.onCoeCellClick); 配合自定义系数使用,现在自定义系数不在这显示了
  100. this[pre+"coeSpread"].bind(GC.Spread.Sheets.Events.ButtonClicked, this.onButtonClick);
  101. this[pre+"coeSheet"].bind(GC.Spread.Sheets.Events.ValueChanged,this.onCoeValueChange);
  102. this[pre+"coeSheet"].bind(GC.Spread.Sheets.Events.RangeChanged, this.onCoeRangeChanged);
  103. this[pre+"coeSheet"].bind(GC.Spread.Sheets.Events.SelectionChanged, function (e,args) {
  104. args.sheet.repaint();
  105. });
  106. SheetDataHelper.protectdSheet(this[pre+"coeSheet"]);
  107. }
  108. },
  109. initCusSpread:function () {
  110. if(zmhs_obj.cusSpread == null){
  111. this.cusSpread = SheetDataHelper.createNewSpread($("#cusSpread")[0]);
  112. sheetCommonObj.spreadDefaultStyle(this.cusSpread);
  113. this.cusSheet = this.cusSpread.getSheet(0);
  114. sheetCommonObj.initSheet(this.cusSheet, this.cusSetting, 30);
  115. this.cusSheet.name('ration_cus');
  116. this.cusSheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onCusValueChange);
  117. this.cusSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onCusRangeChanged);
  118. SheetDataHelper.protectdSheet(this.cusSheet);
  119. }
  120. },
  121. initAssSpread:function () {
  122. if(zmhs_obj.assSheet == null){
  123. this.assSpread = SheetDataHelper.createNewSpread($("#assSpread")[0]);
  124. sheetCommonObj.spreadDefaultStyle(this.assSpread);
  125. this.assSheet = this.assSpread.getSheet(0);
  126. sheetCommonObj.initSheet(this.assSheet, this.assSetting, 30);
  127. this.assSheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onAssEditEnded);
  128. this.assSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onAssRangeChanged);
  129. this.assSheet.name('ration_ass');
  130. SheetDataHelper.protectdSheet(this.assSheet);
  131. }
  132. },
  133. initStableSpread:function () {
  134. if(zmhs_obj.stableSpread == null){
  135. this.stableSpread = SheetDataHelper.createNewSpread($("#stableSpread")[0]);
  136. sheetCommonObj.spreadDefaultStyle(this.stableSpread);
  137. this.stableSheet = this.stableSpread.getSheet(0);
  138. sheetCommonObj.initSheet(this.stableSheet, this.stableSetting, 30);
  139. this.stableSheet.name('ration_stable');
  140. this.stableSheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onStableValueChange);
  141. this.stableSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onStableRangeChanged);
  142. SheetDataHelper.protectdSheet(this.stableSheet);
  143. }
  144. },
  145. showCoeData:function (node) {
  146. let preSelections = this.coeSheet.getSelections();
  147. let selected = node?node:projectObj.project.mainTree.selected;
  148. let ration_coe = projectObj.project.ration_coe;
  149. let coeList = [];
  150. this.coeSheet.suspendPaint();
  151. this.coeSheet.suspendEvent();
  152. if(selected&&selected.sourceType == "ration"){
  153. let ration = selected.data;
  154. let assList = this.getAssList(node); //2019-01-23 新需求,将辅助定额合并到一个表显示 -- 20191206
  155. // this.assFirstIndex = coeList.length;//没改前这里要记录辅助定额的起始下标,现在调整顺序后,默认就是0
  156. coeList = ration_coe.getCoeByRationID(ration.ID);
  157. _.remove(coeList,{"coeID":-1})//2018-12-24 新需求,把自定义乘系数分离出来,这里排除自定义乘系数行
  158. coeList = assList.concat(coeList)
  159. }
  160. this.coeSheet.setRowCount(0);
  161. sheetCommonObj.showData(this.coeSheet, this.coeSetting,coeList);
  162. if (coeList.length > 0) {
  163. for(let i =0;i<coeList.length;i++ ){
  164. if(gljUtil.isDef(coeList[i].option_codes)&&coeList[i].option_codes!=""){
  165. this.getComboBoxForCodes(coeList[i],i);//设置可选类型的下拉框
  166. // sheet.setValue(row, col, val, ch);
  167. } else if(coeList[i].assistCode && coeList[i].assistCode !=''){//是辅助定额列
  168. this.coeSheet.getCell(i, 2, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  169. } else if(coeList[i].coeID == -1){ //自定义系数列
  170. this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  171. this.coeSheet.setCellType(i, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport);
  172. }
  173. }
  174. }
  175. this.coeSheetData = coeList;
  176. if(projectReadOnly){
  177. disableSpread(zmhs_obj.coeSpread);
  178. }
  179. if(preSelections){//定位光标到之前的位置
  180. this.coeSheet.setSelection(preSelections[0].row,preSelections[0].col,preSelections[0].rowCount,preSelections[0].colCount);
  181. }
  182. this.coeSheet.resumeEvent();
  183. this.coeSheet.resumePaint();
  184. },
  185. showCusData:function (node) {
  186. let selected = node?node:projectObj.project.mainTree.selected;
  187. let ration_coe = projectObj.project.ration_coe;
  188. let cusList = [];
  189. if(selected&&selected.sourceType == "ration"){
  190. let ration = selected.data;
  191. let coeList = ration_coe.getCoeByRationID(ration.ID);
  192. this.cusSheetData = _.find(coeList,{"coeID":-1});
  193. if(this.cusSheetData) cusList = this.cusSheetData.coes;
  194. }
  195. sheetCommonObj.showData(this.cusSheet, this.cusSetting,cusList);
  196. this.cusSheet.getRange(cusList.length,-1,this.cusSheet.getRowCount()-cusList.length, -1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  197. if(projectReadOnly){
  198. disableSpread(zmhs_obj.cusSpread);
  199. }
  200. },
  201. showStableData: function (node) {
  202. // 过滤出定额配合比不为0的数据
  203. const stableList = gljOprObj.sheetData.filter(glj => !glj.isMixRatio && glj.rationProportion);
  204. this.stableSheetData = stableList;
  205. sheetCommonObj.showData(this.stableSheet, this.stableSetting, stableList);
  206. const proportionCol = this.stableSetting.header.findIndex(item => item.dataCode === 'adjustProportion');
  207. this.stableSheet.getRange(0, proportionCol, stableList.length, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  208. this.stableSheet.getRange(stableList.length, -1, this.stableSheet.getRowCount() - stableList.length, -1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  209. if(projectReadOnly){
  210. disableSpread(zmhs_obj.cusSpread);
  211. }
  212. },
  213. getComboBoxForCodes:function (coe,i) {
  214. this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  215. let options = coe.option_list; //coe.option_codes.split("|");
  216. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();//sheetCommonObj.getDynamicCombo(true); 2019-4-1 这里用普通的下拉框,一直显示
  217. let buttonRow = this.coeSheet.getViewportBottomRow(1);
  218. combo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  219. combo.items(options).maxDropDownItems(buttonRow - i -1 < 3 ?3:buttonRow - i -1 );//itemHeight(options.length).
  220. this.coeSheet.setCellType(i, 1, combo, GC.Spread.Sheets.SheetArea.viewport);
  221. this.coeSheet.setValue(i, 1, coe.select_code);
  222. },
  223. showAssData:function (node) {
  224. this.assSheet.suspendPaint();
  225. this.assSheet.suspendEvent();
  226. let selected = node?node:projectObj.project.mainTree.selected;
  227. let assList = selected&&selected.data.rationAssList ? selected.data.rationAssList : [];
  228. this.assSheet.setRowCount(0);
  229. sheetCommonObj.showData(this.assSheet, this.assSetting, assList);
  230. this.assSheetData = assList;
  231. this.assSheet.getRange(assList.length,-1,this.assSheet.getRowCount()-assList.length, -1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  232. this.assSheet.resumePaint();
  233. this.assSheet.resumeEvent();
  234. if(projectReadOnly){
  235. disableSpread(this.assSpread);
  236. }
  237. },
  238. getAssList:function (node) {
  239. let selected = node?node:projectObj.project.mainTree.selected;
  240. let assList = selected&&selected.data.rationAssList ? selected.data.rationAssList : [];
  241. this.assSheetData = assList;
  242. return assList;
  243. },
  244. refreshAfterUpdate:function(result){
  245. let ration_glj = projectObj.project.ration_glj;
  246. let calcInstall = false;//是否记取安装增加费
  247. let nodes = projectObj.project.updateNodesCache([{type:ModuleNames.ration,data:result.ration}]);
  248. if(result.add && result.add.length > 0){//需添加定额工料机的情况
  249. ration_glj.datas = ration_glj.datas.concat(result.add);
  250. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.add);
  251. }
  252. if(result.delete && result.delete.length > 0 && this.deleteGLJs(result.delete)) calcInstall = true; //这样保证delete返回值是true的时候才改变变量类型
  253. if(result.replace && result.replace.length > 0){ //替换工料机的情况
  254. for(let r of result.replace){//替换缓存内容
  255. ration_glj.datas.splice(_.findIndex(ration_glj.datas,{'ID': r.ID}),1,r);
  256. gljOprObj.sheetData.splice(_.findIndex(gljOprObj.sheetData,{'ID': r.ID}),1,r);
  257. let node = ration_glj.updateGLJNodeAfterReplace(r);
  258. if(node) nodes.push(node);
  259. }
  260. }
  261. projectObj.mainController.refreshTreeNode(nodes, false);
  262. let rationID = result.ration.ID;
  263. ration_glj.updateCacheAfterAdjust(result.ration_glj);
  264. if(result.projectGLJList && result.projectGLJList.length > 0){//有添加、替换、工料机等需重新加载的情况
  265. projectObj.project.projectGLJ.loadNewProjectGLJToCaches(result.projectGLJList,true);
  266. if(result.add && result.add.length > 0) ration_glj.addToMainTree(result.add);//这个方法有再去项目工料机那里取价格,所以要在回调里调用,不像替换工料的情况
  267. ration_glj.reCalcWhenGLJChange({rationID:rationID});
  268. if(result.delete && result.delete.length > 0 && calcInstall) installationFeeObj.calcInstallationFee();//如果是删除节点的话,
  269. }else {
  270. ration_glj.reCalcWhenGLJChange({rationID:rationID});
  271. }
  272. gljOprObj.refreshView();
  273. },
  274. deleteGLJs:function (IDs) {
  275. let ration_glj = projectObj.project.ration_glj;
  276. let glj_list = ration_glj.datas;
  277. let calcInstall = false;
  278. let oldData = _.remove(glj_list, function (o) {
  279. return _.includes(IDs,o.ID);
  280. });
  281. _.remove(gljOprObj.sheetData, function (o) {
  282. return _.includes(IDs,o.ID);
  283. });
  284. for (let o of oldData) {
  285. if (ration_glj.needShowToTree(o)) {
  286. let node = ration_glj.findGLJNodeByID(o.ID); //找到对应的树节点
  287. projectObj.mainController.deleteNode(node, null);
  288. calcInstall = true;
  289. }
  290. }
  291. return calcInstall;
  292. },
  293. refresh:function () {
  294. zmhs_obj.initSpread();
  295. let pre = $('#divide_subSpread').is(':visible')?"divide_":"";
  296. $('#'+pre+'coeSpread').is(':visible')&&this[pre+'coeSpread']?this[pre+'coeSpread'].refresh():'';
  297. $('#'+pre+'coeSpread').is(':visible')&&this[pre+'coeSpread']?this.showDatas():'';//这里combobox下拉框要重新加载一下
  298. $('#'+pre+'cusSpread').is(':visible')&&this[pre+'cusSpread']?this[pre+'cusSpread'].refresh():'';
  299. $('#'+pre+'assSpread').is(':visible')&&this[pre+'assSpread']?this[pre+'assSpread'].refresh():'';
  300. $('#'+pre+'stableSpread').is(':visible')&&this[pre+'stableSpread']?this[pre+'stableSpread'].refresh():'';
  301. },
  302. showDatas:function () {
  303. if($('#itemCharacterText').is(':visible'))MaterialController.showItemCharacterText()
  304. if($('#coeSpread').is(':visible')) this.showCoeData();
  305. if($('#cusSpread').is(':visible')) this.showCusData();
  306. if($('#assSpread').is(':visible')) this.showAssData();
  307. if($('#stableSpread').is(':visible')) this.showStableData();
  308. },
  309. refreshStableDataIfNeeded: function () {
  310. if ($('#stableSpread').is(':visible')) {
  311. this.showStableData();
  312. }
  313. },
  314. showZMHSData:function (node) {
  315. if(this.coeSpread&& this.assSpread && $('#linkZMHS').hasClass('active')){
  316. this.showCoeData(node);
  317. this.showAssData(node);
  318. }
  319. },
  320. onCoeCellClick: function (sender, args) {
  321. let me = zmhs_obj;
  322. let sheet = args.sheet, row = args.row, col = args.col;
  323. if(sheet.getCell(row, col).locked() !=true){
  324. if(!sheet.isEditing()) sheet.startEdit();
  325. }
  326. },
  327. onButtonClick:function (sender, args) {
  328. let me = zmhs_obj;
  329. let sheet = args.sheet, row = args.row, col = args.col;
  330. let cellType = sheet.getCellType(row, col);
  331. if (args.sheetName == 'ration_coe' && cellType instanceof GC.Spread.Sheets.CellTypes.CheckBox) {
  332. me.onCoeCheckBoxClick(sender, args)
  333. }
  334. },
  335. bindCusEditorValue:function(context){
  336. let me = zmhs_obj;
  337. if(me.coeSheetData[context.row]){
  338. let data = me.coeSheetData[context.row];
  339. for(let c of data.coes){
  340. $("#"+ c.coeType).val(c.amount);
  341. }
  342. /*$('#coe_ration').val(data.coes[0].amount);
  343. $('#manual').val(data.coes[1].amount);
  344. $('#material').val(data.coes[2].amount);
  345. $('#manchine').val(data.coes[3].amount);
  346. $('#mainM').val(data.coes[4].amount);
  347. $('#equipment').val(data.coes[5].amount);*/
  348. }
  349. },
  350. updateCusCoeAfterEditor:function(){
  351. let me = zmhs_obj;
  352. let result = me.checkIfNeedUpdate();
  353. if (result.isNeed) {
  354. projectObj.project.ration_coe.updateCustomerCoe(result);
  355. }
  356. },
  357. onInputChange(id, name){
  358. var coe = _.find(zmhs_obj.coeSheetData, function (c) {
  359. return c.coeID == -1;
  360. });
  361. if(coe){
  362. let newValue = zmhs_obj.numberValueChecking($('#' + id).val());
  363. if (newValue) {
  364. newValue = _.round(newValue, 2);
  365. if (newValue == coe.coes[name].amount) return;
  366. if (id == '定额') {
  367. for(let c of coe.coes){
  368. $('#'+c.coeType).val(newValue)
  369. }
  370. } else {
  371. $('#' + id).val(newValue);
  372. }
  373. } else {
  374. $('#' + id).val(coe.coes[name].amount);
  375. }
  376. }
  377. },
  378. onInputClick(ele){//点中系数单元格,则默认选中系数值
  379. setSelection(ele,0,$(ele).val().length)
  380. },
  381. checkIfNeedUpdate(){
  382. let data = _.find(zmhs_obj.coeSheetData, function (c) {
  383. return c.coeID == -1;
  384. });
  385. let result = {isNeed: false};
  386. if(data){
  387. for(let c of data.coes){
  388. let amount = $("#"+c.coeType).val();
  389. if(amount!=c.amount){
  390. result.isNeed = true;
  391. c.amount = amount;
  392. }
  393. }
  394. if (result.isNeed) {
  395. result.doc = {
  396. coes: data.coes
  397. };
  398. result.query = {
  399. projectID: data.projectID,
  400. ID: data.ID,
  401. rationID: data.rationID
  402. };
  403. }
  404. }
  405. return result;
  406. },
  407. numberValueChecking: function (val) {
  408. var newval = Number(val);
  409. if (number_util.isNumber(newval)) {
  410. return newval;
  411. } else {
  412. if (val) {
  413. alert('您输入的数据类型不正确,请重新输入。');
  414. }
  415. newval = null;
  416. }
  417. return newval;
  418. },
  419. onCoeCheckBoxClick:function (sender, args) {
  420. let me = zmhs_obj;
  421. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  422. let newval = 0;
  423. if (checkboxValue) {
  424. newval = 0;
  425. args.sheet.getCell(args.row, args.col).value(newval);
  426. } else {
  427. newval = 1;
  428. args.sheet.getCell(args.row, args.col).value(newval);
  429. }
  430. let recode = me.coeSheetData[args.row];
  431. recode.assistCode && recode.assistCode != "" ? me.adjustAssClick(args,newval) : projectObj.project.ration_coe.adjustCoeClick(recode, newval);
  432. },
  433. generateHtmlString: function (context,cellRect,$editor) {//这里要改成动态的了,根据自定义系数内容生成对应的输入框
  434. let me = zmhs_obj;
  435. let height = cellRect.height;
  436. let offect = 0;
  437. let newString = "<form style='margin-top:1px' ><table width='100%' cellpadding='0' border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;'>";
  438. let cus_coe = me.coeSheetData[context.row];
  439. if(cus_coe){
  440. for(let i =0;i< cus_coe.coes.length;i++){
  441. newString += me.getOneRow(cus_coe.coes[i].coeType, i, cus_coe.coes[i].coeType,height);
  442. offect += height +3
  443. }
  444. }
  445. newString += "</table></form><div style='height:"+ height+"px'><div onclick='zmhs_obj.coeSheet.endEdit()' style='margin:-1px 1px 0px'>自定义系数</div></div>";
  446. $editor.html(newString);
  447. $editor.css("margin-top",-(offect+2));
  448. return newString;
  449. },
  450. getOneRow: function (text, name, id,inputHeight) {
  451. var rowstr = "<tr ><td style='width: 50%'>" + text
  452. + ":</td><td style='width: 50%' align='right'><input class='text-right' type='text' value='1' name=" + name
  453. + " style='width:100%;border:0;height:"+ inputHeight+"px;' align='right' id=" + id + " onchange='zmhs_obj.onInputChange(this.id,this.name)' onclick='zmhs_obj.onInputClick(this)' autocomplete='off'></td></tr>";
  454. return rowstr;
  455. },
  456. coeStartEdit(){
  457. if(zmhs_obj.coeSheet.isEditing()){
  458. return;
  459. }else {
  460. zmhs_obj.coeSheet.startEdit();
  461. }
  462. },
  463. onCoeRangeChanged:function(e,args){
  464. if(args.action == GC.Spread.Sheets.RangeChangedAction.clear){
  465. args.newValue = null;//目前只支持delete清除辅助定额
  466. zmhs_obj.onCoeValueChange(e,args);
  467. }
  468. },
  469. onCoeValueChange:function (e,args) {
  470. let fieldID = zmhs_obj.coeSetting.header[args.col].dataCode;
  471. let recode = zmhs_obj.coeSheetData[args.row];
  472. if(gljUtil.isDef(recode.option_codes)&&recode.option_codes!=""&& fieldID == 'name'){//说明是选择了下拉框
  473. projectObj.project.ration_coe.adjustCoeClick(recode, 1,{'select_code':args.newValue});
  474. }else if(recode.assistCode &&recode.assistCode!=""){//编辑的是辅助定额
  475. zmhs_obj.updateRationAss({editingText:args.newValue,row:args.row - zmhs_obj.assFirstIndex})//转换一下
  476. }
  477. },
  478. onCusValueChange:function (e,args) {
  479. zmhs_obj.changeCusValue([{row:args.row,col:args.col,value:args.newValue}]);
  480. },
  481. changeCusValue:function (datas) {//[{row:,col,value}]
  482. if(this.cusSheetData){
  483. let tem_coes = _.cloneDeep(this.cusSheetData.coes);
  484. for(let d of datas){
  485. if(d.value&&!sheetCommonObj.checkData(d.col,this.cusSetting,d.value)){
  486. this.showDatas();
  487. alert('输入的数据类型不对,请重新输入!');
  488. return;
  489. }
  490. if(gljUtil.isDef(d.value)&&d.value !=""){
  491. if(tem_coes[d.row].coeType=="定额"){
  492. for(let t of tem_coes){
  493. t.amount = d.value;
  494. }
  495. }else {
  496. tem_coes[d.row].amount = d.value;
  497. }
  498. }
  499. }
  500. let doc = {'coes':tem_coes,'content':this.generationContent(tem_coes)};
  501. projectObj.project.ration_coe.adjustCoeClick(this.cusSheetData, 1,doc);
  502. }
  503. },
  504. generationContent:function (coes) {
  505. let rationAmount = coes[0].amount;
  506. let string ='';
  507. if(_.every(coes,'amount',rationAmount)){
  508. string = coes[0].coeType + 'x'+rationAmount;
  509. }else {
  510. let context_arr =[];
  511. for(let i =1;i<coes.length;i++){
  512. context_arr.push( coes[i].coeType + 'x'+coes[i].amount);
  513. }
  514. string = context_arr.join(',');
  515. }
  516. return string;
  517. },
  518. onAssEditEnded:function (e,args) {
  519. var me = zmhs_obj;
  520. if (args.row >= me.assSheetData.length) {
  521. me.assSheet.getCell(args.row, args.col).value(null);
  522. return;
  523. }
  524. if (me.assSetting.header[args.col].dataCode == 'actualValue') {//实际值
  525. me.updateRationAss(args);
  526. }
  527. },
  528. onCusRangeChanged:function (e,args) {
  529. let datas = [];
  530. for(let c of args.changedCells){
  531. let value= args.sheet.getCell(c.row, c.col).text();
  532. datas.push({row:c.row,col:c.col,value:value})
  533. }
  534. zmhs_obj.changeCusValue(datas);
  535. },
  536. onAssRangeChanged:function (e,args) {
  537. let me = zmhs_obj;
  538. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  539. args.editingText = null;
  540. }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
  541. args.editingText = args.sheet.getCell(args.row,args.col).value();
  542. }
  543. if (args.sheetName == 'ration_ass') {
  544. me.updateRationAss(args);
  545. }
  546. },
  547. adjustAssClick:function (args,newval) {
  548. let me = zmhs_obj, row = args.row - me.assFirstIndex;
  549. projectObj.project.ration_ass.updateActualValue(me.assSheetData, row,null,newval);
  550. },
  551. updateRationAss: function (args) {
  552. var me = zmhs_obj;
  553. var newval;
  554. newval = me.numberValueChecking(args.editingText);
  555. var recode = me.assSheetData[args.row];
  556. if (args.editingText === null) {
  557. newval = parseFloat(recode.stdValue);
  558. }
  559. var isValidate = false;
  560. if (newval) {
  561. isValidate = me.checkingActualValue(recode, newval)
  562. }
  563. if (isValidate) {
  564. newval = scMathUtil.roundTo(newval, -2);
  565. projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval);
  566. } else {
  567. me.showDatas();
  568. }
  569. },
  570. checkingActualValue(record, newval){
  571. let minExist = record.minValue && record.minValue != '0' ? true : false;
  572. let maxExist = record.maxValue && record.maxValue != '0' ? true : false;
  573. let minValue = parseFloat(record.minValue);
  574. let maxValue = parseFloat(record.maxValue);
  575. if (!maxExist && minExist) {
  576. if (newval < minValue) {
  577. alert('实际值应≥' + minValue);
  578. return false;
  579. }
  580. }
  581. if (maxExist && !minExist) {
  582. if (newval > maxValue) {
  583. alert('实际值应≤' + maxValue);
  584. return false;
  585. }
  586. }
  587. if (maxExist && minExist) {
  588. if (newval < minValue || newval > maxValue) {
  589. alert('实际值应介于' + minValue + '~' + maxValue + '之间');
  590. return false;
  591. }
  592. }
  593. return true;
  594. },
  595. onStableValueChange: function (e, args) {
  596. const changeData = [{ row: args.row, col: args.col, value: args.newValue }];
  597. zmhs_obj.changeStableValue(changeData);
  598. },
  599. onStableRangeChanged: function (e, args) {
  600. const changeData = args.changedCells.map(cell => {
  601. const value = args.sheet.getValue(cell.row, cell.col);
  602. return { row: cell.row, col: cell.col, value};
  603. });
  604. zmhs_obj.changeStableValue(changeData);
  605. },
  606. changeStableValue: function (data) {
  607. const isValid = data.every(cell => commonUtil.isDef(cell.value) && sheetCommonObj.checkData(cell.col, this.stableSetting, cell.value));
  608. if (!isValid) {
  609. this.showDatas();
  610. alert('输入的数据类型不对,请重新输入!');
  611. return;
  612. }
  613. const precision = this.stableSetting.header.find(item => item.dataCode === 'adjustProportion').precision;
  614. this.handleDataWithPrecision(data, precision);
  615. const sheetData = this.getAutoStableSheetData(data, precision);
  616. // 获取需要更新的数据
  617. const rationGLJ = projectObj.project.ration_glj;
  618. const updateProportionList = this.getStablePostData(sheetData);
  619. const projectID = projectObj.project.ID();
  620. const rationID = projectObj.project.mainTree.selected.data.ID;
  621. rationGLJ.updateProportion(updateProportionList, projectID, rationID);
  622. },
  623. // 将值进行四舍五入处理
  624. handleDataWithPrecision: function (data, precision) {
  625. data.forEach(cell => {
  626. cell.value = scMathUtil.roundTo(cell.value, -precision);
  627. });
  628. },
  629. // 获取经过自动处理后的表格数据
  630. getAutoStableSheetData: function (changedData, precision) {
  631. const expectedValue = 100;
  632. const unchangedData = [];
  633. const col = this.stableSetting.header.findIndex(item => item.dataCode === 'adjustProportion');
  634. this.stableSheetData.forEach((item, index) => {
  635. const matchData = changedData.find(dItem => dItem.row === index);
  636. if (!matchData) {
  637. unchangedData.push({ row: index, col: col, value: item.adjustProportion});
  638. }
  639. });
  640. // 稳定土各项调整配合比总值必须为100,不为100则自动调整某一项
  641. const allData = _.sortBy(changedData.concat(unchangedData), 'row');
  642. const total = allData.reduce((acc, cur) => scMathUtil.roundTo(acc + cur.value, -precision), 0);
  643. if (total === expectedValue) {
  644. return allData;
  645. }
  646. const autoAdjustData = getAutoAdjustData(changedData, unchangedData);
  647. // 排除自动调整行后的总值
  648. const exclusionTotal = allData.reduce((acc, cur) =>
  649. cur.row !== autoAdjustData.row
  650. ? scMathUtil.roundTo(acc + cur.value, -precision)
  651. : acc + 0 , 0);
  652. const autoAdjustValue = scMathUtil.roundTo(expectedValue - exclusionTotal, -precision);
  653. autoAdjustData.value = autoAdjustValue;
  654. return allData;
  655. // 获取自动调整行数据
  656. function getAutoAdjustData(changedData, unchangedData) {
  657. debugger;
  658. const changedMaxData = changedData[changedData.length - 1];
  659. // 如果不存在不变的数据,自动调整行号为:最大变化数据行
  660. if (!unchangedData.length) {
  661. return changedMaxData;
  662. }
  663. const unchangedMinData = unchangedData[0];
  664. // 如果存在不变的数据,则自动调整配合比的行数据为:比最大变化数据行大的行,或最小未变数据行
  665. const greaterData = unchangedData.find(item => item.row > changedMaxData.row);
  666. return greaterData ? greaterData : unchangedMinData;
  667. }
  668. },
  669. getStablePostData: function (sheetData) {
  670. const postData = [];
  671. sheetData.forEach(cell => {
  672. const originItem = this.stableSheetData[cell.row];
  673. if (cell.value !== originItem.adjustProportion) {
  674. postData.push({ ID: originItem.ID, adjustProportion: cell.value});
  675. }
  676. });
  677. return postData;
  678. },
  679. getSideResize: function () {
  680. let zmhs_sideResizeEles = {};
  681. zmhs_sideResizeEles.eleObj = {
  682. module: zmhs_obj.module,
  683. resize: $('#zmhsResize'),
  684. parent: $('#tabZMHS'),
  685. left: $('#coeSpread'),
  686. right: $('#assDiv')
  687. };
  688. zmhs_sideResizeEles.limit = {
  689. min: 100,
  690. max: `$('#tabZMHS').width()-100`
  691. };
  692. return zmhs_sideResizeEles;
  693. },
  694. loadSideResize: function () {
  695. let resizeObj = this.getSideResize();
  696. SlideResize.loadHorizonWidth(resizeObj.eleObj.module, [resizeObj.eleObj.resize], [resizeObj.eleObj.left, resizeObj.eleObj.right]);
  697. }
  698. };