129 lines
3.0 KiB
Vue
Raw Normal View History

2024-07-09 18:07:55 +08:00
<template>
<t-card :bordered="false">
<div class="form-step-container">
<t-button @click="add">新增</t-button>
<t-table
rowKey="index"
:data="list"
:columns="columns"
:stripe="false"
:bordered="false"
:hover="true"
size="large"
table-layout="auto"
cellEmptyContent="-"
>
<template #select="{ row }">
<t-space size="24px" v-if="row.id!=0">
<t-button theme="warning" @click="edit(row)">编辑</t-button>
<t-popconfirm content="确认删除吗?" @confirm="del(row)">
<t-button theme="danger" >删除</t-button>
</t-popconfirm>
</t-space>
</template>
</t-table>
</div>
<t-dialog header="新增区域" :visible="addMode" :onClose="onCloseMy" @confirm="onSubmit">
<t-form>
<t-form-item label="区域名称" name="region_name">
<t-input placeholder="请输入区域名称" v-model="region_name"/>
</t-form-item>
</t-form>
</t-dialog>
</t-card>
</template>
<script lang="ts">
export default {
data() {
return {
region_name: '',
addMode: false,
isEdit: false,
editID:0,
list: [],
columns: [
{colKey: 'region_name', title: '区域名称'},
{colKey: 'select', title: '操作', width: 200},
],
}
},
mounted() {
//this.member_id=this.$route.query.id;
this.getList();
},
methods: {
del(d){
console.log(d);
this.$request
.post('/region/del',{id:d.id})
.then((res) => {
if(res.code==1){
this.$message.success(res.msg);
this.getList();
}else {
this.$message.error(res.msg);
}
console.log(res);
})
.catch((e) => {
console.log(e);
});
},
add(){
this.region_name= '';
this.addMode=true;
this.isEdit=false;
},
edit(d){
this.editID=d.id;
this.region_name=d.region_name;
this.addMode=true;
this.isEdit=true;
},
getList() {
this.$request
.post("/region")
.then((res) => {
console.log(res);
this.list = res.data;
})
.catch((e) => {
console.log(e);
});
},
onSubmit() {
if (this.region_name == '') {
this.$message.error('区域名称不能为空');
return;
}
var url='/region/add';
if(this.isEdit){
url='/region/update';
}
this.$request
.post(url,{region_name:this.region_name,id:this.editID})
.then((res) => {
if(res.code==1){
this.$message.success(res.msg);
this.addMode=false;
this.getList();
}else {
this.$message.error(res.msg);
}
console.log(res);
})
.catch((e) => {
console.log(e);
});
},
onCloseMy() {
this.addMode = false;
}
}
}
</script>
<style scoped lang="less">
</style>