zmhs_view.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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: 250, dataCode: "name", dataType: "String", cellType: "button"},
  13. {headerName: "内容", headerWidth: 160, dataCode: "content", dataType: "String", hAlign: "left",getText:'forContent'}
  14. ],
  15. view: {
  16. lockColumns:[0,1,2],
  17. rowHeaderWidth:25
  18. },
  19. getText:{
  20. forContent:function (item) {
  21. if(gljUtil.isDef(item.select_code)&&item.select_code!=""){
  22. return item.select_code;
  23. }else {
  24. return item.content;
  25. }
  26. }
  27. },
  28. autoFit:true,
  29. fitRow:['name']
  30. },
  31. assSpread:null,
  32. assSheet:null,
  33. assSheetData: [],
  34. assSetting: {
  35. header: [
  36. {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  37. {headerName: "定额值", headerWidth: 80, dataCode: "stdValue", hAlign: "right", dataType: "String"},
  38. {headerName: "实际值", headerWidth: 80, dataCode: "actualValue", hAlign: "right", dataType: "String"}
  39. ],
  40. view: {
  41. lockColumns: [0, 1],
  42. rowHeaderWidth:25
  43. }
  44. },
  45. initSpread:function () {
  46. this.initCoeSpread();
  47. this.initAssSpread();
  48. },
  49. initCoeSpread:function () {
  50. if(zmhs_obj.coeSpread == null){
  51. this.coeSpread = SheetDataHelper.createNewSpread($("#coeSpread")[0]);
  52. sheetCommonObj.spreadDefaultStyle(this.coeSpread);
  53. this.coeSheet = this.coeSpread.getSheet(0);
  54. sheetCommonObj.initSheet(this.coeSheet, this.coeSetting, 30);
  55. this.coeSheet.name('ration_coe');
  56. this.coeSheet.bind(GC.Spread.Sheets.Events.CellClick, this.onCoeCellClick);
  57. this.coeSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onButtonClick);
  58. this.coeSheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onCoeValueChange);
  59. this.coeSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e,args) {
  60. args.sheet.repaint();
  61. });
  62. SheetDataHelper.protectdSheet(this.coeSheet);
  63. }
  64. },
  65. initAssSpread:function () {
  66. if(zmhs_obj.assSheet == null){
  67. this.assSpread = SheetDataHelper.createNewSpread($("#assSpread")[0]);
  68. sheetCommonObj.spreadDefaultStyle(this.assSpread);
  69. this.assSheet = this.assSpread.getSheet(0);
  70. sheetCommonObj.initSheet(this.assSheet, this.assSetting, 30);
  71. this.assSheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onAssEditEnded);
  72. this.assSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onAssRangeChanged);
  73. this.assSheet.name('ration_ass');
  74. SheetDataHelper.protectdSheet(this.assSheet);
  75. }
  76. },
  77. showCoeData:function (node) {
  78. let selected = node?node:projectObj.project.mainTree.selected;
  79. let ration_coe = projectObj.project.ration_coe;
  80. let coeList = [];
  81. if(selected&&selected.sourceType == "ration"){
  82. let ration = selected.data;
  83. coeList = ration_coe.getCoeByRationID(ration.ID);
  84. }
  85. sheetCommonObj.showData(this.coeSheet, this.coeSetting,coeList);
  86. if (coeList.length > 0) {
  87. this.coeSheet.suspendPaint();
  88. this.coeSheet.suspendEvent();
  89. for(let i =0;i<coeList.length;i++ ){
  90. if(gljUtil.isDef(coeList[i].option_codes)&&coeList[i].option_codes!=""){
  91. this.getComboBoxForCodes(coeList[i],i);//设置可选类型的下拉框
  92. // sheet.setValue(row, col, val, ch);
  93. } else if(coeList[i].coeID == -1){ //自定义系数列
  94. this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  95. this.coeSheet.setCellType(i, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport);
  96. }
  97. }
  98. this.coeSheet.resumeEvent();
  99. this.coeSheet.resumePaint();
  100. }
  101. this.coeSheetData = coeList;
  102. if(projectReadOnly){
  103. disableSpread(zmhs_obj.coeSpread);
  104. }
  105. },
  106. getComboBoxForCodes:function (coe,i) {
  107. this.coeSheet.getCell(i, 2, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  108. let options = coe.option_codes.split("|");
  109. let combo = sheetCommonObj.getDynamicCombo(true);
  110. combo.itemHeight(options.length).items(options);
  111. this.coeSheet.setCellType(i, 2, combo, GC.Spread.Sheets.SheetArea.viewport);
  112. this.coeSheet.setValue(i, 2, coe.select_code);
  113. },
  114. showAssData:function (node) {
  115. this.assSheet.suspendPaint();
  116. this.assSheet.suspendEvent();
  117. let selected = node?node:projectObj.project.mainTree.selected;
  118. let assList = selected&&selected.data.rationAssList ? selected.data.rationAssList : [];
  119. this.assSheet.setRowCount(0);
  120. sheetCommonObj.showData(this.assSheet, this.assSetting, assList);
  121. this.assSheetData = assList;
  122. this.assSheet.getRange(assList.length,-1,this.assSheet.getRowCount()-assList.length, -1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  123. this.assSheet.resumePaint();
  124. this.assSheet.resumeEvent();
  125. if(projectReadOnly){
  126. disableSpread(this.assSpread);
  127. }
  128. },
  129. refreshAfterUpdate:function(result,reload){
  130. let ration_glj = projectObj.project.ration_glj;
  131. let calcInstall = false;//是否记录安装增加费
  132. let nodes = projectObj.project.updateNodesCache([{type:ModuleNames.ration,data:result.ration}]);
  133. if(result.add && result.add.length > 0){//需添加定额工料机的情况
  134. ration_glj.datas = ration_glj.datas.concat(result.add);
  135. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.add);
  136. }
  137. if(result.delete && result.delete.length > 0 && this.deleteGLJs(result.delete)) calcInstall = true; //这样保证delete返回值是true的时候才改变变量类型
  138. if(result.replace && result.replace.length > 0){ //替换工料机的情况
  139. for(let r of result.replace){//替换缓存内容
  140. ration_glj.datas.splice(_.findIndex(ration_glj.datas,{'ID': r.ID}),1,r);
  141. gljOprObj.sheetData.splice(_.findIndex(gljOprObj.sheetData,{'ID': r.ID}),1,r);
  142. let node = ration_glj.updateGLJNodeAfterReplace(r);
  143. if(node) nodes.push(node);
  144. }
  145. }
  146. projectObj.mainController.refreshTreeNode(nodes, false);
  147. let rationID= ration_glj.updateCacheAfterAdjust(result.ration_glj);
  148. if(reload == true){//有添加、替换、工料机等需重新加载的情况
  149. $.bootstrapLoading.start();
  150. projectObj.project.projectGLJ.loadData(function () {
  151. $.bootstrapLoading.end();
  152. if(result.add && result.add.length > 0) ration_glj.addToMainTree(result.add);//这个方法有再去项目工料机那里取价格,所以要在回调里调用,不像替换工料的情况
  153. ration_glj.reCalcWhenGLJChange({rationID:rationID});
  154. if(result.delete && result.delete.length > 0 && calcInstall) installationFeeObj.calcInstallationFee();//如果是删除节点的话,
  155. });
  156. }else {
  157. ration_glj.reCalcWhenGLJChange({rationID:rationID});
  158. }
  159. gljOprObj.showRationGLJSheetData(true);
  160. },
  161. deleteGLJs:function (IDs) {
  162. let ration_glj = projectObj.project.ration_glj;
  163. let glj_list = ration_glj.datas;
  164. let calcInstall = false;
  165. let oldData = _.remove(glj_list, function (o) {
  166. return _.includes(IDs,o.ID);
  167. });
  168. _.remove(gljOprObj.sheetData, function (o) {
  169. return _.includes(IDs,o.ID);
  170. });
  171. for (let o of oldData) {
  172. if (ration_glj.needShowToTree(o)) {
  173. let node = ration_glj.findGLJNodeByID(o.ID); //找到对应的树节点
  174. projectObj.mainController.deleteNode(node, null);
  175. calcInstall = true;
  176. }
  177. }
  178. return calcInstall;
  179. },
  180. refresh:function () {
  181. this.coeSpread?this.coeSpread.refresh():'';
  182. this.assSpread?this.assSpread.refresh():'';
  183. },
  184. showZMHSData:function (node) {
  185. if(this.coeSpread&& this.assSpread && $('#linkZMHS').hasClass('active')){
  186. this.showCoeData(node);
  187. this.showAssData(node);
  188. }
  189. },
  190. onCoeCellClick: function (sender, args) {
  191. let me = zmhs_obj;
  192. let sheet = args.sheet, row = args.row, col = args.col;
  193. if(sheet.getCell(row, col).locked() !=true){
  194. if(!sheet.isEditing()) sheet.startEdit();
  195. }
  196. },
  197. onButtonClick:function (sender, args) {
  198. let me = zmhs_obj;
  199. let sheet = args.sheet, row = args.row, col = args.col;
  200. let cellType = sheet.getCellType(row, col);
  201. if (args.sheetName == 'ration_coe' && cellType instanceof GC.Spread.Sheets.CellTypes.CheckBox) {
  202. me.onCoeCheckBoxClick(sender, args)
  203. }
  204. },
  205. bindCusEditorValue:function(context){
  206. let me = zmhs_obj;
  207. if(me.coeSheetData[context.row]){
  208. let data = me.coeSheetData[context.row];
  209. for(let c of data.coes){
  210. $("#"+ c.coeType).val(c.amount);
  211. }
  212. /*$('#coe_ration').val(data.coes[0].amount);
  213. $('#manual').val(data.coes[1].amount);
  214. $('#material').val(data.coes[2].amount);
  215. $('#manchine').val(data.coes[3].amount);
  216. $('#mainM').val(data.coes[4].amount);
  217. $('#equipment').val(data.coes[5].amount);*/
  218. }
  219. },
  220. updateCusCoeAfterEditor:function(){
  221. let me = zmhs_obj;
  222. let result = me.checkIfNeedUpdate();
  223. if (result.isNeed) {
  224. projectObj.project.ration_coe.updateCustomerCoe(result);
  225. }
  226. },
  227. onInputChange(id, name){
  228. var coe = _.find(zmhs_obj.coeSheetData, function (c) {
  229. return c.coeID == -1;
  230. });
  231. if(coe){
  232. let newValue = zmhs_obj.numberValueChecking($('#' + id).val());
  233. if (newValue) {
  234. newValue = _.round(newValue, 2);
  235. if (newValue == coe.coes[name].amount) return;
  236. if (id == '定额') {
  237. for(let c of coe.coes){
  238. $('#'+c.coeType).val(newValue)
  239. }
  240. } else {
  241. $('#' + id).val(newValue);
  242. }
  243. } else {
  244. $('#' + id).val(coe.coes[name].amount);
  245. }
  246. }
  247. },
  248. onInputClick(ele){//点中系数单元格,则默认选中系数值
  249. setSelection(ele,0,$(ele).val().length)
  250. },
  251. checkIfNeedUpdate(){
  252. let data = _.find(zmhs_obj.coeSheetData, function (c) {
  253. return c.coeID == -1;
  254. });
  255. let result = {isNeed: false};
  256. if(data){
  257. for(let c of data.coes){
  258. let amount = $("#"+c.coeType).val();
  259. if(amount!=c.amount){
  260. result.isNeed = true;
  261. c.amount = amount;
  262. }
  263. }
  264. if (result.isNeed) {
  265. result.doc = {
  266. coes: data.coes
  267. };
  268. result.query = {
  269. projectID: data.projectID,
  270. ID: data.ID,
  271. rationID: data.rationID
  272. };
  273. }
  274. }
  275. return result;
  276. },
  277. numberValueChecking: function (val) {
  278. var newval = Number(val);
  279. if (number_util.isNumber(newval)) {
  280. return newval;
  281. } else {
  282. if (val) {
  283. alert('您输入的数据类型不正确,请重新输入。');
  284. }
  285. newval = null;
  286. }
  287. return newval;
  288. },
  289. onCoeCheckBoxClick:function (sender, args) {
  290. let me = zmhs_obj;
  291. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  292. let newval = 0;
  293. if (checkboxValue) {
  294. newval = 0;
  295. args.sheet.getCell(args.row, args.col).value(newval);
  296. } else {
  297. newval = 1;
  298. args.sheet.getCell(args.row, args.col).value(newval);
  299. }
  300. let recode = me.coeSheetData[args.row];
  301. projectObj.project.ration_coe.adjustCoeClick(recode, newval);
  302. },
  303. generateHtmlString: function (context,cellRect,$editor) {//这里要改成动态的了,根据自定义系数内容生成对应的输入框
  304. let me = zmhs_obj;
  305. let height = cellRect.height;
  306. let offect = 0;
  307. let newString = "<form style='margin-top:1px' ><table width='100%' cellpadding='0' border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;'>";
  308. let cus_coe = me.coeSheetData[context.row];
  309. if(cus_coe){
  310. for(let i =0;i< cus_coe.coes.length;i++){
  311. newString += me.getOneRow(cus_coe.coes[i].coeType, i, cus_coe.coes[i].coeType,height);
  312. offect += height +3
  313. }
  314. }
  315. newString += "</table></form><div style='height:"+ height+"px'><div onclick='zmhs_obj.coeSheet.endEdit()' style='margin:-1px 1px 0px'>自定义系数</div></div>";
  316. $editor.html(newString);
  317. $editor.css("margin-top",-(offect+2));
  318. return newString;
  319. },
  320. getOneRow: function (text, name, id,inputHeight) {
  321. var rowstr = "<tr ><td style='width: 50%'>" + text
  322. + ":</td><td style='width: 50%' align='right'><input class='text-right' type='text' value='1' name=" + name
  323. + " 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>";
  324. return rowstr;
  325. },
  326. coeStartEdit(){
  327. if(zmhs_obj.coeSheet.isEditing()){
  328. return;
  329. }else {
  330. zmhs_obj.coeSheet.startEdit();
  331. }
  332. },
  333. onCoeValueChange:function (e,args) {
  334. let fieldID = zmhs_obj.coeSetting.header[args.col].dataCode;
  335. let recode = zmhs_obj.coeSheetData[args.row];
  336. if(gljUtil.isDef(recode.option_codes)&&recode.option_codes!=""&& fieldID == 'content'){//说明是选择了下拉框
  337. projectObj.project.ration_coe.adjustCoeClick(recode, 1,{'select_code':args.newValue});
  338. }
  339. },
  340. onAssEditEnded:function (e,args) {
  341. var me = zmhs_obj;
  342. if (args.row >= me.assSheetData.length) {
  343. me.assSheet.getCell(args.row, args.col).value(null);
  344. return;
  345. }
  346. if (me.assSetting.header[args.col].dataCode == 'actualValue') {//实际值
  347. me.updateRationAss(args);
  348. }
  349. },
  350. onAssRangeChanged:function (e,args) {
  351. let me = zmhs_obj;
  352. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  353. args.editingText = null;
  354. }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
  355. args.editingText = args.sheet.getCell(args.row,args.col).value();
  356. }
  357. if (args.sheetName == 'ration_ass') {
  358. me.updateRationAss(args);
  359. }
  360. },
  361. updateRationAss: function (args) {
  362. var me = zmhs_obj;
  363. var newval;
  364. newval = me.numberValueChecking(args.editingText);
  365. var recode = me.assSheetData[args.row];
  366. if (args.editingText === null) {
  367. newval = parseFloat(recode.stdValue);
  368. }
  369. var isValidate = false;
  370. if (newval) {
  371. isValidate = me.checkingActualValue(recode, newval)
  372. }
  373. if (isValidate) {
  374. newval = scMathUtil.roundTo(newval, -2);
  375. projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval);
  376. } else {
  377. newval = recode.actualValue;
  378. me.assSheet.getCell(args.row, args.col).value(newval);
  379. }
  380. },
  381. checkingActualValue(record, newval){
  382. let minExist = record.minValue && record.minValue != '0' ? true : false;
  383. let maxExist = record.maxValue && record.maxValue != '0' ? true : false;
  384. let minValue = parseFloat(record.minValue);
  385. let maxValue = parseFloat(record.maxValue);
  386. if (!maxExist && minExist) {
  387. if (newval < minValue) {
  388. alert('实际值应≥' + minValue);
  389. return false;
  390. }
  391. }
  392. if (maxExist && !minExist) {
  393. if (newval > maxValue) {
  394. alert('实际值应≤' + maxValue);
  395. return false;
  396. }
  397. }
  398. if (maxExist && minExist) {
  399. if (newval < minValue || newval > maxValue) {
  400. alert('实际值应介于' + minValue + '~' + maxValue + '之间');
  401. return false;
  402. }
  403. }
  404. return true;
  405. },
  406. getSideResize: function () {
  407. let zmhs_sideResizeEles = {};
  408. zmhs_sideResizeEles.eleObj = {
  409. module: zmhs_obj.module,
  410. resize: $('#zmhsResize'),
  411. parent: $('#tabZMHS'),
  412. left: $('#coeSpread'),
  413. right: $('#assDiv')
  414. };
  415. zmhs_sideResizeEles.limit = {
  416. min: 100,
  417. max: `$('#tabZMHS').width()-100`
  418. };
  419. return zmhs_sideResizeEles;
  420. },
  421. loadSideResize: function () {
  422. let resizeObj = this.getSideResize();
  423. SlideResize.loadHorizonWidth(resizeObj.eleObj.module, [resizeObj.eleObj.resize], [resizeObj.eleObj.left, resizeObj.eleObj.right]);
  424. }
  425. };
  426. /*let zmhsResize = zmhs_obj.getSideResize();
  427. SlideResize.horizontalSlide(zmhsResize.eleObj, zmhsResize.limit, function () {
  428. zmhs_obj.refresh();
  429. });*/