Blame view

src/pages/performance/EvaGroupSetting/EditComfirm/components/AddEvaGroupModal.tsx 9.68 KB
a7b88b33   曾柯   考评组设置部分
1
2
3
  /* eslint-disable no-return-assign */
  /* eslint-disable no-return-assign */
  import React, { useEffect, useState } from "react";
4d934cf7   曾柯   考评组配置0208
4
  import { Modal, Form, Select, InputNumber, message, Spin, Radio, Input, Button, DatePicker } from "antd";
a7b88b33   曾柯   考评组设置部分
5
6
7
8
  import { saveRewardsListApi } from "../RewardsList/api";
  import { useStore } from "../index";
  import _ from "lodash";
  import useInitail from "@/hooks/useInitail";
dae0d4f2   曾柯   考评组设置1645
9
  import { EvaGroupSetteing } from "@/pages/performance/EvaGroupSetting/interface";
4d934cf7   曾柯   考评组配置0208
10
11
12
13
14
  import * as api from "@/pages/performance/KpiGroupSetting/EditComfirm/api";
  import ShopSelectNew from "@/components/ShopSelectNew";
  import PersonModal from "@/pages/performance/KpiGroupSetting/components/PersonModal";
  import { transformDTO } from "../entity";
  import IndivatorsTable from "./IndivatorsTable";
cd477b8c   曾柯   考评0213
15
  import RewardsTableSal from "./RewardsTableSal";
4927eb1a   曾柯   考评组设置加列表及草稿
16
17
  import moment from "moment";
  import { getManagerRoleListApi } from "@/common/api";
a7b88b33   曾柯   考评组设置部分
18
19
  
  const Option = Select.Option;
4d934cf7   曾柯   考评组配置0208
20
  const { RangePicker } = DatePicker;
a7b88b33   曾柯   考评组设置部分
21
22
23
  interface Props {
    visible: boolean;
    onCancel: Function;
a7b88b33   曾柯   考评组设置部分
24
    onOk: (vales: any) => void;
dae0d4f2   曾柯   考评组设置1645
25
    evaItem: EvaGroupSetteing.EvalGroups;
a34f5d4b   曾柯   考评bugfix
26
27
    scopeType: number;
    setScopeType: Function;
a7b88b33   曾柯   考评组设置部分
28
29
30
  }
  
  export default function AddIndicatorsModal(props: Props) {
4927eb1a   曾柯   考评组设置加列表及草稿
31
32
    const { postList, readOnly } = useStore();
    const [roleList, setRoleList] = useState<any>([]);
a7b88b33   曾柯   考评组设置部分
33
  
a34f5d4b   曾柯   考评bugfix
34
    const { visible, onCancel, onOk, evaItem, scopeType, setScopeType } = props;
a7b88b33   曾柯   考评组设置部分
35
  
4d934cf7   曾柯   考评组配置0208
36
    const [form] = Form.useForm();
4d934cf7   曾柯   考评组配置0208
37
38
    // 选择岗位id
    const [postId, setPostId] = useState<number>();
d3a736bf   曾柯   管理人员改为一个
39
  
4d934cf7   曾柯   考评组配置0208
40
41
42
43
44
45
46
    // 门店列表
    const [shopList, setShopList] = useState<EvaGroupSetteing.ShopList[]>([]);
  
    // 人员查看模块
    const [personModal, setPersonModal] = useState<EvaGroupSetteing.Person>({
      visible: false,
      postId: undefined,
d3a736bf   曾柯   管理人员改为一个
47
      shopIds: "",
4d934cf7   曾柯   考评组配置0208
48
49
    });
  
dae0d4f2   曾柯   考评组设置1645
50
    // visible变化时(修改等)
a7b88b33   曾柯   考评组设置部分
51
    useEffect(() => {
4927eb1a   曾柯   考评组设置加列表及草稿
52
      getRoleList();
dae0d4f2   曾柯   考评组设置1645
53
      if (visible && evaItem.name) {
2683f431   曾柯   考评数据导入
54
55
56
57
58
59
60
        if (evaItem.shop) {
          const shopIds = evaItem.shop.map((item) => item.value);
          setPersonModal({
            shopIds: shopIds.join(","),
            visible: false,
          });
        }
d3a736bf   曾柯   管理人员改为一个
61
62
63
        if (evaItem.shop && evaItem.post) {
          const shopIds = evaItem.shop.map((item) => item.value);
          const postId = evaItem.post.value;
7cb12675   曾柯   考评0221
64
65
66
67
68
          setPersonModal({
            postId,
            shopIds: shopIds.join(","),
            visible: false,
          });
d3a736bf   曾柯   管理人员改为一个
69
70
        }
        console.log("evaItem", evaItem);
a7b88b33   曾柯   考评组设置部分
71
        form.setFieldsValue({
dae0d4f2   曾柯   考评组设置1645
72
          ...evaItem,
a7b88b33   曾柯   考评组设置部分
73
74
        });
      }
a7b88b33   曾柯   考评组设置部分
75
76
    }, [visible]);
  
4d934cf7   曾柯   考评组配置0208
77
78
    // 查询门店
    useEffect(() => {
c0188e80   曾柯   考评bugfix0306
79
80
      if (evaItem.post) {
        getDealerList(evaItem.post.value);
4d934cf7   曾柯   考评组配置0208
81
      }
c0188e80   曾柯   考评bugfix0306
82
    }, [evaItem]);
4d934cf7   曾柯   考评组配置0208
83
84
    console.log("shopList", shopList);
  
4927eb1a   曾柯   考评组设置加列表及草稿
85
86
87
    // 查询管理角色
    function getRoleList() {
      getManagerRoleListApi()
d3a736bf   曾柯   管理人员改为一个
88
89
90
91
92
93
        .then((res) => {
          setRoleList(res.data || []);
        })
        .catch((e) => {
          message.error(e.message);
        });
4927eb1a   曾柯   考评组设置加列表及草稿
94
95
    }
  
4d934cf7   曾柯   考评组配置0208
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    // 根据岗位查门店
    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) {
        message.error("请选择门店");
        return;
      }
      setPersonModal({ ...personModal, visible: true });
    };
  
a7b88b33   曾柯   考评组设置部分
120
    function handSubmit(fieldsValue: any) {
4d934cf7   曾柯   考评组配置0208
121
      const res = transformDTO(fieldsValue);
4d934cf7   曾柯   考评组配置0208
122
123
      let pa = { ...res, force: true };
      onOk(pa);
4927eb1a   曾柯   考评组设置加列表及草稿
124
      console.log("考评组", pa);
dae0d4f2   曾柯   考评组设置1645
125
      onCancel && onCancel();
a7b88b33   曾柯   考评组设置部分
126
127
    }
  
a7b88b33   曾柯   考评组设置部分
128
129
    return (
      <Modal
dae0d4f2   曾柯   考评组设置1645
130
        title={`${evaItem.name ? "编辑" : "新增"}考评组`}
a7b88b33   曾柯   考评组设置部分
131
132
133
134
135
136
137
138
        visible={visible}
        maskClosable={false}
        afterClose={() => {
          form.resetFields();
          onCancel();
        }}
        onCancel={() => onCancel()}
        onOk={form.submit}
4d934cf7   曾柯   考评组配置0208
139
        width={1400}
a7b88b33   曾柯   考评组设置部分
140
      >
27c7284a   曾柯   考评组配置
141
        <Form form={form} labelCol={{ span: 6 }} wrapperCol={{ span: 16 }} onFinish={handSubmit}>
dae0d4f2   曾柯   考评组设置1645
142
143
144
          <Form.Item name="name" label="考评组名称" rules={[{ required: true, message: "请输入名称" }]}>
            <Input placeholder="请输入考评组名称" disabled={readOnly} />
          </Form.Item>
5ac136b7   曾柯   考评组设置1620
145
          <Form.Item label="考评时间" name="time" rules={[{ required: true, message: "请选择考评时间" }]}>
4927eb1a   曾柯   考评组设置加列表及草稿
146
147
148
149
150
            <RangePicker
              style={{ width: 900 }}
              disabled={readOnly}
              disabledDate={(current) => current && current < moment().add(-1, "days").endOf("day")}
            />
5ac136b7   曾柯   考评组设置1620
151
          </Form.Item>
dae0d4f2   曾柯   考评组设置1645
152
          <Form.Item label="考评范围" name="scopeType" rules={[{ required: true, message: "请选择考评范围" }]}>
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
153
            <Radio.Group disabled={readOnly} onChange={(e) => setScopeType(e.target.value)}>
f3e17a99   曾柯   考评0221
154
155
              <Radio value={1}>人员考评</Radio>
              <Radio value={2}>门店考评</Radio>
dae0d4f2   曾柯   考评组设置1645
156
157
            </Radio.Group>
          </Form.Item>
4d934cf7   曾柯   考评组配置0208
158
159
160
161
          <Form.Item
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
          >
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
162
            {({ getFieldValue }) =>
f3e17a99   曾柯   考评0221
163
              getFieldValue("scopeType") === 1 ? (
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
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
                <Form.Item name="post" label="岗位" rules={[{ required: true, message: "请选择岗位" }]}>
                  <Select
                    labelInValue
                    placeholder="请选择岗位"
                    allowClear
                    disabled={readOnly}
                    showSearch
                    optionFilterProp="children"
                    onChange={(post: { label: string; value: number; key: number }) => {
                      setPersonModal({
                        postId: post.value,
                        visible: false,
                        shopIds: "",
                      });
                      setPostId(post.value);
                      form.setFieldsValue({ shop: [] });
                      // 根据岗位查门店
                      if (post) {
                        getDealerList(post.value);
                      }
                    }}
                  >
                    {postList.map((item) => (
                      <Option value={item.id}>{item.postName}</Option>
                    ))}
                  </Select>
                </Form.Item>
              ) : null
            }
4d934cf7   曾柯   考评组配置0208
193
194
195
196
197
198
199
200
201
202
203
204
205
          </Form.Item>
  
          <Form.Item
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
          >
            {({ getFieldValue }) => {
              const scopeType = getFieldValue("scopeType");
              return (
                <Form.Item name="shop" label="门店" rules={[{ required: true, message: "请选择门店" }]}>
                  <ShopSelectNew
                    multiple
                    disabled={readOnly}
f3e17a99   曾柯   考评0221
206
                    shopIds={scopeType === 1 ? shopList.map((item) => item.shopId) : []}
d3a736bf   曾柯   管理人员改为一个
207
                    type={scopeType === 1 ? 2 : 1}
4d934cf7   曾柯   考评组配置0208
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
                    onChange={(
                      shops: {
                        key: number;
                        label: string;
                        value: number;
                      }[]
                    ) => {
                      const shopIds = shops.map((item) => item.value).join(",");
                      setPersonModal({ ...personModal, shopIds });
                    }}
                  />
                </Form.Item>
              );
            }}
          </Form.Item>
          <Form.Item
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
          >
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
227
            {({ getFieldValue }) =>
f3e17a99   曾柯   考评0221
228
              getFieldValue("scopeType") === 1 ? (
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
229
230
231
232
233
                <div style={{ marginBottom: 20, marginLeft: 250 }}>
                  <a onClick={() => personView()}>{`人员查看 >`}</a>
                </div>
              ) : null
            }
4d934cf7   曾柯   考评组配置0208
234
          </Form.Item>
4927eb1a   曾柯   考评组设置加列表及草稿
235
236
237
238
239
          <Form.Item
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
          >
            {({ getFieldValue }) =>
f3e17a99   曾柯   考评0221
240
              getFieldValue("scopeType") === 2 ? (
ccdb0384   曾柯   考评组配置及数据导入
241
                <Form.Item name="role" label="门店奖惩分配" rules={[{ required: true, message: "请选择管理角色" }]}>
4927eb1a   曾柯   考评组设置加列表及草稿
242
243
244
245
246
247
248
                  <Select
                    labelInValue
                    placeholder="请选择管理角色"
                    allowClear
                    disabled={readOnly}
                    showSearch
                    optionFilterProp="children"
4927eb1a   曾柯   考评组设置加列表及草稿
249
250
251
252
253
254
255
256
257
                  >
                    {roleList.map((item) => (
                      <Option value={item.roleCode}>{item.roleName}</Option>
                    ))}
                  </Select>
                </Form.Item>
              ) : null
            }
          </Form.Item>
5ac136b7   曾柯   考评组设置1620
258
  
c0188e80   曾柯   考评bugfix0306
259
260
261
262
263
264
265
266
267
          <Form.Item noStyle shouldUpdate={(prevValues, currentValues) => prevValues.rewards !== currentValues.rewards}>
            {({ getFieldValue }) => {
              const rewards = getFieldValue("rewards");
              return (
                <Form.Item name="indicators" label="考评指标" rules={[{ required: !(rewards && rewards.length > 0) }]}>
                  <IndivatorsTable postId={postId} personModal={personModal} scopeType={scopeType} />
                </Form.Item>
              );
            }}
5ac136b7   曾柯   考评组设置1620
268
          </Form.Item>
c0188e80   曾柯   考评bugfix0306
269
270
271
272
273
274
275
276
277
278
279
280
          <Form.Item
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.indicators !== currentValues.indicators}
          >
            {({ getFieldValue }) => {
              const indicators = getFieldValue("indicators");
              return (
                <Form.Item name="rewards" label="考评奖惩" rules={[{ required: !(indicators && indicators.length > 0) }]}>
                  <RewardsTableSal postId={postId} personModal={personModal} scopeType={scopeType} />
                </Form.Item>
              );
            }}
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
281
          </Form.Item>
dae0d4f2   曾柯   考评组设置1645
282
        </Form>
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
283
  
4d934cf7   曾柯   考评组配置0208
284
        <PersonModal item={personModal} setPersonModal={setPersonModal} />
a7b88b33   曾柯   考评组设置部分
285
286
287
      </Modal>
    );
  }