<template>
  <div>
    <el-card shadow="hover" class="layout-padding-auto">
      <div class="system-user-search mb15">
        <el-date-picker size="default" v-model="state.date" type="month" value-format="YYYY-MM" placeholder="请选择日期"
          style="margin-right: 20px" />
        <el-select style="margin-right: 20px" size="default" v-model="state.areaName" class="m-2" placeholder="请选择区县">
          <el-option v-for="item in state.county" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-select size="default" v-model="state.state" class="m-2" placeholder="请选择状态">
          <el-option label="全部" value="" />
          <el-option label="未上传" value="1" />
          <el-option label="已上传" value="2" />
          <el-option label="已退回" value="3" />
        </el-select>
        <el-button @click="getTableData" size="default" type="primary" class="ml10">
          <el-icon>
            <ele-Search />
          </el-icon>
          查询
        </el-button>
      </div>
      <el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%" border stripe
        :cell-style="{ textAlign: 'center' }" :header-cell-style="{ 'text-align': 'center' }">
        <el-table-column prop="date" label="日期"> </el-table-column>
        <el-table-column prop="month" label="月份"> </el-table-column>
        <el-table-column prop="areaCode" label="行政代码"> </el-table-column>
        <el-table-column prop="areaName" label="区县名称"> </el-table-column>
        <el-table-column prop="state" label="状态">
          <template #default="scope">
            <el-tag size="default" v-if="scope.row.state == 2" type="success">已上传</el-tag>
            <el-tag size="default" v-if="scope.row.state == 1" type="info">未上传</el-tag>
            <el-tag size="default" v-if="scope.row.state == 3" type="warning">已退回</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间">
          <template #default="scope">{{ proxy?.$method.formatDate(scope.row.createTime) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" show-overflow-tooltip fixed="right">
          <template #default="scope">
            <el-button size="small" @click="look(scope.row)" text type="primary">
              查看详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
        :pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="state.tableData.param.pageNum" background
        v-model:page-size="state.tableData.param.pageSize" layout="total, sizes, prev, pager, next, jumper"
        :total="state.tableData.total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script setup lang="ts" name="reportrundata">
import { defineAsyncComponent, reactive, onMounted, ref, getCurrentInstance } from "vue";
import { ElMessageBox, ElMessage, ElNotification } from "element-plus";
import { getCons } from "/@/api/report/construct";
import { useCurrentInstance } from '/@/method/get'
const { proxy } = useCurrentInstance()
import { getAll } from "/@/api/sys/index";
import { useRouter } from "vue-router";
const router = useRouter();

const state = reactive<any>({
  date: undefined,
  tableData: {
    data: [],
    county: [],
    total: 0,
    loading: false,
    areaName: "",
    param: {
      pageNum: 1,
      pageSize: 10,
    },
    state: ''
  },
});

const getCodeApi = async () => {
  let item = await getAll().codeApi();
  item.data.unshift({ label: "潍坊市", value: "" });
  state.county = item.data;
  getTableData();
};

// const download = async (row: any) => {
//   // 下载excel
//   let item = await getCons().downloadUrl(row.id);
//   //   proxy.method.download(item, `${row.dates}${row.areaName}建筑报表`);
//   let download: any = await getCons().download(item);
//   let blob = new Blob([download], { type: "application/octet-stream;" });
//   const url = window.URL.createObjectURL(blob);
//   const link = document.createElement("a");
//   link.href = url;
//   link.download = `${row.dates}${row.areaName}建设部报表.xlsx`;
//   document.body.appendChild(link);
//   link.click();
// };
const look = (row: any) => {
  router.push({
    path: "/construct/usdetail",
    query: {
      id: row.id,
      state: row.state,
      tagsViewName: row.areaName + "建设部报表详情"
    },
  });
};
// 初始化表格数据
const getTableData = async () => {
  state.tableData.loading = true;
  // 项目
  const data = await getCons().getList({
    page: state.tableData.param.pageNum,
    limit: state.tableData.param.pageSize,
    date: state.date,
    state: state.state,
    areaCode: state.areaName,
  });
  state.tableData.data = data.data;
  state.tableData.total = data.count;
  state.tableData.loading = false;
};
// 分页改变
const onHandleSizeChange = (val: number) => {
  state.tableData.param.pageSize = val;
  getTableData();
};

// 分页改变
const onHandleCurrentChange = (val: number) => {
  state.tableData.param.pageNum = val;
  getTableData();
};
// 页面加载时
onMounted(() => {
  getCodeApi();
});
</script>

<style scoped lang="scss">
.wgt {
  font-weight: bold;
}

.system-user-container {
  :deep(.el-card__body) {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: auto;

    .el-table {
      flex: 1;
    }
  }
}
</style>
