Blame view

src/pages/order3/RetailTaskConfiguration/components/EditMidal.tsx 2.92 KB
3b916ae7   舒述军   线索到店零售台数占比
1
2
3
4
5
6
7
  import React, { useState, useEffect } from 'react';
  import { Button, Form, message, InputNumber, Select, Modal} from 'antd';
  import ShopSelectNew from '@/components/ShopSelectNew';
  import { debounce } from 'lodash';
  import currency from 'currency.js';
  import useInitail from '@/hooks/useInitail';
  import { useStore } from '../index';
6e1e695a   舒述军   线索到店零售占比配置
8
  import { saveRetailConfigApi } from '../api';
3b916ae7   舒述军   线索到店零售台数占比
9
10
11
12
13
  
  const Option = Select.Option;
  
  export default function Index() {
    const [form] = Form.useForm();
6e1e695a   舒述军   线索到店零售占比配置
14
    const { visible, setVisible, current, setCurrent, setLoading } = useStore();
3b916ae7   舒述军   线索到店零售台数占比
15
16
17
    const [confirm, setConfirm] = useState<boolean>(false);
  
    useEffect(() => {
6e1e695a   舒述军   线索到店零售占比配置
18
      if (visible && current.id) {
3b916ae7   舒述军   线索到店零售台数占比
19
20
21
22
23
24
        handleSetValue();
      }
    }, [visible]);
  
    function handleCancle() {
      setVisible(false);
6e1e695a   舒述军   线索到店零售占比配置
25
      setCurrent({});
3b916ae7   舒述军   线索到店零售台数占比
26
27
28
29
30
    }
  
    async function handleSubmit() {
      const params = await form.validateFields();
      setConfirm(true);
6e1e695a   舒述军   线索到店零售占比配置
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
      const _params = {
        id: current.id,
        retailRate: params.retailRate,
        shopList: params.shopList?.map((v: any) => ({shopId: v.value, shopName: v.label}))
      };
      saveRetailConfigApi(_params)
      .then(res => {
        message.success(res.result);
        setVisible(false);
        setConfirm(false);
        setLoading(true);
        setCurrent({});
      })
      .catch(e => {
        message.error(e.message);
        setConfirm(false);
      });
3b916ae7   舒述军   线索到店零售台数占比
48
49
50
    }
  
    function handleSetValue() {
6e1e695a   舒述军   线索到店零售占比配置
51
52
53
54
      form.setFieldsValue({
        retailRate: current.retailRate,
        shopList: current.shopList?.map(v => ({label: v.shopName, value: v.shopId}))
      });
3b916ae7   舒述军   线索到店零售台数占比
55
56
57
    }
    return (
      <Modal
6e1e695a   舒述军   线索到店零售占比配置
58
        title={current.id ? "编辑" : "新增"}
3b916ae7   舒述军   线索到店零售台数占比
59
60
61
62
        destroyOnClose
        visible={visible}
        maskClosable={false}
        onCancel={handleCancle}
6e1e695a   舒述军   线索到店零售占比配置
63
64
        afterClose={() => form.setFieldsValue({shopList: [], retailRate: undefined})}
        style={{minWidth: "500px"}}
3b916ae7   舒述军   线索到店零售台数占比
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        footer={[
          <Button key="cancel" onClick={handleCancle} style={{marginLeft: 10}}>取消</Button>,
          <Button key="submit" onClick={handleSubmit} type="primary" htmlType="submit" loading={confirm}>确认</Button>
          ]}
      >
        <Form
          form={form}
          labelCol={{ span: 10 }}
          wrapperCol={{ span: 10 }}
        >
          <Form.Item
            label="适用门店"
            name="shopList"
            rules={[{ required: true, message: "请选择门店" }]}
            labelAlign="right"
          >
2d631337   舒述军   线索到店零售占比配置门店选择业态固定
81
            <ShopSelectNew defaultOptions={{bizTypes: "1"}} placeholder="请选择门店" multiple />
3b916ae7   舒述军   线索到店零售台数占比
82
          </Form.Item>
6e1e695a   舒述军   线索到店零售占比配置
83
  
3b916ae7   舒述军   线索到店零售台数占比
84
85
          <Form.Item
            label="线索到店零售台数占比"
6e1e695a   舒述军   线索到店零售占比配置
86
            name="retailRate"
f460ca23   舒述军   修改提示
87
            rules={[{ required: true, message: "请输入" }]}
3b916ae7   舒述军   线索到店零售台数占比
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
          >
            <InputNumber
              style={{width: '100%'}}
              controls={false}
              min={0}
              max={100}
              formatter={value => `${value}%`}
              precision={2}
              parser={value => value?.replace('%', '')}
            />
          </Form.Item>
          
        </Form>
  
      </Modal>
    );
  }