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