index.tsx
7.99 KB
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
import usePagination from '@/hooks/usePagination';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, message, Table, Select, Popconfirm, Button, Input } from 'antd';
import { getPageListApi, cancelApi, statusType } from './api';
import { getBrandFilterApi } from '@/common/api';
import UploadImg from './SubPages/UploadImg';
import useInitial from '@/hooks/useInitail';
import React, { useEffect, useState } from 'react';
import st from './style.less';
import moment from 'moment';
import { history } from "umi";
import OptionalDetails from '@/pages/stock/Components/OptionalDetails';
interface Optionals {
visible: boolean,
listItem?: SpecialOfferCar.OptionalVo[],
}
const Column = Table.Column;
const Option = Select.Option;
export default function Index() {
const [delay, setDelay] = useState(true);
const { list, paginationConfig, loading, setParams, setLoading, innerParams } = usePagination<SpecialOfferCar.Item>(getPageListApi, {}, { delay });
// 品牌
const { data: brandList = [] } = useInitial<CommonApi.OptionVO[], {}>(getBrandFilterApi, [], {});
const [timer, setTimer] = useState<any>();
const [visible, setVisible] = useState(false);
const [currentItem, setCurrentItem] = useState<SpecialOfferCar.Item>();
const [Optionals, setOptionals] = useState<Optionals>({ visible: false });
/**
* 条件查询
*/
function filter(param: SampleCar.QueryParams = {}) {
timer && clearTimeout(timer);
setTimer(setTimeout(() => {
setParams({ ...innerParams, ...param }, true);
}, 500));
}
/**
* 下架
*/
function _delete(params: SpecialOfferCar.Item) {
cancelApi(params).then(() => {
message.success('操作成功');
setParams({ ...innerParams, current: 1 }, true);
}).catch(e => {
message.error(e.message);
});
}
useEffect(() => {
if (brandList.length > 0) {
setDelay(false);
setParams({ brandId: brandList[0].id }, true);
}
}, [brandList]);
function expendRow(record: SpecialOfferCar.Item) {
return (
<div style={{ display: 'flex', alignItems: 'start', flexDirection: 'column', marginLeft: 50 }}>
{record.addTime && <p style={{ margin: 0 }}>新增申请时间:{moment(record.addTime).format('YYYY-MM-DD')}</p>}
{record.cancelTime && <p style={{ margin: 0 }}>取消申请时间:{moment(record.cancelTime).format('YYYY-MM-DD')}</p>}
{record.approveTime && <p style={{ margin: 0 }}>审批时间:{moment(record.approveTime).format('YYYY-MM-DD')}</p>}
</div>
);
}
return (
<PageHeaderWrapper title="特价车管理">
<Card className={st.page}>
<div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', marginBottom: 20 }}>
<div>
<Select
allowClear
value={innerParams.brandId}
placeholder="请选择品牌"
notFoundContent="暂无数据"
style={{ minWidth: 200, maxWidth: 300 }}
onChange={(v) => filter({ brandId: v && Number(v) || undefined, current: 1 })}
>
{
brandList.map((item) => {
return <Option value={item.id || -1} key={item.id}>{item.name}</Option>;
})
}
</Select>
<Input.Search
allowClear
style={{ width: 200, marginLeft: 20 }}
placeholder="请输入VIN"
onChange={(v) => filter({ vin: v && v.target.value || undefined, current: 1 })}
onSearch={(v) => v && filter({ vin: v })}
/>
<Input.Search
allowClear
style={{ width: 200, marginLeft: 20 }}
placeholder="请输入物料代码"
onSearch={(v) => v && filter({ materialCode: v })}
onChange={(v) => filter({ materialCode: v && v.target.value || undefined, current: 1 })}
/>
<Select
allowClear
placeholder="请选择状态"
style={{ width: 200, marginLeft: 20 }}
onChange={(v) => filter({ status: v, current: 1 })}
>
{
statusType.map((item: { value: number, label: string }) => {
return <Option value={item.value} key={item.value}>{item.label}</Option>;
})
}
</Select>
</div>
<Button type="primary" onClick={() => history.push(`/fvm/specialCar/save`)}>新增上架</Button>
</div>
<Table
size="small"
loading={loading}
pagination={paginationConfig}
rowKey={(item) => String(item.id)}
dataSource={list}
expandable={{
expandedRowRender: record => expendRow(record),
rowExpandable: record => !!record.addTime,
}}
className={st.table}
>
<Column title="品牌" dataIndex="brandName" />
<Column title="车系" dataIndex="seriesName" />
<Column title="车型" dataIndex="specName" />
<Column title="物料代码" dataIndex="materialCode" />
<Column title="VIN" dataIndex="vin" />
<Column title="库房" dataIndex="storageName" />
<Column title="启票价" dataIndex="invoicePrice" />
<Column title="商家加装价" dataIndex="dealerOptionalPrice" />
<Column title="商家零售价(含加装项目)" dataIndex="dealerRetailPrice" />
<Column title="特价(含加装项目)" dataIndex="price" />
<Column
title="加装项目"
dataIndex="optionalItemList"
render={(t, record: SpecialOfferCar.Item) => (t && record.optionalTag ? (<Button type="link" onClick={() => setOptionals({ visible: true, listItem: t })}>查看</Button>) : "--")}
/>
<Column
title="有效时间"
width="10%"
render={(text, record: SpecialOfferCar.Item) => (
<div>
<p style={{ margin: 0 }}>{record.startTime && moment(record.startTime).format('YYYY-MM-DD HH:mm:ss')}</p>
<p style={{ margin: 0 }}>{record.endTime && moment(record.endTime).format('YYYY-MM-DD HH:mm:ss') || '——'}</p>
</div>
)}
/>
<Column
title="状态"
dataIndex="status"
width="8%"
render={(text) => {
switch (text) {
case 0: return '已下架';
case 1: return '上架审核中';
case 2: return '已上架';
case 3: return '下架审核中';
default: return '-';
}
}}
/>
<Column
title="操作"
width="10%"
render={(text, record: SpecialOfferCar.Item) => {
return (
<>
<div>
{record.status == 2 ? (
<Popconfirm
title="确认下架此特价车?"
onConfirm={() => _delete(record)}
okText="确认"
cancelText="取消"
>
<a onClick={(e) => { e.preventDefault(); }} style={{ color: 'red' }}>下架</a>
</Popconfirm>
) : null}
</div>
<div>
<Button type="link" style={{ padding: 0 }} onClick={() => { setVisible(true); setCurrentItem(record); }}>{record.image || record.video ? "查看图文视频" : "上传图文视频"}</Button>
</div>
</>
);
}}
/>
</Table>
</Card>
<UploadImg
visible={visible}
setLoading={() => setLoading(true)}
onCancel={() => setVisible(false)}
currentItem={currentItem}
/>
<OptionalDetails
{...Optionals}
onCancel={() => setOptionals({ visible: false, listItem: undefined })}
/>
</PageHeaderWrapper>
);
}