<template>
  <div class="app-container">
    <el-card>
      <el-radio-group v-model="radio" size="small" style="margin: 10px;" @change="checked = false;partNum=[];partNumValue = '';typeValue = '';partName = '';material = '';materialName = '';prepareMateriel = '';spec = '';batchNum = '';searchPartsByMachineGroup();">
        <el-radio v-model="radio" :label="1">未编制</el-radio>
        <el-radio v-model="radio" :label="2">已编制</el-radio>
      </el-radio-group>
      <span>工艺员:</span>
      <el-select v-model="CraftmenValue" placeholder="工艺员" size="small" style="width:100px" @change="clearDetail();">
        <el-option
          v-for="item in Craftmen"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <!--<span>零件号:</span>
      <el-input v-model="partNumber" clearable placeholder="零件号" size="small" style="width:200px">
        <el-button slot="append" icon="el-icon-right" @click="searchParts();partNumValue=''"/>
      </el-input>-->
      <span>机床-分组 或 零件号:</span>
      <el-input v-model="machine_Group_part" clearable placeholder="例：机床号-组号 或 零件号" size="small" style="width:260px">
        <el-button slot="append" icon="el-icon-right" @click="searchPartsByMachineGroup();partNumValue=''"/>
      </el-input>
      <el-select v-model="partNumValue" placeholder="选择零件编制工艺定额" size="small" @clear="clearDetail" @change="searchDetail()">
        <el-option
          v-for="item in partNum"
          :key="item.value"
          :label="item.label"
          :value="item.value">
          <b style="float: left">{{ item.label }}</b>
          <b style="float: right; color: #8492a6; font-size: 13px">-{{ item.group }}</b>
          <b style="float: right; color: #8492a6; font-size: 13px">&nbsp;&nbsp;{{ item.machine }}</b>
        </el-option>
      </el-select>
      <el-checkbox v-model="checked" :disabled="isShow2 || (parseInt(token) !== 6 && parseInt(token) !== 19)" size="small" style="margin:10px">是否核准</el-checkbox>
      <!--<el-button v-show="isShow2" type="danger" icon="el-icon-edit" size="small" @click="returnEdit">在制零件工艺调整</el-button>-->
      <!--<el-button v-show="false" plain size="small" style="margin: 10px;float:right" @click="switchEdit()">切换编辑模式</el-button>-->
      <div v-show="isShow">
        <span>种类:</span>
        <el-input v-model="typeValue" placeholder="种类" size="small" readonly style="width:100px"/>
        <span>零件名称:</span>
        <el-input v-model="partName" placeholder="零件名称" size="small" readonly style="width:115px"/>
        <span>投产总数量:</span>
        <el-input v-model="batchNum" readonly size="small" style="width:80px;margin-top:10px;"/>
        <span>物料:</span>
        <el-input v-model="materialName" placeholder="物料" size="small" style="width:215px" readonly>
          <el-button slot="prepend" icon="el-icon-search" @click="dialogMaterial=true"/>
          <el-button slot="append" icon="el-icon-cjn-09" @click="saveMaterial"/>
        </el-input>
        <!--<span>规格:</span>-->
        <!--<el-input v-model="spec" :readonly="isShow2" style="width:100px" size="small" placeholder="规格"/>-->
      </div>
      <div>
        <el-row>
          <el-col style="width:210px">
            <span>物料类型:</span>
            <el-select v-model="materielValue" size="small" style="margin-top: 20px;width:120px" placeholder="物料类型" @change="clear()">
              <el-option
                v-for="item in materiel"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-col>

          <el-col v-show="materielValue==='1'||materielValue==='6'||materielValue==='7'||materielValue==='8'" :span="15">
            <span>直径:</span>
            <el-input-number v-model="diameter" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>长度:</span>
            <el-input-number v-model="height2" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <el-button style="margin-top: 20px;margin-left: 10px;" type="primary" size="small" @click="Calculation1()">计算重量</el-button>
            <span>重量:</span>
            <el-input v-model="weight" style="width:150px" size="small" placeholder="重量">
              <el-button slot="append" icon="el-icon-cjn-09" @click="saveWeight"/>
            </el-input>
            <el-button style="margin-left: 10px;" type="primary" size="small" @click="insertThestring()">合并生产</el-button>
          </el-col>

          <el-col v-show="materielValue==='2'||materielValue==='9'||materielValue==='10'||materielValue==='11'" :span="20">
            <span>长:</span>
            <el-input-number v-model="Length" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>宽:</span>
            <el-input-number v-model="Width" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>厚:</span>
            <el-input-number v-model="height1" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <el-button style="margin-top: 20px;margin-left: 10px;" type="primary" size="small" @click="Calculation2()">计算重量
            </el-button>
            <span>重量:</span>
            <el-input v-model="weight" style="width:150px" size="small" placeholder="重量">
              <el-button slot="append" icon="el-icon-cjn-09" @click="saveWeight"/>
            </el-input>
          </el-col>

          <el-col v-show="materielValue==='3'" :span="20">
            <span>对边宽:</span>
            <el-input-number v-model="OppositeSideWidth" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>长度:</span>
            <el-input-number v-model="length2" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <el-button style="margin-top: 20px;margin-left: 10px;" type="primary" size="small" @click="Calculation3()">计算重量
            </el-button>
            <span>重量:</span>
            <el-input v-model="weight" style="width:150px" size="small" placeholder="重量">
              <el-button slot="append" icon="el-icon-cjn-09" @click="saveWeight"/>
            </el-input>
          </el-col>

          <el-col v-show="materielValue==='4'" :span="20">
            <span>边宽:</span>
            <el-input-number v-model="biankuan" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>边厚:</span>
            <el-input-number v-model="bianhou" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>长度:</span>
            <el-input-number v-model="changdu" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <el-button style="margin-top: 20px;margin-left: 10px;" type="primary" size="small" @click="Calculation4()">计算重量
            </el-button>
            <span>重量:</span>
            <el-input v-model="weight" style="width:150px" size="small" placeholder="重量">
              <el-button slot="append" icon="el-icon-cjn-09" @click="saveWeight"/>
            </el-input>
          </el-col>

          <el-col v-show="materielValue==='5'" :span="20">
            <span>壁厚:</span>
            <el-input-number v-model="bihou" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>外径:</span>
            <el-input-number v-model="waijing" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <span>长度:</span>
            <el-input-number v-model="changdu2" size="small" controls-position="right" style="width:100px;margin-top:20px;"/>
            <el-button style="margin-top: 20px;margin-left: 10px;" type="primary" size="small" @click="Calculation5()">计算重量
            </el-button>
            <span>重量:</span>
            <el-input v-model="weight" style="width:150px" size="small" placeholder="重量">
              <el-button slot="append" icon="el-icon-cjn-09" @click="saveWeight"/>
            </el-input>
          </el-col>

        </el-row>
      </div>
    </el-card>

    <el-card>
      <el-row>
        <span>输入数值:</span>
        <el-input v-model="numVal" size="small" style="width:100px" placeholder="输入数值"/>
        <span>选择参数:</span>
        <el-select v-model="selParaValue" size="small" style="width:100px" placeholder="选择参数">
          <el-option
            v-for="item in selPara"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span>公差:</span>
        <el-input v-model="tolerance" size="small" style="width:150px" placeholder="公差"/>
        <el-button style="margin:10px" type="primary" size="small" @click="calTol()">计算公差</el-button>
        <el-button-group v-if="isShow1" style="margin: 10px">
          <el-button v-if="isShow1" type="info" size="small" icon="el-icon-document" @click="pasteTable">粘贴
          </el-button>
          <el-button v-if="true" :disabled="disabled" type="warning" size="small" icon="el-icon-tickets" @click="DYbtn">原有
          </el-button>
          <el-button :disabled="disabled" type="warning" size="small" icon="el-icon-tickets" @click="WYbtn">
            完艺
          </el-button>
          <el-button :disabled="disabled" type="danger" size="small" icon="el-icon-delete" @click="deleteTable">删除
          </el-button>
          <el-button v-if="isShow1" type="primary" size="small" icon="el-icon-tickets" @click="copyAndSave">
            复制并保存
          </el-button>
          <el-button :disabled="disabled" type="primary" size="small" icon="el-icon-tickets" @click="saveApprove">保存
          </el-button>
        </el-button-group>
        <el-button v-if="!isShow1" type="warning" size="small" icon="el-icon-tickets" @click="saveCompiled">记录修改备注</el-button>
      </el-row>
      <div style="margin-top: 5px;margin-bottom: 10px;display: inline-block"><span>符号：</span>
        <el-tag type="info">∮</el-tag>
        <el-tag type="info">°</el-tag>
        <el-tag type="info">#</el-tag>
        <el-tag type="info">□</el-tag>
        <el-tag type="info">±</el-tag>
        <el-tag type="info">×</el-tag>
        <el-tag type="info">Ⅰ</el-tag>
        <el-tag type="info">Ⅱ</el-tag>
        <el-tag type="info">Ⅲ</el-tag>
        <el-tag type="info">⊥</el-tag>
        <el-tag type="info">％</el-tag>
        <el-tag type="info">■</el-tag>
        <el-tag type="info">∠</el-tag>
        <el-tag type="info">mm</el-tag>
        <el-tag type="info">◎</el-tag>
        <el-tag type="info">○</el-tag>
        <el-tag type="info">δ</el-tag>
        <el-tag type="info">μm</el-tag>
        <el-tag type="info">／</el-tag>
        <el-tag type="info">◇</el-tag>
        <el-tag type="info">()</el-tag>
      </div>
      <el-table
        v-loading="loading0"
        :data="tableData"
        class="processTable"
        border
        style="width: 100%;min-height: 400px;"
        size="mini">
        <el-table-column prop="num" label="序号" width="50" align="center" type="index"/>
        <el-table-column prop="name" label="工艺名称" width="180" align="center">
          <template slot-scope="scope">
            <el-cascader
              v-model="scope.row.工艺分类及名称"
              :options="options"
              :show-all-levels="false"
              placeholder=""
              filterable
              @change="handleChange(scope.row)"/>
          </template>
        </el-table-column>
        <el-table-column prop="hard" label="难度等级" width="110" align="center">
          <template slot-scope="scope">
            <el-select
              v-model="scope.row.工艺难度等级"
              clearable
              placeholder=""
              @change="hardEdit(scope.row)">
              <el-option v-for="item in hard" :key="item.value" :label="item.label" :value="item.value">
                <span style="color: #8492a6; font-size: 13px">{{ item.value }}</span>
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="request" label="工艺要求" align="center" min-width="350">
          <template slot-scope="scope">
            <el-autocomplete
              v-model="scope.row.工艺要求"
              :fetch-suggestions="querySearch"
              placeholder=""
              style="width: 100%"
              @focus="focusRequest(scope.row)"
              @blur="blurRequest(scope.row)"
              @select="blurRequest(scope.row)"/>
          </template>
        </el-table-column>
        <el-table-column prop="singleton" label="单件" width="100" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.单件定额工时" style="width:100%" placeholder="" @change="singleChange(scope.row)"/>
          </template>
        </el-table-column>
        <el-table-column prop="Settlement" label="准结" width="100" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.准结定额工时" style="width:100%" placeholder="" @change="readyChange(scope.row)"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300" align="center" fixed="right">
          <template slot-scope="scope">
            <div>
              <el-button
                icon="el-icon-arrow-up"
                type="primary"
                @click="upOne(scope.row)"/>
              <el-button
                icon="el-icon-arrow-down"
                type="primary"
                @click="downOne(scope.row)"/>
              <el-button
                icon="el-icon-circle-plus-outline"
                type="primary"
                @click="insertOne(scope.row)"/>
              <el-button
                icon="el-icon-delete"
                type="danger"
                @click="deleteOne(scope.row)"/>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog :visible.sync="dialogMaterial" title="物料选择" center width="400px">
      <el-input v-model="input" placeholder="材质" size="small" style="width:200px"/>
      <el-button type="success" size="small" icon="el-icon-search" style="margin: 0 0 10px 10px" @click="total=0;pageCurrent=1;pageSize=10;searchMaterial()">查询
      </el-button>
      <el-table :data="tableMaterial" size="mini" highlight-current-row border @row-click="selectMaterial">
        <el-table-column align="center" label="材质名称">
          <template slot-scope="scope">
            {{ scope.row.材料 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="1"
          :page-sizes="[10, 20]"
          :page-size="10"
          :pager-count="5"
          :total="total"
          small
          layout="sizes, prev, pager, next"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="selectMaterial2()">提交</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible2" title="工艺名称、工艺要求选择" center width="400px">
      <el-form ref="form2" :model="form2" label-position="left" label-width="125px" class="demo-ruleForm">
        <el-form-item label="工艺名称分类">
          <el-select v-model="processNameClassValue" filterable placeholder="分类" size="small" @change="cChange()">
            <el-option
              v-for="item in processNameClass"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="工艺名称">
          <el-select v-model="processNameValue" filterable placeholder="名称" size="small" @change="nChange()">
            <el-option
              v-for="item in processName"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="工艺要求">
          <el-select v-model="processRequestValue" placeholder="要求" size="small">
            <el-option
              v-for="item in processRequest"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="confirmSelect()">确定选择</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible" title="工艺选择" center width="800px">
      <el-form ref="form" :model="form" label-position="left" label-width="125px" class="demo-ruleForm">
        <el-row>
          <el-col :span="24">
            <el-form-item label="零件图号">
              <el-input v-model="partNameValue1" size="small" placeholder="输入零件图号" style="width: 150px" clearable/>
              <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 20px" @click="searchProcess()">查询
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="零件图号">
              <el-select id="num" v-model="processNumValue" placeholder="零件图号" style="width:150px" size="small" @change="numChange()">
                <el-option
                  v-for="item in partName1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
              <el-button size="small" style="margin-left: 20px" @click="processCopy()">工艺拷贝</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-table
          :data="tableData2"
          style="width: 97%;max-height: 300px;margin-top:15px"
          height="300px"
          border
          size="mini">
          <el-table-column align="center" label="工艺序号" width="80">
            <template slot-scope="scope">
              {{ scope.row.工序顺序 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="工艺名称" width="180">
            <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="80">
            <template slot-scope="scope">
              {{ scope.row.工艺难度等级 }}
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible1" title="已完工艺选择" center width="800px">
      <el-form ref="form1" :model="form1" label-position="left" label-width="80px" class="demo-ruleForm">
        <el-row>
          <el-col :span="10">
            <el-form-item label="零件号">
              <el-input v-model="PN" size="small" placeholder="输入零件号" style="width: 150px" clearable @change="inputChange"/>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-button size="small" type="success" icon="el-icon-search" @click="searchProcess1()">查询</el-button>
            <el-button size="small" @click="processCopy1()">工艺拷贝</el-button>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="零件图号">
              <el-select
                v-model="tuhaoValue"
                placeholder="零件图号"
                size="small"
                filterable
                style="width:150px"
                @change="numChange1()">
                <el-option
                  v-for="item in tuhao"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="零件名称">
              <el-input v-model="remark1" size="small" readonly style="width: 150px;"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-table :data="tableData4" style="width: 97%;max-height: 250px;margin-top: 15px" size="mini" border height="250px">
          <el-table-column align="center" label="工艺序号" width="80">
            <template slot-scope="scope">
              {{ scope.row.工序顺序 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="工艺名称" width="120">
            <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="110">
            <template slot-scope="scope">
              {{ scope.row.单件定额工时 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="准结定额工时" width="110">
            <template slot-scope="scope">
              {{ scope.row.准结定额工时 }}
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible3" title="工艺定额人员" center style="min-height: 300px">
      <el-table :data="tableData3" size="mini" style="width: 97%;max-height: 300px" height="300" highlight-current-row border @row-click="selectPerson">
        <el-table-column align="center" label="考勤编号" width="150">
          <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="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>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="tijiao()">提交</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import '@/icon/iconfont.css'
import {
  saveWeight,
  numChange,
  searchProcess11,
  WeightCopy,
  initCraftmen,
  getPartnames1,
  getPartnames2,
  detailInfo,
  mainTable,
  getMaterial,
  searchMaterial,
  typicalProcess,
  initTolerance,
  searchWYgongyi,
  gongyiCopy,
  initPerson,
  gongyiYQ,
  hardEdit,
  requestEdit,
  processNameClick,
  processNameSelect,
  processRequestSelect,
  searchTolerance,
  insertOne,
  deleteOne,
  upOne,
  downOne,
  saveMaterial,
  saveApprove,
  selectRequest,
  pasteTable,
  deleteTable,
  returnEdit,
  singleChange,
  readyChange,
  TableAddLi1,
  TableAddLi,
  getPartnames3,
  getPartnames4,
  modifyRemark
} from '@/api/ManufacturingCenter/ProcessQuotaEstablishment'
import elInput from 'element-ui/packages/input'
import { mapGetters } from 'vuex'
export default {
  name: 'ProcessQuotaEstablishment',
  components: {
    elInput
  },
  data() {
    return {
      machine_Group_part: '',
      partNumber: '',
      options: [],
      weight: '',
      dialogMateria2: false,
      prepareMateriel: '',
      lastFocusText: '',
      Result1: '',
      Result2: '',
      Result3: '',
      Result4: '',
      Result5: '',
      Length: '',
      Width: '',
      height1: '',
      diameter: '',
      height2: '',
      OppositeSideWidth: '',
      length2: '',
      biankuan: '',
      bianhou: '',
      changdu: '',
      bihou: '',
      waijing: '',
      changdu2: '',
      materielValue: '1',
      materiel: [
        {
          value: '1',
          label: '园钢'
        }, {
          value: '2',
          label: '钢板'
        }, {
          value: '3',
          label: '六角钢'
        }, {
          value: '4',
          label: '角钢'
        }, {
          value: '5',
          label: '钢管'
        }, {
          value: '6',
          label: '园紫铜棒'
        }, {
          value: '7',
          label: '园黄铜棒'
        }, {
          value: '8',
          label: '园铝棒'
        }, {
          value: '9',
          label: '紫铜板'
        }, {
          value: '10',
          label: '黄铜板'
        }, {
          value: '11',
          label: '6061铝板'
        }
      ],
      total: 0,
      pageCurrent: 1,
      pageSize: 10,
      input: '', // 材质对话框查询1
      tableMaterial: [],
      dialogMaterial: false,
      loading0: false,
      radio: 1, // 第一组
      partNumValue: '', // 零件号值
      partNum: [], // 零件号
      typeValue: '', // 种类
      CraftmenValue: '', // 工艺员值
      Craftmen: [], // 工艺员
      CraftmanValue: '', // 完艺表单工艺员值
      CraftmanValue2: '', // 完艺表单工艺员值中间变量
      Craftman: [], // 完艺表单工艺员
      partName: '', // 零件名称
      batchNum: '', // 投产总数量
      material: '', // 材质流水号
      materialName: '', // 材质名称
      materialClass: [], // 材质类
      typicalClassValue: '', // 典型工艺零件分类值
      typicalClass: [], // 典型工艺零件分类
      partNameValue1: '', // 典型工艺零件名称值
      partName1: [], // 典型工艺零件名称
      partNameValue1check: false, // 典型工艺零件名称check
      processNumValue: '', // 典型工艺号值
      processNum: [], // 典型工艺号
      processNumValuecheck: false, // 典型工艺号check
      remark: '', // 备注
      remark1: '', // 完艺零件名称
      dialogFormVisible: false, // 典艺对话框可见性
      dialogFormVisible1: false, // 完艺对话框可见性
      dialogFormVisible2: false, // 主界面查询工艺名称要求对话框可见性
      dialogFormVisible3: false, // 完艺对话框中选择工艺员可见性
      form: null, // 典艺表单
      form1: null, // 完艺表单
      form2: null, // 主界面查询表单
      serialNum1: [], // 典型工艺名称分类流水号
      serialNumValue1: '1', // 典型工艺名称分类流水号值,初值1否则置空时无参数
      serialNumValue1check: false, // 典型工艺名称分类流水号check
      serialNum2: [], // 典型工艺流水号
      serialNumValue2: '1', // 典型工艺流水号值，初值1否则置空时无参数
      numVal: '', // 输入数值
      selPara: [], // 选择参数数组
      selParaValue: '', // 选择参数值
      tolerance: '', // 公差
      tableData: [], // 主表
      tableData2: [], // 典艺内的表格
      tableData3: [], // 工艺定额人员
      tableData4: [], // 完艺表格
      processSelect: [], // 工艺分类流水号
      processNameClass: [], // 工艺名称分类
      processNameClassValue: '',
      processName: [], // 工艺名称
      processNameValue: '',
      processRequest: [], // 工艺要求
      processRequestValue: '',
      processN1: '', // 工艺编号
      str: '', // 拼接字符串用的
      value: '', // 第一个select的
      checked: false, // 是否核准
      checked1: false, // 修改
      spec: '', // 规格
      isShow: true, // '编辑模式'可见性
      isShow1: true, // “复制并保存”“粘贴”按钮的可见性
      isShow2: false, // 修改的可见性
      date01: '', // 完艺开始时间
      date02: '', // 完艺结束时间
      PN: '', // 零件号
      num: '', // 工艺计划流水号
      perNum: '',
      perNum2: '',
      tuhao: [],
      tuhaoValue: '',
      check1: 0,
      check2: 0,
      check3: 0,
      check4: 0,
      hard: [{ value: 'A' }, { value: 'B' }, { value: 'C' }],
      disabled: false,
      result: 0,
      oldNum: '',
      newNum: '',
      // tableRecord: [],
      materialName2: '',
      material2: ''
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'id',
      'token'
    ])
  },
  mounted() {
    this.fetchData()
    this.initPerson()
    this.getList()
    this.openCascader()
  },
  methods: {
    // 保存已编制
    saveCompiled() {
      if (this.partNumValue) {
        this.$prompt('请输入工艺修改备注', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({ value }) => {
          console.log(value, '日期', this.id, this.partNumValue)
          modifyRemark(this.id, value, this.partNumValue)
          this.$message.success('记录成功')
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作'
          })
        })
      } else {
        this.$message.warning('请选择零件')
      }
    },
    blurRequest(row) {
      selectRequest(row.工序流水号, row.工艺计划流水号, row.工艺编号, row.工序顺序, row.工艺要求).then(response => {
        if (response.data[0].result === '1') {
          console.log('工艺要求编辑成功')
        } else {
          console.log('工艺要求编辑失败')
        }
      })
    },
    focusRequest(row) {
      processRequestSelect(row.工艺编号).then(response => { // 查询工艺名称
        this.processRequest = []
        for (let j = 0; j < response.data.length; j++) {
          this.processRequest.push({
            value: response.data[j].工艺要求
          })
        }
      })
    },
    querySearch(queryString, cb) {
      const results = this.processRequest
      // 调用 callback 返回建议列表的数据
      cb(results)
    },
    // 初始化级联选择
    openCascader() {
      processNameClick().then(response => { // 初始化工艺分类
        this.options = []
        for (let i = 0; i < response.data.length; i++) {
          this.options.push({
            label: response.data[i].工艺分类名称,
            value: response.data[i].工艺分类流水号,
            children: []
          })
        }
      }).then(() => {
        this.options.map(firstLevel => {
          processNameSelect(firstLevel.value).then(response => { // 根据分类查询工艺名称
            firstLevel.children = []
            for (let j = 0; j < response.data.length; j++) {
              firstLevel.children.push({
                label: response.data[j].工艺名称,
                value: response.data[j].工艺编号
              })
            }
          })
        })
      })
    },
    handleChange(row) {
      row.工艺编号 = row.工艺分类及名称[1]
      row.工艺要求 = ''
      selectRequest(row.工序流水号, row.工艺计划流水号, row.工艺编号, row.工序顺序, row.工艺要求).then(response => {
        if (response.data[0].result === '1') {
          console.log('工艺名称编辑成功')
        } else {
          console.log('工艺名称编辑失败')
        }
      })
    },
    singleChange(row) {
      singleChange(row.工序流水号, row.单件定额工时).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('单件定额编辑成功')
        } else {
          this.$message.error('单件定额编辑失败')
        }
      })
    },
    readyChange(row) {
      readyChange(row.工序流水号, row.准结定额工时).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('准结定额编辑成功')
        } else {
          this.$message.error('准结定额编辑失败')
        }
      })
    },
    saveWeight() {
      if (this.partNumValue === '' || this.material === '') {
        this.$message.error('请选择一个零件')
      } else {
        saveWeight(this.partNumValue, this.weight).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('保存成功')
          } else {
            this.$message.error('保存失败')
          }
        })
      }
    },
    clear() {
      this.weight = ''
      this.Length = ''
      this.Width = ''
      this.height1 = ''
      this.diameter = ''
      this.height2 = ''
      this.OppositeSideWidth = ''
      this.biankuan = ''
      this.bianhou = ''
      this.changdu = ''
      this.bihou = ''
      this.waijing = ''
      this.changdu2 = ''
    },
    // 直径高计算
    Calculation1() {
      if (this.partNumValue === '' || this.partNumValue === null) {
        this.$message.error('请先选择一个零件')
      } else {
        if (this.materielValue === '1') {
          this.Result2 = '物料:' + this.materiel[1].label + ' 直径:' + this.diameter + 'mm  长度:' + this.height2
          // + 'mm  重量:' + 0.00617 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2) + 'kg'
          this.weight = 0.00617 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2)
          WeightCopy(this.partNumValue, this.Result2).then(response => {
            this.searchDetai2()
          })
        }
        if (this.materielValue === '6') {
          this.Result2 = '物料:' + this.materiel[6].label + ' 直径:' + this.diameter + 'mm  长度:' + this.height2
          // + 'mm  重量:' + 0.00698 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2) + 'kg'
          this.weight = 0.00698 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2)
          WeightCopy(this.partNumValue, this.Result2).then(response => {
            this.searchDetai2()
          })
        }
        if (this.materielValue === '7') {
          this.Result2 = '物料:' + this.materiel[7].label + ' 直径:' + this.diameter + 'mm  长度:' + this.height2
          // + 'mm  重量:' + 0.00668 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2) + 'kg'
          this.weight = 0.00668 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2)
          WeightCopy(this.partNumValue, this.Result2).then(response => {
            this.searchDetai2()
          })
        }
        if (this.materielValue === '8') {
          this.Result2 = '物料:' + this.materiel[8].label + ' 直径:' + this.diameter + 'mm  长度:' + this.height2
          // + 'mm  重量:' + 0.0022 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2) + 'kg'
          this.weight = 0.0022 * 0.001 * parseInt(this.diameter) * parseInt(this.diameter) * parseFloat(this.height2)
          WeightCopy(this.partNumValue, this.Result2).then(response => {
            this.searchDetai2()
          })
        }
      }
    },
    // 长宽高计算
    Calculation2() {
      if (this.partNumValue === '' || this.partNumValue === null) {
        this.$message.error('请先选择一个零件')
      } else {
        if (this.materielValue === '2') {
          this.Result1 = '物料:' + this.materiel[2].label + ' 长:' + this.Length + 'mm  宽:' + this.Width + 'mm  厚:' + this.height1
          // + 'mm  重量:' + 0.001 * 0.00785 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1) + 'kg'
          this.weight = 0.001 * 0.00785 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1)
          WeightCopy(this.partNumValue, this.Result1).then(response => {
            this.searchDetai2()
          })
        }
        if (this.materielValue === '9') {
          this.Result1 = '物料:' + this.materiel[9].label + ' 长:' + this.Length + 'mm  宽:' + this.Width + 'mm  厚:' + this.height1
          // + 'mm  重量:' + 0.001 * 0.0089 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1) + 'kg'
          this.weight = 0.001 * 0.0089 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1)
          WeightCopy(this.partNumValue, this.Result1).then(response => {
            this.searchDetai2()
          })
        }
        if (this.materielValue === '10') {
          this.Result1 = '物料:' + this.materiel[10].label + ' 长:' + this.Length + 'mm  宽:' + this.Width + 'mm  厚:' + this.height1
          // + 'mm  重量:' + 0.001 * 0.0085 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1) + 'kg'
          this.weight = 0.001 * 0.0085 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1)
          WeightCopy(this.partNumValue, this.Result1).then(response => {
            this.searchDetai2()
          })
        }
        if (this.materielValue === '11') {
          this.Result1 = '物料:' + this.materiel[11].label + ' 长:' + this.Length + 'mm  宽:' + this.Width + 'mm  厚:' + this.height1
          // + 'mm  重量:' + 0.001 * 0.0028 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1) + 'kg'
          this.weight = 0.001 * 0.0028 * parseInt(this.Length) * parseInt(this.Width) * parseFloat(this.height1)
          WeightCopy(this.partNumValue, this.Result1).then(response => {
            this.searchDetai2()
          })
        }
      }
    },
    // 对边宽*对边宽*长度
    Calculation3() {
      if (this.partNumValue === '' || this.partNumValue === null) {
        this.$message.error('请先选择一个零件')
      } else {
        if (this.materielValue === '3') {
          this.Result3 = '物料:' + this.materiel[3].label + ' 对边宽:' + this.OppositeSideWidth + 'mm  长度:' + this.length2
          // + 'mm  重量:' + 0.001 * 0.0068 * parseInt(this.OppositeSideWidth) * parseInt(this.OppositeSideWidth) * parseInt(this.length2) + 'kg'
          this.weight = 0.001 * 0.0068 * parseInt(this.OppositeSideWidth) * parseInt(this.OppositeSideWidth) * parseInt(this.length2)
          WeightCopy(this.partNumValue, this.Result3).then(response => {
            this.searchDetai2()
          })
        }
      }
    },
    // （边宽+边宽-边厚）×边厚×长度÷1000
    Calculation4() {
      if (this.partNumValue === '' || this.partNumValue === null) {
        this.$message.error('请先选择一个零件')
      } else {
        if (this.materielValue === '4') {
          this.Result4 = '物料:' + this.materiel[4].label + ' 边宽:' + this.biankuan + 'mm  边厚:' + this.bianhou + 'mm  长度:' + this.changdu
          // + 'mm  重量:' + 0.001 * 0.00785 * (parseInt(this.biankuan) + parseInt(this.biankuan) - parseInt(this.bianhou)) * parseInt(this.bianhou) * parseInt(this.changdu) + 'kg'
          this.weight = 0.001 * 0.00785 * (parseInt(this.biankuan) + parseInt(this.biankuan) - parseInt(this.bianhou)) * parseInt(this.bianhou) * parseInt(this.changdu)
          WeightCopy(this.partNumValue, this.Result4).then(response => {
            this.searchDetai2()
          })
        }
      }
    },
    Calculation5() {
      if (this.partNumValue === '' || this.partNumValue === null) {
        this.$message.error('请先选择一个零件')
      } else {
        if (this.materielValue === '5') {
          this.Result5 = '物料:' + this.materiel[5].label + ' 壁厚:' + this.bihou + 'mm  外径:' + this.waijing + 'mm  长度:' + this.changdu2
          // + 'mm  重量:' + 0.001 * 0.02466 * parseInt(this.bihou) * (parseInt(this.waijing) - parseInt(this.bihou)) * parseInt(this.changdu2) + 'kg'
          this.weight = 0.001 * 0.02466 * parseInt(this.bihou) * (parseInt(this.waijing) - parseInt(this.bihou)) * parseInt(this.changdu2)
          WeightCopy(this.partNumValue, this.Result5).then(response => {
            this.searchDetai2()
          })
        }
      }
    },
    insertThestring(NewCode) {
      this.lastFocusText = event.srcElement
      this.lastFocusText.focus()
      var sel = document.selection.createRange()
      sel.text = NewCode
      return
    },
    clearDetail() {
      this.checked = false
      this.weight = ''
      this.partNumValue = ''
      this.typeValue = ''
      this.partName = ''
      this.material = ''
      this.materialName = ''
      this.spec = ''
      this.batchNum = ''
    },
    returnEdit() { // 在制零件工艺修改
      if (this.partNumValue === '' || this.partNumValue === null) {
        this.$message.error('请选择零件')
      } else {
        this.$confirm('此操作会将该零件打回至未编制状态, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          returnEdit(this.partNumValue).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('打回成功')
              this.partNumValue = ''
              this.tableData = []
            } else {
              this.$message.error('打回失败')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          })
        })
      }
    },
    handleCurrentChange(val) { // 材质分页
      this.pageCurrent = val
      if (this.input === '' || this.input === null) {
        this.getList()
      } else {
        this.searchMaterial()
      }
    },
    handleSizeChange(val) { // 材质分页
      this.pageCurrent = 1
      this.pageSize = val
      if (this.input === '' || this.input === null) {
        this.getList()
      } else {
        this.searchMaterial()
      }
    },
    selectMaterial(row) { // 选择材质
      this.materialName2 = ''
      this.material2 = ''
      this.materialName2 = row.材料
      this.material2 = row.材料流水号
    },
    selectMaterial2() {
      this.materialName = ''
      this.material = ''
      this.materialName = this.materialName2
      this.material = this.material2
      this.dialogMaterial = false
    },
    fetchData() {
      this.materialClass = []
      getMaterial().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.materialClass.push({
            label: response.data[i].材料,
            value: response.data[i].材料流水号
          })
        }
      })
      initCraftmen().then(response => { // 初始化工艺员
        for (let i = 0; i < response.data.length; i++) {
          this.Craftmen.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
      typicalProcess().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.typicalClass.push({
            value: response.data[i].典型工艺名称分类
          })
          this.serialNum1.push({
            value: response.data[i].典型工艺名称分类流水号
          })
        }
      })
      initTolerance().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.selPara.push({
            value: response.data[i].参数
          })
        }
      })
    },
    initPerson() { // 初始化工艺员
      console.log(this.token, 12334)
      initPerson().then(response => {
        this.tableData3 = response.data
      })
    },
    getList() { // 往材质对话框中放
      this.tableMaterial = []
      getMaterial(this.pageCurrent, this.pageSize).then(response => {
        this.total = response.data.total
        this.tableMaterial = response.data.rows
      })
    },
    searchMaterial() { // 材质查询
      searchMaterial(this.pageCurrent, this.pageSize, this.input).then(response => {
        this.total = response.data.total
        this.tableMaterial = response.data.rows
      })
    },
    // 根据机床号-组号查询零件（包含借用件）
    searchPartsByMachineGroup() {
      this.tableData = []
      this.partNum = []
      if (this.radio === 1) { // 未编制
        this.disabled = false
        this.isShow1 = true
        this.isShow2 = false
        this.checked1 = true
        getPartnames3(this.CraftmenValue, this.machine_Group_part).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.partNum.push({
              label: response.data[i].零件图号,
              value: response.data[i].工艺计划流水号,
              machine: response.data[i].机床图号,
              group: response.data[i].组号
            })
          }
        })
      } else { // 已编制
        this.isShow = true
        this.isShow1 = false
        this.isShow2 = true
        this.disabled = true
        this.checked1 = false
        getPartnames4(this.CraftmenValue, this.machine_Group_part).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.partNum.push({
              label: response.data[i].零件图号,
              value: response.data[i].工艺计划流水号,
              machine: response.data[i].机床图号,
              group: response.data[i].组号
            })
          }
        })
      }
    },
    searchParts() { // 根据条件查零件号
      this.tableData = []
      this.partNum = []
      if (this.radio === 1) { // 未编制
        this.disabled = false
        this.isShow1 = true
        this.isShow2 = false
        this.checked1 = true
        getPartnames1(this.CraftmenValue, this.partNumber).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.partNum.push({
              label: response.data[i].零件图号,
              value: response.data[i].工艺计划流水号
            })
          }
        })
      } else { // 已编制
        this.isShow = true
        this.isShow1 = false
        this.isShow2 = true
        this.disabled = true
        this.checked1 = false
        getPartnames2(this.CraftmenValue, this.partNumValue).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.partNum.push({
              label: response.data[i].零件图号,
              value: response.data[i].工艺计划流水号
            })
          }
        })
      }
    },
    switchEdit() { // 切换编辑模式
      if (this.radio === 1) {
        this.isShow = !this.isShow
      } else {
        this.isShow = true
      }
    },
    // 查主表和上面显示的信息
    searchDetail() {
      if (this.partNumValue !== '' && this.partNumValue !== null) {
        this.loading0 = true
        detailInfo(this.partNumValue).then(response => {
          if (response.data.length !== 0) {
            this.typeValue = response.data[0].零件类型名称
            this.partName = response.data[0].零件名称
            this.batchNum = response.data[0].批次数量
            this.material = response.data[0].材料流水号
            this.materialName = response.data[0].材料
            this.spec = response.data[0].原材料规格
            if (response.data[0].重量 === null) {
              this.weight = ''
            } else {
              this.weight = response.data[0].重量
            }
          }
        })
        mainTable(this.partNumValue).then(response => {
          // console.log(response.data)
          this.tableData = []
          for (let i = 0; i < response.data.length; i++) {
            if (response.data[i].工艺编号 === null) {
              response.data[i].工艺编号 = 0
            }
            if (response.data[i].工艺要求 === null) {
              response.data[i].工艺要求 = ''
            }
            if (response.data[i].工艺名称 === null || response.data[i].工艺名称 === '') {
              response.data[i].工艺难度等级 = ''
              response.data[i].单件定额工时 = ''
              response.data[i].准结定额工时 = ''
            }
          }
          this.tableData = response.data
          this.tableData.map(h => {
            this.$set(h, '工艺分类及名称', [])
            this.options.map(v => {
              v.children.map(l => {
                if (l.value === h.工艺编号) {
                  h.工艺分类及名称 = [Number(v.value), Number(h.工艺编号)]
                }
              })
            })
          })
          this.newNum = this.partNumValue
        }).then(() => {
          this.loading0 = false
        })
      }
    },
    searchDetai2() {
      if (this.partNumValue !== '' && this.partNumValue !== null) {
        this.loading0 = true
        mainTable(this.partNumValue).then(response => {
          this.tableData = []
          for (let i = 0; i < response.data.length; i++) {
            if (response.data[i].工艺编号 === null) {
              response.data[i].工艺编号 = 0
            }
            if (response.data[i].工艺要求 === null) {
              response.data[i].工艺要求 = ''
            }
            if (response.data[i].工艺名称 === null || response.data[i].工艺名称 === '') {
              response.data[i].工艺难度等级 = ''
              response.data[i].单件定额工时 = ''
              response.data[i].准结定额工时 = ''
            }
          }
          this.tableData = response.data
          this.tableData.map(h => {
            this.$set(h, '工艺分类及名称', [])
            this.options.map(v => {
              v.children.map(l => {
                if (l.value === h.工艺编号) {
                  h.工艺分类及名称 = [Number(v.value), Number(h.工艺编号)]
                }
              })
            })
          })
          this.newNum = this.partNumValue
        }).then(() => {
          this.loading0 = false
        })
      }
    },
    DYbtn() { // 典艺按钮
      this.dialogFormVisible = true
      this.processNumValue = ''
      this.partNameValue1 = ''
      this.typicalClassValue = ''
      this.remark = ''
      this.serialNumValue1 = '1' // 有默认值
      this.serialNumValue2 = '1' // 有默认值
      this.tableData2 = null
    },
    WYbtn() { // 完艺按钮
      this.tableData4 = []
      this.tuhaoValue = ''
      this.remark1 = ''
      this.dialogFormVisible1 = true
    },
    selectPerson(row) { // 选择工艺员
      this.CraftmanValue2 = row.姓名
      this.perNum2 = row.人员编号
    },
    tijiao() { // 提交完艺表单中工艺定额人员的选择
      this.dialogFormVisible3 = false
      this.CraftmanValue = this.CraftmanValue2
      this.perNum = this.perNum2
      this.remark1 = ''
      this.tuhaoValue = ''
    },
    inputChange() { // 零件号改变
      this.remark1 = ''
      this.tuhaoValue = ''
    },
    // 典艺工艺查询
    searchProcess() {
      this.processNumValue = ''
      this.partName1 = []
      this.tableData2 = []
      searchProcess11(this.partNameValue1).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.partName1.push({
            label: response.data[i].零件图号,
            value: response.data[i].典艺流水号
          })
        }
      })
    },
    // 典艺选择查表格
    numChange() {
      numChange(this.processNumValue).then(response => {
        this.tableData2 = response.data
      })
    },
    // 典艺工艺拷贝
    processCopy() {
      if (this.partNumValue === '') {
        this.$message.error('请在主界面选择一个零件作为被拷贝对象')
        this.dialogFormVisible = false
      } else if (this.processNumValue === '') {
        this.$message.error('请选择零件图号')
      } else {
        for (let i = 0; i < this.tableData2.length; i++) {
          this.tableData[i].工艺名称 = this.tableData2[i].工艺名称
          this.tableData[i].工艺难度等级 = this.tableData2[i].工艺难度等级
          this.tableData[i].工艺要求 = this.tableData2[i].工艺要求
          selectRequest(this.tableData[i].工序流水号, this.tableData[i].工艺计划流水号, this.tableData2[i].工艺编号, this.tableData2[i].工序顺序, this.tableData2[i].工艺要求)
          hardEdit(this.tableData[i].工序流水号, this.tableData2[i].工艺难度等级)
        }
        this.dialogFormVisible = false
      }
    },
    searchProcess1() { // 完艺工艺查询
      this.tuhao = []
      if (this.PN === '') { // 零件号
        this.check1 = 0
      } else {
        this.check1 = 1
      }
      if (this.perNum === '') { // 工艺员编号
        this.check2 = 0
      } else {
        this.check2 = 1
      }
      if (this.remark1 === '') { // 零件名称
        this.check4 = 0
      } else {
        this.check4 = 1
      }
      if (this.date01 === '' || this.date02 === '' || this.date01 === null || this.date02 === null) { // 日期
        this.check3 = 0
      } else {
        this.check3 = 1
      }
      searchWYgongyi(this.check1, this.PN, this.check2, this.perNum, this.check3, this.date01, this.date02, this.check4, this.remark1).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.tuhao.push({
            label: response.data[i].零件图号,
            name: response.data[i].零件名称,
            value: response.data[i].工艺计划流水号
          })
        }
      })
    },
    // 完艺工艺拷贝
    processCopy1() {
      this.dialogFormVisible1 = false
      if (this.partNumValue === '') {
        this.$message.error('请在主界面选择一个零件作为被拷贝对象')
      } else {
        gongyiCopy(this.num, this.partNumValue).then(res => { // 工艺计划流水号_完成工艺, 工艺计划流水号_被拷工艺
          this.searchDetail()
        })
      }
    },
    // 当完成工艺号改变时，零件名称改变，并获取工艺要求
    numChange1() {
      this.remark1 = ''
      this.tableData4 = null
      console.log(this.tuhaoValue)
      for (let i = 0; i < this.tuhao.length; i++) {
        if (this.tuhaoValue === this.tuhao[i].value) {
          this.remark1 = this.tuhao[i].name
          this.num = this.tuhao[i].value
        }
      }
      gongyiYQ(this.num).then(response => {
        this.tableData4 = response.data
      })
    },
    hardEdit(row) { // 修改难度等级
      hardEdit(row.工序流水号, row.工艺难度等级).then(response => {
        if (response.data[0].result === '1') {
          console.log('难度等级编辑成功')
        } else {
          console.log('难度等级编辑失败')
        }
      })
    },
    // 修改工艺要求
    requestEdit(row) {
      requestEdit(row.工序流水号, row.工艺要求)
    },
    tableSearch(index) { // 主界面工艺名称分类、工艺名称及工艺要求后续查询
      if (this.checked1 === false) {
        this.dialogFormVisible2 = false
      } else {
        this.dialogFormVisible2 = true
        if (index !== this.index) {
          this.str = '' // 清字符串
        }
        this.index = index
        this.processNameClassValue = ''
        this.processNameValue = ''
        this.processRequestValue = ''
        this.processNameClass = []
        this.processName = []
        this.processRequest = []
        processNameClick().then(response => { // 初始化工艺名称的
          for (let i = 0; i < response.data.length; i++) {
            this.processNameClass.push({ // 工艺名称分类
              value: response.data[i].工艺分类名称
            })
            this.processSelect.push({ // 工艺分类流水号
              value: response.data[i].工艺分类流水号
            })
          }
        })
      }
    },
    cChange() { // 工艺名称分类改变
      this.processNameValue = ''
      this.processName = []
      this.processRequestValue = ''
      this.processRequest = []
      for (let i = 0; i < this.processNameClass.length; i++) {
        if (this.processNameClassValue === this.processNameClass[i].value) {
          processNameSelect(this.processSelect[i].value).then(response => { // 查询工艺名称
            for (let j = 0; j < response.data.length; j++) {
              this.processName.push({
                value: response.data[j].工艺名称,
                num: response.data[j].工艺编号
              })
            }
          })
        }
      }
    },
    nChange() { // 工艺名称改变
      this.processRequestValue = ''
      this.processRequest = []
      for (let i = 0; i < this.processName.length; i++) {
        if (this.processNameValue === this.processName[i].value) {
          this.processN1 = this.processName[i].num // 工艺编号
          processRequestSelect(this.processName[i].num).then(response => { // 查询工艺名称
            for (let j = 0; j < response.data.length; j++) {
              this.processRequest.push({
                value: response.data[j].工艺要求
              })
            }
          })
        }
      }
    },
    // 确定选择主表的工艺名称及要求
    confirmSelect() {
      this.tableData[this.index].工艺编号 = this.processN1
      this.tableData[this.index].工艺名称 = this.processNameValue
      this.str = this.str + this.processRequestValue
      this.tableData[this.index].工艺要求 = this.str
      this.dialogFormVisible2 = false
      selectRequest(this.tableData[this.index].工序流水号, this.tableData[this.index].工艺计划流水号, this.tableData[this.index].工艺编号, this.tableData[this.index].工序顺序, this.tableData[this.index].工艺要求)
    },
    calTol() { // 计算公差
      this.tolerance = ''
      for (let i = 0; i < this.selPara.length; i++) {
        if (this.selParaValue === this.selPara[i].value) {
          break
        }
      }
      searchTolerance(this.numVal, this.selParaValue).then(response => {
        if (response.data.length !== 0) { // 防止超出范围报错
          this.tolerance = response.data[0].公差
        } else {
          this.$message.error('输入的数值不对！')
        }
      })
    },
    copyAndSave() { // 复制并保存
      if (this.tableData.length !== 0) {
        this.oldNum = this.tableData[0].工艺计划流水号
        this.saveApprove()
      } else {
        this.$message.error('当前没有可以被复制的工艺')
      }
    },
    saveApprove() { // 核准保存
      if (this.checked === true) {
        let 零件图号
        let flag = 0
        for (let i = 0; i < this.tableData.length; i++) {
          saveApprove(this.tableData[i].工艺计划流水号, this.tableData[i].工艺编号, this.tableData[i].工艺要求, this.spec, this.tableData[i].工序顺序, this.tableData[i].工序间是否外协, this.tableData[i].工序流水号, this.material, '', '', this.CraftmenValue, this.tableData[i].工艺难度等级).then(() => {
            for (let j = 0; j < this.partNum.length; j++) {
              if (this.partNum[j].value === this.partNumValue) {
                零件图号 = this.partNum[j].label
              }
            }
            TableAddLi(this.tableData[i].单件定额工时, this.tableData[i].准结定额工时, 零件图号, this.tableData[i].工序流水号, this.tableData[i].工艺计划流水号).then(() => {
              flag++
              if (flag === this.tableData.length) {
                TableAddLi1(this.partNumValue, this.CraftmenValue).then(() => {
                  this.checked = false
                  this.partNumValue = ''
                  this.typeValue = ''
                  this.partName = ''
                  this.batchNum = ''
                  this.material = ''
                  this.materialName = ''
                  this.spec = ''
                  this.newNum = ''
                  this.searchParts()
                  this.searchPartsByMachineGroup()
                  this.$message.success('保存成功')
                })
              }
            })
          })
        }
      } else {
        this.$message.error('请核准后保存')
      }
    },
    insertOne(row) { // 插入行
      if (this.partNumValue === '') {
        this.$message.error('请先选择一个零件')
      } else {
        insertOne(this.partNumValue, row.工序流水号).then(response => {
          this.searchDetail()
        })
      }
    },
    deleteOne(row) { // 删除行
      if (this.partNumValue === '') {
        this.$message.error('请先选择一个零件')
      } else {
        this.$confirm('此操作将永久删除该行工艺, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteOne(this.partNumValue, row.工序流水号).then(() => {
            this.$message.success('删除成功')
            this.searchDetail()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    },
    upOne(row) { // 上移
      if (this.partNumValue === '') {
        this.$message.error('请先选择一个零件')
      } else {
        upOne(this.partNumValue, row.工序流水号).then(response => {
          this.searchDetail()
        })
      }
    },
    downOne(row) { // 下移
      if (this.partNumValue === '') {
        this.$message.error('请先选择一个零件')
      } else {
        downOne(this.partNumValue, row.工序流水号).then(response => {
          this.searchDetail()
        })
      }
    },
    saveMaterial() { // 保存材质
      if (this.partNumValue === '' || this.material === '') {
        this.$message.error('请选择一个零件')
      } else {
        saveMaterial(this.partNumValue, this.material).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('保存成功')
          } else {
            this.$message.error('保存失败')
          }
        })
      }
    },
    pasteTable() { // 粘贴
      if (this.partNumValue === '' || this.partNumValue === null) {
        this.$message.error('请选择零件作为被粘贴对象')
      } else {
        pasteTable(this.oldNum, this.newNum).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('粘贴成功')
            this.searchDetail()
          } else {
            this.$message.error('粘贴失败')
          }
        })
      }
    },
    deleteTable() { // 删除
      if (this.newNum === '') {
        this.$message.error('请选择一个零件')
      } else {
        this.$confirm('此操作将永久删除该零件的工艺, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          for (let i = 0; i < 30; i++) {
            hardEdit(this.tableData[i].工序流水号, '').then(response => {
            })
          }
          deleteTable(this.newNum).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('删除成功')
              this.searchDetail()
            } else {
              this.$message.error('删除失败')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    }
  }
}
</script>

<style scoped>
  .doing-row4 {
    background: #f0f9eb;
  }
  .el-card {
    margin-bottom: 15px;
  }
  .el-date-editor {
    width: 150px
  }
  span {
    margin: 10px 0 10px 10px;
  }
  .el-table .change {
    background: oldlace;
  }
</style>
<style lang="scss">
  .processTable{
    .el-input__inner{
      font-weight: bold;
      font-size: 20px;
    }
    .el-textarea__inner{
      font-weight: bold;
      font-size: 20px;
    }
    .el-cascader__label{
      font-weight: bold;
      font-size: 20px;
    }
  }
</style>
