Commit 8fc136ac by wufan

feat:完成企业微信对接

parent ef85c884
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: wufan * @Author: wufan
* @Date: 2020-11-27 16:21:49 * @Date: 2020-11-27 16:21:49
* @LastEditors: wufan * @LastEditors: wufan
* @LastEditTime: 2020-12-28 10:21:12 * @LastEditTime: 2021-01-09 16:32:41
* @Description: Description * @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -35,17 +35,23 @@ interface AddEmployeeModalProps { ...@@ -35,17 +35,23 @@ interface AddEmployeeModalProps {
role: Array<string>; role: Array<string>;
avatar?: string; avatar?: string;
storeUserId?: string; storeUserId?: string;
weChatAccount?: string
}; };
onClose: () => void; onClose: () => void;
isWorkWechat: boolean;
} }
function AddEmployeeModal(props: AddEmployeeModalProps) { function AddEmployeeModal(props: AddEmployeeModalProps) {
const [nickName, setName] = useState(""); const [nickName, setName] = useState("");
const [phone, setPhone] = useState(""); const [phone, setPhone] = useState("");
const [role, setRole] = useState("CloudLecturer"); const [role, setRole] = useState("CloudLecturer");
const [avatar, setAvatar] = useState("https://image.xiaomaiketang.com/xm/rJeQaZxtc7.png"); const [avatar, setAvatar] = useState(
"https://image.xiaomaiketang.com/xm/rJeQaZxtc7.png"
);
const storeUserId = props.choosedItem.storeUserId; const storeUserId = props.choosedItem.storeUserId;
const [imgUrl, setImgUrl] = useState(avatar || 'https://image.xiaomaiketang.com/xm/rJeQaZxtc7.png'); const [imgUrl, setImgUrl] = useState(
avatar || "https://image.xiaomaiketang.com/xm/rJeQaZxtc7.png"
);
const [nameErrorMsg, setNameErrorMsg] = useState(""); const [nameErrorMsg, setNameErrorMsg] = useState("");
const [nameStatus, setNameStatus] = useState< const [nameStatus, setNameStatus] = useState<
"" | "error" | "success" | "warning" | "validating" | undefined "" | "error" | "success" | "warning" | "validating" | undefined
...@@ -64,14 +70,16 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -64,14 +70,16 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
props.choosedItem.phone && setPhone(props.choosedItem.phone); props.choosedItem.phone && setPhone(props.choosedItem.phone);
props.choosedItem.role && setRole(props.choosedItem.role[0]); props.choosedItem.role && setRole(props.choosedItem.role[0]);
props.choosedItem.avatar && setAvatar(props.choosedItem.avatar); props.choosedItem.avatar && setAvatar(props.choosedItem.avatar);
const _role = props.choosedItem.role[0] === "CloudLecturer" ? "CloudLecturer" : "CloudManager"; const _role =
props.choosedItem.role[0] === "CloudLecturer"
? "CloudLecturer"
: "CloudManager";
form.setFieldsValue({ form.setFieldsValue({
nickName: props.choosedItem.nickName, nickName: props.choosedItem.nickName,
role: _role, role: _role,
phone: props.choosedItem.phone, phone: props.choosedItem.phone,
avatar: props.choosedItem.avatar avatar: props.choosedItem.avatar,
}); });
} }
}, [props.choosedItem.nickName]); }, [props.choosedItem.nickName]);
...@@ -98,7 +106,7 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -98,7 +106,7 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
function changeAvatar(img: string): any { function changeAvatar(img: string): any {
form.setFieldsValue({ form.setFieldsValue({
avatar: img avatar: img,
}); });
setAvatar(img); setAvatar(img);
setImgUrl(img); setImgUrl(img);
...@@ -118,7 +126,7 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -118,7 +126,7 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
setNameErrorMsg(""); setNameErrorMsg("");
setNameStatus(""); setNameStatus("");
if (!String(values.phone)) { if (!String(values.phone) && !props.isWorkWechat) {
setPhoneErrorMessage("请输入手机号码"); setPhoneErrorMessage("请输入手机号码");
setPhoneStatus("error"); setPhoneStatus("error");
return; return;
...@@ -126,7 +134,7 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -126,7 +134,7 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
setPhoneErrorMessage(""); setPhoneErrorMessage("");
setPhoneStatus(""); setPhoneStatus("");
if (String(values.phone).length !== 11) { if (String(values.phone).length !== 11 && !props.isWorkWechat) {
setPhoneErrorMessage("请输入11位手机号"); setPhoneErrorMessage("请输入11位手机号");
setPhoneStatus("error"); setPhoneStatus("error");
return; return;
...@@ -135,7 +143,6 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -135,7 +143,6 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
setPhoneStatus(""); setPhoneStatus("");
props.choosedItem.nickName ? handleEditEmployee() : handleAddEmployee(); props.choosedItem.nickName ? handleEditEmployee() : handleAddEmployee();
} }
function handleChangeValues(name: string, value: any) { function handleChangeValues(name: string, value: any) {
...@@ -160,17 +167,16 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -160,17 +167,16 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
default: default:
break; break;
} }
} }
function handleAddEmployee() { function handleAddEmployee() {
const params = { const params = {
nickName, nickName,
phone: String(phone), phone: String(phone),
roleCodes:[role], roleCodes: [role],
avatar avatar,
}; };
console.log("params",params); console.log("params", params);
StoreService.addEmployee(params).then((res) => { StoreService.addEmployee(params).then((res) => {
message.success("保存成功"); message.success("保存成功");
props.onClose(); props.onClose();
...@@ -181,11 +187,11 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -181,11 +187,11 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
const params = { const params = {
nickName, nickName,
phone: String(phone), phone: String(phone),
roleCodes:[role], roleCodes: [role],
avatar, avatar,
storeUserId:storeUserId storeUserId: storeUserId,
}; };
console.log("params",params); console.log("params", params);
StoreService.editEmployee(params).then((res) => { StoreService.editEmployee(params).then((res) => {
message.success("编辑成功"); message.success("编辑成功");
...@@ -226,7 +232,14 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -226,7 +232,14 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
onChange={(e) => handleChangeValues("nickName", e.target.value)} onChange={(e) => handleChangeValues("nickName", e.target.value)}
/> />
</Form.Item> </Form.Item>
{props.isWorkWechat ? (
<Form.Item
label="企业微信账号"
name="weChatAccount"
>
<div>{props.choosedItem.weChatAccount}</div>
</Form.Item>
) : (
<Form.Item <Form.Item
label="手机号码" label="手机号码"
name="phone" name="phone"
...@@ -241,17 +254,16 @@ function AddEmployeeModal(props: AddEmployeeModalProps) { ...@@ -241,17 +254,16 @@ function AddEmployeeModal(props: AddEmployeeModalProps) {
autoComplete="off" autoComplete="off"
disabled={!!props.choosedItem.nickName} disabled={!!props.choosedItem.nickName}
onChange={(e) => { onChange={(e) => {
if((e.target.value).match(/^\d+$/)){ if (e.target.value.match(/^\d+$/)) {
handleChangeValues("phone", e.target.value); handleChangeValues("phone", e.target.value);
} else { } else {
setPhoneErrorMessage("只能输入数字"); setPhoneErrorMessage("只能输入数字");
setPhoneStatus("error"); setPhoneStatus("error");
} }
} }}
}
/> />
</Form.Item> </Form.Item>
)}
<Form.Item <Form.Item
label="员工身份" label="员工身份"
name="role" name="role"
......
...@@ -15,4 +15,12 @@ ...@@ -15,4 +15,12 @@
color: #BFBFBF; color: #BFBFBF;
} }
} }
.employee-info {
img {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 20px;
}
}
} }
...@@ -17,6 +17,7 @@ import EmployeeAddOrEditModal from "./EmployeeAddOrEditModal"; ...@@ -17,6 +17,7 @@ import EmployeeAddOrEditModal from "./EmployeeAddOrEditModal";
import User from "@/common/js/user"; import User from "@/common/js/user";
import "./EmployeesManagePage.less"; import "./EmployeesManagePage.less";
import Item from "antd/lib/list/Item";
const { confirm } = Modal; const { confirm } = Modal;
const { Search } = Input; const { Search } = Input;
...@@ -29,6 +30,7 @@ interface RecordTypes { ...@@ -29,6 +30,7 @@ interface RecordTypes {
nickName: string; nickName: string;
phone: string; phone: string;
avatar?: string; avatar?: string;
weChatAccount?: string;
} }
interface RoleItemType { interface RoleItemType {
...@@ -52,6 +54,7 @@ interface ChoosedItemType { ...@@ -52,6 +54,7 @@ interface ChoosedItemType {
role: Array<string>; role: Array<string>;
avatar?: string; avatar?: string;
storeUserId?: string; storeUserId?: string;
weChatAccount?: string;
} }
function EmployeesManagePage() { function EmployeesManagePage() {
...@@ -61,7 +64,7 @@ function EmployeesManagePage() { ...@@ -61,7 +64,7 @@ function EmployeesManagePage() {
size: 10, size: 10,
nickName: "", nickName: "",
phone: "", phone: "",
roleCodes: [] roleCodes: [],
}); });
const [valueLike, setValueLike] = useState(); const [valueLike, setValueLike] = useState();
...@@ -83,6 +86,8 @@ function EmployeesManagePage() { ...@@ -83,6 +86,8 @@ function EmployeesManagePage() {
StoreManager: "店铺管理员", StoreManager: "店铺管理员",
}; };
const storeId = User.getStoreId(); const storeId = User.getStoreId();
const StoreType = User.getStoreType();
const isWorkWechat = !!(StoreType === "WE_CHAT_STORE");
useEffect(() => { useEffect(() => {
getEmployeeList(); getEmployeeList();
...@@ -110,7 +115,7 @@ function EmployeesManagePage() { ...@@ -110,7 +115,7 @@ function EmployeesManagePage() {
const data = [...res.result]; const data = [...res.result];
const _query = { ...query }; const _query = { ...query };
let _data = _.filter(data, _item => { let _data = _.filter(data, (_item) => {
return _item.roleCode !== "StoreManager"; return _item.roleCode !== "StoreManager";
}); });
...@@ -119,13 +124,23 @@ function EmployeesManagePage() { ...@@ -119,13 +124,23 @@ function EmployeesManagePage() {
} }
function parseColumn() { function parseColumn() {
return [ const columns = [
{ {
title: "员工", title: "员工",
dataIndex: "nickName", dataIndex: "nickName",
render: (val: string) => { render: (val: string, record: RecordTypes) => {
return ( return (
<div className="coupon-info"> <div className="employee-info">
{isWorkWechat && (
<img
src={
record.avatar ||
"https://image.xiaomaiketang.com/xm/rJeQaZxtc7.png"
}
alt=""
/>
)}
<span className="title">{val}</span> <span className="title">{val}</span>
</div> </div>
); );
...@@ -162,7 +177,11 @@ function EmployeesManagePage() { ...@@ -162,7 +177,11 @@ function EmployeesManagePage() {
<span className="divider-line">{" | "}</span> <span className="divider-line">{" | "}</span>
<span <span
className="delete" className="delete"
onClick={() => handleDeleteEmployeeConfirm(record)} onClick={() =>{
isWorkWechat?
handleDeleteWorkWechatEmployeeConfirm(record) :
handleDeleteEmployeeConfirm(record)
}}
> >
删除 删除
</span> </span>
...@@ -171,16 +190,30 @@ function EmployeesManagePage() { ...@@ -171,16 +190,30 @@ function EmployeesManagePage() {
}, },
}, },
]; ];
if (isWorkWechat && columns) {
const item = {
title: "企业微信账号",
dataIndex: "weChatAccount",
key: "weChatAccount",
render: (val: string) => {
return <div>{val}</div>;
},
};
columns.splice(1, 1, item);
}
return columns;
} }
function handleEditEmployee(record: RecordTypes) { function handleEditEmployee(record: RecordTypes) {
const { nickName, phone, roleCodes, avatar, id } = record; const { nickName, phone, roleCodes, avatar, id, weChatAccount } = record;
const _choosesItem = { const _choosesItem = {
nickName: nickName, nickName: nickName,
phone: phone, phone: phone,
role: roleCodes, role: roleCodes,
avatar: avatar, avatar: avatar,
storeUserId: id, storeUserId: id,
weChatAccount
}; };
setChooseItem(_choosesItem); setChooseItem(_choosesItem);
const model: React.ReactNode = ( const model: React.ReactNode = (
...@@ -194,9 +227,11 @@ function EmployeesManagePage() { ...@@ -194,9 +227,11 @@ function EmployeesManagePage() {
phone: "", phone: "",
role: [], role: [],
avatar: "", avatar: "",
storeUserId: "" storeUserId: "",
weChatAccount:""
}); });
}} }}
isWorkWechat={isWorkWechat}
/> />
); );
setModel(model); setModel(model);
...@@ -206,9 +241,27 @@ function EmployeesManagePage() { ...@@ -206,9 +241,27 @@ function EmployeesManagePage() {
return confirm({ return confirm({
title: "你确定要删除此讲师吗?", title: "你确定要删除此讲师吗?",
content: "删除后,讲师将不能登录系统,此操作不能被撤销", content: "删除后,讲师将不能登录系统,此操作不能被撤销",
icon: <span className="icon iconfont default-confirm-icon">&#xe839; </span>, icon: (
<span className="icon iconfont default-confirm-icon">&#xe839; </span>
),
okText: "删除", okText: "删除",
okType: 'danger', okType: "danger",
cancelText: "取消",
onOk: () => {
handleDeleteEmployee(record.id);
},
});
}
function handleDeleteWorkWechatEmployeeConfirm(record: RecordTypes) {
return confirm({
title: "你确定要删除此员工吗?",
content: "管理员需在企业微信后台的“小麦企培”应用管理中移除此员工,此员工才无法继续登陆小麦企培",
icon: (
<span className="icon iconfont default-confirm-icon">&#xe839; </span>
),
okText: "删除",
okType: "danger",
cancelText: "取消", cancelText: "取消",
onOk: () => { onOk: () => {
handleDeleteEmployee(record.id); handleDeleteEmployee(record.id);
...@@ -228,9 +281,10 @@ function EmployeesManagePage() { ...@@ -228,9 +281,10 @@ function EmployeesManagePage() {
phone: "", phone: "",
role: [], role: [],
avatar: "", avatar: "",
storeUserId: "" storeUserId: "",
}); });
}} }}
isWorkWechat={isWorkWechat}
/> />
); );
setModel(model); setModel(model);
...@@ -238,7 +292,8 @@ function EmployeesManagePage() { ...@@ -238,7 +292,8 @@ function EmployeesManagePage() {
function handleDeleteEmployee(storeUserId: string) { function handleDeleteEmployee(storeUserId: string) {
StoreService.deleteEmployee({ storeUserId }).then((res: any) => { StoreService.deleteEmployee({ storeUserId }).then((res: any) => {
message.success("讲师已删除"); const msg = isWorkWechat ? "员工已删除":"讲师已删除";
message.success(msg);
getEmployeeList(); getEmployeeList();
}); });
} }
...@@ -269,17 +324,26 @@ function EmployeesManagePage() { ...@@ -269,17 +324,26 @@ function EmployeesManagePage() {
width: 300, width: 300,
marginRight: 40, marginRight: 40,
}} }}
placeholder="搜索员工昵称/手机号" placeholder={
isWorkWechat ? "请输入员工昵称" : "搜索员工昵称/手机号"
}
onSearch={(value) => { onSearch={(value) => {
const _query = { ...query }; const _query = { ...query };
// 企业微信用户只能搜索员工昵称
if (isWorkWechat) {
_query.nickName = value;
_query.current = 0;
setQuery(_query);
return;
}
if (value) { if (value) {
const isPhone = (value || "").match(/^\d+$/); const isPhone = (value || "").match(/^\d+$/);
const name = isPhone ? "phone" : "nickName"; const name = isPhone ? "phone" : "nickName";
const otherName = isPhone ? "nickName" : "phone"; const otherName = isPhone ? "nickName" : "phone";
_query[name] = value; _query[name] = value;
_query[otherName] = ''; _query[otherName] = "";
_query.current = 0; _query.current = 0;
} else { } else {
_query.nickName = ""; _query.nickName = "";
_query.phone = ""; _query.phone = "";
...@@ -327,6 +391,7 @@ function EmployeesManagePage() { ...@@ -327,6 +391,7 @@ function EmployeesManagePage() {
})} })}
</div> </div>
</div> </div>
{!isWorkWechat && (
<Button <Button
onClick={() => { onClick={() => {
handleToAddEmployee(); handleToAddEmployee();
...@@ -336,6 +401,7 @@ function EmployeesManagePage() { ...@@ -336,6 +401,7 @@ function EmployeesManagePage() {
> >
添加员工 添加员工
</Button> </Button>
)}
</div> </div>
<div className="box-body"> <div className="box-body">
<Table <Table
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
* @Author: wufan * @Author: wufan
* @Date: 2020-11-30 10:47:38 * @Date: 2020-11-30 10:47:38
* @LastEditors: wufan * @LastEditors: wufan
* @LastEditTime: 2020-12-22 11:52:56 * @LastEditTime: 2021-01-09 15:59:32
* @Description: 员工管理页面 * @Description: 店铺装修页面
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment