This commit is contained in:
red-deng-deng 2021-11-11 19:18:41 +08:00
parent b837423b6b
commit c4d7604a8f
1 changed files with 55 additions and 2 deletions

View File

@ -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(
<div className="newitem companyBtn"><input value={item.name}/>
<div className="newitem companyBtn"><input value={item.name} onKeyDown={(e)=>this.sureFn(e,'公司')} disabled onChange={(e)=>this.changeval(e,item.name,'公司')}/>
<p><span className="operation
" onClick={(e)=>this.saveFn(e,'公司')}>删除</span></p>
" onClick={(e)=>this.saveFn(e,'公司')}>删除</span><span className="operation
" onClick={(e)=>this.editFns(e,key)} style={{marginLeft:'15px'}}>编辑</span></p>
</div>
)
})