<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="请输入专家ID" v-model="searchForm.chargeId"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-input placeholder="请输入处罚标题" v-model="searchForm.title"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-input placeholder="请输入处罚金额" v-model="searchForm.punishAmount"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-select placeholder="请选择状态" v-model="searchForm.statuz">
                                    <el-option label="已撤销" :value="1"></el-option>
                                    <el-option label="已处罚" :value="0"></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-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="chargeId" label="专家ID"></el-table-column>
                    <el-table-column prop="title" label="处罚标题" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="punishAmount" label="处罚金额"></el-table-column>
                    <el-table-column prop="picUrl" label="图片">
                        <template slot-scope="scope">
                            <span v-if="scope.row.picUrl" @click="imgOpen(scope.row.picUrl)">
                            <el-image                                
                                :src="scope.row.picUrl | pathPipe"
                                style="width:40px;height:40px;cursor:pointer"
                                fit="cover"
                            ></el-image>
                            </span>
                            <span v-else>暂无图片</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="statuz" label="处罚状态">
                        <template slot-scope="scope">
                            <span class="warn" v-if="scope.row.statuz == 1">已撤销</span>
                            <span class="success" v-if="scope.row.statuz == 0">已处罚</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="des" label="描述" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column label="操作" min-width="220px;">
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="primary"
                                plain
                                round
                                :disabled="scope.row.statuz === 1 "
                                @click="cancelHandle(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>
    </div>
</template>
<script>
import TitleBar from '@/apps/mobile/components/common/TitleBar';
import { queryExpertPunishmentList, cancelPunishment } from '@/apps/mobile/api/expert/index';
export default {
    components: {
        TitleBar,
    },
    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',
                },
            };
            queryExpertPunishmentList(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.tableData.forEach(item => {
                        item.picUrl = item.picUrl.split(',');
                    });
                    this.listLoading = false;
                })
                .catch(() => {
                    this.listLoading = false;
                });
        },
        cancelHandle(data) {
            console.log(data);
            this.$confirm('确定撤销处罚吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    cancelPunishment({ids: [data.id]})
                        .then(() => {
                            this.$message.success('撤销成功');
                            this.queryListData();
                        })
                        .catch(() => {});
                })
                .catch(() => {});
        },
        querySearch() {
            this.queryListData();
        },
        reset() {
            this.searchForm = {};
            this.page.pageNum = 1;
            this.queryListData();
        },
        selectColumn(selection) {
            this.tableSelection = selection;
        },
        handSizeChange() {},
        // 页码变化时
        handlePagination(val) {
            this.page = val;
            this.queryListData();
        },
        imgOpen(imgs){
            window.open(imgs);
        }
    },
};
</script>
<style lang="stylus" scoped>
.TableSelectMain .el-date-editor.el-input.el-input--prefix.el-input--suffix.el-date-editor--date {
    width: 95%;
}
</style>
