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

    <el-card>
      <span>表单号:</span>
      <el-input v-model="formNumber" size="small" placeholder="表单号" clearable style="width:200px"/>
      <span>外协厂家:</span>
      <el-input v-model="manufacturers" readonly size="small" placeholder="外协厂家" style="width:250px" clearable>
        <el-button slot="append" icon="el-icon-search" @click="onFocus1();param=0"/>
      </el-input>
      <span>下达任务日期:</span>
      <el-date-picker
        v-model="time"
        type="date"
        size="small"
        placeholder="选择日期"/>
      <el-button type="success" size="mini" icon="el-icon-search" style="margin-left:10px" @click="pageSize=10;pageList=1;fetchData()">查询</el-button>
      <el-button type="primary" size="mini" icon="el-icon-circle-plus-outline" style="margin-left:10px" @click="handleAdd()">增加</el-button>
    </el-card>

    <el-card>
      <el-table v-loading="loading2" :data="List" highlight-current-row height="350" border @row-click="searchProcess" >
        <el-table-column label="单据状态" width="100" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.单据状态==='成交'" type="success" size="small">成交</el-tag>
            <el-tag v-else type="info" size="small">未成交</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="表单号" align="center" min-width="200px">
          <template slot-scope="scope">
            {{ scope.row.表单号 }}
          </template>
        </el-table-column>
        <el-table-column label="外协厂家" align="center" min-width="200px">
          <template slot-scope="scope">
            {{ scope.row.外协厂家 }}
          </template>
        </el-table-column>
        <el-table-column label="任务下达日期" align="center" min-width="100px">
          <template slot-scope="scope">
            {{ scope.row.任务下达日期 }}
          </template>
        </el-table-column>
        <el-table-column label="外协计划员" align="center" >
          <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" min-width="200px">
          <template slot-scope="scope">
            <el-button :disabled="scope.row.单据状态==='成交'" type="primary" size="mini" icon="el-icon-edit" style="margin-left:10px" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button :disabled="scope.row.单据状态==='成交'" type="danger" size="mini" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-show="!loading2"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>

    <el-card>
      <span>零件号:</span>
      <el-input v-model="partNumber" size="small" placeholder="零件号" clearable style="width:200px"/>
      <el-button type="success" size="mini" icon="el-icon-search" style="margin-left:10px" @click="getList()">查询</el-button>
      <el-table
        v-loading="loading1"
        ref="multipleTable"
        :data="List1"
        border
        highlight-current-row
        height="450"
        tooltip-effect="dark"
        style="width: 100%;margin-top: 20px"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55"/>
        <el-table-column label="项目名称" align="center" >
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" align="center" >
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center" >
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" >
          <template slot-scope="scope">
            {{ scope.row.批次数量 }}
          </template>
        </el-table-column>
        <el-table-column label="材料费" align="center" >
          <template slot-scope="scope">
            {{ scope.row.材料费 }}
          </template>
        </el-table-column>
        <el-table-column label="分类" align="center" >
          <template slot-scope="scope">
            {{ scope.row.外协分类 }}
          </template>
        </el-table-column>
        <el-table-column label="投产" align="center" >
          <template slot-scope="scope">
            {{ scope.row.传递时间_短 }}
          </template>
        </el-table-column>
        <el-table-column label="计划结束" align="center" >
          <template slot-scope="scope">
            {{ scope.row.计划结束时间_短 }}
          </template>
        </el-table-column>
        <el-table-column label="预算" align="center" >
          <template slot-scope="scope">
            {{ (scope.row.外协预算总价格).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column label="零件类型" align="center" >
          <template slot-scope="scope">
            {{ scope.row.是否临时件 }}
          </template>
        </el-table-column>
        <el-table-column label="外协工序" align="center">
          <template slot-scope="scope">
            {{ scope.row.外协工序 }}
          </template>
        </el-table-column>
      </el-table>
      <el-button type="info" size="mini" icon="el-icon-arrow-down" style="margin-left:10px;margin-top: 15px" @click="getSpareParts">选入零件</el-button>
    </el-card>

    <el-card>
      <el-table v-loading="loading" :data="List3" :summary-method="getSummaries" :row-class-name="tableRowClassName" show-summary>
        <el-table-column :index="indexMethod" label="序号" align="center" type="index" width="50px"/>
        <el-table-column label="零件图号" align="center" width="200px">
          <template slot-scope="scope">
            {{ 零件图号[scope.$index] }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center" width="180px">
          <template slot-scope="scope">
            {{ 零件名称[scope.$index] }}
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" width="100px">
          <template slot-scope="scope">
            {{ 批次数量[scope.$index] }}
          </template>
        </el-table-column>
        <!--<el-table-column label="零件工艺" align="center">-->
        <!--<el-table-column label="[1]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][0] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[2]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][1] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[3]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][2] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[4]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][3] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[5]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][4] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[6]" width="100px" align="center">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][5] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[7]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][6] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[8]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][7] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[9]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][8] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[10]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][9] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[11]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][10] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[12]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][11] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[13]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][12] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[14]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][13] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[15]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][14] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[16]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][15] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[17]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][16] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[18]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][17] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[19]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][18] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--<el-table-column label="[20]" align="center" width="100px">-->
        <!--<template slot-scope="scope">-->
        <!--{{ process[scope.$index][19] }}-->
        <!--</template>-->
        <!--</el-table-column>-->
        <!--</el-table-column>-->
        <el-table-column label="加工价格" align="center">
          <el-table-column label="预算" align="center" width="130px">
            <template slot-scope="scope">
              {{ 外协预算总价格[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="成交" align="center" width="130px">
            <template slot-scope="scope">
              <el-input v-model="加工价格_成交[scope.$index]"/>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="材料价格" align="center">
          <el-table-column label="类别" align="center" width="130px">
            <template slot-scope="scope">
              {{ 外协分类[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="预算" align="center" width="130px">
            <template slot-scope="scope">
              {{ 材料费[scope.$index] }}
            </template>
          </el-table-column>
          <el-table-column label="成交" align="center" width="130px">
            <template slot-scope="scope">
              <el-input v-model="材料价格_价格[scope.$index]"/>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="其他价格" align="center" width="120px">
          <template slot-scope="scope">
            <el-input v-model="其他价格[scope.$index]"/>
          </template>
        </el-table-column>
        <el-table-column label="计划要求" align="center" width="100px">
          <el-table-column label="开始" align="center" width="100px">
            <template slot-scope="scope">
              {{ (机加工开始时间[scope.$index]) }}
            </template>
          </el-table-column>
          <el-table-column label="结束" align="center" width="100px">
            <template slot-scope="scope">
              {{ (机加工结束时间[scope.$index]) }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              @click="handleDelete1(scope.$index)">移除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div>
        <span>下调金额:（百分比）</span>
        <el-input v-model="money" size="small" clearable style="width:200px"/>
        <el-button type="success" size="mini" icon="el-icon-edit" style="margin-left:10px;margin-top: 15px" @click="calculatingPrice">计算价格</el-button>
        <el-button type="success" size="mini" icon="el-icon-edit" style="margin-left:10px;margin-top: 15px" @click="confirmPrice">确定价格</el-button>
        <el-button type="success" size="mini" icon="el-icon-success" style="margin-left:10px;margin-top: 15px" @click="Deal">成交</el-button>
        <el-button type="primary" size="mini" icon="el-icon-download" style="margin-left:10px;margin-top: 15px" @click="downLoadRWD('RWD')">导出外协加工任务单</el-button>
      </div>
    </el-card>

    <el-card v-show="card">
      <table id="RWD" cellspacing="0px" align="center" width="100%" style="">
        <tbody id="1">
          <tr>
            <td colspan="4" style="text-align: left;font-size: 30px;font-weight: bold">GAOJING</td>
            <td colspan="24" style="text-align:center;font-size: 30px;font-weight: bold">外协加工任务单</td>
          </tr>
          <tr class="tbodyHead">
            <td colspan="2">任务单号:</td>
            <td colspan="6">{{ 任务单号 }}</td>
            <td colspan="4">任务下达日期:</td>
            <td colspan="4">{{ 任务下达日期 }}</td>
            <td colspan="3">外协厂家:</td>
            <td colspan="9">{{ 外协厂家 }}</td>
          </tr>
          <tr class="tbodyHead">
            <td colspan="2">外协员:</td>
            <td colspan="6">{{ 外协员 }}</td>
            <td colspan="2">电话:</td>
            <td colspan="6">{{ 外协员电话 }}</td>
            <td colspan="3">联系人:</td>
            <td colspan="3">{{ 联系人 }}</td>
            <td colspan="2">电话:</td>
            <td colspan="4">{{ 联系人电话 }}</td>
          </tr>
          <tr id="tableHead">
            <td style="width: 2%">序号</td>
            <td colspan="5">零件图号</td>
            <td colspan="2" style="width: 4%">零件名称</td>
            <td colspan="2" style="width: 2%">数量</td>
            <td colspan="9" width="30%">内容</td>
            <td colspan="1">零件类型</td>
            <td>外协类别</td>
            <td>加工价格</td>
            <td>材料价格</td>
            <td>其他价格</td>
            <td colspan="2">计划开始</td>
            <td colspan="2">计划结束</td>
          </tr>

        </tbody>
        <tfoot>
          <tr id="tableFoot">
            <td>费用</td>
            <td colspan="17" style="text-align: left;">加工费：￥{{ 加工价格合计 }}元；材料费：￥{{ 材料价格合计 }}元；其他费用：￥{{ 其他价格合计 }}元；运费￥{{ 运费 }}元；合计：￥{{ 总计 }}元；人民币大写：{{ 大写金额 }}</td>
            <td colspan="1">0</td>
            <td colspan="1"/>
            <td/>
            <td>{{ 加工价格合计 }}</td>
            <td>{{ 材料价格合计 }}</td>
            <td>{{ 其他价格合计 }}</td>
            <td colspan="2">{{ 最早时间 }}</td>
            <td colspan="2">{{ 最晚时间 }}</td>
          </tr>
          <tr class="foot">
            <td colspan="4">外协员:</td>
            <td colspan="4">外协科长:</td>
            <td colspan="4">采购二部长:</td>
            <td colspan="4">制品部长:</td>
            <td colspan="4">定额科统计员:</td>
            <td colspan="4">定额科长:</td>
            <td colspan="4">外协厂:</td>
          </tr>
        </tfoot>
      </table>
    </el-card>

    <el-dialog :visible.sync="dialogFormVisible1" title="外协厂家" center width="500px" height="600px">
      <div align="center">
        <el-input v-model="input" size="small" style="width:200px"/>
        <el-button type="success" size="mini" icon="el-icon-search" style="margin-left:10px" @click="searchData()">查询</el-button>
      </div>
      <el-table :data="List2" max-height="370" highlight-current-row @row-click="handleCurrentChange3">
        <el-table-column label="外协厂家" align="center" >
          <template slot-scope="scope">
            {{ scope.row.外协厂家名称 }}
          </template>
        </el-table-column>
      </el-table>
      <div align="center" style="margin-top: 10px">
        <el-button type="warning" size="small" icon="el-icon-edit-outline" @click="submit1">提交</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="dialogFormVisible" center style="min-height: 300px" width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-position="left" label-width="110px" class="demo-ruleForm">
        <el-form-item label="表单号" prop="表单号" style="margin-left: 200px">
          <el-input v-model="form.表单号" placeholder="表单号" size="small" style="width:200px" disabled/>
        </el-form-item>
        <el-form-item label="下达任务日期" prop="下达任务日期" style="margin-left: 200px">
          <el-date-picker
            v-model="form.下达任务日期"
            type="date"
            size="small"
            style="width:200px"
            disabled
            default-value
            placeholder="下达任务日期"
            value-format="yyyy-MM-dd"/>
        </el-form-item>
        <el-form-item label="外协厂家" prop="外协厂家" style="margin-left: 200px">
          <el-input v-model="form.外协厂家" readonly placeholder="外协厂家" size="small" style="width:200px" clearable>
            <el-button slot="append" icon="el-icon-search" @click="onFocus1();param=1"/>
          </el-input>
        </el-form-item>
        <el-form-item label="运费" prop="运费" style="margin-left: 200px">
          <el-input v-model="form.运费" placeholder="运费" size="small" style="width:200px" clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff('form')">取消</el-button>
        <el-button type="primary" @click="submit('form')">确定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getTable, getData1, getTable1, getprocedure, searchManufactor, spareParts, addTable, editData, deleteData, insertParts, getParts, getPrice, editData1, deleteData1, getNumber } from '@/api/Outsourcing/OutsourcingTaskExecution'
import { getExplorer, method5, Cleanup } from '@/vendor/exportExcel'
import { convertCurrency } from '@/vendor/int2Chinese'
import { mapGetters } from 'vuex'
import elInput from 'element-ui/packages/input'

export default {
  components: {
    elInput
  },
  data() {
    return {
      bianliang: [],
      card: false,
      费用: '',
      加工价格合计: 0,
      材料价格合计: 0,
      其他价格合计: 0,
      运费: 0,
      总计: 0,
      大写金额: '',
      任务单号: '',
      任务下达日期: '',
      外协厂家: '',
      外协员: '',
      外协员电话: '',
      联系人: '',
      联系人电话: '',
      最早时间: '',
      最晚时间: '',
      // 以上是新增的
      loading: false,
      loading1: false,
      loading2: false,
      num: null,
      num1: null,
      num2: null,
      name1: '',
      time: '',
      time1: '',
      time2: '',
      input: '',
      contrast: 3000000000000,
      contrast1: 0,
      param: 0,
      partNumber: '',
      processingPrice: null,
      materialPrice: null,
      formNumber: '',
      coOperationProcess: [],
      ManufactorNumber: null,
      ManufactorNumber1: null,
      manufacturers: '',
      dialogFormVisible: false,
      dialogFormVisible1: false,
      data2: [],
      List: [],
      money: null,
      sum: 0,
      num10: [],
      title: '',
      result: 0,
      documentStatus: null,
      sign: null,
      Number: null,
      form: {
        表单号: '',
        下达任务日期: '',
        外协厂家: '',
        运费: null
      },
      rules: {
        外协厂家: [{ required: true, message: '请选择外协厂家', trigger: 'change' }],
        运费: [{ required: true, message: '请输入运费', trigger: 'blur' }]
      },
      code: 0,
      code1: 0,
      processNum: [],
      single: null,
      procedure: [],
      List1: [],
      List2: [],
      List3: [],
      Explain: '',
      freight: null,
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      process: [[]],
      returns: [],
      零件图号: [],
      零件名称: [],
      批次数量: [],
      外协预算总价格: [],
      加工价格_成交: [],
      外协分类: [],
      材料费: [],
      材料价格_价格: [],
      其他价格: [],
      机加工开始时间: [],
      机加工结束时间: [],
      外协加工任务单明细流水号: [],
      total: null, // 总条数
      pageSize: 10, // 每页显示条数
      pageList: 1, // 后台获取页
      currentPage: 1 // 显示当前页
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id'
    ])
  },
  created() {
    this.fetchData()
    this.getList()
  },
  methods: {
    fetchData() {
      this.loading2 = true
      var day3 = new Date(this.time)
      var day4 = new Date(this.time)
      day3.setTime(day3.getTime() - 24 * 60 * 60 * 1000)
      day4.setTime(day4.getTime() + 24 * 60 * 60 * 1000)
      var month1 = day3.getMonth() + 1
      var month2 = day4.getMonth() + 1
      var day1 = day3.getDate()
      var day2 = day4.getDate()
      if (month1 >= 1 && month1 <= 9) {
        month1 = '0' + month1
      }
      if (day1 >= 1 && day1 <= 9) {
        day1 = '0' + day1
      }
      if (month2 >= 1 && month2 <= 9) {
        month2 = '0' + month2
      }
      if (day2 >= 1 && day2 <= 9) {
        day2 = '0' + day2
      }
      this.time1 = day3.getFullYear() + '/' + month1 + '/' + day1
      this.time2 = day4.getFullYear() + '/' + month2 + '/' + day2
      if (this.formNumber !== '') {
        this.num = 1
      } else {
        this.num = 0
      }
      if (this.manufacturers !== '') {
        this.num1 = 1
      } else {
        this.num1 = 0
      }
      if (this.time === '' || this.time === null) {
        this.num2 = 0
      } else {
        this.num2 = 1
      }
      if (this.time1 === 'NaN/NaN/NaN') {
        this.time1 = ''
      }
      if (this.time2 === 'NaN/NaN/NaN') {
        this.time2 = ''
      }
      this.List = []
      this.List3 = []
      getTable(this.num, this.formNumber, this.num1, this.ManufactorNumber, this.num2, this.time1, this.time2, this.id, this.pageList, this.pageSize).then(response => {
        this.total = parseInt(response.data.total)
        for (let i = 0; i < response.data.rows.length; i++) {
          if (response.data.rows[i].任务下达日期 !== null) {
            response.data.rows[i].任务下达日期 = response.data.rows[i].任务下达日期.substr(0, 10)
          }
        }
        this.List = response.data.rows
      })
      this.loading2 = false
    },
    // 查询
    searchProcess(row) {
      this.任务单号 = row.表单号
      this.任务下达日期 = row.任务下达日期
      this.外协厂家 = row.外协厂家
      this.外协员 = row.外协计划员
      // 以上是新增的
      this.contrast = 3000000000000
      this.contrast1 = 0
      this.loading = true
      this.List3 = []
      this.bianliang = []
      this.零件图号 = []
      this.零件名称 = []
      this.批次数量 = []
      this.外协预算总价格 = []
      this.加工价格_成交 = []
      this.外协分类 = []
      this.材料费 = []
      this.材料价格_价格 = []
      this.其他价格 = []
      this.机加工开始时间 = []
      this.机加工结束时间 = []
      this.外协加工任务单明细流水号 = []
      this.process = []
      this.freight = row.运费
      this.ManufactorNumber = row.外协厂家流水号
      this.Number = row.外协加工任务单流水号
      getParts(this.Number).then(response => {
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          data[i].差价 = data[i].外协预算总价格 * 1.15.toFixed(2) + data[i].材料费 * 1.15.toFixed(2) - data[i].加工价格_成交.toFixed(2) - data[i].材料价格_价格.toFixed(2) - data[i].其他价格.toFixed(2)
        }
        this.returns = data
        this.List3 = data
        this.加工价格合计 = 0
        this.材料价格合计 = 0
        this.其他价格合计 = 0
        if (response.data.length !== 0) {
          this.外协员电话 = response.data[0].联系电话
          this.联系人 = response.data[0].联系人
          this.联系人电话 = response.data[0].电话
          this.运费 = response.data[0].运费
          this.card = true
        } else {
          this.card = false
        }
        const children = document.getElementsByClassName('tableData')
        const parent = document.getElementById('1')
        if (children.length !== 0) {
          for (let i = children.length - 1; i >= 0; i--) {
            parent.removeChild(children[i])
          }
        }
        const tr = []
        for (let i = 0; i < this.returns.length; i++) {
          tr[i] = document.createElement('tr')
          tr[i].setAttribute('class', 'tableData')
          tr[i].innerHTML = '<td></td>' + '<td colspan="5"></td>' + '<td colspan="2"></td>' + '<td colspan="2"></td>' +
              '<td colspan="9" style="text-align: left;"></td>' + '<td colspan="1"></td>' + '<td></td><td></td><td></td><td></td><td colspan="2"></td><td colspan="2"></td>'
          document.getElementById('tableHead').after(tr[i])
        }
        for (let j = 0; j < this.returns.length; j++) {
          document.getElementsByClassName('tableData')[j].children[0].innerHTML = j + 1
          document.getElementsByClassName('tableData')[j].children[1].innerHTML = response.data[j].零件图号
          document.getElementsByClassName('tableData')[j].children[2].innerHTML = response.data[j].零件名称
          document.getElementsByClassName('tableData')[j].children[3].innerHTML = response.data[j].批次数量
          document.getElementsByClassName('tableData')[j].children[4].innerHTML = ''
          document.getElementsByClassName('tableData')[j].children[5].innerHTML = response.data[j].是否临时件1
          document.getElementsByClassName('tableData')[j].children[6].innerHTML = response.data[j].外协分类
          document.getElementsByClassName('tableData')[j].children[7].innerHTML = parseInt(response.data[j].加工价格_成交.toFixed(2))
          document.getElementsByClassName('tableData')[j].children[8].innerHTML = parseInt(response.data[j].材料价格_价格.toFixed(2))
          document.getElementsByClassName('tableData')[j].children[9].innerHTML = parseInt(response.data[j].其他价格.toFixed(2))
          if (response.data[j].机加工开始时间 !== null) {
            document.getElementsByClassName('tableData')[j].children[10].innerHTML = response.data[j].机加工开始时间.substr(0, 10)
          }
          if (response.data[j].机加工结束时间 !== null) {
            document.getElementsByClassName('tableData')[j].children[11].innerHTML = response.data[j].机加工结束时间.substr(0, 10)
          }
          this.加工价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[7].innerHTML)
          this.材料价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[8].innerHTML)
          this.其他价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[9].innerHTML)
        }
        this.总计 = this.加工价格合计 + this.材料价格合计 + this.其他价格合计 + this.运费
        this.大写金额 = convertCurrency(this.总计)
        // RWD end
        if (response.data.length === 0) {
          this.loading = false
        }
        for (let i = 0; i < response.data.length; i++) { // 声明二维数组
          this.零件图号.push(response.data[i].零件图号)
          this.零件名称.push(response.data[i].零件名称)
          this.批次数量.push(response.data[i].批次数量)
          this.外协预算总价格.push(response.data[i].外协预算总价格.toFixed(2))
          this.加工价格_成交.push(response.data[i].加工价格_成交.toFixed(2))
          this.外协分类.push(response.data[i].外协分类)
          this.材料费.push(response.data[i].材料费.toFixed(2))
          this.材料价格_价格.push(response.data[i].材料价格_价格.toFixed(2))
          this.其他价格.push(response.data[i].其他价格.toFixed(2))
          if (response.data[i].机加工开始时间 !== null) {
            this.机加工开始时间.push(response.data[i].机加工开始时间.substr(0, 10))
          } else {
            this.机加工开始时间.push(' ')
          }
          if (response.data[i].机加工结束时间 !== null) {
            this.机加工结束时间.push(response.data[i].机加工结束时间.substr(0, 10))
          } else {
            this.机加工结束时间.push(' ')
          }
          this.外协加工任务单明细流水号.push(response.data[i].外协加工任务单明细流水号)
          this.process[i] = []
        }
        for (let i = 0; i < this.returns.length; i++) {
          spareParts(this.returns[i].工艺计划流水号, this.returns[i].单件是否外协).then(response => {
            for (let k = 0; k < response.data.length; k++) {
              this.process[i][k] = response.data[k].工艺名称简称
              document.getElementsByClassName('tableData')[i].children[4].innerHTML += response.data[k].工艺名称简称 + '/'
            }
          }).then(() => {
            // this.bianliang.push(this.returns[i])
          })
        }
      }).then(() => {
        // this.List3 = this.bianliang
        this.loading = false
      })
    },
    callOff(formName) {
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.title === '增加') {
            this.submitAdd()
            this.title = ''
          } else if (this.title === '编辑') {
            this.submitEdit()
            this.title = ''
          }
        }
      })
    },
    handleAdd() {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '增加'
      this.dialogFormVisible = true
      var time = new Date()
      var month = time.getMonth() + 1
      var day = time.getDate()
      if (month >= 1 && month <= 9) {
        month = '0' + month
      }
      if (day >= 1 && day <= 9) {
        day = '0' + day
      }
      this.form.下达任务日期 = time.getFullYear() + '/' + month + '/' + day
      getNumber(this.form.下达任务日期).then(response => {
        this.form.表单号 = response.data.result[0].Column1
      })
      this.form.运费 = null
      this.form.外协厂家 = ''
    },
    submitAdd() {
      addTable(this.form.表单号, this.id, this.ManufactorNumber1, this.form.下达任务日期, this.form.运费).then(response => {
        if (response.data[0].result === '1') {
          this.$notify({
            title: '成功',
            message: '信息添加成功',
            type: 'success'
          })
          this.dialogFormVisible = false
          this.fetchData()
        } else {
          this.$message.error('信息添加失败')
        }
      })
    },
    getList() {
      if (this.partNumber !== '') {
        this.check = 1
      } else {
        this.check = 0
      }
      this.loading1 = true
      getTable1(this.check, this.partNumber).then(response => {
        this.List1 = []
        for (let j = 0; j < response.data.length; j++) {
          this.List1.push({
            项目名称: response.data[j].项目名称,
            零件图号: response.data[j].零件图号,
            零件名称: response.data[j].零件名称,
            批次数量: response.data[j].批次数量,
            加工价格_成交: response.data[j].加工价格_成交,
            材料价格_价格: response.data[j].材料价格_价格,
            其他价格: response.data[j].其他价格,
            材料费: response.data[j].材料费,
            外协分类: response.data[j].外协分类,
            外协预算总价格: response.data[j].外协预算总价格,
            传递时间_短: response.data[j].传递时间_短,
            计划结束时间_短: response.data[j].计划结束时间_短,
            是否临时件: response.data[j].是否临时件,
            工艺计划流水号: response.data[j].工艺计划流水号,
            单件是否外协: response.data[j].单件是否外协,
            外协工序: ''
          })
        }
        this.loading1 = false
        this.getProcedure(this.List1)
      })
    },
    getProcedure(row) {
      for (let i = 0; i < row.length; i++) {
        getprocedure(row[i].工艺计划流水号, row[i].单件是否外协).then(response => {
          this.procedure[i] = ''
          for (let j = 0; j < response.data.length; j++) {
            this.procedure[i] = this.procedure[i] + ' ' + response.data[j].工艺名称简称
          }
          this.List1[i].外协工序 = this.procedure[i]
        })
      }
    },
    onFocus1() {
      this.dialogFormVisible1 = true
      this.input = ''
      getData1().then(response => {
        this.List2 = response.data
      })
    },
    handleCurrentChange3(row) {
      if (this.param === 0) {
        this.name1 = row.外协厂家名称
        this.ManufactorNumber = row.外协厂家流水号
      } else {
        this.form.外协厂家 = row.外协厂家名称
        this.ManufactorNumber1 = row.外协厂家流水号
      }
    },
    submit1() {
      this.dialogFormVisible1 = false
      this.manufacturers = this.name1
    },
    getSummaries(param) {
      const { data } = param
      const sums = ['', '', '', 0, '', 0, '', 0, '', 0, '', 0, '', '', '', '', '', '', '', '', '', '', '', '', 0, 0, '', 0, 0, 0, '', '']
      sums[1] = '费用'
      sums[2] = '加工费:'
      sums[4] = '材料费:'
      sums[6] = '其他费用:'
      sums[8] = '运费:'
      sums[9] = parseInt(this.freight)
      sums[10] = '合计:'
      for (let i = 0; i < data.length; i++) {
        sums[24] += Math.round(parseFloat(data[i].外协预算总价格) * 100) / 100
      }
      sums[24] = Math.round(sums[24] * 100) / 100
      for (let i = 0; i < data.length; i++) {
        sums[25] += Math.round(parseFloat(data[i].加工价格_成交) * 100) / 100
      }
      sums[25] = Math.round(sums[25] * 100) / 100
      for (let i = 0; i < data.length; i++) {
        sums[27] += Math.round(parseFloat(data[i].材料费) * 100) / 100
      }
      sums[27] = Math.round(sums[27] * 100) / 100
      for (let i = 0; i < data.length; i++) {
        sums[28] += Math.round(parseFloat(data[i].材料价格_价格) * 100) / 100
      }
      sums[28] = Math.round(sums[28] * 100) / 100
      for (let i = 0; i < data.length; i++) {
        sums[29] += Math.round(parseFloat(data[i].其他价格) * 100) / 100
      }
      sums[29] = Math.round(sums[29] * 100) / 100
      for (let i = 0; i < data.length; i++) {
        if (data[i].机加工开始时间 !== null) {
          if (Date.parse(data[i].机加工开始时间) <= this.contrast) {
            this.contrast = Date.parse(data[i].机加工开始时间)
            sums[30] = data[i].机加工开始时间.substr(0, 10)
            this.最早时间 = data[i].机加工开始时间.substr(0, 10)
          }
        }
      }
      for (let i = 0; i < data.length; i++) {
        if (data[i].机加工结束时间 !== null) {
          if (Date.parse(data[i].机加工结束时间) >= this.contrast1) {
            this.contrast1 = Date.parse(data[i].机加工结束时间)
            sums[31] = data[i].机加工结束时间.substr(0, 10)
            this.最晚时间 = data[i].机加工结束时间.substr(0, 10)
          }
        }
      }
      sums[3] = sums[25]
      sums[5] = sums[28]
      sums[7] = sums[29]
      sums[11] = Math.round((sums[3] + sums[5] + sums[7] + sums[9]) * 100) / 100
      sums[26] = '---'
      return sums
    },
    // 计算价格
    calculatingPrice() {
      this.code = 0
      for (let i = 0; i < this.List3.length; i++) {
        this.加工价格_成交[i] = (this.外协预算总价格[i] * (1 - this.money / 100)).toFixed(2)
        getPrice(this.外协加工任务单明细流水号[i], this.外协预算总价格[i], this.加工价格_成交[i], this.材料价格_价格[i], this.其他价格[i]).then(response => {
          this.code = this.code + parseInt(response.data[0].result)
          if (this.code === this.List3.length) {
            this.contrast = 3000000000000
            this.contrast1 = 0
            this.loading = true
            this.List3 = []
            this.零件图号 = []
            this.零件名称 = []
            this.批次数量 = []
            this.外协预算总价格 = []
            this.加工价格_成交 = []
            this.外协分类 = []
            this.材料费 = []
            this.材料价格_价格 = []
            this.其他价格 = []
            this.机加工开始时间 = []
            this.机加工结束时间 = []
            this.外协加工任务单明细流水号 = []
            this.process = []
            getParts(this.Number).then(response => {
              const data = response.data
              for (let i = 0; i < data.length; i++) {
                data[i].差价 = data[i].外协预算总价格 * 1.15.toFixed(2) + data[i].材料费 * 1.15.toFixed(2) - data[i].加工价格_成交.toFixed(2) - data[i].材料价格_价格.toFixed(2) - data[i].其他价格.toFixed(2)
              }
              this.returns = data
              this.加工价格合计 = 0
              this.材料价格合计 = 0
              this.其他价格合计 = 0
              if (response.data.length !== 0) {
                this.外协员电话 = response.data[0].联系电话
                this.联系人 = response.data[0].联系人
                this.联系人电话 = response.data[0].电话
                this.运费 = response.data[0].运费
                this.card = true
              } else {
                this.card = false
              }
              const children = document.getElementsByClassName('tableData')
              const parent = document.getElementById('1')
              if (children.length !== 0) {
                for (let i = children.length - 1; i >= 0; i--) {
                  parent.removeChild(children[i])
                }
              }
              const tr = []
              for (let i = 0; i < this.returns.length; i++) {
                tr[i] = document.createElement('tr')
                tr[i].setAttribute('class', 'tableData')
                tr[i].innerHTML = '<td></td>' + '<td colspan="5"></td>' + '<td colspan="2"></td>' + '<td colspan="2"></td>' +
                    '<td colspan="9" style="text-align: left;"></td>' + '<td colspan="1"></td>' + '<td></td><td></td><td></td><td></td><td colspan="2"></td><td colspan="2"></td>'
                document.getElementById('tableHead').after(tr[i])
              }
              for (let j = 0; j < this.returns.length; j++) {
                document.getElementsByClassName('tableData')[j].children[0].innerHTML = j + 1
                document.getElementsByClassName('tableData')[j].children[1].innerHTML = response.data[j].零件图号
                document.getElementsByClassName('tableData')[j].children[2].innerHTML = response.data[j].零件名称
                document.getElementsByClassName('tableData')[j].children[3].innerHTML = response.data[j].批次数量
                document.getElementsByClassName('tableData')[j].children[4].innerHTML = ''
                document.getElementsByClassName('tableData')[j].children[5].innerHTML = response.data[j].是否临时件1
                document.getElementsByClassName('tableData')[j].children[6].innerHTML = response.data[j].外协分类
                document.getElementsByClassName('tableData')[j].children[7].innerHTML = parseInt(response.data[j].加工价格_成交.toFixed(2))
                document.getElementsByClassName('tableData')[j].children[8].innerHTML = parseInt(response.data[j].材料价格_价格.toFixed(2))
                document.getElementsByClassName('tableData')[j].children[9].innerHTML = parseInt(response.data[j].其他价格.toFixed(2))
                if (response.data[j].机加工开始时间 !== null) {
                  document.getElementsByClassName('tableData')[j].children[10].innerHTML = response.data[j].机加工开始时间.substr(0, 10)
                }
                if (response.data[j].机加工结束时间 !== null) {
                  document.getElementsByClassName('tableData')[j].children[11].innerHTML = response.data[j].机加工结束时间.substr(0, 10)
                }
                this.加工价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[7].innerHTML)
                this.材料价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[8].innerHTML)
                this.其他价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[9].innerHTML)
              }
              this.总计 = this.加工价格合计 + this.材料价格合计 + this.其他价格合计 + this.运费
              this.大写金额 = convertCurrency(this.总计)
              if (response.data.length === 0) {
                this.loading = false
              }
              // RWD end
              if (response.data.length === 0) {
                this.loading = false
              }
              for (let i = 0; i < response.data.length; i++) { // 声明二维数组
                this.零件图号.push(response.data[i].零件图号)
                this.零件名称.push(response.data[i].零件名称)
                this.批次数量.push(response.data[i].批次数量)
                this.外协预算总价格.push(response.data[i].外协预算总价格.toFixed(2))
                this.加工价格_成交.push(response.data[i].加工价格_成交.toFixed(2))
                this.外协分类.push(response.data[i].外协分类)
                this.材料费.push(response.data[i].材料费.toFixed(2))
                this.材料价格_价格.push(response.data[i].材料价格_价格.toFixed(2))
                this.其他价格.push(response.data[i].其他价格.toFixed(2))
                if (response.data[i].机加工开始时间 !== null) {
                  this.机加工开始时间.push(response.data[i].机加工开始时间.substr(0, 10))
                } else {
                  this.机加工开始时间.push(' ')
                }
                if (response.data[i].机加工结束时间 !== null) {
                  this.机加工结束时间.push(response.data[i].机加工结束时间.substr(0, 10))
                } else {
                  this.机加工结束时间.push(' ')
                }
                this.外协加工任务单明细流水号.push(response.data[i].外协加工任务单明细流水号)
                this.process[i] = []
              }
              for (let i = 0; i < this.returns.length; i++) {
                spareParts(this.returns[i].工艺计划流水号, this.returns[i].单件是否外协).then(response => {
                  for (let k = 0; k < response.data.length; k++) { // 执行n次2
                    this.process[i].push(response.data[k].工艺名称简称)
                    document.getElementsByClassName('tableData')[i].children[4].innerHTML += response.data[k].工艺名称简称 + '/'
                  }
                }).then(() => {
                  this.List3 = this.returns
                  this.money = null
                  this.loading = false
                })
              }
            })
          }
        })
      }
    },
    // 确定价格
    confirmPrice() {
      this.code1 = 0
      for (let i = 0; i < this.List3.length; i++) {
        getPrice(this.外协加工任务单明细流水号[i], this.外协预算总价格[i], this.加工价格_成交[i], this.材料价格_价格[i], this.其他价格[i]).then(response => {
          this.code1 = this.code1 + parseInt(response.data[0].result)
          if (this.code1 === this.List3.length) {
            this.contrast = 3000000000000
            this.contrast1 = 0
            this.loading = true
            this.List3 = []
            this.零件图号 = []
            this.零件名称 = []
            this.批次数量 = []
            this.外协预算总价格 = []
            this.加工价格_成交 = []
            this.外协分类 = []
            this.材料费 = []
            this.材料价格_价格 = []
            this.其他价格 = []
            this.机加工开始时间 = []
            this.机加工结束时间 = []
            this.外协加工任务单明细流水号 = []
            this.process = []
            getParts(this.Number).then(response => {
              const data = response.data
              for (let i = 0; i < data.length; i++) {
                data[i].差价 = data[i].外协预算总价格 * 1.15.toFixed(2) + data[i].材料费 * 1.15.toFixed(2) - data[i].加工价格_成交.toFixed(2) - data[i].材料价格_价格.toFixed(2) - data[i].其他价格.toFixed(2)
              }
              this.returns = data
              this.加工价格合计 = 0
              this.材料价格合计 = 0
              this.其他价格合计 = 0
              if (response.data.length !== 0) {
                this.外协员电话 = response.data[0].联系电话
                this.联系人 = response.data[0].联系人
                this.联系人电话 = response.data[0].电话
                this.运费 = response.data[0].运费
                this.card = true
              } else {
                this.card = false
              }
              const children = document.getElementsByClassName('tableData')
              const parent = document.getElementById('1')
              if (children.length !== 0) {
                for (let i = children.length - 1; i >= 0; i--) {
                  parent.removeChild(children[i])
                }
              }
              const tr = []
              for (let i = 0; i < this.returns.length; i++) {
                tr[i] = document.createElement('tr')
                tr[i].setAttribute('class', 'tableData')
                tr[i].innerHTML = '<td></td>' + '<td colspan="5"></td>' + '<td colspan="2"></td>' + '<td colspan="2"></td>' +
                    '<td colspan="9" style="text-align: left;"></td>' + '<td colspan="1"></td>' + '<td></td><td></td><td></td><td></td><td colspan="2"></td><td colspan="2"></td>'
                document.getElementById('tableHead').after(tr[i])
              }
              for (let j = 0; j < this.returns.length; j++) {
                document.getElementsByClassName('tableData')[j].children[0].innerHTML = j + 1
                document.getElementsByClassName('tableData')[j].children[1].innerHTML = response.data[j].零件图号
                document.getElementsByClassName('tableData')[j].children[2].innerHTML = response.data[j].零件名称
                document.getElementsByClassName('tableData')[j].children[3].innerHTML = response.data[j].批次数量
                document.getElementsByClassName('tableData')[j].children[4].innerHTML = ''
                document.getElementsByClassName('tableData')[j].children[5].innerHTML = response.data[j].是否临时件1
                document.getElementsByClassName('tableData')[j].children[6].innerHTML = response.data[j].外协分类
                document.getElementsByClassName('tableData')[j].children[7].innerHTML = parseInt(response.data[j].加工价格_成交.toFixed(2))
                document.getElementsByClassName('tableData')[j].children[8].innerHTML = parseInt(response.data[j].材料价格_价格.toFixed(2))
                document.getElementsByClassName('tableData')[j].children[9].innerHTML = parseInt(response.data[j].其他价格.toFixed(2))
                if (response.data[j].机加工开始时间 !== null) {
                  document.getElementsByClassName('tableData')[j].children[10].innerHTML = response.data[j].机加工开始时间.substr(0, 10)
                }
                if (response.data[j].机加工结束时间 !== null) {
                  document.getElementsByClassName('tableData')[j].children[11].innerHTML = response.data[j].机加工结束时间.substr(0, 10)
                }
                this.加工价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[7].innerHTML)
                this.材料价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[8].innerHTML)
                this.其他价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[9].innerHTML)
              }
              this.总计 = this.加工价格合计 + this.材料价格合计 + this.其他价格合计 + this.运费
              this.大写金额 = convertCurrency(this.总计)
              // RWD end
              if (response.data.length === 0) {
                this.loading = false
              }
              for (let i = 0; i < response.data.length; i++) { // 声明二维数组
                this.零件图号.push(response.data[i].零件图号)
                this.零件名称.push(response.data[i].零件名称)
                this.批次数量.push(response.data[i].批次数量)
                this.外协预算总价格.push(response.data[i].外协预算总价格.toFixed(2))
                this.加工价格_成交.push(response.data[i].加工价格_成交.toFixed(2))
                this.外协分类.push(response.data[i].外协分类)
                this.材料费.push(response.data[i].材料费.toFixed(2))
                this.材料价格_价格.push(response.data[i].材料价格_价格.toFixed(2))
                this.其他价格.push(response.data[i].其他价格.toFixed(2))
                if (response.data[i].机加工开始时间 !== null) {
                  this.机加工开始时间.push(response.data[i].机加工开始时间.substr(0, 10))
                } else {
                  this.机加工开始时间.push(' ')
                }
                if (response.data[i].机加工结束时间 !== null) {
                  this.机加工结束时间.push(response.data[i].机加工结束时间.substr(0, 10))
                } else {
                  this.机加工结束时间.push(' ')
                }
                this.外协加工任务单明细流水号.push(response.data[i].外协加工任务单明细流水号)
                this.process[i] = []
              }
              for (let i = 0; i < this.returns.length; i++) {
                spareParts(this.returns[i].工艺计划流水号, this.returns[i].单件是否外协).then(response => {
                  for (let k = 0; k < response.data.length; k++) { // 执行n次2
                    this.process[i].push(response.data[k].工艺名称简称)
                    document.getElementsByClassName('tableData')[i].children[4].innerHTML += response.data[k].工艺名称简称 + '/'
                  }
                }).then(() => {
                  this.List3 = this.returns
                  this.loading = false
                })
              }
            })
          }
        })
      }
    },
    // 成交
    Deal() {
      this.documentStatus = 2
      this.sign = 1
      this.$confirm('成交后单据不可修改, 确定成交吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        editData1(this.Number, this.ManufactorNumber, this.freight, this.documentStatus, this.sign, this.Explain).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('提交成功')
            this.fetchData()
            this.List3 = []
            this.零件图号 = []
            this.零件名称 = []
            this.批次数量 = []
            this.外协预算总价格 = []
            this.加工价格_成交 = []
            this.外协分类 = []
            this.材料费 = []
            this.材料价格_价格 = []
            this.其他价格 = []
            this.机加工开始时间 = []
            this.机加工结束时间 = []
            this.外协加工任务单明细流水号 = []
            this.process = []
            this.card = false
          } else { this.$message.error('提交失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交'
        })
      })
    },
    handleEdit(row) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '编辑'
      this.dialogFormVisible = true
      this.form.表单号 = row.表单号
      this.form.运费 = row.运费
      this.form.外协厂家 = row.外协厂家
      this.form.下达任务日期 = row.任务下达日期
      this.ManufactorNumber1 = row.外协厂家流水号
      this.Number = row.外协加工任务单流水号
      if (row.入库标志 === null) {
        this.sign = 1
      }
      if (row.单据状态 === '未成交') {
        this.documentStatus = 1
      } else {
        this.documentStatus = 2
      }
    },
    // 提交编辑
    submitEdit() {
      editData(this.Number, this.ManufactorNumber1, this.form.运费, this.documentStatus, 1, this.Explain).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('编辑成功')
          this.dialogFormVisible = false
          this.fetchData()
        } else { this.$message.error('编辑失败') }
      })
    },
    handleDelete(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteData(row.外协加工任务单流水号).then(response => {
          if (response.data[0].result === '1') {
            if (this.List && this.List.length === 1 && this.pageList > 1) { // 判断删除的是否是最后一页最后一行，如果是且不是第一页，页数减一
              this.pageList--
            }
            this.$message.success('删除成功')
            this.fetchData()
            this.getList()
            this.card = false
          } else { this.$message.error('删除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleDelete1(index) {
      this.$confirm('此操作将移除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteData1(this.外协加工任务单明细流水号[index]).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('移除成功')
            this.getList()
            this.contrast = 3000000000000
            this.contrast1 = 0
            this.loading = true
            this.List3 = []
            this.零件图号 = []
            this.零件名称 = []
            this.批次数量 = []
            this.外协预算总价格 = []
            this.加工价格_成交 = []
            this.外协分类 = []
            this.材料费 = []
            this.材料价格_价格 = []
            this.其他价格 = []
            this.机加工开始时间 = []
            this.机加工结束时间 = []
            this.外协加工任务单明细流水号 = []
            this.process = []
            getParts(this.Number).then(response => {
              this.returns = response.data
              this.加工价格合计 = 0
              this.材料价格合计 = 0
              this.其他价格合计 = 0
              if (response.data.length !== 0) {
                this.外协员电话 = response.data[0].联系电话
                this.联系人 = response.data[0].联系人
                this.联系人电话 = response.data[0].电话
                this.运费 = response.data[0].运费
                this.card = true
              } else {
                this.loading = false
                this.card = false
              }
              const children = document.getElementsByClassName('tableData')
              const parent = document.getElementById('1')
              if (children.length !== 0) {
                for (let i = children.length - 1; i >= 0; i--) {
                  parent.removeChild(children[i])
                }
              }
              const tr = []
              for (let i = 0; i < this.returns.length; i++) {
                tr[i] = document.createElement('tr')
                tr[i].setAttribute('class', 'tableData')
                tr[i].innerHTML = '<td></td>' + '<td colspan="5"></td>' + '<td colspan="2"></td>' + '<td colspan="2"></td>' +
                    '<td colspan="9" style="text-align: left;"></td>' + '<td colspan="1"></td>' + '<td></td><td></td><td></td><td></td><td colspan="2"></td><td colspan="2"></td>'
                document.getElementById('tableHead').after(tr[i])
              }
              for (let j = 0; j < this.returns.length; j++) {
                document.getElementsByClassName('tableData')[j].children[0].innerHTML = j + 1
                document.getElementsByClassName('tableData')[j].children[1].innerHTML = response.data[j].零件图号
                document.getElementsByClassName('tableData')[j].children[2].innerHTML = response.data[j].零件名称
                document.getElementsByClassName('tableData')[j].children[3].innerHTML = response.data[j].批次数量
                document.getElementsByClassName('tableData')[j].children[4].innerHTML = ''
                document.getElementsByClassName('tableData')[j].children[5].innerHTML = response.data[j].是否临时件1
                document.getElementsByClassName('tableData')[j].children[6].innerHTML = response.data[j].外协分类
                document.getElementsByClassName('tableData')[j].children[7].innerHTML = parseInt(response.data[j].加工价格_成交.toFixed(2))
                document.getElementsByClassName('tableData')[j].children[8].innerHTML = parseInt(response.data[j].材料价格_价格.toFixed(2))
                document.getElementsByClassName('tableData')[j].children[9].innerHTML = parseInt(response.data[j].其他价格.toFixed(2))
                if (response.data[j].机加工开始时间 !== null) {
                  document.getElementsByClassName('tableData')[j].children[10].innerHTML = response.data[j].机加工开始时间.substr(0, 10)
                }
                if (response.data[j].机加工结束时间 !== null) {
                  document.getElementsByClassName('tableData')[j].children[11].innerHTML = response.data[j].机加工结束时间.substr(0, 10)
                }
                this.加工价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[7].innerHTML)
                this.材料价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[8].innerHTML)
                this.其他价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[9].innerHTML)
              }
              this.总计 = this.加工价格合计 + this.材料价格合计 + this.其他价格合计 + this.运费
              this.大写金额 = convertCurrency(this.总计)
              if (response.data.length === 0) {
                this.loading = false
              }
              for (let i = 0; i < response.data.length; i++) { // 声明二维数组
                this.零件图号.push(response.data[i].零件图号)
                this.零件名称.push(response.data[i].零件名称)
                this.批次数量.push(response.data[i].批次数量)
                this.外协预算总价格.push(response.data[i].外协预算总价格.toFixed(2))
                this.加工价格_成交.push(response.data[i].加工价格_成交.toFixed(2))
                this.外协分类.push(response.data[i].外协分类)
                this.材料费.push(response.data[i].材料费.toFixed(2))
                this.材料价格_价格.push(response.data[i].材料价格_价格.toFixed(2))
                this.其他价格.push(response.data[i].其他价格.toFixed(2))
                if (response.data[i].机加工开始时间 !== null) {
                  this.机加工开始时间.push(response.data[i].机加工开始时间.substr(0, 10))
                } else {
                  this.机加工开始时间.push(' ')
                }
                if (response.data[i].机加工结束时间 !== null) {
                  this.机加工结束时间.push(response.data[i].机加工结束时间.substr(0, 10))
                } else {
                  this.机加工结束时间.push(' ')
                }
                this.外协加工任务单明细流水号.push(response.data[i].外协加工任务单明细流水号)
                this.process[i] = []
              }
              for (let i = 0; i < this.returns.length; i++) {
                spareParts(this.returns[i].工艺计划流水号, this.returns[i].单件是否外协).then(response => {
                  for (let k = 0; k < response.data.length; k++) { // 执行n次2
                    this.process[i].push(response.data[k].工艺名称简称)
                    document.getElementsByClassName('tableData')[i].children[4].innerHTML += response.data[k].工艺名称简称 + '/'
                  }
                }).then(() => {
                  this.List3.push(this.returns[i])
                  this.loading = false
                })
              }
            })
          } else { this.$message.error('移除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    searchData() {
      searchManufactor(this.input).then(response => {
        this.List2 = response.data
      })
    },
    indexMethod(index) {
      return index + 1
    },
    handleSelectionChange(val) {
      this.processNum = val
    },
    getSpareParts() { // 选入零件
      if (this.Number !== null) {
        this.result = 0
        for (let i = 0; i < this.processNum.length; i++) {
          insertParts(this.processNum[i].工艺计划流水号, this.Number).then(response => {
            this.result += parseInt(response.data[0].result)
            if (this.processNum.length === this.result) {
              this.contrast = 3000000000000
              this.contrast1 = 0
              this.loading = true
              this.getList()
              this.List3 = []
              this.零件图号 = []
              this.零件名称 = []
              this.批次数量 = []
              this.外协预算总价格 = []
              this.加工价格_成交 = []
              this.外协分类 = []
              this.材料费 = []
              this.材料价格_价格 = []
              this.其他价格 = []
              this.机加工开始时间 = []
              this.机加工结束时间 = []
              this.外协加工任务单明细流水号 = []
              this.process = []
              getParts(this.Number).then(response => {
                this.returns = response.data
                this.加工价格合计 = 0
                this.材料价格合计 = 0
                this.其他价格合计 = 0
                if (response.data.length !== 0) {
                  this.外协员电话 = response.data[0].联系电话
                  this.联系人 = response.data[0].联系人
                  this.联系人电话 = response.data[0].电话
                  this.运费 = response.data[0].运费
                  this.card = true
                } else {
                  this.card = false
                }
                const children = document.getElementsByClassName('tableData')
                const parent = document.getElementById('1')
                if (children.length !== 0) {
                  for (let i = children.length - 1; i >= 0; i--) {
                    parent.removeChild(children[i])
                  }
                }
                const tr = []
                for (let i = 0; i < this.returns.length; i++) {
                  tr[i] = document.createElement('tr')
                  tr[i].setAttribute('class', 'tableData')
                  tr[i].innerHTML = '<td></td>' + '<td colspan="5"></td>' + '<td colspan="2"></td>' + '<td colspan="2"></td>' +
                      '<td colspan="9" style="text-align: left;"></td>' + '<td colspan="1"></td>' + '<td></td><td></td><td></td><td></td><td colspan="2"></td><td colspan="2"></td>'
                  document.getElementById('tableHead').after(tr[i])
                }
                for (let j = 0; j < this.returns.length; j++) {
                  document.getElementsByClassName('tableData')[j].children[0].innerHTML = j + 1
                  document.getElementsByClassName('tableData')[j].children[1].innerHTML = response.data[j].零件图号
                  document.getElementsByClassName('tableData')[j].children[2].innerHTML = response.data[j].零件名称
                  document.getElementsByClassName('tableData')[j].children[3].innerHTML = response.data[j].批次数量
                  document.getElementsByClassName('tableData')[j].children[4].innerHTML = ''
                  document.getElementsByClassName('tableData')[j].children[5].innerHTML = response.data[j].是否临时件1
                  document.getElementsByClassName('tableData')[j].children[6].innerHTML = response.data[j].外协分类
                  document.getElementsByClassName('tableData')[j].children[7].innerHTML = parseInt(response.data[j].加工价格_成交.toFixed(2))
                  document.getElementsByClassName('tableData')[j].children[8].innerHTML = parseInt(response.data[j].材料价格_价格.toFixed(2))
                  document.getElementsByClassName('tableData')[j].children[9].innerHTML = parseInt(response.data[j].其他价格.toFixed(2))
                  if (response.data[j].机加工开始时间 !== null) {
                    document.getElementsByClassName('tableData')[j].children[10].innerHTML = response.data[j].机加工开始时间.substr(0, 10)
                  }
                  if (response.data[j].机加工结束时间 !== null) {
                    document.getElementsByClassName('tableData')[j].children[11].innerHTML = response.data[j].机加工结束时间.substr(0, 10)
                  }
                  this.加工价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[7].innerHTML)
                  this.材料价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[8].innerHTML)
                  this.其他价格合计 += parseInt(document.getElementsByClassName('tableData')[j].children[9].innerHTML)
                }
                this.总计 = this.加工价格合计 + this.材料价格合计 + this.其他价格合计 + this.运费
                this.大写金额 = convertCurrency(this.总计)
                if (response.data.length === 0) {
                  this.loading = false
                }
                for (let i = 0; i < response.data.length; i++) { // 声明二维数组
                  this.零件图号.push(response.data[i].零件图号)
                  this.零件名称.push(response.data[i].零件名称)
                  this.批次数量.push(response.data[i].批次数量)
                  this.外协预算总价格.push(response.data[i].外协预算总价格.toFixed(2))
                  this.加工价格_成交.push(response.data[i].加工价格_成交.toFixed(2))
                  this.外协分类.push(response.data[i].外协分类)
                  this.材料费.push(response.data[i].材料费.toFixed(2))
                  this.材料价格_价格.push(response.data[i].材料价格_价格.toFixed(2))
                  this.其他价格.push(response.data[i].其他价格.toFixed(2))
                  if (response.data[i].机加工开始时间 !== null) {
                    this.机加工开始时间.push(response.data[i].机加工开始时间.substr(0, 10))
                  } else {
                    this.机加工开始时间.push(' ')
                  }
                  if (response.data[i].机加工结束时间 !== null) {
                    this.机加工结束时间.push(response.data[i].机加工结束时间.substr(0, 10))
                  } else {
                    this.机加工结束时间.push(' ')
                  }
                  this.外协加工任务单明细流水号.push(response.data[i].外协加工任务单明细流水号)
                  this.process[i] = []
                  spareParts(this.returns[i].工艺计划流水号, this.returns[i].单件是否外协).then(response => {
                    for (let k = 0; k < response.data.length; k++) { // 执行n次2
                      this.process[i].push(response.data[k].工艺名称简称)
                      document.getElementsByClassName('tableData')[i].children[4].innerHTML += response.data[k].工艺名称简称 + '/'
                    }
                  }).then(() => {
                    this.List3.push(this.returns[i])
                    this.loading = false
                  })
                }
              })
            }
          })
        }
      } else {
        this.$message.warning('请选择订单')
      }
    },
    downLoadRWD(tableid) {
      if (this.List3.length === 0) {
        this.$message.warning('暂无数据')
      } else {
        getExplorer()
        method5(tableid)
        Cleanup()
      }
    },
    // 表格颜色
    tableRowClassName({ row }) {
      if (row.差价 < 0) {
        return 'chajia'
      } else {
        return ''
      }
    },
    // 分页
    handleSizeChange(val) {
      this.pageList = 1
      this.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.pageList = val
      this.fetchData()
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  span{
    margin: 10px 0 10px 10px;
  }
</style>
<style>
  td{
    width: 100px;
    height: 30px;
    text-align:center;
  }
  #tableHead td{
    border:1px solid black;
  }
  .tableData td{
    border:1px solid black;
  }
  #tableFoot td{
    border:1px solid black;
  }
  .tbodyHead td{
    text-align: left;
  }
  .foot td{
    width: 7%;
    text-align: left;
  }
</style>
<style>
  .el-table .chajia {
    background: #EBF953;
  }
  .el-table .chengjiao {
    background: #AEF199;
  }
  .el-input__inner {
    height: 30px;
  }
</style>

