<template>
  <div>
    <el-card style="height: 958px">
      <div style="height: 100px">
        <div style="display: flex">
          <div class="planInfo" style="background: #009e1c">
            <span>工单号</span>
            <br />
            <span style="line-height: 0">{{orderData.ORDER_CODE}}</span>
          </div>
          <div class="planInfo" style="background: #009e1c">
            <span>产品编码</span>
            <br />
            <span>{{orderData.PRO_CODE}}</span>
          </div>
          <div class="planInfo" style="background: #009e1c">
            <span>计划数量</span>
            <br />
            <span>{{orderData.QTY}}</span>
          </div>
          <div class="planInfo" style="background: #009e1c">
            <span>今日下线</span>
            <br />
            <span>{{orderData.QTY_TODAY}}</span>
          </div>
          <div class="planInfo" style="background: #009e1c">
            <span>完成率</span>
            <br />
            <span>{{orderData.完成率}}%</span>
          </div>
        </div>
      </div>
      <el-tabs v-model="activeName">
        <el-tab-pane label="产量总览" name="first" style="height: 867px">
          <div style="display: flex;flex-wrap: wrap;overflow-y: auto">
            <div v-for="(item, index) in countList" :key="index" class="toolCard">
              <div style="width: 400px;height: 160px;border: 1px solid #afafaf;border-radius: 5px">
                <div style="font-size: 20px;font-weight: bold;padding: 5px;background-color: #03a9f4;color: #fff">{{ item.工位号 }}{{'【' + item.工位名称 + '】' }}</div>
                <div style="text-align: left;margin-left: 10px;font-size: 16px">
                  <el-col :span="14">
                    <div style="height: 40px;line-height: 40px">今日累计：{{ item.今日累计 }}台</div>
                    <div style="height: 40px;line-height: 40px;color: #ff0000">今日报废：{{ item.今日报废 }}台</div>
                    <div style="height: 40px;line-height: 40px">昨日合格：{{ item.昨日合格 }}台</div>
                  </el-col>
                  <el-col :span="10">
                    <el-row style="margin-top: 20px">
                      <el-col :span="6">
                        <img src="../../img/productCount.png">
                      </el-col>
                      <el-col :span="18" style="font-size: 34px;font-weight: bolder">
                        <div style="color: #00893d">{{ item.今日合格 }}台</div>
                      </el-col>
                    </el-row>
                    <el-row>今日合格</el-row>
                  </el-col>
                </div>
                <div style="margin-left: 20px;">
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="产量详细" name="second" style="height: 867px">
          <span>工位号：</span>
          <el-select v-model="opnameThis" style="width:250px" multiple collapse-tags placeholder="工位号">
            <el-option
                v-for="item in opnames"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
          </el-select>
          <span style="margin-left: 10px">时间：</span>
          <el-date-picker v-model="deliveryDate" type="daterange" range-separator="至" start-placeholder="开始日期" value-format="yyyy-MM-dd" end-placeholder="结束日期" style="width:250px"/>
          <el-button :disabled="loading" type="success" plain icon="el-icon-search" style="margin-left: 10px" @click="searchTable()">查询</el-button>
<!--          <el-button :disabled="loading" type="warning" plain icon="el-icon-download" style="margin-left: 10px" @click="searchTable1()">导出</el-button>-->
          <div style="margin-top: 10px">
            <el-table
                v-loading="loading"
                :data="tableData"
                :header-cell-style="{background:'#F5F5F5'}"
                element-loading-text="数据加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.2)"
                tooltip-effect="dark"
                style="width: 100%"
                height="660"
                border
                highlight-current-row
                stripe>
              <el-table-column
                  type="index"
                  align="center"
                  width="100">
              </el-table-column>
              <el-table-column align="center" label="工位名称" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.工位名称 }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="产品编码" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.产品编码 }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="进站时间" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.进站时间 }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="出站时间" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.出站时间 }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="节拍(s)" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.停站时长 }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="合格标志" min-width="150">
                <template slot-scope="scope">
                  <span v-if="scope.row.合格标志 === 2" style="color: #ff0000;font-weight: bolder">不合格</span>
                  <span v-else style="color: #009e1c;font-weight: bolder">合格</span>
                </template>
              </el-table-column>
            </el-table>
            <div class="block" style="margin-top: 10px;">
              <el-pagination
                  v-if="!loading"
                  :current-page="PageCurrent"
                  :page-sizes="[50, 70, 100, 150]"
                  :page-size="pageSize"
                  :total="total"
                  layout="total, sizes, prev, pager, next, jumper"
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"/>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
      <span>上线时间：</span>
    </el-card>
  </div>
</template>
<script>
import { getNowTime2 } from '@/utils/tool'
export default {
  data() {
    return {
      opnameThis: '',
      opnames: [],
      activeName: 'first',
      orderData: {
        ORDER_CODE: '',
        QTY: '0',
        QTY_TODAY: '0',
        PRO_CODE: '',
        PLAN_START_DATE: '',
        PLAN_END_DATE: '',
        完成率: 0
      },
      addData: {
        Value: '',
        planDate: ''
      },
      editData: {
        planDate: '',
        Value: '',
        ID: '',
        disabled: true
      },
      daliyOutPutData_X: [],
      daliyOutPutData_Y: [],
      daliyOutPutData_Average: [],
      daliyOutPutData1_X: [],
      daliyOutPutData1_Y: [],
      daliyOutPutData1_Average: [],
      deliveryDate: [],
      loading: false,
      countList: [],
      tableData: [],
      total: 0, // 总条数
      pageSize: 50, // 每页显示条数
      PageCurrent: 1 // 后台获取页
    }
  },
  props: ['opname'],
  computed: {},
  mounted() {
    this.searchDayPlan()
    this.searchDayCount()
  },
  beforeDestroy() {
  },
  created() {
    this.searchTableOpName()
    const start = new Date()
    const end = new Date(start.getTime() - 3600 * 1000 * 24 * 20)
    this.deliveryDate[1] = getNowTime2(start)
    this.deliveryDate[0] = getNowTime2(end)
  },
  watch: {
  },
  methods: {
    searchTableOpName() {
      var param = []
      this.opnames = []
      var Data = this.CreateData('11', '工位管理_工位基础信息_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.opnames.push({
            label: response.data[i].工位号 + '-' + response.data[i].工位名称,
            value: response.data[i].工位号,
            id: response.data[i].GUID
          })
        }
      })
    },
    searchDayCount() {
      this.countList = []
      var param = []
      var Data = this.CreateData('11', '产量管理_今日产出_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.countList = response.data
        }
      })
    },
    searchDayPlan() {
      this.orderData = {}
      var param = []
      var Data = this.CreateData('11', '产量管理_今日计划_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.orderData.QTY = response.data[0]['QTY']
          this.orderData.PRO_CODE = response.data[0]['PRO_CODE']
          this.orderData.QTY_TODAY = response.data[0]['QTY_TODAY']
          this.orderData.ORDER_CODE = response.data[0]['ORDER_CODE']
          this.orderData.PLAN_END_DATE = response.data[0]['PLAN_END_DATE']
          this.orderData.PLAN_START_DATE = response.data[0]['PLAN_START_DATE']
          this.orderData.完成率 = response.data[0]['完成率']
        }
      })
    },
    searchTable() {
      if (!this.deliveryDate) {
        this.$message.warning('请选择查询时间')
        return
      }
      if (this.deliveryDate.length < 2) {
        this.$message.warning('请选择查询时间')
        return
      }
      if (this.deliveryDate[0] === '') {
        this.$message.warning('请选择查询时间')
        return
      }
      let op = ''
      if (this.opnameThis.length === 0) {
        for (const datum of this.opnames) {
          op += `${datum.value}","`
        }
      } else {
        for (const datum of this.opnameThis) {
          op += `${datum}","`
        }
      }
      op = '\'' + op.substring(0, op.length - 3).replaceAll('"', '\'') + '\''
      this.loading = true
      this.tableData = []
      var param = []
      param[0] = ['开始时间', this.deliveryDate[0]]
      param[1] = ['结束时间', this.deliveryDate[1]]
      param[2] = ['PageCurrent', this.PageCurrent]
      param[3] = ['PageSize', this.pageSize]
      param[4] = ['PageCount', '1111', 'int', '1']
      param[1] = ['结束时间', this.deliveryDate[1]]
      param[5] = ['ItemCount', '1111', 'int', '1']
      param[6] = ['工位号', op]
      var Data = this.CreateData('11', '产量管理_过站信息_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.result.length !== 0) {
          this.tableData = response.data.result
          this.total = parseInt(response.data.output[0].ItemCount)
        }
        this.loading = false
      })
    },
    searchTable1() {
      if (!this.deliveryDate) {
        this.$message.warning('请选择查询时间')
        return
      }
      if (this.deliveryDate.length < 2) {
        this.$message.warning('请选择查询时间')
        return
      }
      if (this.deliveryDate[0] === '') {
        this.$message.warning('请选择查询时间')
        return
      }
      this.tableData1 = []

      var param = []
      const blob = 'data:image/gif;base64,R0lGODlhCQACAIAAAMzMzP///yH5BAEAAAEALAAAAAAJAAIAAAIEjI9pUAA7'
      param[0] = ['开始时间', this.deliveryDate[0]]
      param[1] = ['结束时间', this.deliveryDate[1]]
      var Data = this.CreateData('2003', 'LG_临工看板_计划管理_每日计划导出', param)
      this.exportExcel_NPOI(Data, blob)
    },
    editPlanInfo(row) {
      this.editData.ID = row.ID
      this.editData.planDate = row.planDate
      this.editData.Value = row.Value
      this.editData.disabled = false
    },
    confirmEditData() {
      if (this.editData.Value === null) {
        this.$message.warning('请重新选择计划')
        return
      }
      if (this.editData.planDate === '') {
        this.$message.warning('请重新选择计划')
        return
      }

      var param = []
      param[0] = ['planDate', this.editData.planDate]
      param[1] = ['Value', this.editData.Value]
      var Data = this.CreateData('11', 'LG_临工看板_计划管理_每日计划新增', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          if (response.data[0]['result'] === 1) {
            this.$message.success('计划修改成功')
          } else if (response.data[0]['result'] === 2) {
            this.$message.success('计划修改成功')
          } else {
            this.$message.error('计划修改失败')
          }
          this.editData.ID = ''
          this.editData.planDate = ''
          this.editData.Value = 0
          this.editData.disabled = true
        }
        this.searchTable()
      })
    },
    confirmAddData() {
      const _this = this
      if (this.addData.Value === null) {
        this.$message.warning('请输入计划数')
        return
      }
      if (this.addData.planDate === '') {
        this.$message.warning('请选择计划时间')
        return
      }
      var param = []
      param[0] = ['planDate', this.addData.planDate]
      param[1] = ['Value', this.addData.Value]
      var Data = this.CreateData('11', 'LG_临工看板_计划管理_每日计划新增', param)
      this.ExecDatabase(Data).then(response => {
        if (!_this.deliveryDate) {
          _this.deliveryDate = [_this.addData.planDate, _this.addData.planDate]
        }
        if (_this.deliveryDate.length < 2) {
          _this.deliveryDate = [_this.addData.planDate, _this.addData.planDate]
        }
        if (_this.deliveryDate[0] === '') {
          _this.deliveryDate = [_this.addData.planDate, _this.addData.planDate]
        }
        if (response.data.length !== 0) {
          if (response.data[0]['result'] === 1) {
            this.$message.success('计划新增成功')
            this.addData.planDate = ''
            this.addData.Value = 0
          } else if (response.data[0]['result'] === 2) {
            this.$message.warning('计划存在，修改成功')
            this.addData.planDate = ''
            this.addData.Value = 0
          } else {
            this.$message.error('计划新增失败')
          }
        }

        this.searchTable()
      })
    },
    confirmDeleteData() {
      if (this.editData.Value === null) {
        this.$message.warning('请重新选择计划')
        return
      }
      if (this.editData.planDate === '') {
        this.$message.warning('请重新选择计划')
        return
      }

      var param = []
      param[0] = ['ID', this.editData.ID]
      var Data = this.CreateData('11', 'LG_临工看板_计划管理_每日计划删除', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          if (response.data[0]['result'] === 1) {
            this.$message.success('计划删除成功')
          } else {
            this.$message.error('计划删除失败')
          }
        }
        this.searchTable()
      })
    },
    handleSizeChange(val) {
      this.PageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.PageCurrent = val
      this.searchTable()
    }
  }
}
</script>
<style scoped>
.toolCard {
  text-align: center;
  font-size: 30px;
  margin: 10px 0 0 10px;
}
.planInfo{
  height: 100px;
  line-height: 50px;
  text-align: center;
  font-size: 32px;
  color: white;
  flex: 1;
  margin: 0 10px;
}
</style>

