<template>
  <div class="system-user-container layout-padding">
    <el-card shadow="hover" class="layout-padding-auto">
      <div class="system-user-search mb15">
        <el-date-picker size="default" v-model="state.number" value-format="YYYY-MM" type="month" placeholder="选择月份" />
        <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="years" label="年份" />
        <el-table-column prop="month" label="月份" />
        <el-table-column prop="count" label="区县上传数量"></el-table-column>
        <el-table-column prop="approveArea" label="批售面积（㎡）">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.approveArea) }}
          </template>
        </el-table-column>
        <el-table-column prop="resApproveArea" label="批售住宅面积（㎡）">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.resApproveArea) }}
          </template>
        </el-table-column>
        <el-table-column prop="resApproveCount" label="批售住宅套数">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.resApproveCount) }}套
          </template>
        </el-table-column>
        <el-table-column prop="inventoryTotalArea" label="商品房库存面积(㎡)">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.inventoryTotalArea) }}
          </template>
        </el-table-column>
        <el-table-column prop="resInventoryTotalCount" label="商品房库存总套数">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.resInventoryTotalCount) }}套
          </template>
        </el-table-column>
        <el-table-column prop="outProportion" label="外地人购房比例">
          <template #default="scope">
            {{ proxy?.$method.numFormat(scope.row.outProportion) }}%
          </template>
        </el-table-column>
        <el-table-column label="操作" show-overflow-tooltip width="100" 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>
    <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 { getmonth } from "/@/api/report/month";
import { useCurrentInstance } from '/@/method/get'
const { proxy } = useCurrentInstance()
import { useRouter } from "vue-router";
let router = useRouter();

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

const look = (row: any) => {
  router.push({
    path: '/report/monthDeatil',
    query: {
      id: row.id,
      tagsViewName: row.years + '-' + row.month + "详情"
    }
  });
}

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