index.jsx 11.4 KB
Newer Older
左玲玲's avatar
左玲玲 committed
1 2 3 4 5
import React, { useState, useMemo, useRef, useEffect } from 'react';
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
6
import { doFetch, exportFetch } from '@/utils/doFetch';
左玲玲's avatar
左玲玲 committed
7 8 9 10
import { useRequest } from "ahooks";
import { Divider, Tabs, ProDescriptions, message } from "antd";
import dayjs from 'dayjs';
import Leaseterminformation from "./Leaseterminformation";
11
import { useLocation } from '@umijs/max';
左玲玲's avatar
左玲玲 committed
12
const Costanalysis = () => {
13
    const { pathname, state } = useLocation();
左玲玲's avatar
左玲玲 committed
14 15 16 17 18
    let actionRef = useRef(), formRef = useRef(), boxRef = useRef();
    const [drawer, setdrawer] = useState({
        open: false,
    }),
        [extraparams, setextraparams] = useState({}),
19 20
        [activeKey, catk] = useState('item-1'),
        [searchParams, csearch] = useState({});
左玲玲's avatar
左玲玲 committed
21 22 23 24 25 26 27 28 29 30 31 32 33
    const { run, loading, runAsync } = useRequest(doFetch, {
        manual: true,
        onSuccess: (res, params) => {
            if (res?.code == "0000") {
                actionRef?.current?.reload();
                setdrawer((s) => ({
                    ...s,
                    open: false,
                }));
            }
        },
    });
    const columns = useMemo(() => {
34
        csearch({});
左玲玲's avatar
左玲玲 committed
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
        let defcolumn = getcolumns(setdrawer, activeKey)?.filter(it => it.key == activeKey)?.[0]?.columns ?? [];
        return defcolumn.concat({
            title: '操作',
            valueType: 'option',
            width: activeKey == 'item-1' ? 260 : 100,
            render: (text, row, _, action) => rightExtra(text, row, _, action),
        });
    }, [activeKey]);
    const rightExtra = (text, row, _, action) => {
        return [
            activeKey == 'item-1' && <PremButton
                key='confirm'
                btn={{
                    size: 'small',
                    onClick: async () => {
                        let res = await doFetch({ url: '/lease/umContractEquipment/queryBeforeCollection', params: { id: row.id } });
                        if (res?.data?.data?.waitNum == 0) {
                            message.warning('该设备需回款的租期已全部回款,无需再次回款!')
                        } else {
                            setdrawer((s) => ({
                                ...s,
                                open: true,
                                item: { ...row, waitNum: res?.data?.data?.waitNum, isColl: res?.data?.data?.isColl },
                                val: 'confirm',
                                title: '回款确认',
                                fields: [
                                    {
                                        title: '本期是否回款',
                                        dataIndex: 'isColl',
                                        key: 'isColl',
                                        fieldProps: {
                                            disabled: true
                                        },
                                        colProps: { span: 8 },
                                    },
                                    {
                                        title: '剩余回款期数',
                                        dataIndex: 'waitNum',
                                        key: 'waitNum',
                                        fieldProps: {
                                            disabled: true
                                        },
77
                                        valueType: 'digit',
左玲玲's avatar
左玲玲 committed
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
                                        colProps: { span: 8 },
                                    },
                                    {
                                        title: '本次回款期数',
                                        dataIndex: 'collNum',
                                        key: 'collNum',
                                        valueType: 'digit',
                                        colProps: { span: 8 },
                                        precision: 0,
                                        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] }
                                    },
                                    {
                                        title: '回款形式',
                                        dataIndex: 'collType',
                                        key: 'collType',
                                        valueType: 'select',
                                        options: [
                                            { label: '现金', value: 1 },
                                            { label: '银行承兑', value: 2 },
                                        ],
                                        colProps: { span: 8 },
                                        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
                                    },
                                ]
                            }));
                        }
                    },
                }}
            >
                回款确认
            </PremButton>,
            activeKey == 'item-1' && <PremButton
                key='reduction'
                btn={{
                    size: 'small',
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
                    onClick: () => {
                        setdrawer((s) => ({
                            ...s,
                            open: true,
                            item: { ...row, reducePrice: null },
                            val: 'reduction',
                            title: '租金减免',
                            fields: [
                                {
                                    title: '当前减免金额(元)',
                                    dataIndex: 'reducePrice',
                                    key: 'reducePrice',
                                    valueType: 'digit',
                                    colProps: { span: 8 },
                                    precision: 0,
                                    formItemProps: { rules: [{ required: true, message: '此项为必填项' }] }
                                },
                                {
                                    title: '减免情况说明',
                                    dataIndex: 'reduceRemark',
                                    key: 'reduceRemark',
                                    valueType: 'textarea',
                                    colProps: { span: 24 },
                                },
                                {
                                    title: '附件上传',
                                    dataIndex: 'reduceFileList',
                                    key: 'reduceFileList',
                                    valueType: 'uploadBtn',
                                    fieldProps: {
                                        limit: 1,
                                    },
                                    colProps: { span: 24 }
                                }
                            ]
                        }));
左玲玲's avatar
左玲玲 committed
149 150 151 152 153 154 155 156 157 158
                    },
                }}
            >
                租金减免
            </PremButton>,
            <PremButton
                key='invoicing'
                btn={{
                    size: 'small',
                    onClick: async () => {
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
                        let res = await doFetch({ url: '/lease/umContractEquipment/queryBeforeInvoicing', params: { id: row.id } });
                        if (res?.data?.data?.openNum == 0) {
                            message.warning('该设备已无需要开票的租期,无需开票记录!')
                        } else {
                            setdrawer((s) => ({
                                ...s,
                                open: true,
                                item: { ...row, openNum: null },
                                val: 'invoicing',
                                title: '开票记录',
                                fields: [
                                    {
                                        title: '开票期数',
                                        dataIndex: 'openNum',
                                        key: 'openNum',
                                        valueType: 'digit',
                                        colProps: { span: 8 },
                                        precision: 0,
                                        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] }
                                    }
                                ]
                            }));
                        }
左玲玲's avatar
左玲玲 committed
182 183 184 185 186 187 188
                    },
                }}
            >
                开票记录
            </PremButton>
        ]
    };
189 190 191 192 193 194
    useEffect(() => {
        if (state) {
            catk(state.pageStatus == 1 ? 'item-1' : 'item-2');
            setextraparams(state.extraparams);
        }
    }, [state])
左玲玲's avatar
左玲玲 committed
195 196 197 198 199 200 201 202 203 204 205 206 207

    return <div ref={boxRef}>
        <AutoTable
            pagetitle={<h3 className="page-title">费用分析</h3>}
            columns={columns}
            path={activeKey == 'item-1' ? '/lease/umContractEquipment/queryNoAnalysis' : '/lease/umContractEquipment/queryYesAnalysis'}
            actionRef={actionRef}
            resizeable={false}
            bordered={false}
            x={2500}
            extraparams={extraparams}
            onTabChange={(key) => {
                catk(key);
208
                setextraparams({})
左玲玲's avatar
左玲玲 committed
209 210 211
            }}
            activeTabKey={activeKey}
            tabList={getcolumns()}
212 213 214 215 216 217 218 219 220 221 222 223 224 225
            pageextra={'export'}
            formRef={formRef}
            dataSourceFieldsChange={(vals) => {
                csearch(vals)
            }}
            exportconfig={{
                btn: {
                    type: 'primary',
                    onClick: async () => {
                        message.warning('导出中,请稍后');
                        await exportFetch({ url: activeKey == 'item-1' ? '/lease/umContractEquipment/exportExcelNoAnalysis' : '/lease/umContractEquipment/exportExcelYesAnalysis', params: { ...extraparams, ...searchParams } });
                    }
                }
            }}
左玲玲's avatar
左玲玲 committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
        />


        <DrawerPro
            {...drawer}
            fields={drawer.fields}
            params={{ id: drawer?.item?.id }}
            defaultFormValue={drawer?.item ?? {}}
            placement="right"
            onClose={() => {
                setdrawer((s) => ({
                    ...s,
                    open: false,
                }));
            }}
241 242 243 244 245 246 247 248 249 250 251 252 253
            onValuesChange={(changedValues, allValues) => {

            }}
            onFinish={async (vals) => {
                let newVals = JSON.parse(JSON.stringify(vals));
                if (drawer?.val == 'confirm') {
                    await runAsync({ url: '/lease/umContractEquipment/collection', params: { collNum: newVals.collNum, collType: newVals.collType, id: drawer?.item?.id } });
                } else if (drawer?.val == 'reduction') {
                    await runAsync({ url: '/lease/umContractEquipment/exemption', params: { ...newVals, id: drawer?.item?.id } });
                } else if (drawer?.val == 'invoicing') {
                    await runAsync({ url: '/lease/umContractEquipment/invoicing', params: { ...newVals, id: drawer?.item?.id } });
                }
            }}
左玲玲's avatar
左玲玲 committed
254 255 256 257 258 259
        >
            <Leaseterminformation drawer={drawer} boxRef={boxRef} />
        </DrawerPro>
    </div>
}
export default Costanalysis;