<template>
    <div class="filter-container" style="padding:0px 12px;">
        <a-row :gutter="12">

          <a-col :span="10">

            <a-range-picker
                format="YYYY-MM-DD HH:mm:ss"
                @change="onDateChange"
              />
              
          </a-col>
          <a-col :span="6">
            <a-input v-model:value="tifListParams.name" placeholder="搜索名称" />
          </a-col>
          <a-col :span="8">
            <a-button type="primary" @click="getTifByTimeList">查询</a-button>
            &nbsp;
            <a-button type="primary" @click="handlerUpdateTif">更新数据</a-button>
          </a-col>
        </a-row>
      </div>
      <div class="list-container" style="padding:12px;" >
        <a-table
          size="small"
          :columns="columns"
          :data-source="tifListData"
          rowKey="id"
          :row-selection="{ selectedRowKeys: selectedRowKeysA, onChange: handleSelectionChange }"
          :loading="loading"
          :pagination="{
            current: tifListParams.page, 
            pageSize: tifListParams.limit, 
            total: total, 
            onChange: handlePageChange,
            pageSizeOptions:[5,10,20,50],
        }"
        />
        


      </div>
</template>
<script lang="ts" setup>
import {ref,defineProps,defineExpose} from 'vue';
import {getAiShape,updateShape,getTifByTime,updateTif,addTask,updateTask} from '@/api/task'
import { useMessage } from '@/hooks/web/useMessage';
const { createMessage } = useMessage();

const columns = [
  {
    title: '县区',
    dataIndex: 'areaName',
  },
  {
    title: '日期',
    dataIndex: 'tifDate',
  },
  {
    title: '名称',
    dataIndex: 'tifName',
  },
];

const loading = ref(true)

const tifListParams = ref({
    name:null,
    beginTime:null,
    endTime:null,
    page:1,
    limit:5
})



const total = ref(0)


const tifListData = ref([])



function getTifByTimeList(){
    getTifByTime(tifListParams.value).then(res=>{
        tifListData.value = res.items;
        total.value = res.total;
        loading.value = false;
    })
}

getTifByTimeList();

const handlePageChange = (page, pageSize) => {
    tifListParams.value.page = page;
    tifListParams.value.limit  = pageSize;
    getTifByTimeList();
    
};

const selectedRowKeysA = ref([]); 
const selectedRowsA = ref();
// 选择框变化时的回调函数
const handleSelectionChange = (selectedRowKeys, selectedRows)=>{
    selectedRowKeysA.value = selectedRowKeys;
    selectedRowsA.value = selectedRows;
    console.log("selectedRowKeys",selectedRowKeys.value,selectedRows.value)
}



function handlerUpdateTif(){
    updateTif().then(res=>{
        if(res){
        createMessage.success("更新数据成功！");
        }else{
        createMessage.error("更新数据失败！");
        }
    })
}


function onDateChange(date){
    tifListParams.value.beginTime = date[0];
    tifListParams.value.endTime = date[1];
  }

  function getSelectedInfo(){
    let res = {
        selectedRowKeys:selectedRowKeysA.value,
        selectedRows:selectedRowsA.value
    }
    return res;
  }


  defineExpose({
    getSelectedInfo
  })
</script>