From c4d7604a8f8b14aeddef6c45b0b330b3fb966b5e Mon Sep 17 00:00:00 2001 From: red-deng-deng <1924913374@qq.com> Date: Thu, 11 Nov 2021 19:18:41 +0800 Subject: [PATCH] update --- src/pages/system/station/main.js | 57 ++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/pages/system/station/main.js b/src/pages/system/station/main.js index 311c448b..40f96950 100644 --- a/src/pages/system/station/main.js +++ b/src/pages/system/station/main.js @@ -13,12 +13,16 @@ export default class station extends React.Component{ companyBtn:true, departmentBtn:true, postBtn:true, + editId:0, visible: false, company:[{id:1,name:'四川科技有限公司'},{id:2,name:'北京科技有限公司'},{id:3,name:'上海科技有限公司'}], department:[{id:1-1,name:'技术部'},{id:2,name:'财务部'},{id:3,name:'行政部'}], post:[{id:1-1-1,name:'后端'},{id:2,name:'前端'},{id:3,name:'测试'}], } this.addItem=this.addItem.bind(this); + this.changeval= this.changeval.bind(this); + this.editFns= this.editFns.bind(this); + } onChange = options => { @@ -149,6 +153,54 @@ export default class station extends React.Component{ delbtnFn(){ this.setState({'visible':true}); } + editFns(e,key){ + e.target.parentNode.parentNode.children[0].disabled=""; + e.target.parentNode.parentNode.children[0].focus(); + this.setState({editId:key}); + } + changeval(e,row,placeholder){ + let index=this.hasVal(this.state.company,row); + let companydata=_.cloneDeepWith(this.state.company, []); + if(index!=-1){ + companydata[index]['name']=e.target.value; + this.setState({company:companydata}); + console.log(e); + if(e.target.value&&e.keyCode==13){ + let cssname=null; + let stationame=[]; + if(placeholder=='公司'){ + cssname='companyBtn'; + stationame=this.state.company + }else if(placeholder=='部门'){ + cssname='departmentBtn'; + stationame=this.state.department + }else if(placeholder=='岗位'){ + cssname='postBtn'; + stationame=this.state.post + } + + if(this.hasVal(stationame,e.target.value)>-1){ + Notify.clear() + Notify.warn(`${placeholder}已存在,请重新增加`); + }else{ + e.parentNode.children[1].firstChild.innerHTML='删除'; + e.disabled="disabled"; + e.parentNode.className=cssname+" newitem"; + Notify.clear() + Notify.success('保存成功'); + e.parentNode.children[1].lastChild.innerHTML="编辑"; + if(placeholder=='公司'){ + this.setState({'companyBtn':true}); + }else if(placeholder=='部门'){ + this.setState({'departmentBtn':true}); + }else if(placeholder=='岗位'){ + this.setState({'postBtn':true}); + } + } + } + } + + } addItem(e,disbtn){ //获取节点,追加填入的input let flag=null; @@ -217,9 +269,10 @@ export default class station extends React.Component{ { this.state.company.map((item,key)=>{ return( -
+
this.sureFn(e,'公司')} disabled onChange={(e)=>this.changeval(e,item.name,'公司')}/>

this.saveFn(e,'公司')}>删除

+ " onClick={(e)=>this.saveFn(e,'公司')}>删除this.editFns(e,key)} style={{marginLeft:'15px'}}>编辑

) })