<template>
  <div class="app-container">

    <el-card>

      <el-col :span="12">
        <el-form label-width="270px" label-position="right" class="Time">
          <el-form-item v-show="false">
            <el-radio-group v-model="radio" size="small">
              <el-radio :label="0">正常件投产</el-radio>
              <el-radio :label="1">整改件投产</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="机床号" style="margin-top:28px">
            <el-select v-model="toolNumValue" filterable size="small" style="margin-bottom:10px" placeholder="机床号" @change="typeChange1()">
              <el-option
                v-for="item in toolNum"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <div style="float: left">{{ item.label }}</div>
                <div style="float: right; color: #8492a6; font-size: 13px">{{ item.value2 }}</div>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="分组">
            <el-select v-model="NumValue" filterable size="small" style="margin-bottom:10px" placeholder="分组" @change="total = 0;pageSize = 10;pageList = 1;getTable()">
              <el-option
                v-for="item in Num"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-button type="success" size="small" icon="el-icon-search" style="margin-left:10px" @click="total = 0;pageSize = 10;pageList = 1;getTable()">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>

      <el-col style="width: 530px">
        <el-form label-width="70px" label-position="left" class="Time">
          <el-form-item label="计划下达">
            <el-col :span="11">
              <el-date-picker v-model="time_planStart" size="small" type="datetime" class="time" readonly/>
            </el-col>
            <el-col :span="1" class="line">～</el-col>
            <el-col :span="11">
              <el-date-picker v-model="time_planFinish" size="small" type="datetime" class="time" readonly/>
            </el-col>
          </el-form-item>
          <el-form-item label="工艺">
            <el-col :span="11">
              <el-date-picker v-model="time_gongyiStart" size="small" type="datetime" class="time" readonly/>
            </el-col>
            <el-col :span="1" class="line">～</el-col>
            <el-col :span="11">
              <el-date-picker v-model="time_gongyiFinish" size="small" type="datetime" class="time" readonly/>
            </el-col>
          </el-form-item>
          <el-form-item label="定额">
            <el-col :span="11">
              <el-date-picker v-model="time_dingeStart" size="small" type="datetime" class="time" readonly/>
            </el-col>
            <el-col :span="1" class="line">～</el-col>
            <el-col :span="11">
              <el-date-picker v-model="time_dingeFinish" size="small" type="datetime" class="time" readonly/>
            </el-col>
          </el-form-item>
          <el-form-item label="计划平衡">
            <el-col :span="11">
              <el-date-picker v-model="time_planpinghengStart" size="small" type="datetime" class="time" readonly/>
            </el-col>
            <el-col :span="1" class="line">～</el-col>
            <el-col :span="11">
              <el-date-picker v-model="time_planpinghengFinish" size="small" type="datetime" class="time" readonly/>
            </el-col>
          </el-form-item>
          <el-form-item label="加工">
            <el-col :span="11">
              <el-date-picker v-model="time_machiningStart" size="small" type="datetime" class="time" readonly/>
            </el-col>
            <el-col :span="1" class="line">～</el-col>
            <el-col :span="11">
              <el-date-picker v-model="time_machiningFinish" default-time="23:59:59" size="small" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" style="margin-bottom:20px;width:200px"/>
            </el-col>
          </el-form-item>
        </el-form>
      </el-col>

    </el-card>

    <el-card>
      <div>
        <el-table
          v-loading="listLoading"
          :data="tableData"
          border
          style="width: 100%;max-height: 400px"
          height="400"
          @selection-change="handleSelectionChange"
          @row-click="handleCurrentChange1">
          <el-table-column
            type="selection"
            align="center"
            width="35"/>
          <el-table-column label="零件号" align="center" min-width="220">
            <template slot-scope="scope">
              {{ scope.row.零件图号 }}
            </template>
          </el-table-column>
          <el-table-column label="零件名称" align="center">
            <template slot-scope="scope">
              {{ scope.row.零件名称 }}
            </template>
          </el-table-column>
          <el-table-column label="投产" align="center">
            <template slot-scope="scope">
              {{ scope.row.投产总数量 }}
            </template>
          </el-table-column>
          <el-table-column label="批次" align="center">
            <template slot-scope="scope">
              {{ scope.row.最大投产批次 }}
            </template>
          </el-table-column>
          <el-table-column label="已投" align="center">
            <template slot-scope="scope">
              {{ scope.row.已投产数量 }}
            </template>
          </el-table-column>
          <el-table-column label="未投" align="center">
            <template slot-scope="scope">
              {{ scope.row.未投产数量 }}
            </template>
          </el-table-column>
          <el-table-column label="零件类型" align="center" width="100">
            <template slot-scope="scope">
              {{ scope.row.零件类型名称 }}
            </template>
          </el-table-column>
          <!--<el-table-column label="是否外协" align="center" width="90">-->
          <!--<template slot-scope="scope">-->
          <!--<el-checkbox v-model="tableData[scope.$index].checked_waixie" @change="gaibianwaixie(scope.$index, scope.row)"/>-->
          <!--外协-->
          <!--</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column label="是否带料" align="center" width="90">-->
          <!--<template slot-scope="scope">-->
          <!--<el-checkbox :disabled="!tableData[scope.$index].checked_waixie" v-model="tableData[scope.$index].checked_dailiao"/>-->
          <!--带料-->
          <!--</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column label="是否着急" align="center" width="90">-->
          <!--<template slot-scope="scope">-->
          <!--<el-checkbox v-model="tableData[scope.$index].checked_zhaoji"/>-->
          <!--着急-->
          <!--</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column prop="name" label="打回原因" width="170" align="center">-->
          <!--<template slot-scope="scope">-->
          <!--<el-input v-model="tableData[scope.$index].name" type="textarea" :rows="1" style="width:150px" placeholder="原因">-->
          <!--</el-input>-->
          <!--</template>-->
          <!--</el-table-column>-->
          <el-table-column label="操作" width="200px" fixed="right" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                @click="handleEdit(scope.$index, scope.row, 'form')">分批投产</el-button>
                <!--<el-button-->
                <!--size="mini"-->
                <!--type="primary"-->
                <!--@click="handleDele(scope.$index, scope.row, 'form1')">打回</el-button>-->
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            :total="total"
            style="width:50%;display:inline-block;"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
          <!--<el-checkbox v-model="checked_baitu" style="margin-top:0px">是否白图</el-checkbox>-->
          <!--<el-checkbox v-model="checked_gaonandu">是否高难度</el-checkbox>-->
          <el-button :loading="listLoading3" type="primary" size="small" style="float:right;margin-top:10px" @click="production">投产</el-button>
        </div>
      </div>
    </el-card>

    <el-card>
      <div>
        <el-table
          v-loading="listLoading1"
          :data="tableData1"
          stripe
          size="mini"
          tooltip-effect="dark"
          style="width: 100%">
          <el-table-column
            label="零件号">
            <template slot-scope="scope">{{ scope.row.零件图号 }}</template>
          </el-table-column>
          <el-table-column
            label="零件名称">
            <template slot-scope="scope">{{ scope.row.零件名称 }}</template>
          </el-table-column>
          <el-table-column
            label="投产总数量">
            <template slot-scope="scope">{{ scope.row.投产总数量 }}</template>
          </el-table-column>
          <el-table-column
            label="未投产数量">
            <template slot-scope="scope">{{ scope.row.未投产数量 }}</template>
          </el-table-column>
          <el-table-column
            label="投产批次">
            <template slot-scope="scope">{{ scope.row.投产批次 }}</template>
          </el-table-column>
          <el-table-column
            label="批次数量">
            <template slot-scope="scope">{{ scope.row.批次数量 }}</template>
          </el-table-column>
          <!--<el-table-column-->
          <!--label="是否外协">-->
          <!--<template slot-scope="scope">{{ scope.row.是否外协 }}</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column-->
          <!--label="是否带料">-->
          <!--<template slot-scope="scope">{{ scope.row.是否带料 }}</template>-->
          <!--</el-table-column>-->
          <el-table-column
            label="机加工开始时间">
            <template slot-scope="scope">{{ scope.row.机加工开始时间 }}</template>
          </el-table-column>
          <el-table-column
            label="机加工结束时间">
            <template slot-scope="scope">{{ scope.row.机加工结束时间 }}</template>
          </el-table-column>
          <el-table-column label="操作" width="200px">
            <template slot-scope="scope">
              <el-button
                size="mini"
                fixed="rihgt"
                type="primary"
                icon="el-icon-edit"
                @click="handleEdit1(tableData1, scope.$index, scope.row, 'form')">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            :current-page="currentPage3"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize3"
            :total="total3"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange3"
            @current-change="handleCurrentChange3"/>
        </div>

      </div>
    </el-card>

    <el-dialog :visible.sync="dialogFormVisible2" title="打回档案" center width="28%">
      <el-form ref="form1" :model="form1" :rules="rules" label-position="left" label-width="110px" class="demo-ruleForm">
        <el-form-item label="打回原因" prop="reason">
          <el-input v-model="form1.reason" size="small" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff1('form1')">取消</el-button>
        <el-button size="small" type="primary" @click="submit1('form1')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="dialogFormVisible1" center width="450px">
      <el-form ref="form" :model="form" :rules="rules" label-position="left" label-width="110px" class="demo-ruleForm">
        <el-form-item label="零件图号" prop="PDnumber">
          <el-input v-model="form.PDnumber" size="small" readonly style="width:250px" />
        </el-form-item>
        <el-form-item label="投产总数量" prop="quantity">
          <el-input v-model="form.quantity" size="small" readonly style="width:250px" />
        </el-form-item>
        <el-form-item label="未投产数量" prop="unputquantity">
          <el-input v-model="form.unputquantity" size="small" readonly style="width:250px"/>
        </el-form-item>
        <el-form-item label="投产批次" prop="productionBatch">
          <el-input v-model="form.productionBatch" size="small" readonly style="width:250px" placeholder="请输入投产批次"/>
        </el-form-item>
        <el-form-item v-show="temp === 1" label="批次数量1" prop="batchQuantity">
          <el-input-number v-model="form.batchQuantity" :min="1" :max="parseInt(form.unputquantity)" size="small" style="width:250px" label="批次数量"/>
        </el-form-item>
        <el-form-item v-show="temp === 2" label="批次数量2" prop="batchQuantity2">
          <el-input-number v-model="form.batchQuantity2" :min="1" :max="parseInt(maxmax)" size="small" style="width:250px" label="批次数量"/>
        </el-form-item>
        <el-form-item label="加工开始时间">
          <el-date-picker
            v-model="form.startDate_F"
            size="small"
            readonly
            type="date"
            value-format="yyyy-MM-dd"
            style="top: 1px;width:250px"
            placeholder="选择开始日期"/>
        </el-form-item>
        <el-form-item label="加工结束时间" prop="endDate_F">
          <el-date-picker
            :readonly="readonly"
            v-model="form.endDate_F"
            size="small"
            type="date"
            value-format="yyyy-MM-dd"
            style="top: 1px;width:250px"
            placeholder="选择结束日期"/>
        </el-form-item>
        <el-row>
          <el-col :span="14"/>
          <el-form-item >
            <el-button size="small" @click="callOff('form')">取消</el-button>
            <el-button size="small" type="primary" @click="submit('form')">确定</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import { getEntryNameValue, getToolNum, getNum, getTable, production, getTable1, revisionBatch, editList, dele } from '@/api/ManufacturingCenter/InitialProduction'
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      maxmax: '',
      clearTable: 0,
      readonly: true,
      gongyirenwuzhuangtai: '',
      count: 0, // 表单计数器
      count2: 0,
      count3: 0,
      midcode: 0, // 查询表2的中间变量
      shijiancuo: 0,
      shijiancuo1: 0,
      jieguo: 0,
      value: '',
      title: null,
      listLoading3: false,
      temp: 0,
      ComponentflowNumber: '', // 组件零件基本件流水号
      TypeflowNumber: '',
      dataType: '', // 数据类型
      productionQuantity: '', // 投产总数量
      checked_waixie1: '',
      MaterialflowNumber: '', // 材料流水号
      checked_zhaoji1: '',
      time_planStart: '',
      time_planFinish: '',
      time_gongyiFinish: '',
      time_gongyiStart: '',
      time_dingeFinish: '',
      time_dingeStart: '',
      time_planpinghengFinish: '',
      time_planpinghengStart: '',
      time_machiningFinish: '',
      time_machiningStart: '',
      form: { // 修改表单
        PDnumber: '',
        quantity: '',
        unputquantity: '',
        productionBatch: '',
        batchQuantity: '',
        batchQuantity2: '',
        startDate_F: '',
        endDate_F: ''
      },
      form1: {
        reason: ''
      },
      rules: { // 表单验证规则
        batchQuantity: [{ required: true, message: '请输入批次数量', trigger: 'blur' }],
        // startDate_F: [{ required: true, message: '请选择加工开始时间', trigger: 'change' }],
        endDate_F: [{ required: true, message: '请选择加工结束时间', trigger: 'change' }],
        reason: [{ required: true, message: '请输入打回原因', trigger: 'blur' }]
      },
      // value1: '',
      result: 0,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      date: '',
      a: false,
      multipleSelection: [],
      checked_baitu: false,
      checked_gaonandu: false,
      tableData: [], // 表1
      tableData1: [], // 表2
      entryNameValue: '',
      entryName: [], // 项目名称
      toolNumValue: '',
      toolNum: [], // 机床号
      NumValue: '',
      Num: [], // 分组
      liushuihao: '',
      gongyijihua: '',
      radio: 0, // 第一组
      total: 0, // 总条数
      pageSize: 10, // 每页显示条数
      pageList: 1, // 后台获取页
      currentPage: 1, // 显示当前页
      total3: 0, // 总条数
      pageSize3: 10, // 每页显示条数
      pageList3: 1, // 后台获取页
      currentPage3: 1, // 显示当前页
      listLoading: false,
      listLoading1: false
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id'
    ])
  },
  created() {
    this.typeChange()
    this.getCurrentTime()
    this.getNowTime()
  },
  methods: {
    gaibianwaixie(index, row) {
      if (row.checked_waixie === false) {
        row.checked_dailiao = false
      }
    },
    select(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    getCurrentTime() {
      this.time_planFinish = this.getTime0(0)
      this.time_gongyiFinish = this.getTime0(2)
      this.time_gongyiStart = this.getTime0(0)
      this.time_dingeFinish = this.getTime0(2)
      this.time_dingeStart = this.getTime0(2)
      this.time_planpinghengFinish = this.getTime0(3)
      this.time_planpinghengStart = this.getTime0(2)
      this.time_machiningStart = this.getTime0(3)
      const _this = this
      setTimeout(() => {
        _this.getCurrentTime()
      }, 1000)
    },
    getTime0(num) {
      var date0 = new Date()
      var date = new Date(date0.getTime() + num * 24 * 60 * 60 * 1000)
      var month = this.zeroFill(date.getMonth() + 1)
      var day = this.zeroFill(date.getDate())
      var hour = this.zeroFill(date.getHours())
      var minute = this.zeroFill(date.getMinutes())
      var second = this.zeroFill(date.getSeconds())
      return date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
    },
    getNowTime() {
      var date = new Date()
      var month = this.zeroFill(date.getMonth() + 1)
      var day = this.zeroFill(date.getDate())
      var hour = this.zeroFill(date.getHours())
      var minute = this.zeroFill(date.getMinutes())
      var second = this.zeroFill(date.getSeconds())
      this.time_planStart = date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
    },
    zeroFill(i) {
      if (i >= 0 && i <= 9) {
        return '0' + i
      } else {
        return i
      }
    },
    // 初始化获取项目名称
    fetchData() {
      getEntryNameValue().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.entryName.push({
            label: response.data[i].项目名称,
            value: response.data[i].项目流水号
          })
        }
      })
    },
    typeChange() {
      this.NumValue = ''
      this.Num = []
      getToolNum().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.toolNum.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号,
            value2: response.data[i].项目名称
          })
        }
      })
    },
    typeChange1() {
      this.NumValue = ''
      this.Num = []
      getNum(this.toolNumValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.Num.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    getTable() {
      if (this.NumValue === '') {
        this.$message.error('请选择机床组号')
      } else {
        this.listLoading = true
        this.tableData1 = []
        getTable(this.NumValue, this.pageList, this.pageSize).then(response => {
          this.total = parseInt(response.data.total)
          this.tableData = []
          for (let i = 0; i < response.data.rows.length; i++) {
            this.tableData.push({
              零件图号: response.data.rows[i].零件图号,
              零件名称: response.data.rows[i].零件名称,
              投产总数量: response.data.rows[i].投产总数量,
              最大投产批次: response.data.rows[i].最大投产批次,
              已投产数量: response.data.rows[i].已投产数量,
              未投产数量: response.data.rows[i].未投产数量,
              零件类型名称: response.data.rows[i].零件类型名称,
              组件零件基本件流水号: response.data.rows[i].组件零件基本件流水号,
              投产类型流水号: response.data.rows[i].投产类型流水号,
              数据类型: response.data.rows[i].数据类型,
              材料流水号: response.data.rows[i].材料流水号,
              checked_dailiao: false,
              checked_waixie: false,
              checked_zhaoji: false
            })
          }
        }).then(() => {
          this.listLoading = false
        })
      }
    },
    // 点击Table查询设备信息
    handleCurrentChange1(row) {
      this.tableData1 = []
      this.listLoading1 = true
      getTable1(row.组件零件基本件流水号, this.pageList3, this.pageSize3).then(response => {
        if (response.data.total !== 0) {
          this.gongyirenwuzhuangtai = response.data.rows[0].工艺任务分配状态
          this.midcode = row.组件零件基本件流水号
          this.total3 = parseInt(response.data.total)
          this.tableData1 = response.data.rows
        }
        this.listLoading1 = false
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 打开分批投产
    handleEdit(index, row, formName) {
      this.temp = 1
      this.title = '分批投产'
      this.readonly = true
      this.midcode = row.组件零件基本件流水号
      if (this.time_machiningFinish === '') {
        this.$message.error('请选择加工结束时间')
      } else {
        this.count = this.count + 1
        if (this.count !== 1) {
          this.$refs[formName].resetFields()
        }
        this.form.endDate_F = this.time_machiningFinish
        this.form.PDnumber = row.零件图号
        this.form.quantity = row.投产总数量
        if (row.未投产数量 !== '' && row.未投产数量 !== null) {
          this.form.unputquantity = row.未投产数量
        } else {
          this.form.unputquantity = row.投产总数量
        }
        if (row.最大投产批次 !== '' && row.最大投产批次 !== null) {
          this.form.productionBatch = parseInt(row.最大投产批次) + 1
        } else {
          this.form.productionBatch = 1
        }
        this.form.startDate_F = this.time_machiningStart
        this.ComponentflowNumber = row.组件零件基本件流水号
        this.TypeflowNumber = row.投产类型流水号
        this.dataType = row.数据类型
        this.productionQuantity = row.投产总数量
        this.checked_waixie1 = row.checked_waixie
        this.MaterialflowNumber = row.材料流水号
        this.checked_zhaoji1 = row.checked_zhaoji
        this.dialogFormVisible1 = true
      }
    },
    // 打开编辑
    handleEdit1(tableData, index, row, formName) {
      let Sum = null
      this.temp = 2
      this.title = '编辑'
      this.readonly = false
      this.count3 = this.count3 + 1
      if (this.count3 !== 1) {
        this.$refs[formName].resetFields()
      }
      this.form.endDate_F = row.机加工结束时间
      this.dialogFormVisible1 = true
      this.form.PDnumber = row.零件图号
      this.form.quantity = row.投产总数量
      if (row.最大投产批次 !== '' && row.最大投产批次 !== null) {
        this.form.productionBatch = row.最大投产批次
      } else {
        this.form.productionBatch = 1
      }
      this.form.startDate_F = row.机加工开始时间
      this.ComponentflowNumber = row.组件零件基本件流水号
      this.TypeflowNumber = row.投产类型流水号
      this.dataType = row.数据类型
      this.productionQuantity = row.投产总数量
      this.checked_waixie1 = row.checked_waixie
      this.MaterialflowNumber = row.材料流水号
      this.checked_zhaoji1 = row.checked_zhaoji
      this.form.batchQuantity2 = parseInt(row.批次数量)
      this.form.batchQuantity = parseInt(row.批次数量)
      this.gongyijihua = row.工艺计划流水号
      this.form.unputquantity = row.投产总数量 - row.已投产数量
      for (let i = 0; i < tableData.length; i++) {
        Sum += parseInt(tableData[i].批次数量)
        if (i === tableData.length - 1) {
          Sum -= parseInt(row.批次数量)
          this.maxmax = row.投产总数量 - Sum
        }
      }
    },
    // 提交编辑
    submitEdit() {
      this.shijiancuo1 = Date.parse(this.form.startDate_F)
      this.shijiancuo = Date.parse(this.form.endDate_F)
      this.jieguo = this.shijiancuo1 - this.shijiancuo
      if (this.jieguo >= 0) {
        this.$message.error('加工结束时间应大于开始时间')
      } else {
        this.temp = null
        if (this.gongyirenwuzhuangtai === '1') {
          editList(this.gongyijihua, this.form.batchQuantity2, this.form.startDate_F, this.form.endDate_F).then(response => {
            if (response.data[0].result === '1') {
              this.dialogFormVisible1 = false
              this.$message({
                type: 'success',
                message: '信息更新成功!'
              })
              getTable1(this.midcode, this.pageList3, this.pageSize3).then(response => {
                this.total3 = parseInt(response.data.total)
                this.tableData1 = response.data.rows
                this.listLoading1 = false
              })
              this.total = 0
              this.pageSize = 10
              this.pageList = 1
              this.getTable()
            } else {
              this.dialogFormVisible1 = false
              this.$message.error('信息更新失败')
            }
          })
        } else {
          this.dialogFormVisible1 = false
          this.$message.error('零件任务已经分配，无法更改')
        }
        this.shijiancuo1 = 0
        this.shijiancuo = 0
        this.jieguo = 0
      }
    },
    // 分批投产确定
    revisionBatch() {
      if (this.checked_waixie1 === false) {
        this.checked_waixie1 = 1
      } else {
        this.checked_waixie1 = 2
      }
      if (this.checked_zhaoji1 === false) {
        this.checked_zhaoji1 = 0
      } else {
        this.checked_zhaoji1 = 1
      }
      if (this.checked_gaonandu === false) {
        this.checked_gaonandu = 0
      } else {
        this.checked_gaonandu = 1
      }
      if (this.checked_baitu === false) {
        this.checked_baitu = 0
      } else {
        this.checked_baitu = 1
      }
      if (this.checked_dailiao === true) {
        this.checked_dailiao = 2
      } else {
        this.checked_dailiao = 1
      }
      this.shijiancuo1 = Date.parse(this.time_machiningStart)
      this.shijiancuo = Date.parse(this.form.endDate_F)
      this.jieguo = this.shijiancuo1 - this.shijiancuo
      if (this.jieguo >= 0) {
        this.$message.error('加工结束时间应大于开始时间')
      } else {
        this.temp = null
        this.listLoading = true
        revisionBatch(this.ComponentflowNumber, this.TypeflowNumber, this.dataType, this.form.productionBatch, this.form.batchQuantity, this.time_planStart, this.time_planFinish, this.time_gongyiStart, this.time_gongyiFinish, this.time_dingeStart, this.time_dingeFinish, this.time_planpinghengStart, this.time_planpinghengFinish, this.time_machiningStart, this.time_machiningFinish, this.time_planStart, this.checked_waixie1, this.checked_dailiao, this.id, this.MaterialflowNumber, this.radio, this.checked_gaonandu, this.checked_zhaoji1, this.checked_baitu).then(response => {
          if (response.data[0].result === '1') {
            this.dialogFormVisible1 = false
            this.$message({
              type: 'success',
              message: '分批投产成功!'
            })
            this.clearTable = this.total
            this.checked_baitu = false
            this.checked_gaonandu = false
            this.total = 0
            this.pageSize = 10
            this.pageList = 1
            this.shijiancuo1 = 0
            this.shijiancuo = 0
            this.checked_dailiao = 0
            this.jieguo = 0
            this.tableData = []
            getTable(this.NumValue, this.pageList, this.pageSize).then(response => {
              this.total = parseInt(response.data.total)
              for (let i = 0; i < response.data.rows.length; i++) {
                this.tableData.push({
                  零件图号: response.data.rows[i].零件图号,
                  零件名称: response.data.rows[i].零件名称,
                  投产总数量: response.data.rows[i].投产总数量,
                  最大投产批次: response.data.rows[i].最大投产批次,
                  已投产数量: response.data.rows[i].已投产数量,
                  未投产数量: response.data.rows[i].未投产数量,
                  零件类型名称: response.data.rows[i].零件类型名称,
                  组件零件基本件流水号: response.data.rows[i].组件零件基本件流水号,
                  投产类型流水号: response.data.rows[i].投产类型流水号,
                  数据类型: response.data.rows[i].数据类型,
                  材料流水号: response.data.rows[i].材料流水号,
                  checked_dailiao: false,
                  checked_waixie: false,
                  checked_zhaoji: false
                })
              }
              return this.total
            }).then((total) => {
              this.listLoading = false
              getTable1(this.midcode, this.pageList3, this.pageSize3).then(response => {
                const data = response.data.rows
                for (let i = 0; i < data.length; i++) {
                  data[i].批次数量 = parseInt(data[i].批次数量)
                }
                this.total3 = parseInt(response.data.total)
                if (this.clearTable === total) {
                  this.tableData1 = data
                } else {
                  this.tableData1 = []
                }
                this.listLoading1 = false
              })
            })
          } else {
            this.dialogFormVisible1 = false
            this.$message.error('分批投产失败')
          }
        })
      }
    },
    // 投产
    production() {
      this.listLoading3 = true
      this.result = 0
      if (this.time_machiningFinish === '' || this.time_machiningFinish === null) {
        this.$message.error('请输入加工结束时间')
      } else {
        this.shijiancuo1 = Date.parse(this.time_machiningStart)
        this.shijiancuo = Date.parse(this.time_machiningFinish)
        this.jieguo = this.shijiancuo1 - this.shijiancuo
        if (this.jieguo >= 0) {
          this.$message.error('加工结束时间应大于开始时间')
        } else {
          if (this.multipleSelection.length === 0) {
            this.$message.error('请至少选择一个零件')
          } else {
            for (let i = 0; i < this.multipleSelection.length; i++) {
              if (this.multipleSelection[i].checked_waixie === false) {
                this.multipleSelection[i].checked_waixie = 1
              } else {
                this.multipleSelection[i].checked_waixie = 2
              }
              if (this.multipleSelection[i].checked_zhaoji === false) {
                this.multipleSelection[i].checked_zhaoji = 0
              } else {
                this.multipleSelection[i].checked_zhaoji = 1
              }
              if (this.multipleSelection[i].checked_dailiao === true) {
                this.multipleSelection[i].checked_dailiao = 2
              } else {
                this.multipleSelection[i].checked_dailiao = 1
              }
              if (this.checked_gaonandu === false) {
                this.checked_gaonandu = 0
              } else {
                this.checked_gaonandu = 1
              }
              if (this.checked_baitu === false) {
                this.checked_baitu = 0
              } else {
                this.checked_baitu = 1
              }
              production(this.multipleSelection[i].组件零件基本件流水号, this.multipleSelection[i].投产类型流水号, this.multipleSelection[i].数据类型, this.multipleSelection[i].投产总数量, this.time_planStart, this.time_planFinish, this.time_gongyiStart, this.time_gongyiFinish, this.time_dingeStart, this.time_dingeFinish, this.time_planpinghengStart, this.time_planpinghengFinish, this.time_machiningStart, this.time_machiningFinish, this.time_planStart, this.multipleSelection[i].checked_waixie, this.multipleSelection[i].checked_dailiao, this.id, this.multipleSelection[i].材料流水号, this.radio, this.checked_gaonandu, this.multipleSelection[i].checked_zhaoji, this.checked_baitu).then(response => {
                this.result += parseInt(response.data[0].result)
                if (this.result === this.multipleSelection.length) {
                  this.$message.success('投产成功')
                  this.total = 0
                  this.pageList = 1
                  this.getTable()
                  this.checked_baitu = false
                  this.checked_gaonandu = false
                  this.tableData1 = []
                  this.listLoading3 = false
                } else if (response.data[0].result === '0') {
                  this.listLoading3 = false
                  this.$message.error('投产失败')
                }
              })
              this.shijiancuo1 = 0
              this.shijiancuo = 0
              this.jieguo = 0
            }
          }
        }
      }
    },
    // 打回档案
    handleDele(index, row, formName) {
      this.count2 = this.count2 + 1
      if (this.count2 !== 1) {
        this.$refs[formName].resetFields()
      }
      this.temp = 3
      this.liushuihao = row.组件零件基本件流水号
      this.form1.reason = ''
      this.dialogFormVisible2 = true
    },
    Dele() {
      dele(this.liushuihao, this.form1.reason, this.time_gongyiStart).then(response => {
        if (response.data[0].result === '1') {
          this.dialogFormVisible2 = false
          this.$message({
            type: 'success',
            message: '打回档案成功!'
          })
          this.total = 0
          this.pageSize = 10
          this.pageList = 1
          this.getTable()
        } else {
          this.dialogFormVisible2 = false
          this.$message.error('打回档案失败')
        }
      })
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.temp === 1) {
            this.revisionBatch()
          } else if (this.temp === 2) {
            this.submitEdit()
            // this.temp = null
          }
        } else {
          return false
        }
      })
    },
    // 重置表单
    callOff(formName) {
      this.dialogFormVisible1 = false
      this.$refs[formName].resetFields()
    },
    submit1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.Dele()
        } else {
          return false
        }
      })
    },
    // 重置表单
    callOff1(formName) {
      this.dialogFormVisible2 = false
      this.$refs[formName].resetFields()
    },
    // 分页
    handleSizeChange(val) {
      this.pageSize = val
      this.getTable()
    },
    handleCurrentChange(val) {
      this.pageList = val
      this.getTable()
    },
    handleSizeChange3(val) {
      this.pageSize3 = val
      this.getTable1()
    },
    handleCurrentChange3(val) {
      this.pageList3 = val
      this.getTable1()
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  .el-date-editor{
    width:150px
  }
  .el-select{
    width:200px
  }
  span{
    margin: 10px 0 10px 10px;
  }
  .time{
    width: 200px;
  }
  .Time>.el-form-item{
    margin:2px;
    /*margin-left: 120px;*/
  }
</style>
