company.vue 14.1 KB
<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.companyName" placeholder="公司名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="getCompanys()">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="companyAdd">新增</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
        <el-table :data="companyList" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column type="index">
            </el-table-column>
            <el-table-column prop="companyId" label="ID" sortable>
            </el-table-column>
            <el-table-column prop="companyName" label="公司名称"  sortable>
            </el-table-column>
            <el-table-column prop="groupName" label="集团名称"  sortable>
            </el-table-column>
            <el-table-column prop="creatTime" label="入库时间"  sortable>
            </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>
            <el-pagination layout="total, prev, pager, next" @current-change="handleCurrentChange" :page-size="5" :total="total" style="float:right;">
            </el-pagination>
        </el-col>

        <!--编辑界面-->
        <el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false">
            <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
                <el-form-item label="ID">
                    <span>{{editForm.companyId}}</span>
                </el-form-item>
                <el-form-item label="公司名称">
                    <el-input v-model="editForm.companyName" auto-complete="off" placeholder="请输入公司名称"></el-input>
                </el-form-item>
                <el-form-item label="集团名称">
                    <el-select v-model="editForm.groupId" placeholder="请选择">
                        <el-option
                                v-for="item in groupLists"
                                :key="item.groupId"
                                :label="item.groupName"
                                :value="item.groupId">
                        </el-option>
                    </el-select>
                </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>

        <!--新增界面-->
        <el-dialog title="新增" :visible.sync="addFormVisible" :close-on-click-modal="false">
            <el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm">
                <el-form-item label="公司名称" prop="companyName">
                    <el-input v-model="addForm.companyName" auto-complete="off" placeholder="请输入公司名称"></el-input>
                </el-form-item>
                <el-form-item label="集团名称" prop="groupId">
                    <el-select v-model="addForm.groupId" placeholder="请选择">
                        <el-option
                                v-for="item in groupLists"
                                :key="item.groupId"
                                :label="item.groupName"
                                :value="item.groupId">
                        </el-option>
                    </el-select>
                </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'
    import { getList, remove, batchRemove, edit, add } from '../../api/company';
    import { getList as groupList } from '../../api/group_company';
    import moment from 'moment'

    export default {
        data() {
            return {
                filters: {
                    companyName: ''
                },
                companyList: [],
                // 接受集团名称
                groupLists:[],
                permIds: [],
                total: 0,
                pageNum: 1,
                pageSize: 5,
                listLoading: false,
                sels: [],//列表选中列
                //编辑界面是否显示
                editFormVisible: false,
                editLoading: false,
                editFormRules: {
                    companyName: [
                        { required: true, message: '请输入公司名称', trigger: 'blur' }
                    ]
                },
                //编辑界面数据
                editForm: {
                    companyId: '',
                    companyName: '',
                    groupId: ''
                },
                //设置权限数据
                setPermForm: {},
                //新增界面是否显示
                addFormVisible: false,
                //设置权限界面是否显示
                PermFormVisible: false,
                addLoading: false,
                addFormRules: {
                    companyName: [
                        { required: true, message: '请输入公司名称', trigger: 'blur' }
                    ]
                },

                //新增界面数据
                addForm: {
                    companyName: '',
                    groupId: ''
                },
                companyFrom: {
                    companyId: 1,
                    companyName: '',
                    companys: []
                }

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

            handleCurrentChange(val) {
                this.pageNum = val;
                this.getRoles();
            },
            //获取公司列表
            getCompanys() {
                let para = {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    companyName: this.filters.companyName
                };
                this.listLoading = true;
                //NProgress.start();
                getList(para).then((res) => {
                    this.total = res.data.total;
                    this.companyList = res.data.list;
                    console.log(this.companyList);
                    this.listLoading = false;
                    //NProgress.done();
                }).catch((error) => {

                    this.listLoading = false;
                    if(null!= error.response && error.response!==undefined){
                        let status= error.response.status;
                        let msg = error.response.statusText;
                        alert(status+msg);
                    }else {
                        alert(error);
                    }

                });

            },

            //获取集团列表
            getGroupComapnys() {

                this.listLoading = true;
                //NProgress.start();
                groupList().then((res) => {
                    this.total = res.data.total;
                    this.groupLists = res.data.list;
                    console.log(this.companyList);
                    this.listLoading = false;
                    //NProgress.done();
                }).catch((error) => {

                    this.listLoading = false;
                    if(null!= error.response && error.response!==undefined){
                        let status= error.response.status;
                        let msg = error.response.statusText;
                        alert(status+msg);
                    }else {
                        alert(error);
                    }

                });

            },

            //删除
            handleDel: function (index, row) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    let para = { companyId: row.companyId };
                    remove(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getCompanys();
                    }).catch((error) => {
                        this.listLoading = false;
                        alert(error);
                    });
                }).catch();
            },
            /**
             * 显示编辑界面
             * @param index
             * @param row 为这行的数据对象
             */
            handleEdit: function (index, row) {
                this.editFormVisible = true;
                this.editForm = Object.assign({}, row);
                this.getGroupComapnys();
            },
            setPerm: function (index, row) {
                var _this = this;
                this.companyIds = [];
                this.PermFormVisible = true;
                this.companyFrom = Object.assign({}, row);
                let rolePerms = this.companyFrom.companys;
                if (util.checkNull(rolePerms)){
                    rolePerms.forEach(function (company,v_index,v_arr) {
                        if(util.checkNull(perm)){
                            _this.companyIds[v_index] = company.companyId;
                        }
                    });
                }
                this.getPermList();
            },
            //显示新增界面,每次点开初始化数据
            companyAdd: function () {
                this.addFormVisible = true;
                this.addForm = {
                    companyName: '',
                    groupId: ''
                };
                this.getGroupComapnys();
            },

            //新增
            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.getCompanys();
                            }).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.getCompanys();
                            }).catch(error => alert(error));
                        });
                    }
                });
            },

            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {
                var ids = this.sels.map(item => item.companyId).toString();
                console.log(ids);
                this.$confirm('确认删除选中记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    let para = { ids: ids };
                    batchRemove(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getCompanys();
                    });
                }).catch(() => {

                });
            }
        },

    }
</script>