import React from 'react';
import { Icon, Modal, message, AutoComplete, Spin, Input, Select, Button, Form, Popconfirm, TreeSelect } from 'antd';
import $ from 'jquery/src/ajax';
import './userMangagement.less';
import { cityArr, station, post } from '../../../dataDic.js';
import { splitUrl, getNewArray } from '../../../tools.js';
import moment from 'moment';
import ImgList from "../../../common/imgList";
import StaffSearch from '../../../../component/common/staffSearch';
//图片组件
const PicturesWall = React.createClass({
getInitialState() {
return {
previewVisible: false,
previewImage: '',
fileList: [],
role: [],
district: [],
cityOption: [],
}
},
handleCancel() {
this.setState({ previewVisible: false })
},
handlePreview(file) {
this.setState({
previewImage: file.url || file.thumbUrl,
previewVisible: true,
});
},
handleChange(info) {
let fileList = info.fileList;
this.setState({ fileList });
this.props.fileList(fileList);
},
componentWillReceiveProps(nextProps) {
this.state.fileList = nextProps.pictureUrl;
},
render() {
const { previewVisible, previewImage, fileList } = this.state;
const uploadButton = (
);
return (
{
this.handleChange(infor)
}}
fileList={fileList}
/>
);
}
});
const Newuser = Form.create()(React.createClass({
getInitialState() {
return {
orgCodeUrl: [],
loading: false,
loaduser: {},
datauser: [],
role: [],
Business: [{ reviewerName: "", reviewerId: "" }], // 公出审核
Coorder: [{ reviewerName: "", reviewerId: "" }], // 协单审核
superiorList: [{ superior: '', superiorId: '' }], // 上级主管
publicCarbonCopyList: [{ publicCarbonCopy: "", publicCarbonCopyName: "" }], // 公出抄送
};
},
getDefaultProps() {
return {
userDetaile: false
}
},
handleSubmit(e) {
e.preventDefault();
if (!this.state.role || this.state.role.length === 0) {
message.warning('请选择角色');
return false;
};
// if (!this.state.status && this.props.userDetaile) {
// message.warning('请选择角色状态');
// return false;
// };
if (window.adminData.isSuperAdmin) {
if (!this.state.departmentId) {
message.warning('请选择组织部门');
return false;
};
}
// if (!this.state.theTypes && !this.state.superiorId) {
// message.warning('请输入正确的上级主管');
// return false;
// };
if (!this.state.superiorList.length) {
message.warning('请输入正确的上级主管');
return false;
} else {
let flag = true;
let text = '';
for (let i=0; i item.reviewerId == superiorItem.superiorId)) {
// text = `上级主管【${superiorItem.superior}】在公出审核人员中存在`;
// flag = false;
// continue;
// } else if (this.state.Coorder.some(item => item.reviewerId == superiorItem.superiorId)) {
// text = `上级主管【${superiorItem.superior}】在协单审核人员中存在`;
// flag = false;
// continue;
// } else if (this.state.managerId == superiorItem.superiorId) {
// text = `上级主管【${superiorItem.superior}】在经理审核人员中存在`;
// flag = false;
// continue;
// } else if (this.state.publicCarbonCopyList.some(item => item.publicCarbonCopy == superiorItem.superiorId)) {
// text = `上级主管【${superiorItem.superior}】在公出抄送人员中存在`;
// flag = false;
// continue;
// }
}
if (!flag) {
message.warning(text);
return false;
}
}
if (!getNewArray(this.state.Business, "reviewerId").toString()) {
message.warning('请输入正确的公出审核人');
return false;
}
if (this.state.publicCarbonCopyList.length) {
let flag = true;
let text = '';
for (let i=0; i item.superiorId).join(','),
// reviewer: this.state.reviewer,
district: this.state.district,
headPortraitUrl: theorgCodeUrl.length ? theorgCodeUrl : '',
entryTime: this.state.selTime,
ambId: !!this.state.ambId ? this.state.ambId : null,
managerId: this.state.managerId,
expenseSuperExamine: this.state.expenseSuperExamine, // 报销是否需要上级审核
publicCarbonCopy: this.state.publicCarbonCopy,// 公出抄送
callNo: this.state.callNo, // 外呼编号
teamId: this.state.teamId, // 团队
}),
publicReviewerIds: getNewArray(this.state.Business, "reviewerId").toString(),// 公出审核
assistReviewerIds: getNewArray(this.state.Coorder, "reviewerId").toString(),// 协单审核
superReviewerIds: uniqueSuperArr.map(item => item.superiorId).join(','), // 上级主管
carbonCopyReviewerIds: uniqueCarbonCopyReviewerArr.map(item => item.publicCarbonCopy).join(',') // 公出推送
}
}).done(function (data) {
this.setState({
loading: false
});
if (!data.error.length) {
message.success('保存成功!');
this.handleOk();
} else {
message.warning(data.error[0].message);
}
}.bind(this));
},
//主管初始加载(自动补全)
supervisor(e) {
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/organization/selectName",
data: {
name: e
},
success: function (data) {
let thedata = data.data;
if (!thedata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thedata = {};
};
this.setState({
customerArr: thedata,
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
//上级主管输入框失去焦点是判断客户是否存在
selectAuto(value, idx) {
let theType = '';
let contactLists = this.state.customerArr || [];
if (value) {
contactLists.map(function (item) {
if (item.name === value.toString()) {
theType = item.id;
}
});
}
const { superiorList } = this.state;
superiorList[idx].superiorId = theType;
superiorList[idx].superior = value;
this.setState({
// theTypes: theType,
// superior: value
superiorList
})
if (!this.state.reviewerName || !this.state.reviewer) {
this.setState({
reviewerName: value,
reviewer: theType
})
}
},
//值改变时请求客户名称
httpChange(e, idx) {
if (e.length >= 1) {
this.supervisor(e);
}
const { superiorList } = this.state;
superiorList[idx].superior = e;
this.setState({
superiorList
})
},
//查看基本详情基本信息
loaduser(record) {
if (record) {
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/superviser/selectAllByid',
data: {
id: record.id
},
success: function (data) {
let thisdata = data.data;
if (!thisdata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thisdata = {};
};
// let superiorList = [];
// let superiorIdArr = thisdata.superiorId ? thisdata.superiorId.toString().split(',') : [];
// let superiorArr = thisdata.superior ? thisdata.superior.toString().split(',') : [];
// superiorIdArr.map((id, idx) => {
// superiorList.push({ superiorId: id, superior: superiorArr[idx] });
// })
this.setState({
id: thisdata.id,
mobile: thisdata.mobile,
name: thisdata.name,
email: thisdata.email,
createTime: thisdata.createTime,
district: thisdata.district != ' ' ? JSON.parse(thisdata.district) : undefined,
position: thisdata.position ? thisdata.position : undefined,
superior: thisdata.superior,
superiorId: thisdata.superiorId,//上级Id
// superiorList, // 上级list
reviewerName: thisdata.reviewerName,
reviewer: thisdata.reviewer, // 公出审核人
managerName: thisdata.managerName,
managerId: thisdata.managerId, // 经理审核
theTypes: '',
duty: thisdata.duty ? thisdata.duty : undefined,//职务
publicPurview: thisdata.publicPurview,
seniorStaff: thisdata.seniorStaff,
status: Number(thisdata.status),
contactMobile: thisdata.contactMobile ? thisdata.contactMobile : undefined,//手机号
departmentId: thisdata.departmentId ? thisdata.departmentId : undefined,//部门id
userNo: thisdata.userNo,
orgCodeUrl: thisdata.headPortraitUrl ? splitUrl(thisdata.headPortraitUrl, ',', globalConfig.avatarHost + '/upload') : [],
role: this.props.role,
entryTime: thisdata.entryTime ? moment(thisdata.entryTime, 'YYYY-MM-DD') : undefined,
selTime: thisdata.entryTime,
ambId: !!thisdata.ambId && Number(thisdata.ambId), // 分巴id
expenseSuperExamine: thisdata.expenseSuperExamine, // 报销是否需要上级主管审核
publicCarbonCopy: thisdata.publicCarbonCopy, // 公出抄送
publicCarbonCopyName: thisdata.publicCarbonCopyName,
callNo: thisdata.callNo, // 外呼编号
teamId: thisdata.teamId, // 团队
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
}
},
getReviewer(record) {
if (record) {
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/superviser/publicReviewer',
data: {
id: record.id
},
success: function (data) {
let thisdata = data.data;
if (!thisdata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thisdata = {};
};
let superiorList = [{ superior: '', superiorId: '' }];
if (thisdata.superReviewer.length) {
superiorList = thisdata.superReviewer.map(item => {
return { superior: item.reviewerName, superiorId: item.reviewerId };
})
}
let publicCarbonCopyList = [{ publicCarbonCopyName: '', publicCarbonCopy: '' }];
if (thisdata.carbonCopyReviewer.length) {
publicCarbonCopyList = thisdata.carbonCopyReviewer.map(item => {
return { publicCarbonCopyName: item.reviewerName, publicCarbonCopy: item.reviewerId }
});
}
this.setState({
Business: thisdata.publicReviewer.length > 0 ? thisdata.publicReviewer : [{ reviewerName: "", reviewerId: "" }],
Coorder: thisdata.assistReviewer.length > 0 ? thisdata.assistReviewer : [{ reviewerName: "", reviewerId: "" }],
superiorList,
publicCarbonCopyList,
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
}
},
//重置密码
resetPwd() {
this.setState({
loading: true
})
$.ajax({
type: 'post',
url: globalConfig.context + "/api/admin/superviser/resetPwd",
dataType: "json",
data: {
id: this.props.datauser.id
},
}).done((res) => {
if (res.error && res.error.length) {
message.error(res.error[0].message);
} else {
message.success("密码重置成功");
}
}).always(() => {
this.setState({
loading: false
})
});
},
handleOk(e) {
this.props.closeDesc(false, true);
},
handleCancel(e) {
this.props.closeDesc(false);
},
//入职时间选择
selTime(e, index) {
this.setState({
entryTime: e,
selTime: index
})
},
getOrgCodeUrl(e) {
this.setState({ orgCodeUrl: e });
},
componentWillMount(e) {
const cityArrs = [];
cityArr.map(function (item) {
cityArrs.push(
{item.key}
)
});
this.state.cityOption = cityArrs;
},
componentDidMount() {
if (this.props.datauser.id) {
this.loaduser(this.props.datauser)
this.getReviewer(this.props.datauser)
this.setState({
rolek: this.props.role
})
}
},
add() {
const { Coorder } = this.state;
let arr = Coorder
let obj = { title: "", value: "" }
arr.push(obj)
this.setState({
Coorder: arr
})
},
remove(i) {
const { Coorder } = this.state;
let arr = Coorder
arr.splice(i, 1)
this.setState({
Coorder: arr
})
},
add1() {
const { Business } = this.state;
let arr = Business
let obj = { title: "", value: "" }
arr.push(obj)
this.setState({
Business: arr
})
},
remove1(i) {
const { Business } = this.state;
let arr = Business
arr.splice(i, 1)
this.setState({
Business: arr
})
},
addSupersor() {
const { superiorList } = this.state;
superiorList.push({ superiorId: '', superior: '' });
this.setState({ superiorList });
},
removeSupersor(idx) {
this.state.superiorList.splice(idx, 1)
this.setState({
superiorList: this.state.superiorList
});
},
addPublicCarbonCopy() {
const { publicCarbonCopyList } = this.state;
publicCarbonCopyList.push({ publicCarbonCopy: '', publicCarbonCopyName: '' });
this.setState({ publicCarbonCopyList });
},
removePublicCarbonCopy(idx) {
this.state.publicCarbonCopyList.splice(idx, 1)
this.setState({
publicCarbonCopyList: this.state.publicCarbonCopyList
});
},
render() {
const { Coorder, Business } = this.state
const FormItem = Form.Item
const formItemLayout = {
labelCol: { span: 8 },
wrapperCol: { span: 14 },
};
const dataSources = this.state.customerArr || [];
const options = dataSources.map((group, index) =>
{group.name}
)
const departmentArr = this.props.departmentArr || [];
const roleArrS = this.props.roleArr || [];
const rolst = this.state.rolek || [];
return (
)
}
}));
export default Newuser;