<template>
  <div class="system-user-container layout-padding">
    <el-card shadow="hover" class="layout-padding-auto">
      <el-page-header style="margin-bottom: 10px" @back="goBack">
        <template #content>
          <div class="rows">
            <el-input v-model="state.contractNumber" size="defalut" placeholder="请输入合同编号" :prefix-icon="Search"
              style="margin-right: 10px" />
            <el-button @click="getTableData" type="primary" plain size="default">查询</el-button>
          </div>
        </template>
        <template #extra>
          <div class="flex items-center">
          </div>
        </template>
      </el-page-header>
      <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="contractNumber" label="合同编号"></el-table-column>
        <el-table-column prop="content" label="预警内容" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="price" label="总价（元）" width="110px">
          <template #default="scope">
            <span>{{ proxy?.$method.numFormat(scope.row.price) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="unitPrice" label="单价（元）" width="110px">
          <template #default="scope">
            <span>{{ proxy?.$method.numFormat(scope.row.houseArea) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="unitPrice" label="均价（元）" width="110px">
          <template #default="scope">
            <span>{{ state.money }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="houseArea" width="110px" label="房屋面积">
          <template #default="scope">
            <span>{{ scope.row.houseArea }}m²</span>
          </template>
        </el-table-column>
        <el-table-column prop="houseAddress" label="房屋地址" width="300px"></el-table-column>
        <!-- <el-table-column prop="buyer" label="买受人" show-overflow-tooltip></el-table-column> -->
        <!-- <el-table-column prop="idCard" label="身份证" width="200px"></el-table-column> -->
        <el-table-column prop="floor" label="楼层">
          <template #default="scope">
            <span>{{ scope.row.floor }}层</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="buildId" label="楼顶ID"> </el-table-column> -->
        <!-- <el-table-column prop="houseId" label="房屋ID"> </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="pricehouse">
import { defineAsyncComponent, reactive, onMounted, ref } from "vue";
import { ElMessageBox, ElMessage, ElNotification } from "element-plus";
import { getprice } from "/@/api/early/price";
import { useRoute, useRouter } from "vue-router";
import { useCurrentInstance } from "/@/method/get";
const { proxy } = useCurrentInstance();
const route = useRoute();
const router = useRouter();
import mittBus from "/@/utils/mitt";
import { Search } from "@element-plus/icons-vue";

// 引入组件

// 定义变量内容
const state = reactive<any>({
  searchname: "",
  money: "",
  uid: "",
  contractNumber: '',
  type: 1,
  tableData: {
    data: [],
    total: 0,
    loading: false,
    param: {
      pageNum: 1,
      pageSize: 10,
    },
  },
});
const goBack = () => {
  router.go(-1);
  mittBus.emit(
    "onCurrentContextmenuClick",
    Object.assign({}, { contextMenuClickId: 1, ...route })
  );
};

// 初始化表格数据
const getTableData = async () => {
  state.tableData.loading = true;
  const data = await getprice().gethouseList({
    page: state.tableData.param.pageNum,
    limit: state.tableData.param.pageSize,
    salePriceProjectId: state.uid,
    contractNumber: state.contractNumber
  });
  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(() => {
  let query = route.query;
  if (!query.id) return router.go(-1);
  state.money = query.money;
  state.uid = query.id;
  getTableData();
});
</script>

<style scoped lang="scss">
.rows {
  display: flex;
  align-items: center;
}

.wgt {
  font-weight: bold;
}

.gr {
  color: rgb(13, 0, 255);
}

.grs {
  color: #d32222;
}

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

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