<template>
  <div class="device_management_platform">
    <el-row :gutter="20">
      <el-col :span="18">
        <div class="header">
          <div class="h_left">
            <div class="box_title">设备管理工作台</div>
            <DateSwitch @tab-change="handleTabChange" />
          </div>
          <el-button type="warning" class="add_device_btn">添加设备 +</el-button>
        </div>

        <div class="device_summary">
          <div class="summary_item">
            <div class="box_title">设备台账</div>
            <p>36 台</p>
            <div class="bottom_item"><el-button link>查看设备分布</el-button></div>
          </div>
          <div class="summary_item">
            <div class="box_title">报修设备</div>
            <p>6 台</p>
            <div class="bottom_item"><p class="trend_down">相比上周 ↓10%</p></div>
          </div>
          <div class="summary_item">
            <div class="box_title">保养设备</div>
            <p>13 台</p>
            <div class="bottom_item"><p class="trend_up">相比上周 ↑50%</p></div>
          </div>
          <div class="summary_item">
            <div class="box_title">巡检设备</div>
            <p>30 台</p>
            <div class="bottom_item"><p class="trend_up">相比上周 ↑300%</p></div>
          </div>
        </div>

        <div class="weekly_maintenance_chart">
          <div class="chart_left_box">
            <div>周维修数据统计</div>
            <div>按设备维修统计</div>
            <div>按维度时长统计</div>
          </div>
          <div class="chart_center_box">
            <div class="chart_item" style="margin-top: 0">
              <div class="chart_item_title"> 气保焊机 (26) </div>
              <div class="chart_tips_box">
                <div class="progress_box">
                  <el-progress :percentage="50" color="orange" :show-text="false" />
                </div>
                <p>10</p>
              </div>
            </div>
            <div class="chart_item">
              <div class="chart_item_title"> 激光切板机</div>
              <div class="chart_tips_box">
                <div class="progress_box">
                  <el-progress :percentage="30" color="blue" :show-text="false" />
                </div>
                <p>2</p>
              </div>
            </div>
            <div class="chart_item">
              <div class="chart_item_title"> 焊接机器人 </div>
              <div class="chart_tips_box">
                <div class="progress_box">
                  <el-progress :percentage="10" color="grid" :show-text="false" />
                </div>
                <p>1</p>
              </div>
            </div>
          </div>
          <div class="chart_right_box">
            <div class="stat_ring" id="deviceEcharts" style="width: 600px; height: 230px"></div>
          </div>
        </div>

        <div class="today_tasks">
          <div class="h_left">
            <div class="box_title">今日任务</div>
            <DateSwitch @tab-change="handleTabChange" :isYear="false" />
          </div>
          <div class="task_summary">
            <div class="task_left">
              <div class="task_item">
                <div class="task_title">已处理维修工单</div>
                <div>33</div>
              </div>
              <div class="task_item">
                <div class="task_title">处理中</div>
                <div>6</div>
              </div>
              <div class="task_item">
                <div class="task_title">待处理</div>
                <div class="task_tips_box">
                  <p>12</p>
                  <span class="overdue">超期未处理 12</span>
                </div>
              </div>
            </div>
            <div class="task_center">
              <div class="task_title">保养总数</div>
              <div class="task_tips_box">
                <p>13</p>
                <div class="progress_box"><el-progress :percentage="50" color="orange" /></div>
              </div>
              <div class="task_title mtop">已完成</div>
              <div class="task_tips_box">
                <p>10</p>
                <div class="progress_box"><el-progress :percentage="50" color="orange" /></div>
              </div>
              <div class="tips_title_box">设备保养数据</div>
            </div>
            <div class="task_right">
              <div class="task_title">巡检总数</div>
              <div class="task_tips_box">
                <p>33</p>
                <div class="progress_box"><el-progress :percentage="50" color="orange" /></div>
                <p>超期 30</p>
              </div>

              <div class="task_title mtop">已完成</div>
              <div class="task_tips_box">
                <p>10</p>
                <div class="progress_box"><el-progress :percentage="50" color="blue" /></div>
                <span class="abnormal">异常 2</span>
              </div>

              <div class="tips_title_box">设备巡检数据</div>
            </div>
          </div>
        </div>

        <div class="other_data_summary">
          <div class="box_title">其他数据汇总</div>
          <div class="data_item_box">
            <div class="data_item">
              <div class="other_data_title">月度维修费</div>
              <p>17020,00</p>
            </div>
            <div class="data_item">
              <div class="other_data_title">维修效率</div>
              <p>36h</p>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="home_right_box">
          <div class="approval_process">
            <div class="right_item_header_box">
              <div class="box_title">审批流程</div>
              <div class="link_b">发起流程 +</div>
            </div>
            <ul>
              <li>我发起的 <span>10</span></li>
              <li>抄送我的 <span>81</span></li>
              <li>我处理的 <span>99+</span></li>
            </ul>
          </div>

          <div class="reminder_list">
            <div class="right_item_header_box">
              <div class="box_title">待办提醒</div>
              <div class="link_b">查看全部</div>
            </div>
            <ul>
              <li>
                <div class="img_box">
                  <img class="logo_img" alt="格莱默打印系统" src="../../../assets/imgs/logo.png" />
                </div>
                <div class="right_value">
                  <div>设备巡检</div>
                  <div class="fmx">工厂2区点焊设备巡检任务...</div>
                </div>
              </li>
              <li>
                <div class="img_box">
                  <img class="logo_img" alt="格莱默打印系统" src="../../../assets/imgs/logo.png" />
                </div>
                <div class="right_value">
                  <div>维修工单</div>
                  <div class="fmx">员工陈波发起设备维修审批</div>
                </div>
              </li>
              <li>
                <div class="img_box">
                  <img class="logo_img" alt="格莱默打印系统" src="../../../assets/imgs/logo.png" />
                </div>
                <div class="right_value">
                  <div>保养设备</div>
                  <div class="fmx">工厂3区注塑设备7天后保养到期</div>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import * as echarts from 'echarts'
import DateSwitch from './DateSwitch.vue'
const activeTab = ref('day')

const currentTab = ref('day')

const handleTabChange = (tab) => {
  currentTab.value = tab
}

onMounted(() => {
  const chartDom = document.getElementById('deviceEcharts')
  const myChart = echarts.init(chartDom)
  const option = {
    title: {
      text: '维修单'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['去年', '今年']
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    toolbox: {
      feature: {
        saveAsImage: {}
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['36周', '37周', '38周', '39周', '40周', '41周', '42周']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name: '去年',
        type: 'line',
        // stack: 'Total',
        data: [120, 132, 101, 134, 90, 230, 210]
      },
      {
        name: '今年',
        type: 'line',
        // stack: 'Total',
        data: [220, 182, 191, 234, 290, 330, 310]
      }
    ]
  }
  myChart.setOption(option)
})
</script>

<style lang="less" scoped>
.device_management_platform {
  // padding: 20px;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    .h_left {
      display: flex;
      align-items: center;
      .box_title {
        font-size: 16px;
        font-weight: bold;
        margin-right: 20px;
      }
    }
    .date_tabs {
      flex: 1;
      max-width: 500px;
      margin: 0 20px;
    }
    .add_device_btn {
      white-space: nowrap;
    }
  }
  .device_summary {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    .summary_item {
      border: 1px solid #e7e0e0;
      padding: 10px;
      width: 23%;
      .box_title {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 2px;
      }
      .bottom_item {
        margin-top: 6px;
        text-align: right;
      }
      .trend_down {
        color: red;
      }
      .trend_up {
        color: green;
      }
    }
  }
  .weekly_maintenance_chart {
    border: 1px solid #eee;
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    .chart_left_box {
      border-right: 1px solid #eee;
      padding-right: 20px;
      width: 140px;
      div {
        font-size: 14px;
        font-weight: bold;
        margin-bottom: 20px;
      }
    }
    .chart_center_box {
      margin-left: 20px;
      padding-right: 20px;
      border-right: 1px solid #eee;
      width: 160px;
      .chart_item {
        padding-bottom: 20px;
        margin-top: 20px;
        border-bottom: 1px solid #eee;
        .chart_item_title {
          font-size: 14px;
        }
        .chart_tips_box {
          display: flex;
          margin-top: 2px;
          align-items: center;
          .progress_box {
            width: 100px;
            margin-right: 6px;
          }
        }
      }
    }
    // .chart_placeholder {
    //   height: 300px;
    //   background-color: #f5f5f5;
    // }
  }
  .today_tasks {
    margin-bottom: 20px;
    .h_left {
      display: flex;
      align-items: center;
      .box_title {
        font-size: 16px;
        font-weight: bold;
        margin-right: 20px;
      }
    }
    .task_summary {
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      .task_left {
      }
      .task_center {
        background: #f2f2f2;
        padding: 10px;
        margin-left: 20px;
        width: 300px;
      }
      .task_right {
        background: #f2f2f2;
        padding: 10px;
        margin-left: 20px;
        width: 300px;
      }
      .task_title {
        font-size: 14px;
        font-weight: bold;
        margin-bottom: 6px;
      }
      .mtop {
        margin-top: 20px;
      }
      .tips_title_box {
        font-size: 14px;
        font-weight: bold;
        text-align: center;
        margin-top: 30px;
      }
      .task_tips_box {
        display: flex;
        justify-content: space-between;
        .progress_box {
          width: 150px;
        }
      }
      .task_item {
        background: #f2f2f2;
        padding: 10px;
        margin-bottom: 10px;
        width: 200px;
        .overdue {
          color: orange;
          font-size: 12px;
        }
        .abnormal {
          color: red;
          font-size: 12px;
        }
      }
    }
  }
  .other_data_summary {
    .box_title {
      font-size: 16px;
      font-weight: bold;
      margin-bottom: 20px;
    }
    .data_item_box {
      display: flex;
    }
    .data_item {
      display: flex;
      justify-content: space-between;
      width: 200px;
      .other_data_title {
        font-size: 14px;
        font-weight: bold;
      }
      background: #f2f2f2;
      border-radius: 6px;
      padding: 16px;
      margin-right: 16px;
    }
  }
  .home_right_box {
    border-left: 1px solid #eee;
    padding-left: 5px;
  }
  .approval_process,
  .reminder_list {
    .right_item_header_box {
      background: #f2f2f2;
      padding: 16px 10px;
      display: flex;
      justify-content: space-between;
      .box_title {
        font-size: 16px;
        font-weight: bold;
      }
      .link_b {
        font-size: 14px;
        font-weight: bold;
        cursor: pointer;
      }
    }
    // border: 1px solid #eee;
    // padding: 10px;
    ul {
      list-style: none;
      padding: 0;
      margin-left: 16px;
      li {
        padding: 5px 0;
        margin-top: 10px;
        font-size: 14px;
        font-weight: bold;
        span {
          background: #f3f0f0;
          padding: 2px 6px;
          border-radius: 4px;
          margin-left: 60px;
        }
      }
    }
  }
  .approval_process {
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
    margin-bottom: 20px;
  }
  .reminder_list {
    li {
      display: flex;
      .right_value {
        margin-left: 10px;
        .fmx {
          font-size: 13px;
        }
      }
    }
  }
  .img_box {
    width: 40px;
    height: 40px;
    background: #f2f2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    .logo_img {
      width: 30px;
      height: 30px;
    }
  }
}
</style>
