<template>
  <n-button type="primary" @click="showImportModal">导出数据</n-button>
  <!-- <n-modal style="width: 30%" v-model:show="showModal" :show-icon="false" preset="dialog" title="导出" positive-text="确认"
    negative-text="取消" @positive-click="exportTask">
    <n-form :model="formValue" label-width="auto" show-require-mark>
      <n-form-item label="Id" path="T_sn_list">
        <n-select v-model:value="formValue.T_sn_list" label-field="T_id" value-field="T_sn" :options="options" multiple
          :max-tag-count="2" clearable>
        </n-select>
      </n-form-item>
      <n-form-item label="开始时间" path="Time_start">
        <n-date-picker v-model:formatted-value="formValue.Time_start" value-format="yyyy.MM.dd HH:mm:ss" type="datetime"
          clearable class="w-full" />
      </n-form-item>
      <n-form-item label="结束时间" path="Time_end">
        <n-date-picker v-model:formatted-value="formValue.Time_end" value-format="yyyy.MM.dd HH:mm:ss" type="datetime"
          clearable class="w-full" />
      </n-form-item>
    </n-form>
  </n-modal> -->
</template>

<script setup>
import { exportTaskData } from '@/api';
import { useMessage } from 'naive-ui';
import {TimeDate} from '@/plugin/timeFun.js'
const message = useMessage();
const props = defineProps({
  queryObj: {
    type: Object,
    default: () => ({}),
  },
  pickleveTime:{
    type:Array,
    default: () => ([])
  },
  checkData: {
    type: Array,
    default: () => ([])
  }
});

const options = computed(() => {
  return props.classList;
});



// 表单数据
const formValue = reactive({
  T_task_id: '',
  T_sn_list: [],
  Time_start: null,
  Time_end: null,
});

// 显示导入
const showImportModal = async () => {
  console.log('sds',props.pickleveTime)
  // return
  if (props.checkData == null || props.checkData.length == 0) {
    message.error('请选择需要导出的设备')
    return
  } else {
    formValue.T_task_id = props.queryObj.T_task_id
    formValue.Time_start = props.pickleveTime==null?'':TimeDate(props.pickleveTime[0])
    formValue.Time_end = props.pickleveTime==null?'':TimeDate(props.pickleveTime[1])
    formValue.T_sn_list = exportTask(props.checkData);

    exportTaskData(formValue).then(res => {
      console.log('请求完成', res)
      if (res.data.Code === 200){
        location.href = res.data.Data;
      } 
    })
  }

};

const exportTask = (dataArr) => {
  let arr = dataArr.map((item) => item.T_sn);
  return arr.join(',')
  try {
    if (formValue.T_sn_list.length === 0) {
      formValue.T_sn_list = props.classList.map((item) => item.T_sn);
    }
    const { data: res } = exportTaskData({
      T_task_id: props.task.T_task_id,
      T_sn_list: formValue.T_sn_list.join(),
      Time_start: formValue.Time_start + '',
      Time_end: formValue.Time_end + '',
    });
    location.href = res.Data;
  } catch (e) {
    console.log(e);
  }
};
</script>

<style lang="scss" scoped></style>
