
import React from 'react';
import { Form, Input, Button, DatePicker, Drawer, message } from 'kts-xui';
import moment from 'moment';
import agent from '../../Server';
const { RangePicker } = DatePicker;
const GoodsPanel = (props: any) => {
    const [form] = Form.useForm();
    const type = props.type;
    const onFinish = async (values: any) => {
        values = {
            ...props.data,
            productName: values['productName'],
            specification: values['specification'],
            authStartTime: values['validdate'][0].format('YYYY-MM-DD'),
            authEndTime: values['validdate'][1].format('YYYY-MM-DD'),
            type
        }
        const res: any = await agent.post('/verifierparty/config/default/scope/batch/update', [values], this);
        if (res.err) {
            return false;
        }
        if (res.res) {
            if (res.res.failList.length > 0) {
                message.warn('操作失败');
            } else {
                message.success('操作成功');
                props.onSuccess && props.onSuccess();
            }

        }
    };
    const submit = () => {
        form.submit();
    }
    const initValues = {
        ...props.data,
        validdate: [moment(props.data.authStartTime), moment(props.data.authEndTime)]
    }
    return (
        <div>
            <Drawer
                title='修改商品'
                visible={true}
                onClose={props.onClose}
                footer={[<Button key='0' type="primary" style={{ marginRight: 10 }} onClick={submit}>修改</Button>, <Button key='1' onClick={props.onClose}>取消</Button>]}
            >
                <Form form={form} layout='vertical' onFinish={onFinish} autoComplete="off" initialValues={initValues}>

                    <Form.Item
                        label='商品名称'
                        name={'productName'}
                        fieldKey={'productName'}
                        rules={[{ required: true, message: '请输入必填项' }]}
                    >
                        <Input maxLength={80}/>
                    </Form.Item>
                    <Form.Item
                        label='规格型号'
                        name={'specification'}
                        fieldKey={'specification'}
                        rules={[{ required: true, message: '请输入必填项' }]}
                    >
                        <Input maxLength={20}/>
                    </Form.Item>
                    <Form.Item
                        label='授权有效时间'
                        name={'validdate'}
                        fieldKey={'validdate'}
                        rules={[{ required: true, message: '请输入必填项' }]}
                    >
                        <RangePicker format="YYYY-MM-DD " style={{ width: '100%' }} />
                    </Form.Item>
                </Form >
            </Drawer>
        </div >
    );
};
export default GoodsPanel