审查视图

src/views/nav1/department.vue 14.3 KB
shenhailong authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="filters">
                <el-form-item>
                    <el-input v-model="filters.departmentName" placeholder="部门名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="getDepartments()">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="departmentAdd">新增</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
19 20
        <el-table :data="departmentList" highlight-current-row v-loading="listLoading" @selection-change="selsChange"
                  style="width: 100%;">
shenhailong authored
21 22 23 24
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column type="index">
            </el-table-column>
25
            <el-table-column prop="departmentId" label="ID" sortable>
shenhailong authored
26
            </el-table-column>
27
            <el-table-column prop="departmentName" label="部门名称" sortable>
shenhailong authored
28
            </el-table-column>
29
            <el-table-column prop="companyName" label="所属公司名称" sortable>
30
            </el-table-column>
31
            <el-table-column prop="creatTime" label="入库时间" sortable>
shenhailong authored
32 33 34 35 36 37 38 39 40 41 42 43
            </el-table-column>
            <el-table-column label="操作" min-width="150">
                <template slot-scope="scope">
                    <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
44 45
            <el-pagination layout="total, prev, pager, next" @current-change="handleCurrentChange" :page-size="5"
                           :total="total" style="float:right;">
shenhailong authored
46 47 48 49
            </el-pagination>
        </el-col>

        <!--编辑界面-->
50
        <el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false">
shenhailong authored
51 52 53 54 55 56 57 58
            <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
                <el-form-item label="ID">
                    <span>{{editForm.departmentId}}</span>
                </el-form-item>
                <el-form-item label="部门名称">
                    <el-input v-model="editForm.departmentName" auto-complete="off" placeholder="请输入公司名称"></el-input>
                </el-form-item>
                <el-form-item label="公司名称">
59 60 61 62 63 64 65 66
                    <el-select v-model="editForm.companyId" placeholder="请选择公司">
                        <el-option
                                v-for="item in companyList"
                                :key="item.companyId"
                                :label="item.companyName"
                                :value="item.companyId">
                        </el-option>
                    </el-select>
shenhailong authored
67 68 69 70 71 72 73 74 75
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
            </div>
        </el-dialog>

        <!--新增界面-->
76
        <el-dialog title="新增" :visible.sync="addFormVisible" :close-on-click-modal="false">
shenhailong authored
77
            <el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm">
78 79
                <el-form-item label="部门名称" prop="deprtmentName">
                    <el-input v-model="addForm.departmentName" auto-complete="off" placeholder="请输入部门名称"></el-input>
shenhailong authored
80
                </el-form-item>
81 82 83 84 85 86 87 88 89
                <el-form-item label="公司名称" prop="companyId">
                    <el-select v-model="addForm.companyId" placeholder="请选择公司">
                        <el-option
                                v-for="item in companyList"
                                :key="item.companyId"
                                :label="item.companyName"
                                :value="item.companyId">
                        </el-option>
                    </el-select>
shenhailong authored
90 91 92 93 94 95 96 97 98 99 100 101 102
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="addFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
    import util from '../../common/js/util'
    import NProgress from 'nprogress'
103 104
    import {getList, remove, batchRemove, edit, add} from '../../api/department';
    import {getList as getCompanyList} from '../../api/company';
shenhailong authored
105 106 107 108 109 110
    import moment from 'moment'

    export default {
        data() {
            return {
                filters: {
shenhailong authored
111
                    departmentName: ''
shenhailong authored
112
                },
113
shenhailong authored
114
                departmentList: [],
115
                companyList: [],
shenhailong authored
116 117 118
                permIds: [],
                total: 0,
                pageNum: 1,
shenhailong authored
119
                pageSize: 10,
shenhailong authored
120 121 122 123 124 125 126
                listLoading: false,
                sels: [],//列表选中列
                //编辑界面是否显示
                editFormVisible: false,
                editLoading: false,
                editFormRules: {
                    departmentName: [
127
                        {required: true, message: '请输入部门名称', trigger: 'blur'}
shenhailong authored
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
                    ]
                },
                //编辑界面数据
                editForm: {
                    departmentId: '',
                    departmentName: '',
                    companyId: ''
                },
                //设置权限数据
                setPermForm: {},
                //新增界面是否显示
                addFormVisible: false,
                //设置权限界面是否显示
                PermFormVisible: false,
                addLoading: false,
                addFormRules: {
                    departmentName: [
145
                        {required: true, message: '请输入部门名称', trigger: 'blur'}
shenhailong authored
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
                    ]
                },
                //新增界面数据
                addForm: {
                    departmentName: '',
                    companyId: ''
                },
                departmentFrom: {
                    departmentId: 1,
                    departmentName: '',
                    departments: []
                }

            }
        },
        mounted() {
            this.getDepartments();
        },
        methods: {

            handleCurrentChange(val) {
                this.pageNum = val;
                this.getDepartments();
            },
170
            //获取列表
shenhailong authored
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
            getDepartments() {
                let para = {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    departmentName: this.filters.departmentName
                };
                this.listLoading = true;
                //NProgress.start();
                getList(para).then((res) => {
                    this.total = res.data.total;
                    this.departmentList = res.data.list;
                    this.listLoading = false;
                    //NProgress.done();
                }).catch((error) => {

                    this.listLoading = false;
187 188
                    if (null != error.response && error.response !== undefined) {
                        let status = error.response.status;
shenhailong authored
189
                        let msg = error.response.statusText;
190 191
                        alert(status + msg);
                    } else {
shenhailong authored
192 193 194 195 196 197
                        alert(error);
                    }

                });

            },
198 199
            //获取列表
            getCompanylists() {
200
                let para = {};
201 202 203 204 205 206 207 208 209
                this.listLoading = true;
                //NProgress.start();
                getCompanyList(para).then((res) => {
                    this.total = res.data.total;
                    this.companyList = res.data.list;
                    this.listLoading = false;
                    //NProgress.done();
                }).catch((error) => {
                    this.listLoading = false;
210 211
                    if (null != error.response && error.response !== undefined) {
                        let status = error.response.status;
212
                        let msg = error.response.statusText;
213 214
                        alert(status + msg);
                    } else {
215 216 217 218 219 220
                        alert(error);
                    }

                });

            },
shenhailong authored
221 222 223 224 225 226 227 228

            //删除
            handleDel: function (index, row) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
229
                    let para = {departmentId: row.departmentId};
shenhailong authored
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                    remove(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getDepartments();
                    }).catch((error) => {
                        this.listLoading = false;
                        alert(error);
                    });
                }).catch();
            },
            /**
             * 显示编辑界面
             * @param index
             * @param row 为这行的数据对象
             */
            handleEdit: function (index, row) {
                this.editFormVisible = true;
                this.editForm = Object.assign({}, row);
252
                this.getCompanylists();
shenhailong authored
253 254 255 256 257 258 259
            },
            setPerm: function (index, row) {
                var _this = this;
                this.departmentIds = [];
                this.PermFormVisible = true;
                this.departmentFrom = Object.assign({}, row);
                let rolePerms = this.departmentFrom.departments;
260 261 262
                if (util.checkNull(rolePerms)) {
                    rolePerms.forEach(function (department, v_index, v_arr) {
                        if (util.checkNull(perm)) {
shenhailong authored
263 264 265 266 267 268 269 270 271 272 273 274 275
                            _this.departmentIds[v_index] = department.departmentId;
                        }
                    });
                }
                this.getPermList();
            },
            //显示新增界面,每次点开初始化数据
            departmentAdd: function () {
                this.addFormVisible = true;
                this.addForm = {
                    departmentName: '',
                    companyId: ''
                };
276
                this.getCompanylists();
shenhailong authored
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
            },

            //新增
            addSubmit: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗?', '提示', {}).then(() => {
                            this.addLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.addForm);
                            add(para).then((res) => {
                                this.addLoading = false;
                                //NProgress.done();
                                this.$message({
                                    message: '提交成功',
                                    type: 'success'
                                });
                                this.$refs['addForm'].resetFields();
                                this.addFormVisible = false;
                                this.getDepartments();
                            }).catch(error => alert(error));
                        });
                    }
                });
            },
            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗?', '提示', {}).then(() => {
                            this.editLoading = true;
                            let para = Object.assign({}, this.editForm);
                            this.editLoading = false;
                            edit(para).then((res) => {

                                //NProgress.done();
                                this.$message({
                                    message: '提交成功',
                                    type: 'success'
                                });
                                this.$refs['editForm'].resetFields();
                                this.editFormVisible = false;
                                this.getDepartments();
                            }).catch(error => alert(error));
                        });
                    }
                });
            },

            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {
                var ids = this.sels.map(item => item.departmentId).toString();
                console.log(ids);
                this.$confirm('确认删除选中记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
338
                    let para = {ids: ids};
shenhailong authored
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
                    batchRemove(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getDepartments();
                    });
                }).catch(() => {

                });
            }
        },

    }
</script>