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

    <div class="chartBox chartBox1">
      <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"
            style="width: 100%"
            ref="planTable"
            highlight-current-row
          >
            <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="materialSpec"
              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
                  size="small"
                  type="text"
                  @click="SOP(scope.row)"
                >
                  SOP预览
                </el-button>

                <el-button
                  size="small"
                  type="text"
                  @click="getDetail(scope)"
                >
                  明细
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div>
      <div class="roundBorder" style="top: 32%;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: 32%;left: 49%;">
        <el-button :disabled="nowNum1 >= totalNum1" circle icon="el-icon-right" size="mini" @click="next1"></el-button>
      </div>
    </div>

    <div class="chartBox chartBox2">
      <div class="title">物料安装情况(已完成)</div>
      <div class="chart">
        <div class="whiteTable">
          <el-table
            :cell-style="{textAlign:'center'}"
            :data="tableData2"
            :header-cell-style="{textAlign:'center'}"
            :max-height="19.13 * vw"
            style="width: 100%"
          >
            <el-table-column
              label="序号"
              type="index"
              width="50"
            >
            </el-table-column>
            <el-table-column
              label="物料编码"
              prop="materialCode"
            >
            </el-table-column>
            <el-table-column
              label="物料名称"
              prop="materialName"
            >
            </el-table-column>
            <el-table-column
              label="完成数量"
              prop="checkAmount"
              width="100"
            >
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div>
      <div class="roundBorder" style="top: 32%;left: 51%;">
        <el-button :disabled="nowNum2 <= 1" circle icon="el-icon-back" size="mini" @click="pre2"></el-button>
      </div>
      <div class="roundBorder" style="top: 32%;left: 98.8%;">
        <el-button :disabled="nowNum2 >= totalNum2" circle icon="el-icon-right" size="mini" @click="next2"></el-button>
      </div>
    </div>

    <div class="chartBox chartBox3">
      <div class="title">生产明细</div>
      <div class="chart">
        <div class="whiteTable">
          <el-table
            highlight-current-row
            @current-change="getMaterialInstall"
            :cell-style="{textAlign:'center'}"
            :data="tableData1"
            :header-cell-style="{textAlign:'center'}"
            :max-height="19.13 * vw"
            style="width: 100%"
            ref="table"

          >
            <el-table-column
              label="序号"
              type="index"
              width="50"
            >
            </el-table-column>
            <el-table-column
              label="派工单号"
              prop="planCode"
              width="80"
            >
            </el-table-column>
            <el-table-column
              label="明细编号"
              prop="planDetailCode"
            >
            </el-table-column>
            <el-table-column
              label="开始时间"
              prop="realBeginTime"
              width="150"
            >
            </el-table-column>
            <el-table-column
              label="结束时间"
              prop="realEndTime"
              width="150"
            >
            </el-table-column>
            <el-table-column
              label="状态"
              prop="createTime"
              width="80"
            >
              <template slot-scope="scope">
                <dict-tag :options="dict.type.mes_plan_detail_status" :value="scope.row.planDetailStatus"/>
              </template>

            </el-table-column>
            <el-table-column
              label="操作"
              width="160"
            >
              <template slot-scope="scope">
                <el-button
                  v-if="scope.row.planDetailStatus !== '3' && scope.row.planDetailStatus !== '9'"
                  size="small"
                  type="text"
                  @click="planExecute(scope.row)"
                >
                  {{ scope.row.planDetailStatus === '1' ? '开始' : '完成' }}
                </el-button>
                <el-button
                  v-if="scope.row.planDetailStatus ===  PLAN_DETAIL_STATUS.STARTED"                  size="small"
                  type="text"
                  @click="getMaterials(scope.row) "
                >
                  领料
                </el-button>
                <el-button
                  v-if="scope.row.planDetailStatus ===  PLAN_DETAIL_STATUS.STARTED"
                  size="small"
                  type="text"
                  @click="handleMaterialConfirmForm(scope)"
                >
                  扫描
                </el-button>
                <el-button
                  size="small"
                  type="text"
                  @click="returnMaterial(scope)"
                  v-if="scope.row.planDetailStatus !== PLAN_DETAIL_STATUS.TO_START"
                >
                  退库
                </el-button>
                <el-button
                  size="small"
                  type="text"
                  @click="print(scope.row)"
                  v-if="scope.row.planDetailStatus === PLAN_DETAIL_STATUS.FINISHED || scope.row.planDetailStatus === PLAN_DETAIL_STATUS.ABNORMAL_FINISHED"
                >
                  条码
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div>
      <div class="roundBorder" style="top: 72%;left: 1.2%;">
        <el-button :disabled="nowNum3 <= 1" circle icon="el-icon-back" size="mini" @click="pre3"></el-button>
      </div>
      <div class="roundBorder" style="top: 72%;left: 49%;">
        <el-button :disabled="nowNum3 >= totalNum3" circle icon="el-icon-right" size="mini" @click="next3"></el-button>
      </div>
    </div>

    <div class="chartBox chartBox4">
      <div class="title">物料安装情况(未完成)</div>
      <div class="chart">
        <div class="whiteTable">
          <el-table
            :cell-style="{textAlign:'center'}"
            :data="tableData3"
            :header-cell-style="{textAlign:'center'}"
            :max-height="19.13 * vw"
            style="width: 100%"
          >
            <el-table-column
              label="序号"
              type="index"
              width="50"
            >
            </el-table-column>
            <el-table-column
              label="物料编码"
              prop="materialCode"
            >
            </el-table-column>
            <el-table-column
              label="物料名称"
              prop="materialName"
            >
            </el-table-column>
            <el-table-column
              label="差异值"
              prop="needAmount"
              width="100"
            >
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div>
      <div class="roundBorder" style="top: 72%;left: 51%;">
        <el-button :disabled="nowNum4 <= 1" circle icon="el-icon-back" size="mini" @click="pre4"></el-button>
      </div>
      <div class="roundBorder" style="top: 72%;left: 98.8%;">
        <el-button :disabled="nowNum4 >= totalNum4" circle icon="el-icon-right" size="mini" @click="next4"></el-button>
      </div>
    </div>

    <div class="bottom">
      <el-row>
        <el-button type="primary">首页</el-button>
        <el-button type="success" @click="handleProductInstock">成品入库</el-button>
        <el-button type="danger" @click="logout">退出</el-button>
      </el-row>
    </div>

    <!-- 申请领料信息对话框 -->
    <el-dialog title="申请领料" :visible.sync="dialogVisible" append-to-body>
      <apply-raw-outstock ref="applyRawOutstockRef" :defineData="productPlanData" v-if="dialogVisible"></apply-raw-outstock>
    </el-dialog>

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

    <el-dialog
      :visible.sync="productInstockVisible"
      title="成品入库"
      width="40%">
      <el-form ref="productInstockForm" :model="productInstockForm" :rules="productInstockRules" label-width="80px">
        <el-form-item label="成品条码" prop="materialBarcode">
          <el-input v-model="productInstockForm.materialBarcode" suffix-icon="el-icon-full-screen"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitProductInstock">确 定</el-button>
        <el-button @click="cancelProductInstock">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog
      :visible.sync="materialConfirmVisible"
      title="确认物料使用"
      width="40%">
      <el-form ref="materialConfirmForm" :model="materialConfirmForm" :rules="materialConfirmRules" label-width="80px">
        <el-form-item v-if="false" label="计划ID" prop="planId">
          <el-input v-model="materialConfirmForm.planId"></el-input>
        </el-form-item>
        <el-form-item v-if="false" label="明细ID" prop="planDetailId">
          <el-input v-model="materialConfirmForm.planDetailId"></el-input>
        </el-form-item>
        <el-form-item label="明细编号" prop="planDetailCode">
          <el-input v-model="materialConfirmForm.planDetailCode" disabled></el-input>
        </el-form-item>
        <el-form-item label="物料条码" prop="materialBarcode">
          <el-input v-model="materialConfirmForm.materialBarcode" suffix-icon="el-icon-full-screen"></el-input>
        </el-form-item>
        <el-form-item label="数量" prop="checkAmount">
          <el-input v-model="materialConfirmForm.checkAmount" disabled></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitMaterialConfirm">确 定</el-button>
        <el-button @click="cancelMaterialConfirm">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="returnModelVisible" title="申请退库" width="400">
      <el-form ref="returnModelForm" :model="returnModelForm" label-width="80px" :rules="returnModelFormRules">
        <el-form-item label="计划编号">
          <el-input v-model="returnModelForm.planCode" autocomplete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="明细编号">
          <el-input v-model="returnModelForm.planDetailCode" autocomplete="off" disabled></el-input>
        </el-form-item>
        <!--el-form-item label="成品">
          <el-input v-model="returnModelForm.materialName" autocomplete="off" disabled></el-input>
        </el-form-item-->
        <el-form-item label="物料条码">
          <el-input placeholder="请扫描或输入物料条码" v-model="returnModelForm.materialBarcode" suffix-icon="el-icon-full-screen">
          </el-input>
        </el-form-item>
        <el-form-item label="仓库">
          <el-select v-model="returnModelForm.warehouseId" placeholder="请选择仓库"
                     style="width: 260px">
            <el-option :label="i.label" :key="i.value" :value="i.value" v-for="i in WarehousesList"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数量" prop="planAmount">
          <el-input-number v-model="returnModelForm.planAmount" controls-position="right" :min="1" style="width: 260px"></el-input-number>
        </el-form-item>
        <el-form-item label="退库类型" prop="taskType">
          <el-select v-model="returnModelForm.taskType" placeholder="请选择退库类型" style="width: 260px">
            <el-option :label="i.label" :key="i.value" :value="i.value"
                       v-for="i in dict.type.wms_raw_return_task_type"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请原因">
          <el-input type="textarea" v-model="returnModelForm.applyReason" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="returnModelVisible = false">取 消</el-button>
          <el-button type="primary" @click="returnModelConfirm">退 库</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      :visible.sync="SOPModel"
      title="SOP预览"
      width="30%"
      @before-close="blueprintModel = false">
      <el-upload
        ref="drawingUpload"
        :auto-upload="true"
        :file-list="fileList"
        :headers="headers"
        :limit="0"
        action="uploadImgUrl"
        list-type="picture-card"
        single
      >
        <i slot="default" class="el-icon-plus"></i>
        <div slot="file" slot-scope="{file}">
          <img
            v-if="isAssetTypeAnImage(file.name)"
            :alt="file.name"
            :src="file.url" class="el-upload-list__item-thumbnail"
          >
          <span v-else>{{ file.name }}</span>
          <span class="el-upload-list__item-actions">
        <span
          v-if="isAssetTypeAnImage(file.name)"
          class="el-upload-list__item-preview"
          @click="handlePictureCardPreview(file)"
        >
          <i class="el-icon-zoom-in"></i>
        </span>
        <span
          class="el-upload-list__item-delete"
          @click="handleDownload(file)"
        >
          <i class="el-icon-download"></i>
        </span>
      </span>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button @click="SOPModel = false">关 闭</el-button>
      </div>
    </el-dialog>


    <el-dialog
      :visible.sync="pictureDetailModel"
      append-to-body
      title="图纸预览"
      width="800"
    >
      <img
        :src="dialogImageUrl"
        style="display: block; max-width: 100%; margin: 0 auto"
      />
    </el-dialog>

    <div id="workshopNotice">
      <WorkshopNotice :visible.sync="showTableDialog" :noticeListData="noticeListData"></WorkshopNotice>
    </div>
  </div>
</template>

<script>
import Chart from '@/components/board/Chart'
import PrintPage from '@/views/mes/barcode/endProductIndex'
import {monitorSerialData} from "@/utils/serial"
import WorkshopNotice from "@/components/workshopNotice/index.vue";
import {noticeData} from "@/utils/notice"
import * as echarts from 'echarts'
import {
  getWarehouses,
  getProductPlans,
  insertProductPlanDetails,
  getProductPlanDetails,
  startProductPlanDetail,
  completeProductPlanDetail,
  firstFloorProduceInstock,
  scanMaterial2Confirm,
  applyRawReturn,
  selectMaterialInstallationCircumstance
} from '@/api/board'
import {getToken} from "@/utils/auth";
import applyRawOutstock from "@/views/board/common/applyRawOutstock.vue";

const vw = (document.documentElement.clientWidth || document.body.clientWidth) / 100
export default {
  name: 'Board1',
  dicts: ['mes_plan_detail_status', 'wms_raw_return_task_type',"mes_safe_flag"],
  components: {
    'apply-raw-outstock': applyRawOutstock,
    Chart,
    PrintPage,
    WorkshopNotice
  },
  mixins: [monitorSerialData, noticeData],
  data() {
    return {
      info: {},
      fileList: [],
      SOPModel: false,
      pictureDetailModel: false,
      dialogImageUrl: '',
      returnModelVisible: false,
      returnModelForm: {},
      WarehousesList: [],
      PrintData: {},
      printModel: false,
      nowNum1: 1,
      totalNum1: 0,
      nowNum2: 1,
      totalNum2: 0,
      nowNum3: 1,
      totalNum3: 0,
      nowNum4: 1,
      totalNum4: 0,
      materialBomId:null,
      planId: null,
      nowMaterial: null,
      vw: (document.documentElement.clientWidth || document.body.clientWidth) / 100,
      searchMaterialValue: '',
      warehouseList: [],
      form: {},
      dialogVisible: false,
      tableData: [],
      tableData1: [],
      tableData2: [],
      tableData3: [],

      productInstockVisible: false,
      productInstockForm: {
        materialBarcode: null
      },
      productInstockRules: {
        materialBarcode: [
          {required: true, message: "成品条码不能为空", trigger: "blur"}
        ],
      },

      materialConfirmVisible: false,
      materialConfirmForm: {
        materialBarcode: null,
        planId: null,
        planDetailId: null,
        planDetailCode: null,
        checkAmount: 1
      },
      materialConfirmRules: {
        materialBarcode: [
          {required: true, message: "物料条码不能为空", trigger: "blur"}
        ],
        checkAmount: [
          {required: true, message: "数量不能为空", trigger: "blur"}
        ],
      },
      returnModelFormRules: {
        taskType: [
          {required: true, message: '请选择退库类型', trigger: 'change'}
        ],
        planAmount: [
          {required: true, message: '请输入数量', trigger: 'change'}
        ],
      },
      headers: {
        Authorization: "Bearer " + getToken(),
      },

      PLAN_DETAIL_STATUS:{
        TO_START : '1',
        STARTED : '2',
        FINISHED : '3',
        ABNORMAL_FINISHED : '9'
      },

      productPlanData:{}
    }
  },
  mounted() {
    this.firstConnectSerial();
    // setInterval(() => {
    //   this.$notify.info({
    //     title: '通知',
    //     message: '通知公告',
    //     position: 'bottom-right',
    //     duration: 0
    //   });
    // }, 60 * 1000)
    getProductPlans({pageNum: 1, pageSize: 5}).then(e => {
      this.tableData = e.rows
      this.totalNum1 = Math.ceil(e.total / 5)
      this.nowMaterial = e.rows?.[0]?.materialName
      this.materialBomId = e.rows?.[0]?.materialBomId
      this.saleOrderId = e.rows?.[0]?.saleOrderId
      this.$refs.planTable.setCurrentRow(e.rows?.[0]);
      getProductPlanDetails({pageNum: 1, pageSize: 5, planId: e.rows?.[0]?.planId}).then(res => {
        this.tableData1 = res.rows
        this.totalNum3 = Math.ceil(res.total / 5)
        this.$refs.table.setCurrentRow(res.rows[0]);
      })
    })
  },
  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)
      })
    },
    next2() {
      this.nowNum2 += 1
      selectMaterialInstallationCircumstance({
        installType: 1,
        planDetailId: this.info.planDetailId,
        pageNum: this.nowNum2,
        pageSize: 5
      }).then(v => {
        this.tableData2 = v.rows
        this.totalNum2 = Math.ceil(v.total / 5)
      })
    },
    pre2() {
      this.nowNum2 -= 1
      selectMaterialInstallationCircumstance({
        installType: 1,
        planDetailId: this.info.planDetailId,
        pageNum: this.nowNum2,
        pageSize: 5
      }).then(v => {
        this.tableData2 = v.rows
        this.totalNum2 = Math.ceil(v.total / 5)
      })
    },
    next3() {
      this.nowNum3 += 1
      getProductPlanDetails({pageNum: this.nowNum3, pageSize: 5, planId: this.planId}).then(res => {
        this.tableData1 = res.rows
        this.totalNum3 = Math.ceil(res.total / 5)
      })
    },
    pre3() {
      this.nowNum3 -= 1
      getProductPlanDetails({pageNum: this.nowNum3, pageSize: 5, planId: this.planId}).then(res => {
        this.tableData1 = res.rows
        this.totalNum3 = Math.ceil(res.total / 5)
      })
    },
    next4() {
      this.nowNum4 += 1
      selectMaterialInstallationCircumstance({
        installType: 2,
        materialBomId: this.materialBomId,
        planDetailId: this.info.planDetailId,
        pageNum: this.nowNum4,
        pageSize: 5
      }).then(v => {
        this.tableData3 = v.rows
        this.totalNum4 = Math.ceil(v.total / 5)
      })
    },
    pre4() {
      this.nowNum4 -= 1
      selectMaterialInstallationCircumstance({
        installType: 2,
        materialBomId: this.materialBomId,
        planDetailId: this.info.planDetailId,
        pageNum: this.nowNum4,
        pageSize: 5
      }).then(v => {
        this.tableData3 = v.rows
        this.totalNum4 = Math.ceil(v.total / 5)
      })
    },
    // 开始/继续计划
    planExecute(e) {
      if (e.planDetailStatus === '1') {
        this.$confirm('是否开始生产明细', '确认', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'success'
        }).then(() => {
          startProductPlanDetail({
            planDetailId: e.planDetailId
          })
            .finally(() => {
              this.getDetail({row: {planId: e.planId}})
              getProductPlans({pageNum: this.nowNum1, pageSize: 5}).then(e => {
                this.tableData = e.rows
                this.totalNum1 = Math.ceil(e.total / 5)
              })
            })
        })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          })
      }
      if (e.planDetailStatus === '2') {
        this.$confirm('是否完成计划', '确认', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'success'
        }).then(() => {
          completeProductPlanDetail({
            planDetailId: e.planDetailId
          })
            .finally(() => {
              this.getDetail({row: {planId: e.planId}})
              getProductPlans({pageNum: this.nowNum1, pageSize: 5}).then(e => {
                this.tableData = e.rows
                this.totalNum1 = Math.ceil(e.total / 5)
              })
            })
        })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          })
      }
    },
    // 生成/获取明细
    async getDetail(e) {
      this.planId = e.row.planId
      this.materialBomId = e.row.materialBomId
      this.nowMaterial = e.row.materialName
      this.saleOrderId = e.row.saleOrderId
      this.nowNum3 = 1
      await getProductPlanDetails({pageNum: 1, pageSize: 5, planId: e.row.planId}).then(res => {
        if (res.rows.length === 0) {
          this.$confirm('是否生成计划明细', '确认', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'success'
          }).then(() => {
            insertProductPlanDetails({
              "planId": e.row.planId,
            }).then(val => {
              getProductPlanDetails({pageNum: this.nowNum3, pageSize: 5, planId: e.row.planId}).then(res => {
                this.tableData1 = res.rows
                this.totalNum3 = Math.ceil(res.total / 5)
                this.$refs.table.setCurrentRow(res.rows[0]);
              })
              this.$message({
                type: 'info',
                message: `生成完成`
              });
            })
          })
            .catch(() => {
              this.$message({
                type: 'info',
                message: '已取消'
              });
            })
        } else {
          this.tableData1 = res.rows
          this.$refs.table.setCurrentRow(res.rows[0]);
          this.totalNum3 = Math.ceil(res.total / 5)
        }

      })
    },
    async getMaterialInstall(e){
      this.info = e
      this.nowNum2 = 1
      this.nowNum4 = 1
      const table1 = await selectMaterialInstallationCircumstance({
        installType: 1,
        planDetailId: e.planDetailId,
        pageNum: this.nowNum2,
        pageSize: 5
      })
      const table2 = await selectMaterialInstallationCircumstance({
        installType: 2,
        materialBomId: this.materialBomId,
        planDetailId: e.planDetailId,
        pageNum: this.nowNum4,
        pageSize: 5
      })
      this.tableData2 = table1.rows
      this.tableData3 = table2.rows
      this.totalNum2 = Math.ceil(table1.total / 5)
      this.totalNum4 = Math.ceil(table2.total / 5)
    },


    // 领料页面
    getMaterials(val) {
      this.dialogVisible = true
      this.productPlanData = {
        warehouseId: '',
        planId: val.planId,
        planCode: val.planCode,
        dispatchCode: val.dispatchCode,
        planDetailCode: val.planDetailCode,
        saleOrderId: val.saleOrderId,
        maxPlanAmount: 100000000,
        returnFlag: "0",
        applyReason: '',
        taskType: "1",
        warehouseFloor: 1,
        wmsRawOutstockDetailList: []
      }
    },

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

    // 表单重置
    resetProductInstock() {
      this.productInstockForm = {
        materialBarcode: null
      };
      this.resetForm("productInstockForm");
    },

    /** 成品入库按钮操作 */
    handleProductInstock() {
      this.resetProductInstock();
      this.productInstockVisible = true;

      if (!this.checkSerialConnected()) {
        this.$confirm('请连接条码枪', '提示', {
          confirmButtonText: '连接',
          showClose: true,
          showCancelButton: true,
          type: 'warning'
        }).then(() => {
          console.log("dddd")
          this.connectSerial(this.setSerialData);
        }).catch(() => {
        });
      }
    },


    submitProductInstock() {
      this.$refs["productInstockForm"].validate(valid => {
        if (valid) {
          firstFloorProduceInstock(this.productInstockForm).then(response => {
            this.$modal.msgSuccess("入库成功");
            this.cancelProductInstock();
          });
        }
      });
    },

    cancelProductInstock() {
      this.productInstockVisible = false;
      this.resetProductInstock();
    },


    // 表单重置
    resetMaterialConfirm() {
      this.materialConfirmForm = {
        materialBarcode: null,
        planId: null,
        planDetailId: null,
        planDetailCode:null,
        checkAmount: 1
      };
      this.resetForm("materialConfirmForm");
    },

    /** 扫描确认按钮操作 */
    handleMaterialConfirmForm(scope) {
      this.materialConfirmForm = {
        materialBarcode: null,
        planId: scope.row.planId,
        planDetailId: scope.row.planDetailId,
        planDetailCode:scope.row.planDetailCode,
        checkAmount: 1
      };
      this.materialConfirmVisible = true;

      if (!this.checkSerialConnected()) {
        this.$confirm('请连接条码枪', '提示', {
          confirmButtonText: '连接',
          showClose: true,
          showCancelButton: true,
          type: 'warning'
        }).then(() => {
          console.log("dddd")
          this.connectSerial(this.setSerialData);
        }).catch(() => {
        });
      }

    },


    submitMaterialConfirm() {
      this.$refs["materialConfirmForm"].validate(valid => {
        if (valid) {
          scanMaterial2Confirm(this.materialConfirmForm).then(response => {
            this.$modal.msgSuccess("确认成功");
            this.cancelMaterialConfirm();
          });
        }
      });
    },

    cancelMaterialConfirm() {
      this.materialConfirmVisible = false;
      this.resetMaterialConfirm();
    },
    returnMaterial(e) {
      this.returnModelVisible = true
      this.returnModelForm = {materialName: this.nowMaterial, ...e.row}
      this.setReturnModelForm();

      if (!this.checkSerialConnected()) {
        this.$confirm('请连接条码枪', '提示', {
          confirmButtonText: '连接',
          showClose: true,
          // beforeClose:async(action,instance,done)=>{
          //   if(action==='confirm'){
          //   }else{
          //     this.connectSerialPort();
          //   }
          //
          // },
          showCancelButton: true,
          type: 'warning'
        }).then(() => {
          console.log("dddd")
          this.connectSerial(this.setSerialData);
        }).catch(() => {
        });
      }

    },
    setReturnModelForm() {
      getWarehouses({
        warehouseFloor: 1,
        materialBarcode: this.returnModelForm.materialBarcode
      }).then(e => {
        this.WarehousesList = e.data.map(v => {
          return {
            label: v.warehouseName,
            value: v.warehouseId,
          }
        })

        this.returnModelForm.warehouseId = e.data[0]?.warehouseId

      })
    },
    returnModelConfirm() {
      this.$refs.returnModelForm.validate((valid) => {
        if (valid) {
          let data = [this.returnModelForm]
          applyRawReturn(data).then(v => {
            if (v.code === 200) {
              this.$message({
                message: '退库成功',
                type: 'success'
              });
            }
            this.returnModelVisible = false
          })
        } else {
          return false;
        }
      });
    },

    async SOP(e) {
      this.fileList = []

      console.log(e)
      // const data = await fun()
      // this.fileList = data.map(v=>v)

      this.fileList = [
        {
          name: 'Snipaste_2023-09-04_08-16-59.png',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/Snipaste_2023-09-04_08-16-59_20240417142903A013.png'
        },
        {
          name: '会议纪要 0825_20240417143926A014.docx',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/会议纪要 0825_20240417143926A014.docx'
        },
        {
          name: '会议纪要 0825_20240417143926A014.docx',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/会议纪要 0825_20240417143926A014.docx'
        },
        {
          name: '会议纪要 0825_20240417143926A014.docx',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/会议纪要 0825_20240417143926A014.docx'
        },
        {
          name: 'Snipaste_2023-09-04_08-16-59.png',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/Snipaste_2023-09-04_08-16-59_20240417142903A013.png'
        },
        {
          name: 'Snipaste_2023-09-04_08-16-59.png',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/Snipaste_2023-09-04_08-16-59_20240417142903A013.png'
        },
        {
          name: 'Snipaste_2023-09-04_08-16-59.png',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/Snipaste_2023-09-04_08-16-59_20240417142903A013.png'
        },
        {
          name: 'Snipaste_2023-09-04_08-16-59.png',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/Snipaste_2023-09-04_08-16-59_20240417142903A013.png'
        },
        {
          name: 'Snipaste_2023-09-04_08-16-59.png',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/Snipaste_2023-09-04_08-16-59_20240417142903A013.png'
        },
        {
          name: '会议纪要 0825_20240417143926A014.docx',
          url: 'http://175.27.215.92:9665/statics/2024/04/17/会议纪要 0825_20240417143926A014.docx'
        },
      ]
      this.SOPModel = true;
    },
    //查看图纸预览
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.pictureDetailModel = true;
    },
    //图纸下载
    async handleDownload(file) {
      this.fileDownload(file)
    },
    isAssetTypeAnImage(ext) {
      let suffix = ext.lastIndexOf(".");
      let name = ext.substr(suffix + 1);
      return ['png', 'jpg', 'jpeg'].includes(name.toLowerCase())
    },



    firstConnectSerial() {
      if (!this.checkSerialConnected()) {
        this.$confirm('请连接条码枪', '提示', {
          confirmButtonText: '连接',
          showClose: true,
          showCancelButton: true,
          type: 'warning'
        }).then(() => {
          this.connectSerial(this.setSerialData);
        }).catch(() => {
        });
      }
    },


    setSerialData() {
      if (this.productInstockVisible) {
        this.productInstockForm.materialBarcode = this.serialData;
      } else if (this.returnModelVisible) {
        this.returnModelForm.materialBarcode = this.serialData;
      } else if(this.materialConfirmVisible){
        this.materialConfirmForm.materialBarcode = this.serialData;
      }
      // console.log(this.serialData)
    }

  }
}
</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;
  //overflow: auto;
}

.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%;
}

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

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

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

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

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

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

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

/deep/ .el-upload {
  display: none;
}
</style>
