<template>
    <el-card class="tjm_card_style_custom">
        <div class="tjm_card_title">条件检索</div>
        <div class="tjm_card_select">
            <el-form class="tjm_card_select_left" :model="params" inline label-width="80px" label-position="left">
                <el-form-item label="项目名称">
                    <el-input v-model="params.name" clearable placeholder="请输入项目名称"></el-input>
                </el-form-item>
                <el-form-item label="填报日期">
                    <el-date-picker v-model="createTime" type="daterange" value-format="YYYY-MM-DD" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="search" @click="reloadTable">搜索</el-button>
                    <el-button icon="refresh-right" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-divider></el-divider>

        <div class="tjm_card_tools">
            <div class="tjm_card_tools_left">
                <el-button type="primary" icon="tools" @click="$emit('condition_set')">设置应填报日期</el-button>
            </div>
            <div class="tjm_card_tools_right">
                <el-button icon="download" @click="table_export">导出</el-button>
            </div>
        </div>

        <div class="tjm_card_table">
            <el-table v-loading="loading" row-key="id" header-cell-class-name="tjm_card_table_header" height="400" :data="tableData" border @row-click="table_detail">
                <el-table-column type="index" label="序号" width="55"></el-table-column>
                 <template v-for="(item, index) in columns" :key="index">
                    <el-table-column :label="item.label" :prop="item.props" :min-width="item.width || 180" show-overflow-tooltip>
                        <template #default="scope">{{ columnFormat(scope.row, item.props) }}</template>
                    </el-table-column>
                </template>
                <el-table-column label="操作" fixed="right" width="100">
                    <template #default="scope">
                        <el-button type="primary" link icon="tickets" @click.stop="table_detail(scope.row)">查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="tjm_card_pagination">
            <yh-pagination v-model:pageNo="params.page" v-model:pageSize="params.size" :total="total" @paginationChange="reloadTable"></yh-pagination>
        </div>
    </el-card>
</template>

<script>
import API from "@/api/policy/progress";
import { columns } from "@/views/progress/main";
import yhPagination from "@/components/Pagination/index.vue";

export default {
    components: {
        yhPagination
    },

    data() {
        return {
            columns,

            loading: false,
            params: {
                page: 1,
                size: 10
            },

            total: 0,
            tableData: []
        }
    },

    mounted() {
        this.reloadTable();
    },

    methods: {
        columnFormat(row, props) {
            if (props == "ytbDate") return "ytbDate";
            return row[props];
        },

        reloadTable() {
            this.loading = true;
            API.progress.strive(this.params).then(res => {
                this.loading = false;
                this.tableData = res.data.records;
                this.total = res.data.total;
            }).catch(() => this.loading = false);
        },

        table_detail(row) {
            // this.$emit("table_detail", );
        }
    }
}
</script>

<style lang="scss" scoped>
.tjm_card_style_custom {
  border: none;
  box-shadow: 0 0;

  :deep(.el-card__body) {
    padding-top: 10px;

    .tjm_card_table {
      margin-top: 0;
    }
  }
}
</style>