Merge remote-tracking branch 'origin/main' into main

# Conflicts:
#	src/pages/configuration/Configuration.tsx
main
wuyize 2023-01-05 22:40:12 +08:00
commit 2fbdc8cadd
3 changed files with 281 additions and 18 deletions

View File

@ -1,12 +1,214 @@
import React from "react"; import React from "react";
import {
ActionType,
EditableProTable,
ProColumns,
} from "@ant-design/pro-components";
import axiosInstance from "../../../utils/axiosInstance";
type DataSourceType = {
id: React.Key;
placeName: string;
subsidyPerDay: number;
baseExisted: boolean;
};
class CityConfig extends React.Component<any, any> { class CityConfig extends React.Component<any, any> {
actionRef = React.createRef<ActionType>();
constructor(props: any) {
super(props);
this.state = {
activated: props.activate,
tableData: [],
editableKeys: [],
}
}
saveRow = (row: DataSourceType) => {
console.log(row)
this.update()
}
deleteRow = (row: DataSourceType) => {
console.log(row);
this.update()
}
update = () => {
this.actionRef.current?.reload()
}
convertor = (columns: DataSourceType[] | undefined | null) => {
if (columns === undefined || columns === null) {
return []
}
return this.fakeData
}
async request() {
let response = await axiosInstance.get("common/place")
let data = this.convertor(response.data)
return {
data: data,
success: true,
}
}
static getDerivedStateFromProps(props: any, state: any) {
return {activated: props.activate};
}
render() { render() {
return ( return (
<div> <div>
<h1>City Config</h1> <EditableProTable<DataSourceType>
actionRef={this.actionRef}
rowKey="id"
headerTitle="城市信息配置"
maxLength={5}
scroll={{
x: 960,
}}
recordCreatorProps={
{
creatorButtonText: '添加城市',
position: "bottom",
record: {
id: (Math.random() * 1000000).toFixed(0),
placeName: "",
subsidyPerDay: 0,
baseExisted: false
},
}
}
loading={false}
columns={this.columns}
request={async (params, sorter, filter) => {
return this.request()
}}
value={this.state.tableData}
onChange={(data) => {
this.setState({tableData: data})
}}
editable={{
type: 'single',
editableKeys: this.state.editableKeys,
onSave: async (rowKey, data, row) => {
if (typeof data.baseExisted === "string") {
data.baseExisted = data.baseExisted === "true"
}
this.saveRow(data)
},
onChange: (e) => {
this.setState({editableKeys: e});
},
}}
/>
</div> </div>
); );
} }
columns: ProColumns<DataSourceType>[] = [
{
title: '地点名称',
dataIndex: 'placeName',
formItemProps: {
rules: [{
required: true, type: "string", whitespace: true, validator: (rule, value) => {
if (value === undefined || value === null || typeof value !== "string" || value.trim() === "") {
return Promise.reject("此项为必填项")
} }
for (let i = 0; i < this.state.tableData.length; i++) {
if (this.state.tableData[i] === value.trim()) {
return Promise.reject("地点名称重复")
}
}
return Promise.resolve()
}
}],
},
editable: (text, record, index) => {
return record.placeName === "";
},
width: '15%',
},
{
title: '每日补贴',
dataIndex: 'subsidyPerDay',
render: (_) => <span>¥{_}</span>,
formItemProps: (a, b) => {
return {
rules: [{
required: true, validator: (rule, value) => {
if (!isNaN(Number(value)) && Number(value) >= 0 && Number(value) <= 1000000) {
if ((typeof value === "string") && value.split(".").length === 2 && value.split(".")[1].length > 2) {
return Promise.reject("至多两位小数")
}
return Promise.resolve()
}
return Promise.reject("请输入正确金额")
}
}],
}
//style: {width: '100%'}
},
valueType: "text",
width: '25%'
},
{
title: '设有基地',
dataIndex: 'baseExisted',
width: '15%',
valueType: 'radio',
valueEnum: {
true: {text: '是', status: 'Success'},
false: {text: '否', status: 'Error'},
},
},
{
title: '操作',
valueType: 'option',
width: 200,
render: (text, record, _, action) => [
<a
key="editable"
onClick={() => {
action?.startEditable?.(record.id);
}}
>
</a>,
<a
key="delete"
onClick={(item) => {
this.deleteRow(record);
}}
>
</a>,
],
},
];
fakeData: DataSourceType[] = [
{
id: 0,
placeName: '北京',
subsidyPerDay: 100,
baseExisted: true,
}, {
id: 1,
placeName: '上海',
subsidyPerDay: 100,
baseExisted: true,
}, {
id: 2,
placeName: '广州',
subsidyPerDay: 100,
baseExisted: false,
}
]
}
export default CityConfig; export default CityConfig;

View File

@ -1,12 +1,74 @@
import React from "react"; import React from "react";
import {Button, Col, Form, InputNumber, Row, Switch, Table} from "antd";
import {ActionType} from "@ant-design/pro-components";
import {FormInstance} from "antd/es/form";
import Column from "antd/es/table/Column";
import RedoOutlined from "@ant-design/icons/lib/icons/RedoOutlined";
class OtherConfig extends React.Component<any, any> { class OtherConfig extends React.Component<any, any> {
refresh = () => {
//TODO: refresh
this.setState({forced: true, limit: 0})
}
submit = () => {
//TODO: submit
this.refresh()
}
constructor(props: any) {
super(props);
this.state = {
activated: props.activate,
limit: 0,
forced: true,
refresh: this.refresh
}
}
static getDerivedStateFromProps(props: any, state: any) {
if (props.activate !== state.activated && typeof state.refresh === "function")
state.refresh()
return {activated: props.activate};
}
render() { render() {
return ( return (
<div> <div style={{paddingTop: 50,paddingLeft:50}}>
<h1>Other Config</h1> <Row>
{"强制总经理审批:"}
<Switch checked={this.state.forced} onChange={(e) => {
this.setState({forced: e, limit: 0})
}}/>
</Row>
<Row style={{marginTop: 30, alignContent: "center"}}>
{"总经理审批阈值:"}
<InputNumber prefix={"¥"} controls={false}
min={0} max={100000} defaultValue={500}
disabled={this.state.forced} value={this.state.limit}
onChange={(value) => {
if (isNaN(value)||Number(value) < 0) {
this.setState({limit: 0})
} else if (value.toString().split(".").length === 1) {
this.setState({limit: Number(value)})
} else if (value.toString().split(".")[1].length <= 2) {
this.setState({limit: Number(value)})
} else {
this.setState({limit: Number(value).toFixed(2)})
}
}}/>
</Row>
<Row style={{marginTop: 30,paddingBottom:30}}>
<Button style={{marginLeft: 30}} type={"default"} onClick={() => {
this.refresh()
}}><RedoOutlined /></Button>
<Button style={{marginLeft: 60}} type={"default"} onClick={() => {
}}></Button>
</Row>
</div> </div>
); );
} }
} }
export default OtherConfig; export default OtherConfig;

View File

@ -135,15 +135,14 @@ class ReimbursementCreate extends React.Component<any, any> {
}; };
submitCheck = () => { submitCheck = () => {
//TODO: check
let msgContent:string = "" let msgContent:string = ""
if(this.state.departureName == "" ) { if(this.state.departureName === "" ) {
msgContent = "未填写出发地" msgContent = "未填写出发地"
} else if(this.state.destinationName == "") { } else if(this.state.destinationName === "") {
msgContent = "未填写目的地" msgContent = "未填写目的地"
} else if(this.state.departureInvoice == null) { } else if(this.state.departureInvoice === null) {
msgContent = "未上传出发票据" msgContent = "未上传出发票据"
} else if(this.state.selectedDepartment == null || this.state.selectedDepartment.isEmpty()) { } else if(this.state.selectedDepartment === null) {
msgContent = "未选择报销部门" msgContent = "未选择报销部门"
} else { } else {
return {ok: true, msg: ""} return {ok: true, msg: ""}