<template>
  <div class="app-container">

    <el-card style="margin-bottom: 20px">
      <el-radio-group
        v-model="radio"
        size="small"
        style="margin: 10px;"
        @change="Organization()">
        <el-radio :label="0">未编制</el-radio>
        <el-radio :label="1">已编制</el-radio>
      </el-radio-group>
      <span>工艺员:</span>
      <el-select v-model="CraftmenValue" placeholder="工艺员" size="small" style="width:100px" @change="clearDetail();searchMachine()">
        <el-option
          v-for="item in Craftmen"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <span>机床编号:</span>
      <el-select v-model="machineNumberValue" filterable clearable placeholder="机床编号" size="small" @change="searchGroup()">
        <el-option
          v-for="item in machineNumber"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <el-button type="success" icon="el-icon-search" style="margin: 10px;" size="small" @click="searchDetail">查询</el-button>
      <el-button v-show="isShow2" type="danger" icon="el-icon-edit" size="small" @click="returnEdit">装配工艺调整</el-button>
    </el-card>
    <el-card style="background-color: #DCDCDC">
      <el-row>
        <el-button :disabled="disabled" type="warning" size="small" icon="el-icon-tickets" style="margin-left: 20px" @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="primary" size="small" icon="el-icon-tickets" @click="handleAdd">增加</el-button>
        <el-button :disabled="disabled" type="danger" size="small" icon="el-icon-delete" @click="deleteTable">删除</el-button>
        <el-button :disabled="disabled" type="primary" size="small" icon="el-icon-cjn-09" @click="saveApprove">保存</el-button>
        <el-checkbox v-model="checked" :disabled="isShow2" size="small" style="margin:10px">是否核准</el-checkbox>
      </el-row>
      <div v-for="(item, key) in dataAll" :key="key" style="margin-bottom: 30px">
        <el-table
          :data="item.table1"
          border
          style="width: 100%;margin-top: 15px">
          <el-table-column
            label="序号"
            width="80"
            align="center">
            <template slot-scope="scope">
              {{ scope.row.序号 }}
            </template>
          </el-table-column>
          <el-table-column
            label="组号"
            width="240"
            align="center">
            <template slot-scope="scope">
              {{ scope.row.组号 }}
            </template>
          </el-table-column>
          <el-table-column
            label="装配任务"
            align="center">
            <template slot-scope="scope">
              {{ scope.row.装配任务 }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="300">
            <template slot-scope="scope">
              <el-button
                :disabled="disabled"
                size="mini"
                icon="el-icon-edit"
                type="primary"
                @click="handleEdit(scope.row, 'form2')">编辑</el-button>
              <el-button
                :disabled="disabled"
                size="mini"
                icon="el-icon-delete"
                type="danger"
                @click="deleteGroup(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-table :data="item.table2" size="mini" border style="width: 100%">
          <el-table-column label="序号" width="90" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.序号" :disabled="disabled" size="mini" style="width:60px" @change="update(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column label="工序名称" width="230" align="center">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.工序名称"
                :disabled="disabled"
                size="mini"
                style="width:200px"
                @dblclick.native="tableSearch(scope.row)"
                @change="update(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column label="工艺内容及装配具体要求" align="center">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.工艺内容及装配具体要求"
                :rows="1"
                :disabled="disabled"
                size="mini"
                type="textarea"
                @change="update(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column label="质检" align="center" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.质检" :disabled="disabled" size="mini" align="center" @change="update(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="300">
            <template slot-scope="scope">
              <el-button
                :disabled="disabled"
                size="mini"
                icon="el-icon-arrow-up"
                type="primary"
                @click="upOne(scope.row)"/>
              <el-button
                :disabled="disabled"
                size="mini"
                icon="el-icon-arrow-down"
                type="primary"
                @click="downOne(scope.row)"/>
              <el-button
                :disabled="disabled"
                size="mini"
                icon="el-icon-circle-plus-outline"
                type="primary"
                @click="insertOne(scope.row)"/>
              <el-button
                :disabled="disabled"
                size="mini"
                icon="el-icon-delete"
                type="danger"
                @click="deleteOne(scope.row)"/>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <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" 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" 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-input v-model="processRequestValue" placeholder="要求" size="small"/>
        </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 :title="title" :visible.sync="dialogFormVisible4" center width="400px">
      <el-form ref="form2" :model="form2" :rules="rules" label-position="left" label-width="125px" class="demo-ruleForm">
        <el-form-item label="序号" prop="序号">
          <el-input v-model="form2.序号" placeholder="序号" size="small"/>
        </el-form-item>
        <el-form-item label="组件" prop="组件">
          <el-select v-model="form2.组件" multiple placeholder="组件" size="small">
            <el-option
              v-for="item in GroupNumber"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="装配任务" prop="装配任务">
          <el-input v-model="form2.装配任务" placeholder="装配任务" type="textarea" size="small"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible4=false">取消</el-button>
        <el-button v-show="title==='增加组件工艺'" type="primary" @click="submitAdd()">确定</el-button>
        <el-button v-show="title==='编辑组件工艺'" type="primary" @click="submitEdit()">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible5" title="典型工艺选择" center width="800px">
      <el-form ref="form1" :model="form1" label-position="left" class="demo-ruleForm">
        <el-row>
          <el-col :span="9">
            <el-form-item label="典型工艺机床分类">
              <el-select v-model="machineTypeValue" placeholder="机床分类" size="small" style="width:150px" @change="SearchMachine">
                <el-option
                  v-for="item in machineType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="机床编号">
              <el-select v-model="machineNumberValue1" placeholder="机床编号" size="small" style="width:150px">
                <el-option
                  v-for="item in machineNumber2"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-button size="small" type="success" icon="el-icon-search" @click="searchCompleted()">查询</el-button>
            <el-button size="small" @click="processCopy1()">工艺拷贝</el-button>
          </el-col>
        </el-row>
        <div v-for="(item, key) in dataAll1" :key="key" style="margin-bottom: 30px">
          <el-table
            :data="item.table1"
            border
            style="width: 100%;margin-top: 15px">
            <el-table-column
              label="序号"
              width="80"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.序号 }}
              </template>
            </el-table-column>
            <el-table-column
              label="组号"
              width="240"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column
              label="装配任务"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.装配任务 }}
              </template>
            </el-table-column>
          </el-table>
          <el-table :data="item.table2" size="mini" border style="width: 100%">
            <el-table-column label="序号" width="90" align="center">
              <template slot-scope="scope">
                {{ scope.row.序号 }}
              </template>
            </el-table-column>
            <el-table-column label="工序名称" width="230" align="center">
              <template slot-scope="scope">
                {{ scope.row.工序名称 }}
              </template>
            </el-table-column>
            <el-table-column label="工艺内容及装配具体要求" align="center">
              <template slot-scope="scope">
                {{ scope.row.工艺内容及装配具体要求 }}
              </template>
            </el-table-column>
            <el-table-column label="质检" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.质检 }}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible1" title="已完工艺选择" center width="800px">
      <el-form ref="form1" :model="form1" label-position="left" class="demo-ruleForm">
        <el-row>
          <el-col :span="8">
            <el-form-item label="工艺员">
              <el-input v-model="CraftmanValue" size="small" readonly style="width: 150px;" @focus="dialogFormVisible3=true"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="机床编号">
              <el-select v-model="machineNumberValue1" placeholder="机床编号" size="small" style="width:150px">
                <el-option
                  v-for="item in machineNumber1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-button size="small" type="success" icon="el-icon-search" @click="searchCompleted()">查询</el-button>
            <el-button size="small" @click="processCopy1()">工艺拷贝</el-button>
          </el-col>
        </el-row>
        <div v-for="(item, key) in dataAll1" :key="key" style="margin-bottom: 30px">
          <el-table
            :data="item.table1"
            border
            style="width: 100%;margin-top: 15px">
            <el-table-column
              label="序号"
              width="80"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.序号 }}
              </template>
            </el-table-column>
            <el-table-column
              label="组号"
              width="240"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.组号 }}
              </template>
            </el-table-column>
            <el-table-column
              label="装配任务"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.装配任务 }}
              </template>
            </el-table-column>
          </el-table>
          <el-table :data="item.table2" size="mini" border style="width: 100%">
            <el-table-column label="序号" width="90" align="center">
              <template slot-scope="scope">
                {{ scope.row.序号 }}
              </template>
            </el-table-column>
            <el-table-column label="工序名称" width="230" align="center">
              <template slot-scope="scope">
                {{ scope.row.工序名称 }}
              </template>
            </el-table-column>
            <el-table-column label="工艺内容及装配具体要求" align="center">
              <template slot-scope="scope">
                {{ scope.row.工艺内容及装配具体要求 }}
              </template>
            </el-table-column>
            <el-table-column label="质检" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.质检 }}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </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 { initCraftmen, searchMachine, searchGroup, submitAdd, submitEdit, searchDetail, searchProcess, insertOne, update, upOne, downOne, deleteOne,
  deleteGroup, saveApprove, returnEdit, procedureCopy1, processCopy1, initprocessNameClass, initProcessName, update1, initmachineType, SearchMachine } from '@/api/Assembly/AssemblyProcessPlanning'
import '@/icon/iconfont.css'
export default {
  data() {
    return {
      title: '',
      radio: 0,
      checked: false,
      disabled: false,
      CraftmenValue: '',
      Craftmen: [],
      CraftmanValue: '',
      perNum: '',
      Name: '',
      Number: '',
      machineNumberValue: '',
      machineNumber: [],
      machineNumberValue1: '',
      machineNumber1: [],
      machineNumberValue2: '',
      machineNumber2: [],
      machineTypeValue: '',
      machineType: [],
      AssemblyTask: '',
      Group: '',
      GroupNumberValue: '',
      GroupNumberValue1: '',
      GroupNumber: [],
      GroupNum: '',
      GroupProcessNumber: '',
      SerialNumber: '',
      SerialNumberGroup: [],
      isShow2: false,
      processNameClassValue: '',
      processNameClass: [],
      processNameValue: '',
      Process: '',
      processName: [],
      Procedure: '',
      ProcedureNameGroup: [],
      processRequestValue: '',
      QualityTesting: [],
      ProcessSequence: [],
      tableData: [],
      tableData1: [],
      tableData2: [],
      tableData3: [],
      loading: false,
      form1: {},
      form2: {
        序号: '',
        组件: [],
        装配任务: ''
      },
      rules: {
        序号: [{ required: true, message: '请输入序号', trigger: 'blur' }],
        组件: [{ required: true, message: '请选择组件', trigger: 'change' }],
        装配任务: [{ required: true, message: '请输入装配任务', trigger: 'blur' }]
      },
      num1: '',
      result: 0,
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      dialogFormVisible4: false,
      dialogFormVisible5: false,
      dataAll: [],
      dataAll1: []
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      initCraftmen().then(response => { // 初始化工艺员
        this.tableData3 = response.data
        for (let i = 0; i < response.data.length; i++) {
          this.Craftmen.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
      initprocessNameClass().then(response => { // 初始化工序分类
        for (let i = 0; i < response.data.length; i++) {
          this.processNameClass.push({
            label: response.data[i].工序分类名称,
            value: response.data[i].工序分类流水号
          })
        }
      })
      initmachineType().then(response => { // 初始化机床分类
        for (let i = 0; i < response.data.length; i++) {
          this.machineType.push({
            label: response.data[i].机床分类名称,
            value: response.data[i].机床分类流水号
          })
        }
      })
    },
    clearDetail() {
      this.checked = false
      this.machineNumberValue = ''
    },
    searchMachine() { // 根据条件查机床编号
      this.machineNumber = []
      searchMachine(this.CraftmenValue, this.radio).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineNumber.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    searchGroup() {
      this.GroupNumber = []
      searchGroup(this.machineNumberValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.GroupNumber.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    async searchDetail() { // 主表查询
      this.dataAll = []
      if (this.machineNumberValue !== '') {
        const response = await searchDetail(this.machineNumberValue)
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          const response2 = await searchProcess(data[i].组件工艺流水号)
          this.dataAll.push({
            table1: [data[i]],
            table2: response2.data
          })
        }
      } else {
        this.$message.warning('请先选择机床编号')
      }
    },
    Organization() {
      this.CraftmenValue = ''
      this.checked = false
      this.machineNumberValue = ''
      this.machineNumber = []
      if (this.radio === 0) {
        this.dataAll = []
        this.isShow2 = false
        this.disabled = false
      } else if (this.radio === 1) {
        this.dataAll = []
        this.isShow2 = true
        this.disabled = true
      }
    },
    returnEdit() {
      returnEdit(this.machineNumberValue).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('调整成功')
          this.CraftmenValue = ''
          this.machineNumberValue = ''
          this.machineNumber = []
          this.dataAll = []
        } else { this.$message.error('调整失败') }
      })
    },
    DYbtn() {
      if (this.machineNumberValue !== '') {
        this.dialogFormVisible5 = true
        this.dataAll1 = []
        this.machineTypeValue = ''
        this.machineNumber2 = []
        this.machineNumberValue1 = ''
      } else {
        this.$message.warning('请先选择机床')
      }
    },
    SearchMachine() {
      this.machineNumberValue1 = ''
      this.machineNumber2 = []
      SearchMachine(this.machineTypeValue).then(response => { // 典型机床查询
        for (let i = 0; i < response.data.length; i++) {
          this.machineNumber2.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    WYbtn() {
      if (this.machineNumberValue !== '') {
        this.dialogFormVisible1 = true
        this.dataAll1 = []
        this.machineNumber1 = []
        this.machineNumberValue1 = ''
        this.CraftmanValue = ''
      } else {
        this.$message.warning('请先选择机床')
      }
    },
    selectPerson(row) { // 选择工艺员
      this.Name = row.姓名
      this.Number = row.人员编号
    },
    tijiao() {
      this.dialogFormVisible3 = false
      this.CraftmanValue = this.Name
      this.perNum = this.Number
      this.machineNumber = []
      searchMachine(this.perNum, 1).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineNumber1.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    async searchCompleted() { // 主表查询
      this.dataAll1 = []
      if (this.machineNumberValue1 !== '') {
        const response = await searchDetail(this.machineNumberValue1)
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          const response2 = await searchProcess(data[i].组件工艺流水号)
          this.dataAll1.push({
            table1: [data[i]],
            table2: response2.data
          })
        }
      } else {
        this.$message.warning('请先选择机床编号')
      }
    },
    async processCopy1() {
      this.result = 0
      for (let i = 0; i < this.dataAll1.length; i++) {
        processCopy1(this.machineNumberValue, this.dataAll1[i].table1[0].序号, this.dataAll1[i].table1[0].组号, this.dataAll1[i].table1[0].装配任务).then(response => {
          this.GroupNum = parseInt(response.data.output[0].组件工艺流水号)
          if (response.data.result[0].result === '1') {
            for (let j = 0; j < this.dataAll1[i].table2.length; j++) {
              procedureCopy1(this.GroupNum, this.dataAll1[i].table2[j].序号, this.dataAll1[i].table2[j].工序名称, this.dataAll1[i].table2[j].工艺内容及装配具体要求, this.dataAll1[i].table2[j].质检, this.dataAll1[i].table2[j].工序顺序).then(response => {
              })
            }
          }
          this.result += parseInt(response.data.result[0].result)
          if (this.result === this.dataAll1.length) {
            this.$message.success('拷贝成功')
            this.dialogFormVisible1 = false
            this.dialogFormVisible5 = false
            this.searchDetail()
          }
        })
      }
    },
    handleAdd() {
      if (this.machineNumberValue !== '') {
        this.addForm('form2', [this.dialogFormVisible4 = true, this.title = '增加组件工艺', this.Group = '', this.GroupNumberValue1 = ''])
      } else {
        this.$message.warning('请先选择机床编号')
      }
    },
    handleEdit(row, formName) {
      if (this.$refs[formName] !== undefined) {
        this.$refs[formName].resetFields()
      }
      this.GroupProcessNumber = row.组件工艺流水号
      this.GroupNumberValue1 = ''
      this.title = '编辑组件工艺'
      this.dialogFormVisible4 = true
      this.form2.序号 = row.序号
      this.form2.装配任务 = row.装配任务
      this.Group = ''
      console.log(row, 1111)
      this.form2.组件 = (row.组件流水号.split(',')).map(Number)
      console.log(this.form2.组件)
    },
    submitAdd() {
      this.GroupNumberValue1 = this.form2.组件[0]
      for (let h = 1; h < this.form2.组件.length; h++) {
        this.GroupNumberValue1 += ',' + this.form2.组件[h]
      }
      for (let i = 0; i < this.form2.组件.length; i++) {
        for (let j = 0; j < this.GroupNumber.length; j++) {
          if (this.form2.组件[i] === this.GroupNumber[j].value) {
            this.form2.组件[i] = this.GroupNumber[j].label
          }
        }
        this.Group += this.form2.组件[i] + '组 '
      }
      this.addTable(submitAdd, [this.machineNumberValue, this.form2.序号, this.Group, this.form2.装配任务, this.GroupNumberValue1], 'form2', function() { this.dialogFormVisible4 = false; this.searchDetail() })
    },
    submitEdit() {
      this.GroupNumberValue1 = this.form2.组件[0]
      for (let h = 1; h < this.form2.组件.length; h++) {
        this.GroupNumberValue1 += ',' + this.form2.组件[h]
      }
      for (let i = 0; i < this.form2.组件.length; i++) {
        for (let j = 0; j < this.GroupNumber.length; j++) {
          if (this.form2.组件[i] === this.GroupNumber[j].value) {
            this.form2.组件[i] = this.GroupNumber[j].label
          }
        }
        this.Group += this.form2.组件[i] + '组 '
      }
      this.editTable(submitEdit, [this.GroupProcessNumber, this.form2.序号, this.Group, this.form2.装配任务, this.GroupNumberValue1], 'form2', function() { this.searchDetail(); this.dialogFormVisible4 = false })
    },
    deleteGroup(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteGroup(row.组件工艺流水号).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.searchDetail()
          } else { this.$message.error('删除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    insertOne(row) {
      insertOne(row.组件工艺流水号).then(response => {})
      this.searchDetail()
    },
    update(row) {
      update(row.装配工序流水号, row.序号, row.工序名称, row.工艺内容及装配具体要求, row.质检).then(response => {
        console.log(response.data, '工艺要求修改成功', 505)
      })
    },
    deleteTable() {
      this.$confirm('此操作将永久删除该工艺, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.result = 0
        for (var i = 0; i < this.dataAll.length; i++) {
          deleteGroup(this.dataAll[i].table1[0].组件工艺流水号).then(response => {
            this.result += parseInt(response.data[0].result)
            if (this.result === this.dataAll.length) {
              this.$message.success('删除成功')
              this.searchDetail()
            } else {
              this.$message.error('删除失败')
            }
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    saveApprove() {
      if (this.checked === true) {
        saveApprove(this.machineNumberValue).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('保存成功')
            this.CraftmenValue = ''
            this.machineNumberValue = ''
            this.machineNumber = []
            this.dataAll = []
          } else { this.$message.error('保存失败') }
        })
      } else {
        this.$message.warning('请勾选是否核准')
      }
    },
    upOne(row) {
      upOne(row.装配工序流水号, row.组件工艺流水号, row.工序顺序).then(response => {})
      this.searchDetail()
    },
    downOne(row) {
      downOne(row.装配工序流水号, row.组件工艺流水号, row.工序顺序).then(response => {})
      this.searchDetail()
    },
    deleteOne(row) {
      deleteOne(row.装配工序流水号).then(response => {})
      this.searchDetail()
    },
    cChange() {
      this.processName = []
      this.processNameValue = ''
      this.Process = ''
      this.processRequestValue = ''
      initProcessName(this.processNameClassValue).then(response => { // 初始化工序分类
        this.tableData = response.data
        for (let i = 0; i < response.data.length; i++) {
          this.processName.push({
            label: response.data[i].工序名称,
            value: response.data[i].工序名称流水号
          })
        }
      })
    },
    nChange() {
      for (let i = 0; i < this.tableData.length; i++) {
        if (this.processNameValue === this.tableData[i].工序名称流水号) {
          this.Process = this.tableData[i].工序名称
          this.processRequestValue = this.tableData[i].工艺内容及装配具体要求
        }
      }
    },
    tableSearch(row) {
      this.dialogFormVisible2 = true
      this.processNameClassValue = ''
      this.processNameValue = ''
      this.processRequestValue = ''
      this.processName = []
      this.Procedure = row.装配工序流水号
      this.number = row.序号
    },
    confirmSelect() {
      console.log(this.Procedure, this.number, this.Process, this.processRequestValue)
      update1(this.Procedure, this.number, this.Process, this.processRequestValue).then(response => {
        if (response.data[0].result === '1') {
          this.dialogFormVisible2 = false
          this.$message.success('选择成功')
          this.searchDetail()
        } else {
          this.$message.success('选择失败')
        }
      })
    }
  }
}
</script>

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