<template>
  <div class="app-container">
    <el-card>
      <span>项目名称</span>
      <el-select v-model="projectValue" placeholder="请选择项目名称" filterable size="small">
        <el-option
          v-for="item in project"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <span>机床图号</span>
      <el-select v-model="machineValue" placeholder="请选择机床图号" filterable size="small">
        <el-option
          v-for="item in machine"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>

      <span>组号</span>
      <el-select v-model="groupValue" placeholder="请选择组号" filterable size="small">
        <el-option
          v-for="item in group"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>

      <span>零件图号:</span>
      <el-input v-model="partNumber" clearable filterable size="small" placeholder="零件图号" style="width: 200px;"/>

      <el-button icon="el-icon-search" type="success" size="small" @click="pageCurrentWB = 1;pageSizeWB = 10;pageCurrent = 1;pageSize = 10;getTableData();pageCurrent1 = 1;pageSize1 = 10;getTable();pageCurrent2 = 1;pageSize2 = 10;getTable1()">查询</el-button>
    </el-card>
    <el-card>
      <div>
        <span style="font-size: 20px;margin-bottom: 20px">基本件三表数量</span>
        <el-button style="float: right;margin-bottom: 20px" type="danger" size="small" @click="alldelete()">全部删除</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        size="mini"
        style="width: 100%;max-height: 520px"
        height="320">
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50"/>
        <el-table-column
          label="机床图号"
          align="center"
          min-width="150px">
          <template slot-scope="scope">{{ scope.row.机床图号 }}</template>
        </el-table-column>
        <el-table-column
          label="零件图号"
          align="center"
          min-width="200px">
          <template slot-scope="scope">{{ scope.row.零件图号 }}</template>
        </el-table-column>
        <el-table-column
          label="零件名称"
          align="center"
          min-width="100px">
          <template slot-scope="scope">{{ scope.row.零件名称 }}</template>
        </el-table-column>
        <el-table-column
          label="组号"
          align="center"
          min-width="100px">
          <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 align="center" label="分类码" width="150">
          <template slot-scope="scope">
            {{ scope.row.分类码 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="旧零件图号" width="150">
          <template slot-scope="scope">
            {{ scope.row.前零件图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="整改类型" width="150">
          <template slot-scope="scope">
            {{ scope.row.整改类型 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="type=1;handleEdit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChanges"
          @current-change="handleCurrentChanges"/>
      </div>
    </el-card>
    <el-card>
      <div>
        <span style="font-size: 20px;margin-bottom: 20px">外购件和标准件三表数量</span>
        <el-button style="float: right;margin-bottom: 20px" type="danger" size="small" @click="alldeleteWB()">全部删除</el-button>
      </div>
      <el-table
        v-loading="loadingWB"
        :data="tableDataWB"
        style="width: 100%"
        size="mini"
        height="320"
        highlight-current-row
        border>
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50"/>
        <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 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 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="100">
          <template slot-scope="scope">
            {{ scope.row.备注 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="标记" width="100">
          <template slot-scope="scope">
            {{ scope.row.标记 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="type=1;handleEdit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px">
        <el-pagination
          :current-page="pageCurrentWB"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSizeWB"
          :total="totalWB"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChangeWB"
          @current-change="handleCurrentChangeWB"/>
      </div>
    </el-card>
    <el-card>
      <div>
        <div style="font-size: 20px;margin-bottom: 20px">未投产数量</div>
        <el-table
          :data="tableData1"
          border
          style="width: 100%"
          height="320">
          <el-table-column label="零件号" align="center" min-width="220">
            <template slot-scope="scope">
              {{ scope.row.零件图号 }}
            </template>
          </el-table-column>
          <el-table-column label="零件名称" align="center">
            <template slot-scope="scope">
              {{ scope.row.零件名称 }}
            </template>
          </el-table-column>
          <el-table-column label="投产" align="center">
            <template slot-scope="scope">
              {{ scope.row.投产总数量 }}
            </template>
          </el-table-column>
          <el-table-column label="批次" align="center">
            <template slot-scope="scope">
              {{ scope.row.最大投产批次 }}
            </template>
          </el-table-column>
          <el-table-column label="已投" align="center">
            <template slot-scope="scope">
              {{ scope.row.已投产数量 }}
            </template>
          </el-table-column>
          <el-table-column label="未投" align="center">
            <template slot-scope="scope">
              {{ scope.row.未投产数量 }}
            </template>
          </el-table-column>
          <el-table-column label="零件类型" align="center" width="100">
            <template slot-scope="scope">
              {{ scope.row.零件类型名称 }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200px" fixed="right" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                @click="type=1;handleEdit(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            :current-page="pageCurrent1"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize1"
            :total="total1"
            style="width:50%;display:inline-block;"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"/>
        </div>
      </div>
    </el-card>
    <el-card>
      <div style="font-size: 20px;margin-bottom: 20px">未平衡数量</div>
      <el-table
        :data="tableData2"
        border
        style="max-height: 400px;margin-top:10px"
        height="320">
        <el-table-column label="零件图号" align="center" width="300">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center" width="200">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="零件数量" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.投产数量 }}
          </template>
        </el-table-column>
        <el-table-column label="机加工开始时间" align="center">
          <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="操作" width="200px" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="handleEdit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent2"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize2"
          :total="total2"
          style="float:left"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange2"
          @current-change="handleCurrentChange2"/>
      </div>
    </el-card>
    <el-card>
      <div style="font-size: 20px;margin-bottom: 20px">未分配采购零件数量</div>
      <el-tabs type="border-card" @tab-click="searchTable1();searchTable2()">
        <el-tab-pane label="标准件和外购件">
          <el-table :data="tableData3" size="mini" style="max-height: 320px" height="320px" border>
            <el-table-column align="center" label="机床图号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.机床图号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="组号" min-width="80px">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="物料类别" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料类别 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="物料品种" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料品种 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="图号或型号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料型号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="名称" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料名称 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="规格" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料规格 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="数量" min-width="80px">
              <template slot-scope="scope">
                {{ scope.row.零件数量 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="备注" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.备注 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="200px" fixed="right" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="primary"
                  @click="type=2;handleEdit(scope.row)">编辑</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination
              :current-page="pageCurrent3"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="pageSize3"
              :total="total3"
              style="display:inline-block;width:50%"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange3"
              @current-change="handleCurrentChange3"/>
          </div>
        </el-tab-pane>
        <el-tab-pane label="基本件">
          <el-table :data="tableData4" size="mini" style="max-height: 320px" height="320px" border>
            <el-table-column align="center" label="机床图号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.机床图号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="组号" min-width="80px">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="图号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.零件图号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="名称" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.零件名称 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="规格" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.规格 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="材料" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.材料 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="数量" min-width="80px">
              <template slot-scope="scope">
                {{ scope.row.数量 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="备注" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.备注 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="200px" fixed="right" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="primary"
                  @click="type=2;handleEdit(scope.row)">编辑</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination
              :current-page="pageCurrent4"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="pageSize4"
              :total="total4"
              style="display:inline-block;width:50%"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange4"
              @current-change="handleCurrentChange4"/>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <el-card>
      <div>
        <span style="font-size: 20px">临时表</span>
        <el-button style="float: right" type="danger" size="small" @click="alldelete5()">全部删除</el-button>
      </div>
      <el-tabs v-model="activeName" style="margin-top: 20px" type="border-card" @tab-click="searchTable5();searchTable6()">
        <el-tab-pane label="标准件和外购件" name="1">
          <el-table :data="tableData5" size="mini" style="max-height: 320px" height="320px" border>
            <el-table-column align="center" label="项目" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.项目 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="机床" min-width="80px">
              <template slot-scope="scope">
                {{ scope.row.机床 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="组号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="物料名称" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料名称 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="物料规格" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料规格 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="物料型号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.物料型号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="装机数量" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.装机数量 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="200px" fixed="right" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click="handleDelete5(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination
              :current-page="pageCurrent5"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="pageSize5"
              :total="total5"
              style="display:inline-block;width:50%"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange5"
              @current-change="handleCurrentChange5"/>
          </div>
        </el-tab-pane>
        <el-tab-pane label="基本件" name="2">
          <el-table :data="tableData6" size="mini" style="max-height: 320px" height="320px" border>
            <el-table-column align="center" label="项目" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.项目 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="机床" min-width="80px">
              <template slot-scope="scope">
                {{ scope.row.机床 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="组号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="图号或者型号" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.图号或者型号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="材料或者规格" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.材料或者规格 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="装机数量" min-width="100px">
              <template slot-scope="scope">
                {{ scope.row.装机数量 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="200px" fixed="right" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click="handleDelete6(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination
              :current-page="pageCurrent6"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="pageSize6"
              :total="total6"
              style="display:inline-block;width:50%"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange6"
              @current-change="handleCurrentChange6"/>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <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 type="primary" @click="submitEdit('form3')">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { alldeleteWB, alldelete, projectSelect, machineSelect, groupSelect, basicPartsData, deleteBasicParts, deleteBasicParts5, deleteBasicParts6, alldeleteBasicParts5, alldeleteBasicParts6, purchasePartsData, deletePurchaseData, editPurchaseData, editBasicParts, getTable, editProductNum, getTable1, editProduceNum, searchTable1, searchTable2, searchTable5, searchTable6, searchTable7, editGroupBasicPartNum, editGroupPartNum } from '@/api/BasicData/PartsNumberMaintenance'
export default {
  name: 'Index',
  data() {
    return {
      activeName: '1',
      projectValue: '',
      projectName: '',
      BasicParts: '',
      PurchaseData: '',
      productNum: '',
      produceNum: '',
      partNumber: '',
      groupPartNum: '',
      groupBasicPartNum: '',
      type: '',
      project: [],
      machineValue: '',
      machineName: '',
      machine: [],
      groupValue: '',
      group: [],
      form3: {
        数量: ''
      },
      rules3: {
        数量: [{ required: true, message: '请输入数量', trigger: 'blur' }]
      },
      dialogFormVisible3: false,
      loading: false,
      loadingWB: false,
      total: 0,
      tableData: [],
      tableData1: [],
      tableData2: [],
      tableData3: [],
      tableData4: [],
      tableData5: [],
      tableData6: [],
      tableData7: [],
      tableDataWB: [],
      pageCurrent: 1,
      pageSize: 10,
      pageCurrent1: 1,
      pageSize1: 10,
      total1: 0,
      pageCurrent2: 1,
      pageSize2: 10,
      total2: 0,
      pageCurrent3: 1,
      pageSize3: 10,
      total3: 0,
      pageCurrent4: 1,
      pageSize4: 10,
      total4: 0,
      pageCurrent5: 1,
      pageSize5: 10,
      total5: 0,
      pageCurrent6: 1,
      pageSize6: 10,
      total6: 0,
      pageCurrent7: 1,
      pageSize7: 10,
      total7: 0,
      pageCurrentWB: 1,
      pageSizeWB: 10,
      totalWB: 0
    }
  },
  computed: {
    groupName() {
      for (let i = 0; i < this.group.length; i++) {
        if (this.group[i].value === this.groupValue) {
          return this.group[i].label
        }
      }
    }
  },
  watch: {
    project(val) {
      if (val.length > 0) {
        this.projectValue = val[0].value
      }
    },
    projectValue(val) {
      for (let i = 0; i < this.project.length; i++) {
        if (this.project[i].value === this.projectValue) {
          this.projectName = this.project[i].label
        }
      }
      this.machineValue = ''
      this.machine = []
      this.groupValue = ''
      this.group = []
      if (val) {
        this.getMachineSelect(val)
      }
    },
    machine(val) {
      if (val.length > 0) {
        this.machineValue = val[0].value
        for (let i = 0; i < this.machine.length; i++) {
          if (this.machine[i].value === val[0].value) {
            this.machineName = this.machine[i].label
          }
        }
      }
    },
    machineValue(val) {
      this.groupValue = ''
      this.group = []
      if (val) {
        this.getGroupSelect(val)
      }
    },
    group(val) {
      if (val.length > 0) {
        this.groupValue = val[0].value
      }
    },
    groupValue(val) {
      if (val) {
        this.pageCurrentWB = 1
        this.pageSizeWB = 10
        this.pageCurrent = 1
        this.pageSize = 10
        // console.log(this.projectName, this.machineName, this.groupName)
        this.getTableData()
        this.getTable()
        this.getTable1()
        this.searchTable1()
        this.searchTable2()
        this.searchTable5()
        this.searchTable6()
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.getSelect(projectSelect, ['项目名称', '项目流水号'], 'project')
    },
    getMachineSelect(val) {
      this.getSelect(machineSelect, ['机床图号', '机床流水号'], 'machine', val)
    },
    getGroupSelect(val) {
      this.getSelect(groupSelect, ['组号', '组件流水号'], 'group', val)
    },
    alldelete5() {
      this.$confirm('此操作将永久删除所有数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.activeName === '1') {
          alldeleteBasicParts5(this.projectName, this.machineName, this.groupName).then(res => {
            console.log(res, 1)
            if (res.data[0].result === '1') {
              this.$message.success('删除成功')
              this.searchTable5()
              this.searchTable6()
            } else { this.$message.error('删除失败') }
          })
        } else if (this.activeName === '2') {
          alldeleteBasicParts6(this.projectName, this.machineName, this.groupName).then(res => {
            console.log(res, 2)
            if (res.data[0].result === '1') {
              this.$message.success('删除成功')
              this.searchTable5()
              this.searchTable6()
            } else { this.$message.error('删除失败') }
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    alldelete() {
      this.$confirm('此操作将永久删除所有数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        alldelete(this.groupValue).then(res => {
          if (res.data[0].result === '1') {
            this.$message.success('删除成功')
            this.getTableData()
          } else { this.$message.error('删除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    alldeleteWB() {
      this.$confirm('此操作将永久删除所有数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        alldeleteWB(this.groupValue).then(res => {
          if (res.data[0].result === '1') {
            this.$message.success('删除成功')
            this.getTableData()
          } else { this.$message.error('删除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    getTableData() {
      const project_check = this.projectValue ? 1 : 0
      const machine_check = this.machineValue ? 1 : 0
      const group_check = this.groupValue ? 1 : 0
      this.loading = true
      basicPartsData(project_check, this.projectValue, machine_check, this.machineValue, group_check, this.groupValue, this.pageSize, this.pageCurrent).then(response => {
        this.loading = false
        const res = response.data
        this.total = res.total
        // console.log(this.tableData)
        this.tableData = res.rows.map(item => {
          if (item.整改类型 === '1') {
            item.整改类型 = '新增'
          } else if (item.整改类型 === '2') {
            item.整改类型 = '替换'
          } else if (item.整改类型 === '3') {
            item.整改类型 = '补充加工'
          }
          return item
        })
      })
      this.loadingWB = true
      purchasePartsData(this.groupValue, this.pageCurrentWB, this.pageSizeWB).then(response => {
        this.loadingWB = false
        const data = response.data
        this.totalWB = data.total
        this.tableDataWB = data.rows.map(item => {
          console.log(item)
          item.零件类型 = item.零件类型 === '2' ? '外购件' : '标准件'
          return item
        })
      })
    },
    getTable() {
      this.tableData1 = []
      getTable(this.groupValue, this.pageCurrent1, this.pageSize1).then(response => {
        this.total1 = parseInt(response.data.total)
        this.tableData1 = []
        for (let i = 0; i < response.data.rows.length; i++) {
          this.tableData1.push({
            零件图号: response.data.rows[i].零件图号,
            零件名称: response.data.rows[i].零件名称,
            投产总数量: response.data.rows[i].投产总数量,
            最大投产批次: response.data.rows[i].最大投产批次,
            已投产数量: response.data.rows[i].已投产数量,
            未投产数量: response.data.rows[i].未投产数量,
            零件类型名称: response.data.rows[i].零件类型名称,
            组件零件基本件流水号: response.data.rows[i].组件零件基本件流水号,
            投产类型流水号: response.data.rows[i].投产类型流水号,
            数据类型: response.data.rows[i].数据类型,
            材料流水号: response.data.rows[i].材料流水号
          })
        }
      })
    },
    getTable1() {
      this.tableData2 = []
      this.checked_entryName = false
      if (this.machineValue === '') {
        this.checked_toolNum = false
      } else {
        this.checked_toolNum = true
      }
      if (this.groupValue === '') {
        this.checked_Num = false
      } else {
        this.checked_Num = true
      }
      if (this.partNumber !== '' && this.partNumber !== null) {
        this.checked_partNumber = true
      } else {
        this.checked_partNumber = false
      }
      getTable1(this.checked_entryName, '', this.checked_toolNum, this.machineValue, this.checked_Num, this.groupValue, this.checked_partNumber, this.partNumber, this.pageCurrent2, this.pageSize2).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          response.data.rows[i].机加工开始时间_长日期 = response.data.rows[i].机加工开始时间_长日期.substring(0, response.data.rows[i].机加工开始时间_长日期.indexOf(' '))
          response.data.rows[i].机加工结束时间_长日期 = response.data.rows[i].机加工结束时间_长日期.substring(0, response.data.rows[i].机加工结束时间_长日期.indexOf(' '))
        }
        this.total2 = parseInt(response.data.total)
        for (let i = 0; i < response.data.rows.length; i++) {
          this.tableData2.push({
            零件图号: response.data.rows[i].零件图号,
            零件名称: response.data.rows[i].零件名称,
            投产数量: response.data.rows[i].投产数量,
            机加工开始时间: response.data.rows[i].机加工开始时间_长日期,
            机加工结束时间: response.data.rows[i].机加工结束时间_长日期,
            工序数量: response.data.rows[i].工序数量,
            工艺计划流水号: response.data.rows[i].工艺计划流水号
          })
        }
      })
    },
    searchTable1() { // 查询标准件和外购件
      let check0, check1, check2
      this.projectValue ? check2 = 1 : check2 = 0
      this.machineValue ? check0 = 1 : check0 = 0
      this.groupValue ? check1 = 1 : check1 = 0
      searchTable1(this.pageCurrent3, this.pageSize3, check2, this.projectValue, check0, this.machineValue, check1, this.groupValue).then(response => {
        this.tableData3 = response.data.rows
        this.total3 = response.data.total
      })
    },
    searchTable2() { // 查询基本件
      let check0, check1, check2
      this.projectValue ? check2 = 1 : check2 = 0
      this.machineValue ? check0 = 1 : check0 = 0
      this.groupValue ? check1 = 1 : check1 = 0
      searchTable2(this.pageCurrent4, this.pageSize4, check2, this.projectValue, check0, this.machineValue, check1, this.groupValue).then(response => {
        this.tableData4 = response.data.rows
        this.total4 = response.data.total
      })
    },
    searchTable5() { // 查询标准件
      let check0, check1, check2
      this.projectName ? check2 = 1 : check2 = 0
      this.machineName ? check0 = 1 : check0 = 0
      this.groupName ? check1 = 1 : check1 = 0
      searchTable5(this.pageCurrent6, this.pageSize6, check2, this.projectName, check0, this.machineName, check1, this.groupName).then(response => {
        console.log(response, 5, this.activeName)
        this.tableData5 = response.data.rows
        this.total5 = response.data.total
      })
    },
    searchTable6() { // 查询基本件
      let check0, check1, check2
      this.projectName ? check2 = 1 : check2 = 0
      this.machineName ? check0 = 1 : check0 = 0
      this.groupName ? check1 = 1 : check1 = 0
      // console.log(this.projectName, this.machineName, this.groupName, 44)
      searchTable6(this.pageCurrent6, this.pageSize6, check2, this.projectName, check0, this.machineName, check1, this.groupName).then(response => {
        console.log(response, 6)
        this.tableData6 = response.data.rows
        this.total6 = response.data.total
      })
    },
    searchTable7() { // 查询外购件
      let check0, check1, check2
      this.projectName ? check2 = 1 : check2 = 0
      this.machineName ? check0 = 1 : check0 = 0
      this.groupName ? check1 = 1 : check1 = 0
      searchTable7(this.pageCurrent7, this.pageSize7, check2, this.projectName, check0, this.machineName, check1, this.groupName).then(response => {
        console.log(response, 7)
        this.tableData7 = response.data.rows
        this.total7 = response.data.total
      })
    },
    handleEdit(row) {
      this.BasicParts = ''
      this.PurchaseData = ''
      this.productNum = ''
      this.produceNum = ''
      if (this.$refs['form3'] !== undefined) {
        this.$refs['form3'].resetFields()
      }
      this.dialogFormVisible3 = true
      if (row.基本件流水号 && this.type === 1) {
        this.BasicParts = row.基本件流水号
        this.form3.数量 = row.零件数量
      } else if (row.标准件和外购件流水号 && this.type === 1) {
        this.PurchaseData = row.标准件和外购件流水号
        this.form3.数量 = row.零件数量
      } else if (row.组件零件基本件流水号 && this.type === 1) {
        this.productNum = row.组件零件基本件流水号
        this.form3.数量 = row.投产总数量
      } else if (row.工艺计划流水号) {
        this.produceNum = row.工艺计划流水号
        this.form3.数量 = row.投产数量
      } else if (row.组件零件流水号 && this.type === 2) {
        this.groupPartNum = row.组件零件流水号
        this.form3.数量 = row.零件数量
      } else if (row.组件零件基本件流水号 && this.type === 2) {
        this.groupBasicPartNum = row.组件零件基本件流水号
        this.form3.数量 = row.数量
      }
    },
    submitEdit(formName) { // 提交单据编辑
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.BasicParts !== '') {
            editBasicParts(this.BasicParts, this.form3.数量).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.dialogFormVisible3 = false
                this.getTableData()
              } else { this.$message.error('编辑失败') }
            })
          } else if (this.PurchaseData !== '') {
            editPurchaseData(this.PurchaseData, this.form3.数量).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.dialogFormVisible3 = false
                this.getTableData()
              } else { this.$message.error('编辑失败') }
            })
          } else if (this.productNum !== '') {
            editProductNum(this.productNum, this.form3.数量).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.dialogFormVisible3 = false
                this.getTable()
              } else { this.$message.error('编辑失败') }
            })
          } else if (this.produceNum !== '') {
            editProduceNum(this.produceNum, this.form3.数量).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.dialogFormVisible3 = false
                this.getTable1()
              } else { this.$message.error('编辑失败') }
            })
          } else if (this.groupPartNum !== '') {
            editGroupPartNum(this.groupPartNum, this.form3.数量).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.dialogFormVisible3 = false
                this.searchTable1()
              } else { this.$message.error('编辑失败') }
            })
          } else if (this.groupBasicPartNum !== '') {
            editGroupBasicPartNum(this.groupBasicPartNum, this.form3.数量).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.dialogFormVisible3 = false
                this.searchTable2()
              } else { this.$message.error('编辑失败') }
            })
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleDelete(row) {
      if (row.基本件流水号) {
        this.deleteRow(deleteBasicParts, row.基本件流水号, function() {
          this.getTableData()
        })
      } else {
        this.deleteRow(deletePurchaseData, row.标准件和外购件流水号, function() {
          this.getTableData()
        })
      }
    },
    handleDelete5(row) {
      if (row.id) {
        this.deleteRow(deleteBasicParts5, row.id, function() {
          this.searchTable5()
          this.searchTable6()
        })
      }
    },
    handleDelete6(row) {
      if (row.id) {
        this.deleteRow(deleteBasicParts6, row.id, function() {
          this.searchTable5()
          this.searchTable6()
        })
      }
    },
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.getTableData()
    },
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.getTableData()
    },
    handleSizeChangeWB(val) {
      this.pageCurrentWB = 1
      this.pageSizeWB = val
      this.getTableData()
    },
    handleCurrentChangeWB(val) {
      this.pageCurrentWB = val
      this.getTableData()
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.getTable()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.getTable()
    },
    handleSizeChange2(val) {
      this.pageSize2 = val
      this.pageCurrent2 = 1
      this.getTable1()
    },
    handleCurrentChange2(val) {
      this.pageCurrent2 = val
      this.getTable1()
    },
    handleSizeChange3(val) {
      this.pageSize3 = val
      this.pageCurrent3 = 1
      this.searchTable1()
    },
    handleCurrentChange3(val) {
      this.pageCurrent3 = val
      this.searchTable1()
    },
    handleSizeChange4(val) {
      this.pageSize4 = val
      this.pageCurrent4 = 1
      this.searchTable2()
    },
    handleCurrentChange4(val) {
      this.pageCurrent4 = val
      this.searchTable2()
    },
    handleSizeChange5(val) {
      this.pageSize5 = val
      this.pageCurrent5 = 1
      this.searchTable5()
    },
    handleCurrentChange5(val) {
      this.pageCurrent5 = val
      this.searchTable5()
    },
    handleSizeChange6(val) {
      this.pageSize6 = val
      this.pageCurrent6 = 1
      this.searchTable6()
    },
    handleCurrentChange6(val) {
      this.pageCurrent6 = val
      this.searchTable6()
    },
    handleSizeChange7(val) {
      this.pageSize7 = val
      this.pageCurrent7 = 1
      this.searchTable7()
    },
    handleCurrentChange7(val) {
      this.pageCurrent7 = val
      this.searchTable7()
    }
  }
}
</script>

<style scoped>
  span{
    margin: 20px;
  }
</style>
