<template>
  <div class="app-container">
    <el-card style="height: 850px;padding: 0">
      <el-tabs v-model="PartType" type="border-card">
        <el-tab-pane label="通用件" name="通用件">
          <div style="margin-top: 7px; margin-bottom: 7px">
            <el-cascader
              ref="cascader"
              :options="product"
              :show-all-levels="false"
              placeholder="产品名称"
              clearable
              size="small"
              @clear="clearData"
              @change="getData"/>
            <el-select
              v-model="partTypeValue"
              style="width:100px"
              placeholder="类型"
              size="small"
              filterable
              clearable
              @change="pageCurrent=1;searchTable()">
              <el-option
                v-for="item in partType"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <span style="font-size: 13px;color: black">导入时间</span>
            <el-date-picker
              v-model="dateRange"
              size="small"
              type="daterange"
              align="center"
              style="width: 240px;"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              range-separator="～"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              @change="pageCurrent=1;searchTable()"/>
            <el-button
              icon="el-icon-search"
              type="primary"
              plain
              size="small"
              style="margin-left: 10px"
              @click="pageCurrent = 1;pageSize = 20;searchTable()">查询
            </el-button>
            <el-button type="success" plain icon="el-icon-download" size="small" @click="exportExcel()">导出</el-button>
            <el-button type="distribution" icon="el-icon-plus" size="small" @click="addMaterial()">物料</el-button>
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="small"
              style="margin-left: 22.7%"
              @click="deletePart()">删除
            </el-button>
          </div>
          <div style="margin-top: 10px">
            <el-table
              v-loading="loading"
              :data="tableData"
              highlight-current-row
              show-summary
              border
              stripe
              size="small"
              style="width: 1341px"
              height="710px"
              @sort-change="sortChange"
              @selection-change="handleSelectionChange">
              <el-table-column type="selection" align="center" width="50px"/>
              <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center" prop="状态"/>
              <el-table-column
                :width="setColumnWidth('产品名称')"
                label="产品名称"
                align="center"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.产品名称 }}
                </template>
              </el-table-column>
              <el-table-column
                width="170px"
                label="零件名称"
                align="center"
                show-overflow-tooltip
                prop="零件名称"
                sortable="零件名称">
                <template slot-scope="scope">
                  {{ scope.row.零件名称 }}
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('图号或型号')"
                label="图号/型号"
                align="center"
                prop="图号或型号"
                sortable="图号或型号">
                <template slot-scope="scope">
                  {{ scope.row.图号或型号 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('数量')" label="数量" align="center" prop="数量">
                <template slot-scope="scope">
                  {{ scope.row.数量 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('材料')" label="材料" align="center">
                <template slot-scope="scope">
                  {{ scope.row.材料 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('材料')" label="单件重量" align="center">
                <template slot-scope="scope">
                  {{ scope.row.单件重量 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('备注')" label="零件备注" align="center">
                <template slot-scope="scope">
                  {{ scope.row.零件备注 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('类型')" label="类型" align="center">
                <template slot-scope="scope">
                  {{ scope.row.类型 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('日期')" label="导入时间" align="center">
                <template slot-scope="scope">
                  {{ scope.row.导入时间 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('姓名')" label="导入人" align="center">
                <template slot-scope="scope">
                  {{ scope.row.导入人 }}
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                  <el-tooltip :open-delay="700" effect="dark" content="查看图纸" placement="top">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-search"
                      style="margin-right: 10px"
                      @click="getNum(scope.row)">图纸
                    </el-button>
                  </el-tooltip>
                  <el-tooltip :open-delay="700" effect="dark" content="更替物料" placement="top">
                    <el-button type="text" size="mini" style="margin-right: 10px" @click="editPart(scope.row)">
                      更替物料
                    </el-button>
                  </el-tooltip>
                  <el-tooltip :open-delay="700" effect="dark" content="编辑零件信息" placement="top">
                    <el-button
                      type="text"
                      icon="el-icon-edit"
                      size="mini"
                      style="margin-right: 10px"
                      @click="editPartMX(scope.row)"/>
                  </el-tooltip>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="block" style="margin-top: 10px;">
            <el-pagination
              :current-page="pageCurrent"
              :page-sizes="[10, 20, 30, 40, 100]"
              :page-size="pageSize"
              :total="total"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChanges"
              @current-change="handleCurrentChanges"/>
          </div>
        </el-tab-pane>
        <el-tab-pane label="订单BOM" name="专机">
          <div style="margin-top: 7px; margin-bottom: 7px">
            <el-input
              v-model="partTool"
              clearable
              placeholder="产品名称筛选"
              size="small"
              style="width:200px"
              @clear="searchPartsGroup('')">
              <el-button slot="append" icon="el-icon-right" @click="searchPartsGroup('')"/>
            </el-input>
            <el-select
              v-model="orderValue"
              :remote-method="searchPartsGroup"
              style="width:200px"
              placeholder="订单编号"
              size="small"
              filterable
              clearable
              remote
              @change="getGroupName();pageCurrent2=1;searchTable1()">
              <el-option
                v-for="item in orderArray"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-select
              v-model="groupNameValue"
              style="width:200px"
              placeholder="产品名称"
              size="small"
              filterable
              clearable
              @change="pageCurrent2=1;searchTable1();getGroupNameNEW()">
              <el-option
                v-for="item in groupName"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-select
              v-model="partTypeValue1"
              style="width:100px"
              placeholder="类型"
              size="small"
              filterable
              clearable
              @change="pageCurrent2=1;searchTable1()">
              <el-option
                v-for="item in partType"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <span style="font-size: 13px;color: black">导入时间</span>
            <el-date-picker
              v-model="dateRange1"
              size="small"
              type="daterange"
              align="center"
              style="width: 240px;"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              range-separator="～"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              @change="pageCurrent2=1;searchTable1()"/>
            <el-button
              icon="el-icon-search"
              type="primary"
              plain
              size="small"
              style="margin-left: 10px"
              @click="pageCurrent2 = 1;searchTable1()">查询
            </el-button>
            <el-button type="success" plain icon="el-icon-download" size="small" @click="exportExcel1()">导出
            </el-button>
            <el-button type="distribution" icon="el-icon-plus" size="small" @click="addMaterial()">物料</el-button>
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="small"
              style="margin-left: 103px"
              @click="deletePart1()">删除
            </el-button>
          </div>
          <div style="margin-top: 10px">
            <el-table
              v-loading="loading"
              :data="tableData2"
              highlight-current-row
              show-summary
              border
              stripe
              size="small"
              style="width: 1481px"
              height="710px"
              @sort-change="sortChange1"
              @selection-change="handleSelectionChange1">
              <el-table-column :selectable="selectable1" type="selection" align="center" width="50px"/>
              <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center" prop="状态"/>
              <el-table-column
                :width="setColumnWidth('订单编号')"
                label="订单编号"
                align="center"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.订单编号 }}
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('产品名称')"
                label="产品名称"
                align="center"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.产品名称 }}
                </template>
              </el-table-column>
              <el-table-column
                width="170px"
                label="零件名称"
                align="center"
                show-overflow-tooltip
                prop="零件名称"
                sortable="零件名称">
                <template slot-scope="scope">
                  {{ scope.row.零件名称 }}
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('图号或型号')"
                label="图号/型号"
                align="center"
                prop="图号或型号"
                sortable="图号或型号">
                <template slot-scope="scope">
                  {{ scope.row.图号或型号 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('数量')" label="数量" align="center" prop="数量">
                <template slot-scope="scope">
                  {{ scope.row.数量 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('材料')" label="材料" align="center">
                <template slot-scope="scope">
                  {{ scope.row.材料 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('材料')" label="单件重量" align="center">
                <template slot-scope="scope">
                  {{ scope.row.单件重量 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('备注')" label="零件备注" align="center">
                <template slot-scope="scope">
                  {{ scope.row.零件备注 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('类型')" label="类型" align="center">
                <template slot-scope="scope">
                  {{ scope.row.类型 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('日期')" label="导入时间" align="center">
                <template slot-scope="scope">
                  {{ scope.row.导入时间 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('姓名')" label="导入人" align="center">
                <template slot-scope="scope">
                  {{ scope.row.导入人 }}
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                  <el-tooltip :open-delay="700" effect="dark" content="查看图纸" placement="top">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-search"
                      style="margin-right: 10px"
                      @click="getNum(scope.row)">图纸
                    </el-button>
                  </el-tooltip>
                  <el-tooltip :open-delay="700" effect="dark" content="更替物料" placement="top">
                    <el-button
                      :disabled="((Number(scope.row.零件类型)===1||Number(scope.row.零件类型)===2) && Number(scope.row.是否传递)=== 1 && jobNumber != '2009') || ((Number(scope.row.零件类型)===3||Number(scope.row.零件类型)===4) && Number(scope.row.考核状态) > 1 && jobNumber != '2009')"
                      type="text"
                      size="mini"
                      style="margin-right: 10px"
                      @click="editPart(scope.row)">更替物料
                    </el-button>
                  </el-tooltip>
                  <el-tooltip :open-delay="700" effect="dark" content="编辑零件信息" placement="top">
                    <el-button
                      :disabled="((Number(scope.row.零件类型)===1||Number(scope.row.零件类型)===2) && Number(scope.row.是否传递)=== 1 && jobNumber != '2009') || ((Number(scope.row.零件类型)===3||Number(scope.row.零件类型)===4) && Number(scope.row.考核状态) > 1 && jobNumber != '2009')"
                      type="text"
                      icon="el-icon-edit"
                      size="mini"
                      style="margin-right: 10px"
                      @click="editPartMX(scope.row)"/>
                  </el-tooltip>
                  <!--<el-tooltip :open-delay="700" effect="dark" content="删除零件" placement="top">
                    <el-button :disabled="((Number(scope.row.零件类型)===1||Number(scope.row.零件类型)===2) && Number(scope.row.是否传递)=== 1) || ((Number(scope.row.零件类型)===3||Number(scope.row.零件类型)===4) && Number(scope.row.考核状态) > 1)" type="text" icon="el-icon-delete" size="mini" @click="deletePart1(scope.row)"/>
                  </el-tooltip>-->
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="block" style="margin-top: 10px;">
            <el-pagination
              :current-page="pageCurrent2"
              :page-sizes="[10, 20, 30, 40, 100]"
              :page-size="pageSize2"
              :total="total2"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange2"
              @current-change="handleCurrentChange2"/>
          </div>
        </el-tab-pane>
      </el-tabs>
      <!-- <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" >
          <el-form-item label="零件名称" prop="零件名称">
            <el-input v-model="form.零件名称" size="small" clearable style="width:200px"/>
          </el-form-item>
          <el-form-item label="图号或型号" prop="图号或型号">
            <el-input v-model="form.图号或型号" size="small" clearable style="width:200px"/>
          </el-form-item>
          <el-form-item label="数量" prop="数量">
            <el-input v-model="form.数量" size="small" clearable style="width:200px"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="callOff('form')">取 消</el-button>
          <el-button v-if="PartType==='通用件'" type="primary" @click="submit('form')">确 定</el-button>
          <el-button v-if="PartType==='专机'" type="primary" @click="submit1('form')">确 定</el-button>
        </div>
      </el-dialog>-->

      <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">
          <el-form-item label="数量" prop="数量">
            <el-input-number v-model="form.数量" :min="1" :step="1" size="small" clearable style="width:200px"/>
          </el-form-item>
          <el-form-item label="材料" prop="材料">
            <el-select
              v-model="form.材料"
              :remote-method="getMaterial"
              style="width:200px"
              placeholder="材料"
              size="small"
              filterable
              clearable
              remote>
              <el-option
                v-for="item in MaterialScience"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="类型" prop="类型">
            <el-select v-model="form.类型" style="width:200px" placeholder="类型" size="small" filterable clearable>
              <el-option
                v-for="item in partType"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="单件重量" prop="单件重量">
            <el-input v-model="form.单件重量" type="number" size="small" clearable style="width:200px"/>
          </el-form-item>
          <el-form-item label="零件备注" prop="零件备注">
            <el-input v-model="form.零件备注" size="small" clearable style="width:200px"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="callOff('form')">取 消</el-button>
          <el-button v-if="PartType==='通用件'" type="primary" @click="submitMaterial('form')">确 定</el-button>
          <el-button v-if="PartType==='专机'" type="primary" @click="submitMaterial1('form')">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog
        v-el-drag-dialog
        :visible.sync="dialogFormVisible1"
        title="更替物料"
        center
        style="min-height: 300px;"
        width="680px">
        <el-row style="margin-bottom: 10px">
          <span>名称：</span>
          <el-input v-model="materialName" placeholder="名称" style="width: 170px" size="small" clearable/>
          <span>图号/型号：</span>
          <el-input v-model="materialSpec" placeholder="图号/型号" style="width: 170px" size="small" clearable/>
          <el-button
            type="success"
            size="small"
            icon="el-icon-search"
            style="margin-left:10px"
            @click="pageCurrent1=1;pageSize1=10;total1=0;searchMaterial()">查询
          </el-button>
        </el-row>
        <el-table
          :data="tableData1"
          :header-cell-style="{background: '#383E4B',color: 'white'}"
          size="mini"
          style="width: 97%;max-height: 300px;margin-top:15px"
          height="400px"
          border
          highlight-current-row
          @row-click="selectNewMaterial">
          <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>
        <div class="block" style="margin: 10px 0;">
          <el-pagination
            :current-page="pageCurrent1"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize1"
            :total="total1"
            :pager-count="5"
            style="display:inline-block;width:50%"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"/>
        </div>
        <div>
          <span style="font-size: large;color: red">将原物料替换为: {{ materialNew }}</span>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="dialogFormVisible1=false">取消</el-button>
          <el-button v-if="PartType==='通用件'" type="primary" size="small" @click="submitMaterialChange">确定
          </el-button>
          <el-button v-if="PartType==='专机'" type="primary" size="small" @click="submitMaterialChange1">确定
          </el-button>
        </div>
      </el-dialog>
      <el-dialog
        v-el-drag-dialog
        :visible.sync="dialogFormVisible2"
        title="新增物料"
        center
        style="min-height: 300px;"
        width="860px">
        <el-row style="margin-bottom: 10px">
          <span>名称：</span>
          <el-input v-model="materialName" placeholder="名称" style="width: 170px" size="small" clearable/>
          <span>图号/型号：</span>
          <el-input v-model="materialSpec" placeholder="图号/型号" style="width: 170px" size="small" clearable/>
          <el-button
            type="success"
            size="small"
            icon="el-icon-search"
            style="margin-left:10px"
            @click="pageCurrent1=1;pageSize1=10;total1=0;searchMaterial()">查询
          </el-button>
        </el-row>
        <el-table
          :data="tableData1"
          :header-cell-style="{background: '#383E4B',color: 'white'}"
          size="mini"
          style="width: 97%;margin-top:15px"
          height="400px"
          border
          highlight-current-row
          @row-click="selectNewMaterial1">
          <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>
        <div class="block" style="margin: 10px 0;">
          <el-pagination
            :current-page="pageCurrent1"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize1"
            :total="total1"
            :pager-count="5"
            style="display:inline-block;width:50%"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"/>
        </div>
        <div>
          <el-select
            v-show="PartType==='专机'"
            v-model="orderValue"
            :remote-method="searchPartsGroup"
            size="small"
            style="width: 150px"
            clearable
            remote
            placeholder="请选择订单"
            @change="getGroupName()">
            <el-option
              v-for="item in orderArray"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-select
            v-show="PartType==='专机'"
            v-model="groupNameValue"
            size="small"
            style="width: 150px"
            clearable
            placeholder="请选择产品名称"
            @change="getGroupNameNEW()">
            <el-option
              v-for="item in groupName"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <!--<el-select v-show="PartType==='通用件'" v-model="productValue" size="small" style="width: 150px" clearable placeholder="请选择产品名称">
            <el-option
              v-for="item in product"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>-->
          <el-cascader
            v-show="PartType==='通用件'"
            ref="cascader"
            :options="product"
            :show-all-levels="false"
            placeholder="请选择产品名称"
            clearable
            size="small"
            @change="getData1"/>
          <el-input-number v-model="NumberValue" clearable size="small" style="width:150px" placeholder="数量"/>
          <el-input v-model="remarks" clearable size="small" style="width:150px" placeholder="备注"/>
          <el-select
            v-show="PartType==='通用件'"
            v-model="partTypeValue"
            size="small"
            style="width: 150px"
            clearable
            placeholder="请选择类型">
            <el-option
              v-for="item in partType"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-select
            v-show="PartType==='专机'"
            v-model="partTypeValue1"
            size="small"
            style="width: 150px"
            clearable
            placeholder="请选择类型">
            <el-option
              v-for="item in partType"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </div>
        <div v-show="PartType==='专机' && groupNameValue !== ''" style="margin-left: 170px;">
          <span style="margin-right: 20px;">
            部件状态：
            <el-tag v-if="taskStatus==='未下达'" type="danger" size="small" style="margin: 0px">未下达</el-tag>
            <el-tag v-if="taskStatus==='未接受'" type="warning" size="small" style="margin: 0px">未接受</el-tag>
            <el-tag v-if="taskStatus==='未开始'" type="info" size="small" style="margin: 0px">未开始</el-tag>
            <el-tag v-if="taskStatus==='加工中'" size="small" style="margin: 0px">加工中</el-tag>
            <el-tag v-if="taskStatus==='装配中'" type="primary" size="small" style="margin: 0px">装配中</el-tag>
            <el-tag v-if="taskStatus==='完成'" type="success" size="small" style="margin: 0px">完成</el-tag>
          </span>
          <span>需求数：{{ numberOfParts }}</span>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="dialogFormVisible2=false">取消</el-button>
          <el-button v-if="PartType==='通用件'" type="primary" size="small" @click="submitAddMaterial">确定</el-button>
          <el-button v-if="PartType==='专机'" type="primary" size="small" @click="submitAddMaterial1">确定</el-button>
        </div>
      </el-dialog>
    </el-card>
    <el-dialog v-el-drag-dialog :visible.sync="dialogVisible" width="350px">
      <div v-for="(file, key) in hadFile" :key="key">
        <div class="wrapper">
          <div class="content">
            <div v-if="file.suffix==='pdf'" class="icon">
              <svg-icon icon-class="pdf"/>
            </div>
            <div v-else-if="file.suffix==='docx'||file.suffix === 'doc'" class="icon">
              <svg-icon icon-class="doc"/>
            </div>
            <div v-else-if="file.suffix==='xlsx' || file.suffix === 'xls'" class="icon">
              <svg-icon icon-class="excel"/>
            </div>
            <div v-else-if="file.suffix==='pptx' || file.suffix === 'ppt'" class="icon">
              <svg-icon icon-class="ppt"/>
            </div>
            <div v-else-if="file.suffix==='jpg' || file.suffix === 'jpeg'|| file.suffix === 'png'" class="icon">
              <svg-icon icon-class="pic"/>
            </div>
            <div v-else class="icon">
              <svg-icon icon-class="file"/>
            </div>
            <a id="appUrl" :href="file.url" target="view_window">
              <div class="info">{{ file.name }}</div>
            </a>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import request, { MESDownloadFile } from '@/utils/request'
import Cookie from 'js-cookie'

export default {
  data() {
    return {
      partTool: '',
      numberOfParts: '',
      taskStatus: '',
      dialogVisible: false,
      hadFile: [],
      multipleSelection: [],
      multipleSelection_variable: [],
      multipleSelection1: [],
      multipleSelection_variable1: [],
      PartType: '通用件',
      materialName: '',
      materialSpec: '',
      materialNumber: '',
      materialNew: '',
      addmaterial: '',
      materialNewValue: '',
      materialValue: '',
      productNumber: '',
      productName: '',
      NumberValue: '',
      remarks: '',
      productValue: '', // 产品名称
      productValue1: '',
      product: [], // 产品名称数组
      dateRange: '', // 导入时间
      partValue: '', // 零件流水号
      partTypeValue: '', // 零件类型
      partType: [
        {
          value: 1,
          label: '标准'
        }, {
          value: 2,
          label: '外购'
        }, {
          value: 3,
          label: '自制'
        }, {
          value: 4,
          label: '外协'
        }
      ], // 零件类型数组
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      MaterialScience: [],
      form: {
        数量: '',
        材料: '',
        单件重量: '',
        零件备注: '',
        类型: ''
      },
      rules: {
        数量: [{ required: true, message: '请输入数量', trigger: 'blur' }],
        类型: [{ required: true, message: '请选择类型', trigger: 'change' }]
      },
      orderArray: [],
      orderValue: '',
      orderNumber: '',
      groupName: [],
      groupNameValue: '',
      groupNumber: '',
      partTypeValue1: '',
      partsType: '',
      dateRange1: '',
      loading: false, // 数据加载
      tableData: [], // 通用件信息表
      tableData1: [], // 物料表
      tableData2: [], // 专机表
      total: 0, // 分页总数
      pageCurrent: 1, // 分页当前页
      pageSize: 20, // 分页每页显示条数
      total1: 0, // 分页总数
      pageCurrent1: 1, // 分页当前页
      pageSize1: 10, // 分页每页显示条数
      total2: 0, // 分页总数
      pageCurrent2: 1, // 分页当前页
      pageSize2: 20, // 分页每页显示条数
      orderName: '', // 排序列名
      order: '', // 排序方式
      jobNumber: 0
    }
  },
  computed: {
    ...mapGetters([
      'id',
      'token'
    ])
  },
  created() {
    this.fetchData()

    this.jobNumber = Cookie.get('jobNumber')
  },
  methods: {
    getGroupNameNEW() {
      var param = []
      param[0] = ['组件流水号', this.groupNameValue]
      var Data = this.CreateData('11', '订单BOM_部件数量_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.numberOfParts = response.data[0].数量
        this.taskStatus = response.data[0].任务状态
        console.log('订单BOM_部件数量_查询数据', response.data)
      })
    },
    searchPartsGroup(query) {
      let check
      this.partTool ? check = 1 : check = 0
      var param = []
      param[0] = ['产品名称_check', check]
      param[1] = ['产品名称', this.partTool]
      param[2] = ['订单编号', query]
      var Data = this.CreateData('11', 'BOM查询维护_产品名称_查询_订单编号_BAK', param)
      this.ExecDatabase(Data).then(response => {
        this.orderArray = []
        for (let i = 0; i < response.data.length; i++) {
          this.orderArray.push({
            label: response.data[i].订单编号,
            value: response.data[i].订单流水号
          })
        }
      })
    },
    fetchData() {
      this.getTreeData()
      this.searchPartsGroup('')
      // this.getOrder()
      this.getMaterial('')
    },
    getOrder() {
      var param = []
      var Data = this.CreateData('11', '订单信息_列表_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.orderArray.push({
            label: response.data[i].订单编号,
            value: response.data[i].订单流水号
          })
        }
      })
    },
    getMaterial(query) {
      var param = []
      this.MaterialScience = []
      param[0] = ['材料', query]
      var Data = this.CreateData('11', 'PDM_零件明细表_材料_查询数据_bak', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.MaterialScience.push({
            label: response.data[i].材料,
            value: response.data[i].材料流水号
          })
        }
      })
    },
    getGroupName() {
      this.groupNameValue = ''
      this.groupName = []
      if (this.orderValue) {
        var param = []
        param[0] = ['订单流水号', this.orderValue]
        var Data = this.CreateData('11', '订单信息_产品信息_查询数据', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.groupName.push({
              label: response.data[i].产品名称,
              value: response.data[i].组件流水号
            })
          }
        })
      }
    },
    getTreeData() {
      var param = []
      param[0] = ['子节点', 0]
      var Data = this.CreateData('11', '产品关系_查询节点', param)
      this.ExecDatabase(Data).then(response => {
        const data = response.data
        this.product = this.tree(data, 0)
      })
    },
    tree(data, pid) {
      const result = []
      let temp
      for (let i = 0; i < data.length; i++) {
        if (data[i].父节点 === pid) {
          const obj = { label: data[i].节点名称, value: data[i].子节点 }
          temp = this.tree(data, data[i].子节点)
          if (temp.length > 0) {
            obj.children = temp
          }
          result.push(obj)
        }
      }
      return result
    },
    getData(val) {
      this.pageCurrent = 1
      this.productValue = val[val.length - 1]
      if (this.productValue) {
        this.searchTable()
      } else {
        this.tableData = []
        this.total = 0
      }
    },
    getData1(val) {
      this.productValue1 = val[val.length - 1]
    },
    clearData() {
      this.productValue = ''
      this.tableData = []
    },
    selectable1(row) {
      return !(((Number(row.零件类型) === 1 || Number(row.零件类型) === 2) && Number(row.是否传递) === 1) || ((Number(row.零件类型) === 3 || Number(row.零件类型) === 4) && Number(row.考核状态) > 1))
    },
    // 查看零件图
    getNum(row) {
      this.dialogVisible = true
      this.getFileList(row.图号或型号)
    },
    async getFileList(value) {
      this.hadFile = []
      if (value) {
        await request({
          url: '',
          method: 'post',
          data: {
            type: '3',
            name: `select * from 机加工MES_零件图PDF表 where 是否启用 = 1 and name = '${value}'`
          }
        }).then(data => {
          this.suffix = data.data
          if (data.data.length > 0) {
            const server = `${MESDownloadFile}`.split('/')
            data.data.map(item => {
              this.hadFile.push({
                url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
                name: `${item.name}.${item.suffix}`,
                suffix: item.suffix,
                id: item.uid
              })
            })
          }
        })
      }
    },
    exportExcel() {
      if (this.tableData.length !== 0) {
        let productValue_check, dateRange_check, partTypeValue_check
        this.productValue ? productValue_check = 1 : productValue_check = 0
        this.dateRange ? dateRange_check = 1 : (dateRange_check = 0, this.dateRange = '')
        this.partTypeValue ? partTypeValue_check = 1 : partTypeValue_check = 0
        var param = []
        param[0] = ['产品流水号_check', productValue_check]
        param[1] = ['产品流水号', this.productValue]
        param[2] = ['时间_check', dateRange_check]
        param[3] = ['开始时间', this.dateRange[0]]
        param[4] = ['结束时间', this.dateRange[1]]
        param[5] = ['零件类型_check', partTypeValue_check]
        param[6] = ['零件类型', this.partTypeValue]
        param[7] = ['排序名称', this.orderName]
        param[8] = ['排序方式', this.order]
        var Data = this.CreateData('2001', '报表_产品信息_BOM查询', param)
        this.exportExcel_NPOI(Data)
      } else {
        this.$message.warning('暂无数据')
      }
    },
    searchTable() {
      if (this.productValue) {
        let productValue_check, dateRange_check, partTypeValue_check
        this.productValue ? productValue_check = 1 : productValue_check = 0
        this.dateRange ? dateRange_check = 1 : (dateRange_check = 0, this.dateRange = '')
        this.partTypeValue ? partTypeValue_check = 1 : partTypeValue_check = 0
        var param = []
        param[0] = ['产品流水号_check', productValue_check]
        param[1] = ['产品流水号', this.productValue]
        param[2] = ['时间_check', dateRange_check]
        param[3] = ['开始时间', this.dateRange[0]]
        param[4] = ['结束时间', this.dateRange[1]]
        param[5] = ['零件类型_check', partTypeValue_check]
        param[6] = ['零件类型', this.partTypeValue]
        param[7] = ['排序名称', this.orderName]
        param[8] = ['排序方式', this.order]
        var Data = this.CreateData('11', '产品信息_BOM查询', param, this.pageSize, this.pageCurrent)
        this.ExecDatabase(Data).then(response => {
          this.tableData = response.data.rows
          this.total = response.data.total
        })
      } else {
        this.$message.warning('请选择产品名称')
      }
    },
    sortChange(column) {
      if (column.prop === '零件名称') {
        this.orderName = 1
      } else if (column.prop === '图号或型号') {
        this.orderName = 2
      } else {
        this.orderName = 0
      }
      if (column.order === 'ascending') {
        this.order = 1
      } else if (column.order === 'descending') {
        this.order = 2
      } else {
        this.order = ''
      }
      this.searchTable()
    },
    addMaterial() {
      this.dialogFormVisible2 = true
    },
    exportExcel1() {
      if (this.tableData2.length !== 0) {
        let orderValue_check, groupNameValue_check, dateRange_check, partTypeValue_check
        this.orderValue ? orderValue_check = 1 : orderValue_check = 0
        this.groupNameValue ? groupNameValue_check = 1 : groupNameValue_check = 0
        this.dateRange1 ? dateRange_check = 1 : (dateRange_check = 0, this.dateRange1 = '')
        this.partTypeValue1 ? partTypeValue_check = 1 : partTypeValue_check = 0
        var param = []
        param[0] = ['组件流水号_check', groupNameValue_check]
        param[1] = ['组件流水号', this.groupNameValue]
        param[2] = ['时间_check', dateRange_check]
        param[3] = ['开始时间', this.dateRange[0]]
        param[4] = ['结束时间', this.dateRange[1]]
        param[5] = ['零件类型_check', partTypeValue_check]
        param[6] = ['零件类型', this.partTypeValue]
        param[7] = ['排序名称', this.orderName]
        param[8] = ['排序方式', this.order]
        param[9] = ['订单流水号_check', orderValue_check]
        param[10] = ['订单流水号', this.orderValue]
        var Data = this.CreateData('2001', '报表_技术管理_BOM查询', param)
        this.exportExcel_NPOI(Data)
      } else {
        this.$message.warning('暂无数据')
      }
    },
    searchTable1() {
      let orderValue_check, groupNameValue_check, dateRange_check, partTypeValue_check
      this.orderValue ? orderValue_check = 1 : orderValue_check = 0
      this.groupNameValue ? groupNameValue_check = 1 : groupNameValue_check = 0
      this.dateRange1 ? dateRange_check = 1 : (dateRange_check = 0, this.dateRange1 = '')
      this.partTypeValue1 ? partTypeValue_check = 1 : partTypeValue_check = 0
      var param = []
      param[0] = ['组件流水号_check', groupNameValue_check]
      param[1] = ['组件流水号', this.groupNameValue]
      param[2] = ['时间_check', dateRange_check]
      param[3] = ['开始时间', this.dateRange[0]]
      param[4] = ['结束时间', this.dateRange[1]]
      param[5] = ['零件类型_check', partTypeValue_check]
      param[6] = ['零件类型', this.partTypeValue1]
      param[7] = ['排序名称', this.orderName]
      param[8] = ['排序方式', this.order]
      param[9] = ['订单流水号_check', orderValue_check]
      param[10] = ['订单流水号', this.orderValue]
      var Data = this.CreateData('11', '技术管理_BOM查询', param, this.pageSize2, this.pageCurrent2)
      this.ExecDatabase(Data).then(response => {
        this.tableData2 = response.data.rows
        this.total2 = response.data.total
      })
    },
    sortChange1(column) {
      if (column.prop === '零件名称') {
        this.orderName = 1
      } else if (column.prop === '图号或型号') {
        this.orderName = 2
      } else {
        this.orderName = 0
      }
      if (column.order === 'ascending') {
        this.order = 1
      } else if (column.order === 'descending') {
        this.order = 2
      } else {
        this.order = ''
      }
      this.searchTable1()
    },
    editPart(row) {
      this.partValue = row.流水号
      this.productNumber = row.产品流水号
      this.groupNumber = row.组件流水号
      this.productName = row.产品名称
      this.orderNumber = row.订单流水号
      this.partsType = Number(row.零件类型)
      this.dialogFormVisible1 = true
      this.materialNumber = row.数量
      this.materialNew = ''
      this.materialNewValue = ''
      this.tableData1 = []
      this.materialName = ''
      this.materialSpec = ''
    },
    editPartMX(row) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.partValue = row.流水号
      this.productNumber = row.产品流水号
      this.groupNumber = row.组件流水号
      this.productName = row.产品名称
      this.orderNumber = row.订单流水号
      this.partsType = Number(row.零件类型)
      this.form.类型 = Number(row.零件类型)
      this.dialogFormVisible = true
      this.form.数量 = Number(row.数量)
      this.form.零件备注 = row.零件备注
      this.form.单件重量 = row.单件重量
      this.form.材料 = row.材料流水号 !== null && Number(row.材料流水号) !== 3 && Number(row.材料流水号) !== 0 ? Number(row.材料流水号) : null
    },
    /* editPart1(row) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.partValue = row.流水号
      this.groupNumber = row.组件流水号
      this.productName = row.产品名称
      if (Number(row.零件类型) === 3 || Number(row.零件类型) === 4) {
        this.dialogFormVisible = true
        this.form.零件名称 = row.零件名称
        this.form.图号或型号 = row.图号或型号
        this.form.数量 = row.数量
      } else {
        this.dialogFormVisible1 = true
        this.materialNumber = row.数量
      }
    },*/
    callOff(formName) {
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    submitMaterial(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['流水号', this.partValue]
          param[1] = ['零件数量', this.form.数量]
          param[2] = ['材料', this.form.材料]
          param[3] = ['零件类型', this.form.类型]
          param[4] = ['备注', this.form.零件备注]
          param[5] = ['修改人员', this.id]
          param[6] = ['原零件类型', this.partsType]
          param[7] = ['单件重量', this.form.单件重量]
          var Data = this.CreateData('12', 'PDM_产品明细表_编辑数据', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.searchTable()
              this.dialogFormVisible = false
              this.$message.success('编辑成功')
            } else {
              this.$message.error('编辑失败')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    submitMaterial1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['流水号', this.partValue]
          param[1] = ['零件数量', this.form.数量]
          param[2] = ['材料', this.form.材料]
          param[3] = ['零件类型', this.form.类型]
          param[4] = ['备注', this.form.零件备注]
          param[5] = ['修改人员', this.id]
          param[6] = ['原零件类型', this.partsType]
          param[7] = ['单件重量', this.form.单件重量]
          var Data = this.CreateData('12', 'PDM_零件明细表_编辑数据', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.searchTable1()
              this.dialogFormVisible = false
              this.$message.success('编辑成功')
            } else {
              this.$message.error('编辑失败')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    /* submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['产品流水号', this.productNumber]
          param[1] = ['零件图号', this.form.图号或型号]
          var Data = this.CreateData('11', 'PDM_产品明细表_基本件_编辑数据_验证图号', param)
          this.ExecDatabase(Data).then(response => {
            if (Number(response.data[0].Column1) === 0) {
              var param1 = []
              param1[0] = ['流水号', this.partValue]
              param1[1] = ['零件名称', this.form.零件名称]
              param1[2] = ['零件图号', this.form.图号或型号]
              param1[3] = ['零件数量', this.form.数量]
              param1[4] = ['产品名称', this.productName]
              param1[5] = ['修改人员', this.id]
              var Data1 = this.CreateData('12', 'PDM_产品明细表_基本件_编辑数据', param1)
              this.ExecDatabase(Data1).then(response => {
                if (response.data[0].result === '1') {
                  this.searchTable()
                  this.dialogFormVisible = false
                  this.$message.success('编辑成功')
                } else {
                  this.$message.error('编辑失败')
                }
              })
            } else {
              this.$message.error('更改后的图号已存在')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    submit1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['组件流水号', this.groupNumber]
          param[1] = ['零件图号', this.form.图号或型号]
          var Data = this.CreateData('11', 'PDM_零件明细表_基本件_编辑数据_验证图号', param)
          this.ExecDatabase(Data).then(response => {
            if (Number(response.data[0].Column1) === 0) {
              var param1 = []
              param1[0] = ['流水号', this.partValue]
              param1[1] = ['零件名称', this.form.零件名称]
              param1[2] = ['零件图号', this.form.图号或型号]
              param1[3] = ['零件数量', this.form.数量]
              param1[4] = ['产品名称', this.productName]
              param1[5] = ['修改人员', this.id]
              param1[6] = ['订单流水号', this.orderNumber]
              var Data1 = this.CreateData('12', 'PDM_零件明细表_基本件_编辑数据', param1)
              this.ExecDatabase(Data1).then(response => {
                if (response.data[0].result === '1') {
                  this.searchTable()
                  this.dialogFormVisible = false
                  this.$message.success('编辑成功')
                } else {
                  this.$message.error('编辑失败')
                }
              })
            } else {
              this.$message.error('更改后的图号已存在')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },*/
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    deletePart() {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.multipleSelection.length > 0) {
          const NumberData = []
          const NumberData1 = []
          const NumberData2 = []
          const NumberData3 = []
          const NumberData4 = []
          const NumberData5 = []
          this.multipleSelection_variable = this.multipleSelection
          this.multipleSelection = []
          for (let i = 0; i < this.multipleSelection_variable.length; i++) {
            NumberData[i] = parseInt(this.multipleSelection_variable[i].流水号)
            NumberData1[i] = this.multipleSelection_variable[i].零件名称
            NumberData2[i] = this.multipleSelection_variable[i].图号或型号
            NumberData3[i] = this.multipleSelection_variable[i].产品名称
            NumberData4[i] = parseInt(this.multipleSelection_variable[i].物料流水号)
            NumberData5[i] = parseInt(this.multipleSelection_variable[i].零件类型)
          }
          var param = []
          param[0] = ['流水号组', NumberData]
          param[1] = ['零件名称组', NumberData1]
          param[2] = ['零件图号组', NumberData2]
          param[3] = ['产品名称组', NumberData3]
          param[4] = ['物料流水号组', NumberData4]
          param[5] = ['零件类型组', NumberData5]
          var Data = this.CreateData('12', 'PDM_产品明细表_基本件_删除数据_全部', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('删除成功')
              this.searchTable()
            } else {
              this.$message.error('删除失败')
            }
          })
        } else {
          this.$message.warning('请选择要删除的零件')
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消确认'
        })
      })
    },
    handleSelectionChange1(val) {
      this.multipleSelection1 = val
    },
    deletePart1() {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.multipleSelection1.length > 0) {
          const NumberData = []
          const NumberData1 = []
          const NumberData2 = []
          const NumberData3 = []
          const NumberData4 = []
          const NumberData5 = []
          const NumberData6 = []
          const NumberData7 = []
          this.multipleSelection_variable1 = this.multipleSelection1
          this.multipleSelection1 = []
          for (let i = 0; i < this.multipleSelection_variable1.length; i++) {
            NumberData[i] = parseInt(this.multipleSelection_variable1[i].流水号)
            NumberData1[i] = this.multipleSelection_variable1[i].零件名称
            NumberData2[i] = this.multipleSelection_variable1[i].图号或型号
            NumberData3[i] = this.multipleSelection_variable1[i].产品名称
            NumberData4[i] = parseInt(this.multipleSelection_variable1[i].物料流水号)
            NumberData5[i] = parseInt(this.multipleSelection_variable1[i].零件类型)
            NumberData6[i] = parseInt(this.multipleSelection_variable1[i].订单流水号)
            NumberData7[i] = this.multipleSelection_variable1[i].数量
          }
          var param = []
          param[0] = ['流水号组', NumberData]
          param[1] = ['零件名称组', NumberData1]
          param[2] = ['零件图号组', NumberData2]
          param[3] = ['产品名称组', NumberData3]
          param[4] = ['物料流水号组', NumberData4]
          param[5] = ['零件类型组', NumberData5]
          param[6] = ['订单流水号组', NumberData6]
          param[7] = ['数量组', NumberData7]
          var Data = this.CreateData('12', 'PDM_零件明细表_基本件_删除数据_全部', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('删除成功')
              this.searchTable1()
            } else {
              this.$message.error('删除失败')
            }
          })
        } else {
          this.$message.warning('请选择要删除的零件')
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消确认'
        })
      })
    },
    searchMaterial() {
      let materialName_check, materialSpec_check
      this.materialName ? materialName_check = 1 : materialName_check = 0
      this.materialSpec ? materialSpec_check = 1 : materialSpec_check = 0
      var param = []
      param[0] = ['名称_check', materialName_check]
      param[1] = ['名称', this.materialName]
      param[2] = ['代号_check', materialSpec_check]
      param[3] = ['代号', this.materialSpec]
      var Data = this.CreateData('11', '物料信息_查询', param, this.pageSize1, this.pageCurrent1)
      this.ExecDatabase(Data).then(response => {
        this.tableData1 = response.data.rows
        this.total1 = response.data.total
      })
    },
    selectNewMaterial(row) {
      this.materialNew = ''
      this.materialNewValue = row.物料流水号
      this.materialNew += row.名称 + ' ' + row.代号
    },
    submitMaterialChange() {
      if (this.materialNew) {
        var param = []
        param[0] = ['产品流水号', this.productNumber]
        param[1] = ['物料流水号', this.materialNewValue]
        var Data = this.CreateData('11', 'PDM_产品明细表_外购件_编辑数据_验证图号', param)
        this.ExecDatabase(Data).then(response => {
          if (Number(response.data[0].Column1) === 0) {
            var param1 = []
            param1[0] = ['流水号', this.partValue]
            param1[1] = ['物料流水号', this.materialNewValue]
            param1[2] = ['产品名称', this.productName]
            param1[3] = ['修改人员', this.id]
            param1[4] = ['物料类别', this.partsType]
            var Data1 = this.CreateData('12', 'PDM_产品明细表_外购件_编辑数据', param1)
            this.ExecDatabase(Data1).then(response => {
              if (response.data[0].result === '1') {
                this.searchTable()
                this.dialogFormVisible1 = false
                this.$message.success('编辑成功')
              } else {
                this.$message.error('编辑失败')
              }
            })
          } else {
            this.$message.error('更改后的物料已存在')
          }
        })
      } else {
        this.$message.warning('请选择物料')
      }
    },
    submitMaterialChange1() {
      if (this.materialNew) {
        var param = []
        param[0] = ['组件流水号', this.groupNumber]
        param[1] = ['物料流水号', this.materialNewValue]
        var Data = this.CreateData('11', 'PDM_零件明细表_外购件_编辑数据_验证图号', param)
        this.ExecDatabase(Data).then(response => {
          if (Number(response.data[0].Column1) === 0) {
            var param1 = []
            param1[0] = ['流水号', this.partValue]
            param1[1] = ['物料流水号', this.materialNewValue]
            param1[2] = ['产品名称', this.productName]
            param1[3] = ['修改人员', this.id]
            param1[4] = ['订单流水号', this.orderNumber]
            param1[5] = ['物料类别', this.partsType]
            var Data1 = this.CreateData('12', 'PDM_零件明细表_外购件_编辑数据', param1)
            this.ExecDatabase(Data1).then(response => {
              if (response.data[0].result === '1') {
                this.searchTable1()
                this.dialogFormVisible1 = false
                this.$message.success('编辑成功')
              } else {
                this.$message.error('编辑失败')
              }
            })
          } else {
            this.$message.error('更改后的物料已存在')
          }
        })
      } else {
        this.$message.warning('请选择物料')
      }
    },
    selectNewMaterial1(row) {
      this.addmaterial = row.物料流水号
    },
    submitAddMaterial() {
      if (this.addmaterial) {
        if (this.productValue1) {
          if (this.NumberValue) {
            if (this.partTypeValue) {
              var param = []
              param[0] = ['产品流水号', this.productValue1]
              param[1] = ['物料流水号', this.addmaterial]
              var Data = this.CreateData('11', 'PDM_产品明细表_外购件_新增数据_验证图号', param)
              this.ExecDatabase(Data).then(response => {
                if (Number(response.data[0].Column1) === 0) {
                  var param1 = []
                  param1[0] = ['产品流水号', this.productValue1]
                  param1[1] = ['物料流水号', this.addmaterial]
                  param1[2] = ['数量', this.NumberValue]
                  param1[3] = ['人员编号', this.id]
                  param1[4] = ['物料类别', this.partTypeValue]
                  param1[5] = ['备注', this.remarks]
                  var Data1 = this.CreateData('12', '物料管理_通用件_新增物料', param1)
                  this.ExecDatabase(Data1).then(response => {
                    if (response.data[0].result === '1') {
                      this.searchTable()
                      this.dialogFormVisible2 = false
                      this.$message.success('新增成功')
                    } else {
                      this.$message.error('新增失败')
                    }
                  })
                } else {
                  this.$message.error('新增的物料已存在，不能重复增加')
                }
              })
            } else {
              this.$message.warning('请选择零件类型')
            }
          } else {
            this.$message.warning('请填写数量')
          }
        } else {
          this.$message.warning('请选择产品')
        }
      } else {
        this.$message.warning('请选择物料')
      }
    },
    submitAddMaterial1() {
      if (this.addmaterial) {
        if (this.orderValue) {
          if (this.groupNameValue) {
            if (this.NumberValue) {
              if (this.partTypeValue1) {
                var param = []
                param[0] = ['组件流水号', this.groupNameValue]
                param[1] = ['物料流水号', this.addmaterial]
                param[2] = ['订单流水号', this.orderValue]
                var Data = this.CreateData('11', 'PDM_零件明细表_外购件_新增数据_验证图号', param)
                this.ExecDatabase(Data).then(response => {
                  if (Number(response.data[0].Column1) === 0) {
                    var param1 = []
                    param1[0] = ['组件流水号', this.groupNameValue]
                    param1[1] = ['物料流水号', this.addmaterial]
                    param1[2] = ['数量', this.NumberValue]
                    param1[3] = ['人员编号', this.id]
                    param1[4] = ['物料类别', this.partTypeValue1]
                    param1[5] = ['备注', this.remarks]
                    param1[6] = ['订单流水号', this.orderValue]
                    var Data1 = this.CreateData('12', '物料管理_专机_新增物料', param1)
                    this.ExecDatabase(Data1).then(response => {
                      if (response.data[0].result === '1') {
                        this.searchTable1()
                        this.dialogFormVisible2 = false
                        this.$message.success('新增成功')
                      } else {
                        this.$message.error('新增失败')
                      }
                    })
                  } else {
                    this.$message.error('新增的物料已存在，不能重复增加')
                  }
                })
              } else {
                this.$message.warning('请选择零件类型')
              }
            } else {
              this.$message.warning('请填写数量')
            }
          } else {
            this.$message.warning('请选择产品')
          }
        } else {
          this.$message.warning('请选择订单')
        }
      } else {
        this.$message.warning('请选择物料')
      }
    },
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.searchTable()
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.searchMaterial()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchMaterial()
    },
    handleSizeChange2(val) {
      this.pageCurrent2 = 1
      this.pageSize2 = val
      this.searchTable1()
    },
    handleCurrentChange2(val) {
      this.pageCurrent2 = val
      this.searchTable1()
    }
  }
}
</script>
<style scoped lang="scss">
/deep/ .el-card__body {
  padding: 0px !important;
}
</style>
<style scoped>
.wrapper {
  width: 90%;
  height: 50px;
  overflow: hidden;
  border: 1px solid #b8c7d9;
  /*float: left;*/
  margin: 10px;
}

.content {
  position: relative;
  padding: 8px 8px 0 8px;
}

.action {
  position: absolute;
  top: 2px;
  right: 8px;
}

.delete {
  padding: 0 5px;
  border-radius: 3px;
  color: #0f84b0;
  font-size: 12px;
}

.delete:hover {
  background: -webkit-linear-gradient(top, #0ba9e3, #0099d3);
  color: #fff;
}

a {
  text-decoration: none;
}

.icon {
  width: 30px;
  height: 30px;
  display: inline-block;
  margin-right: 7px;
  margin-top: 2px;
  font-size: 26px;
}

.info {
  width: 160px;
  height: 50px;
  position: absolute;
  left: 44px;
  line-height: 30px;
  display: inline-block;
  color: #999;
}
</style>
