<template>
  <div class="app-container">
    <div class="headTitle">京源环保生产管理系统</div>

    <div class="chartBox chartBox1">
      <div class="title">生产详细信息</div>
      <div class="chart">
        <div class="form">

          <el-form :model="form" label-position="right" label-width="80px">
            <el-form-item label="工单编号">
              <el-input v-model="form.planCode"></el-input>
            </el-form-item>
            <el-form-item label="明细编号">
              <el-input v-model="form.planDetailCode"></el-input>
            </el-form-item>
            <el-form-item label="成品名称">
              <el-input v-model="form.materialName"></el-input>
            </el-form-item>
            <el-form-item label="成品编号">
              <el-input v-model="form.materialCode"></el-input>
            </el-form-item>
            <el-form-item label="状态">
              <el-input v-model="form.planDetailStatus"></el-input>
            </el-form-item>
          </el-form>
          <div style="text-align: center">
            <el-button type="success" v-if="(!$route.query || $route.query.id!=='2')" :disabled="form.planDetailStatus === '已完成' || !form.planDetailCode" @click="getMaterials('0')">领料
            </el-button>
            <el-button type="primary" v-if="($route.query && $route.query.id) === '2'" :disabled="form.planDetailStatus === '已完成' || !form.planDetailCode" @click="getMaterials('1')">
              领柜体
            </el-button>
            <el-button v-if="($route.query && $route.query.id) === '2'" type="info" :disabled="form.planDetailStatus === '已完成' || !form.planDetailCode" @click="handleBindBarcode">绑定
            </el-button>
            <el-button v-if="($route.query && $route.query.id) === '2'" type="warning" :disabled="form.planDetailStatus === '已完成' || !form.planDetailCode"  @click="handleRawBack">返库
            </el-button>
            <el-button :disabled="form.planDetailStatus === '已完成' || !form.planDetailCode" type="primary" @click="finish">完成</el-button>
            <el-popover
              v-if="($route.query && $route.query.id) === '2'"
              v-model="assignModel"
              placement="top"
              style="margin-left: 10px"
              trigger="click"
              width="400">
              <el-form ref="assignTaskForm" :model="assignTaskForm" :rules="assignTaskRules" label-width="80px">
                <el-form-item label="成品条码" prop="materialBarcode">
                  <el-input v-model="assignTaskForm.materialBarcode"></el-input>
                </el-form-item>
                <el-form-item label="工位">
                  <el-radio-group v-model="assignTaskForm.stationId">
                    <el-radio v-for="i in stationData" :label="i.stationId" :value="i.stationId" :key="i.stationId">
                      {{ i.stationName }}
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-form>
              <div style="float:right;margin-top: 8px">
                <el-button type="primary" :loading="submitAssignLoading" @click="completeStation">确 定</el-button>
              </div>
              <el-button slot="reference" type="success" :disabled="form.planDetailStatus === '已完成' || !form.planDetailCode">下发
              </el-button>
            </el-popover>

          </div>
        </div>

      </div>
      <div class="chart1">
        <Chart ref="chart1_1"></Chart>
      </div>
      <div class="chart2">
        <Chart ref="chart1_2"></Chart>
      </div>
      <div class="chart3">
        <Chart ref="chart1_3"></Chart>
      </div>
      <div class="chart4">
        <Chart ref="chart1_4"></Chart>
      </div>
    </div>

    <div class="chartBox chartBox2">
      <div class="title">库存统计</div>
      <div class="chart">
        <Chart ref="chart2"></Chart>
      </div>
    </div>

    <div class="chartBox chartBox3">
      <div class="title">生产派工</div>
      <div class="chart">
        <div class="whiteTable">
          <el-table
            :cell-style="{textAlign:'center'}"
            :data="tableData"
            :header-cell-style="{textAlign:'center'}"
            :max-height="19.13 * vw"
            highlight-current-row
            style="width: 100%"
            @current-change="tableClick"
          >
            <el-table-column
              label="序号"
              type="index"
              width="50"
            >
            </el-table-column>
            <el-table-column
              label="工单编号"
              prop="planCode"
            >
            </el-table-column>
            <el-table-column
              label="物料名称"
              prop="materialName"
              width="100"
            >
            </el-table-column>
            <el-table-column
              label="计划"
              prop="planAmount"
              width="100"
            >
            </el-table-column>
            <el-table-column
              label="实际"
              prop="completeAmount"
              width="100"
            >
            </el-table-column>
            <el-table-column
              label="差异"
              prop="difference"
              width="100"
            >
              <template slot-scope="scope">
                {{ scope.row.planAmount - scope.row.completeAmount }}
              </template>
            </el-table-column>
            <el-table-column
              label="交付时间"
              prop="planDeliveryDate"
              width="150"
            >
            </el-table-column>
            <el-table-column
              label="操作"
              width="120"
            >
              <template slot-scope="scope">
                <el-button
                  v-if="($route.query && $route.query.id) === '2'"
                  size="small"
                  style="margin-right: 12px"
                  type="text"
                  @click="print(scope.row)"
                >
                  条码打印
                </el-button>
                <!--                <el-button-->
                <!--                  size="small"-->
                <!--                  type="text"-->
                <!--                >-->
                <!--                  SOP预览-->
                <!--                </el-button>-->

<!--                <el-popconfirm-->
<!--                  v-if="($route.query && $route.query.id) === '2'"-->
<!--                  cancel-button-text='否'-->
<!--                  confirm-button-text='是'-->
<!--                  icon="el-icon-info"-->
<!--                  icon-color="red"-->
<!--                  title="确定开始计划吗？"-->
<!--                  @confirm="startPlan(scope.row)"-->
<!--                >-->
<!--                  <el-button-->
<!--                    slot="reference"-->
<!--                    size="small"-->
<!--                    type="text">开始-->
<!--                  </el-button>-->
<!--                </el-popconfirm>-->

                <el-popover
                  placement="top"
                  title="标题"
                  width="400"
                  ref="popoverRef"
                  v-if="($route.query && $route.query.id) !== '2'"
                  trigger="click">
                  <div>
                    <div style="margin: 15px 0;">
                      <el-input placeholder="请输入物料条码" v-model="input1" class="input-with-select">
                        <el-button slot="append" icon="el-icon-full-screen"></el-button>
                      </el-input>
                    </div>
                    <div style="text-align: right; margin: 0">
                      <el-button size="mini" type="text" @click="closePopover">取消</el-button>
                      <el-button type="primary" size="mini" @click="startPlan1(scope.row)">确定</el-button>
                    </div>
                  </div>
                  <el-button
                    slot="reference"
                    size="small"
                    @click="input1 = null"
                    type="text">开始
                  </el-button>
                </el-popover>

              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div>
      <div class="roundBorder" style="top: 72%;left: 1.2%;">
        <el-button :disabled="nowNum1 <= 1" circle icon="el-icon-back" size="mini" @click="pre1"></el-button>
      </div>
      <div class="roundBorder" style="top: 72%;left: 49%;">
        <el-button :disabled="nowNum1 >= totalNum1" circle icon="el-icon-right" size="mini" @click="next1"></el-button>
      </div>
    </div>

    <div class="chartBox chartBox4">
      <div class="title">每周产量</div>
      <div class="chart">
        <Chart ref="chart4"></Chart>
      </div>
    </div>

    <div class="bottom">
      <el-row>
        <el-button type="primary">首页</el-button>
        <!--        <el-button type="success" @click="getMaterialsModel = true">条码打印</el-button>-->
        <el-button type="info">SOP预览</el-button>
        <el-button type="danger" @click="logout">退出</el-button>
      </el-row>
    </div>


    <el-dialog
      :visible.sync="dialogVisible"
      :title="applyMaterialTitle"
      width="40%">
      <el-form ref="form" :model="form1" label-width="100px">
        <el-form-item label="工单编号">
          <el-input v-model="form1.planCode" disabled></el-input>
        </el-form-item>
        <el-form-item label="明细编号">
          <el-input v-model="form1.planDetailCode" disabled></el-input>
        </el-form-item>
        <el-form-item label="仓库">
          <el-select v-model="form1.warehouseId" placeholder="请选择仓库" @change="warehouseChange">
            <el-option v-for="item in warehouseList" :key="item.warehouseId" :label="item.warehouseName"
                       :value="item.warehouseId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="领取原因">
          <el-input v-model="form1.applyReason" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <el-table
        :cell-style="{textAlign:'center'}"
        :data="form1.wmsRawOutstockDetailList"
        :header-cell-style="{textAlign:'center'}"
        max-height="19.13vw"
        style="width: 100%"
      >
        <el-table-column
          label="物料编号"
          prop="materialCode"
        >
        </el-table-column>
        <el-table-column
          label="物料名称"
          prop="materialName"
        >
        </el-table-column>
        <el-table-column
          label="可用库存数量"
          prop="availableAmount"
        >
        </el-table-column>
        <el-table-column
          label="占用库存数量"
          prop="unavailableAmount"
        >
        </el-table-column>
        <el-table-column
          label="领取数量"
          prop="planAmount"
          width="120"
        >
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.planAmount"
              :min="1"
              :disabled="planAmountDisabled"
              controls-position="right"
              style="width: 100%"
            >
            </el-input>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          width="160"
        >
          <template slot="header" slot-scope="scope">
            <el-input
              v-model="searchMaterialValue"
              placeholder="输入物料名称搜索"
              size="mini"
              @change="searchMaterial"/>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align: center;margin-top: 12px">
        <el-button type="primary" @click="receiveMaterial">申请领柜体</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="printModel" class="dialog" title="条码打印" width="80%">
      <div style="height: 50vh;">
        <PrintPage :defineData="PrintData"/>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="printModel = false">关闭</el-button>
      </div>
    </el-dialog>


    <el-dialog
      :visible.sync="bindBarcodeVisible"
      title="柜体绑定"
      width="40%">
      <el-form ref="bindBarcodeForm" :model="bindBarcodeForm" :rules="bindBarcodeRules" label-width="80px">
        <el-form-item label="成品条码" prop="productBarcode">
          <el-input v-model="bindBarcodeForm.productBarcode"></el-input>
        </el-form-item>
        <el-form-item label="物料条码" prop="materialBarcode">
          <el-input v-model="bindBarcodeForm.materialBarcode"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitBindBarcode">确 定</el-button>
        <el-button @click="cancelBindBarcode">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="rawBackVisible"
      title="柜体返库"
      width="40%">
      <el-form ref="rawBackForm" :model="rawBackForm" :rules="rawBackRules" label-width="80px">
        <el-form-item label="返库仓库" prop="warehouseId">
          <el-select v-model="rawBackForm.warehouseId" placeholder="请选择返库仓库">
            <el-option v-for="item in warehouseList" :key="item.warehouseId" :label="item.warehouseName"
                       :value="item.warehouseId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料条码" prop="materialBarcode">
          <el-input v-model="rawBackForm.materialBarcode"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRawBack">确 定</el-button>
        <el-button @click="cancelRawBack">取 消</el-button>
      </div>
    </el-dialog>


    <!--    <el-dialog :visible.sync="assignModel" title="工位选择" width="80%">-->

    <!--      <el-table :data="stationData" highlight-current-row-->
    <!--                @current-change="stationChange"-->
    <!--      >-->
    <!--        <el-table-column align="center" label="主键标识" prop="planId"/>-->
    <!--        <el-table-column align="center" class-name="small-padding fixed-width" label="操作">-->
    <!--          <template slot-scope="scope">-->
    <!--            <el-button-->
    <!--              v-hasPermi="['mes:productplan:edit']"-->
    <!--              icon="el-icon-edit"-->
    <!--              size="mini"-->
    <!--              type="text"-->
    <!--              @click="handleUpdate(scope.row)"-->
    <!--            >修改-->
    <!--            </el-button>-->
    <!--            <el-button-->
    <!--              v-hasPermi="['mes:productplan:remove']"-->
    <!--              icon="el-icon-delete"-->
    <!--              size="mini"-->
    <!--              type="text"-->
    <!--              @click="handleDelete(scope.row)"-->
    <!--            >删除-->
    <!--            </el-button>-->
    <!--          </template>-->
    <!--        </el-table-column>-->
    <!--      </el-table>-->
    <!--      <div slot="footer" class="dialog-footer">-->
    <!--        <el-button type="primary" @click="completeStation ">确 定</el-button>-->
    <!--        <el-button @click="assignModel = false">关 闭</el-button>-->
    <!--      </div>-->
    <!--    </el-dialog>-->
  </div>
</template>

<script>
import PrintPage from '@/views/mes/barcode/endProductIndex'
import Chart from '@/components/board/Chart'
import * as echarts from 'echarts'
import {
  completeProductPlanDetail,
  getNewestProductPlanDetail,
  getProductPlans,
  startNextProductPlanDetail,
  applyRawOutstock,
  getStockTotal,
  getWarehouses,
  bindBarcode,
  applyRawBack,
  assignTask
} from "@/api/board";

const setState = (e) => {
  if (e === '1') {
    return '未开始'
  }
  if (e === '2') {
    return '已开始'
  }
  if (e === '3' || e === '9') {
    return '已完成'
  }
}
const vw = (document.documentElement.clientWidth || document.body.clientWidth) / 100
export default {
  name: 'Board1',
  components: {
    Chart,
    PrintPage
  },
  data() {
    return {
      input1:null,
      PrintData: {},
      printModel: false,
      assignModel: false,
      nowNum1: 1,
      totalNum1: 0,
      getMaterialsModel: false,
      applyMaterialTitle: '',
      planAmount : null,
      planAmountDisabled : true,
      taskType:'',
      dialogVisible: false,
      form: {},
      form1: {},
      assignTaskForm: {
        materialBarcode: null,
        stationId: null
      },
      assignTaskRules: {
        materialBarcode: [
          {required: true, message: "物料条码不能为空", trigger: "blur"}
        ],
        stationId: [
          {required: true, message: "工位不能为空", trigger: "change"}
        ],
      },
      submitAssignLoading: false,

      tableData: [],
      nowStation: null,
      stationData: [
        {
          stationName: '五楼装配工位1',
          stationId: 521,
        },
        {
          stationName: '五楼装配工位2',
          stationId: 522,
        },
        {
          stationName: '五楼装配工位3',
          stationId: 523,
        },
        {
          stationName: '五楼装配工位4',
          stationId: 524,
        },
        {
          stationName: '五楼装配工位5',
          stationId: 525,
        },
        {
          stationName: '五楼装配工位6',
          stationId: 526,
        },
      ],
      warehouseList: [],
      searchMaterialValue: '',
      vw: (document.documentElement.clientWidth || document.body.clientWidth) / 100,

      bindBarcodeVisible: false,
      bindBarcodeForm: {
        productBarcode: null,
        materialBarcode: null
      },
      bindBarcodeRules: {
        productBarcode: [
          {required: true, message: "成品条码不能为空", trigger: "blur"}
        ],
        materialBarcode: [
          {required: true, message: "物料条码不能为空", trigger: "blur"}
        ],
      },

      rawBackVisible: false,
      rawBackForm: {
        materialBarcode: null,
        warehouseId: null
      },
      rawBackRules: {
        materialBarcode: [
          {required: true, message: "物料条码不能为空", trigger: "blur"}
        ],
        warehouseId: [
          {required: true, message: "仓库不能为空", trigger: "change"}
        ]
      }
    }
  },
  async mounted() {
    getProductPlans({pageNum: this.nowNum1, pageSize: 5}).then(e => {
      this.tableData = e.rows
      this.totalNum1 = Math.ceil(e.total / 5)
      this.tableClick(e.rows[0])
    })
    this.$refs.chart2.setData({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          // 坐标轴指示器，坐标轴触发有效
          type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
        }
      },
      grid: {
        left: '0',
        right: '4%',
        bottom: '0',
        top: 20,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        data: [1, 2, 3, 4, 5, 6],
        axisLine: {
          lineStyle: {
            color: 'white'
          }
        },
        axisLabel: {
          // interval: 0,
          // rotate: 40,
          textStyle: {
            fontFamily: 'Microsoft YaHei'
          }
        }
      },

      yAxis: {
        type: 'value',
        axisLine: {
          show: false,
          lineStyle: {
            color: 'white'
          }
        },
        splitLine: {
          show: false
        },
        axisLabel: {}
      },
      series: [
        {
          name: '数量',
          label: {
            normal: {
              show: true,
              position: 'top',
              textStyle: {
                color: '#a8aab0',
                fontStyle: 'normal',
                fontFamily: '微软雅黑',
                fontSize: 0.75 * vw
              }
            }
          },
          type: 'bar',
          barWidth: '30%',
          barMaxWidth: 50,
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: '#39ffff'
                },
                {
                  offset: 1,
                  color: '#5affa6'
                }
              ])
            }
          },
          data: [1, 2, 3, 4, 5, 6]
        }
      ]
    })
    this.$refs.chart4.setData({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          // 坐标轴指示器，坐标轴触发有效
          type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
        }
      },
      grid: {
        left: '0',
        right: '4%',
        bottom: '0',
        top: 20,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        data: [1, 2, 3, 4, 5, 6],
        axisLine: {
          lineStyle: {
            color: 'white'
          }
        },
        axisLabel: {
          // interval: 0,
          // rotate: 40,
          textStyle: {
            fontFamily: 'Microsoft YaHei'
          }
        }
      },

      yAxis: {
        type: 'value',
        axisLine: {
          show: false,
          lineStyle: {
            color: 'white'
          }
        },
        splitLine: {
          show: false
        },
        axisLabel: {}
      },
      series: [
        {
          name: '数量',
          label: {
            normal: {
              show: true,
              position: 'top',
              textStyle: {
                color: '#a8aab0',
                fontStyle: 'normal',
                fontFamily: '微软雅黑',
                fontSize: 0.75 * vw
              }
            }
          },
          type: 'bar',
          barWidth: '30%',
          barMaxWidth: 50,
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: '#39ffff'
                },
                {
                  offset: 1,
                  color: '#5affa6'
                }
              ])
            }
          },
          data: [1, 2, 3, 4, 5, 6]
        }
      ]
    })
  },
  methods: {

    async logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.href = '/login?isStationId=true';
        })
      }).catch(() => {
      });
    },
    next1() {
      this.nowNum1 += 1
      getProductPlans({pageNum: this.nowNum1, pageSize: 5}).then(e => {
        this.tableData = e.rows
        this.totalNum1 = Math.ceil(e.total / 5)
      })
    },
    pre1() {
      this.nowNum1 -= 1
      getProductPlans({pageNum: this.nowNum1, pageSize: 5}).then(e => {
        this.tableData = e.rows
        this.totalNum1 = Math.ceil(e.total / 5)
      })
    },
    async startPlan(val) {

      const data = await startNextProductPlanDetail({planId: val.planId})
      if (data.code === 200) {
        this.$message({
          message: '已开始',
          type: 'success'
        });
      }
      this.form = data.data || {}
      this.form.materialId = val.materialId
      this.form.materialCode = val.materialCode
      this.form.materialName = val.materialName
      this.form.planDetailStatus = setState(data.data.planDetailStatus)
      this.getInfo(val)
    },
    closePopover(){
      document.body.click()
    },
    async startPlan1(val) {
      console.log(this.input1)
      console.log(val)
      document.body.click()

      // const data = await startNextProductPlanDetail({planId: val.planId})
      // if (data.code === 200) {
      //   this.$message({
      //     message: '已开始',
      //     type: 'success'
      //   });
      // }
      // this.form = data.data || {}
      // this.form.materialId = val.materialId
      // this.form.materialCode = val.materialCode
      // this.form.materialName = val.materialName
      // this.form.planDetailStatus = setState(data.data.planDetailStatus)
      // this.getInfo(val)
    },
    async tableClick(val) {
      if (!val) return
      const {data} = await getNewestProductPlanDetail({planId: val.planId})
      this.form = data || {}
      this.form.materialId = val.materialId
      this.form.materialCode = val.materialCode
      this.form.materialName = val.materialName
      this.form.planDetailStatus = setState(data.planDetailStatus)
      this.getInfo(val)
    },
    stationChange(val) {
      this.nowStation = val
    },


    // 下发柜体任务表单重置
    resetAssignTask() {
      this.assignTaskForm = {
        materialBarcode: null,
        stationNo: null
      };
      this.resetForm("assignTaskForm");
    },

    cancelAssignTask() {
      this.assignModel = false;
      this.submitAssignLoading = false;
      this.resetAssignTask();
    },


    completeStation() {
      this.submitAssignLoading = true;
      this.$refs["assignTaskForm"].validate(valid => {
        if (valid) {
          assignTask(this.assignTaskForm).then(response => {
            this.$modal.msgSuccess("下发成功");
            this.cancelAssignTask();
          }).catch(() => {
            this.submitAssignLoading = false;
          });
        }
      });

    },


    getInfo(e) {
      this.$refs.chart1_1.setData({
        series: [
          {
            type: "pie",
            clockWise: false,
            radius: ['60%', '75%'],
            itemStyle: {
              normal: {
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                shadowBlur: 0,
                shadowColor: "#aa8e2c",
              },
            },
            hoverAnimation: false,
            center: ["50%", "50%"],
            data: [
              {
                value: e.planAmount === 0 ? 0.0001 : e.planAmount,
                label: {
                  normal: {
                    rich: {
                      a: {
                        color: "#aa8e2c",
                        align: "center",
                        fontSize: 1.1 * vw,
                        fontWeight: "bold",
                      },
                      b: {
                        color: "#fff",
                        align: "center",
                        fontSize: 0.9 * vw,
                      },
                    },
                    formatter: function (params) {
                      return (
                        "{a|" +
                        (params.data.value === 0.0001 ? 0 : params.data.value) +
                        "}" +
                        "\n{b|计划}"
                      );
                    },
                    position: "center",
                    show: true,
                    textStyle: {
                      fontSize: "14",
                      fontWeight: "normal",
                      color: "#fff",
                    },
                  },
                },
                itemStyle: {
                  normal: {
                    color: "#aa8e2c",
                    shadowColor: "#aa8e2c",
                    shadowBlur: 0,
                  },
                },
              },
              {
                value: 0,
                name: "invisible",
                itemStyle: {
                  normal: {
                    color: "#412a4e",
                  },
                  emphasis: {
                    color: "#412a4e",
                  },
                },
              },
            ],
          },
        ],
      })
      this.$refs.chart1_2.setData({
        series: [
          {
            type: "pie",
            clockWise: false,
            radius: ['60%', '75%'],
            itemStyle: {
              normal: {
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                shadowBlur: 0,
                shadowColor: "#389af4",
              },
            },
            hoverAnimation: false,
            center: ["50%", "50%"],
            data: [
              {
                value: e.completeAmount === 0 ? 0.0001 : e.completeAmount,
                label: {
                  normal: {
                    rich: {
                      a: {
                        color: "#389af4",
                        align: "center",
                        fontSize: 1.1 * vw,
                        fontWeight: "bold",
                      },
                      b: {
                        color: "#fff",
                        align: "center",
                        fontSize: 0.9 * vw,
                      },
                    },
                    formatter: function (params) {
                      return (
                        "{a|" +
                        (params.data.value === 0.0001 ? 0 : params.data.value) +
                        "}" +
                        "\n{b|实际}"
                      );
                    },
                    position: "center",
                    show: true,
                    textStyle: {
                      fontSize: "14",
                      fontWeight: "normal",
                      color: "#fff",
                    },
                  },
                },
                itemStyle: {
                  normal: {
                    color: "#389af4",
                    shadowColor: "#389af4",
                    shadowBlur: 0,
                  },
                },
              },
              {
                value: 0,
                name: "invisible",
                itemStyle: {
                  normal: {
                    color: "#412a4e",
                  },
                  emphasis: {
                    color: "#412a4e",
                  },
                },
              },
            ],
          },
        ],
      })
      this.$refs.chart1_3.setData({
        series: [
          {
            type: "pie",
            clockWise: false,
            radius: ['60%', '75%'],
            itemStyle: {
              normal: {
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                shadowBlur: 0,
                shadowColor: "#ff0000",
              },
            },
            hoverAnimation: false,
            center: ["50%", "50%"],
            data: [
              {
                value: Math.abs((e.planAmount - e.completeAmount) === 0 ? 0.0001 : (e.planAmount - e.completeAmount)),
                label: {
                  normal: {
                    rich: {
                      a: {
                        color: "#ff0000",
                        align: "center",
                        fontSize: 1.1 * vw,
                        fontWeight: "bold",
                      },
                      b: {
                        color: "#fff",
                        align: "center",
                        fontSize: 0.9 * vw,
                      },
                    },
                    formatter: function (params) {
                      return (
                        "{a|" +
                        (params.data.value === 0.0001 ? 0 : params.data.value) +
                        "}" +
                        "\n{b|差异}"
                      );
                    },
                    position: "center",
                    show: true,
                    textStyle: {
                      fontSize: "14",
                      fontWeight: "normal",
                      color: "#fff",
                    },
                  },
                },
                itemStyle: {
                  normal: {
                    color: "#b32b2b",
                    shadowColor: "#ff0000",
                    shadowBlur: 0,
                  },
                },
              },
              {
                value: 0,
                name: "invisible",
                itemStyle: {
                  normal: {
                    color: "#412a4e",
                  },
                  emphasis: {
                    color: "#412a4e",
                  },
                },
              },
            ],
          },
        ],
      })
      this.$refs.chart1_4.setData({
        series: [
          {
            type: "pie",
            clockWise: false,
            radius: ['60%', '75%'],
            itemStyle: {
              normal: {
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                shadowBlur: 0,
                shadowColor: "#00ff00",
              },
            },
            hoverAnimation: false,
            center: ["50%", "50%"],
            data: [
              {
                value: ((e.completeAmount / e.planAmount) * 100).toFixed(2),
                label: {
                  normal: {
                    rich: {
                      a: {
                        color: "#00ff00",
                        align: "center",
                        fontSize: 1.1 * vw,
                        fontWeight: "bold",
                      },
                      b: {
                        color: "#fff",
                        align: "center",
                        fontSize: 0.9 * vw,
                      },
                    },
                    formatter: function (params) {
                      return (
                        "{a|" +
                        (params.data.value === 0.0001 ? 0 : params.data.value) +
                        "%}" +
                        "\n{b|完成率}"
                      );
                    },
                    position: "center",
                    show: true,
                    textStyle: {
                      fontSize: "14",
                      fontWeight: "normal",
                      color: "#fff",
                    },
                  },
                },
                itemStyle: {
                  normal: {
                    color: "#3ac13a",
                    shadowColor: "#00ff00",
                    shadowBlur: 0,
                  },
                },
              },
              {
                value: ((1 - (e.completeAmount / e.planAmount)) * 100).toFixed(2),
                name: "invisible",
                itemStyle: {
                  normal: {
                    color: "#412a4e",
                  },
                  emphasis: {
                    color: "#412a4e",
                  },
                },
              },
            ],
          },
        ],
      })
    },
    async finish() {

      this.$confirm('确认计划完成?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const data = await completeProductPlanDetail({
          planDetailId: this.form.planDetailId
        })
        if (data.code === 200) {
          this.$message({
            message: '已完成',
            type: 'success'
          });
        }
        getProductPlans({pageNum: this.nowNum1, pageSize: 5}).then(e => {
          this.tableData = e.rows
          this.totalNum1 = Math.ceil(e.total / 5)
          this.tableClick(e.rows.find(v => v.planCode === this.form.planCode))
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    getOrderInfo(e) {
      this.getInfo(e)
      getNewestProductPlanDetail({planId: e.planId}).then(val => {
        this.form = val.data
        this.form.materialId = e.materialId
        this.form.materialName = e.materialName
        this.form.planDetailStatus = setState(val.data.planDetailStatus)
      })
    },

    // 领柜体页面
    getMaterials(returnFlag) {
      if (returnFlag == '1') {
        this.applyMaterialTitle = "领柜体";
        this.planAmount = 1;
        this.planAmountDisabled = true;
        this.taskType = '2';//拆分出库
      } else {
        this.applyMaterialTitle = "领料";
        this.planAmount = null;
        this.planAmountDisabled = false;
        this.taskType='1';//生产领料
      }

      this.searchMaterialValue = ''
      this.dialogVisible = true
      this.form1 = {
        warehouseId: '',
        planId: this.form?.planId,
        planCode: this.form?.planCode,
        planDetailCode: this.form?.planDetailCode,
        applyReason: '',
        taskType: '1',
        wmsRawOutstockDetailList: []
      }
      // 获取仓库信息
      getWarehouses({"warehouseFloor": 5, "returnFlag": returnFlag}).then(e => {
        this.warehouseList = e.data
        this.form1.warehouseId = e.data[0]?.warehouseId
        this.searchMaterial();
      })

    },

    // 物料搜索
    searchMaterial(val) {
      if (this.form1.warehouseId == null || this.form1.warehouseId == undefined
        || this.form1.warehouseId == "") {
        return;
      }
      getStockTotal({
        warehouseId: this.form1.warehouseId,
        materialName: val
      }).then(e => {
        this.form1.wmsRawOutstockDetailList = e.data.map(r => {
          return {
            materialId: r.materialId,
            materialCode: r.materialCode,
            materialName: r.materialName,
            availableAmount: r.totalAmount - r.occupyAmount - r.frozenAmount,
            unavailableAmount: r.occupyAmount + r.frozenAmount,
            planAmount: this.planAmount
          }
        })
      })
    },


    warehouseChange(warehouseId) {
      this.form.wmsRawOutstockDetailList = [];
      this.form.warehouseId = warehouseId;
      this.searchMaterial('');
    },

    receiveMaterial() {
      this.form1.taskType = this.taskType;
      applyRawOutstock(this.form1).then(e => {
        if (e.code === 200) {
          this.dialogVisible = false
          this.$message({
            message: '申请领柜体成功',
            type: 'success'
          });
        }
      })
    },

    print(val) {
      this.PrintData = val
      this.printModel = true
    },
    assignClick() {
      this.assignModel = true
    },


    // 表单重置
    resetBindBarcode() {
      this.bindBarcodeForm = {
        productBarcode: null,
        materialBarcode: null,
        planCode: this.form.planCode,
        planDetailCode: this.form.planDetailCode
      };
      this.resetForm("bindBarcodeForm");
    },

    /** 柜体绑定按钮操作 */
    handleBindBarcode() {
      this.resetBindBarcode();
      this.bindBarcodeVisible = true;
    },

    submitBindBarcode() {
      this.$refs["bindBarcodeForm"].validate(valid => {
        if (valid) {
          bindBarcode(this.bindBarcodeForm).then(response => {
            this.$modal.msgSuccess("绑定成功");
            this.cancelBindBarcode();
          });
        }
      });
    },

    cancelBindBarcode() {
      this.bindBarcodeVisible = false;
      this.resetBindBarcode();
    },


    // 表单重置
    resetRawBack() {
      this.rawBackForm = {
        materialBarcode: null,
        warehouseId: null
      };
      this.resetForm("rawBackForm");
    },

    /** 柜体返库按钮操作 */
    handleRawBack(scope) {
      this.resetRawBack();
      // 获取仓库信息
      if (this.warehouseList == null || this.warehouseList.length == 0) {
        getWarehouses({"warehouseFloor": 5, "returnFlag": 1}).then(e => {
          this.warehouseList = e.data
          this.rawBackForm.warehouseId = this.warehouseList[0]?.warehouseId
        })
      } else {
        this.rawBackForm.warehouseId = this.warehouseList[0]?.warehouseId
      }

      this.rawBackVisible = true;
    },


    submitRawBack() {
      this.$refs["rawBackForm"].validate(valid => {
        if (valid) {
          applyRawBack(this.rawBackForm).then(response => {
            this.$modal.msgSuccess("申请成功");
            this.cancelRawBack();
          });
        }
      });
    },

    cancelRawBack() {
      this.rawBackVisible = false;
      this.resetRawBack();
    },

  }
}
</script>
<style lang="less" scoped>

.app-container {
  background-image: url("../../../assets/board/bg.jpg");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.headTitle {
  position: absolute;
  top: 5%;
  left: 50%;
  transform: translate(-50%, -100%);
  font-size: 1.5vw;
  color: #d6eaed;
  letter-spacing: 10px;
}

.el-table {
  background-color: #fff0;
}

.whiteTable {
  /deep/ .el-table .el-table__header-wrapper th {
    background-color: #fff0;
  }

  /deep/ .el-table tr {
    background-color: #fff0;
  }

  /deep/ .el-table .cell {
    color: #fff
  }

  /deep/ .current-row .cell {
    color: #000
  }

  /deep/ .el-table--enable-row-hover .el-table__body tr:hover > td.el-table__cell {
    background-color: #fff0;
  }
}

.chartBox {
  background-image: url("../../../assets/board/box.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  position: absolute;
  width: 46%;
  height: 23.34vw;

  .title {
    position: absolute;
    top: 8%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2vw;
    color: #ccc;
  }

  .chart {
    position: absolute;
    top: 16%;
    left: 1%;
    width: 98%;
    height: 82%;
  }
}

.chartBox1 {
  top: 10%;
  left: 2%;

  .chart1 {
    position: absolute;
    top: 16%;
    left: 60%;
    width: 20%;
    height: 35%;
  }

  .chart2 {
    position: absolute;
    top: 16%;
    left: 80%;
    width: 20%;
    height: 35%;
  }

  .chart3 {
    position: absolute;
    top: 55%;
    left: 60%;
    width: 20%;
    height: 35%;
  }

  .chart4 {
    position: absolute;
    top: 55%;
    left: 80%;
    width: 20%;
    height: 35%;
  }
}

.chartBox2 {
  top: 10%;
  right: 2%;
}

.chartBox3 {
  top: 53%;
  left: 2%;
}

.chartBox4 {
  top: 53%;
  right: 2%;
}

.bottom {
  position: absolute;
  bottom: 1.5%;
  left: 2%;
}

.form {
  position: absolute;
  width: 50%;
  height: 100%;
  top: 2%;
  left: 2%;

  /deep/ .el-form-item__label {
    color: #fff;
    font-weight: 500;
  }

  /deep/ .el-input__inner {
    color: #fff;
    background-color: #0000;
    border: none;
    border-bottom: 1px solid #fff9;
    border-radius: 0;
  }
}

.roundBorder {
  position: absolute;
  transform: translate(-50%, -50%);
}

/deep/ .dialog .app-container {
  background: none !important;
  position: static;
}

/deep/ .dialog .el-dialog__body {
  padding: 0 !important;
}
</style>
