<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="5">
            <a-form-item label="热力公司">
              <a-select ref="select" placeholder="请选择热力公司" v-model:value="queryParam.view001" style="width: 150px"
                @focus="focus" @change="handleChange1">
                <a-select-option :value="item.id" v-for="item in thermalcompany" :key="item.id">{{ item.companyName
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="5">
            <a-form-item label="锅炉房">
              <a-select ref="select" placeholder="请选择锅炉房" v-model:value="queryParam.view002" style="width: 150px"
                @focus="focus" @change="handleChange2">
                <a-select-option :value="item.id" v-for="item in heatsource" :key="item.id">{{ item.sourceName
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
<!--          <a-col :lg="5">-->
<!--            <a-form-item label="换热站">-->
<!--              <a-select ref="select" placeholder="请选择换热站" v-model:value="queryParam.view004" style="width: 250px"-->
<!--                @focus="focus" @change="handleChange3">-->
<!--                <a-select-option :value="item.id" v-for="item in heatsourcestation" :key="item.id">{{ item.stationName-->
<!--                }}</a-select-option>-->
<!--              </a-select>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :lg="5">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button preIcon="ant-design:sync-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
          <!--          <a-col :lg="5">
            <a-form-item label="一次供水温度">
              <a-input placeholder="请输入一次供水温度" v-model:value="queryParam.view005"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="5">
            <a-form-item label="一次回水温度">
              <a-input placeholder="请输入一次回水温度" v-model:value="queryParam.view006"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="5">
            <a-form-item label="二次供水温度">
              <a-input placeholder="请输入二次供水温度" v-model:value="queryParam.view009"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="5">
            <a-form-item label="二次回水温度">
              <a-input placeholder="请输入二次回水温度" v-model:value="queryParam.view010"></a-input>
            </a-form-item>
          </a-col>-->
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <template v-slot:bodyCell="{ column, record, index, text }">
        <template v-if="column.dataIndex === 'view005'">
          <span v-if="record.fromFlow == 0">{{ record.view005 }}</span>
          <span v-else-if="record.fromFlow == 1">{{ record.view035 }}</span>
          <span v-else>{{ record.view005 || record.view035 || 0 }}</span>
        </template>
        <template v-if="column.dataIndex === 'view006'">
          <span v-if="record.fromFlow == 0">{{ record.view006 }}</span>
          <span v-else-if="record.fromFlow == 1">{{ record.view036 }}</span>
          <span v-else>{{ record.view005 || record.view035 || 0 }}</span>
        </template>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="heatanalysis-heatanalysis" setup>
import { ref, reactive, onMounted } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { columnsJx } from './Heatanalysis.data';
import { list, companylist, heatsourcelist, heatsourcestationlist } from './Heatanalysis.api';

const queryParam = ref<any>({});
const toggleSearchStatus = ref<boolean>(false);
const registerModal = ref();
//注册table数据
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
  tableProps: {
    title: '',
    api: list,
    columns: columnsJx,
    canResize: false,
    useSearchForm: false,
    clickToRowSelect: false,
    showActionColumn: false,
    showIndexColumn: false,
    tableSetting: {
      // 是否显示刷新按钮
      redo: false,
      // 是否显示尺寸调整按钮
      size: false,
      // 是否显示字段调整按钮
      setting: false,
      // 是否显示全屏按钮
      fullScreen: false,
    },
    beforeFetch: (params) => {
      queryParam.value.regionType = '郊县'
      params.column = '', params.order = '';//新生成的默认不带排序
      return Object.assign(params, queryParam.value);
    },
  },
});
const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
const labelCol = reactive({
  xs: { span: 24 },
  sm: { span: 7 },
});
const wrapperCol = reactive({
  xs: { span: 24 },
  sm: { span: 16 },
});

/**
 * 成功回调
 */
function handleSuccess() {
  (selectedRowKeys.value = []) && reload();
}

/**
 * 查询
 */
function searchQuery() {
  reload();
}

/**
 * 重置
 */
function searchReset() {
  queryParam.value = {};
  selectedRowKeys.value = [];
  getHeatsource();
  // getHeatsourcestation();
  //刷新数据
  reload();
}

const thermalcompany = ref();
async function getThermalcompany() {
  let params = {regionType:'郊县'};
  thermalcompany.value = await companylist(params);
}

const heatsource = ref();
async function getHeatsource() {
  let params = {regionType:'郊县'};
  heatsource.value = await heatsourcelist(params);
}

// const heatsourcestation = ref();
// async function getHeatsourcestation() {
//   heatsourcestation.value = await heatsourcestationlist();
// }

async function handleChange1(record) {
  var params = { companyId: record,regionType:'郊县' };
  heatsource.value = await heatsourcelist(params);
  // heatsourcestation.value = [];
}
async function handleChange2(record) {
  // var params = { sourceId: record };
  // heatsourcestation.value = await heatsourcestationlist(params);
}
function handleChange3(record) {
}

onMounted(() => {
  getThermalcompany();
  getHeatsource();
  // getHeatsourcestation();
});


</script>

<style lang="less" scoped>
.jeecg-basic-table-form-container {
  .table-page-search-submitButtons {
    display: block;
    margin-bottom: 8px;
    white-space: nowrap;
  }

  .query-group-cust {
    width: calc(50% - 15px);
    min-width: 100px !important;
  }

  .query-group-split-cust {
    width: 30px;
    display: inline-block;
    text-align: center
  }
}

:deep(.ant-table-title) {
  display: none;
}

:deep(.jeecg-basic-table-form-container) {
  padding: 0px;
}

:deep(.ant-form-item) {
  margin-bottom: 0px;
}
</style>
