功能点:
- Form表单验证
- 重置表单
功能点代码
//表单校验规则,dataRule()是form表单中需要引用的。见下方源码的form表单写法。
computed:{
dataRule(){
return {
stationCode: [
{required: true, message: '车站编码不能为空'}
],
lineCode: [
{required: true, message: '线路编码不能为空' }
],
stationNameCN: [
{required: true, message: '中文名称不能为空' }
],
stationNameEN: [
{required: true, message: '英文名称不能为空' }
],
stationState: [
{required: true, message: '车站状态不能为空' }
],
isHeadEnd: [
{required: true, message: '首末站不能为空' }
],
isTransfer: [
{required: true, message: '换乘站不能为空' }
],
isImportant: [
{required: true, message: '重点站不能为空' }
],
turnBackFlag: [
{required: true, message: '折返站不能为空' }
],
longitude: [
{required: true, message: '经度不能为空' }
],
latitude: [
{required: true, message: '纬度不能为空' }
],
atsLineId: [
{required: true, message: 'ATS线路编码不能为空' }
],
atsStationId: [
{required: true, message: 'ATS车站编码不能为空' }
],
telNum: [
{required: true, message: '电话号码不能为空' }
],
shortName: [
{required: true, message: '简称不能为空' }
],
}
}
},
//一键重置表单,怎么用见下方源码
dataFormResetHandle(formname){
this.$refs[formname].resetFields();
},
该页面完整源码:拿着上面的关键字直接ctrl+f搜,大家看看就明白了。
<template>
<el-card shadow="never" class="aui-card-fill">
<div style="margin-left: 20px;margin-right: 20px">
<div>
<br>
<span style="font-size: 30px;">车站基本信息</span>
</div>
<div style="height: 60px;margin-top: 10px;font-size: 16px">
<el-row >
<el-col :span="21">
<el-form :inline="true" ref="form" :model="form" label-width="80px">
<el-form-item >
<span>开通状态</span>
</el-form-item>
<el-form-item>
<el-radio-group v-model="form.stationStateRadio">
<el-radio :label="0" >全部</el-radio>
<el-radio :label="1" >已开通</el-radio>
<el-radio :label="2" >未开通</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item>
<el-input v-model="form.searchMessage" placeholder="请输入关键字搜索" ></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" style="margin-left: 15px;" icon="el-icon-search" @click="searchHandle()">搜索</el-button>
</el-form-item>
</el-form>
</el-col>
<el-col :span="3" style="text-align: right">
<el-button type="primary" @click="add()" icon="el-icon-plus" >新增</el-button>
<el-button type="danger" class="my-icon" icon="el-icon-delete" @click="deleteStation()">删除</el-button>
</el-col>
</el-row>
</div>
<!-- 第二行table-->
<div style="margin-top: 10px">
<el-table
ref="multipleTable"
:data="tableData"
tooltip-effect="dark"
style="width: 100%;"
header-cell-style="background:#E3EDF7"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="30">
</el-table-column>
<el-table-column
label="序号"
width="52"
prop="id"
type="index">
</el-table-column>
<el-table-column
prop="stationCode"
label="站点编号"
width="82">
</el-table-column>
<el-table-column
prop="lineCode"
label="所属线路"
width="82">
</el-table-column>
<el-table-column
prop="stationNameCN"
label="中文名称"
width="100">
</el-table-column>
<el-table-column
:show-overflow-tooltip="true"
prop="stationNameEN"
label="英文名称"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="stationState"
label="开通状态"
width="82">
</el-table-column>
<el-table-column
prop="isHeadEnd"
label="首末站"
width="72">
</el-table-column>
<el-table-column
prop="isTransfer"
label="换乘站"
width="72">
</el-table-column>
<el-table-column
prop="isImportant"
label="重点站"
width="72">
</el-table-column>
<el-table-column
prop="turnBackFlag"
label="折返站"
width="72">
</el-table-column>
<el-table-column
prop="longitude"
label="经度"
width="95">
</el-table-column>
<el-table-column
prop="latitude"
label="纬度"
width="90">
</el-table-column>
<el-table-column
prop="updateTime"
label="更新日期"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="atsLineId"
label="ATS线路编码"
width="120">
</el-table-column>
<el-table-column
prop="atsStationId"
label="ATS车站编码"
width="120">
</el-table-column>
<el-table-column
prop="telNum"
label="车站电话"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="shortName"
label="车站简称"
width="140">
</el-table-column>
<el-table-column
label="操作"
width="110">
<template slot-scope="scope">
<el-button size="mini" type="text" @click="update(scope.row.stationCode)">编辑</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 分页 -->
<div><pagination ref="paginationRef" @refreshDataList="getData"></pagination></div>
</div>
<!-- 弹窗添加车站-->
<el-dialog
:title="insertUpdatetag=='insert' ? '新增车站信息' : '编辑车站信息'"
:visible.sync="dialogVisible"
width="50%"
:before-close="handleClose">
<!-- form表单 -->
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="120px">
<el-row>
<el-col :span="12"><div class="grid-content bg-purple">
<el-form-item label="车站编码:" prop="stationCode" >
<el-input style="width: 95%" v-model="dataForm.stationCode" placeholder="请输入车站编码"></el-input>
</el-form-item>
<el-form-item label="中文名称:" prop="stationNameCN">
<el-input style="width: 95%" v-model="dataForm.stationNameCN" placeholder="请输入中文名称"></el-input>
</el-form-item>
<el-form-item label="车站电话:" prop="telNum">
<el-input style="width: 95%" v-model="dataForm.telNum" placeholder="请输入车站电话"></el-input>
</el-form-item>
<el-form-item label="开通状态:" prop="stationState" style="height: 18px">
<el-radio-group v-model="dataForm.stationState" >
<el-radio :label="0">已开通</el-radio>
<el-radio :label="1">未开通</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="首末站:" prop="isHeadEnd" style="height: 18px">
<el-radio-group v-model="dataForm.isHeadEnd" >
<el-radio :label="0">首末站</el-radio>
<el-radio :label="1">中间站</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="换乘站:" prop="isTransfer" >
<el-radio-group v-model="dataForm.isTransfer">
<el-radio :label="0">换乘站</el-radio>
<el-radio :label="1">普通站</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="经度:" prop="longitude">
<el-input style="width: 95%" v-model="dataForm.longitude" placeholder="请输入经度"></el-input>
</el-form-item>
<el-form-item label="ATS线路编码:" prop="atsLineId">
<el-input style="width: 95%" v-model="dataForm.atsLineId" placeholder="请输入ATS线路编码"></el-input>
</el-form-item>
</div></el-col>
<el-col :span="12"><div class="grid-content bg-purple-light">
<el-form-item label="所属线路:" prop="lineCode">
<el-input style="width: 95%" v-model="dataForm.lineCode" placeholder="请输入所属线路"></el-input>
</el-form-item>
<el-form-item label="英文名称:" prop="stationNameEN" >
<el-input style="width: 95%" v-model="dataForm.stationNameEN" placeholder="请输入英文名称"></el-input>
</el-form-item>
<el-form-item label="简称:" prop="shortName">
<el-input style="width: 95%" v-model="dataForm.shortName" placeholder="请输入简称"></el-input>
</el-form-item>
<el-form-item label="重点站:" prop="isImportant" style="height: 18px">
<el-radio-group v-model="dataForm.isImportant">
<el-radio :label="0">重点站</el-radio>
<el-radio :label="1">普通站</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="折返站:" prop="turnBackFlag" style="height: 18px">
<el-radio-group v-model="dataForm.turnBackFlag">
<el-radio :label="0">折返站</el-radio>
<el-radio :label="1">普通站</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item prop="turnBackFlag">
</el-form-item>
<el-form-item label="纬度:" prop="latitude">
<el-input style="width: 95%" v-model="dataForm.latitude" placeholder="请输入纬度"></el-input>
</el-form-item>
<el-form-item label="ATS车站编码:" prop="atsStationId">
<el-input style="width: 95%" v-model="dataForm.atsStationId" placeholder="请输入ATS车站编码"></el-input>
</el-form-item>
</div></el-col>
</el-row>
<!-- <el-form-item style="margin-top: 20px;margin-left: 0px">-->
<!-- -->
<!-- </el-form-item>-->
</el-form>
<el-row style="margin-top: 15px;text-align: right">
<el-button type="primary" @click="dataFormSubmitHandle('dataForm')">立即提交</el-button>
<el-button type="primary" @click="dataFormResetHandle('dataForm')">重 置</el-button>
</el-row>
</el-dialog>
</el-card>
</template>
<script>
import pagination from '../programme/Pagination'
export default {
name: 'Station',
components:{
pagination
},
data() {
return {
dialogVisible: false,
dataForm:{
stationCode:'',
lineCode:'',
stationNameCN:'',
stationNameEN:'',
stationState:0,
isHeadEnd:0,
isTransfer:0,
isImportant:0,
turnBackFlag:0,
longitude:'',
latitude:'',
atsLineId:'',
atsStationId:'',
telNum:'',
shortName:''
},
form:{
stationStateRadio:0,
searchMessage:'',
},
stationStateRadio:3,
checkBoxData: [],
InfoUnitData:[],
unitsort:'',
searchMessage:'',
tableData: [],
multipleSelection: [],
insertUpdatetag:'insert',
isFirstResetForm:'0',
}
},
mounted(){
this.getData();
},
//校验规则
computed:{
dataRule(){
return {
stationCode: [
{required: true, message: '车站编码不能为空'}
],
lineCode: [
{required: true, message: '线路编码不能为空' }
],
stationNameCN: [
{required: true, message: '中文名称不能为空' }
],
stationNameEN: [
{required: true, message: '英文名称不能为空' }
],
stationState: [
{required: true, message: '车站状态不能为空' }
],
isHeadEnd: [
{required: true, message: '首末站不能为空' }
],
isTransfer: [
{required: true, message: '换乘站不能为空' }
],
isImportant: [
{required: true, message: '重点站不能为空' }
],
turnBackFlag: [
{required: true, message: '折返站不能为空' }
],
longitude: [
{required: true, message: '经度不能为空' }
],
latitude: [
{required: true, message: '纬度不能为空' }
],
atsLineId: [
{required: true, message: 'ATS线路编码不能为空' }
],
atsStationId: [
{required: true, message: 'ATS车站编码不能为空' }
],
telNum: [
{required: true, message: '电话号码不能为空' }
],
shortName: [
{required: true, message: '简称不能为空' }
],
}
}
},
methods:{
getData(){
let formData=new FormData();
this.$http.post('/station/listStation',formData,{baseURL:this.global.apis1}).then(({data:res})=>{
if (res.IsError =="false"){
this.tableData=res.Data;
this.$refs.paginationRef.total = res.total
}else{
return this.$message.error(res.Message)
}
})
},
//新增按钮
add(){
this.insertUpdatetag='insert';
this.dialogVisible=true;
this.dataFormResetHandle('dataForm');
this.isFirstResetForm='1'
},
//修改按钮
update(updateStationId){
this.insertUpdatetag='update';
this.dialogVisible=true;
if (this.isFirstResetForm=='1'){
this.dataFormResetHandle('dataForm');
}
this.getDataById(updateStationId);
},
//查找某一值
getDataById(updateLineId){
let formData=new FormData();
formData.append('stationId',updateLineId);
this.$http.post('/station/getDataById',formData,{baseURL:this.global.apis1}).then(({data:res})=>{
if (res.IsError =="false"){
this.dataForm=res.Data;
}else{
return this.$message.error(res.Message)
}
})
},
//提交按钮
dataFormSubmitHandle(formName){
this.$refs[formName].validate((valid) => {
if (valid) {
let formData=new FormData();
formData.append('stationCode',this.dataForm.stationCode);
formData.append('lineCode',this.dataForm.lineCode);
formData.append('stationNameCN',this.dataForm.stationNameCN);
formData.append('stationNameEN',this.dataForm.stationNameEN);
formData.append('stationState',this.dataForm.stationState);
formData.append('isHeadEnd',this.dataForm.isHeadEnd);
formData.append('isTransfer',this.dataForm.isTransfer);
formData.append('isImportant',this.dataForm.isImportant);
formData.append('turnBackFlag',this.dataForm.turnBackFlag);
formData.append('longitude',this.dataForm.longitude);
formData.append('latitude',this.dataForm.latitude);
formData.append('atsLineId',this.dataForm.atsLineId);
formData.append('atsStationId',this.dataForm.atsStationId);
formData.append('telNum',this.dataForm.telNum);
formData.append('shortName',this.dataForm.shortName);
if(this.insertUpdatetag=='insert'){
this.$http.post('/common/insertStation',formData,{baseURL:this.global.apis1}).then(({data:res})=>{
if (res.IsError =="false"){
this.dialogVisible=false;
this.getData();
this.$message({
message: '新增成功',
type: 'success'
});
}else{
return this.$message.error(res.Message)
}
})
}else {
// 修改
this.$http.post('/common/updateStation',formData,{baseURL:this.global.apis1}).then(({data:res})=>{
if (res.IsError =="false"){
this.dialogVisible=false;
this.getData();
this.$message({
message: '修改成功',
type: 'success'
});
}else{
return this.$message.error(res.Message)
}
})
}
} else {
console.log('error submit!!');
return false;
}
});
},
//重置按钮
dataFormResetHandle(formname){
this.$refs[formname].resetFields();
},
//删除项目
deleteStation(){
if (this.checkBoxData!=0){
this.$confirm('确认删除?')
.then(_ => {
let formData=new FormData();
formData.append('checkBoxData',this.checkBoxData);
this.$http.post('/common/deleteStation',formData,{baseURL:this.global.apis1}).then(({data:res})=>{
if (res.IsError =="false"){
this.getData();
this.$message({
message: '删除成功',
type: 'success'
});
}else{
return this.$message.error(res.Message)
}
})
})
.catch(_ => {});
} else {
this.$message({
message: '请选择至少一条数据',
type: 'warning'
});
}
},
//搜索按钮
searchHandle(){
let formData=new FormData();
this.$http.post('/common/searchStation',formData,{baseURL:this.global.apis1}).then(({data:res})=>{
if (res.IsError =="false"){
this.tableData=res.Data;
}else{
return this.$message.error(res.Message)
}
})
},
handleSelectionChange(val){
this.checkBoxData = val;
},
}
}
</script>
<style >
</style>
【最怕一生碌碌无为,安慰自己平凡可贵】