<template>
  <div class="app-container">
    <el-card style="padding-top: 10px">
      <el-row>
        <!--        <span>机床编号:</span>-->
        <el-select v-model="machineNumberValue" filterable placeholder="机床编号" size="small" style="margin:0px 10px" 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" filterable placeholder="组号" style="margin:0px 10px" size="small" clearable @change="searchTable">
          <el-option
            v-for="item in groupNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span style="margin-left: 50px">三表下达时间:&nbsp;&nbsp;{{ DeliveryTime }}</span>
        <!--        <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="searchTable()">查询</el-button>-->
        <!--        <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="searchPart()">查询1</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="项目名称" prop="项目名称" align="center">-->
    <!--          <template slot-scope="scope">-->
    <!--            {{ scope.row.项目名称 }}-->
    <!--          </template>-->
    <!--        </el-table-column>-->
    <!--        <el-table-column label="机床编号" prop="机床图号" align="center">-->
    <!--          <template slot-scope="scope">-->
    <!--            {{ scope.row.机床图号 }}-->
    <!--          </template>-->
    <!--        </el-table-column>-->
    <!--        <el-table-column label="机床名称" prop="机床名称" align="center">-->
    <!--          <template slot-scope="scope">-->
    <!--            {{ scope.row.机床名称 }}-->
    <!--          </template>-->
    <!--        </el-table-column>-->
    <!--        <el-table-column label="组号" prop="组号" align="center">-->
    <!--          <template slot-scope="scope">-->
    <!--            {{ scope.row.组号 }}-->
    <!--          </template>-->
    <!--        </el-table-column>-->
    <!--        <el-table-column label="组件名称" prop="组件名称" 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" :row-class-name="tableRowClassName1" stripe 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" width="120px">
              <template slot-scope="scope">
                {{ scope.row.零件名称 }}
              </template>
            </el-table-column>
            <el-table-column label="零件图号" align="center" width="120px">
              <template slot-scope="scope">
                {{ scope.row.零件图号 }}
              </template>
            </el-table-column>
            <el-table-column label="前零件图号" align="center" width="120px">
              <template slot-scope="scope">
                {{ scope.row.前零件图号 }}
              </template>
            </el-table-column>
            <el-table-column label="材料" align="center" width="120px">
              <template slot-scope="scope">
                {{ scope.row.材料 }}
              </template>
            </el-table-column>
            <el-table-column label="零件数量" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.零件数量 }}
              </template>
            </el-table-column>
            <el-table-column label="机床数量" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.机床数量 }}
              </template>
            </el-table-column>
            <el-table-column label="零件总数量" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.总数量 }}
              </template>
            </el-table-column>
            <el-table-column label="投产总数量" align="center" width="115px">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.投产总数量" :min="0" size="mini" style="width: 90px"/>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.零件备注 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="100px">
              <template slot-scope="scope">
                <el-button type="danger" size="mini" icon="el-icon-delete" plain @click="OutParts(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" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料代码 }}
              </template>
            </el-table-column>
            <el-table-column label="物料名称" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料名称 }}
              </template>
            </el-table-column>
            <el-table-column label="物料规格" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料规格 }}
              </template>
            </el-table-column>
            <el-table-column label="物料型号" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料型号 }}
              </template>
            </el-table-column>
            <el-table-column label="零件数量" align="center" width="90">
              <template slot-scope="scope">
                {{ scope.row.零件数量 }}
              </template>
            </el-table-column>
            <el-table-column label="机床数量" align="center" width="90">
              <template slot-scope="scope">
                {{ scope.row.机床数量 }}
              </template>
            </el-table-column>
            <el-table-column label="零件总数量" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.总数量 }}
              </template>
            </el-table-column>
            <el-table-column label="采购总数量" align="center" width="115px">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.采购总数量" :min="0" size="mini" style="width: 90px"/>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.备注 }}
              </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" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料代码 }}
              </template>
            </el-table-column>
            <el-table-column label="物料名称" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料名称 }}
              </template>
            </el-table-column>
            <el-table-column label="物料规格" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料规格 }}
              </template>
            </el-table-column>
            <el-table-column label="物料型号" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.物料型号 }}
              </template>
            </el-table-column>
            <el-table-column label="零件数量" align="center" width="90">
              <template slot-scope="scope">
                {{ scope.row.零件数量 }}
              </template>
            </el-table-column>
            <el-table-column label="机床数量" align="center" width="90">
              <template slot-scope="scope">
                {{ scope.row.机床数量 }}
              </template>
            </el-table-column>
            <el-table-column label="零件总数量" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.总数量 }}
              </template>
            </el-table-column>
            <el-table-column label="采购总数量" align="center" width="115px">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.采购总数量" :min="0" size="mini" style="width: 90px"/>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.备注 }}
              </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="选择日期"/>
      <span style="font-weight: bold">制造:</span>
      <el-tooltip :open-delay="1200" effect="dark" content="将零件选择到采购单" placement="top">
        <el-button type="primary" size="small" icon="el-icon-star-off" plain style="margin-top: 3px; margin-left: 5px" @click="purchaseRequisition()">制造部采购</el-button>
      </el-tooltip>
      <span style="margin-left: 40px;font-weight: bold">金工:</span>
      <el-tooltip :open-delay="1200" effect="dark" content="所选零件分配为自家生产" placement="top">
        <el-button type="danger" size="small" icon="el-icon-star-off" plain style="margin-top: 3px; margin-left: 5px" @click="Production()">车间生产</el-button>
      </el-tooltip>
      <span style="margin-left: 40px;font-weight: bold">采购:</span>
      <el-tooltip :open-delay="1200" effect="dark" content="所选零件分配到采购部" placement="top">
        <el-button type="success" size="small" icon="el-icon-star-off" plain style="margin-top: 3px; margin-left: 5px" @click="PurchasingDepartment()">采购部门采购</el-button>
      </el-tooltip>
    </el-card>
    <el-card>
      <el-row>
        <!--        <span>请购单号：</span>-->
        <el-input v-model="PurchaseOrder" size="small" style="width: 155px" placeholder="请购单号" clearable/>
        <el-button type="primary" size="mini" style="margin-left: 10px" plain @click="searchTable1()">查询</el-button>
        <el-button type="warning" size="mini" style="margin-left: 10px" plain @click="handleAdd()">新增</el-button>
        <el-button type="danger" size="mini" style="margin-left: 10px" plain @click="handleDelete()">删除</el-button>
      </el-row>
    </el-card>
    <el-row>
      <el-col style="width: 400px">
        <el-card>
          <el-table :data="tableData4" stripe border size="mini" style="width: 100%" height="300px" highlight-current-row @row-click="searchDetailed">
            <el-table-column label="请购单号" show-overflow-tooltip align="center" width="120px">
              <template slot-scope="scope">
                {{ scope.row.请购单编号 }}
              </template>
            </el-table-column>
            <!--            <el-table-column label="请购车间" align="center" width="100px">-->
            <!--              <template slot-scope="scope">-->
            <!--                {{ scope.row.请购车间 }}-->
            <!--              </template>-->
            <!--            </el-table-column>-->
            <el-table-column label="请购人" align="center" show-overflow-tooltip width="60px">
              <template slot-scope="scope">
                {{ scope.row.请购人 }}
              </template>
            </el-table-column>
            <el-table-column label="请购时间" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.请购时间 }}
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="107px">
              <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="warning" size="mini" icon="el-icon-edit" plain @click="handleEdit(scope.row)">编辑</el-button>-->
            <!--            <el-button type="danger" size="mini" icon="el-icon-delete" style="margin-left: 15px" plain @click="handleDelete(scope.row)">删除</el-button>-->
            <!--          </template>-->
            <!--        </el-table-column>-->
          </el-table>
        </el-card>
      </el-col>
      <el-col style="width: 900px;margin-left: 10px">
        <el-card>
          <el-table :data="tableData6" border size="mini" style="width: 100%" height="300px">
            <el-table-column label="序号" type="index" align="center" width="45px"/>
            <el-table-column label="零件名称" show-overflow-tooltip align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.物料名称 }}
              </template>
            </el-table-column>
            <el-table-column label="图号或型号" show-overflow-tooltip align="center" min-width="120px">
              <template slot-scope="scope">
                {{ scope.row.图号或型号 }}
              </template>
            </el-table-column>
            <el-table-column label="材料或规格" show-overflow-tooltip align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.规格或材料 }}
              </template>
            </el-table-column>
            <el-table-column label="数量" align="center" width="50px">
              <template slot-scope="scope">
                {{ scope.row.零件数量 }}
              </template>
            </el-table-column>
            <el-table-column label="零件类型" align="center" width="70px">
              <template slot-scope="scope">
                {{ scope.row.零件类型 }}
              </template>
            </el-table-column>
            <el-table-column label="交货期" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.物料计划到货时间 }}
              </template>
            </el-table-column>
            <!--            <el-table-column label="项目名称" align="center" width="150px">-->
            <!--              <template slot-scope="scope">-->
            <!--                {{ scope.row.项目名称 }}-->
            <!--              </template>-->
            <!--            </el-table-column>-->
            <el-table-column label="机床编号" align="center" width="90px">
              <template slot-scope="scope">
                {{ scope.row.机床图号 }}
              </template>
            </el-table-column>
            <el-table-column label="组号" align="center" width="50px">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="100px">
              <template slot-scope="scope">
                {{ scope.row.备注 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="80px">
              <template slot-scope="scope">
                <el-tooltip :open-delay="1200" effect="dark" content="编辑" placement="top">
                  <div style="display: inline-block;margin-right: 10px">
                    <el-button type="text" size="mini" icon="el-icon-edit" @click="handleEdit1(scope.row)"/>
                  </div>
                </el-tooltip>
                <el-tooltip :open-delay="1200" effect="dark" content="移出" placement="top">
                  <div style="display: inline-block">
                    <el-button type="text" size="mini" icon="el-icon-delete" @click="MoveOut(scope.row)"/>
                  </div>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" title="新增请购单" 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-item label="备注">
          <el-input
            v-model="form.Remarks"
            size="small"
            style="width:200px"/>
        </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 v-el-drag-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 type="primary" @click="submitEdit1('form3')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-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
      v-el-drag-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"
              plain
              @click="submit(scope.row)">确认</el-button>
            <el-button
              size="mini"
              type="danger"
              plain
              @click="Delete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog
      v-el-drag-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"
              plain
              @click="submit1(scope.row)">确认</el-button>
            <el-button
              size="mini"
              type="danger"
              plain
              @click="Delete1(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { DeliveryTimeSelect, initProject, searchgroup, searchTable, searchPart, searchPart1, searchTable1, addData, editData, deleteData, searchDetailed1, purchaseRequisition, purchaseRequisition1, purchaseRequisition2, MoveOut, MoveOut1, PurchasingDepartment, Production, PartCallbackInformation, PartCallbackInformation1, submit, submit1, Delete, Delete1, editStock, editNum, OutPart } from '@/api/ManufacturingCenter/PartAssignment'
import { mapGetters } from 'vuex'
import Cookie from 'js-cookie'
export default {
  inject: ['reload'],
  data() {
    return {
      DeliveryTime: '', // 三表下达时间
      projectFloatValue: '',
      machineNumberValue: '',
      machineFloatValue: '',
      machineNumber: [],
      machineName: '',
      groupNumberValue: '',
      groupFloatValue: '',
      groupNumber: [],
      StandardAndOutsourcing: '',
      PartNum: '',
      DetailedNum: '',
      stockNum: '',
      MaterialNumber: '',
      PurchaseOrder: '',
      PartType: '基本件',
      tableData: [],
      tableData1: [],
      tableData2: [],
      tableData3: [],
      tableData4: [],
      tableData6: [],
      loading: false,
      title: '',
      dialogFormVisible: false,
      RequisitionList: '',
      form: {
        请购单编号: '',
        请购车间: '制造部',
        请购时间: '',
        Remarks: ''
      },
      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: [],
      multipleSelection: [],
      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'
    ])
  },
  watch: {
    // 如果路由有变化，会再次执行该方法
    '$route': {
      handler(route) {
        const _this = this
        if (route.name === 'PartAssignment') {
          _this.fetchData()
          _this.DeliveryTime = ''
        }
      }
    }
  },
  created() {
    this.DeliveryTime = ''
    this.fetchData()
  },
  methods: {
    fetchData() {
      if (Cookie.get('machineValue') !== undefined) {
        this.machineNumber = []
        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].机床流水号
            })
          }
        }).then(() => {
          this.machineNumberValue = parseInt(Cookie.get('machineValue'))
          this.machineChange()
          this.groupNumberValue = parseInt(Cookie.get('group'))
          this.searchTable()
          Cookie.remove('machineValue')
          Cookie.remove('group')
        })
      } else {
        this.machineNumberValue = ''
        this.groupNumberValue = ''
        this.tableData = []
        this.machineNumber = []
        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'
      }
    },
    tableRowClassName1({ row }) {
      if (row.是否加急件 === 1) {
        return 'isUrgentItem'
      }
    },
    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].组号 + '    ' + response.data[i].组件名称,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    // 三表下达时间查询
    DeliveryTimeSelect() {
      this.DeliveryTime = ''
      DeliveryTimeSelect(this.groupNumberValue).then(response => {
        console.log(response.data)
        this.DeliveryTime = response.data[0].操作日期.substring(0, 10)
      })
    },
    searchTable() {
      this.loading = true
      if (this.machineNumberValue !== '') {
        this.check2 = 1
      } else { this.check2 = 0 }
      if (this.groupNumberValue !== '') {
        this.DeliveryTimeSelect() // 三表下达时间查询
        this.check3 = 1
      } else { this.check3 = 0 }
      searchTable(this.machineNumberValue, this.check2, this.groupNumberValue, this.check3).then(response => {
        // this.tableData = response.data
        this.projectName = response.data[0].项目名称
        this.projectFloatValue = response.data[0].项目流水号
        this.MachineToolNumber = response.data[0].机床图号
        this.machineFloatValue = response.data[0].机床流水号
        this.groupName = response.data[0].组号
        this.groupFloatValue = response.data[0].组件流水号
        this.tableData1 = []
        this.tableData2 = []
        this.tableData3 = []
        this.loading = false
        this.searchPart()
      })
    },
    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() {
      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(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
        })
      }
    },
    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.请购时间, this.form.Remarks).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('增加成功')
              this.dialogFormVisible = false
              this.tableData6 = []
              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.tableData6 = []
              this.searchTable1()
            } else { this.$message.error('编辑失败') }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleDelete() { // 删除单据
      console.log(this.RequisitionList)
      if (this.RequisitionList === '') {
        this.$message.error('请先选择请购单')
      } else {
        this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteData(this.RequisitionList).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('删除成功')
              this.tableData6 = []
              this.searchTable1()
            } else {
              this.$message.error('删除失败')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    },
    OutParts(row) { // 移出数据
      this.$confirm('移出后，该零件将不再参与考核', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        OutPart(row.基本件流水号).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('移出成功')
            searchPart(this.groupFloatValue).then(response => {
              this.tableData1 = response.data
            })
          } 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
              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]
                  }
                }
                const res = response.data
                this.tableData6 = res.map(item => {
                  if (item.零件类型 === '2') {
                    item.零件类型 = '外购件'
                  } else if (item.零件类型 === '1') {
                    item.零件类型 = '标准件'
                  } else if (item.零件类型 === '3') {
                    item.零件类型 = '基本件'
                  }
                  return item
                })
              })
            } 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.请购单流水号
      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]
          }
        }
        const res = response.data
        this.tableData6 = res.map(item => {
          if (item.零件类型 === '2') {
            item.零件类型 = '外购件'
          } else if (item.零件类型 === '1') {
            item.零件类型 = '标准件'
          } else if (item.零件类型 === '3') {
            item.零件类型 = '基本件'
          }
          return item
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    purchaseRequisition() {
      if (this.RequisitionList !== '') {
        if (this.time !== '' && this.time !== null) {
          if (this.multipleSelection.length !== 0) {
            this.result = 0
            if (this.PartType === '基本件') {
              this.MaterialNum = []
              this.BasicPartsNumber = []
              this.MaterialName = []
              this.PartToolNumber = []
              this.Material = []
              this.NumberOfParts = []
              for (let i = 0; i < this.multipleSelection.length; i++) {
                this.MaterialNum[i] = this.multipleSelection[i].物料流水号
                this.BasicPartsNumber[i] = this.multipleSelection[i].基本件流水号
                this.MaterialName[i] = this.multipleSelection[i].零件名称
                this.PartToolNumber[i] = this.multipleSelection[i].零件图号
                this.Material[i] = this.multipleSelection[i].材料
                this.NumberOfParts[i] = this.multipleSelection[i].投产总数量
                this.ReMarks[i] = this.multipleSelection[i].零件备注
              }
              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]
                        }
                      }
                      const res = response.data
                      this.tableData6 = res.map(item => {
                        if (item.零件类型 === '2') {
                          item.零件类型 = '外购件'
                        } else if (item.零件类型 === '1') {
                          item.零件类型 = '标准件'
                        } else if (item.零件类型 === '3') {
                          item.零件类型 = '基本件'
                        }
                        return item
                      })
                    })
                  }
                })
              }
            } else if (this.PartType === '外购件') {
              this.MaterialNum = []
              this.MaterialCode = []
              this.StandardPartsAndOutsourcing = []
              this.MaterialName = []
              this.MaterialSpecification = []
              this.MaterialModel = []
              this.NumberOfParts = []
              for (let i = 0; i < this.multipleSelection.length; i++) {
                this.StandardPartsAndOutsourcing[i] = this.multipleSelection[i].标准件和外购件流水号
                this.MaterialNum[i] = this.multipleSelection[i].物料流水号
                this.MaterialCode[i] = this.multipleSelection[i].物料代码
                this.MaterialName[i] = this.multipleSelection[i].物料名称
                this.MaterialSpecification[i] = this.multipleSelection[i].物料规格
                this.MaterialModel[i] = this.multipleSelection[i].物料型号
                this.NumberOfParts[i] = this.multipleSelection[i].采购总数量
                this.ReMarks[i] = this.multipleSelection[i].备注
              }
              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
                    })
                    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]
                        }
                      }
                      const res = response.data
                      this.tableData6 = res.map(item => {
                        if (item.零件类型 === '2') {
                          item.零件类型 = '外购件'
                        } else if (item.零件类型 === '1') {
                          item.零件类型 = '标准件'
                        } else if (item.零件类型 === '3') {
                          item.零件类型 = '基本件'
                        }
                        return item
                      })
                    })
                  }
                })
              }
            } else if (this.PartType === '标准件') {
              this.MaterialNum = []
              this.MaterialCode = []
              this.StandardPartsAndOutsourcing = []
              this.MaterialName = []
              this.MaterialSpecification = []
              this.MaterialModel = []
              this.NumberOfParts = []
              for (let i = 0; i < this.multipleSelection.length; i++) {
                this.StandardPartsAndOutsourcing[i] = this.multipleSelection[i].标准件和外购件流水号
                this.MaterialNum[i] = this.multipleSelection[i].物料流水号
                this.MaterialCode[i] = this.multipleSelection[i].物料代码
                this.MaterialName[i] = this.multipleSelection[i].物料名称
                this.MaterialSpecification[i] = this.multipleSelection[i].物料规格
                this.MaterialModel[i] = this.multipleSelection[i].物料型号
                this.NumberOfParts[i] = this.multipleSelection[i].采购总数量
                this.ReMarks[i] = this.multipleSelection[i].备注
              }
              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
                    })
                    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]
                        }
                      }
                      const res = response.data
                      this.tableData6 = res.map(item => {
                        if (item.零件类型 === '2') {
                          item.零件类型 = '外购件'
                        } else if (item.零件类型 === '1') {
                          item.零件类型 = '标准件'
                        } else if (item.零件类型 === '3') {
                          item.零件类型 = '基本件'
                        }
                        return item
                      })
                    })
                  }
                })
              }
            }
          } else {
            this.$message.warning('请选择零件或物料')
          }
        } else {
          this.$message.warning('请选择交货期')
        }
      } else {
        this.$message.warning('请先选择请购单')
      }
    },
    PurchasingDepartment() {
      if (this.time !== '' && this.time !== null) {
        if (this.multipleSelection.length !== 0) {
          if (this.PartType === '基本件') {
            this.MaterialNum = []
            this.BasicPartsNumber = []
            this.MaterialName = []
            this.PartToolNumber = []
            this.Material = []
            this.NumberOfParts = []
            for (let i = 0; i < this.multipleSelection.length; i++) {
              this.MaterialNum[i] = this.multipleSelection[i].物料流水号
              this.BasicPartsNumber[i] = this.multipleSelection[i].基本件流水号
              this.MaterialName[i] = this.multipleSelection[i].零件名称
              this.PartToolNumber[i] = this.multipleSelection[i].零件图号
              this.Material[i] = this.multipleSelection[i].材料
              this.NumberOfParts[i] = this.multipleSelection[i].投产总数量
              this.ReMarks[i] = this.multipleSelection[i].零件备注
            }
            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 {
            this.MaterialNum = []
            this.MaterialCode = []
            this.StandardPartsAndOutsourcing = []
            this.MaterialName = []
            this.MaterialSpecification = []
            this.MaterialModel = []
            this.NumberOfParts = []
            for (let i = 0; i < this.multipleSelection.length; i++) {
              this.StandardPartsAndOutsourcing[i] = this.multipleSelection[i].标准件和外购件流水号
              this.MaterialNum[i] = this.multipleSelection[i].物料流水号
              this.MaterialCode[i] = this.multipleSelection[i].物料代码
              this.MaterialName[i] = this.multipleSelection[i].物料名称
              this.MaterialSpecification[i] = this.multipleSelection[i].物料规格
              this.MaterialModel[i] = this.multipleSelection[i].物料型号
              this.NumberOfParts[i] = this.multipleSelection[i].采购总数量
              this.ReMarks[i] = this.multipleSelection[i].备注
            }
            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.multipleSelection.length !== 0) {
        this.MaterialNum = []
        this.BasicPartsNumber = []
        this.MaterialName = []
        this.PartToolNumber = []
        this.Material = []
        this.NumberOfParts = []
        for (let i = 0; i < this.multipleSelection.length; i++) {
          this.MaterialNum[i] = this.multipleSelection[i].物料流水号
          this.BasicPartsNumber[i] = this.multipleSelection[i].基本件流水号
          this.MaterialName[i] = this.multipleSelection[i].零件名称
          this.PartToolNumber[i] = this.multipleSelection[i].零件图号
          this.Material[i] = this.multipleSelection[i].材料
          this.NumberOfParts[i] = this.multipleSelection[i].投产总数量
          this.ReMarks[i] = this.multipleSelection[i].零件备注
        }
        Production(this.groupFloatValue, this.BasicPartsNumber, this.NumberOfParts, 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.零件类型 === '基本件') {
          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]
                  }
                }
                const res = response.data
                this.tableData6 = res.map(item => {
                  if (item.零件类型 === '2') {
                    item.零件类型 = '外购件'
                  } else if (item.零件类型 === '1') {
                    item.零件类型 = '标准件'
                  } else if (item.零件类型 === '3') {
                    item.零件类型 = '基本件'
                  }
                  return item
                })
              })
            } else { this.$message.error('移出失败') }
          })
        } else if (row.零件类型 === '外购件') {
          MoveOut1(row.请购单明细流水号, row.标准件和外购件流水号).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('移出成功')
              searchPart1(this.groupFloatValue, 2).then(response => {
                this.tableData2 = 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
                const res = response.data
                this.tableData6 = res.map(item => {
                  if (item.零件类型 === '2') {
                    item.零件类型 = '外购件'
                  } else if (item.零件类型 === '1') {
                    item.零件类型 = '标准件'
                  } else if (item.零件类型 === '3') {
                    item.零件类型 = '基本件'
                  }
                  return item
                })
              })
            } else { this.$message.error('移出失败') }
          })
        } else if (row.零件类型 === '标准件') {
          MoveOut1(row.请购单明细流水号, row.标准件和外购件流水号).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('移出成功')
              searchPart1(this.groupFloatValue, 1).then(response => {
                this.tableData3 = 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
                const res = response.data
                this.tableData6 = res.map(item => {
                  if (item.零件类型 === '2') {
                    item.零件类型 = '外购件'
                  } else if (item.零件类型 === '1') {
                    item.零件类型 = '标准件'
                  } else if (item.零件类型 === '3') {
                    item.零件类型 = '基本件'
                  }
                  return item
                })
              })
            } 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;
  }
  .el-table .isUrgentItem{
    background: #ff7575;
  }
</style>
