<template>
    <div class="list-view">
        <div class="filters-container">
            <!-- <el-input placeholder="输入关键字" v-model="search" clearable class="filter-item"></el-input>
            <el-button @click="getData" type="primary" icon="el-icon-search" class="filter-item">搜索 </el-button> -->
            <el-form :form="form" inline size="mini" label-width="60px">
                <el-form-item label="姓名">
                    <el-input v-model="form.nickname" placeholder="请输入姓名"></el-input>
                </el-form-item>
                <el-form-item label="单位">
                    <el-input v-model="form.work" placeholder="请输入单位"></el-input>
                </el-form-item>
                <el-form-item label="职称">
                    <el-input v-model="form.position" placeholder="请输入职称"></el-input>
                </el-form-item>
                <el-form-item label="专家">
                    <el-cascader
                        ref="artCascader"
                        style="width: 100%"
                        v-model="form.specialtyId"
                        :props="optionProps"
                        :options="artTypes"
                        :show-all-levels="false"
                        placeholder="请选择专业"
                        clearable
                    >
                    </el-cascader>
                </el-form-item>
            </el-form>
        </div>
        <el-table
            :data="tableData"
            row-key="id"
            ref="table"
            height="tableHeight"
            header-row-class-name="table-header-row"
            header-cell-class-name="table-header-cell"
            row-class-name="table-row"
            cell-class-name="table-cell"
        >
            <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
            <!-- <el-table-column prop="id" label="ID" width="100"> </el-table-column> -->
            <!-- <el-table-column prop="username" label="用户名" min-width="300"> </el-table-column> -->
            <el-table-column prop="nickname" label="姓名"> </el-table-column>
            <el-table-column prop="phone" label="手机号"></el-table-column>
            <el-table-column prop="artType" label="专业"></el-table-column>
            <el-table-column prop="work" label="单位"></el-table-column>
            <el-table-column prop="position" label="职称"></el-table-column>
            <!-- <el-table-column label="操作" align="center" fixed="right" min-width="150">
                <template slot-scope="{ row }">
                    <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>
                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button>
                </template>
            </el-table-column> -->
        </el-table>
        <div class="pagination-wrapper">
            <div class="multiple-mode-wrapper">
                <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)">选择专家</el-button>
                <el-button-group v-else>
                    <el-button @click="operation1">选择</el-button>
                    <!-- <el-button @click="operation2">批量操作2</el-button> -->
                    <el-button @click="toggleMultipleMode(false)">取消</el-button>
                </el-button-group>
            </div>
            <el-pagination
                background
                @size-change="onSizeChange"
                @current-change="onCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 30, 40, 50]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalElements"
            >
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { mapState } from 'vuex';
import pageableTable from '@/mixins/pageableTable';
import ClipboardJS from 'clipboard';
import delChild from '@/mixins/delChild';
const clickData = {};
export default {
    mixins: [pageableTable, delChild],
    data() {
        return {
            multipleMode: false,
            search: '',
            url: '/user/all1',
            downloading: false,
            form: {},
            optionProps: {
                value: 'id',
                label: 'name',
                children: 'children',
                multiple: false,
                emitPath: false,
                checkStrictly: true,
                expandTrigger: 'hover'
            },
            artTypes: []
        };
    },
    created() {
        this.$http
            .post('/artType/allList')
            .then(res => {
                this.artTypes = this.delChild(res);
            })
            .catch(e => {
                console.log(e);
            });
    },
    computed: {
        ...mapState([]),
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            // if (this.search) {
            //     return { search: this.search };
            // }
            let data = { query: {} };
            if (this.form.nickname) {
                data.query.nickname = this.form.nickname;
            }
            return data;
        },
        toggleMultipleMode(multipleMode) {
            this.multipleMode = multipleMode;
            if (!multipleMode) {
                this.$refs.table.clearSelection();
            }
        },
        addRow() {
            this.$router.push({
                path: '/expertEdit',
                query: {
                    ...this.$route.query
                }
            });
        },
        editRow(row) {
            this.$router.push({
                path: '/expertEdit',
                query: {
                    id: row.id
                }
            });
        },
        operation1() {
            // this.$notify({
            //     title: '提示',
            //     message: this.selection
            // });
            this.$alert('确认分配评委吗？', '提示', { type: 'primary' })
                .then(() => {
                    // return this.$http.post(`/performance/del/${row.id}`);
                })
                .then(() => {
                    this.$message.success('分配成功');
                    toggleMultipleMode(false);
                })
                .catch(e => {
                    if (e !== 'cancel') {
                        this.$message.error(e.error);
                    }
                });
        },
        operation2() {
            this.$message('操作2');
        }
    }
};
</script>
<style lang="less" scoped></style>
