<template>
  <div>
    <div class="title_box rx-bc mt6">
      <div class="name">报工信息({{ list.length || 0 }})个 </div>

      <!-- <div class="title_box rx-bc mt6">
        <div
          v-if="!isDetails && isEngrave"
          class="rx-bc"
          style="margin-left: 20px"
        >
          <el-button type="text" size="mini" @click="batchEngrave()"
            >批量填写刻码</el-button
          >
        </div>

        <div
          v-if="!isDetails && isDisposal"
          class="rx-bc"
          style="margin-left: 20px"
        >
          <el-button type="text" size="mini" @click="batchDisposal()"
            >批量处置</el-button
          >
        </div>

        <div
          class="rx-bc"
          v-if="!isDetails && isChoose"
          style="margin-left: 20px"
          ><el-button type="text" size="mini" @click="batchDelete()"
            >批量删除</el-button
          >
        </div>
      </div> -->
    </div>

    <el-table
      ref="oneJobQualityBom"
      class="table_content"
      :max-height="600"
      :data="list"
      tooltip-effect="dark"
      style="width: 100%"
      stripe
      border
      :default-expand-all="true"
    >
      <el-table-column type="expand" label="批量" width="80">
        <template slot-scope="{ row, $index }">
          <div class="material" :key="$index">
            <div class="btn_end">
              <el-button
                v-if="!isDetails"
                type="primary"
                size="mini"
                @click="handAddListPL($index)"
                style="margin-bottom: 4px"
                >分批</el-button
              >

              <div class="content_table2">
                <div class="head row rx-sc">
                  <div class="item ww30">合格品数量</div>
                  <div class="item ww30"
                    >报工总重量 /{{ row.extInfo.weightUnit }}
                  </div>
                  <div
                    class="item ww30"
                    v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >设备</div
                  >
                  <div
                    class="item ww30"
                    v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >炉次号</div
                  >
                  <div class="item ww30">处置</div>
                  <div class="item ww10">操作</div>
                </div>

                <div class="table">
                  <div
                    class="tr row rx-sc"
                    v-for="(it, yyIdx) in row.extInfo.batchReportInfo"
                    :key="$index + yyIdx"
                  >
                    <div class="item ww30">
                      <div v-if="isDetails">{{ it.allFeedQuantity }}</div>
                      <el-input
                        v-else
                        class="content_num"
                        size="mini"
                        v-model="it.allFeedQuantity"
                        @input="blurNum(it, $index, yyIdx)"
                        type="number"
                      ></el-input>
                    </div>

                    <div class="item ww30">
                      <div v-if="isDetails">{{ it.allReportWeight }}</div>
                      <el-input
                        v-else
                        class="content_num"
                        size="mini"
                        v-model="it.allReportWeight"
                        type="number"
                        @input="blurWeight(it, $index, yyIdx)"
                      ></el-input>
                    </div>
                    <!-- 1 -->
                    <div
                      class="item ww30"
                      v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >
                      <div v-if="isDetails">{{ it.deviceName }}</div>
                      <el-select
                        class="content_num"
                        v-model="it.deviceId"
                        filterable
                        placeholder="请选择"
                        @change="(e) => selectValBatch(e, row, $index, yyIdx)"
                        size="mini"
                        v-else
                      >
                        <el-option
                          v-for="item in deviceList"
                          :label="item.name"
                          :value="item.id || item.instanceId"
                          :key="item.id || item.instanceId"
                        >
                        </el-option>
                      </el-select>
                    </div>

                    <div
                      class="item ww30"
                      v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >
                      <div v-if="isDetails">{{ it.heatNumber }}</div>
                      <el-input
                        size="mini"
                        class="content_num"
                        v-model="it.heatNumber"
                        placeholder="请输入炉次号"
                        :disabled="isDetails"
                        v-else
                      />
                    </div>
                    <!-- 2 -->
                    <div class="item ww30">
                      <el-select
                        size="mini"
                        class="content_num"
                        filterable
                        v-model="it.taskId"
                        placeholder="请选择"
                        @change="(e) => selectName(e, $index, yyIdx)"
                        :disabled="isDetails"
                      >
                        <el-option
                          v-for="item in stepsList"
                          :label="item.taskTypeName"
                          :value="item.taskId"
                          :key="item.taskId"
                        >
                        </el-option>
                      </el-select>
                    </div>

                    <div
                      class="item ww10 rx-cc"
                      @click="handDel3($index, yyIdx)"
                      v-if="!isDetails"
                    >
                      <el-link type="danger">删除</el-link>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="material" :key="'not' + $index">
            <div class="btn_end">
              <el-button
                v-if="!isDetails"
                type="primary"
                size="mini"
                @click="handAddListPL4($index)"
                style="margin-bottom: 4px"
                >分批</el-button
              >

              <div class="content_table2">
                <div class="head row rx-sc">
                  <div class="item ww20">不合格品数量</div>
                  <div class="item ww20">重量</div>
                  <div class="item ww20">类型 </div>
                  <div
                    class="item ww30"
                    v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >设备</div
                  >
                  <div
                    class="item ww30"
                    v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >炉次号</div
                  >
                  <div class="item ww30">处置/原因</div>
                  <div class="item ww10">操作</div>
                </div>

                <div class="table">
                  <div
                    class="tr row rx-sc"
                    v-for="(it, yyIdx) in row.extInfo.notBatchReportInfo"
                    :key="'not' + $index + yyIdx"
                  >
                    <div class="item ww20">
                      <div v-if="isDetails">{{ it.allFeedQuantity }}</div>
                      <el-input
                        v-else
                        class="content_num"
                        size="mini"
                        v-model="it.allFeedQuantity"
                        @input="blurNum2(it, $index, yyIdx)"
                        type="number"
                      ></el-input>
                    </div>

                    <div class="item ww20">
                      <div v-if="isDetails">{{ it.allReportWeight }}</div>
                      <el-input
                        v-else
                        class="content_num"
                        size="mini"
                        v-model="it.allReportWeight"
                        type="number"
                        @input="blurWeight2(it, $index, yyIdx)"
                      ></el-input>
                    </div>

                    <div class="item ww20">
                      <el-select
                        size="mini"
                        class="content_num"
                        filterable
                        v-model="it.notType"
                        placeholder="请选择"
                        @change="handLoad()"
                        :disabled="isDetails"
                      >
                        <el-option
                          v-for="item in notTypeList"
                          :label="item.name"
                          :value="item.code"
                          :key="item.code"
                        >
                        </el-option>
                      </el-select>
                    </div>

                    <!-- 1 -->
                    <div
                      class="item ww30"
                      v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >
                      <div v-if="isDetails">{{ it.deviceName }}</div>
                      <el-select
                        class="content_num"
                        v-model="it.deviceId"
                        filterable
                        placeholder="请选择"
                        @change="(e) => selectValNoBatch(e, row, $index, yyIdx)"
                        size="mini"
                        :disabled="isDetails"
                        v-else
                      >
                        <el-option
                          v-for="item in deviceList"
                          :label="item.name"
                          :value="item.id || item.instanceId"
                          :key="item.id || item.instanceId"
                        >
                        </el-option>
                      </el-select>
                    </div>

                    <div
                      class="item ww30"
                      v-if="deviceList.length > 0 && clientEnvironmentId == 3"
                    >
                      <div v-if="isDetails">{{ it.heatNumber }}</div>
                      <el-input
                        size="mini"
                        class="content_num"
                        v-model="it.heatNumber"
                        placeholder="请输入炉次号"
                        v-else
                        :disabled="isDetails"
                      />
                    </div>
                    <!-- 2 -->
                    <div class="item ww30" v-if="it.notType != 5">
                      <div v-if="isDetails">{{ it.notReason }}</div>
                      <el-input
                        v-else
                        class="content_num"
                        size="mini"
                        v-model="it.notReason"
                      ></el-input>
                    </div>

                    <div class="item ww30" v-if="it.notType == 5">
                      <el-select
                        size="mini"
                        class="content_num"
                        filterable
                        v-model="it.taskId"
                        placeholder="请选择"
                        :disabled="isDetails"
                        @change="(e) => selectName(e, $index, yyIdx)"
                      >
                        <el-option
                          v-for="item in stepsList"
                          :label="item.taskTypeName"
                          :value="item.taskId"
                          :key="item.taskId"
                        >
                        </el-option>
                      </el-select>
                    </div>

                    <div
                      class="item ww10 rx-cc"
                      @click="handDel4($index, yyIdx)"
                      v-if="!isDetails"
                    >
                      <el-link type="danger">删除</el-link>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="序号" width="85">
        <template slot-scope="{ row, $index }">
          {{ $index + 1 }}
          <div class="tag_box" v-if="row.isCache">缓</div>
        </template>
      </el-table-column>

      <el-table-column label="编码" prop="code" minWidth="110">
        <template slot-scope="{ row, $index }">
          {{ row.code }}
        </template>
      </el-table-column>

      <el-table-column label="名称" prop="name" minWidth="140">
        <template slot-scope="{ row, $index }">
          {{ row.name }}
        </template>
      </el-table-column>
      <el-table-column
        label="物品分类"
        type="rootCategoryLevelId"
        minWidth="110"
      >
        <template slot-scope="{ row, $index }">
          {{
            row.rootCategoryLevelId == 2
              ? '在制品'
              : row.rootCategoryLevelId == 23
              ? '半成品'
              : row.rootCategoryLevelId == 9
              ? '产品'
              : item.rootCategoryLevelId == 28
              ? '废品'
              : ''
          }}
        </template>
      </el-table-column>

      <el-table-column label="型号" type="modelType">
        <template slot-scope="{ row, $index }">
          {{ row.modelType }}
        </template>
      </el-table-column>

      <el-table-column label="规格" prop="specification">
        <template slot-scope="{ row, $index }">
          {{ row.specification }}
        </template>
      </el-table-column>

      <el-table-column label="牌号" prop="brandNum">
        <template slot-scope="{ row, $index }">
          {{ row.brandNum }}
        </template>
      </el-table-column>

      <el-table-column
        v-if="singleReport == 1"
        :label="
          item.currentTaskDiagram.isFirstTask == 1 ? '物料重量' : '上道工序重量'
        "
        prop="weightUnit"
        width="120"
      >
        <template slot-scope="{ row, $index }">
          <div v-if="item.currentTaskDiagram.isFirstTask == 1">
            {{ row.extInfo.weight || 0 }} {{ row.extInfo.weightUnit }}</div
          >
          <div v-if="item.currentTaskDiagram.isFirstTask == 0">
            {{ row.extInfo.newWeight || 0 }}
            {{ row.extInfo.weightUnit }}</div
          >
        </template>
      </el-table-column>

      <!-- <el-table-column
        v-if="deviceList.length > 0 && clientEnvironmentId!=3"
        width="140"
        label="设备"
        prop="deviceId"
      >
        <template slot-scope="{ row, $index }">
          <el-select
            class="content_num"
            v-model="row.deviceId"
            filterable
            placeholder="请选择"
            @change="(e) => selectVal(e, row, $index)"
            size="mini"
            :disabled="isDetails"
          >
            <el-option
              v-for="item in deviceList"
              :label="item.name + '-' + item.codeNumber"
              :value="item.id || item.instanceId"
              :key="item.id || item.instanceId"
            >
            </el-option>
          </el-select>
          {{ row.deviceName || row.extInfo.deviceName }}
        </template>
      </el-table-column>

      <el-table-column
        v-if="deviceList.length > 0 && clientEnvironmentId!=3"
        label="炉次号"
        width="90"
        prop="heatNumber"
      >
        <template slot-scope="{ row, $index }">
          <el-input
            size="mini"
            class="content_num"
            v-model="row.extInfo.heatNumber"
            placeholder="请输入炉次号"
            :disabled="isDetails"
          />
        </template>
      </el-table-column> -->

      <el-table-column label="投料数量" width="90" prop="feedQuantity">
        <template slot-scope="{ row, $index }">
          <el-input
            size="mini"
            class="content_num"
            v-model="row.feedQuantity"
            placeholder="数量"
          />
        </template>
      </el-table-column>

      <el-table-column label="操作" width="60px">
        <template slot-scope="{ $index, row }">
          <el-link v-if="!isDetails" type="danger" @click="getDelete($index)"
            >删除</el-link
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="处置类型"
      v-if="dialogVisible"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="处置类型">
          <el-select
            size="mini"
            filterable
            v-model="form.taskId"
            placeholder="请选择"
          >
            <el-option
              v-for="item in stepsList"
              :label="item.taskTypeName"
              :value="item.taskId"
              :key="item.taskId"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="batchConfirm()">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="刻码"
      v-if="dialogEngrave"
      :visible.sync="dialogEngrave"
      width="30%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="90px">
        <el-form-item label="刻码区间">
          <el-input
            size="mini"
            type="number"
            v-model="form.minNumber"
            placeholder="请输入刻码最小值"
            prop="digit"
            style="width: 180px"
          />
          -
          <el-input
            size="mini"
            type="number"
            v-model="form.maxNumber"
            placeholder="请输入刻码最大值"
            prop="digit"
            style="width: 180px"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogEngrave = false">取 消</el-button>
        <el-button type="primary" @click="batchEngraveConfirm()"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { getTaskInstanceList } from '@/api/produce/job';

  export default {
    name: 'semiProductJobBom',

    props: {
      list: {
        type: Array,
        default: () => []
      },
      equipmentList: {
        type: Array,
        default: () => []
      },

      item: {
        type: Object,
        default: () => {}
      },
      isDetails: {
        type: Boolean,
        default: false
      },
      singleReport: {
        default: null
      },
      index: {
        default: null
      },
      isChoose: {
        type: Boolean,
        default: false
      },
      isEngrave: {
        type: Boolean,
        default: false
      },
      isDisposal: {
        type: Boolean,
        default: false
      }
    },

    watch: {
      equipmentList: {
        immediate: true,
        deep: true,
        handler(newVal) {
          //设备下拉框数据来源
          let newData = JSON.parse(JSON.stringify(newVal));

          if (this.isDetails) {
            this.deviceList = newData;
          } else {
            this.deviceArr(newData);
          }
          //

          this.changeHeatNumber();
        }
      }
    },
    computed: {
      clientEnvironmentId() {
        return this.$store.state.user.info.clientEnvironmentId;
      }
    },

    data() {
      return {
        deviceList: [],
        stepsList: [],

        notTypeList: [
          {
            code: '1',
            name: '返工'
          },
          {
            code: '2',
            name: '返修'
          },
          {
            code: '3',
            name: '报废'
          },
          {
            code: '4',
            name: '降级使用'
          },
          {
            code: '5',
            name: '让步接收'
          },
          {
            code: 6,
            name: '留样'
          },
          {
            code: 7,
            name: '消耗'
          },
          {
            code: 8,
            name: '回用'
          },
          {
            code: 9,
            name: '转试销'
          }
        ],
        form: {
          taskId: '',
          minNumber: '',
          maxNumber: ''
        },
        dialogVisible: false,
        dialogEngrave: false
      };
    },
    mounted() {
      this.theFirst();
    },
    methods: {
      theFirst() {
        if (this.deviceList.length > 0) {
          let obj = this.deviceList[0];

          this.list.map((item, index) => {
            this.$set(
              this.list[index].extInfo.batchReportInfo[0],
              'deviceName',
              obj.name
            );
            this.$set(
              this.list[index].extInfo.batchReportInfo[0],
              'heatNumber',
              obj.extInfo.heatNumber
            );
            this.$set(
              this.list[index].extInfo.batchReportInfo[0],
              'deviceId',
              obj.instanceId
            );
            this.$set(
              this.list[index].extInfo.notBatchReportInfo[0],
              'deviceName',
              obj.name
            );
            this.$set(
              this.list[index].extInfo.notBatchReportInfo[0],
              'heatNumber',
              obj.extInfo.heatNumber
            );
            this.$set(
              this.list[index].extInfo.notBatchReportInfo[0],
              'deviceId',
              obj.instanceId
            );
          });
        }
      },
      getTaskFn() {
        getTaskInstanceList(this.item.workOrderId).then((res) => {
          this.stepsList = res;
        });
      },
      selectVal(e, item, idx) {
        let obj = this.deviceList.find((f) => f.id == e);

        this.$set(
          this.list[idx],
          'deviceName',
          obj.name + '-' + obj.codeNumber
        );
        this.$set(
          this.list[idx]['extInfo'],
          'heatNumber',
          obj.extInfo.heatNumber
        );
      },
      //碳谷
      selectValBatch(e, item, idx, bidx) {
        let obj = this.deviceList.find((f) => f.id || f.instanceId == e);
        console.log('aaa', e, item, idx, bidx);
        console.log('cccc', obj);
        //设备名称
        this.$set(
          this.list[idx].extInfo.batchReportInfo[bidx],
          'deviceName',
          obj.name
        );
        //炉次号
        this.$set(
          this.list[idx].extInfo.batchReportInfo[bidx],
          'heatNumber',
          obj.extInfo.heatNumber
        );
        //设备id
        this.$set(
          this.list[idx].extInfo.batchReportInfo[bidx],
          'deviceId',
          obj.id || obj.instanceId
        );
      },
      selectValNoBatch(e, item, idx, bidx) {
        let obj = this.deviceList.find((f) => f.id || f.instanceId == e);
        //设备名称
        this.$set(
          this.list[idx].extInfo.notBatchReportInfo[bidx],
          'deviceName',
          obj.name
        );
        //炉次号
        this.$set(
          this.list[idx].extInfo.notBatchReportInfo[bidx],
          'heatNumber',
          obj.extInfo.heatNumber
        );
        //设备id
        this.$set(
          this.list[idx].extInfo.notBatchReportInfo[bidx],
          'deviceId',
          obj.id || obj.instanceId
        );
      },

      deviceArr(data) {
        data.forEach((o, i) => {
          o.id = o.id ? o.id.toString() + '/' + i : '';
          o.instanceId = o.instanceId ? o.instanceId.toString() + '/' + i : '';
        });

        this.deviceList = data;
        console.log('1111', this.deviceList);
        if (this.deviceList.length == 0) {
          this.list.forEach((o, index) => {
            //碳谷合格分批设备炉次号
            o.extInfo.batchReportInfo.map((report, ridx) => {
              this.$set(
                this.list[index].extInfo.batchReportInfo[ridx],
                'deviceName',
                this.deviceList[0].name
              );
              this.$set(
                this.list[index].extInfo.batchReportInfo[ridx],
                'deviceId',
                this.deviceList[0].id || this.deviceList[0].instanceId
              );
            });
            o.extInfo.notBatchReportInfo.map((noReport, noidx) => {
              this.$set(
                this.list[index].extInfo.notBatchReportInfo[noidx],
                'deviceName',
                this.deviceList[0].name
              );
              this.$set(
                this.list[index].extInfo.notBatchReportInfo[noidx],
                'deviceId',
                this.deviceList[0].id || this.deviceList[0].instanceId
              );
            });
            //碳谷合格分批设备炉次号
            this.$forceUpdate();
          });
        }
      },

      changeHeatNumber() {
        this.deviceList.forEach((f) => {
          this.list.forEach((o, index) => {
            //  o.deviceId &&
            //   f.instanceId == o.deviceId &&
            if (this.deviceList.length > 1) {
              // o.extInfo.heatNumber = f.extInfo.heatNumber;
              this.$set(
                this.list[index].extInfo,
                'heatNumber',
                f.extInfo.heatNumber
              );

              //碳谷合格分批设备炉次号
              o.extInfo.batchReportInfo.map((report, ridx) => {
                if (report.deviceId == f.instanceId) {
                  this.$set(
                    this.list[index].extInfo.batchReportInfo[ridx],
                    'heatNumber',
                    f.extInfo.heatNumber
                  );
                }
              });
              o.extInfo.notBatchReportInfo.map((noReport, noidx) => {
                if (noReport.deviceId == f.instanceId) {
                  this.$set(
                    this.list[index].extInfo.notBatchReportInfo[noidx],
                    'heatNumber',
                    f.extInfo.heatNumber
                  );
                }
              });
              this.$forceUpdate();
            } else if (this.deviceList.length == 1) {
              // o['deviceId'] = this.deviceList[0].instanceId;
              // o.extInfo.heatNumber = this.deviceList[0].extInfo.heatNumber;
              this.$set(
                this.list[index].extInfo,
                'heatNumber',
                this.deviceList[0].extInfo.heatNumber
              );

              //碳谷合格分批设备炉次号
              o.extInfo.batchReportInfo.map((report, ridx) => {
                this.$set(
                  this.list[index].extInfo.batchReportInfo[ridx],
                  'deviceId',
                  this.deviceList[0].instanceId
                );
                this.$set(
                  this.list[index].extInfo.batchReportInfo[ridx],
                  'heatNumber',
                  this.deviceList[0].extInfo.heatNumber
                );
                this.$set(
                  this.list[index].extInfo.batchReportInfo[ridx],
                  'deviceName',
                  this.deviceList[0].extInfo.name
                );
              });
              //碳谷合格分批设备炉次号
              o.extInfo.notBatchReportInfo.map((noReport, noidx) => {
                this.$set(
                  this.list[index].extInfo.notBatchReportInfo[noidx],
                  'deviceId',
                  this.deviceList[0].instanceId
                );
                this.$set(
                  this.list[index].extInfo.notBatchReportInfo[noidx],
                  'heatNumber',
                  this.deviceList[0].extInfo.heatNumber
                );
                this.$set(
                  this.list[index].extInfo.notBatchReportInfo[noidx],
                  'deviceName',
                  this.deviceList[0].extInfo.name
                );
              });

              this.$forceUpdate();
            }
          });
        });
      },

      getDelete(idx) {
        this.list.splice(idx, 1);
      },

      handAddListPL(idx) {
        let deviceid = '';
        if (this.deviceList.length > 0) {
          deviceid = this.deviceList[0].id || this.deviceList[0].instanceId;
        }
        this.list[idx].extInfo.batchReportInfo.push({
          allFeedQuantity: '',
          allReportWeight: '',
          taskId: '',
          taskName: '',
          deviceId: deviceid ? deviceid : '',
          deviceName:
            this.deviceList.length > 0 ? this.deviceList[0].deviceName : '',
          heatNumber:
            this.deviceList.length > 0
              ? this.deviceList[0].extInfo.heatNumber
              : ''
        });
      },

      batchConfirm() {
        if (!this.form.taskId) {
          this.$message({ message: '请选择处置类型', type: 'warning' });
          return false;
        }

        this.list.forEach((item, index) => {
          this.$set(this.list[index].extInfo, 'taskId', this.form.taskId);
        });

        this.$forceUpdate();

        this.dialogVisible = false;
      },

      handleClose() {
        this.dialogVisible = false;
        this.dialogEngrave = false;
      },

      batchEngrave() {
        this.form.minNumber = '';
        this.form.maxNumber = '';
        this.dialogEngrave = true;
      },

      batchEngraveConfirm() {
        if (!this.form.minNumber) {
          this.$message({ message: '请输入最小刻码', type: 'warning' });
          return false;
        }

        if (!this.form.maxNumber) {
          this.$message({ message: '请输入最大刻码', type: 'warning' });
          return false;
        }

        if (Number(this.form.minNumber) > Number(this.form.maxNumber)) {
          this.$message({
            message: '最小刻码不能大于最大刻码',
            type: 'warning'
          });
          return false;
        }

        this.list.forEach((item, index) => {
          this.$set(this.list[index].extInfo, 'engrave', '');
        });

        const engraveNumber =
          Number(this.form.maxNumber) - Number(this.form.minNumber) + 1;

        for (let i = 0; i < engraveNumber; i++) {
          if (this.list.length < i) return;

          if (this.list.length > i) {
            this.$set(
              this.list[i].extInfo,
              'engrave',
              Number(this.form.minNumber) + i
            );
          } else {
            break;
          }
        }

        this.dialogEngrave = false;
      },

      blurNum(it, idx, yyIdx) {
        let value = it.allFeedQuantity;
        value = value.replace(/\./g, '');
        this.$set(
          this.list[idx].extInfo.batchReportInfo[yyIdx],
          'allFeedQuantity',
          value
        );

        let count = 0;
        this.list[idx].extInfo.batchReportInfo.forEach((m) => {
          count = count + Number(m.allFeedQuantity || 0);
        });

        let count2 = 0;
        this.list[idx].extInfo.notBatchReportInfo.forEach((m) => {
          count2 = count2 + Number(m.allFeedQuantity || 0);
        });

        if (Number(count + count2) > this.list[idx].feedQuantity) {
          this.$set(
            this.list[idx].extInfo.batchReportInfo[yyIdx],
            'allFeedQuantity',
            0
          );
          this.$forceUpdate();

          this.$message.info('投料数不能大于投料数量');
          this.$emit('countNumPl', this.list, this.index);
        } else {
          this.$emit('countNumPl', this.list, this.index);
        }
      },
      blurWeight(it, idx, yyIdx) {
        let value = it.allReportWeight;
        // value = value.replace(/\./g, '');
        this.$set(
          this.list[idx].extInfo.batchReportInfo[yyIdx],
          'allReportWeight',
          value
        );
        this.$emit('countNumPl', this.list, this.index);
      },

      blurNum2(it, idx, yyIdx) {
        let value = it.allFeedQuantity;
        value = value.replace(/\./g, '');
        this.$set(
          this.list[idx].extInfo.notBatchReportInfo[yyIdx],
          'allFeedQuantity',
          value
        );

        let count = 0;
        this.list[idx].extInfo.batchReportInfo.forEach((m) => {
          count = count + Number(m.allFeedQuantity || 0);
        });

        let count2 = 0;
        this.list[idx].extInfo.notBatchReportInfo.forEach((m) => {
          count2 = count2 + Number(m.allFeedQuantity || 0);
        });

        if (Number(count + count2) > this.list[idx].feedQuantity) {
          this.$set(
            this.list[idx].extInfo.notBatchReportInfo[yyIdx],
            'allFeedQuantity',
            0
          );
          this.$forceUpdate();
          this.$message.info('投料数不能大于投料数量');

          this.$emit('countNumPl', this.list, this.index);
        } else {
          this.$emit('countNumPl', this.list, this.index);
        }
      },
      blurWeight2(it, idx, yyIdx) {
        let value = it.allReportWeight;
        // value = value.replace(/\./g, '');
        this.$set(
          this.list[idx].extInfo.notBatchReportInfo[yyIdx],
          'allReportWeight',
          value
        );
        this.$emit('countNumPl', this.list, this.index);
      },

      handDel3(idx, yyIdx) {
        this.list[idx].extInfo.batchReportInfo.splice(yyIdx, 1);
        this.$emit('countNumPl', this.list, this.index);
      },

      selectName(value, idx, yyIdx) {
        const taskObj = this.stepsList.find((item) => item.taskId === value);
        this.$set(
          this.list[idx].extInfo.batchReportInfo[yyIdx],
          'taskName',
          taskObj.taskTypeName
        );
        this.$forceUpdate();
      },

      handAddListPL4(idx) {
        let deviceid = '';
        if (this.deviceList.length > 0) {
          deviceid = this.deviceList[0].id || this.deviceList[0].instanceId;
        }
        this.list[idx].extInfo.notBatchReportInfo.push({
          allFeedQuantity: '',
          notType: '',
          taskId: '',
          taskName: '',
          notReason: '',
          deviceId: deviceid ? deviceid : '',
          deviceName:
            this.deviceList.length > 0 ? this.deviceList[0].deviceName : '',
          heatNumber:
            this.deviceList.length > 0
              ? this.deviceList[0].extInfo.heatNumber
              : ''
        });
        this.$forceUpdate();
      },

      handDel4(idx, yyIdx) {
        this.list[idx].extInfo.notBatchReportInfo.splice(yyIdx, 1);
        this.$emit('countNumPl', this.list, this.index);
      },

      handLoad() {
        this.$forceUpdate();
      }
    },

    created() {
      this.getTaskFn();
    }
  };
</script>

<style lang="scss" scoped>
  .tag_box {
    display: inline-block;
    padding: 1px 6px;
    margin-right: 6px;
    background: #e6a23c;
    font-size: 11px;
    color: #fff;
    border-radius: 2px;
  }

  .content_num {
    --input-background-color: #f0f8f2;
  }

  .numerate {
    font-size: 22rpx;
    color: #157a2c;
    cursor: pointer;
  }

  .material {
    width: 90%;
    margin: auto;
  }

  .btn_end {
    text-align: right;
    margin-bottom: 10px;
  }

  .content_table2 {
    width: 100%;

    .row {
      width: 100%;

      .item {
        color: #404446;
        font-size: 14px;
        padding-left: 6px;
        text-align: center;
      }

      .color157 {
        color: #157a2c;
      }

      .ww20 {
        width: 20%;
      }

      .ww30 {
        width: 30%;
      }

      .ww25 {
        width: 25%;
      }

      .ww35 {
        width: 35%;
      }

      .ww10 {
        width: 10%;
      }
    }

    .head {
      height: 32px;
      background: #f7f9fa;
      border-top: 1px solid #e3e5e5;
      border-left: 1px solid #e3e5e5;

      .item {
        height: 32px;
        line-height: 32px;
        border-right: 1px solid #e3e5e5;
        box-sizing: border-box;
      }
    }

    .tr {
      border-top: 1px solid #e3e5e5;
      border-left: 1px solid #e3e5e5;

      .item {
        font-size: 12px;
        min-height: 32px;
        display: flex;
        align-items: center;
        border-right: 1px solid #e3e5e5;
        box-sizing: border-box;
        white-space: normal;
        word-break: break-all;
      }

      &:last-child {
        border-bottom: 1px solid #e3e5e5;
      }
    }
  }

  .formula_box {
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
    margin-top: 15px;
    color: #157a2c;
  }

  .reportWeight {
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
    margin-top: 15px;
    color: #157a2c;
  }

  .content_num {
    display: flex;
    align-items: center;
    padding: 2px;
    --input-background-color: #f0f8f2;
  }
</style>
