fix🛠️: data transfer
This commit is contained in:
parent
b2ce1fe392
commit
53ac383f5b
|
@ -1,8 +1,8 @@
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
export enum BillType {
|
export enum BillType {
|
||||||
consume = 0,
|
CONSUME = 0,
|
||||||
income,
|
INCOME,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBill {
|
export interface IBill {
|
||||||
|
@ -21,7 +21,7 @@ export function EmptyBill(): IBill {
|
||||||
return {
|
return {
|
||||||
date: dayjs().format("YYYY-MM-DD"),
|
date: dayjs().format("YYYY-MM-DD"),
|
||||||
money: 0,
|
money: 0,
|
||||||
type: BillType.consume,
|
type: BillType.CONSUME,
|
||||||
cls: "",
|
cls: "",
|
||||||
label: "",
|
label: "",
|
||||||
options: "",
|
options: "",
|
||||||
|
|
|
@ -53,10 +53,10 @@ const Home = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const typeOpt = [
|
const typeOpt = [
|
||||||
{ label: '支出', value: BillType.consume },
|
{ label: '支出', value: BillType.CONSUME },
|
||||||
{ label: '收入', value: BillType.income },
|
{ label: '收入', value: BillType.INCOME },
|
||||||
];
|
];
|
||||||
const [billType, setBillType] = useState(BillType.consume)
|
const [billType, setBillType] = useState(BillType.CONSUME)
|
||||||
|
|
||||||
// 点击bar弹出当天pie
|
// 点击bar弹出当天pie
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
|
|
@ -50,7 +50,7 @@ function Record() {
|
||||||
title: "金额",
|
title: "金额",
|
||||||
key: "money",
|
key: "money",
|
||||||
render: (_: any, record: IBill) => {
|
render: (_: any, record: IBill) => {
|
||||||
const isConsume = record.type === BillType.consume
|
const isConsume = record.type === BillType.CONSUME
|
||||||
const color = isConsume ? "red" : "green"
|
const color = isConsume ? "red" : "green"
|
||||||
const flag = isConsume ? "-" : "+"
|
const flag = isConsume ? "-" : "+"
|
||||||
return <Tag color={color}>{flag}{record.money}</Tag>
|
return <Tag color={color}>{flag}{record.money}</Tag>
|
||||||
|
@ -79,8 +79,8 @@ function Record() {
|
||||||
const [datasource, setDataSource] = useState<IBill[]>([])
|
const [datasource, setDataSource] = useState<IBill[]>([])
|
||||||
|
|
||||||
const typeOpt = [
|
const typeOpt = [
|
||||||
{label: '支出', value: BillType.consume},
|
{label: '支出', value: BillType.CONSUME},
|
||||||
{label: '收入', value: BillType.income},
|
{label: '收入', value: BillType.INCOME},
|
||||||
];
|
];
|
||||||
|
|
||||||
// 提交到表格
|
// 提交到表格
|
||||||
|
@ -93,7 +93,7 @@ function Record() {
|
||||||
bill.money = Number(money)
|
bill.money = Number(money)
|
||||||
bill.options = options
|
bill.options = options
|
||||||
const checkBill = () => {
|
const checkBill = () => {
|
||||||
return bill.cls !== '' && (billType === BillType.income || bill.label !== '') && bill.money > 0
|
return bill.cls !== '' && (billType === BillType.INCOME || bill.label !== '') && bill.money > 0
|
||||||
}
|
}
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
setCls("")
|
setCls("")
|
||||||
|
@ -132,10 +132,10 @@ function Record() {
|
||||||
|
|
||||||
let classData: string[] = []
|
let classData: string[] = []
|
||||||
switch (billType) {
|
switch (billType) {
|
||||||
case BillType.consume:
|
case BillType.CONSUME:
|
||||||
classData = Object.keys(cls2label.consume)
|
classData = Object.keys(cls2label.consume)
|
||||||
break
|
break
|
||||||
case BillType.income:
|
case BillType.INCOME:
|
||||||
classData = cls2label.income
|
classData = cls2label.income
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -170,14 +170,14 @@ function Record() {
|
||||||
value={cls === "" ? null : cls}
|
value={cls === "" ? null : cls}
|
||||||
onChange={c => {
|
onChange={c => {
|
||||||
setCls(c)
|
setCls(c)
|
||||||
if (billType === BillType.consume) setLabel(cls2label.consume[c][0])
|
if (billType === BillType.CONSUME) setLabel(cls2label.consume[c][0])
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
classData.map(c => <Select.Option key={c} value={c}>{c}</Select.Option>)
|
classData.map(c => <Select.Option key={c} value={c}>{c}</Select.Option>)
|
||||||
}
|
}
|
||||||
</Select>
|
</Select>
|
||||||
{billType === BillType.consume && (
|
{billType === BillType.CONSUME && (
|
||||||
<Select
|
<Select
|
||||||
style={{width: 120}}
|
style={{width: 120}}
|
||||||
// showSearch
|
// showSearch
|
||||||
|
|
|
@ -73,7 +73,7 @@ export class Bill {
|
||||||
(s: number) => s.toFixed(2),
|
(s: number) => s.toFixed(2),
|
||||||
R.sum,
|
R.sum,
|
||||||
R.map((bill: IBill) => bill.money),
|
R.map((bill: IBill) => bill.money),
|
||||||
R.filter((bill: IBill) => bill.type === BillType.consume),
|
R.filter((bill: IBill) => bill.type === BillType.CONSUME),
|
||||||
)
|
)
|
||||||
return functions(this._bills)
|
return functions(this._bills)
|
||||||
}
|
}
|
||||||
|
@ -84,16 +84,16 @@ export class Bill {
|
||||||
(s: number) => s.toFixed(2),
|
(s: number) => s.toFixed(2),
|
||||||
R.sum,
|
R.sum,
|
||||||
R.map((bill: IBill) => bill.money),
|
R.map((bill: IBill) => bill.money),
|
||||||
R.filter((bill: IBill) => bill.type === BillType.income),
|
R.filter((bill: IBill) => bill.type === BillType.INCOME),
|
||||||
)
|
)
|
||||||
return functions(this._bills)
|
return functions(this._bills)
|
||||||
}
|
}
|
||||||
|
|
||||||
getTotalMoney(type?: BillType) {
|
getTotalMoney(type?: BillType) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BillType.income:
|
case BillType.INCOME:
|
||||||
return this.incomeMoney
|
return this.incomeMoney
|
||||||
case BillType.consume:
|
case BillType.CONSUME:
|
||||||
return this.consumeMoney
|
return this.consumeMoney
|
||||||
default:
|
default:
|
||||||
return this.totalMoney
|
return this.totalMoney
|
||||||
|
@ -121,7 +121,7 @@ export class Bill {
|
||||||
this._bills = data.map((data: any) => {
|
this._bills = data.map((data: any) => {
|
||||||
return {
|
return {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
type: data.type.toLowerCase() === 'income' ? BillType.income : BillType.consume,
|
type: data.type.toUpperCase === 'INCOME' ? BillType.INCOME : BillType.CONSUME,
|
||||||
date: data.date,
|
date: data.date,
|
||||||
money: data.money,
|
money: data.money,
|
||||||
cls: data.cls,
|
cls: data.cls,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user