<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData"/>

    <el-row :gutter="32" style="padding:0px 16px 0;margin-bottom:32px;">
      <el-card>
        <div slot="header" class="clearfix">
          <span>进行中的作业</span>
        </div>
        <el-table
          height="260"
          v-loading="loading"
          :data="jobList"
          row-key="workorderId"
          default-expand-all
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <!--                <el-table-column label="工单编码" width="180" prop="workorderCode" >-->
          <!--                    <template slot-scope="scope">-->
          <!--                    <el-button v-no-more-click-->
          <!--                        size="mini"-->
          <!--                        type="text"-->
          <!--                        @click="handleView(scope.row)"-->
          <!--                        v-hasPermi="['mes:pro:workorder:query']"-->
          <!--                    >{{scope.row.workorderCode}}</el-button>-->
          <!--                    </template>-->
          <!--                </el-table-column>-->
          <el-table-column label="作业票名称" width="320" align="center" prop="ticketName"/>
          <el-table-column label="岗位" align="center" prop="workstationName" :show-overflow-tooltip="true"/>
          <el-table-column label="设备工艺" align="center" prop="machineryName"/>
          <el-table-column label="作业类型" align="center" prop="ticketType" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.ticket_type" :value="scope.row.ticketType"/>
            </template>
          </el-table-column>
          <el-table-column label="启动时间" align="center" prop="ticketStartTime" :show-overflow-tooltip="true"/>

        </el-table>
      </el-card>
    </el-row>

    <el-row style="width:100%;background:#fff;padding:16px 16px 0; margin-bottom:32px;">
      <line-chart :chart-data="lineChartData"/>
    </el-row>

<!--    <el-row :gutter="32">-->
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <raddar-chart/>-->
<!--        </div>-->
<!--      </el-col>-->
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <pie-chart/>-->
<!--        </div>-->
<!--      </el-col>-->
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <bar-chart/>-->
<!--        </div>-->
<!--      </el-col>-->
<!--    </el-row>-->


  </div>
</template>

<script>
import { listWorkorder } from '@/api/mes/pro/workorder'
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart'
import RaddarChart from './dashboard/RaddarChart'
import PieChart from './dashboard/PieChart'
import BarChart from './dashboard/BarChart'
import { getHomePage } from '@/api/mes/statisticians'
const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'Index',
  dicts: ['ticket_type'],
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      loading: true,
      queryParams: { status: 'CONFIRMED' },
      jobList: [],
      lineChartData: null,
      startTime: null,
      endTime: null,
    }
  },
  created() {
    this.calculateDateRange()
    this.getList()

  },
  methods: {
    calculateDateRange() {
      const today = new Date();
      const endTime = today.toISOString().split('T')[0]; // 今天的日期，格式为 YYYY-MM-DD

      // 计算 startTime，即从今天往前三十天的日期
      const thirtyDaysAgo = new Date(today);
      thirtyDaysAgo.setDate(today.getDate() - 30);
      const startTime = thirtyDaysAgo.toISOString().split('T')[0]; // 三十天前的日期，格式为 YYYY-MM-DD
      this.startTime=startTime;
      this.endTime=endTime;
      console.log(this.startTime, endTime,'传递的时间');
    },
    getList() {
      this.loading = true
      let data={
        startTime:this.startTime,
        endTime:this.endTime,
      }
      getHomePage(data).then((res) => {
        console.log(res, '首页接口')
        this.loading = false
        this.jobList = res.data.jobList
        this.lineChartData= res.data.loanList.sort((a, b) => {
          const dateA = new Date(a.day);
          const dateB = new Date(b.day);
          return dateA-dateB
        })
      })
      // listWorkorder(this.queryParams).then(response => {
      //   this.workorderList = response.rows;
      //   this.loading = false;
      // });
    },
    handleSetLineChartData(type) {
      // this.lineChartData = lineChartData[type]
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
