zmhs_view.js 17 KB

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