Location.vue 15.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.processName" placeholder="公寓名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="getList()">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleAdd()">新增</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <el-table
                :data="locationList"
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                border
                :row-class-name="tableRowClassName"
                default-expand-all
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
            <el-table-column
                    prop="adrname"
                    label="名称"
                    sortable
                    width="300">
            </el-table-column>
            <el-table-column
                    prop="type"
                    label="类型"
                    align="center"
                    :formatter="formatType"
                    width="100">
            </el-table-column>
            <el-table-column :label="$t('table.actions')" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="primary" size="small" @click="handleUpdate(scope.row)">快速编辑</el-button>
                    <el-button type="primary" size="small" @click="handleUpdate(scope.row)">新增</el-button>
                    <el-button size="mini" type="danger" @click="handleModifyStatus(scope.row,'deleted')">{{ $t('table.delete') }}</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="prev, pager, next" @current-change="handleCurrentChange" :page-size="5" :total="total" style="float:right;">
            </el-pagination>
        </el-col>
    </section>
</template>
<style>
    .el-table .building {
        background: oldlace;
    }

    .el-table .floor {
        background: #f0f9eb;
    }

    .el-table .house {
        background: #99CCCC;
    }
</style>
<script>
    import { getList,add} from '@/api/empt/location_api';
    import moment from 'moment'
    import parseTime from '@/utils'
    import loginUserInfo from '@/api/base'

    export default {
        data() {
            return {
                filters: {
                    processName: '',
                    parseTime: parseTime
                },
                locationList:[],
                total: 0,
                pageNum: 1,
                pageSize: 5,
                listLoading: false,
                sels: [],//列表选中列
                //编辑界面是否显示
                editFormVisible: false,
                editLoading: false,
                editFormRules: {
                    roleName: [
                        { required: true, message: '请输入岗位/角色名称', trigger: 'blur' }
                    ]
                },
                //编辑界面数据
                editForm: {
                    roleId: 1,
                    description: '',
                    roleName: '',
                    roleSign: 1,
                    departmentId:''
                },
                //用户ID
                //新增界面是否显示
                addFormVisible: false,
                //设置权限界面是否显示
                addLoading: false,
                addFormRules: {
                    roleName: [
                        { required: true, message: '请输入岗位/角色名称', trigger: 'blur' }
                    ],
                    description: [
                        { required: true, message: '请输入岗位/角色描述', trigger: 'blur' }
                    ]
                },
                //新增界面数据
                addForm: {
                    processname: '',
                    begindate: '',
                    enddate: '',
                    vacationtype:'',
                    reason: '',
                    userId: ''
                },
                permForm: {
                    roleId: 1,
                    description: '',
                    roleName: '',
                    roleSign: 1,
                    permissions: []
                },
                centerDialogVisible: false,
                dialogData:{
                    process:{
                        processname: ''
                    }
                },
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() < Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                options:[{
                    value: '1',
                    label: '测试公司',
                    children: [{
                        value: '2',
                        label: '测试部门一',
                        children: [{
                            value: '1',
                            label: '测试岗位1',
                            children: [{
                                value: '1',
                                label: '测试人员1'
                            }]
                        }]
                    }, {
                        value: '3',
                        label: '测试部门二',
                        children: [{
                            value: '2',
                            label: '测试岗位2',
                            children: [{
                                value: '1',
                                label: '测试人员2'
                            }]
                        }, {
                            value: '3',
                            label: '测试岗位3',
                            children: [{
                                value: '1',
                                label: '测试人员3'
                            }]
                        }]
                    }]
                }],
            }
        },
        methods: {
            //性别显示转换
            formatType: function (row, column) {
                let msg = '未知';
                switch (row.type){
                    case 0:
                        msg='公寓';
                        break;
                    case 1:
                        msg='楼';
                        break;
                    case 2:
                        msg='层';
                        break;
                    case 3:
                        msg='门牌';
                        break;
                }
                return msg;
            },
            handleCurrentChange(val) {
                this.pageNum = val;
            },
            //获取列表
            getList() {
                let para = {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                };
                this.listLoading = true;
                //NProgress.start();
                getList(para).then((res) => {
                    let resData = res.data.data;
                    this.total = resData.total;
                    this.locationList = resData.list;
                    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 = { roleId: row.roleId };
                    remove(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                    }).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.getdepartmentNames();
            },
            //显示新增界面,每次点开初始化数据
            handleAdd: function () {
                this.addFormVisible = true;
                this.addForm =  {
                        processname: '',
                        begindate: '',
                        enddate: '',
                        vacationtype:'',
                        reason: '',
                        userid: loginUserInfo.userId
                }
            },
            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗?', '提示', {}).then(() => {
                            this.editLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.editForm);
                            //不需要提交的 去掉,后端不好接收
                            para.authorities = null;
                            para.permissions = null;
                            para.roles = null;
//							para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
                            /*
        					查询之后格式this.filters.column.create_start_date中日期发生变化;
        					Wed Aug 09 2017 00:00:00 GMT+0800 (中国标准时间) 变成了 "2017-08-08T16:00:00.000Z";
        					所以使用 moment 日期格式化插件将时间转换成 [ Wed Aug 09 2017 00:00:00 GMT+0800 (中国标准时间) ] 格
        					式;
    						*/
                            /*moment 安装 npm install moment --save*/
                            para.creattime = moment(para.creattime).format('YYYY-MM-DD HH:mm:ss');
                            this.editLoading = false;
                            edit(para).then((res) => {

                                //NProgress.done();
                                this.$message({
                                    message: '提交成功',
                                    type: 'success'
                                });
                                this.$refs['editForm'].resetFields();
                                this.editFormVisible = false;
                            }).catch(error => alert(error));
                        });
                    }
                });
            },
            //新增
            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;
                                if (res.status ===200) {
                                    this.$message({
                                        message: '提交成功',
                                        type: 'success'
                                    });
                                    this.$refs['permForm'].resetFields();
                                    this.addFormVisible = false;
                                    this.getProcessList();
                                }
                            }).catch(error => alert(error));
                        });
                    }
                });
            },
            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {
                var ids = this.sels.map(item => item.roleId).toString();
                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'
                        })
                    });
                }).catch(() => {

                });
            },
            tableRowClassName({row, rowIndex}) {
                let type = row.type;
                if (type === 1) {
                    return 'building';
                } else if (type === 2) {
                    return 'floor';
                } else if (type === 3){
                    return 'house';
                }
                    return '';
            },
            handleSelectionChange(val) {
                this.multipleSelection = val
            }
        },
        mounted() {
            this.getList();
        }
    }

</script>

<style scoped>

</style>