<template>
  <div class="app-container">
    <el-card>
      <span>询价状态:</span>
      <el-select v-model="inquiryStateValue" placeholder="询价状态" size="small" clearable>
        <el-option
          v-for="item in inquiryState"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <span>物料名称:</span>
      <el-input v-model="materialName" placeholder="物料名称" size="small" clearable/>
      <el-button
        type="success"
        size="small"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="pageCurrent1=1;pageSize1=10;total1=0;searchTable1()">查询</el-button>
    </el-card>

    <el-card>
      <el-table
        v-loading=""
        :data="tableData1"
        :row-class-name="tableRowClassName"
        border
        style="width: 100%;max-height: 300px;"
        height="300px"
        size="mini"
        @selection-change="handleSelectionChange">
        <el-table-column :selectable="selectable" align="center" width="50" type="selection"/>
        <el-table-column label="操作" align="center" width="100" fixed="left">
          <template slot-scope="scope">
            <el-button :disabled="parseInt(scope.row.询价状态编号)!==1||parseInt(scope.row.是否确认)!==1" type="primary" size="mini" @click="materialChange(scope.row)">物料变更</el-button>
          </template>
        </el-table-column>
        <el-table-column label="物料状态" align="center" width="100">
          <template slot-scope="scope">
            <el-tag v-if="parseInt(scope.row.询价状态编号)===1" type="warning" size="small">未询价</el-tag>
            <el-tag v-if="parseInt(scope.row.询价状态编号)===3&&parseInt(scope.row.采购状态编号)!==3" type="success" size="small">已询价</el-tag>
            <el-tag v-if="parseInt(scope.row.询价状态编号)!==1&&parseInt(scope.row.采购状态编号)===3" type="info" size="small">已采购</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="项目名称" align="center" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="物料名称" align="center" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.物料名称 }}
          </template>
        </el-table-column>
        <el-table-column label="物料规格" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.物料规格 }}
          </template>
        </el-table-column>
        <el-table-column label="物料型号" align="center" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.物料型号 }}
          </template>
        </el-table-column>
        <el-table-column :filters="supplierFilters" :filter-method="filterHandler" label="供货商" align="center" min-width="100" prop="supplier">
          <template slot-scope="scope">
            {{ scope.row.供货商 }}
          </template>
        </el-table-column>
        <el-table-column label="零件数量" align="center" min-width="70">
          <template slot-scope="scope">
            {{ scope.row.零件数量 }}
          </template>
        </el-table-column>
        <el-table-column label="计划到货时间" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.物料计划到货时间.split(' ')[0] }}
          </template>
        </el-table-column>
        <el-table-column label="库存量" align="center" min-width="70">
          <template slot-scope="scope">
            {{ scope.row.库存量 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize1"
          :total="total1"
          style="display:inline-block;width:50%"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
    </el-card>

    <el-card>
      <span>询价单号:</span>
      <el-input v-model="inquirySheetNum" placeholder="询价单号" size="small" clearable/>
      <span>供应商:</span>
      <el-input v-model="supplierName" placeholder="供应商" size="small" clearable/>
      <el-button
        type="success"
        size="small"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="pageCurrent2=1;pageSize2=10;total2=0;searchTable2()">查询</el-button>
      <el-button
        type="primary"
        size="small"
        icon="el-icon-plus"
        style="margin-left: 10px"
        @click="createInquirySheet">创建单据</el-button>
      <el-button
        type="primary"
        size="small"
        icon="el-icon-circle-plus-outline"
        style="margin-left: 10px"
        @click="addInquirySheet">追加物料</el-button>
    </el-card>

    <el-card>
      <el-table v-loading="" :data="tableData2" border style="max-height: 300px;" height="300px" size="mini" highlight-current-row @row-click="searchTable3">
        <el-table-column label="询价单编号" align="center" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.询价单编号 }}
          </template>
        </el-table-column>
        <el-table-column label="供应商" align="center" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.供应商名称 }}
          </template>
        </el-table-column>
        <el-table-column label="电话号码" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.电话号码 }}
          </template>
        </el-table-column>
        <el-table-column label="传真" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.传真 }}
          </template>
        </el-table-column>
        <el-table-column label="电子信箱" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.电子信箱 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="300">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="editInquirySheet(scope.row)">编辑</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteInquirySheet(scope.row)">删除</el-button>
            <el-button type="warning" size="mini" icon="el-icon-download" @click="exportInquirySheet(scope.row)">导出</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="pageCurrent2"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize2"
          :total="total2"
          style="display:inline-block;width:50%"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange2"
          @current-change="handleCurrentChange2"/>
      </div>
      <el-table v-loading="" :data="tableData3" border style="max-height: 300px;" height="300px" size="mini">
        <el-table-column label="物料名称" align="center" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.物料名称 }}
          </template>
        </el-table-column>
        <el-table-column label="物料规格" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.物料规格 }}
          </template>
        </el-table-column>
        <el-table-column label="物料型号" align="center" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.物料型号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件数量" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.零件数量 }}
          </template>
        </el-table-column>
        <el-table-column label="询价单编号" align="center" min-width="70">
          <template slot-scope="scope">
            {{ scope.row.询价单编号 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="outInquirySheet(scope.row)">移出</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog :visible.sync="dialogVisible1" title="供应商选择" center style="min-height: 300px">
      <el-form ref="form1" :model="form1" label-position="left" label-width="90px" class="searchForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应商名称">
              <el-input v-model="supplierName" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业性质">
              <el-input v-model="enterpriseNature" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="货期">
              <el-input v-model="goodTime" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="注册资本">
              <el-input v-model="registeredCapital" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="税号">
              <el-input v-model="taxNum" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电子邮箱">
              <el-input v-model="EMail" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="地址">
              <el-input v-model="address" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账号">
              <el-input v-model="account" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开户行">
              <el-input v-model="openingBank" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话号码">
              <el-input v-model="phone" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="传真">
              <el-input v-model="fax" size="small"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-button
              type="success"
              size="small"
              icon="el-icon-search"
              @click="searchSupplier">查询</el-button>
            <el-button
              type="primary"
              size="small"
              icon="el-icon-check"
              @click="submitSelectSupplier">确定</el-button>
            <el-button
              type="danger"
              size="small"
              icon="el-icon-delete"
              @click="emptySupplierDetail">清空</el-button>
          </el-col>
        </el-row>
        <el-table :data="tableData01" size="mini" style="width: 97%;max-height: 300px;margin-top:15px" height="200px" border @row-click="showSupplierDetail">
          <el-table-column align="center" label="供应商名称" min-width="250">
            <template slot-scope="scope">
              {{ scope.row.供应商名称 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="企业性质" min-width="100">
            <template slot-scope="scope">
              {{ scope.row.企业性质 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="创立日期" min-width="100">
            <template slot-scope="scope">
              {{ scope.row.创立日期 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="注册资本" min-width="100">
            <template slot-scope="scope">
              {{ scope.row.注册资本 }}
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </el-dialog>

    <el-dialog :title="title2" :visible.sync="dialogVisible2" center style="min-height: 300px" width="400px">
      <el-form ref="form2" :model="form2" :rules="rules2" label-position="left" label-width="90px">
        <el-form-item label="询价单号" prop="inquirySheetNum">
          <el-input v-model="form2.inquirySheetNum" size="small"/>
        </el-form-item>
        <el-form-item label="供应商" prop="supplierName">
          <el-input v-model="form2.supplierName" size="small" readonly @focus="dialogVisible1=true"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible2=false">取消</el-button>
        <el-button
          v-show="title2==='创建询价单'"
          type="primary"
          size="small"
          @click="submitCreateInquirySheet">确定</el-button>
        <el-button
          v-show="title2==='编辑询价单'"
          type="primary"
          size="small"
          @click="submitEditInquirySheet">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible3" title="物料变更选择" center style="min-height: 300px;" width="780px">
      <span>物料名称：</span>
      <el-input v-model="materialName0" placeholder="物料名称" size="small" clearable/>
      <el-button type="success" size="small" icon="el-icon-search" style="margin-left:10px" @click="pageCurrent02=1;pageSize02=10;total02=0;searchMaterial()">查询</el-button>
      <el-table :data="tableData02" size="mini" style="width: 97%;max-height: 300px;margin-top:15px" height="400px" border highlight-current-row @row-click="selectNewMaterial">
        <el-table-column align="center" label="物料名称" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.物料名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="物料规格" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.物料规格 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="物料型号" min-width="150">
          <template slot-scope="scope">
            {{ scope.row.物料型号 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="pageCurrent02"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize02"
          :total="total02"
          style="display:inline-block;width:50%"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange02"
          @current-change="handleCurrentChange02"/>
      </div>
      <span style="font-size: large;color: red">将原物料替换为: {{ materialNew }}</span>
      <!--<el-input v-model="materialNew" size="small" readonly style="margin: 10px 10px 0 10px"></el-input>-->
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible3=false">取消</el-button>
        <el-button type="primary" size="small" @click="submitMaterialChange">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { searchMaterial, searchSupplier, searchCreateInquirySheet, searchCreateInquirySheet2, searchSheetDetail, editInquirySheet,
  createInquirySheet, deleteInquirySheet, addInquirySheet, outInquirySheet, searchAllMaterial, materialChange } from '@/api/PurchasingCenter/CreateInquirySheet'
import { mapGetters } from 'vuex'

export default {
  name: '', // 创建询价单
  data() {
    return {
      check1: 0, // 询价状态
      check2: 0, // 物料名称
      check3: 0, // 供应商
      check4: 0, // 询价单号
      inquiryStateValue: '', // 询价状态
      inquiryState: [{
        label: '未询价',
        value: 1
      }, {
        label: '已询价',
        value: 3
      }],
      materialName: '',
      tableData1: [], // 采购任务单明细
      total1: 0,
      pageCurrent1: 1,
      pageSize1: 10,
      supplierFilters: [{ text: '', value: '' }],
      tableData2: [], // 询价单列表
      total2: 0,
      pageCurrent2: 1,
      pageSize2: 10,
      tableData3: [], // 询价单明细
      dialogVisible1: false,
      inquirySheetNum: '', // 询价单号
      inquirySheetFlowNum: '', // 询价单流水号
      form1: {},
      supplierCheck1: 0,
      supplierCheck2: 0,
      supplierCheck3: 0,
      supplierCheck4: 0,
      supplierCheck5: 0,
      supplierCheck6: 0,
      supplierCheck7: 0,
      supplierCheck8: 0,
      supplierCheck9: 0,
      supplierCheck10: 0,
      supplierCheck11: 0,
      supplierCheck12: 0,
      supplierValue: '', // 供应商流水号
      supplierName: '', // 供应商名称
      goodTime: '', // 货期
      enterpriseNature: '', // 企业性质
      createDate: '', // 创立日期
      registeredCapital: '', // 注册资本
      taxNum: '', // 税号
      EMail: '', // 电子邮箱
      address: '', // 地址
      account: '', // 账号
      openingBank: '', // 开户行
      phone: '', // 电话号码
      fax: '', // 传真
      tableData01: [],
      dialogVisible2: false,
      form2: {
        inquirySheetNumValue: '', // 询价单流水号
        inquirySheetNum: '',
        supplierName: '',
        supplierValue: ''
      },
      rules2: { // 表单验证规则
        inquirySheetNum: [{ required: true, message: '请填写询价单号' }],
        supplierName: [{ required: true, message: '请选择供应商' }]
      },
      groupPartNum: [], // 组件零件流水号
      allNum: [], // 总数量
      dialogVisible3: false,
      materialName0: '',
      tableData02: [],
      total02: 0,
      pageCurrent02: 1,
      pageSize02: 10,
      materialNew: '', // 替换为新物料全称
      materialOldValue: '',
      materialNewValue: '',
      groupPartNumValue: '', // 组件零件流水号
      standardAndPurchaseValue: '', // 标准件和外购件流水号
      title2: ''
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id' // 人员编号
    ])
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
    },
    selectable(row, index) { // 控制某行是否可选
      return (parseInt(row.询价状态编号) === 1 && parseInt(row.采购状态编号) === 1 && parseInt(row.是否确认) === 1) // 未询价&&未采购&&确认物料修改
    },
    filterHandler(value, row) { // 筛选供货商
      return row['供货商'] === value
    },
    searchTable1() { // 查询物料列表
      this.inquiryStateValue !== '' && this.inquiryStateValue !== null ? this.check1 = 1 : this.check1 = 0
      this.materialName ? this.check2 = 1 : this.check2 = 0
      searchMaterial(this.pageCurrent1, this.pageSize1, this.check1, this.inquiryStateValue, this.check2, this.materialName, this.id).then(response => {
        this.tableData1 = response.data.rows
        console.log(response.data.rows)
        this.total1 = response.data.total
      })
    },
    handleSizeChange1(val) { // 物料列表分页
      this.pageSize1 = val
      this.pageCurrent1 = 1
      this.searchTable1()
    },
    handleCurrentChange1(val) { // 物料列表分页
      this.pageCurrent1 = val
      this.searchTable1()
    },
    searchTable2() { // 查询询价单列表
      this.supplierName ? this.check3 = 1 : this.check3 = 0
      this.inquirySheetNum ? this.check4 = 1 : this.check4 = 0
      searchCreateInquirySheet(this.pageCurrent2, this.pageSize2, this.check3, this.supplierName, this.check4, this.inquirySheetNum, this.id).then(response => {
        this.tableData2 = response.data.rows
        this.total2 = response.data.total
      })
    },
    handleSizeChange2(val) { // 询价单列表分页
      this.pageSize2 = val
      this.searchTable2()
    },
    handleCurrentChange2(val) { // 询价单列表分页
      this.pageCurrent2 = val
      this.searchTable2()
    },
    createInquirySheet() { // 创建空单据--询价单
      this.title2 = '创建询价单'
      this.form2.inquirySheetNum = ''
      this.form2.supplierValue = ''
      this.form2.supplierName = ''
      this.dialogVisible2 = true
      if (this.$refs['form2'] !== undefined) {
        this.$refs['form2'].resetFields()
      }
    },
    submitCreateInquirySheet() { // 提交创建询价单
      this.$refs['form2'].validate((valid) => {
        if (valid) {
          const numGroup1 = [] // 空数组，放现有的询价单号
          searchCreateInquirySheet2().then(response => { // 先查询判断是否存在
            for (let i = 0; i < response.data.length; i++) {
              numGroup1.push(response.data[i].询价单编号)
            }
          }).then(() => {
            if (numGroup1.indexOf(this.form2.inquirySheetNum) !== -1) {
              this.$message.error('该询价单号已存在')
            } else {
              createInquirySheet(this.form2.inquirySheetNum, this.form2.supplierValue, '', this.id).then(response => {
                if (response.data[0].result === '1') {
                  this.$message.success('创建成功')
                  this.inquirySheetNum = ''
                  this.supplierName = ''
                  this.supplierValue = ''
                  this.dialogVisible2 = false
                  this.searchTable2()
                } else { this.$message.error('操作失败') }
              })
            }
          })
        } else {
          console.log('表单验证未通过')
          return false
        }
      })
    },
    deleteInquirySheet(row) { // 删除询价单
      this.$confirm('确定删除该询价单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteInquirySheet(row.询价单流水号).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.inquirySheetNum = ''
            this.supplierName = ''
            this.supplierValue = ''
            this.searchTable1()
            this.searchTable2()
          } else { this.$message.error('删除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    editInquirySheet(row) { // 编辑询价单
      if (this.$refs['form2'] !== undefined) {
        this.$refs['form2'].resetFields()
      }
      this.title2 = '编辑询价单'
      this.form2.inquirySheetNumValue = row.询价单流水号
      this.form2.inquirySheetNum = row.询价单编号
      this.form2.supplierValue = row.供应商流水号
      this.form2.supplierName = row.供应商名称
      this.dialogVisible2 = true
    },
    submitEditInquirySheet() { // 提交编辑询价单
      this.$refs['form2'].validate((valid) => {
        if (valid) {
          const numGroup1 = [] // 空数组，放现有的询价单号
          const numGroup2 = [] // 空数组，放现有的询价单流水号
          searchCreateInquirySheet2().then(response => { // 先查询判断是否存在
            for (let i = 0; i < response.data.length; i++) {
              numGroup1.push(response.data[i].询价单编号)
              numGroup2.push(response.data[i].询价单流水号)
            }
          }).then(() => {
            if (numGroup1.indexOf(this.form2.inquirySheetNum) !== -1 && numGroup1.indexOf(this.form2.inquirySheetNum) !== numGroup2.indexOf(parseInt(this.form2.inquirySheetNumValue))) {
              this.$message.error('该询价单号已存在')
            } else {
              editInquirySheet(this.form2.inquirySheetNumValue, this.form2.inquirySheetNum, this.form2.supplierValue).then(response => {
                if (response.data[0].result === '1') {
                  this.$message.success('修改成功')
                  this.inquirySheetNum = ''
                  this.supplierName = ''
                  this.supplierValue = ''
                  this.dialogVisible2 = false
                  this.searchTable2()
                } else { this.$message.error('修改失败') }
              })
            }
          })
        } else {
          console.log('表单验证未通过')
          return false
        }
      })
    },
    exportInquirySheet(row) { // 导出询价单
      this.$confirm('确认导出询价单' + row.询价单编号 + '?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        import('@/vendor/Export2Excelcjn').then(excel => {
          const tHeader = ['询价单编号', '供应商名称', '物料名称', '物料规格', '物料型号', '数量', '单价', '备注'] // 表头内容
          const filterVal = ['询价单编号', '供应商名称', '物料名称', '物料规格', '物料型号', '零件数量'] // tableData3里的属性名
          const list = this.tableData3
          const data = list.map(v => filterVal.map(j => v[j]))
          excel.export_json_to_excel({
            header: tHeader,
            data,
            filename: row.询价单编号 + '_' + row.供应商名称,
            autoWidth: true,
            bookType: 'xlsx'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    handleSelectionChange(val) { // 表1多选
      console.log(val)
      this.groupPartNum = []
      this.allNum = []
      for (let i = 0; i < val.length; i++) {
        this.groupPartNum[i] = val[i].组件零件流水号
        this.allNum[i] = val[i].零件数量
      }
    },
    addInquirySheet() { // 追加物料
      const numGroup2 = [] // 空数组，放该询价单中已有的物料
      if (this.inquirySheetNum === '' || this.inquirySheetNum === null) {
        this.$message.error('请选择一个询价单')
      } else {
        searchSheetDetail(this.inquirySheetFlowNum).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            numGroup2.push(response.data[i].组件零件流水号)
          }
        }).then(() => {
          let x = true // 为了只执行一次的中间变量
          for (let i = 0; i < this.groupPartNum.length; i++) {
            if (numGroup2.indexOf(parseInt(this.groupPartNum[i])) !== -1) {
              if (x) {
                this.$notify({
                  title: '注意',
                  message: '无法向该询价单中追加重复物料，已自动跳过',
                  type: 'warning'
                })
                x = false
              }
            } else {
              addInquirySheet(this.inquirySheetFlowNum, this.groupPartNum[i], this.allNum[i], 0, '').then(response => {
                if (response.data[0].result === '1') {
                  this.$message.success('操作成功')
                  this.searchTable1()
                  searchSheetDetail(this.inquirySheetFlowNum).then(response => {
                    this.tableData3 = response.data
                  })
                } else { this.$message.error('操作失败') }
              })
            }
          }
        })
      }
    },
    outInquirySheet(row) {
      outInquirySheet(row.询价单流水号, row.组件零件流水号).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('操作成功')
          this.searchTable1()
          searchSheetDetail(this.inquirySheetFlowNum).then(response => {
            this.tableData3 = response.data
          })
        } else { this.$message.error('操作失败') }
      })
    },
    searchSupplier() { // 查询创立日期和注册资本大于符合条件的数据
      this.supplierName ? this.supplierCheck1 = 1 : (this.supplierCheck1 = 0, this.supplierName = '')
      this.enterpriseNature ? this.supplierCheck2 = 1 : (this.supplierCheck2 = 0, this.enterpriseNature = '')
      this.createDate ? this.supplierCheck3 = 1 : (this.supplierCheck3 = 0, this.createDate = '')
      this.registeredCapital ? this.supplierCheck4 = 1 : (this.supplierCheck4 = 0, this.registeredCapital = '')
      this.taxNum ? this.supplierCheck5 = 1 : (this.supplierCheck5 = 0, this.taxNum = '')
      this.EMail ? this.supplierCheck6 = 1 : (this.supplierCheck6 = 0, this.EMail = '')
      this.address ? this.supplierCheck7 = 1 : (this.supplierCheck7 = 0, this.address = '')
      this.account ? this.supplierCheck8 = 1 : (this.supplierCheck8 = 0, this.account = '')
      this.openingBank ? this.supplierCheck9 = 1 : (this.supplierCheck9 = 0, this.openingBank = '')
      this.phone ? this.supplierCheck10 = 1 : (this.supplierCheck10 = 0, this.phone = '')
      this.fax ? this.supplierCheck11 = 1 : (this.supplierCheck11 = 0, this.fax = '')
      this.goodTime ? this.supplierCheck12 = 1 : (this.supplierCheck12 = 0, this.goodTime = '')
      searchSupplier(this.supplierCheck1, this.supplierName, this.supplierCheck2, this.enterpriseNature, this.supplierCheck3, this.createDate, this.supplierCheck4, this.registeredCapital, this.supplierCheck5, this.taxNum, this.supplierCheck6, this.EMail, this.supplierCheck7, this.address, this.supplierCheck8, this.account, this.supplierCheck9, this.openingBank, this.supplierCheck10, this.phone, this.supplierCheck11, this.fax, this.supplierCheck12, this.goodTime).then(response => {
        this.tableData01 = response.data
      })
    },
    showSupplierDetail(row) {
      this.form2.supplierValue = row.供应商流水号
      this.form2.supplierName = row.供应商名称
      this.supplierValue = row.供应商流水号
      this.supplierName = row.供应商名称
      this.enterpriseNature = row.企业性质
      this.createDate = row.创立日期
      this.registeredCapital = row.注册资本
      this.taxNum = row.税号
      this.EMail = row.电子信箱
      this.address = row.地址
      this.account = row.帐号
      this.openingBank = row.开户行
      this.phone = row.电话号码
      this.fax = row.传真
      this.goodTime = row.货期
    },
    emptySupplierDetail() {
      this.supplierValue = ''
      this.supplierName = ''
      this.enterpriseNature = ''
      this.createDate = ''
      this.registeredCapital = ''
      this.taxNum = ''
      this.EMail = ''
      this.address = ''
      this.account = ''
      this.openingBank = ''
      this.phone = ''
      this.fax = ''
      this.goodTime = ''
    },
    submitSelectSupplier() { // 确定选择供应商
      this.dialogVisible1 = false
    },
    searchTable3(row) { // 查询该询价单中的物料
      this.tableData3 = []
      this.inquirySheetNum = row.询价单编号
      this.inquirySheetFlowNum = row.询价单流水号
      this.supplierValue = row.供应商流水号
      this.supplierName = row.供应商名称
      searchSheetDetail(row.询价单流水号).then(response => {
        this.tableData3 = response.data
      })
    },
    materialChange(row) { // 物料变更
      this.dialogVisible3 = true
      console.log(row)
      this.groupPartNumValue = row.组件零件流水号
      this.standardAndPurchaseValue = row.标准件和外购件流水号
      this.materialOldValue = row.物料流水号
    },
    searchMaterial() {
      searchAllMaterial(this.materialName0, this.pageCurrent02, this.pageSize02).then(response => {
        this.tableData02 = response.data.result
        this.total02 = parseInt(response.data.output[0].ItemCount)
      })
    },
    handleSizeChange02(val) {
      this.pageSize02 = val
      this.searchMaterial()
    },
    handleCurrentChange02(val) {
      this.pageCurrent02 = val
      this.searchMaterial()
    },
    selectNewMaterial(row) {
      this.materialNew = ''
      this.materialNewValue = row.物料流水号
      this.materialNew += row.物料名称 + ' ' + row.物料规格 + ' ' + row.物料型号
    },
    submitMaterialChange() {
      materialChange(this.groupPartNumValue, this.standardAndPurchaseValue, this.materialOldValue, this.materialNewValue, this.id).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('提交变更申请成功')
          this.dialogVisible3 = false
          this.searchTable1()
        } else { this.$message.error('操作失败') }
      })
      console.log(this.groupPartNumValue, this.standardAndPurchaseValue, this.materialOldValue, this.materialNewValue)
    },
    tableRowClassName({ row, rowIndex }) {
      if (parseInt(row.是否确认) === 0) {
        return 'MistyRose'
      }
      return ''
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  .el-select{
    width:200px
  }
  .el-input{
    width:200px
  }
  span{
    margin: 10px 0 10px 10px;
  }
  .searchForm .el-form-item{
    margin-bottom: 5px;
  }
  .el-tag{
    margin: 0
  }
</style>
<style>
  .el-table .green {
    background: lightgreen;
  }
  .el-table .white {
    background: whitesmoke;
  }
  .el-table .red {
    background: Tomato!important;
  }
  .el-table .MistyRose {
    background: MistyRose!important;
  }
  .el-table .gray {
    background: lightgray;
  }
</style>
