<template>
  <div class="system-user-container layout-padding">
    <el-card shadow="hover" class="layout-padding-auto">
      <div class="system-user-search mb15">
        <el-input size="default" v-model="state.number" placeholder="请输入期数" style="max-width: 180px" clearable>
        </el-input>
        <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="year" label="年份"></el-table-column> -->
        <el-table-column prop="date" label="报告日期"></el-table-column>
        <el-table-column prop="number" label="期数">
          <template #default="scope">
            第 {{ scope.row.number }} 期
          </template>
        </el-table-column>
        <el-table-column prop="dateInterval" label="日期区间" width="180"></el-table-column>
        <el-table-column prop="saleCount" label="住宅销售套数">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.saleCount) }} 套
          </template>
        </el-table-column>
        <el-table-column prop="saleArea" label="住宅销售面积（㎡）">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.saleArea) }}
          </template>
        </el-table-column>
        <el-table-column prop="saleUnivalent" label="销售均价">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.saleUnivalent) }}
          </template>
        </el-table-column>
        <el-table-column prop="outProportion" label="外地购房比例"></el-table-column>
        <el-table-column label="操作" show-overflow-tooltip width="100" fixed="right">
          <template #default="scope">
            <el-button size="small" @click="lookpdf(scope.row)" text type="primary">查看PDF</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>
    <dialogCon ref="dialogConRef" @refresh="getTableData()" />
  </div>
</template>

<script setup lang="ts" name="reportrundata">
import { defineAsyncComponent, reactive, onMounted, ref } from "vue";
import { ElMessageBox, ElMessage, ElNotification } from "element-plus";
import { getrundata } from "/@/api/report/rundata";
import { useCurrentInstance } from '/@/method/get'
const { proxy } = useCurrentInstance()
// 引入组件
const dialogCon = defineAsyncComponent(
  () => import("/@/views/report/rundata/dialog.vue")
);

// 定义变量内容
const dialogConRef = ref();

// 定义变量内容
const state = reactive<any>({
  number: "",
  tableData: {
    data: [],
    total: 0,
    loading: false,
    param: {
      pageNum: 1,
      pageSize: 10,
    },
  },
});

const lookpdf = (row: any) => {
  // 查看PDF
  dialogConRef.value.openDialog(row);
};

// 初始化表格数据
const getTableData = async () => {
  state.tableData.loading = true;
  // 项目
  const data = await getrundata().getList({
    page: state.tableData.param.pageNum,
    limit: state.tableData.param.pageSize,
    number: state.number,
  });
  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(() => {
  getTableData();
});
</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>
