<template>
  <div class="app-container home">
    <el-button type="primary" :icon="Download" @click="drawerIshow = true">策略导入</el-button>
    <div class="dev_control_wrapper">
      <div class="dev_control_item" v-for="item in deviceArr" :key="item.deviceId">
        <div class="item_header">
          <span>{{ item.deviceName}}</span>
          <el-switch v-model="item.deviceId" class="switch" style="--el-switch-on-color: #13ce66; --el-switch-off-color: #dddddd"/>
        </div>
        <div class="item_bottom">
          <div class="item_bottom_img">
            <img :src="item.photoUrl" alt="">
          </div>
          <div class="item_bottom_form">
            <el-form :model="form1">
              <el-form-item label="当前状态："><span :class="{'green':item.deviceRunstatus === '开启','red':item.deviceRunstatus === '关闭'}">{{ item.deviceRunstatus }}</span></el-form-item>
              <el-form-item label="进水温度："><el-input v-model="form1.enter" /></el-form-item>
              <el-form-item label="出水温度："><el-input v-model="form1.leave" /></el-form-item>
              <div class="submit" @click="onSubmit1">确定</div>
            </el-form>
          </div>
        </div>
      </div>
<!--      <div class="dev_control_item">-->
<!--        <div class="item_header">-->
<!--          <span>空气源热泵</span>-->
<!--          <el-switch v-model="value2" class="switch" style="&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #dddddd"/>-->
<!--        </div>-->
<!--        <div class="item_bottom">-->
<!--          <div class="item_bottom_img">-->
<!--            <img src="./src/assets/images/空气源热泵.png" alt="">-->
<!--          </div>-->
<!--          <div class="item_bottom_form">-->
<!--            <el-form :model="form2">-->
<!--              <el-form-item label="当前状态："><span class="red">关闭</span></el-form-item>-->
<!--              <el-form-item label="进水温度："><el-input v-model="form2.enter" /></el-form-item>-->
<!--              <el-form-item label="出水温度："><el-input v-model="form2.leave" /></el-form-item>-->
<!--              <div class="submit" @click="onSubmit2">确定</div>-->
<!--            </el-form>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="dev_control_item">-->
<!--        <div class="item_header">-->
<!--          <span>发热电缆</span>-->
<!--          <el-switch v-model="value3" class="switch" style="&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #dddddd"/>-->
<!--        </div>-->
<!--        <div class="item_bottom">-->
<!--          <div class="item_bottom_img">-->
<!--            <img src="./src/assets/images/发热电缆.png" alt="">-->
<!--          </div>-->
<!--          <div class="item_bottom_form">-->
<!--            <el-form :model="form3">-->
<!--              <el-form-item label="当前状态："><span class="red">关闭</span></el-form-item>-->
<!--              <el-form-item label="当前温度："><el-input v-model="form3.now" /></el-form-item>-->
<!--              <div class="submit" @click="onSubmit3">确定</div>-->
<!--            </el-form>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="dev_control_item">-->
<!--        <div class="item_header">-->
<!--          <span>风机盘管</span>-->
<!--          <el-switch v-model="value4" class="switch" style="&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #dddddd"/>-->
<!--        </div>-->
<!--        <div class="item_bottom">-->
<!--          <div class="item_bottom_img">-->
<!--            <img src="./src/assets/images/风机盘管.png" alt="">-->
<!--          </div>-->
<!--          <div class="item_bottom_form">-->
<!--            <el-form>-->
<!--              <el-form-item label="当前状态："><span class="red">关闭</span></el-form-item>-->
<!--            </el-form>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="dev_control_item">-->
<!--        <div class="item_header">-->
<!--          <span>水泵</span>-->
<!--          <el-switch v-model="value5" class="switch" style="&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #dddddd"/>-->
<!--        </div>-->
<!--        <div class="item_bottom">-->
<!--          <div class="item_bottom_img">-->
<!--            <img src="./src/assets/images/水泵.png" alt="">-->
<!--          </div>-->
<!--          <div class="item_bottom_form">-->
<!--            <el-form>-->
<!--              <el-form-item label="当前状态："><span class="red">关闭</span></el-form-item>-->
<!--            </el-form>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="dev_control_item">-->
<!--        <div class="item_header">-->
<!--          <span>蓄热锅炉</span>-->
<!--          <el-switch v-model="value6" class="switch" style="&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #dddddd"/>-->
<!--        </div>-->
<!--        <div class="item_bottom">-->
<!--          <div class="item_bottom_img">-->
<!--            <img src="./src/assets/images/蓄热锅炉.png" alt="">-->
<!--          </div>-->
<!--          <div class="item_bottom_form">-->
<!--            <el-form>-->
<!--              <el-form-item label="当前状态："><span class="red">关闭</span></el-form-item>-->
<!--            </el-form>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="dev_control_item">-->
<!--        <div class="item_header">-->
<!--          <span>沙盘</span>-->
<!--          <el-switch v-model="value7" class="switch" style="&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #dddddd"/>-->
<!--        </div>-->
<!--        <div class="item_bottom">-->
<!--          <div class="item_bottom_img">-->
<!--            <img src="./src/assets/images/沙盘.png" alt="">-->
<!--          </div>-->
<!--          <div class="item_bottom_form">-->
<!--            <el-form>-->
<!--              <el-form-item label="当前状态："><span class="red">关闭</span></el-form-item>-->
<!--            </el-form>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
    </div>
    <div class="dev_control_table">
      <div class="control_header"><span>调控日志</span></div>
      <div class="control_table">
        <el-table :data="controlLogList" height="305px">
          <el-table-column label="序号" align="center" width="50"/>
          <el-table-column label="设备名称" align="center" prop="deviceName"/>
          <el-table-column label="操作内容" align="center" prop="controlValue" width="700"/>
          <el-table-column label="操作时间" align="center" prop="createTime"/>
          <el-table-column label="操作人员" align="center" prop="createBy"/>
          <el-table-column label="操作结果" align="center" prop="controlResult"></el-table-column>
        </el-table>
        <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[5, 10, 20, 50]"
            :small="small"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="tableLength"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
      </div>
    </div>

    <el-drawer v-model="drawerIshow">
      <template #header><h4>策略导入</h4></template>
      <template #default>
        <el-radio v-model="radio" label="策略1" size="large">策略1</el-radio>
        <el-radio v-model="radio" label="策略2" size="large">策略2</el-radio>
      </template>
      <template #footer>
        <div style="flex: auto">
          <el-button type="primary" @click="confirmClick">执行</el-button>
        </div>
      </template>
    </el-drawer>
  </div>
</template>

<script setup name="Index">
import { Download } from '@element-plus/icons-vue'  //element字体图标
import { ref,reactive,onMounted } from 'vue'
import { ElMessageBox } from 'element-plus'
import { getDevice,getControlLogList } from '@/api/control/manual'

onMounted(()=>{
  getDeviceFun();
  getControlLogListFun();
})

/** 获取所有设备*/
const deviceArr = ref([])
function getDeviceFun(){
  getDevice().then((res)=>{
    console.log(res.data)
    deviceArr.value = res.data
    for(let i = 0;i < res.data.length;i++){
      if(res.data[i].deviceRunstatus == 1){
        res.data[i].deviceRunstatus = '开启'
      }else{
        res.data[i].deviceRunstatus = '关闭'
      }
    }
  })
}

/** 设备控制处理*/
const value1 = ref(true)
const value2 = ref(false)
const value3 = ref(false)
const value4 = ref(false)
const value5 = ref(false)
const value6 = ref(false)
const value7 = ref(false)
const form1 = reactive({
  enter:'',
  leave:'',
})
const form2 = reactive({
  enter:'',
  leave:'',
})
const form3 = reactive({
  now:'',
})
const onSubmit1 = () => {
  console.log('确定')
}
const onSubmit2 = () => {
  console.log('确定')
}
const onSubmit3 = () => {
  console.log('确定')
}

/** 数据表格处理*/
const controlLogList = ref([])
const tableLength = ref()
const currentPage = ref(1)
const pageSize = ref(5)
const small = ref(false)
const background = ref(false)
const disabled = ref(false)
const handleSizeChange = (val) => {
  getControlLogListFun()
}
const handleCurrentChange = (val) => {
  getControlLogListFun()
}
function getControlLogListFun(){
  getControlLogList({
    "deviceId": null,
    "deviceName": null,
    "deviceSn": null,
    "controlKey": null,
    "controlValue": null,
    "controlResult": null,
    "controlContext": null,
    "pageNum": currentPage.value,
    "pageSize": pageSize.value
  }).then((res)=>{
    tableLength.value = res.total
    controlLogList.value = res.rows
  })
}


/** 策略导入处理*/
const drawerIshow = ref(false)
const radio = ref()
function confirmClick() {
  ElMessageBox.confirm(`确定执行 ${radio.value} ?`).then(() => {
    drawerIshow.value = false;
      })
}


</script>

<style scoped lang="scss">
.home {
  height: calc(100vh - 118px);
  .dev_control_wrapper{
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    width: 100%;
    height: 50%;
    overflow-y: auto;
    .dev_control_item{
      width: 24%;
      height: 47%;
      margin-right: 12px;
      margin-bottom: 12px;
      background-color: #2F3D8A;
      overflow: hidden;
      &:nth-child(4n){
        margin-right: 0px;
      }

      .item_header{
        width: 100%;
        height: 20%;
        background-color: #374590;
        padding: 0 10px;
        span{
          font-size: 16px;
          font-weight: bold;
          line-height: 37px;
        }
        .switch{
          float: right;
          line-height: 37px;
          height: 37px;
        }
      }
      .item_bottom{
        display: flex;
        width: 100%;
        height: 80%;
        .item_bottom_img{
          width: 40%;
          height: 100%;
          //border: 1px solid red;
          padding: 10px;
          img{
            width: 100%;
            height: 100%;
          }
        }
        .item_bottom_form{
          width: 60%;
          height: 100%;
          //border: 1px solid red;
          padding: 0 10px 0 0;
          .green{
            color: #14FF00;
          }
          .red{
            color: red;
          }
          .submit{
            padding: 3px 15px;
            border-radius: 2px;
            background-color: #2F8EED;
            float: right;
            margin-top: 8px;
            cursor: pointer;
            &:hover{
              background-color: #5ba2f3;
            }
          }
        }
      }
    }
  }
  .dev_control_table{
    width: 100%;
    height: 50%;
    background-color: #2F3D8A;
    .control_header{
      width: 100%;
      height: 10%;
      background-color: #374590;
      padding: 0 10px;
      span{
        font-size: 16px;
        font-weight: bold;
        line-height: 37px;
      }
    }
    .control_table{
      position: relative;
      width: 100%;
      height: 90%;
    }
  }
}

::v-deep .el-button{
  border-radius: 2px;
  margin-bottom: 12px;
}
::v-deep .el-switch__core .el-switch__action{
  top: 1px;
  width: 17px;
  height: 17px;
}
::v-deep .el-form-item--default{
  margin-bottom: 3px;
}
::v-deep .el-input__inner{
  color: #f3ffff;
}
::v-deep .el-pagination{
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
}
::v-deep .el-pagination__total{
  color: #f3ffff;
}
::v-deep .el-pagination__jump{
  color: #f3ffff;
}
::v-deep .el-pager{
  margin: 0 5px;
}
::v-deep .el-table--fit{
  background-color: #2D3D88;
}
</style>

