<template>
  <n-button type="primary" @click="showSetModal">等比缩放</n-button>
  <n-modal v-model:show="showModal" :style="{ width: '400px'}" :show-icon="false" preset="card" title="等比缩放">
    <n-form :model="model" label-width="auto" show-require-mark>
      <!-- <n-divider title-placement="center">  </n-divider> -->
      <n-form-item label="温度比列" path="value">
        <n-input v-model:value="model.Temperature" />
      </n-form-item>

      <!-- <n-divider title-placement="center">  </n-divider> -->

      <n-form-item label="湿度比列" path="value">
        <n-input v-model:value="model.Humidity" />
      </n-form-item>
    </n-form>
    <template #footer>
      <n-button type="primary" @click="submitCallback">
        立即提交
      </n-button>
      <n-button @click="showModal = false" style="margin-left:10px">取消</n-button>
    
    
      
    </template>
  </n-modal>
</template>

<script setup>

import {Taskzoom} from '@/api';
import { useStore } from 'vuex';
const emit = defineEmits(['ratioZoomFun']);
import { useMessage } from 'naive-ui';
import {TimeData} from '@/plugin/timeFun.js'
const message = useMessage();
const props = defineProps({
  queryObj: {
    type: Object,
    default: () => ({}),
  },
  pickleveTime: {
    type: Array,
    default: () => ([])
  },
  checkData: {
    type: Array,
    default: () => ([])
  }
})
const store = useStore()

//提交
const submitCallback = async() => {
  var reg = /^([1-9]\d*(\.\d*[1-9][0-9])?)|(0\.\d*[1-9][0-9])|(0\.\d*[1-9])$/;
  
  if(!reg.test(model.Temperature)){
    message.error('温度比列格式为大于0【必填】')
    return
  }
  if(!reg.test(model.Humidity)) {
    message.error('湿度比列格式为大于0【必填】')
    return
  }
  
  await dataFun()
  TaskzoomApi()
  console.log('sss',model)
  
};
const TaskzoomApi = async()=>{
  Taskzoom(model).then(res=>{
    if(res.data.Code==200){
      message.success(res.data.Msg)
      showModal.value = false
      emit('ratioZoomFun');
    }
  })
}
const dataFun = ()=>{  
  return new Promise(resolve=>{
    model.StartTime = TimeData(model.StartTime)
    model.EndTime = TimeData(model.EndTime)

    // //处理sn List
    let snList = [...props.checkData]
    const arr1 = snList.map(item => item.T_sn + ',' +item.T_id)
    model.SN_List = arr1.join('|')+'|'
    resolve()
  })
}
// 是否展示 Modal
const showModal = ref(false);



const model = reactive({
  Temperature: 1,
  Humidity: 1,
  T_task_id: '',
  SN_List: '',
  StartTime: null,
  EndTime: null,
})

// 显示设置
const showSetModal = () => {
  if (props.checkData == null || props.checkData.length == 0) {
    message.error('请选择需要设置等比缩放的设备')
    return
  } else if (props.pickleveTime == null) {
    message.error('请选择等比缩放时间')
    return
  } else {
    model.T_task_id = props.queryObj.T_task_id
    model.StartTime = new Date(props.pickleveTime[0]).getTime()
    model.EndTime = new Date(props.pickleveTime[1]).getTime()
    showModal.value = true
  }
};
</script>

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