城市配置结束

main
白封羽 2023-01-06 15:25:52 +08:00
parent 8d02ef7ecc
commit 358ea4d733
1 changed files with 50 additions and 16 deletions

View File

@ -10,7 +10,7 @@ type DataSourceType = {
id: React.Key; id: React.Key;
placeName: string; placeName: string;
subsidyPerDay: number; subsidyPerDay: number;
baseExisted: boolean; base: boolean;
}; };
class CityConfig extends React.Component<any, any> { class CityConfig extends React.Component<any, any> {
@ -26,27 +26,58 @@ class CityConfig extends React.Component<any, any> {
} }
saveRow = (row: DataSourceType) => { saveRow = (row: DataSourceType) => {
console.log(row) let newRow = true
this.update() this.state.tableData.forEach((item: DataSourceType) => {
if (item.id === row.id) {
newRow = false
}
})
let data = {
placeName: row.placeName,
subsidyPerDay: row.subsidyPerDay * 100,
base: row.base
}
if (newRow) {
axiosInstance.post("management/place", data).then((res) => {
this.update()
})
} else {
axiosInstance.put("management/place", data).then((res) => {
this.update()
})
}
} }
deleteRow = (row: DataSourceType) => { deleteRow = (row: DataSourceType) => {
console.log(row); axiosInstance({
this.update() url: "management/place", method: "delete", data: {
placeName: row.placeName,
}
}).then((res) => {
this.update()
})
} }
update = () => { update = () => {
this.actionRef.current?.reload() axiosInstance.get("common/place").then((res) => {
this.setState({tableData: this.convertor(res.data)})
this.actionRef.current?.reload()
})
} }
convertor = (columns: DataSourceType[] | undefined | null) => { convertor = (columns: DataSourceType[] | undefined | null) => {
if (columns === undefined || columns === null) { if (columns === undefined || columns === null) {
return [] return []
} }
return this.fakeData for (let i = 0; i < columns.length; i++) {
columns[i].id = i
columns[i].subsidyPerDay /= 100.0
}
return columns
} }
async request() { async request() {
let response = await axiosInstance.get("common/place") let response = await axiosInstance.get("common/place")
console.log(response.data)
let data = this.convertor(response.data) let data = this.convertor(response.data)
return { return {
data: data, data: data,
@ -77,7 +108,7 @@ class CityConfig extends React.Component<any, any> {
id: (Math.random() * 1000000).toFixed(0), id: (Math.random() * 1000000).toFixed(0),
placeName: "", placeName: "",
subsidyPerDay: 0, subsidyPerDay: 0,
baseExisted: false base: false
}, },
} }
} }
@ -94,8 +125,8 @@ class CityConfig extends React.Component<any, any> {
type: 'single', type: 'single',
editableKeys: this.state.editableKeys, editableKeys: this.state.editableKeys,
onSave: async (rowKey, data, row) => { onSave: async (rowKey, data, row) => {
if (typeof data.baseExisted === "string") { if (typeof data.base === "string") {
data.baseExisted = data.baseExisted === "true" data.base = data.base === "true"
} }
this.saveRow(data) this.saveRow(data)
}, },
@ -157,13 +188,16 @@ class CityConfig extends React.Component<any, any> {
}, },
{ {
title: '设有基地', title: '设有基地',
dataIndex: 'baseExisted', dataIndex: 'base',
width: '15%', width: '15%',
valueType: 'radio', valueType: 'radio',
valueEnum: { valueEnum: {
true: {text: '是', status: 'Success'}, true: {text: '是', status: 'Success'},
false: {text: '否', status: 'Error'}, false: {text: '否', status: 'Error'},
}, },
editable: (text, record, index) => {
return record.placeName !== "其他";
}
}, },
{ {
title: '操作', title: '操作',
@ -176,7 +210,7 @@ class CityConfig extends React.Component<any, any> {
action?.startEditable?.(record.id); action?.startEditable?.(record.id);
}} }}
> >
{record.placeName !== "其他" ? "编辑" : ""}
</a>, </a>,
<a <a
key="delete" key="delete"
@ -184,7 +218,7 @@ class CityConfig extends React.Component<any, any> {
this.deleteRow(record); this.deleteRow(record);
}} }}
> >
{record.placeName !== "其他" ? "删除" : ""}
</a>, </a>,
], ],
}, },
@ -194,17 +228,17 @@ class CityConfig extends React.Component<any, any> {
id: 0, id: 0,
placeName: '北京', placeName: '北京',
subsidyPerDay: 100, subsidyPerDay: 100,
baseExisted: true, base: true,
}, { }, {
id: 1, id: 1,
placeName: '上海', placeName: '上海',
subsidyPerDay: 100, subsidyPerDay: 100,
baseExisted: true, base: true,
}, { }, {
id: 2, id: 2,
placeName: '广州', placeName: '广州',
subsidyPerDay: 100, subsidyPerDay: 100,
baseExisted: false, base: false,
} }
] ]
} }