71697291
舒述军
添加站岗小组
|
1
2
3
4
5
6
|
import React, { useState, useEffect, useRef } from 'react';
import { Modal, Button, message, Form, Input, Switch, Select, Tag } from 'antd';
import {useStore} from '../index';
import { authShopRoleListApi } from '@/common/api';
import { List, saveStandGroupApi } from '../api';
import { debounce } from 'lodash';
|
2ff0eb35
zhangkang
站岗门店优化
|
7
|
import ShopSelect from '@/components/ShopSelect';
|
71697291
舒述军
添加站岗小组
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
const Option = Select.Option;
interface RoleShop {
roleCode?: string // 角色编码
roleName?: string // 角色名称
shopId?: number // 门店id
shopName?: string // 门店名称
}
export default function DetailModal() {
const { visible, setVisible, shopList, roleList, setLoading: setPageLoading, currentItem, setCurrentItem } = useStore();
const [loading, setLoading] = useState<boolean>(false);
const [staffList, setStaffList] = useState<any>([]);
const [roleShop, setRoleShop] = useState<RoleShop>({});
|
71697291
舒述军
添加站岗小组
|
23
24
|
const [form] = Form.useForm();
const resetRef = useRef<any>(true);
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
25
|
// const [shopValue, setShopValue] = useState<any>();
|
71697291
舒述军
添加站岗小组
|
26
27
28
|
useEffect(() => {
if (visible && currentItem.id) {
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
29
30
|
const _staff = currentItem?.staffList?.map((i:any) => ({value: i.staffId, label: i.staffName}));
// setShopValue([{value: currentItem.shopId, label: currentItem.shopName}]);
|
71697291
舒述军
添加站岗小组
|
31
32
33
34
|
form.setFieldsValue({
name: currentItem.name,
roleCode: currentItem.roleCode,
roleName: currentItem.roleName,
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
35
|
shop: [{value: currentItem.shopId, label: currentItem.shopName}],
|
2ff0eb35
zhangkang
站岗门店优化
|
36
|
staff: _staff,
|
71697291
舒述军
添加站岗小组
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
});
setRoleShop({roleCode: currentItem.roleCode, roleName: currentItem.roleName, shopId: currentItem.shopId, shopName: currentItem.shopName});
}
}, [visible]);
useEffect(() => {
if (roleShop.roleCode && roleShop.shopId) {
getStaffList(roleShop);
// 编辑首次进入不重置表单人员
if (!(currentItem.id && resetRef.current)) {
form.setFieldsValue({staff: []});
}
resetRef.current = false;
} else {
setStaffList([]);
form.setFieldsValue({staff: []});
|
71697291
舒述军
添加站岗小组
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
}
}, [roleShop.roleCode, roleShop.shopId]);
// 获取员工列表
function getStaffList(params: any) {
authShopRoleListApi({rangeValue: params.shopId, roleCode: params.roleCode})
.then(res => {
setStaffList(res.data || []);
})
.catch(e => message.error(e.message));
}
function handleCancel() {
setVisible(false);
resetStatus();
}
// 重置页面数据
function resetStatus() {
form.resetFields();
setStaffList([]);
setRoleShop({});
setCurrentItem({});
|
71697291
舒述军
添加站岗小组
|
76
77
78
79
80
|
resetRef.current = true;
}
async function onFinish() {
const params = await form.validateFields();
|
71697291
舒述军
添加站岗小组
|
81
|
setLoading(true);
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
82
|
const _staff = params.staff.map((v:any) => {
|
71697291
舒述军
添加站岗小组
|
83
84
|
const k = {
staffId: v.value,
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
85
|
staffName: v.label
|
71697291
舒述军
添加站岗小组
|
86
87
88
89
|
};
return k;
});
const _params: List = {
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
90
91
|
shopId: Array.isArray(params.shop)? params.shop[0].value: params.shop.value,
shopName: Array.isArray(params.shop)? params.shop[0].label: params.shop.label,
|
71697291
舒述军
添加站岗小组
|
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
roleCode: params.roleCode,
roleName: roleShop.roleName,
staffList: _staff,
name: params.name
};
if (currentItem.id) {
_params.id = currentItem.id;
}
saveStandGroupApi(_params)
.then(res => {
message.success(res.result);
setLoading(false);
setVisible(false);
resetStatus();
setPageLoading(true);
})
.catch(e => {
message.error(e.message);
setLoading(false);
});
}
return (
<Modal
destroyOnClose
forceRender
title={currentItem.id ? "编辑站岗小组" : "新增站岗小组"}
visible={visible}
maskClosable={false}
onCancel={handleCancel}
footer={[
|
2ff0eb35
zhangkang
站岗门店优化
|
123
124
125
126
127
128
129
130
131
132
133
134
135
|
<Button key="cancel" onClick={handleCancel} style={{ marginLeft: 10 }}>
取消
</Button>,
<Button
key="submit"
onClick={debounce(() => onFinish(), 380)}
type="primary"
htmlType="submit"
loading={loading}
>
确认
</Button>,
]}
|
71697291
舒述军
添加站岗小组
|
136
|
>
|
2ff0eb35
zhangkang
站岗门店优化
|
137
138
139
140
141
142
|
<Form form={form} labelCol={{ span: 6 }} wrapperCol={{ span: 18 }}>
<Form.Item
label="小组名称"
rules={[{ required: true, message: "请输入小组名称!" }]}
name="name"
>
|
c3b0ca1e
舒述军
修改输入提示
|
143
|
<Input placeholder="请输入小组名称" allowClear />
|
71697291
舒述军
添加站岗小组
|
144
|
</Form.Item>
|
2ff0eb35
zhangkang
站岗门店优化
|
145
146
147
148
149
150
|
<Form.Item
label="门店"
name="shop"
rules={[{ required: true, message: "请选择门店!" }]}
>
{/* <Select
|
71697291
舒述军
添加站岗小组
|
151
152
153
154
155
156
157
|
placeholder="门店"
allowClear
showSearch
optionFilterProp="children"
onChange={(value, option: any) => setRoleShop({...roleShop, shopId: value || undefined, shopName: option.children || undefined})}
>
{shopList.length && shopList.map(item => <Option key={item.id} value={item.id}>{item.name}</Option>)}
|
2ff0eb35
zhangkang
站岗门店优化
|
158
159
160
161
162
163
164
165
|
</Select> */}
<ShopSelect
labelInValue
onChange={(item: any) => setRoleShop({
...roleShop,
shopId: item.value || undefined,
shopName: item.label || undefined,
})}
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
166
|
// value={shopValue}
|
2ff0eb35
zhangkang
站岗门店优化
|
167
|
/>
|
71697291
舒述军
添加站岗小组
|
168
|
</Form.Item>
|
2ff0eb35
zhangkang
站岗门店优化
|
169
170
171
172
173
|
<Form.Item
label="角色名称"
name="roleName"
rules={[{ required: true, message: "请选择角色!" }]}
>
|
71697291
舒述军
添加站岗小组
|
174
175
176
177
178
|
<Select
placeholder="角色编码"
allowClear
showSearch
optionFilterProp="children"
|
2ff0eb35
zhangkang
站岗门店优化
|
179
180
181
182
183
184
185
186
|
onChange={(value, option: any) => {
setRoleShop({
...roleShop,
roleCode: value || undefined,
roleName: option.children || undefined,
});
form.setFieldsValue({ roleCode: value || undefined });
}}
|
71697291
舒述军
添加站岗小组
|
187
|
>
|
2ff0eb35
zhangkang
站岗门店优化
|
188
189
190
191
192
193
|
{roleList.length &&
roleList.map((item) => (
<Option key={item.roleCode} value={item.roleCode}>
{item.roleName}
</Option>
))}
|
71697291
舒述军
添加站岗小组
|
194
195
|
</Select>
</Form.Item>
|
2ff0eb35
zhangkang
站岗门店优化
|
196
197
198
199
200
|
<Form.Item
label="角色码"
rules={[{ required: true, message: "请选择角色!" }]}
name="roleCode"
>
|
c3b0ca1e
舒述军
修改输入提示
|
201
|
<Input placeholder="请选择角色" allowClear disabled />
|
71697291
舒述军
添加站岗小组
|
202
|
</Form.Item>
|
2ff0eb35
zhangkang
站岗门店优化
|
203
204
205
206
207
|
<Form.Item
label="员工"
name="staff"
rules={[{ required: true, message: "请选择员工!" }]}
>
|
71697291
舒述军
添加站岗小组
|
208
209
210
211
212
213
214
|
<Select
placeholder="请选择员工"
allowClear
showSearch
mode="multiple"
showArrow={false}
optionFilterProp="children"
|
227df3b1
莫红玲
站岗小组编辑bugfix
|
215
|
labelInValue
|
71697291
舒述军
添加站岗小组
|
216
|
>
|
2ff0eb35
zhangkang
站岗门店优化
|
217
218
219
220
221
222
|
{staffList.length &&
staffList.map((item: any) => (
<Option key={item.userId} value={item.userId}>
{item.userName}
</Option>
))}
|
71697291
舒述军
添加站岗小组
|
223
224
225
226
227
228
|
</Select>
</Form.Item>
</Form>
</Modal>
);
}
|