AddFeeModal.jsx 7.92 KB
Newer Older
DarkForst's avatar
DarkForst committed
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
import React, { useState, useEffect } from 'react';
import { Modal, Form, Select, Input, Button, Row, Col } from 'antd'
import { UploadOutlined, CloseOutlined, LinkOutlined } from '@ant-design/icons'
import { history, connect } from 'umi'

import UploadFile from '@/components/UploadFile';
import style from "../index.less"
import { dispatchHandle } from '@/utils/publicHandle';
import { dicFindUtils, DictBizType } from '@/utils/utils'

const { Option } = Select;
const { TextArea } = Input;

const AddFeeModal = (props) => {
    const {
        dispatch,
        id,
        editId,
        feevisible,
        setFeeVisible,
        type,
        search,
        dict: {
            dicTotalsList
        },
    } = props;
    // 费用对话框事件方法
    const [form] = Form.useForm()
    // 上传文件
    const [imgList, setImgList] = useState([]);
    const [fileList, setfileList] = useState();
    // upload
    const changeUpload = (files, fileInfo) => {
        console.log(files, fileInfo);
        const value = String(files);
        const filesList = fileInfo.fileList;
        setImgList(filesList);
        setfileList(value)
    }
    const feeHandleOk = e => {
        // 点击弹框确定按钮
        e.preventDefault();
        form.validateFields()
            .then((values) => {
                const arr = imgList.length > 0 && imgList.map(item => ({
                    url: item.response.data.url || '',
                    enclosurName: item.name
                }))
                const payload = {
                    ...values,
                    taskId: id,
                    expensesEnclosurs: arr
                }
                delete payload.annex;
                if (editId) {
                    payload.id = editId;
                    dispatchHandle(
                        dispatch,
                        'maintaining/operation_service_m_curing_task_expensesAddEdit_patch',
                        payload,
                        () => {
                            search.refresh()
                        }
                    )
                } else {
                    dispatchHandle(
                        dispatch,
                        'maintaining/operation_service_m_curing_task_expensesAddEdit_patch',
                        payload,
                        () => {
                            search.refresh()
                        }
                    )
                }
                form.resetFields()
                setImgList([]);
                setFeeVisible(false)
            })
            .catch(() => {
                form.resetFields()
            });
    };
    const feeHandleCancel = () => {
        form.resetFields()
        setImgList([]);
        setFeeVisible(false)
    };
    useEffect(() => {
        if (feevisible && type === 'edit') {
            dispatchHandle(
                dispatch,
                'maintaining/operation_service_m_curing_task_costDetail_id_get',
                { id: editId },
                res => {
                    if (res) {
                        form.setFieldsValue({ ...res })
                        if (res.expenseso && res.expenseso.length > 0) {
                            const arr = res.expenseso.map(item => ({
                                name: item?.enclosurName,
                                response: {
                                    data: {
                                        url: item?.url
                                    }
                                }
                            }))
                            setImgList(arr)
                        }
                    }
                }
            )
        }
    }, [feevisible])
    const deleteImgAction = (name) => {
        const arr = imgList.filter(item => item.name !== name)
        setImgList(arr)
    }
    const checkAnnexAction = (url) => {
        dispatchHandle(
            dispatch,
            'universal/account_service_file_online_preview_url_post',
            { name: url },
            res => {
                if (res) {
                    window.open(res)
                }
            }
        )
    }
    const formItemLayout = {
        labelCol: {
            span: 6
        },
        wrapperCol: {
            span: 18
        }
    }
    const outFeeType = dicFindUtils(dicTotalsList, DictBizType.outFeeType)
    const unitMetering = dicFindUtils(dicTotalsList, DictBizType.unitMetering)
    return <Modal
        title="添加费用"
        visible={feevisible}
        onOk={feeHandleOk}
        onCancel={feeHandleCancel}
        className={style.add_fee}
        destroyOnClose={true}
        getContainer={false}
    >
        <Form form={form} {...formItemLayout} className={style.add_fee_modal}>
            <Form.Item label="费用类型" name="usageTypeId" rules={[{ required: true, message: "费用类型不能为空!" }]}>
                <Select placeholder="请选择" allowClear>
                    {
                        outFeeType && outFeeType.length > 0 && outFeeType.map(i => <Option value={i.id} key={i.id}>{i.dicValue}</Option>)
                    }
                </Select>
            </Form.Item>
            <Form.Item label="需求数量" name="demandQuantity" rules={[{ required: true, message: "需求数量不能为空!" }]}>
                <Input placeholder="请输入" allowClear />
            </Form.Item>
            <Form.Item label="单位" name="companyId" rules={[{ required: true, message: "单位不能为空!" }]}>
                <Select placeholder="请选择" allowClear>
                    {
                        unitMetering && unitMetering.length > 0 && unitMetering.map(i => <Option value={i.id} key={i.id}>{i.dicValue}</Option>)
                    }
                </Select>
            </Form.Item>
            <Form.Item label="单价" name="unitPrice" rules={[{ required: true, message: "单位不能为空!" }]}>
                <Input
                    placeholder="请输入"
                    className={style.unitPrice}
                    allowClear
                />
            </Form.Item>
            {/* <Form.Item label="使用人" name="user" rules={[{ required: true, message: "使用人不能为空!" }]}>
                <Input placeholder="请输入" allowClear />
            </Form.Item> */}
            <Form.Item label="费用说明" name="costDescription">
                <TextArea placeholder="请输入" rows={4} allowClear />
            </Form.Item>
            <Form.Item className={style.add_fee_annex} label="附件:" name="annex" style={{ marginBottom: 10 }}>
                <UploadFile
                    fileType="document"
                    onChange={changeUpload}
                    showUploadList={false}
                >
                    <Button><UploadOutlined />上传文档</Button>
                </UploadFile>
            </Form.Item>
            <Form.Item label=" " colon={false}>
                <ul style={{ display: 'flex', flexWrap: 'wrap' }}>
                    {
                        imgList && imgList.length > 0 && imgList.map(item => (
                            <li style={{ marginRight: 5, cursor: 'pointer', display: 'flex', alignItems: 'center' }}>
                                <span onClick={()=>checkAnnexAction(item?.response?.data?.url)} style={{ display: 'flex', alignItems: 'center', }}>
                                    <LinkOutlined />
                                    <span style={{ margin: '0 5px 0' }}>{item?.name}</span>
                                </span>
                                <CloseOutlined style={{ fontSize: '12px' }} onClick={() => deleteImgAction(item.name)} />
                            </li>
                        ))
                    }
                </ul>
                <i>支持扩展名:.rar .zip .doc .docx .pdf .png</i>
            </Form.Item>
        </Form>
    </Modal>
}

export default connect(({ maintaining, user, dict,universal , loading }) => ({
    user,universal,
    dict,
    maintaining,
}))(AddFeeModal)