<template>
    <div style="overflow-y: auto;">
        <div class="common-card">
            <h3>审批进度</h3>
            <yl-step></yl-step>
        </div>
        <div class="common-card">
            <h3>申请信息</h3>
            <el-form :model="applyForm" ref="applyform" label-width="237px" class="grid-form-class">
            <div class="form-body">
            <div class="flex-css">
                <el-form-item label="明细条数" prop="">
                    <div class="content">
                        {{ number }}
                    </div>
                </el-form-item>
                <el-form-item label="申请人" prop="initr">
                    <div class="content">
                        {{ applyForm.initr }}
                    </div>
                </el-form-item>
                <el-form-item label="申请时间" prop="crteTime">
                    <div class="content">
                        {{ applyForm.crteTime }}
                    </div>
                </el-form-item>
            </div>
            </div>
            </el-form>
        </div>
        <div class="common-card">
            <h3>目录明细</h3>
            <el-table
                v-loading="tableLoading"
                element-loading-text="加载中"
                :data="tableData"
                fit
                stripe
                border
            >
                <template slot="empty">
                    <img src="@/assets/nopage.png" alt />
                    <p>暂无数据</p>
                </template>
                <el-table-column fixed type="index" label="序号" width="60"/>
                <el-table-column label="药品名称" prop="drugName" />
                <el-table-column label="剂型" prop="dosformName" />
                <el-table-column label="规格信息" prop="specName" />
                <el-table-column label="转换比" prop="convrat" />
                <el-table-column label="制剂单位" prop="prepunt" />
                <el-table-column label="包装单位" prop="pacUnt" />
                <el-table-column label="生产企业" prop="prodentpName" />
                <!-- <el-table-column label="限价/参考价" prop="" />
                <el-table-column label="集团价格" prop="" /> -->
                <el-table-column label="药品编码" prop="drugListId" />
                <el-table-column label="基药类型" prop="essdrugType" >
                    <template #default="{ row }">
                        <span v-if="row.essdrugType == '0'">非基药</span>
                        <span v-if="row.essdrugType == '1'">基药</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="挂网类型" prop="pubonlnType" />
                <el-table-column label="目录类型" prop="listType" /> -->
                <el-table-column label="批准文号" prop="aprvNo" />
                <el-table-column label="目录状态" prop="enabFlag" >
                    <template #default="{ row }">
                        <span v-if="row.enabFlag == '0'">启用</span>
                        <span v-if="row.enabFlag == '1'">停用</span>
                    </template>
                </el-table-column>
            </el-table>
            <div class="foot-button" style="margin:30px 0 20px;" v-if="isShow">
                <el-button type="primary" @click="handlePass" :loading="ppLoad">通过</el-button>
                <el-button type="danger" @click="handleNoPass" :loading="nnLoad">驳回</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import ylStep from "@/components/yl-step";
import { getGrpDrugList } from "@/api/drugCataManage/index";
import { apprGrpDrug } from "@/api/approve/index";
    export default {
        components:{
            ylStep
        },
        data() {
            return {
                applyForm:{
                    aa: "9",
                    initr: "",
                    crteTime: "",
                },
                tableLoading: false,
                tableData: [],
                ppLoad: false,
                nnload: false,
                isShow: false,
                number: 0,
                reason: "",
            }
        },
        created () {
            if(this.$route.query.stas == "待审核"){
                this.isShow = true;
            }else{
                this.isShow = false;
            }
            this.applyForm.initr = this.$route.query.initr;
            this.applyForm.crteTime = this.$route.query.crteTime;
        },
        mounted () {
            this.getData();
        },
        methods: {
            getData(){
                this.tableLoading = true;
                getGrpDrugList({drugListId:this.$route.query.sourceId}).then((res) => {
                    this.tableData = res.data.records;
                    this.number = this.tableData.length;
                    this.total = res.data.total;
                    this.tableLoading = false;
                })
                .catch((err) => {
                    this.tableLoading = false;
                });
            },
            // 通过
            handlePass() {
                this.$confirm("确认通过", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    let aa = this.tableData.map((i)=>{
                        return i.drugListId
                    })
                    this.ppLoad = true;
                    let data = {
                        apprStas: "Y",
                        drugId: aa
                    }
                    apprGrpDrug(data).then((res) => {
                        this.ppLoad = false;
                        this.$router.push('approveA')
                    })
                    .catch((err) => {
                        this.ppLoad = false;
                    });
                })
            },
            // 驳回
            handleNoPass() {
                this.$prompt("请输入驳回原因", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                    inputValidator: (value) => {
                    if (!value) {
                        return "驳回原因不能为空";
                    } else {
                        this.reason = value;
                    }
                    },
                }).then(() => {
                    let aa = this.tableData.map((i)=>{
                        return i.drugListId
                    })
                    this.nnLoad = true;
                    let data = {
                        apprStas: "R",
                        drugId: aa,
                        reason: this.reason
                    }
                    apprGrpDrug(data).then((res) => {
                        this.nnLoad = false;
                        this.$router.push('approveA')
                    })
                    .catch((err) => {
                        this.nnLoad = false;
                    });
                })
            }
        },
    }
</script>

<style lang="scss" scoped>

</style>