<template>
    <div class="main-content12 recharge-wrap">
        <div class="flex-common">
            <el-form class="mt24">
                <div class="flex-between">
                    <div class="flex filter-area">
                        <label for="">收录申请</label>
                        <GuipSelect width="150px" clearable label="状态" :options="['麻辣烫','提拉米苏']" v-model="review_status" />
                        <GuipSelect width="150px" clearable label="学历" :options="['麻辣烫','提拉米苏']" v-model="degree" />
                        <GuipInput ref="GuipInput" label="学校" placeholder="输入学校名称" v-model="school" />
                    </div>
                    <GuipButton>收录成功通知</GuipButton>
                </div>
                <GuipTable :tableData="tableList" :key="tableKey" ref="multipleTable" autoColumn="true" :loading="tableLoading" style="flex:1">
                    <template>
                        <el-table-column fixed="left" prop="school_name" label="学校" min-width="200"></el-table-column>
                        <el-table-column prop="degree_name" label="学历" min-width="200"></el-table-column>
                        <el-table-column prop="college_name" label="学院" min-width="200"></el-table-column>
                        <el-table-column prop="review_status_desc" label="要求" min-width="200"></el-table-column>
                        <el-table-column prop="review_status_desc" label="论文" min-width="200"></el-table-column>
                        <el-table-column prop="review_status_desc" label="上传时间" min-width="200"></el-table-column>
                        <el-table-column prop="review_status_desc" label="状态" min-width="200"></el-table-column>
                        <el-table-column fixed="right" prop="tid" label="操作" min-width="100">
                            <template slot-scope="scope">
                                <div class="flex">
                                    <GuipButton type="text" @click="handleConfirm(scope.row.id)">收录</GuipButton>
                                    <GuipButton type="text" @click="handleRefuse(scope.row)">拒绝</GuipButton>
                                </div>
                            </template>
                        </el-table-column>
                    </template>
                </GuipTable>
                <el-pagination background @size-change='handleSizeChange' @current-change='handleCurrentChange'
                               :current-page="currentPage" :page-size=pageSize layout="prev, pager, next,jumper"
                               :total="parseInt(total)">
                </el-pagination>
            </el-form>
        </div>

        <GuipDialog :dialogVisible="isShowDialog" title="拒绝收录原因" :show-close-button="false"
                    :show-cancel-button="true" @confirm="handleConfirmRefuse" @cancel="handleCancelRefuse">
            <!-- 自定义内容 -->
            <el-form>
                <GuipTextarea :label="'拒绝收录'+tpl_name+'模板'" :styleObject="{ width: '450px' }" placeholder="说明原因，发送短信给用户手机" autosize v-model="refuse_reason" />
            </el-form>
        </GuipDialog>

    </div>
</template>
<script>


import GuipButton from "@/components/GuipButton.vue";
import GuipTable from "@/components/GuipTable.vue";
import GuipSelect from "@/components/GuipSelect.vue";
import GuipInput from "@/components/GuipInput.vue";
import GuipDialog from "@/components/GuipDialog.vue";
import GuipTextarea from "@/components/GuipTextarea.vue";

export default {
    components: {
        GuipTextarea,
        GuipDialog,
        GuipInput, GuipSelect,
        GuipTable,
        GuipButton,

    },
    options: { styleIsolation: "shared" },
    data() {
        return {
            tableLoading:false,
            tableKey: '',

            school:'',
            degree:'',
            review_status: -1,

            tableList:[],
            currentPage: 1,    //当前页
            pageSize: 20,   //每页的容量
            total: 0,   //列表总数

            isShowDialog:false,
            refuse_id:0,
            tpl_name:'',
            refuse_reason:''
        }
    },
    mounted() {
        this.$nextTick(()=>{
            this.init()
        })
    },
    methods: {
        init(){
            this.tableList = []
            this.total = 0
            this.total_money = 0
            this.currentPage = 1
            this.pageSize = 20
            this.getList()
        },
        getList() {
            try {
                this.$http('POST', '/supernew/ajax_get_paiban_review_list', {
                    school: this.school,
                    degree: this.degree,
                    review_status: this.review_status,
                    page: this.currentPage,
                }).then(response => {
                    this.$nextTick(() => {
                        this.tableList = response.data.list
                        this.total = response.data.count
                    })
                }).catch(error => {
                    console.error(error, 'error')
                })
            } catch (error) {
                console.error('数据加载失败:', error)
            }
        },
        handleSizeChange(val) {
            this.pageSize = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.getList()
        },
        handleConfirm(id){
            console.log(id)
            this.isShowDialog = false
            try {
                this.$http('POST', '/supernew/ajax_update_paiban_template_review_status', {
                    template_id: id,
                    review_status: 1,
                }).then(response => {
                    this.$nextTick(() => {
                        if (response.status) {
                            this.$Message.success(response.info);
                            this.getList()
                        } else {
                            this.$Message.error(response.info);
                        }
                    })
                }).catch(error => {
                    console.error(error, 'error')
                })
            } catch (error) {
                console.error('数据加载失败:', error)
            }
        },
        handleRefuse(row){
            this.isShowDialog = true
            this.refuse_id = row.id
            this.tpl_name += row.school_name
            if(row.degree_name) this.tpl_name += '-'+row.degree_name
            if(row.college_name) this.tpl_name += '-'+row.college_name
        },
        handleCancelRefuse(){
            this.isShowDialog = false
        },
        handleConfirmRefuse(){
            try {
                this.$http('POST', '/supernew/ajax_update_paiban_template_review_status', {
                    template_id: this.refuse_id,
                    review_status: 3,
                    refuse_reason: this.refuse_reason
                }).then(response => {
                    this.$nextTick(() => {
                        this.isShowDialog = false;
                        if (response.status) {
                            this.$Message.success(response.info);
                            this.getList()
                        } else {
                            this.$Message.error(response.info);
                        }
                    })
                }).catch(error => {
                    console.error(error, 'error')
                })
            } catch (error) {
                console.error('数据加载失败:', error)
            }
        },
    }
}

</script>
<style lang="scss" scoped>
::v-deep .el-form-item{
  margin: 0;
}
::v-deep .el-form-item__label{
  margin-bottom: 12px;
}

.filter-area{
  margin-bottom: 20px;
  gap: 32px;
  label{
    letter-spacing: 0.08em;
    font-size: 14px;
    font-weight: bold;
    line-height: normal;
    color: #1E2226;
  }
}
</style>