AddSparePartModal.jsx 7.18 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 213 214 215 216 217 218 219 220 221 222
import React, { useState, useEffect } from "react"
import { Card, Form, Row, Col, Input, Tabs, Button, Table, Tag, Divider, Modal, Popconfirm, Tooltip, Select, TreeSelect } from "antd"
import { connect } from 'umi'

import { SearchOutlined } from "@ant-design/icons"
import { dispatchHandle } from "@/utils/publicHandle";
import useFormTable from '@/useHooks/useFormTable';
import { dicFindUtils, DictBizType } from '@/utils/utils'

import style from "../index.less"

const { TabPane } = Tabs;
const { TextArea, Search } = Input
const { Option } = Select

const AddSparePartModal = (props) => {
    const {
        dispatch,
        visible,
        loading,
        setVisible,
        id,
        searches,
        systemData,
        type,
        dict: {
            dicTotalsList
        },
        maintaining: {
            materialList,
            deviceSystemList,
            supplierList
        }
    } = props;
    const [form] = Form.useForm()
    const data = [{ name: "1" }, { name: "2" }]
    const getListItem = (payload = {}) => {
        payload.noCodeLab = false;
        dispatchHandle(
            dispatch,
            'maintaining/warehouse_service_account_post',
            payload
        )
    }
    const { tableProps, search } = useFormTable(getListItem, {
        form
    })
    // 新增备件列表
    const sparePartColumns = [
        {
            title: '物料编号',
            dataIndex: ['materialInfo', 'materialCode'],
            key: 'id',
        },
        {
            title: '品名',
            dataIndex: ['materialInfo', 'materialName'],
            key: 'name',
        },
        {
            title: '类型',
            dataIndex: ['materialInfo', 'materialType'],
            key: 'type',
        },
        {
            title: '品牌',
            dataIndex: ['materialSupplier', 'brand'],
            key: 'brand',
        },
        {
            title: '规格',
            dataIndex: ['materialInfo', 'mmodel'],
            key: 'specs',
        },
        {
            title: '单位',
            dataIndex: ['materialInfo', 'munit'],
            key: 'unit',
        },
        {
            title: '库存数量',
            dataIndex: 'stockNum',
            key: 'inventoryNum',
            render: text => <a style={{ color: '#138900' }}>{text}</a>
        },
        {
            title: '单价(元)',
            dataIndex: ['materialSupplier', 'materialPrice'],
            key: 'unitPrice',
            render: text => <a style={{ color: '#138900' }}>{text}</a>
        },
        {
            title: '供应商',
            dataIndex: ['materialSupplier', 'supplierName'],
            key: 'supplier',
        },
        // {
        //     title: '操作',
        //     key: 'action',
        //     fixed: 'right',
        //     align: 'center',
        //     dataIndex: 'action',
        //     render: (text, record) => <Popconfirm title='确定移除此项?' onConfirm={() => deleteConfirm(record)}>
        //         <a style={{ color: '#138900' }}>移除</a>
        //     </Popconfirm>

        // },

    ];
    const [selectedRowKeys, setSelectedRowKeys] = useState([])// 选中的行的key值
    const [selectedRow, setSelectedRow] = useState([])// 选中的行
    // 新增备件table所选项发生变化
    const newRowSelections = {
        selectedRowKeys,
        onChange: (selectedRowKeys, selectedRows) => {
            setSelectedRowKeys(selectedRowKeys);
            setSelectedRow(selectedRows)
        }
    }
    const [confirmLoading, setConfirmLoading] = useState(false)
    const sparePartHandleOk = () => {
        setConfirmLoading(true)
        const list = selectedRow.map(i => ({
            materielId: i?.materialInfoId,
            planNumber: id
        }))
        const payload = {
            list,
            planNumber: id
        }
        dispatchHandle(
            dispatch,
            'maintaining/operation_service_m_curing_plan_addMaterie_patch',
            payload,
            () => {
                setVisible(false)
                setConfirmLoading(false)
                searches.submit()
            }
        )
    };
    const sparePartHandleCancel = () => {
        setVisible(false)
        setConfirmLoading(false)
    };
    const formItemLayout = {
        wrapperCol: {
            span: 18
        },
        labelCol: {
            span: 6
        }
    }
    // 设备类型
    const deviceType = dicFindUtils(dicTotalsList, DictBizType.deviceType);
    const materialType = dicFindUtils(dicTotalsList, DictBizType.materielType); //物料类型
    return <Card className={style.spare_part_modal
    } >
        <Modal
            confirmLoading={confirmLoading}
            title="添加备件"
            visible={visible}
            onOk={sparePartHandleOk}
            onCancel={sparePartHandleCancel}
            width='80%'
            className={style.add_new_spare_part}
            getContainer={false}
        >
            <Form form={form} onValuesChange={search.submit} style={{ padding: '9px 0' }}>
                <Row>
                    <Col span={10}>
                        <Form.Item label="物料类型" name="materialType" {...formItemLayout}>
                            <Select placeholder="请选择" allowClear>
                                {materialType && materialType.map(item => {
                                    return <Option value={item.id} key={item.id}>
                                        {item.dicValue}
                                    </Option>
                                })}
                            </Select>
                        </Form.Item>

                    </Col>
                    <Col span={10}>
                        <Form.Item label="物料品名" name="search" {...formItemLayout}>
                            <Input placeholder="请输入" suffix={<SearchOutlined style={{ color: '#d1d1d1' }} />} />
                        </Form.Item>
                    </Col>
                </Row>
            </Form>
            <Divider style={{ margin: "0 0 10px" }} />
            <Table
                loading={loading}
                columns={sparePartColumns}
                dataSource={materialList.list}
                rowSelection={newRowSelections}
                scroll={{
                    x: 1300
                }}
                pagination={materialList.pagination}
                {...tableProps}
                footer={() => {
                    return (
                        <div
                            style={{ display: 'flex', justifyContent: 'flex-start', alignItems: 'center' }}
                        >
                            <span style={{ fontSize: 14 }}>
                                已选数量:<span style={{ margin: '0 10px', color: '#5ca6f3' }}>{selectedRowKeys.length}</span>
                            </span>
                        </div>
                    );
                }}
            />
            {/* <p className={style.selected_num}><span>已选数量:</span><i>{selectedRowKeys.length}</i></p> */}
        </Modal>
    </Card >
}

export default connect(({ maintaining, dict, loading }) => ({
    dict,
    maintaining,
    loading: loading.effects['maintaining/warehouse_service_account_post']
}))(AddSparePartModal)