<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <span>机床编号:</span>
        <el-select v-model="machineNumberValue" filterable placeholder="机床编号" size="small" clearable @change="machineChange">
          <el-option
            v-for="item in machineNumber"
            :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.name }}</div>
          </el-option>
        </el-select>
        <span>组号:</span>
        <el-select v-model="groupNumberValue" placeholder="组号" size="small" clearable>
          <el-option
            v-for="item in groupNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="searchTable()">查询</el-button>
        <el-badge :value="value1" :max="99" class="item">
          <el-button size="small" type="text" @click="PartCallbackInformation1">外购件和标准件打回信息</el-button>
        </el-badge>
        <el-badge :value="value" :max="99" class="item">
          <el-button size="small" type="text" @click="PartCallbackInformation">基本件打回信息</el-button>
        </el-badge>
      </el-row>
    </el-card>
    <el-card>
      <el-table :data="tableData" border size="mini" highlight-current-row style="width: 100%;margin-top: 15px" height="250px" @row-click="searchPart">
        <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>
    </el-card>
    <el-card>
      <el-tabs type="border-card" @tab-click="selectPart">
        <el-tab-pane label="基本件">
          <el-table :data="tableData1" border size="mini" style="width: 100%" height="300px" @selection-change="handleSelectionChange">
            <el-table-column align="center" width="50" type="selection"/>
            <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">
              <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="120px" fixed="right">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleEdit(scope.row)">使用</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="外购件">
          <el-table :data="tableData2" border size="mini" style="width: 100%" height="300px" @selection-change="handleSelectionChange">
            <el-table-column align="center" width="50" type="selection"/>
            <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">
              <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="120px" fixed="right">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleEdit2(scope.row)">使用</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="标准件">
          <el-table :data="tableData3" border size="mini" style="width: 100%" height="300px" @selection-change="handleSelectionChange">
            <el-table-column align="center" width="50" type="selection"/>
            <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">
              <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="120px" fixed="right">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleEdit2(scope.row)">使用</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <span>交货期：</span>
      <el-date-picker
        v-model="time"
        size="small"
        type="date"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
        placeholder="选择日期"/>
      <el-button type="success" size="small" icon="el-icon-star-off" style="margin-top: 15px; margin-left: 15px" @click="purchaseRequisition()">制造部采购</el-button>
      <el-button type="primary" size="small" icon="el-icon-star-off" style="margin-top: 15px; margin-left: 15px" @click="PurchasingDepartment()">采购部门采购</el-button>
      <el-button type="warning" size="small" icon="el-icon-star-off" style="margin-top: 15px; margin-left: 15px" @click="Production()">车间生产</el-button>
    </el-card>
    <el-card>
      <el-row>
        <span>请购单号：</span>
        <el-input v-model="PurchaseOrder" size="small" style="width: 200px" placeholder="请购单号" clearable/>
        <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="searchTable1()">查询</el-button>
        <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" style="margin-left: 15px" @click="handleAdd()">创建</el-button>
      </el-row>
    </el-card>
    <el-card>
      <el-table :data="tableData4" border size="mini" style="width: 100%" height="200px" highlight-current-row @row-click="searchDetailed">
        <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="250px" fixed="right">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete" style="margin-left: 15px" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card>
      <el-table :data="tableData6" border size="mini" style="width: 100%" height="300px">
        <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">
          <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="250px" fixed="right">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleEdit1(scope.row)">编辑</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="MoveOut(scope.row)">移出</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card>
      <el-table :data="tableData5" border size="mini" style="width: 100%" height="300px">
        <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">
          <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="250px" fixed="right">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleEdit1(scope.row)">编辑</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="MoveOut(scope.row)">移出</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog :title="title" :visible.sync="dialogFormVisible" center style="min-height: 300px" width="400px">
      <el-form ref="form" :model="form" :rules="rules" label-position="left" label-width="110px" class="demo-ruleForm">

        <el-form-item label="请购车间" prop="请购车间">
          <el-input
            v-model="form.请购车间"
            size="small"
            style="width:200px"/>
        </el-form-item>

        <el-form-item label="请购人">
          <el-input
            v-model="name"
            size="small"
            readonly
            style="width:200px"/>
        </el-form-item>

        <el-form-item label="请购时间" prop="请购时间">
          <el-date-picker
            v-model="form.请购时间"
            size="small"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel('form')">取消</el-button>
        <el-button v-show="title==='增加'" type="primary" @click="submitAdd('form')">确定</el-button>
        <el-button v-show="title==='编辑'" type="primary" @click="submitEdit('form')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible3" title="更改数量" center style="min-height: 300px" width="400px">
      <el-form ref="form3" :model="form3" :rules="rules3" label-position="left" label-width="110px" class="demo-ruleForm">
        <el-form-item label="数量" prop="数量">
          <el-input
            v-model="form3.数量"
            size="small"
            style="width:200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel('form3')">取消</el-button>
        <el-button type="primary" @click="submitEdit1('form3')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible4" title="使用库存" center style="min-height: 300px" width="400px">
      <el-form ref="form4" :model="form4" :rules="rules4" label-position="left" label-width="110px" class="demo-ruleForm">
        <el-form-item label="数量" prop="数量">
          <el-input-number v-model="form4.数量" :min="0" :max="100" size="small" style="width:200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel('form4')">取消</el-button>
        <el-button type="primary" @click="submitEdit2('form4')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogFormVisible1"
      title="基本件打回信息"
      center
      width="70%"
      style="min-height: 400px">
      <el-table
        :data="tableData9"
        :row-class-name="tableRowClassName"
        size="mini"
        style="width: 97%;max-height: 300px"
        height="400"
        highlight-current-row
        border>
        <el-table-column align="center" label="零件图号">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件名称">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="材料">
          <template slot-scope="scope">
            {{ scope.row.材料 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件数量" width="70">
          <template slot-scope="scope">
            {{ scope.row.零件数量 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目名称">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="机床编号">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="组号">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="退回时间">
          <template slot-scope="scope">
            {{ scope.row.退回时间 }}
          </template>
        </el-table-column>
        <el-table-column property="date" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              @click="submit(scope.row)">确认</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="Delete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogFormVisible2"
      title="外购件和标准件打回信息"
      center
      width="70%"
      style="min-height: 400px">
      <el-table
        :data="tableData10"
        :row-class-name="tableRowClassName"
        size="mini"
        style="width: 97%;max-height: 300px"
        height="400"
        highlight-current-row
        border>
        <el-table-column align="center" label="物料名称">
          <template slot-scope="scope">
            {{ scope.row.物料名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="物料规格">
          <template slot-scope="scope">
            {{ scope.row.物料规格 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="物料型号">
          <template slot-scope="scope">
            {{ scope.row.物料型号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件数量" width="70">
          <template slot-scope="scope">
            {{ scope.row.零件数量 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目名称">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="机床编号">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="组号">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="退回时间">
          <template slot-scope="scope">
            {{ scope.row.退回时间 }}
          </template>
        </el-table-column>
        <el-table-column property="date" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              @click="submit1(scope.row)">确认</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="Delete1(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { initProject, searchgroup, searchTable, searchPart, searchPart1, searchTable1, addData, editData, deleteData, searchDetailed, searchDetailed1, purchaseRequisition, purchaseRequisition1, purchaseRequisition2, MoveOut, MoveOut1, PurchasingDepartment, Production, PartCallbackInformation, PartCallbackInformation1, submit, submit1, Delete, Delete1, editStock, editNum } from '@/api/ManufacturingCenter/PartAssignment'
import { mapGetters } from 'vuex'
export default {
  inject: ['reload'],
  data() {
    return {
      projectFloatValue: '',
      machineNumberValue: '',
      machineFloatValue: '',
      machineNumber: [],
      machineName: '',
      groupNumberValue: '',
      groupFloatValue: '',
      groupNumber: [],
      StandardAndOutsourcing: '',
      PartNum: '',
      DetailedNum: '',
      stockNum: '',
      MaterialNumber: '',
      PurchaseOrder: '',
      PartType: '基本件',
      tableData: [],
      tableData1: [],
      tableData2: [],
      tableData3: [],
      tableData4: [],
      tableData5: [],
      tableData6: [],
      loading: false,
      title: '',
      dialogFormVisible: false,
      RequisitionList: '',
      form: {
        请购单编号: '',
        请购车间: '',
        请购时间: ''
      },
      rules: {
        请购单编号: [{ required: true, message: '请输入请购单编号', trigger: 'blur' }],
        请购车间: [{ required: true, message: '请输入请购车间', trigger: 'blur' }],
        请购时间: [{ required: true, message: '请选择请购时间', trigger: 'change' }]
      },
      form3: {
        数量: ''
      },
      rules3: {
        数量: [{ required: true, message: '请输入数量', trigger: 'blur' }]
      },
      form4: {
        数量: ''
      },
      rules4: {
        数量: [{ required: true, message: '请输入数量', trigger: 'blur' }]
      },
      BasicPartsNumber: [],
      StandardPartsAndOutsourcing: [],
      MaterialNum: [],
      MaterialCode: [],
      MaterialName: [],
      PartToolNumber: [],
      MaterialSpecification: [],
      MaterialModel: [],
      NumberOfParts: [],
      ReMarks: [],
      projectName: '',
      MachineToolNumber: '',
      groupName: '',
      time: '',
      result: 0,
      pageSize: '',
      pageCurrent: '',
      total: '',
      check: '',
      value: 0,
      value1: 0,
      tableData9: [],
      tableData10: [],
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      dialogFormVisible4: false
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id'
    ])
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      initProject().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineNumber.push({
            label: response.data[i].机床图号,
            name: response.data[i].项目名称,
            value: response.data[i].机床流水号
          })
        }
      })
      PartCallbackInformation().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (response.data[i].退回时间 !== '') {
            response.data[i].退回时间 = (response.data[i].退回时间).split(' ')[0]
          }
          if (response.data[i].是否确认 === 0) {
            this.value += 1
          }
        }
        this.tableData9 = response.data
      })
      PartCallbackInformation1().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (response.data[i].退回时间 !== '') {
            response.data[i].退回时间 = (response.data[i].退回时间).split(' ')[0]
          }
          if (response.data[i].是否确认 === 0) {
            this.value1 += 1
          }
        }
        this.tableData10 = response.data
      })
    },
    PartCallbackInformation() {
      this.dialogFormVisible1 = true
    },
    PartCallbackInformation1() {
      this.dialogFormVisible2 = true
    },
    submit(row) {
      submit(row.基本件流水号).then(response => {
        this.value = 0
        if (response.data[0].result === '1') {
          this.$message.success('确认成功')
          PartCallbackInformation().then(response => {
            for (let i = 0; i < response.data.length; i++) {
              if (response.data[i].退回时间 !== '') {
                response.data[i].退回时间 = (response.data[i].退回时间).split(' ')[0]
              }
              if (response.data[i].是否确认 === 0) {
                this.value += 1
              }
            }
            this.tableData9 = response.data
          })
        } else {
          this.$message.error('确认失败')
        }
      })
    },
    submit1(row) {
      submit1(row.标准件和外购件流水号).then(response => {
        this.value1 = 0
        if (response.data[0].result === '1') {
          this.$message.success('确认成功')
          PartCallbackInformation1().then(response => {
            for (let i = 0; i < response.data.length; i++) {
              if (response.data[i].退回时间 !== '') {
                response.data[i].退回时间 = (response.data[i].退回时间).split(' ')[0]
              }
              if (response.data[i].是否确认 === 0) {
                this.value1 += 1
              }
            }
            this.tableData10 = response.data
          })
        } else {
          this.$message.error('确认失败')
        }
      })
    },
    Delete(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        Delete(row.基本件流水号).then(response => {
          this.value = 0
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            PartCallbackInformation().then(response => {
              for (let i = 0; i < response.data.length; i++) {
                if (response.data[i].退回时间 !== '') {
                  response.data[i].退回时间 = (response.data[i].退回时间).split(' ')[0]
                }
                if (response.data[i].是否确认 === 0) {
                  this.value += 1
                }
              }
              this.tableData9 = response.data
            })
          } else {
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    Delete1(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        Delete1(row.标准件和外购件流水号).then(response => {
          this.value1 = 0
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            PartCallbackInformation1().then(response => {
              for (let i = 0; i < response.data.length; i++) {
                if (response.data[i].退回时间 !== '') {
                  response.data[i].退回时间 = (response.data[i].退回时间).split(' ')[0]
                }
                if (response.data[i].是否确认 === 0) {
                  this.value1 += 1
                }
              }
              this.tableData10 = response.data
            })
          } else {
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    tableRowClassName({ row }) {
      console.log(row.是否确认)
      if (row.是否确认 === 0) {
        return 'NotThrough'
      } else {
        return 'adopt'
      }
    },
    machineChange() {
      this.groupNumberValue = ''
      this.groupNumber = []
      searchgroup(this.machineNumberValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.groupNumber.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    searchTable() {
      this.loading = true
      if (this.machineNumberValue !== '') {
        this.check2 = 1
      } else { this.check2 = 0 }
      if (this.groupNumberValue !== '') {
        this.check3 = 1
      } else { this.check3 = 0 }
      searchTable(this.machineNumberValue, this.check2, this.groupNumberValue, this.check3).then(response => {
        this.tableData = response.data
        this.tableData1 = []
        this.tableData2 = []
        this.tableData3 = []
        this.loading = false
      })
    },
    selectPart(val) {
      this.PartType = val.label
      if (this.PartType === '基本件') {
        searchPart(this.groupFloatValue).then(response => {
          this.tableData1 = response.data
        })
      } else if (this.PartType === '外购件') {
        searchPart1(this.groupFloatValue, 2).then(response => {
          this.tableData2 = response.data
        })
      } else if (this.PartType === '标准件') {
        searchPart1(this.groupFloatValue, 1).then(response => {
          this.tableData3 = response.data
        })
      }
    },
    searchPart(row) {
      this.tableData1 = []
      this.tableData2 = []
      this.tableData3 = []
      this.projectName = row.项目名称
      this.projectFloatValue = row.项目流水号
      this.MachineToolNumber = row.机床图号
      this.machineFloatValue = row.机床流水号
      this.groupName = row.组号
      this.groupFloatValue = row.组件流水号
      if (this.PartType === '基本件') {
        searchPart(row.组件流水号).then(response => {
          this.tableData1 = response.data
        })
      } else if (this.PartType === '外购件') {
        searchPart1(row.组件流水号, 2).then(response => {
          this.tableData2 = response.data
        })
      } else if (this.PartType === '标准件') {
        searchPart1(row.组件流水号, 1).then(response => {
          this.tableData3 = response.data
        })
      }
    },
    searchTable1() {
      if (this.PurchaseOrder !== '') {
        this.check4 = 1
      } else {
        this.check4 = 0
      }
      searchTable1(this.PurchaseOrder, this.check4).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          console.log(response.data[i].请购时间)
          if (response.data[i].请购时间 !== '') {
            response.data[i].请购时间 = (response.data[i].请购时间).split(' ')[0]
          }
        }
        this.tableData4 = response.data
      })
    },
    handleAdd() {
      this.addForm('form', [this.dialogFormVisible = true, this.title = '增加'])
    },
    submitAdd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          addData(this.form.请购车间, this.name, this.id, this.form.请购时间).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('增加成功')
              this.dialogFormVisible = false
              this.tableData5 = []
              this.searchTable1()
            } else { this.$message.error('增加失败') }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleEdit(row) { // 弹出单据编辑
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '编辑'
      this.dialogFormVisible = true
      this.RequisitionList = row.请购单流水号
      this.form.请购车间 = row.请购车间
      this.form.请购时间 = row.请购时间
    },
    submitEdit(formName) { // 提交单据编辑
      this.$refs[formName].validate((valid) => {
        if (valid) {
          editData(this.RequisitionList, this.form.请购车间, this.form.请购时间).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.dialogFormVisible = false
              this.tableData5 = []
              this.searchTable1()
            } else { this.$message.error('编辑失败') }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleDelete(row) { // 删除单据
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteData(row.请购单流水号).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.tableData5 = []
            this.searchTable1()
          } else { this.$message.error('删除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    cancel(formName) {
      this.form = {}
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    handleEdit1(row) { // 弹出单据编辑
      if (this.$refs['form3'] !== undefined) {
        this.$refs['form3'].resetFields()
      }
      this.dialogFormVisible3 = true
      this.DetailedNum = row.请购单明细流水号
      this.form3.数量 = row.零件数量
    },
    submitEdit1(formName) { // 提交单据编辑
      this.$refs[formName].validate((valid) => {
        if (valid) {
          editNum(this.DetailedNum, this.form3.数量).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.dialogFormVisible3 = false
              searchDetailed(this.RequisitionList).then(response => {
                for (let i = 0; i < response.data.length; i++) {
                  if (response.data[i].物料计划到货时间 !== '') {
                    response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                  }
                }
                this.tableData5 = response.data
              })
              searchDetailed1(this.RequisitionList).then(response => {
                for (let i = 0; i < response.data.length; i++) {
                  if (response.data[i].物料计划到货时间 !== '') {
                    response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                  }
                }
                this.tableData6 = response.data
              })
            } else { this.$message.error('编辑失败') }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleEdit2(row) { // 弹出单据编辑
      if (this.$refs['form4'] !== undefined) {
        this.$refs['form4'].resetFields()
      }
      this.dialogFormVisible4 = true
      this.StandardAndOutsourcing = row.标准件和外购件流水号
      this.MaterialNumber = row.物料流水号
      this.PartNum = row.零件数量
      this.stockNum = row.安全库存量
    },
    submitEdit2(formName) { // 提交使用库存数量
      this.$refs[formName].validate((valid) => {
        if (valid) {
          editStock(this.StandardAndOutsourcing, this.form4.数量, this.PartNum, this.MaterialNumber, this.stockNum).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.dialogFormVisible4 = false
              if (this.PartType === '基本件') {
                searchPart(this.groupFloatValue).then(response => {
                  this.tableData1 = response.data
                })
              } else if (this.PartType === '外购件') {
                searchPart1(this.groupFloatValue, 2).then(response => {
                  this.tableData2 = response.data
                })
              } else if (this.PartType === '标准件') {
                searchPart1(this.groupFloatValue, 1).then(response => {
                  this.tableData3 = response.data
                })
              }
            } else { this.$message.error('编辑失败') }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    searchDetailed(row) {
      this.RequisitionList = row.请购单流水号
      searchDetailed(row.请购单流水号).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (response.data[i].物料计划到货时间 !== '') {
            response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
          }
        }
        this.tableData5 = response.data
      })
      searchDetailed1(row.请购单流水号).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (response.data[i].物料计划到货时间 !== '') {
            response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
          }
        }
        this.tableData6 = response.data
      })
    },
    handleSelectionChange(val) {
      if (this.PartType === '基本件') {
        this.MaterialNum = []
        this.BasicPartsNumber = []
        this.MaterialName = []
        this.PartToolNumber = []
        this.Material = []
        this.NumberOfParts = []
        for (let i = 0; i < val.length; i++) {
          this.MaterialNum[i] = val[i].物料流水号
          this.BasicPartsNumber[i] = val[i].基本件流水号
          this.MaterialName[i] = val[i].零件名称
          this.PartToolNumber[i] = val[i].零件图号
          this.Material[i] = val[i].材料
          this.NumberOfParts[i] = val[i].零件数量
          this.ReMarks[i] = val[i].零件备注
        }
      } else if (this.PartType === '外购件') {
        this.MaterialNum = []
        this.MaterialCode = []
        this.StandardPartsAndOutsourcing = []
        this.MaterialName = []
        this.MaterialSpecification = []
        this.MaterialModel = []
        this.NumberOfParts = []
        for (let i = 0; i < val.length; i++) {
          this.StandardPartsAndOutsourcing[i] = val[i].标准件和外购件流水号
          this.MaterialNum[i] = val[i].物料流水号
          this.MaterialCode[i] = val[i].物料代码
          this.MaterialName[i] = val[i].物料名称
          this.MaterialSpecification[i] = val[i].物料规格
          this.MaterialModel[i] = val[i].物料型号
          this.NumberOfParts[i] = val[i].需求数量
          this.ReMarks[i] = val[i].备注
        }
      } else if (this.PartType === '标准件') {
        this.MaterialNum = []
        this.MaterialCode = []
        this.StandardPartsAndOutsourcing = []
        this.MaterialName = []
        this.MaterialSpecification = []
        this.MaterialModel = []
        this.NumberOfParts = []
        for (let i = 0; i < val.length; i++) {
          this.StandardPartsAndOutsourcing[i] = val[i].标准件和外购件流水号
          this.MaterialNum[i] = val[i].物料流水号
          this.MaterialCode[i] = val[i].物料代码
          this.MaterialName[i] = val[i].物料名称
          this.MaterialSpecification[i] = val[i].物料规格
          this.MaterialModel[i] = val[i].物料型号
          this.NumberOfParts[i] = val[i].需求数量
          this.ReMarks[i] = val[i].备注
        }
      }
    },
    purchaseRequisition() {
      if (this.RequisitionList !== '') {
        if (this.time !== '' && this.time !== null) {
          if (this.BasicPartsNumber.length !== 0 || this.StandardPartsAndOutsourcing.length !== 0) {
            this.result = 0
            if (this.PartType === '基本件') {
              for (let i = 0; i < this.BasicPartsNumber.length; i++) {
                purchaseRequisition(this.RequisitionList, this.projectName, this.projectFloatValue, this.MachineToolNumber, this.machineFloatValue, this.groupName, this.groupFloatValue, this.BasicPartsNumber[i], this.MaterialName[i], this.PartToolNumber[i], this.Material[i], this.NumberOfParts[i], 3, this.time, this.MaterialNum[i], this.ReMarks[i]).then(response => {
                  this.result += parseInt(response.data[0].result)
                  if (this.result === this.BasicPartsNumber.length) {
                    this.$message.success('请购成功')
                    searchPart(this.groupFloatValue).then(response => {
                      this.tableData1 = response.data
                    })
                    searchDetailed1(this.RequisitionList).then(response => {
                      for (let i = 0; i < response.data.length; i++) {
                        if (response.data[i].物料计划到货时间 !== '') {
                          response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                        }
                      }
                      this.tableData6 = response.data
                    })
                  }
                })
              }
            } else if (this.PartType === '外购件') {
              for (let i = 0; i < this.StandardPartsAndOutsourcing.length; i++) {
                purchaseRequisition1(this.RequisitionList, this.projectName, this.projectFloatValue, this.MachineToolNumber, this.machineFloatValue, this.groupName, this.groupFloatValue, this.StandardPartsAndOutsourcing[i], this.MaterialName[i], this.MaterialCode[i], this.MaterialSpecification[i], this.MaterialModel[i], this.NumberOfParts[i], 2, this.time, this.MaterialNum[i], this.ReMarks[i]).then(response => {
                  this.result += parseInt(response.data[0].result)
                  if (this.result === this.StandardPartsAndOutsourcing.length) {
                    this.$message.success('请购成功')
                    searchPart1(this.groupFloatValue, 2).then(response => {
                      this.tableData2 = response.data
                    })
                    searchDetailed(this.RequisitionList).then(response => {
                      for (let i = 0; i < response.data.length; i++) {
                        if (response.data[i].物料计划到货时间 !== '') {
                          response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                        }
                      }
                      this.tableData5 = response.data
                    })
                  }
                })
              }
            } else if (this.PartType === '标准件') {
              for (let i = 0; i < this.StandardPartsAndOutsourcing.length; i++) {
                purchaseRequisition1(this.RequisitionList, this.projectName, this.projectFloatValue, this.MachineToolNumber, this.machineFloatValue, this.groupName, this.groupFloatValue, this.StandardPartsAndOutsourcing[i], this.MaterialName[i], this.MaterialCode[i], this.MaterialSpecification[i], this.MaterialModel[i], this.NumberOfParts[i], 1, this.time, this.MaterialNum[i], this.ReMarks[i]).then(response => {
                  this.result += parseInt(response.data[0].result)
                  if (this.result === this.StandardPartsAndOutsourcing.length) {
                    this.$message.success('请购成功')
                    searchPart1(this.groupFloatValue, 1).then(response => {
                      this.tableData3 = response.data
                    })
                    searchDetailed(this.RequisitionList).then(response => {
                      for (let i = 0; i < response.data.length; i++) {
                        if (response.data[i].物料计划到货时间 !== '') {
                          response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                        }
                      }
                      this.tableData5 = response.data
                    })
                  }
                })
              }
            }
          } else {
            this.$message.warning('请选择零件或物料')
          }
        } else {
          this.$message.warning('请选择交货期')
        }
      } else {
        this.$message.warning('请先选择请购单')
      }
    },
    PurchasingDepartment() {
      if (this.time !== '' && this.time !== null) {
        if (this.BasicPartsNumber.length !== 0 || this.StandardPartsAndOutsourcing.length !== 0) {
          if (this.PartType === '基本件') {
            purchaseRequisition2(this.projectFloatValue, this.machineFloatValue, this.groupFloatValue, this.BasicPartsNumber, this.NumberOfParts, this.time).then(response => {
              if (response.data[0].result !== '0') {
                console.log(response.data[0].result)
                this.$message.success('请购成功')
                searchPart(this.groupFloatValue).then(response => {
                  this.tableData1 = response.data
                })
              } else {
                this.$message.error('请购失败')
              }
            })
          } else {
            PurchasingDepartment(this.groupFloatValue, this.StandardPartsAndOutsourcing, this.time, this.MaterialNum, this.NumberOfParts, this.projectFloatValue, this.machineFloatValue).then(response => {
              if (response.data[0].result !== '0') {
                this.$message.success('请购成功')
                if (this.PartType === '外购件') {
                  searchPart1(this.groupFloatValue, 2).then(response => {
                    this.tableData2 = response.data
                  })
                } else {
                  searchPart1(this.groupFloatValue, 1).then(response => {
                    this.tableData3 = response.data
                  })
                }
              } else {
                this.$message.error('请购失败')
              }
            })
          }
        } else {
          this.$message.warning('请选择零件或物料')
        }
      } else {
        this.$message.warning('请选择交货期')
      }
    },
    Production() {
      if (this.PartType === '基本件' && this.BasicPartsNumber.length !== 0) {
        Production(this.groupFloatValue, this.BasicPartsNumber, this.projectFloatValue, this.machineFloatValue).then(response => {
          if (response.data[0].result !== '0') {
            this.$message.success('投产成功')
            searchPart(this.groupFloatValue).then(response => {
              this.tableData1 = response.data
            })
          } else {
            this.$message.error('投产失败')
          }
        })
      } else {
        this.$message.warning('请选择基本件')
      }
    },
    MoveOut(row) {
      this.$confirm('此操作将该物料移出, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (row.零件类型 === '3') {
          MoveOut(row.请购单明细流水号, row.基本件流水号).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('移出成功')
              searchPart(this.groupFloatValue).then(response => {
                this.tableData1 = response.data
              })
              searchDetailed1(this.RequisitionList).then(response => {
                for (let i = 0; i < response.data.length; i++) {
                  if (response.data[i].物料计划到货时间 !== '') {
                    response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                  }
                }
                this.tableData6 = response.data
              })
            } else { this.$message.error('移出失败') }
          })
        } else if (row.零件类型 === '2') {
          MoveOut1(row.请购单明细流水号, row.标准件和外购件流水号).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('移出成功')
              searchPart1(this.groupFloatValue, 2).then(response => {
                this.tableData2 = response.data
              })
              searchDetailed(this.RequisitionList).then(response => {
                for (let i = 0; i < response.data.length; i++) {
                  if (response.data[i].物料计划到货时间 !== '') {
                    response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                  }
                }
                this.tableData5 = response.data
              })
            } else { this.$message.error('移出失败') }
          })
        } else if (row.零件类型 === '1') {
          MoveOut1(row.请购单明细流水号, row.标准件和外购件流水号).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('移出成功')
              searchPart1(this.groupFloatValue, 1).then(response => {
                this.tableData3 = response.data
              })
              searchDetailed(this.RequisitionList).then(response => {
                for (let i = 0; i < response.data.length; i++) {
                  if (response.data[i].物料计划到货时间 !== '') {
                    response.data[i].物料计划到货时间 = (response.data[i].物料计划到货时间).split(' ')[0]
                  }
                }
                this.tableData5 = response.data
              })
            } else { this.$message.error('移出失败') }
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消移出'
        })
      })
    },
    handleSizeChange(val) {},
    handleCurrentChange(val) {}
  }
}
</script>

<style scoped>
  span{
    margin: 10px 0px 10px 10px;
  }
  .item {
    float: right;
    margin-top: 10px;
    margin-right: 40px;
  }
</style>
<style>
  .el-table .NotThrough{
    background: palevioletred;
  }
  .el-table .adopt{
    background: limegreen;
  }
</style>
