<template>
    <div class="common-box">
        <el-form :model="listQuery" ref="queryForm" :inline="true">
            <el-form-item label="名称" prop="sourceName">
                <el-input v-model="listQuery.sourceName" placeholder="请输入名称"></el-input>
            </el-form-item>
            <el-form-item label="审批状态" prop="stas">
                <el-select
                    v-model="listQuery.stas"
                    placeholder="请选择审批状态"
                >
                    <el-option
                        v-for="item in stasOptions"
                        :key="item.value"
                        :label="item.name"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="审批类型" prop="bizName">
                <el-select
                    v-model="listQuery.bizName"
                    placeholder="请选择审批类型"
                    clearable
                >
                    <el-option
                        v-for="item in bizOptions"
                        :key="item.value"
                        :label="item.name"
                        :value="item.name"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="发起时间" prop="Time">
                <el-date-picker
                v-model="listQuery.Time"
                type="daterange"
                range-separator="至"
                :editable="false"
                value-format="yyyy-MM-dd"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                style="width: 230px"
                />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="getData('search')">查询 </el-button>
                <el-button @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table
            v-loading="listLoading"
            element-loading-text="加载中"
            :data="list"
            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="sourceId" />
            <el-table-column label="名称" prop="sourceName" />
            <el-table-column label="类型" prop="bizName" />
            <el-table-column label="审批发起人" prop="initr" />
            <el-table-column label="发起时间" prop="crteTime" />
            <el-table-column label="状态" prop="stas" />
            <el-table-column label="操作" width="100">
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        @click="handleDetail(scope.row)"
                        >详情</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
        <!--分页-->
        <yl-pagination
            v-show="total > 0"
            :total="total"
            :page.sync="listQuery.current"
            :limit.sync="listQuery.size"
            @pagination="getData"
        />
    </div>
</template>

<script>
import ylPagination from "@/components/yl-pagination";
import { GetBizQueryByUser } from "@/api/approve/index";
    export default {
        components: {
            ylPagination
        },
        data() {
            return {
                listQuery:{
                    current: 1,
                    size: 10,
                    sourceName: "",
                    stas: "Y",
                    bizName: "",
                    bigenTime: "",
                    endTime: "",
                    Time: [],
                },
                listLoading: false,
                list: [],
                total: 0,
                stasOptions: [
                    {value: "Y", name: "通过"},
                    {value: "R", name: "驳回"},
                ],
                bizOptions: [
                    {value: "0", name: "资质审批"},
                    {value: "1", name: "药品目录审批"},
                    {value: "2", name: "药品采购计划审批"},
                    {value: "3", name: "药品退货审批"},
                    {value: "4", name: "调价申请审批"},
                    {value: "5", name: "申领审批"}
                ]
            }
        },
        methods: {
            getData(type) {
                if (type == "search") {
                    this.listQuery.current = 1;
                }
                // this.list = [{aa:11,bb:"资质审批",cc:"qualificationAppr",dd:"已审批"},
                // {aa:22,bb:"目录审批",cc:"drugCataAppr",dd:"已审批"},{aa:33,bb:"药品采购计划审批",cc:"drugPurchasePlan",dd:"已审批"},
                // {aa:44,bb:"药品退货审批",cc:"drugReturn",dd:"已审批"},{aa:55,bb:"调价申请审批",cc:"priceUpApply",dd:"已审批"},
                // {aa:66,bb:"申领审批",cc:"applyAppr",dd:"已审批"}];
                // this.total = 6;
                this.listLoading = true;
                this.listQuery.bigenTime = this.listQuery.Time[0];
                this.listQuery.endTime = this.listQuery.Time[1];
                GetBizQueryByUser(this.listQuery).then((res) => {
                    this.list = res.data.records;
                    this.total = res.data.total;
                    this.listLoading = false;
                })
                .catch((err) => {
                    this.listLoading = false;
                });
            },
            reset(){
                this.$refs.queryForm.resetFields();
                this.getData();
            },
            // 详情
            handleDetail(row){
                this.$router.push({
                    name: row.route,
                    query: { 
                        sourceId: row.sourceId,
                        initr: row.initr,
                        crteTime: row.crteTime,
                        stas: row.stas
                    },
                });
            },
        },
        mounted () {
            this.getData();
        },
    }
</script>

<style lang="scss" scoped>

</style>