<template>
  <div class="home-container layout-pd">

    <el-row :gutter="15" class="home-card-one mb10">
      <el-col :span="24">
        <el-card shadow="hover">
          <el-radio-group v-model="state.radio" @change="radioChange">
            <el-radio v-for="(item, index) in state.county" :key="index" :label="item.value">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-card>
      </el-col>
    </el-row>

    <el-card shadow="hover" class="layout-padding-auto">
      <div class="system-user-search mb15">
        <el-input size="default" v-model="state.projectName" placeholder="请输入项目名称" style="max-width: 180px">
        </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="projectName" label="项目名称" />
        <el-table-column prop="district" label="区县名称" show-overflow-tooltip></el-table-column>
        <el-table-column prop="avgPrice" label="均价(元)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="upCount" label="预警上限数量" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="downCount" label="预警下限数量" show-overflow-tooltip>
        </el-table-column>

        <el-table-column prop="state" label="状态" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.state == 1 ? '正常' : '预警' }}
          </template>
        </el-table-column>
        <el-table-column label="操作" show-overflow-tooltip width="180" fixed="right">
          <template #default="scope">
            <el-button size="small" @click="godetail(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="priceindex">
import { defineAsyncComponent, reactive, onMounted, ref } from "vue";
import { ElMessageBox, ElMessage, ElNotification } from "element-plus";
import { getprice } from "/@/api/early/price";
import { useRouter } from "vue-router";
import { getAll } from "/@/api/sys/index";
import { useCurrentInstance } from "/@/method/get";
import {entApi} from "/@/api/ent";
const { proxy } = useCurrentInstance();

const router = useRouter();
// 引入组件

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

const getCodeApi = async () => {
  let item = await entApi().typesApi(); //区县数据
  state.county = item.data;
  state.radio = state.county[0].value
  getTableData();
};
const godetail = (row: any) => {
  router.push({
    path: "/early/price/house",
    query: {
      id: row.id,
      money: row.avgPrice,
      tagsViewName: row.projectName + "详情",
    },
  });
};

// 初始化表格数据
const getTableData = async () => {
  state.tableData.loading = true;
  // 项目
  const data = await getprice().getList({
    page: state.tableData.param.pageNum,
    limit: state.tableData.param.pageSize,
    projectName: state.projectName,
    areaCode: state.radio
  });
  state.tableData.data = data.data;
  state.tableData.total = data.count;
  state.tableData.loading = false;
  // 获取总数
};
const radioChange = (val: any) => {
  state.radio = val;
  getTableData();
};

// 分页改变
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">
.ors {
  display: flex;
  align-items: center;
}

.wgt {
  font-weight: bold;
}

.projecttop {
  display: flex;
  align-items: center;
  padding-top: 10px;

  &item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    position: relative;

    &:last-child {
      &::before {
        width: 0;
      }

      span {
        &::after {
          font-size: 14px;
          font-weight: normal;
          margin-left: 2px;
          content: "";
        }
      }
    }

    &:nth-child(2) {
      span {
        &::after {
          font-size: 14px;
          font-weight: normal;
          margin-left: 2px;
          content: "%";
        }
      }
    }


    &:nth-last-child(2) {
      span {
        &::after {
          font-size: 14px;
          font-weight: normal;
          margin-left: 2px;
          content: "%";
        }
      }
    }

    &::before {
      content: "";
      width: 2px;
      height: 30px;
      background-color: #eee;
      position: absolute;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
    }

    span {
      font-size: 24px;
      font-weight: bold;
    }

    p {
      margin-top: 10px;
      font-size: 14px;
      color: #666;
    }
  }
}

.title {
  font-weight: bold;
  font-size: 14px;
  padding-left: 10px;
  border-left: 3px solid #409efe;
}
</style>
