<template>
    <div class="common-container">
        <TitleBar></TitleBar>
        <div class="main-container">
            <div class="search-container TableSelectMain">
                <el-form class="table-select-main" :model="searchForm" label-position="left">
                    <el-row :gutter="15">
                        <el-col :span="4">
                            <el-form-item>
                                <el-input placeholder="请输入登录手机号" v-model="searchForm.mobile"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-input placeholder="请输入昵称" v-model="searchForm.name"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-select placeholder="请选择状态" v-model="searchForm.checkFlag">
                                    <el-option label="通过" :value="1"></el-option>
                                    <el-option label="驳回" :value="0"></el-option>
                                    <el-option label="待审核" :value="2"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-button type="primary" round @click="querySearch">查询</el-button>
                                <el-button type="primary" plain round @click="reset">重置</el-button>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item>
                                <!-- <el-button
                                    type="primary"
                                    round
                                    icon="el-icon-plus"
                                    @click="showAddEditDialog(null)"
                                >新建</el-button>-->
                                <!-- <el-button type="primary" plain round @click="deleteData(null)">批量删除</el-button> -->
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <div class="SearchTitle">
                已选择
                <span class="subject-color">{{ tableSelection.length }}</span> 项
            </div>
            <div class="MaintenanceTable">
                <el-table
                    ref="multipleTable"
                    :data="tableData"
                    style="width: 100%"
                    tooltip-effect="dark"
                    @selection-change="selectColumn"
                    class="OutTable"
                    border
                    v-loading="listLoading"
                >
                    <el-table-column type="selection"></el-table-column>
                    <el-table-column prop="registMobile" label="登录手机号"></el-table-column>
                    <el-table-column prop="nickname" label="昵称"></el-table-column>
                    <el-table-column prop="age" label="年龄"></el-table-column>
                    <el-table-column prop="gender" label="性别">
                        <template slot-scope="scope">
                            <span v-if="scope.row.gender ===1">男</span>
                            <span v-if="scope.row.gender ===2">女</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="proficiencyBrandName" :show-overflow-tooltip="true" label="擅长品牌"></el-table-column>
                    <el-table-column prop="job" label="工作岗位"></el-table-column>
                    <el-table-column prop="company" label="公司"></el-table-column>
                    <el-table-column prop="workDate" label="从业时长"></el-table-column>
                    <el-table-column prop="professional" label="专业"></el-table-column>
                    <el-table-column prop="checkFlag" label="审核状态">
                        <template slot-scope="scope">
                            <span class="warn" v-if="scope.row.checkFlag == 2">待审核</span>
                            <span class="success" v-if="scope.row.checkFlag == 1">审核通过</span>
                            <span class="warn" v-if="scope.row.checkFlag == 0">已驳回</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" min-width="220px;">
                        <template slot-scope="scope">
                            <!-- <el-button
                                size="mini"
                                type="primary"
                                plain
                                round
                                @click="deleteData(scope.row)"
                            >删除</el-button>-->
                            <!-- <el-button
                                size="mini"
                                type="primary"
                                plain
                                round
                                @click="showAddEditDialog(scope.row)"
                            >编辑</el-button>-->
                            <el-button
                                size="mini"
                                type="primary"
                                plain
                                round
                                :disabled="scope.row.checkFlag === 1 || scope.row.checkFlag === 0 "
                                @click="approvalHandle(scope.row)"
                            >审核</el-button>
                            <el-button
                                size="mini"
                                type="primary"
                                plain
                                round
                                :disabled="scope.row.checkFlag === 1 || scope.row.checkFlag === 0 "
                                @click="rejectHandle(scope.row)"
                            >驳回</el-button>
                            <el-button
                                size="mini"
                                type="primary"
                                plain
                                round
                                @click="showDetails(scope.row)"
                            >详情</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagenation">
                    <PageComponent
                        :total="total"
                        @pagination="handlePagination"
                        :pageSize.sync="page.pageSize"
                        :pageNum.sync="page.pageNum"
                    ></PageComponent>
                </div>
            </div>
        </div>
        <!-- 添加与编辑弹层 -->
        <AddEditDialog ref="addEditDialog" @queryListData="queryListData"></AddEditDialog>
        <!-- 详情弹层 -->
        <DetailsDialog ref="detailsDialog"></DetailsDialog>
        <!-- 审核弹层 -->
        <ApprovalDialog ref="approvalDialog" @queryListData="queryListData"></ApprovalDialog>
    </div>
</template>
<script>
import TitleBar from '@/apps/mobile/components/common/TitleBar';
import AddEditDialog from './components/addEditDialog';
import DetailsDialog from './components/detailsDialog';
import ApprovalDialog from './components/approvalDialog';
import { queryExpertApplyList, deleteApplyExpertSingle, deleteApplyExpertBatch, expertApproval } from '@/apps/mobile/api/expert/index';
export default {
    components: {
        TitleBar,
        AddEditDialog,
        DetailsDialog,
        ApprovalDialog,
    },
    data() {
        return {
            searchForm: {},
            tableData: [],
            page: {
                pageNum: 1,
                pageSize: 5,
            },
            total: 10,
            listLoading: false,
            tableSelection: [],
        };
    },
    created() {
        this.queryListData();
    },
    methods: {
        queryListData() {
            this.listLoading = true;
            let obj = {
                ...this.page,
                ...this.searchForm,
                // checkFlag: 2,
                sort: {
                    order: 'desc',
                    orderBy: 'create_time',
                },
            };
            queryExpertApplyList(obj)
                .then(res => {
                    console.log('res----',res);
                    if(res.statusCode == "10"){
                        this.$router.replace("/login");
                    }
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                    this.listLoading = false;
                })
                .catch(() => {
                    this.listLoading = false;
                });
        },
        deleteData(data) {
            if (data) {
                this.$confirm(' 是否删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                })
                    .then(() => {
                        deleteApplyExpertSingle(data.id)
                            .then(res => {
                                this.queryListData();
                                this.$message({
                                    type: 'success',
                                    message: '删除成功',
                                });
                            })
                            .catch();
                    })
                    .catch(() => {});
            } else {
                if (this.tableSelection.length == 0) {
                    this.$message({
                        type: 'warning',
                        message: '请先选择一个',
                    });
                    return false;
                }
                this.$confirm('是否删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                })
                    .then(() => {
                        let ids = this.tableSelection.map(item => {
                            return item.id;
                        });
                        deleteApplyExpertBatch(ids)
                            .then(res => {
                                this.queryListData();
                                this.$message({
                                    type: 'success',
                                    message: '删除成功',
                                });
                            })
                            .catch();
                    })
                    .catch(() => {});
            }
        },
        approvalHandle(data) {
            this.$refs.approvalDialog.open(data);
        },
        rejectHandle(data) {
            this.$confirm('是否驳回?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    let obj = {
                        checkFlag: 0,
                        id: data.id,
                    };
                    this.approval(obj);
                })
                .catch(() => {});
        },
        approval(obj) {
            expertApproval(obj)
                .then(res => {
                    console.log(res);
                    if (res.statusCode === '1') {
                        this.$message({
                            type: 'success',
                            message: res.message,
                        });
                    } else {
                        this.$message({
                            type: 'warning',
                            message: res.message,
                        });
                    }
                    this.queryListData();
                })
                .catch();
        },
        querySearch() {
            this.page.pageNum = 1;
            this.queryListData();
        },
        reset() {
            this.searchForm = {};
            this.page.pageNum = 1;
            this.queryListData();
        },
        selectColumn(selection) {
            this.tableSelection = selection;
        },
        handSizeChange() {},
        // 页码变化时
        handlePagination(val) {
            this.page = val;
            this.queryListData();
        },
        showAddEditDialog(data) {
            if (data) {
                this.$refs.addEditDialog.open('edit', data);
            } else {
                this.$refs.addEditDialog.open('add');
            }
        },
        showDetails(data) {
            this.$refs.detailsDialog.open(data);
        },
    },
};
</script>
<style lang="stylus" scoped>
.TableSelectMain .el-date-editor.el-input.el-input--prefix.el-input--suffix.el-date-editor--date {
    width: 95%;
}
</style>
