oak-pay-business/es/components/sysAccountOper/list/index.js

128 lines
3.6 KiB
JavaScript

import dayjs from 'dayjs';
import { ToYuan, ThousandCont } from "oak-domain/lib/utils/money";
export default OakComponent({
entity: 'sysAccountOper',
isList: true,
projection: {
id: 1,
delta: 1,
type: 1,
entity: 1,
entityId: 1,
$$createAt$$: 1,
},
filters: [
{
filter() {
const { entity, entityId } = this.props;
return {
entity,
entityId,
};
}
}
],
formData({ data }) {
return {
sysAccountOpers: data.map((oper) => {
const { $$createAt$$, type, delta } = oper;
const num = Math.abs(delta);
const plus = ThousandCont(ToYuan(num), 2);
const sign = delta > 0 ? '+' : '-';
const time = dayjs($$createAt$$).format('YYYY-MM-DD HH:mm');
const symbol = this.t(`sysAccountOper:v.type.${type}`)[0];
const bgColor = this.features.style.getColor('sysAccountOper', 'type', type);
return {
value: `${sign}${plus}`,
time,
type: this.t(`sysAccountOper:v.type.${type}`),
symbol,
bgColor,
};
}),
};
},
pagination: {
pageSize: 7,
currentPage: 1,
},
getTotal: 100,
properties: {
entity: '',
entityId: '',
},
data: {
month: new Date(),
monthStr: '',
type: 'all',
typesOptions: []
},
lifetimes: {
ready() {
let typesOptions = [{
label: this.t('all'),
value: 'all',
}];
const types = ['withdrawTransfer', 'pay', 'refund', 'compensate', 'moveIn', 'moveOut'];
types.forEach((ele) => {
typesOptions.push({
label: this.t(`sysAccountOper:v.type.${ele}`),
value: ele,
});
});
this.setState({
typesOptions,
});
this.setTypeFilter();
}
},
methods: {
setType(type) {
this.setState({
type,
}, () => this.setTypeFilter());
},
setTypeFilter() {
const { type } = this.state;
if (type === 'all') {
this.removeNamedFilterByName('type', true);
}
else {
this.addNamedFilter({
'#name': 'type',
filter: {
type,
}
}, true);
}
},
setMonth(month) {
if (month) {
const m = dayjs(month);
const begin = m.startOf('month').valueOf();
const end = m.endOf('month').valueOf();
this.setState({
monthStr: m.format('YYYY-MM'),
month,
}, () => this.addNamedFilter({
'#name': 'month',
filter: {
$$createAt$$: {
$between: [begin, end],
}
}
}, true));
}
else {
this.setState({
monthStr: '',
month: undefined,
}, () => this.removeNamedFilter({
'#name': 'month',
filter: {}
}, true));
}
},
}
});