kongdeqiang
2023-01-16 0d846fafce55573aacba349935c1f10c6dfc638d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
    <div>
        <div style="padding: 10px 10px 0px 10px;">
            <el-form :inline="true" :model="searchForm">
                <el-form-item label="车牌号">
                <el-input v-model="searchForm.carNo"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="onSearch" icon="el-icon-search">查询</el-button>
                    <el-button type="primary" size="small" @click="onAdd" icon="el-icon-plus">增加</el-button>
                </el-form-item>
            </el-form>
        </div>
 
        <el-table :data="pageData.rows" v-loading="pageData.isLoading" border style="width:100%;border:1px solid #bcbec2;">
            <el-table-column type="index" width="50" label="序号" align="center"> </el-table-column>
            <el-table-column prop="carNo" label="车牌号" align="center" width="150"></el-table-column>
            <el-table-column prop="type" label="类型" align="center" width="100">
                <template slot-scope="scope">
                    <p v-if="scope.row.type==0">永久</p>
                    <p v-if="scope.row.type==1">月票</p>
                </template>
            </el-table-column>
            <el-table-column prop="startTime" label="月票开始日期" align="center"></el-table-column>
            <el-table-column prop="endTime" label="月票结束日期" align="center"></el-table-column>
            <el-table-column prop="name" label="停车场" align="center"></el-table-column>
            <el-table-column label="操作" fixed="right" width="150" align="center">
                <template slot-scope="scope">
                    <el-button size="mini" @click="onEdit(scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="onDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="onPageSizeChange" @current-change="onCurrentPageChange" :current-page="pageData.currentPage" :page-size="pageData.pageSize" :total="pageData.total" style="float: right"></el-pagination>
 
        <el-dialog title="编辑" :visible.sync="flag" width="40%">
            <el-form :model="formData" ref="formData" label-width="100px">
                <el-form-item label="车牌号" prop="carNo" :rules="[{ required: true, message: '请输入车牌号', trigger: 'change'}]">
                    <el-input v-model="formData.carNo"></el-input>
                </el-form-item>
                <el-form-item label="类型" prop="type" :rules="[{ required: true, message: '请选择类型', trigger: 'change'}]">
                    <el-select v-model="formData.type" @change="selectChange">
                        <el-option label="永久" :value=0></el-option>
                        <el-option label="月票" :value=1></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="月票开始日期" prop="startTime" v-if="flag2">
                    <el-date-picker type="date" placeholder="选择时间" v-model="formData.startTime"></el-date-picker>
                </el-form-item>
                <el-form-item label="月票结束日期" prop="endTime" v-if="flag2">
                    <el-date-picker placeholder="选择时间" v-model="formData.endTime"></el-date-picker>
                </el-form-item>
                <el-form-item label="停车场" prop="parkIds" v-if="flag2">
                    <el-select v-model="ids" multiple clearable>
                        <el-option v-for="item in table1" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="flag = false">取 消</el-button>
                <el-button type="primary" @click="onSave">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
 
<script>
    export default {
        name: "index",
        data: function () {
            return {
                flag:false,
                flag2:false,
                searchForm: {
                    name: ''
                },
                pageData: this.$byutil.defaultPageData(),
                formData: {
                    carNo: '',
                    type: 0,
                    endTime: '',
                    startTime: '',
                    parkIds: '',
                    name: ''
                },
                ids:[],
                urlPath:this.$systemconfig.basePath + '/whiteList/',
                table1:[],
            }
        },
        mounted() {
            this.loadData();
            this.$byutil.postData(this, this.$systemconfig.basePath+'/park/findAll', this.formData, res => {
                this.table1 = res.data;
            })
        },
        methods: {
            selectChange(value){
                if(value==1){
                    this.flag2 = true;
                }else{
                    this.flag2 = false;
                }
            },
            onSave(){
                this.$refs['formData'].validate((valid) => {
                    if (valid) {
                      this.formData.parkIds = this.ids.join(",")
                        this.$byutil.postData(this, this.urlPath+'save', this.formData, res => {
                            this.$refs['formData'].resetFields();
                            this.flag=false;
                            this.$message({message:'保存成功', type: 'success'});
                            this.loadData();
                        })
                    } else {
                        return false;
                    }
                });
            },
            loadData() {
                this.$byutil.loadPageData(this, this.urlPath+'findPageNew', this.searchForm);
            },
            onSearch() {
                this.pageData = this.$byutil.defaultPageData();
                this.loadData();
            },
            onAdd() {
                this.flag=true;
                this.flag2=false;
                this.$refs['formData'].resetFields();
                this.formData = {
                    carNo: '',
                    type: 0,
                    endTime: '',
                    startTime: '',
                    parkIds: null
                }
            },
            onEdit(row) {
                this.flag=true;
                this.ids = []
                this.formData  = row;
                if(row.type==1){
                  this.ids = this.formData.parkIds.split(",")
                  this.ids = this.ids.map(function(data){
                    return +data;
                  });
                  this.flag2=true;
                }
            },
            onDelete(row) {
                this.$byutil.deleteData(this,this.urlPath+"delete",{id:row.id}, res => {
                    this.$message({message: '删除成功', type: 'success'});
                    this.loadData();
                })
            },
            onPageSizeChange(val) {
                this.pageData.pageSize = val;
                this.loadData();
            },
            onCurrentPageChange(val) {
                this.pageData.page = val;
                this.loadData();
            },
        }
    }
</script>
 
<style scoped>
 
</style>