index.tsx
10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import React, { useEffect, useState } from "react";
import { Card, Popconfirm, Row, Button, message, Result, Form, Select, Radio, Input } from "antd";
import { FeeweeFileAccept, FeeweeFileChange } from "@/utils/getFidFile";
import { common } from "@/typing/common";
import { PlusOutlined } from "@ant-design/icons";
import { IMGURL } from "@/utils";
import { PageHeaderWrapper } from "@ant-design/pro-layout";
import { createStore } from "@/hooks/moz";
import { history } from "umi";
import store from "./store";
import PersonModal from "../components/PersonModal";
import { KpiGroupSetteing } from "@/pages/performance/KpiGroupSetting/interface";
import * as api from "./api";
import { ShopList, saveKpiGroupConfig } from "./api";
import IndivatorsTable from "./components/IndivatorsTable";
import FeeweeUpload from "@/components/FeeweeUpload";
import { transformDTO, transformFormData } from "../entity";
import moment from "moment";
import ShopSelectNew from "@/components/ShopSelectNew";
export const { Provider, useStore } = createStore(store);
const { Option } = Select;
interface Props extends common.ConnectProps {}
function Index(props: Props) {
const { postList, detailError, configId, setId, data, readOnly, setReadOnly, setSelectedSalaryIds } = useStore();
const [form] = Form.useForm();
const { match } = props;
const { id, read } = match.params;
// 选择岗位id
const [postId, setPostId] = useState<number>();
// 适用门店ids;
const [shopIds, setShopIds] = useState<string>();
const [saveLoading, setSaveLoading] = useState<boolean>(false);
// 门店列表
const [shopList, setShopList] = useState<ShopList[]>([]);
// 人员查看模块
const [personModal, setPersonModal] = useState<KpiGroupSetteing.Person>({
visible: false,
postId: undefined,
shopIds: "",
});
useEffect(() => {
setReadOnly(read === undefined ? false : read !== "false");
}, [read]);
useEffect(() => {
setId(id);
}, [id]);
// 控制回显
useEffect(() => {
if (configId && data) {
const res = transformFormData(data);
console.log('res', res);
form.setFieldsValue({
...res,
});
if (data.shopIds?.length > 0) {
setPersonModal({
postId: data.postId,
shopIds: data.shopIds.join(","),
visible: false,
});
setShopIds(data.shopIds.join(","));
}
if (data.projects && data.projects.length > 0) {
const _salaryProjectId: number[] = data.projects.map((item) => item.salaryProjectId);
setSelectedSalaryIds([..._salaryProjectId]);
}
// 保存已经
setPostId(data.postId);
}
}, [configId, data]);
// 查询门店
useEffect(() => {
if (data.postId) {
getDealerList(data.postId);
}
}, [data.postId]);
function handSubmit(fieldsValue: any) {
const _shopIds: number[] = fieldsValue.shop.map((item:any) => item.value);
const res = transformDTO(fieldsValue);
const _shopNames = fieldsValue.shop.map((item: any) => item.label);
const pa = { ...res, id: configId, shopNames: _shopNames };
console.log("总的提交表单pa", pa);
setSaveLoading(true);
saveKpiGroupConfig(pa)
.then((res) => {
setSaveLoading(false);
message.success("操作成功");
setSaveLoading(false);
history.goBack();
})
.catch((e) => {
setSaveLoading(false);
message.error(e.message);
});
}
// 根据岗位查门店
function getDealerList(postId: number) {
api
.queryShopByPost(postId)
.then((res) => {
setShopList(res.data || []);
})
.catch((e) => {
message.error(e.message);
});
}
// 人员查看
const personView = () => {
if (!personModal.postId) {
message.error("请选择岗位");
return;
}
if (personModal.shopIds.length === 0) {
message.error("请选择门店");
return;
}
setPersonModal({ ...personModal, visible: true });
};
return (
<PageHeaderWrapper title="薪酬组配置">
<Card>
{detailError ? (
<Result status="warning" title={detailError} />
) : (
<div style={{ paddingLeft: "10%", paddingRight: "10%" }}>
{/* 选择岗位和门店 */}
<Form
form={form}
name="control-hooks"
style={{ width: "80%" }}
initialValues={{
projects: [],
}}
onFinish={handSubmit}
>
<Form.Item label="薪酬组名称" name="name" rules={[{ required: true, message: "请输入薪酬组名称" }]}>
<Input />
</Form.Item>
<Form.Item name="post" label="岗位" rules={[{ required: true, message: "请选择岗位" }]}>
<Select
labelInValue
placeholder="请选择岗位"
allowClear
showSearch
optionFilterProp="children"
disabled={readOnly}
onChange={(post: { label: string; value: number; key: number }) => {
setPersonModal({
postId: post.value,
visible: false,
shopIds: undefined,
});
setPostId(post.value);
setShopIds("");
form.setFieldsValue({ shop: [] });
// 根据岗位查门店
if (post) {
getDealerList(post.value);
}
}}
>
{postList.map((item) => (
<Option value={item.id}>{item.postName}</Option>
))}
</Select>
</Form.Item>
<Form.Item name="shop" label="门店" rules={[{ required: true, message: "请选择门店" }]}>
{/* <Select
placeholder="请选择门店"
allowClear
mode="multiple"
labelInValue
disabled={readOnly}
onChange={(
shops: {
key: number;
label: string;
value: number;
}[]
) => {
const shopIds = shops.map((item) => item.value).join(",");
setShopIds(shopIds);
setPersonModal({
...personModal,
shopIds,
});
}}
>
{shopList.map((item) => (
<Option value={item.shopId}>{item.shopName}</Option>
))}
</Select> */}
{/* map那里注意加小括号 */}
<ShopSelectNew
multiple
disabled={readOnly}
shopIds={shopList.map((item) => item.shopId)}
type={2}
onChange={(
shops: {
key: number;
label: string;
value: number;
}[]
) => {
const shopIds = shops.map((item) => item.value).join(",");
setShopIds(shopIds);
setPersonModal({
...personModal,
shopIds,
});
}}
/>
</Form.Item>
<div style={{ marginBottom: 20 }}>
<a onClick={() => personView()}>{`人员查看 >`}</a>
</div>
<Form.Item name="projects" label="薪酬项目" rules={[{ required: true }]}>
<IndivatorsTable postId={postId} shopIds={shopIds} />
</Form.Item>
{/* 查看详情直接展示时间 */}
{readOnly ? (
<Form.Item name="beginTimeType" label="生效月度" rules={[{ required: true, message: "请选择" }]}>
{data.beginTime && moment(data.beginTime).format("YYYY年MM月")}
</Form.Item>
) : (
<Form.Item name="beginTimeType" label="生效月度" rules={[{ required: true, message: "请选择" }]}>
<Radio.Group>
<Radio value={1}>本月</Radio>
<Radio value={2}>次月</Radio>
</Radio.Group>
</Form.Item>
)}
<Form.Item name="reason" label="调整原因">
<Input.TextArea allowClear showCount maxLength={512} disabled={readOnly} />
</Form.Item>
<Form.Item
label="上传附件"
name="salaryAttachList"
valuePropName="fileList"
getValueFromEvent={FeeweeFileChange}
extra="请上传PDF/视频MP4/音频MP3/图片/Word/Excel/PPT"
>
<FeeweeUpload
accept={FeeweeFileAccept}
listType="picture-card"
disabled={readOnly}
limitSize={100}
action={IMGURL.uploadUrl}
>
<div>
<PlusOutlined />
</div>
</FeeweeUpload>
</Form.Item>
</Form>
<Row justify="center" style={{ marginTop: 100 }}>
<Button
type="default"
size="large"
onClick={() => history.goBack()}
style={{ marginRight: 50, width: 200 }}
>
返回
</Button>
{!readOnly && (
<Popconfirm title="确定完成,提交后不可更改?" onConfirm={form.submit} okText="确定" cancelText="取消">
<Button type="primary" size="large" style={{ width: 200 }} loading={saveLoading}>
提交
</Button>
</Popconfirm>
)}
</Row>
<PersonModal item={personModal} setPersonModal={setPersonModal} />
</div>
)}
</Card>
</PageHeaderWrapper>
);
}
export default (props: Props) => (
<Provider>
<Index {...props} />
</Provider>
);