<template>
  <el-dialog
    :title="titleMap[mode]"
    v-model="visible"
    width="1000px"
    :size="1000"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <!-- 混料工序 -->
    <el-form
      v-if="activeType == '8车间'"
      ref="dialogForm"
      :model="form"
      :rules="rules"
      label-width="80px"
    >
      <el-row>
        <!-- <el-col :md="12" :sm="24">
          <el-form-item label="工段" prop="material">
            <el-select
              v-model="form.mgroup"
              placeholder="工段"
              clearable
              style="width: 100%"
              @change="getRouteOptions"
            >
              <el-option
                v-for="item in mgroupOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :md="12" :sm="24">
          <el-form-item label="生产路线" prop="material_out">
            <el-select
              v-model="form.material_out"
              placeholder="生产路线"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in routeOptions"
                :key="item.material_out"
                :label="item.label"
                :value="item.material_out"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :md="12" :sm="24">
          <el-form-item label="班次" prop="material">
            <el-select
              v-model="form.shift"
              placeholder="班次"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in shiftOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :md="12" :sm="24">
          <el-form-item label="物料批次" width="100">
            <el-input
              v-model="form.batch"
              tyle="width:100%"
              placeholder="请输入批次"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="数量" width="100">
            <el-input-number
              v-model="form.count_real"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="请输入数量"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="重量" width="100">
            <el-input-number
              v-model="form.count_real_eweight"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="请输入重量"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="配料人">
            <el-select
              v-model="form.handle_users"
              placeholder="配料人"
              clearable
              multiple
              style="width: 100%"
            >
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="操作日期" prop="handle_date">
            <el-date-picker
              v-model="form.handle_date"
              type="date"
              placeholder="操作日期"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 退火 -->
    <el-form
      v-if="activeType == '退火'"
      ref="dialogForm"
      :model="form"
      :rules="rules"
      label-width="120px"
    >
      <el-row>
        <!-- <el-col :md="12" :sm="24">
          <el-form-item label="工段" prop="material">
            <el-select
              v-model="form.mgroup"
              placeholder="工段"
              clearable
              style="width: 100%"
              @change="getRouteOptions"
            >
              <el-option
                v-for="item in mgroupOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :md="12" :sm="24">
          <el-form-item label="生产路线" prop="material_out">
            <el-select
              v-model="form.material_out"
              placeholder="生产路线"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in routeOptions"
                :key="item.id"
                :label="item.label"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="合格数">
            <el-input-number
              v-model="form.count_ok"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="请输入合格数"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="不合格数">
            <el-input-number
              v-model="form.count_notok"
              controls-position="right"
              style="width: 100%"
              placeholder="不合格数"
              disabled
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="物料批次" prop="material_in">
            <el-select
              v-model="form.batch"
              placeholder="物料批次"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in wMaterialOptions"
                :key="item.batch"
                :label="item.batch"
                :value="item.batch"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :md="12" :sm="24">
          <el-form-item label="班次" prop="material">
            <el-select
              v-model="form.shift"
              placeholder="班次"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in shiftOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :md="12" :sm="24">
          <el-form-item label="退火时间" prop="material">
            <el-date-picker
              v-model="form.handle_date"
              type="date"
              placeholder="退火时间"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <div class="formTitle">不合格原因及数量:</div>
      <el-row>
        <el-col :md="12" :sm="24">
          <el-form-item label="椭圆/弯曲">
            <el-input-number
              v-model="form.count_n_wq"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="椭圆/弯曲"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="条纹">
            <el-input-number
              v-model="form.count_n_tw"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="条纹"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="断裂">
            <el-input-number
              v-model="form.count_n_dl"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="断裂"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="偏壁">
            <el-input-number
              v-model="form.count_n_pb"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="偏壁"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="大小头">
            <el-input-number
              v-model="form.count_n_dxt"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="大小头"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="结石">
            <el-input-number
              v-model="form.count_n_js"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="结石"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="气线">
            <el-input-number
              v-model="form.count_n_qx"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="气线"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="箱中破">
            <el-input-number
              v-model="form.count_break"
              controls-position="right"
              style="width: 100%"
              placeholder="箱中破"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="formTitle">检测统计:</div>
      <el-row>
        <el-col :md="12" :sm="24">
          <el-form-item label="检测数">
            <el-input-number
              v-model="form.count"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="请输入检测数"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="检测合格数">
            <el-input-number
              v-model="form.count"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="请输入检测合格数"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="检测不合格数">
            <el-input-number
              v-model="form.count"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="请输入检测不合格数"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="备注">
            <el-input
              v-model="form.note"
              tyle="width:100%"
              placeholder="备注"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 七车间 -->
    <el-form
      v-if="activeType == '7车间'"
      ref="dialogForm"
      :model="form"
      :rules="rules"
      label-width="120px"
    >
      <el-row>
        <el-col :md="12" :sm="24">
          <el-form-item label="产品名称">
            <el-select
              v-model="form.material_out"
              placeholder="产品名称"
              disabled
              style="width: 100%"
            >
              <el-option
                v-for="item in materialOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="批次号">
            <el-input v-model="form.batch" placeholder="批次号"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :md="12" :sm="24">
          <el-form-item label="班次" prop="material">
            <el-select
              v-model="form.shift"
              placeholder="班次"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in shiftOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :md="12" :sm="24">
          <el-form-item label="炉号">
            <el-select
              v-model="form.equipment"
              placeholder="锅号"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in equipmentOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="第几锅">
            <el-input-number
              v-model="form.index"
              controls-position="right"
              :min="1"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="第几锅"
            >
            </el-input-number>
            <!-- <el-select v-model="form.index" placeholder="第几锅" clearable style="width:100%">
                            <el-option v-for="item in 8" :key="item" :label="item" :value="item"></el-option>
                        </el-select> -->
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="应出量">
            <el-input-number
              v-model="form.count_real"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="生产量"
              @change="countChange"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="合格量">
            <el-input-number
              v-model="form.count_ok"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="合格量"
              @change="countChange"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="合格率">
            <!-- <span>{{ form.count_ok/form.count_real }}</span> -->
            <el-input
              v-model="form.rate"
              style="width: 100%"
              disabled
              placeholder="合格率"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="退火炉号">
            <el-select
              v-model="form.equipment_2"
              placeholder="退火炉号"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in equipmentOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :md="12" :sm="24">
                    <el-form-item label="是否加氧">
                        <el-select
                            v-model="form.o2"
                            placeholder="是否加氧"
                            clearable
                            style="width:100%"
                        >
                            <el-option
                                v-for="item in yseorno"
                                :key="item"
                                :label="item"
                                :value="item"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col> -->
        <el-col :md="12" :sm="24">
          <el-form-item prop="type" label="成型人">
            <el-select
              v-model="form.handle_user"
              placeholder="成型人"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item prop="type" label="切料人">
            <el-select
              v-model="form.handle_user_2"
              placeholder="切料人"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="formTitle">不合格原因及数量:</div>
      <el-row>
        <el-col :md="12" :sm="24">
          <el-form-item label="炸纹">
            <el-input-number
              v-model="form.count_n_zw"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="炸纹"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="条纹">
            <el-input-number
              v-model="form.count_n_tw"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="条纹"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="气泡">
            <el-input-number
              v-model="form.count_n_qp"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="气泡"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="弯曲">
            <el-input-number
              v-model="form.count_n_wq"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="弯曲"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="其他">
            <el-input-number
              v-model="form.count_n_qt"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="其他"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="合计">
            <el-input-number
              v-model="form.count_notok"
              controls-position="right"
              style="width: 100%"
              placeholder="合计"
              disabled
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="备注">
            <el-input v-model="form.note" placeholder="备注"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 十车间 -->
    <el-form
      v-if="activeType == '10车间'"
      ref="dialogForm"
      :model="form"
      :rules="rules"
      label-width="80px"
    >
      <el-row>
        <el-col :md="12" :sm="24">
          <el-form-item label="产品名称" prop="material">
            <el-select
              v-model="form.material_out"
              placeholder="产品名称"
              disabled
              style="width: 100%"
            >
              <el-option
                v-for="item in materialOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="班次" prop="material">
            <el-select
              v-model="form.shift"
              placeholder="班次"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in shiftOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="出管总数">
            <el-input-number
              v-model="form.count_real"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="出管总数"
              @change="countChange"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="合格总数">
            <el-input-number
              v-model="form.count_ok"
              controls-position="right"
              style="width: 100%"
              placeholder="合计"
              :disabled="brothersList.length > 0"
              @change="countChange"
            ></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="合格率">
            <el-input
              v-model="form.rate"
              style="width: 100%"
              disabled
              placeholder="合格率"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item prop="type" label="成型人">
            <el-select
              v-model="form.handle_user"
              placeholder="成型人"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item prop="type" label="带班人">
            <el-select
              v-model="form.handle_leader"
              placeholder="带班人"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="碎料">
            <el-input-number
              v-model="form.count_break"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="碎料"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="批次号">
            <el-input
              v-model="form.batch"
              placeholder="请输入请输入批次号"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div v-if="brothersList.length > 0" class="formTitle">关联产品计数:</div>
      <div v-if="brothersList.length > 0">
        <el-row v-for="item in mlogb" :key="item">
          <el-col :md="12" :sm="24">
            <el-form-item label="产品名称" prop="material">
              <el-select
                v-model="item.material_out"
                placeholder="产品名称"
                disabled
                style="width: 100%"
              >
                <el-option
                  v-for="item in materialOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :md="12" :sm="24">
            <el-form-item label="合格数">
              <el-input-number
                v-model="item.count_ok"
                controls-position="right"
                :min="0"
                :step="1"
                :step-strictly="true"
                style="width: 100%"
                placeholder="合格数"
                @change="countOkSun"
              >
              </el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
      </div>

      <div class="formTitle">不合格原因及数量:</div>
      <el-row>
        <el-col :md="12" :sm="24">
          <el-form-item label="椭圆/弯曲">
            <el-input-number
              v-model="form.count_n_wq"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="椭圆/弯曲"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="条纹">
            <el-input-number
              v-model="form.count_n_tw"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="条纹"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="断裂">
            <el-input-number
              v-model="form.count_n_dl"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="断裂"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="偏壁">
            <el-input-number
              v-model="form.count_n_pb"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="偏壁"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="大小头">
            <el-input-number
              v-model="form.count_n_dxt"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="大小头"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="结石">
            <el-input-number
              v-model="form.count_n_js"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="结石"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="气线">
            <el-input-number
              v-model="form.count_n_qx"
              controls-position="right"
              :min="0"
              :step="1"
              :step-strictly="true"
              style="width: 100%"
              placeholder="气线"
              @change="countNotOkSun"
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="合计">
            <el-input-number
              v-model="form.count_notok"
              controls-position="right"
              style="width: 100%"
              placeholder="合计"
              disabled
            >
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :md="12" :sm="24">
          <el-form-item label="备注">
            <el-input v-model="form.note" placeholder="备注"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-footer>
      <el-button type="primary" v-loading="isSaveing" @click="submit"
        >确定</el-button
      >
      <el-button @click="visible = false">取消</el-button>
    </el-footer>
  </el-dialog>
</template>
<script>
export default {
  emits: ["success", "closed"],
  props: {
    mgroup:{ type: String, default: "" },
    mtask: { type: String, default: "" },
    mgroupId: { type: String, default: "" },
    activeType: { type: String, default: "" },
    material_out: { type: String, default: "" },
    brothersList: { type: Array, default: () => [] },
  },
  data() {
    return {
      yseorno: ["是", "否"],
      loading: false,
      mode: "add",
      titleMap: {
        add: "新增记录",
        edit: "编辑记录",
        show: "查看记录",
      },
      handle_user: [],
      form: {
        shift:'',
        batch:'',
        count_ok: 0,
        count_real: 0,
        count_n_zw: 0,
        count_n_tw: 0,
        count_n_qp: 0,
        count_n_wq: 0,
        count_n_dl: 0,
        count_n_pb: 0,
        count_n_dxt: 0,
        count_n_js: 0,
        count_n_qx: 0,
        count_n_qt: 0,
        count_break:0,
        mlogb: [],
      },
      mlogb: [],
      userList: [],
      cateOptions: [],
      mgroupOptions: [],
      materialOptions: [],
      equipmentOptions: [],
      wMaterialOptions: [],
      shiftOptions: [],
      routeOptions:[],
      visible: false,
      isSaveing: false,
      setFiltersVisible: false,
      handle_name: "",
      leader_name: "",
      count_n_all: null,
      rules:{

      },
    };
  },
  mounted() {
    console.log('brothersList')
    console.log(this.brothersList)
    this.getMaterial();
    this.getMgroupList();
    this.getUserList();
    this.getEquipment();
    this.getShiftOptions();
    this.getRouteOptions();
    this.getWorkShopMaterial();
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    this.form.material_out = this.material_out;
    this.form.mgroup = this.mgroup;
    this.form.handle_date = year + "-" + month + "-" + day;
    if (this.activeType == "10车间") {
      let mlogb = [];
        this.brothersList.forEach((item) => {
          let obj = {};
          obj.material_out = item.material_out;
          obj.count_ok = item.count_ok;
          mlogb.push(obj);
        });
        this.mlogb = mlogb;
    }
    if(this.activeType == "10车间"){
        this.getMaterial(0);
      }else{
        this.getMaterial(this.mgroup);
      }
  },
  methods: {
    getRouteOptions() {
      let mgroup__name = '';
      if(this.activeType=='8车间'){
        mgroup__name = '混料';
      }else if(this.activeType=='退火'){
        mgroup__name = '管料退火';
      }else{return}
      this.$API.mtm.route.list.req({ page: 0, mgroup__name:mgroup__name}).then(res => {
        for (var i = 0; i < res.length; i++) {
          if (res[i].material_in == null) {
            res[i].material_in_name = ''
          }
          if (res[i].material_out == null) {
            res[i].material_out_name = ''
          }
          res[i].label = res[i].material_in_name + '->' + res[i].material_out_name
        }
        this.routeOptions = res;
      })
    },
    getShiftOptions() {
      this.$API.mtm.shift.list.req({ page: 0}).then((res) => {
        this.shiftOptions = [];
        if(this.activeType == "10车间"){
          res.forEach(item=>{
            if(item.rule=='两倒'){
              this.shiftOptions.push(item);
            }
          })
        }else{
          res.forEach(item=>{
            if(item.rule=='默认'){
              this.form.shift = item.id;
            }
          })
        }
      });
    },
    getUserList() {
      let that = this;
      let deptName = "";
      if (this.activeType == "退火") {
        deptName = "8车间";
      } else {
        deptName = this.activeType;
      }
      this.$API.system.user.list
        .req({ belong_dept__name: deptName, page: 0 })
        .then((res) => {
          that.userList = res;
        });
    },
    //获取车间物料批次号
    getBatchs() {
      let that = this;
      this.$API.wpm.wmaterial.batchs
        .req({ belong_dept_name: "6车间" })
        .then((res) => {
          that.batchOptions = res;
        });
    },
    //获取集合列表
    getMgroupList() {
      let that = this;
      let activeDeptName = ''
      if (this.activeType=='退火'){
        activeDeptName = '8车间'
      }else{
        activeDeptName = this.activeType
      }
      this.$API.mtm.mgroup.list
        .req({ page: 0, belong_dept__name: activeDeptName })
        .then((res) => {
          that.mgroupOptions = res;
        });
    },
    //获取设备列表
    getEquipment() {
      this.$API.em.equipment.list.req({ page: 0, type: 10 }).then((res) => {
        this.equipmentOptions = res;
      });
    },
    getMaterial(mgroupId) {
      if (mgroupId != 0) {
        this.$API.mtm.route.list
          .req({ page: 0, mgroup: mgroupId })
          .then((res) => {
            let mOptions = [];
            for (var i = 0; i < res.length; i++) {
              mOptions.push({
                id: res[i].material_out,
                name: res[i].material_out_name,
                material_in: res[i].material_in
              });
            }
            this.materialOptions = mOptions;
          });
      } else {
        let obj = {};
        obj.page = 0;
        obj.is_hidden = false;
        this.$API.mtm.material.list.req(obj).then((res) => {
          this.materialOptions = res;
        });
      }
    },
    //获取车间物料
    //  getMaterial(){
    //     let that = this;
    // 	this.$API.wpm.wmaterial.list.req({belong_dept_name:'8车间',page:0}).then(res=>{
    // 		that.materialOptions = res;
    // 	});
    // },
    getWorkShopMaterial() {
      let that = this;
      this.$API.wpm.wmaterial.list
        .req({ belong_dept__name: "8车间", page: 0 })
        .then((res) => {
          that.wMaterialOptions = res;
        });
    },
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },
    countNotOkSun() {
      if (this.activeType == "7车间") {
        this.form.count_notok =
          this.form.count_n_zw +
          this.form.count_n_tw +
          this.form.count_n_qp +
          this.form.count_n_wq +
          this.form.count_n_qt;
      } else if (this.activeType == "10车间") {
        this.form.count_notok =
          this.form.count_n_wq +
          this.form.count_n_tw +
          this.form.count_n_dl +
          this.form.count_n_pb +
          this.form.count_n_dxt +
          this.form.count_n_js+
          this.form.count_n_qx;
      } else if (this.activeType == "退火") {
        this.form.count_notok =
          this.form.count_n_wq +
          this.form.count_n_tw +
          this.form.count_n_dl +
          this.form.count_n_pb +
          this.form.count_n_dxt +
          this.form.count_n_js +
          this.form.count_n_qx +
          this.form.count_break;
      }
    },
    countOkSun() {
      let ok_number = 0;
      this.mlogb.forEach((item) => {
        ok_number += item.count_ok;
      });
      this.form.count_ok = ok_number;
      this.countChange();
    },
    //提交
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          if (this.activeType == "7车间") {
            this.form.mtask = this.mtask;
            this.form.count_notok =
              this.form.count_n_zw +
              this.form.count_n_tw +
              this.form.count_n_qp +
              this.form.count_n_wq +
              this.form.count_n_qt;
          } else if (this.activeType == "10车间") {
            this.form.mtask = this.mtask;
            this.form.count_notok =
              this.form.count_n_wq +
              this.form.count_n_tw +
              this.form.count_n_dl +
              this.form.count_n_pb +
              this.form.count_n_dxt +
              this.form.count_n_js +
              this.form.count_n_qx;
            let ok_number = 0;
            this.mlogb.forEach((item) => {
              ok_number += item.count_ok;
            });
            this.form.count_ok = ok_number;
          } else if (this.activeType == "退火") {
            this.form.mgroup = "3428194648706011136";
            this.form.count_notok =
              this.form.count_n_wq +
              this.form.count_n_tw +
              this.form.count_n_dl +
              this.form.count_n_pb +
              this.form.count_n_dxt +
              this.form.count_n_js +
              this.form.count_n_qx +
              this.form.count_break;
          }
          if (this.activeType == "10车间") {
            let mlogb = this.mlogb;
            let newArr = [];
            mlogb.forEach((item) => {
              if (item.count_ok !== null && item.count_ok !== "") {
                newArr.push(item);
              }
            });
            this.form.mlogb = newArr;
          }
          let sun = this.form.count_ok+this.form.count_notok;
          if ((this.activeType == "7车间"||this.activeType == "10车间")&&sun!=this.form.count_real) {
              this.isSaveing = false;
              this.$message.error("合格总数与不合格总数与生产量/出管总数不对等");
          }else{
            if (this.mode == "add") {
              this.$API.wpm.mlog.create
                .req(this.form)
                .then((res) => {
                  this.isSaveing = false;
                  this.$emit("success", this.form, this.mode);
                  this.visible = false;
                  this.$message.success("操作成功");
                })
                .catch((err) => {
                  //可以处理校验错误
                  this.isSaveing = false;
                  return err;
                });
            } else if (this.mode == "edit") {
              this.$API.wpm.mlog.update
                .req(this.form.id, this.form)
                .then((res) => {
                  this.isSaveing = false;
                  this.$emit("success", this.form, this.mode);
                  this.visible = false;
                  this.$message.success("操作成功");
                })
                .catch((err) => {
                  //可以处理校验错误
                  this.isSaveing = false;
                  return err;
                });
            }
          }
          
        }
      });
    },
    //表单注入数据
    setData(data) {
      Object.assign(this.form, data);
      if (this.activeType == "8车间") {
        if (this.form.handle_user.indexOf(",") > -1) {
          this.handle_user = this.form.handle_user.split(",");
        } else {
          this.handle_user = [this.form.handle_user];
        }
      } else {
        this.form.rate =
          (this.form.count_ok / this.form.count_real) * 100 + "%";
      }
    },
    //设置过滤项
    setFilters(filters) {
      this.selectionFilters = filters;
      this.setFiltersVisible = true;
    },
    //
    countChange() {
      if (
        this.form.count_real !== null &&
        this.form.count_real !== "" &&
        this.form.count_real !== 0
      ) {
        if (
          this.form.count_ok !== null &&
          this.form.count_ok !== "" &&
          this.form.count_ok !== 0
        ) {
          this.form.rate =
            (this.form.count_ok / this.form.count_real) * 100 + "%";
        } else {
          this.form.rate = null;
        }
      } else {
        this.form.rate = null;
      }
    },
    //选择
    materialInChange(val) {
      for(let i=0;i<this.materialOptions.length;i++){
        if(this.materialOptions[i].id==val){
          this.form.material_out = data[0].material_out;
        }
      }
    },
    //选择
    // wmaterialInChange(val) {
    //   console.log(this.form)
    //   console.log(this.wmaterialOptions);
    //   debugger;
    //   for(let i=0;i<this.wmaterialOptions.length;i++){
    //     if(this.wmaterialOptions[i].id==val){
    //       this.form.batch = data[0].batch;
    //     }
    //   }
    //   console.log(this.form)
    // },
  },
};
</script>
<style scoped>
.formTitle {
  margin-bottom: 10px;
  font-weight: 600;
}
</style>
  