2025-11-10 16:14:42 +08:00
|
|
|
<template>
|
2025-11-19 15:51:58 +08:00
|
|
|
<div class="container">
|
|
|
|
|
<div class="search-area">
|
|
|
|
|
<Form ref="formInline" inline :label-width="120" :model="formInline" :rules="ruleInline">
|
|
|
|
|
<FormItem prop="user" label="充电桩名称:">
|
|
|
|
|
<Input type="text" v-model="formInline.user" placeholder="" />
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem>
|
|
|
|
|
<Button type="primary" @click="handleSubmit('formInline')">搜索</Button>
|
|
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="action-btn">
|
|
|
|
|
<Button type="primary" @click="add">添加</Button>
|
|
|
|
|
<!-- <Button type="error">删除</Button> -->
|
|
|
|
|
</div>
|
|
|
|
|
<div class="table-container">
|
|
|
|
|
<Table border :columns="columns" stripe :height="tableHeight" :data="data">
|
|
|
|
|
<template #action="{ row, index }">
|
|
|
|
|
<Button type="primary" size="small" style="margin-right: 5px" @click="show(row.charge_pile_id)">编辑</Button>
|
|
|
|
|
<Button type="error" size="small" @click="remove(row.charge_pile_id)">删除</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Table>
|
|
|
|
|
<Page :total="total" show-total show-sizer class="page" @on-change="onChangePage"
|
|
|
|
|
@on-page-size-change="onChangePageSize" />
|
|
|
|
|
</div>
|
2025-11-10 16:14:42 +08:00
|
|
|
|
2025-11-19 15:59:35 +08:00
|
|
|
<!-- charge_station_id 所属充电站 -->
|
2025-11-19 16:48:30 +08:00
|
|
|
<!-- ConnectorID 充电桩编号 -->
|
|
|
|
|
<!-- no 位号 -->
|
2025-11-19 15:59:35 +08:00
|
|
|
|
2025-11-19 15:51:58 +08:00
|
|
|
<!-- 添加、编辑 -->
|
|
|
|
|
<Modal v-model="show_modal" title="Common Modal dialog box title" :mask-closable="false" @on-ok="ok"
|
|
|
|
|
@on-cancel="cancel">
|
|
|
|
|
<Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
|
|
|
|
|
<FormItem label="Name" prop="name">
|
|
|
|
|
<Input v-model="formValidate.name" placeholder="Enter your name" />
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem label="E-mail" prop="mail">
|
|
|
|
|
<Input v-model="formValidate.mail" placeholder="Enter your e-mail" />
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem label="City" prop="city">
|
|
|
|
|
<Select v-model="formValidate.city" placeholder="Select your city">
|
|
|
|
|
<Option value="beijing">New York</Option>
|
|
|
|
|
<Option value="shanghai">London</Option>
|
|
|
|
|
<Option value="shenzhen">Sydney</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem label="Date">
|
|
|
|
|
<Row>
|
|
|
|
|
<Col span="11">
|
|
|
|
|
<DatePicker type="date" placeholder="Select date" v-model="formValidate.date"></DatePicker>
|
|
|
|
|
</Col>
|
|
|
|
|
<Col span="2" style="text-align: center">-</Col>
|
|
|
|
|
<Col span="11">
|
|
|
|
|
<TimePicker type="time" placeholder="Select time" v-model="formValidate.time"></TimePicker>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem label="Gender" prop="gender">
|
|
|
|
|
<RadioGroup v-model="formValidate.gender">
|
|
|
|
|
<Radio label="male">Male</Radio>
|
|
|
|
|
<Radio label="female">Female</Radio>
|
|
|
|
|
</RadioGroup>
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem label="Hobby" prop="interest">
|
|
|
|
|
<CheckboxGroup v-model="formValidate.interest">
|
|
|
|
|
<Checkbox label="Eat"></Checkbox>
|
|
|
|
|
<Checkbox label="Sleep"></Checkbox>
|
|
|
|
|
<Checkbox label="Run"></Checkbox>
|
|
|
|
|
<Checkbox label="Movie"></Checkbox>
|
|
|
|
|
</CheckboxGroup>
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem label="Desc" prop="desc">
|
|
|
|
|
<Input v-model="formValidate.desc" type="textarea" :autosize="{ minRows: 2, maxRows: 5 }"
|
|
|
|
|
placeholder="Enter something..." />
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem>
|
|
|
|
|
<Button type="primary" @click="handleSubmit2('formValidate')">Submit</Button>
|
|
|
|
|
<Button @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button>
|
|
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
|
|
|
|
</Modal>
|
|
|
|
|
</div>
|
2025-11-10 16:14:42 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-11-19 15:51:58 +08:00
|
|
|
import {
|
|
|
|
|
getPileList, addPile, getPileRead, getPileUpdate, getPileDelete,
|
|
|
|
|
} from '@/api'
|
2025-11-10 16:14:42 +08:00
|
|
|
|
2025-11-19 15:51:58 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'charging_station',
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
age: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
show_modal: false,
|
|
|
|
|
total: 100,
|
|
|
|
|
tableHeight: 500,
|
|
|
|
|
formInline: {
|
|
|
|
|
user: '',
|
|
|
|
|
password: '',
|
|
|
|
|
},
|
|
|
|
|
ruleInline: {},
|
|
|
|
|
columns: [{
|
|
|
|
|
title: '站点名称',
|
|
|
|
|
key: 'charge_station_name',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '充电桩编号',
|
|
|
|
|
key: 'ConnectorID',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '充电桩状态',
|
|
|
|
|
key: 'status_text',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '位号',
|
|
|
|
|
key: 'no',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '操作',
|
|
|
|
|
slot: 'action',
|
|
|
|
|
width: 150,
|
|
|
|
|
align: 'center',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
data: [],
|
|
|
|
|
formValidate: {
|
|
|
|
|
name: '',
|
|
|
|
|
mail: '',
|
|
|
|
|
city: '',
|
|
|
|
|
gender: '',
|
|
|
|
|
interest: [],
|
|
|
|
|
date: '',
|
|
|
|
|
time: '',
|
|
|
|
|
desc: '',
|
|
|
|
|
},
|
|
|
|
|
ruleValidate: {
|
|
|
|
|
name: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'The name cannot be empty',
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
}],
|
|
|
|
|
mail: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'Mailbox cannot be empty',
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'email',
|
|
|
|
|
message: 'Incorrect email format',
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
city: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'Please select the city',
|
|
|
|
|
trigger: 'change',
|
|
|
|
|
}],
|
|
|
|
|
gender: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'Please select gender',
|
|
|
|
|
trigger: 'change',
|
|
|
|
|
}],
|
|
|
|
|
interest: [{
|
|
|
|
|
required: true,
|
|
|
|
|
type: 'array',
|
|
|
|
|
min: 1,
|
|
|
|
|
message: 'Choose at least one hobby',
|
|
|
|
|
trigger: 'change',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'array',
|
|
|
|
|
max: 2,
|
|
|
|
|
message: 'Choose two hobbies at best',
|
|
|
|
|
trigger: 'change',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
date: [{
|
|
|
|
|
required: true,
|
|
|
|
|
type: 'date',
|
|
|
|
|
message: 'Please select the date',
|
|
|
|
|
trigger: 'change',
|
|
|
|
|
}],
|
|
|
|
|
time: [{
|
|
|
|
|
required: true,
|
|
|
|
|
type: 'string',
|
|
|
|
|
message: 'Please select time',
|
|
|
|
|
trigger: 'change',
|
|
|
|
|
}],
|
|
|
|
|
desc: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'Please enter a personal introduction',
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'string',
|
|
|
|
|
min: 20,
|
|
|
|
|
message: 'Introduce no less than 20 words',
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.getList()
|
|
|
|
|
this.calculateTableHeight()
|
|
|
|
|
window.addEventListener('resize', this.calculateTableHeight)
|
|
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
window.removeEventListener('resize', this.calculateTableHeight)
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
calculateTableHeight() {
|
|
|
|
|
// 计算表格高度 = 窗口高度 - 搜索区域高度 - 分页高度 - 其他间距
|
|
|
|
|
const searchHeight = document.querySelector('.search-area').offsetHeight
|
|
|
|
|
const actionBtnHeight = document.querySelector('.action-btn').offsetHeight
|
|
|
|
|
const pageHeight = 32 // 分页组件大约高度
|
|
|
|
|
const margins = 40 // 上下边距总和
|
|
|
|
|
this.tableHeight = window.innerHeight - actionBtnHeight - searchHeight - pageHeight - margins - 130
|
|
|
|
|
},
|
|
|
|
|
async getList() {
|
|
|
|
|
await getPileList({
|
|
|
|
|
page: this.page,
|
|
|
|
|
pageSize: this.pageSize,
|
|
|
|
|
...this.formInline,
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
this.total = res.data.total
|
|
|
|
|
this.data = res.data.data
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleSubmit() {
|
|
|
|
|
this.getList()
|
|
|
|
|
},
|
|
|
|
|
add() {
|
|
|
|
|
this.show_modal = true
|
|
|
|
|
this.$refs.formValidate.resetFields()
|
|
|
|
|
this.formValidate.charge_pile_id = ''
|
|
|
|
|
},
|
|
|
|
|
cancel() {
|
|
|
|
|
this.$refs.formValidate.resetFields()
|
|
|
|
|
this.show_modal = false
|
|
|
|
|
},
|
|
|
|
|
async show(id) {
|
|
|
|
|
await getPileRead({ id }).then(res => {
|
|
|
|
|
this.formValidate = { ...res.data }
|
|
|
|
|
this.show_modal = true
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async remove(id) {
|
|
|
|
|
const confirm = await new Promise(resolve => {
|
|
|
|
|
this.$Modal.confirm({
|
|
|
|
|
title: '确认删除',
|
|
|
|
|
content: '您确定要删除此项吗?',
|
|
|
|
|
onOk: () => resolve(true),
|
|
|
|
|
onCancel: () => resolve(false),
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
if (!confirm) {
|
|
|
|
|
this.$Message.info('已取消删除')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
await getPileDelete({ id }).then(res => {
|
|
|
|
|
this.$Message.success(res.msg)
|
|
|
|
|
this.getList()
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async ok() {
|
|
|
|
|
const valid = await new Promise(resolve => this.$refs.formValidate.validate(resolve))
|
|
|
|
|
if (!valid) {
|
|
|
|
|
this.$Message.error('请正确填写表单')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (this.formValidate.charge_station_id) {
|
|
|
|
|
await getPileUpdate(this.formValidate).then(res => {
|
|
|
|
|
this.$Message.success(res.msg)
|
|
|
|
|
this.getList()
|
|
|
|
|
this.cancel()
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
await addPile(this.formValidate).then((res) => {
|
|
|
|
|
this.$Message.success(res.msg)
|
|
|
|
|
this.cancel()
|
|
|
|
|
this.getList()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onChangePage(e) {
|
|
|
|
|
if (this.page != e) {
|
|
|
|
|
this.page = e
|
|
|
|
|
this.getList()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onChangePageSize(e) {
|
|
|
|
|
if (this.pageSize != e) {
|
|
|
|
|
this.page = 1
|
|
|
|
|
this.pageSize = e
|
|
|
|
|
this.getList()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-11-10 16:14:42 +08:00
|
|
|
</script>
|
|
|
|
|
<style scoped>
|
2025-11-19 15:51:58 +08:00
|
|
|
.container {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
height: 100vh;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
2025-11-10 16:14:42 +08:00
|
|
|
|
2025-11-19 15:51:58 +08:00
|
|
|
.action-btn {
|
|
|
|
|
margin: 20px 0;
|
|
|
|
|
background-color: white;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
border: 1px solid #F3F7FD;
|
|
|
|
|
border-radius: 15px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2025-11-10 16:14:42 +08:00
|
|
|
|
2025-11-19 15:51:58 +08:00
|
|
|
button {
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-10 16:14:42 +08:00
|
|
|
|
2025-11-19 15:51:58 +08:00
|
|
|
.table-container {
|
|
|
|
|
flex: 1;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.page {
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
text-align: right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.search-area {
|
|
|
|
|
background-color: white;
|
|
|
|
|
padding-top: 20px;
|
|
|
|
|
border: 1px solid #F3F7FD;
|
|
|
|
|
border-radius: 15px;
|
|
|
|
|
}
|
2025-11-10 16:14:42 +08:00
|
|
|
</style>
|