<template>


  <headerBar
    title="初始设备调频设置"
  />

  <div class="page">
  <el-row v-for="item,key in editRowData" :key="index" class="mar-top-10">
    <el-col :span="12">{{key}}</el-col>
    <el-col :span="10">
      <el-input
          v-model="editRowData[key]"
          type="number"
      />
    </el-col>
  </el-row>

  <el-row align="middle" justify="middle" class="bottom-wrap">
    <el-col :span="24">
      <el-button type="primary" @click="get_deviation">读取配置</el-button>
      <el-button type="primary" @click="set_deviation">设置配置</el-button>
    </el-col>
  </el-row>
  </div>

</template>

<script setup lang="ts">

import {ref,reactive,onMounted} from "vue";

import client from "@/stores/modules/client";
import  icpList from '@/utils/ipc'
import socket from "@/stores/modules/socket";
import {ElMessage} from "element-plus";
const clientStore = client();
const socketStore = socket()


const editRowData = ref({
}); // 当前编辑行的数据

onMounted(()=>{
  get_deviation()
})

//获取配置
async function  get_deviation(){
  if(clientStore.isClient){
    socketStore.sendMessage({
      type: 'get_mcu_other_info',
      data:"get_mcu_other_info"
    })


    clientStore.ipc.on(icpList.socket.message+'_get_mcu_other_info', (event, result) => {
      console.log('_get_mcu_other_info')
      console.log(result)
      if(result.code === 0){
        editRowData.value =  result.data

      }else if(result.msg){
        ElMessage.error(result.msg)
      }
      clientStore.ipc.removeAllListeners(icpList.socket.message+'_get_mcu_other_info');
    });
  }
}




//设置 移动 调整
async function set_deviation(action_name, type, key, min, max) {

  socketStore.sendMessage({
    type: 'set_mcu_other_info',
    data:{
      ...editRowData.value
    }
  })


  clientStore.ipc.on(icpList.socket.message+'_set_mcu_other_info', (event, result) => {
    console.log('_set_mcu_other_info')
    console.log(result)
    if(result.code === 0){

      ElMessage.success('设置成功')

    }
    clientStore.ipc.removeAllListeners(icpList.socket.message+'_set_mcu_other_info');
  });



}



</script>

<style scoped lang="scss">
.bottom-wrap {
  position: fixed;
  bottom:0px;
  left: 0;
  right: 0;
  padding: 10px 0;
  background: #fff;
}
.page {
  padding-bottom: 60px;
}
.el-col {
    position: relative;
  ::v-deep {
    .error-msg{
      display: none;
      position: absolute;
      top: 41px;
      top: 28px;
      left: 8px;
      z-index: 22;
      color: #dc2626;
      font-size: 12px;
    }
    &:hover{
      .error-msg{
        display: block;
      }
    }
  }
}
</style>
