<template>
  <div class="app-container">
    <el-card style="height: 850px;width: 100%">
      <el-button
        type="distribution"
        icon="el-icon-search"
        size="small"
        style="margin: 10px 0 0 180px"
        @click="oldContract()">老合同
      </el-button>
      <el-button
        type="shengcheng"
        icon="el-icon-circle-plus-outline"
        size="small"
        style="margin: 10px 0 0 10px"
        @click="createContract()">新合同
      </el-button>
      <el-button
        type="primary"
        icon="el-icon-check"
        plain
        size="small"
        style="margin-left: 50px"
        @click="submitContract()">提交
      </el-button>
      <el-tooltip :open-delay="500" effect="dark" content="查看修改客户信息" placement="top">
        <el-button
          type="text"
          icon="el-icon-search"
          size="mini"
          style="margin-left: 830px;font-size: 20px"
          @click="handleEdit();flag1 = 2"/>
      </el-tooltip>
      <el-tooltip :open-delay="500" effect="dark" content="查看修改付款方式" placement="top">
        <el-button
          type="text"
          icon="el-icon-notebook-2"
          size="mini"
          style="margin-left: 10px;font-size: 20px"
          @click="payment"/>
      </el-tooltip>
      <el-badge :value="numberReturnedItems" class="item">
        <el-button type="text" size="small" @click="viewReturnedContracts()">打回通知</el-button>
      </el-badge>
      <p style="margin: 20px 0 10px 695px;font-weight: bold; font-size: 30px">销&nbsp;&nbsp;售&nbsp;&nbsp;合&nbsp;&nbsp;同</p>
      <el-row style="width: 1192px;margin-left: 200px;">
        <el-col :span="6">
          <span>&nbsp;合同编号：</span>
          <el-select
            v-model="contractNoValue"
            size="small"
            placeholder="选择合同"
            clearable
            filterable
            style="width: 200px;margin: 10px 0 10px 3px"
            @change="selectContract">
            <el-option
              v-for="item in contractNo"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-col>
        <el-col :span="6">
          <span>*买方名称：</span>
          <el-select
            v-model="customerNameValue"
            :remote-method="getCustomer"
            placeholder="选择买方"
            size="small"
            clearable
            filterable
            remote
            style="width: 150px;margin: 10px 0 10px 2px"
            @change="editContract">
            <el-option
              v-for="(item, index) in customerName"
              :key="index.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-tooltip :open-delay="500" effect="dark" content="新增客户" placement="top">
            <el-button icon="el-icon-circle-plus-outline" size="small" @click="addCustomer();flag1 = 1"/>
          </el-tooltip>
        </el-col>
        <el-col :span="6">
          <span>*交货期限：&nbsp;&nbsp;付款后</span>
          <el-input
            v-model="deliveryDate"
            clearable
            size="small"
            style="width:120px;margin: 10px 0 10px 3px"
            @change="editContract"/>
          <span>日内</span>
        </el-col>
        <el-col :span="6">
          <span>*签订日期：</span>
          <el-date-picker
            v-model="signingDate"
            size="small"
            align="center"
            style="width: 200px;margin: 10px 0 10px 3px"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="选择日期"
            @change="editContract"/>
        </el-col>
      </el-row>
      <el-row style="width: 1192px;margin-left: 200px">
        <el-col :span="6">
          <span>*付款方式：</span>
          <el-select
            v-model="paymentMethodValue"
            placeholder="选择付款方式"
            size="small"
            clearable
            filterable
            style="width: 200px;margin: 10px 0 10px 2px"
            @change="editContract">
            <el-option
              v-for="item in paymentMethod"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-col>
        <el-col :span="6">
          <span>*税&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;率：</span>
          <el-input
            v-model="taxRate"
            clearable
            size="small"
            type="number"
            style="width:200px;margin: 10px 0 10px 2px"
            @change="editContract"/>
        </el-col>
        <el-col :span="6">
          <span>&nbsp;收&nbsp;&nbsp;货&nbsp;&nbsp;人：</span>
          <el-input v-model="consignee" readonly size="small" style="width:200px;margin: 10px 0 10px 3px"/>
        </el-col>
        <el-col :span="6">
          <span>&nbsp;合同备注：</span>
          <el-tooltip :open-delay="500" :disabled="contractRemarks ? false : true" effect="dark" placement="top">
            <div slot="content">{{ contractRemarks }}</div>
            <el-input
              v-model="contractRemarks"
              clearable
              size="small"
              style="width:200px;margin: 10px 0 10px 3px"
              show-overflow-tooltip
              @change="editContract"/>
          </el-tooltip>
        </el-col>
      </el-row>
      <div style="margin-left: 170px">
        <el-table
          v-loading="loading"
          ref="table"
          :data="tableData"
          :summary-method="getSummaries"
          show-summary
          size="mini"
          style="width: 1246px"
          height="450px"
          border
          @row-dblclick="changeState">
          <el-table-column align="center" label="序号" width="100px">
            <template slot-scope="scope">
              <template v-if="scope.row.edit">
                <el-input v-model="scope.row.顺序" size="mini" type="number" style="width: 100%" @dblclick.native.stop/>
              </template>
              <template v-else>
                {{ scope.row.顺序 }}
              </template>
            </template>
          </el-table-column>
          <el-table-column align="center" label="产品名称" width="255px">
            <template slot-scope="scope">
              <template v-if="scope.row.edit && scope.row.是否可选 === 1 && scope.row.物料流水号 === 0">
                <el-cascader
                  ref="cascader"
                  v-model="scope.row.产品位置"
                  :options="product"
                  :show-all-levels="false"
                  style="width: 230px"
                  @change="getData"
                  @dblclick.native.stop/>
              </template>
              <template v-else-if="scope.row.edit && scope.row.是否可选 === 0 && scope.row.物料流水号 === 0">
                <el-input v-model="scope.row.产品名称" size="mini" style="width: 100%" @dblclick.native.stop/>
              </template>
              <template v-else>
                {{ scope.row.产品名称 }}
              </template>
            </template>
          </el-table-column>
          <el-table-column align="center" label="详情" width="350px">
            <template slot-scope="scope">
              <template v-if="scope.row.edit">
                <el-input
                  v-model="scope.row.产品详情"
                  size="mini"
                  rows="3"
                  type="textarea"
                  style="width: 100%"
                  @dblclick.native.stop/>
              </template>
              <template v-else>
                {{ scope.row.产品详情 }}
              </template>
            </template>
          </el-table-column>
          <el-table-column align="center" label="数量" width="80px" prop="数量">
            <template slot-scope="scope">
              <template v-if="scope.row.edit">
                <el-input v-model="scope.row.数量" size="mini" type="number" style="width: 100%" @dblclick.native.stop/>
              </template>
              <template v-else>
                {{ scope.row.数量 }}
              </template>
            </template>
          </el-table-column>
          <el-table-column align="center" label="单位" width="80px">
            <template slot-scope="scope">
              <template v-if="scope.row.edit">
                <el-input v-model="scope.row.单位" size="mini" style="width: 100%" @dblclick.native.stop/>
              </template>
              <template v-else>
                {{ scope.row.单位 }}
              </template>
            </template>
          </el-table-column>
          <el-table-column align="center" label="单价" width="130px">
            <template slot-scope="scope">
              <template v-if="scope.row.edit">
                <el-input v-model="scope.row.单价" size="mini" type="number" style="width: 100%" @dblclick.native.stop/>
              </template>
              <template v-else>
                {{ scope.row.单价 ? parseFloat(scope.row.单价).toFixed(2) : '' }}
              </template>
            </template>
          </el-table-column>
          <el-table-column align="center" label="金额（元）" width="120px" prop="金额（元）">
            <template slot-scope="scope">
              {{ (scope.row.数量 * scope.row.单价).toFixed(2) }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作" width="130px">
            <template slot-scope="scope">
              <el-button v-if="scope.row.edit" type="text" size="mini" @click="editProduct(scope.row)">确定</el-button>
              <el-button v-if="scope.row.edit" type="text" size="mini" @click="cancel(scope.row)">取消</el-button>
              <el-tooltip :open-delay="700" effect="dark" content="删除" placement="top">
                <el-button type="text" icon="el-icon-minus" size="mini" @click="deleteProduct(scope.row)"/>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <el-tooltip :open-delay="700" effect="dark" content="增加模块" placement="top">
          <el-button type="primary" size="small" icon="el-icon-cjnmodule" plain @click="createProduct(1)">模块
          </el-button>
        </el-tooltip>
        <el-tooltip :open-delay="700" effect="dark" content="增加BOM零件" placement="top">
          <el-button type="success" size="small" plain icon="el-icon-cjnshezhi" @click="addBom">BOM零件</el-button>
        </el-tooltip>
        <el-tooltip :open-delay="700" effect="dark" content="增加物料" placement="top">
          <el-button type="info" size="small" plain icon="el-icon-cjnweixiu" @click="addMaterial">物料</el-button>
        </el-tooltip>
        <el-tooltip :open-delay="700" effect="dark" content="增加非标件" placement="top">
          <el-button type="info" size="small" plain icon="el-icon-cjnwuliao" @click="createProduct(0)">非标件
          </el-button>
        </el-tooltip>
        <el-tooltip :open-delay="700" effect="dark" content="从老合同里选择" placement="top">
          <el-button type="distribution" icon="el-icon-circle-plus-outline" size="small" @click="addOldContract()">
            老合同
          </el-button>
        </el-tooltip>
      </div>
      <div style="margin: 20px 0 0 170px">
        <span style="float: left">附件：</span>
        <el-tooltip :open-delay="700" effect="dark" content="上传客户提供资料" placement="top">
          <el-button type="primary" plain size="medium" @click="ContractPhoto">客户提供资料</el-button>
        </el-tooltip>
        <el-tooltip :open-delay="700" effect="dark" content="上传需要留存的合同沟通信息" placement="top">
          <el-button type="warning" plain size="medium" @click="ContractPhoto1">合同留存信息</el-button>
        </el-tooltip>
      </div>
    </el-card>
    <el-card v-show="false">
      <div style="width:900px;margin-left: 350px">
        <el-card>
          <div id="WGBLD" style="width: 880px;margin: 0 auto">
            <div style="margin: 0 0 10px 240px">
              <h3>浙江景耀数控科技有限公司</h3>
            </div>
            <div style="margin: 0 0 0 320px">
              <h4>模块订单</h4>
            </div>
            <table cellspacing="0px" align="center" border="1 solid black" width="100%">
              <tr style="height: 40px">
                <td colspan="4" style="text-align: center;width: 20%">下单人员</td>
                <td colspan="5" style="text-align: center;width: 40%">{{ peoples }}</td>
                <td colspan="4" style="text-align: center;width: 20%">订单号</td>
                <td colspan="4" style="text-align: center;width: 20%">{{ contract }}</td>
              </tr>
              <tr style="height: 40px">
                <td colspan="2" style="text-align: center;width: 10%">收货人</td>
                <td colspan="2" style="text-align: center;width: 10%">王总</td>
                <td colspan="2" style="text-align: center;width: 16%">下单日期</td>
                <td colspan="3" style="text-align: center;width: 24%">{{ date1 }}</td>
                <td colspan="4" style="text-align: center;width: 20%">交货日期</td>
                <td colspan="4" style="text-align: center;width: 20%">{{ date2 }}</td>
              </tr>
              <tr id="tablehead11" style="height: 35px">
                <td colspan="5" style="text-align: center;width: 40%">产品名称</td>
                <td colspan="2" style="text-align: center;width: 10%">数量</td>
                <td colspan="10" style="text-align: center;width: 50%">客户要求：我方付运费</td>
              </tr>
              <tr v-for="(list, index) in returns" :key="index" style="height: 35px">
                <td colspan="5" style="text-align: center;width: 40%">{{ list.产品名称 }}</td>
                <td colspan="2" style="text-align: center;width: 10%">{{ list.数量 }}</td>
                <td colspan="10" style="text-align: center;width: 50%">{{ list.配置 }}</td>
              </tr>
              <tr style="height: 40px">
                <td colspan="17" style="text-align: center;width: 40%">配件明细表</td>
              </tr>
              <tr id="tablehead12" style="height: 35px">
                <td colspan="2" rowspan="2" style="text-align: center;width: 10%">轴承型号</td>
                <td colspan="4" rowspan="1" style="text-align: center;width: 20%">电机选配</td>
                <td colspan="2" rowspan="2" style="text-align: center;width: 10%">安装方向</td>
                <td colspan="9" rowspan="1" style="text-align: center;width: 60%">传动方式</td>
              </tr>
              <tr>
                <td colspan="2" rowspan="1" style="text-align: center;width: 10%">功率</td>
                <td colspan="2" rowspan="1" style="text-align: center;width: 10%">转速</td>
                <td colspan="2" rowspan="1" style="text-align: center;width: 10%">三角带及带轮型号</td>
                <td colspan="2" rowspan="1" style="text-align: center;width: 10%">同步带及带轮型号</td>
                <td colspan="2" rowspan="1" style="text-align: center;width: 10%">多楔带及带轮型号</td>
                <td colspan="3" rowspan="1" style="text-align: center;width: 15%">齿轮传动及齿轮型号</td>
              </tr>
              <tr v-for="(list, index1) in returns1" :key="'info2-' + index1" style="height: 35px">
                <td colspan="2" style="text-align: center;width: 10%">{{ list.轴承型号 }}</td>
                <td colspan="2" style="text-align: center;width: 10%">{{ list.功率 }}</td>
                <td colspan="2" style="text-align: center;width: 10%">{{ list.转速 }}</td>
                <td colspan="2" style="text-align: center;width: 10%">{{ list.安装方向 }}</td>
                <td colspan="2" style="text-align: center;width: 10%">{{ list.三角带及带轮型号 }}</td>
                <td colspan="2" style="text-align: center;width: 10%">{{ list.同步带及带轮型号 }}</td>
                <td colspan="2" style="text-align: center;width: 10%">{{ list.多楔带及带轮型号 }}</td>
                <td colspan="3" style="text-align: center;width: 15%">{{ list.齿轮传动及齿轮型号 }}</td>
              </tr>
              <tfoot>
                <tr style="height: 40px">
                  <td colspan="2" align="center">备注：</td>
                  <td colspan="15" align="center">{{ TotalAmount }}</td>
                </tr>
              </tfoot>
            </table>
            <div style="margin-top: 20px">审核1：___________ 审核2：___________ 跟单：___________</div>
            <div style="margin-top: 20px">装配人员：________ 检验人员：________ 装箱人员：_______ 发货人员：___________
            </div>
            <div style="margin-top: 20px;margin-left: 400px">完成时间：______ 年____月_____日</div>
          </div>
        </el-card>
      </div>
    </el-card>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" :title="title" center width="700px">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-position="left"
        label-width="90px"
        class="demo-ruleForm"
        style="margin: auto">
        <el-row>
          <el-col :span="12">
            <el-form-item label="省份:" prop="省份">
              <el-select
                v-model="form.省份"
                size="mini"
                style="margin: 0;width: 200px"
                placeholder="请选择省份"
                filterable
                clearable>
                <el-option
                  v-for="item in province"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称:" prop="客户名称">
              <el-input
                v-model="form.客户名称"
                clearable
                size="small"
                style="width:200px"
                placeholder="请输入客户名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="简称:" prop="简称">
              <el-input v-model="form.简称" clearable size="small" style="width:200px" placeholder="请输入简称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人:" prop="联系人">
              <el-input v-model="form.联系人" clearable size="small" style="width:200px" placeholder="请输入联系人"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话:" prop="经理电话">
              <el-input
                v-model="form.经理电话"
                clearable
                size="small"
                style="width:200px"
                placeholder="请输入联系电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收货人:" prop="收货人">
              <el-input v-model="form.收货人" clearable size="small" style="width:200px" placeholder="请输入收货人"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收货电话:" prop="联系电话">
              <el-input
                v-model="form.联系电话"
                clearable
                size="small"
                style="width:200px"
                placeholder="请输入收货电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮寄地址:" prop="邮寄地址">
              <el-input
                v-model="form.邮寄地址"
                clearable
                size="small"
                style="width:200px"
                placeholder="请输入邮寄地址"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电子邮箱:" prop="电子邮箱">
              <el-input
                v-model="form.电子邮箱"
                clearable
                size="small"
                style="width:200px"
                placeholder="请输入电子邮箱"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注:" prop="备注">
              <el-input v-model="form.备注" clearable size="small" style="width:200px" placeholder="请输入备注"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff('form')">取消</el-button>
        <el-button type="distribution" size="small" @click="submit('form')">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible1" center width="1450px">
      <div style="width: 100%;overflow: hidden">
        <el-col>
          <el-select
            v-model="customerNameValue1"
            :remote-method="getCustomer"
            style="width:150px"
            placeholder="买方名称"
            size="small"
            filterable
            clearable
            remote
            @change="searchOldContract()">
            <el-option
              v-for="(item, index) in customerName"
              :key="index.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-select
            v-model="consigneePeopleValue"
            style="width:150px"
            placeholder="收货人"
            size="small"
            filterable
            clearable
            @change="searchOldContract()">
            <el-option
              v-for="(item, index) in consigneePeople"
              :key="index.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <span style="font-size: 13px;color: black">签订日期</span>
          <el-date-picker
            v-model="dateRange"
            size="small"
            type="daterange"
            align="center"
            style="width: 220px;"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            range-separator="～"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="searchOldContract"/>
        </el-col>
        <el-col style="width: 594px">
          <el-table
            :data="tableData1"
            :header-cell-style="{background: '#2283D4',color: 'white'}"
            highlight-current-row
            border
            stripe
            size="mini"
            style="width: 581px;margin-top: 10px;"
            height="440px"
            @row-click="searchTable2">
            <el-table-column width="140px" label="合同编号" align="center">
              <template slot-scope="scope">
                {{ scope.row.合同编号 }}
              </template>
            </el-table-column>
            <el-table-column width="150px" label="客户名称" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.客户名称 }}
              </template>
            </el-table-column>
            <el-table-column width="100px" label="收货人" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.收货人 }}
              </template>
            </el-table-column>
            <el-table-column :width="setColumnWidth('日期')" label="签订日期" align="center">
              <template slot-scope="scope">
                {{ scope.row.签订日期 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="text" icon="el-icon-circle-plus" size="mini" @click="newContract(scope.row)">新合同
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col style="width: 800px">
          <el-card style="margin-top: 10px">
            <div id="WGBLD1" style="width: 780px;margin: 20px 0 0 0">
              <div style="margin: 0 0 10px 220px">
                <span style="font-size: 23px">销&nbsp;&nbsp;售&nbsp;&nbsp;合&nbsp;&nbsp;同&nbsp;&nbsp;<span
                  v-if="taxRate1 !== '0%'"
                  style="font-size: 12px">（含{{ taxRate1 }}增值税）</span></span>
              </div>
              <div style="font-size: 16px">
                <div style="float: left;width: 45%;margin-left: 20px">
                  <div style="margin-top: 10px">甲方：{{ firstParty }}</div>
                  <div style="margin-top: 10px">乙方：{{ partyB }}</div>
                  <div style="margin-top: 10px">签署地点：{{ addressA }}</div>
                </div>
                <div style="float: left;margin-left: 30px;width: 45%">
                  <div style="margin-top: 10px;margin-left: 70px">合同编号：{{ number }}</div>
                  <div style="margin-top: 10px;margin-left: 70px">签订日期：{{ date }}</div>
                </div>
              </div>
              <table cellspacing="0px" align="center" border="1 solid black" width="100%">
                <tr id="tablehead13" style="height: 35px">
                  <td colspan="1" style="text-align: center;width: 8%">序号</td>
                  <td colspan="5" style="text-align: center;width: 40%">规格品名</td>
                  <td colspan="1" style="text-align: center;width: 8%">单位</td>
                  <td colspan="1" style="text-align: center;width: 8%">数量</td>
                  <td colspan="2" style="text-align: center;width: 18%">单价</td>
                  <td colspan="2" style="text-align: center;width: 18%">金额（元）</td>
                </tr>
                <tr v-for="(list, index) in returns2" :key="index" style="height: 35px">
                  <td colspan="1" style="text-align: center;width: 8%">{{ list.序号 }}</td>
                  <td colspan="5" style="text-align: center;width: 40%">{{ list.规格品名 }}</td>
                  <td colspan="1" style="text-align: center;width: 8%">{{ list.单位 }}</td>
                  <td colspan="1" style="text-align: center;width: 8%">{{ list.数量 }}</td>
                  <td colspan="2" style="text-align: center;width: 18%">{{ list.单价 }}</td>
                  <td colspan="2" style="text-align: center;width: 18%">{{ list.金额 }}</td>
                </tr>
                <tfoot>
                  <tr style="height: 40px">
                    <td colspan="1" align="center">合计：</td>
                    <td colspan="11" align="right"><span style="float: left;font-size: 16px">（大写）{{
                      TotalAmount2
                    }}</span><span style="font-size: 16px;margin-right: 5px">（小写）￥：{{ TotalAmount1 }}</span></td>
                  </tr>
                </tfoot>
              </table>
            </div>
          </el-card>
        </el-col>
      </div>
    </el-dialog>
    <el-dialog
      v-el-drag-dialog
      :visible.sync="dialogVisible1"
      :center="dialogName"
      title="客户提供资料"
      width="20%">
      <div v-for="(file, key) in hadFile" :key="key">
        <div class="wrapper">
          <div class="content">
            <div class="action">
              <a class="delete" @click="deleteFileData(file.id)">删除</a>
            </div>
            <div v-if="file.suffix==='pdf'" class="icon">
              <svg-icon icon-class="pdf"/>
            </div>
            <div v-else-if="file.suffix==='docx'||file.suffix === 'doc'" class="icon">
              <svg-icon icon-class="doc"/>
            </div>
            <div v-else-if="file.suffix==='xlsx' || file.suffix === 'xls'" class="icon">
              <svg-icon icon-class="excel"/>
            </div>
            <div v-else-if="file.suffix==='pptx' || file.suffix === 'ppt'" class="icon">
              <svg-icon icon-class="ppt"/>
            </div>
            <div v-else-if="file.suffix==='jpg' || file.suffix === 'jpeg'|| file.suffix === 'png'" class="icon">
              <svg-icon icon-class="pic"/>
            </div>
            <div v-else class="icon">
              <svg-icon icon-class="file"/>
            </div>
            <a id="appUrl" :href="file.url" target="view_window">
              <div class="info">{{ file.name }}</div>
            </a>
          </div>
        </div>
      </div>
      <div style="margin-left: 37%">
        <el-upload
          :action="action"
          :on-success="uploadSuccess"
          :on-error="uploadFailure"
          :show-file-list="showFileList"
          :file-list="fileList"
          class="upload-demo"
          multiple>
          <el-button size="small" type="shengcheng" @click="batchImportOfDrawings">点击上传</el-button>
        </el-upload>
      </div>
    </el-dialog>
    <el-dialog
      v-el-drag-dialog
      :visible.sync="dialogVisible2"
      :center="dialogName"
      title="合同留存信息"
      width="20%">
      <div v-for="(file, key) in hadFile1" :key="key">
        <div class="wrapper">
          <div class="content">
            <div class="action">
              <a class="delete" @click="deleteFileData1(file.id)">删除</a>
            </div>
            <div v-if="file.suffix==='pdf'" class="icon">
              <svg-icon icon-class="pdf"/>
            </div>
            <div v-else-if="file.suffix==='docx'||file.suffix === 'doc'" class="icon">
              <svg-icon icon-class="doc"/>
            </div>
            <div v-else-if="file.suffix==='xlsx' || file.suffix === 'xls'" class="icon">
              <svg-icon icon-class="excel"/>
            </div>
            <div v-else-if="file.suffix==='pptx' || file.suffix === 'ppt'" class="icon">
              <svg-icon icon-class="ppt"/>
            </div>
            <div v-else-if="file.suffix==='jpg' || file.suffix === 'jpeg'|| file.suffix === 'png'" class="icon">
              <svg-icon icon-class="pic"/>
            </div>
            <div v-else class="icon">
              <svg-icon icon-class="file"/>
            </div>
            <a id="appUrl1" :href="file.url" target="view_window">
              <div class="info">{{ file.name }}</div>
            </a>
          </div>
        </div>
      </div>
      <div style="margin-left: 38%">
        <el-upload
          :action="action1"
          :on-success="uploadSuccess1"
          :on-error="uploadFailure1"
          :show-file-list="showFileList1"
          :file-list="fileList1"
          class="upload-demo"
          multiple>
          <el-button size="small" type="shengcheng" @click="batchImportOfDrawings1">点击上传</el-button>
        </el-upload>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible2" width="383px">
      <el-button type="distribution" icon="el-icon-plus" size="small" @click="addPayment">付款方式</el-button>
      <el-table
        :data="tableData2"
        highlight-current-row
        border
        stripe
        size="small"
        style="width: 341px; margin-top: 10px"
        height="402px">
        <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center"/>
        <el-table-column label="付款方式" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.付款方式 }}
          </template>
        </el-table-column>
        <el-table-column width="100px" label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="updatePayment(scope.row)"/>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="deletePayment(scope.row)"/>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible3" :title="title1" center width="360px">
      <el-form
        ref="form1"
        :model="form1"
        :rules="rules1"
        label-position="center"
        label-width="100px"
        class="demo-ruleForm">
        <el-form-item label="付款方式" prop="付款方式">
          <el-input v-model="form1.付款方式" style="width:150px;" placeholder="付款方式" size="small" clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="callOff1('form1')">取消</el-button>
        <el-button v-show="title1==='新增付款方式'" type="distribution" size="small" @click="submitAdd('form1')">确定
        </el-button>
        <el-button v-show="title1==='编辑付款方式'" type="distribution" size="small" @click="submitUpdate1('form1')">
          确定
        </el-button>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible4" width="813px">
      <el-cascader
        ref="cascader"
        :options="product"
        :show-all-levels="false"
        placeholder="产品名称"
        clearable
        size="small"
        @change="getData1"/>
      <el-button type="distribution" size="small" @click="submitAddParts()">多个提交</el-button>
      <span>&nbsp;组件：</span>
      <el-select
        v-model="groupNumberValue"
        size="small"
        placeholder="选择组件"
        clearable
        filterable
        style="width: 200px;margin: 10px 0 10px 3px">
        <el-option
          v-for="item in groupNumber"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <el-button type="distribution" size="small" @click="submitAddOldParts()">添加</el-button>
      <el-table
        :data="tableData10"
        :header-cell-style="{background: '#383E4B',color: 'white'}"
        highlight-current-row
        border
        stripe
        size="small"
        style="width: 791px"
        height="510px"
        @selection-change="handleSelectionChange"
        @row-dblclick="selectMaterial">
        <el-table-column type="selection" align="center" width="50px"/>
        <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center" prop="状态"/>
        <el-table-column :width="setColumnWidth('产品名称')" label="产品名称" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.产品名称 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center" show-overflow-tooltip prop="零件名称" sortable="零件名称">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column
          :width="setColumnWidth('图号或型号')"
          label="图号/型号"
          align="center"
          prop="图号或型号"
          sortable="图号或型号">
          <template slot-scope="scope">
            {{ scope.row.图号或型号 }}
          </template>
        </el-table-column>
        <el-table-column :width="setColumnWidth('数量')" label="数量" align="center" prop="数量">
          <template slot-scope="scope">
            {{ scope.row.数量 }}
          </template>
        </el-table-column>
        <el-table-column :width="setColumnWidth('数量')" label="库存" align="center" prop="库存">
          <template slot-scope="scope">
            {{ scope.row.累计库存 }}
          </template>
        </el-table-column>
        <el-table-column :width="setColumnWidth('材料')" label="材料" align="center">
          <template slot-scope="scope">
            {{ scope.row.材料 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40, 100]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible5" width="673px">
      <el-row style="margin-bottom: 10px">
        <span>名称：</span>
        <el-input v-model="materialName" placeholder="名称" style="width: 170px" size="small" clearable/>
        <span>图号/型号：</span>
        <el-input v-model="materialSpec" placeholder="图号/型号" style="width: 170px" size="small" clearable/>
        <el-button
          type="success"
          size="small"
          icon="el-icon-search"
          style="margin-left:10px"
          @click="pageCurrent1=1;pageSize1=10;total1=0;searchMaterial()">查询
        </el-button>
      </el-row>
      <el-table
        :data="tableData11"
        :header-cell-style="{background: '#383E4B',color: 'white'}"
        highlight-current-row
        border
        stripe
        size="small"
        style="width: 621px"
        height="510px"
        @row-dblclick="selectMaterial">
        <el-table-column align="center" label="名称">
          <template slot-scope="scope">
            {{ scope.row.名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="图号/型号">
          <template slot-scope="scope">
            {{ scope.row.代号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="库存">
          <template slot-scope="scope">
            {{ scope.row.库存 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="材料">
          <template slot-scope="scope">
            {{ scope.row.材料 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="pageCurrent1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize1"
          :total="total1"
          :pager-count="5"
          style="display:inline-block;width:50%"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisibleReturnContract" width="873px">
      <p style="font-size: 24px;margin: 0 auto">打回合同</p>
      <el-table
        :data="tableDataReturnContract"
        :header-cell-style="{background: '#383E4B',color: 'white'}"
        highlight-current-row
        border
        stripe
        size="small"
        style="width: 821px"
        height="510px"
        @row-click="viewIndividualContracts">
        <el-table-column width="50px" label="序号" type="index" align="center" prop="状态"/>
        <el-table-column width="130px" label="合同编号" align="center">
          <template slot-scope="scope">
            {{ scope.row.合同编号 }}
          </template>
        </el-table-column>
        <el-table-column width="75px" label="打回人" align="center">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column width="135px" label="打回时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.打回时间 }}
          </template>
        </el-table-column>
        <el-table-column label="打回原因" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.打回原因 }}
          </template>
        </el-table-column>
        <el-table-column width="75px" label="是否处理" align="center">
          <template slot-scope="scope">
            {{ scope.row.是否处理 }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible6" center width="1450px">
      <div style="width: 100%;overflow: hidden">
        <el-col>
          <el-select
            v-model="customerNameValue1"
            :remote-method="getCustomer"
            style="width:150px"
            placeholder="买方名称"
            size="small"
            filterable
            clearable
            remote
            @change="searchOldContract()">
            <el-option
              v-for="(item, index) in customerName"
              :key="index.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-select
            v-model="consigneePeopleValue"
            style="width:150px"
            placeholder="收货人"
            size="small"
            filterable
            clearable
            @change="searchOldContract()">
            <el-option
              v-for="(item, index) in consigneePeople"
              :key="index.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <span style="font-size: 13px;color: black">签订日期</span>
          <el-date-picker
            v-model="dateRange"
            size="small"
            type="daterange"
            align="center"
            style="width: 220px;"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            range-separator="～"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="searchOldContract"/>
          <el-button
            type="primary"
            icon="el-icon-check"
            plain
            size="small"
            style="margin-left: 50px"
            @click="submitOldContract()">提交
          </el-button>
        </el-col>
        <el-col style="width: 594px">
          <el-table
            :data="tableData1"
            :header-cell-style="{background: '#2283D4',color: 'white'}"
            highlight-current-row
            border
            stripe
            size="mini"
            style="width: 581px;margin-top: 10px;"
            height="440px"
            @row-click="searchTableA">
            <el-table-column width="140px" label="合同编号" align="center">
              <template slot-scope="scope">
                {{ scope.row.合同编号 }}
              </template>
            </el-table-column>
            <el-table-column label="客户名称" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.客户名称 }}
              </template>
            </el-table-column>
            <el-table-column width="100px" label="收货人" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.收货人 }}
              </template>
            </el-table-column>
            <el-table-column :width="setColumnWidth('日期')" label="签订日期" align="center">
              <template slot-scope="scope">
                {{ scope.row.签订日期 }}
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col style="width: 800px">
          <el-table
            :data="tableDataA"
            :header-cell-style="{background: '#2283D4',color: 'white'}"
            highlight-current-row
            border
            stripe
            size="mini"
            style="width: 581px;margin-top: 10px;"
            height="440px"
            @selection-change="handleSelectionChange1">
            <el-table-column type="selection" align="center" width="50px"/>
            <el-table-column label="规格品名" align="center">
              <template slot-scope="scope">
                {{ scope.row.规格品名 }}
              </template>
            </el-table-column>
            <el-table-column width="150px" label="单位" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.单位 }}
              </template>
            </el-table-column>
            <el-table-column width="100px" label="数量" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.数量 }}
              </template>
            </el-table-column>
            <el-table-column width="100px" label="单价" align="center">
              <template slot-scope="scope">
                {{ scope.row.单价 }}
              </template>
            </el-table-column>
            <el-table-column width="100px" label="金额" align="center">
              <template slot-scope="scope">
                {{ scope.row.金额 }}
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import $ from 'jquery'
import { MESDownloadFile, MESUploadFileProject } from '@/utils/request'

export default {
  data() {
    return {
      groupNumber: [],
      groupNumberValue: '',
      consigneePeople: [], // 收货人数组
      consigneePeopleValue: '', // 收货人
      numberReturnedItems: '',
      tableDataA: [],
      tableData10: [],
      tableData11: [],
      tableDataReturnContract: [],
      materialName: '',
      materialSpec: '',
      form1: {
        付款方式: ''
      },
      rules1: {
        付款方式: [{ required: true, message: '请输入付款方式', trigger: 'blur' }]
      },
      title: '',
      title1: '',
      paymentValue: '',
      tableData2: [],
      returns: [{
        产品名称: 'MT3#-1',
        数量: 2,
        配置: '配1.1KW4级电机，转速700，电机后置，配好拉杆',
        轴承型号: '标配',
        功率: '1.1KW4级',
        转速: '700',
        安装方向: '后置',
        三角带及带轮型号: '',
        同步带及带轮型号: '电机轮22齿，主轴轮40齿',
        多楔带及带轮型号: '',
        齿轮传动及齿轮型号: ''
      }],
      returns1: [{
        产品名称: 'MT3#-1',
        数量: 2,
        配置: '配1.1KW4级电机，转速700，电机后置，配好拉杆',
        轴承型号: '标配',
        功率: '1.1KW4级',
        转速: '700',
        安装方向: '后置',
        三角带及带轮型号: '',
        同步带及带轮型号: '电机轮22齿，主轴轮40齿',
        多楔带及带轮型号: '',
        齿轮传动及齿轮型号: ''
      }],
      peoples: '杨帆',
      contract: 'MK20210417001',
      date1: '2021.01.09',
      date2: '2021.01.19',
      TotalAmount: '',
      returns2: [],
      TotalAmount2: '',
      TotalAmount1: '',
      firstParty: '', // 甲方
      partyB: '', // 乙方
      addressA: '', // 甲地址
      number: '',
      date: '',
      disabled: false,
      dialogName: true,
      nodeName: [],
      loading: false,
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      dialogFormVisible4: false,
      dialogFormVisible5: false,
      dialogFormVisible6: false,
      dialogVisible1: false,
      dialogVisible2: false,
      dialogFormVisibleReturnContract: false,
      customerNameValue1: '',
      tableData1: [],
      dateRange: '',
      flag1: '',
      form: {
        客户名称: '',
        简称: '',
        省份: '',
        联系人: '',
        经理电话: '',
        收货人: '',
        联系电话: '',
        邮寄地址: '',
        电子邮箱: '',
        备注: ''
      },
      people: [],
      province: [],
      rules: {
        省份: [{ required: true, message: '请选择省份' }],
        客户名称: [{ required: true, message: '请输入客户名称' }],
        收货人: [{ required: true, message: '请输入收货人' }],
        联系电话: [{ required: true, message: '请输入收货电话' }],
        简称: [{ required: true, message: '请输入简称' }],
        经理电话: [{ required: true, message: '请输入联系电话' }],
        联系人: [{ required: true, message: '请输入联系人' }]
      },
      show: false, // 控制增加按钮的显示
      tableData: [], // 产品表
      tableData100: [],
      oldProject: '',
      taxRate1: '',
      product: [], // 产品数组
      productValue: '', // 产品数值
      productName: '', // 产品名称
      consignee: '',
      contractType: 1, // 合同类型
      contractNo: [], // 合同号数组
      contractNoValue: '', // 合同号值
      signingDate: '', // 签订日期
      taxRate: '', // 税率
      productValue1: '',
      deliveryDate: '', // 交货日期
      DeliveryPeriod: '', // 交货期限
      customerName: [], // 客户名称数组
      customerNameValue: '', // 客户名称值
      paymentMethod: [], // 付款方式数组
      paymentMethodValue: '', // 付款方式值
      customerRequirements: '', // 客户要求
      contractRemarks: '', // 合同备注
      MachineToolNumber: '',
      multipleSelection: [],
      multipleSelection_variable: [],
      multipleSelection1: [],
      multipleSelection_variable1: [],
      NumberValue: [],
      type: [],
      action: '',
      pageSize: 20,
      pageCurrent: 1,
      total: 0,
      pageSize1: 20,
      pageCurrent1: 1,
      total1: 0,
      showFileList: false,
      hadFile: [],
      fileList: [],
      action1: '',
      showFileList1: false,
      hadFile1: [],
      fileList1: []
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'id',
      'token'
    ])
  },
  watch: {
    '$route': {
      handler(route) {
        if (this.$route.query.模块名称 === '创建报价单') {
          var param = []
          var Data = this.CreateData('11', 'PDM_项目名称_查询数据', param)
          this.ExecDatabase(Data).then(response => {
            this.contractNoValue = response.data[0].项目流水号
            this.selectContract()
          })
        }
      },
      immediate: true
    }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs['table'].doLayout()
    })
  },
  created() {
    this.fetchData()
    this.unprocessedContract()
  },
  methods: {
    submitOldContract() {
      if (this.multipleSelection1.length > 0) {
        const NumberValue1 = []
        this.multipleSelection_variable1 = this.multipleSelection1
        this.multipleSelection1 = []
        for (let i = 0; i < this.multipleSelection_variable1.length; i++) {
          NumberValue1[i] = parseInt(this.multipleSelection_variable1[i].组件流水号)
        }
        var param = []
        param[0] = ['组件流水号组', NumberValue1]
        param[1] = ['机床流水号', this.MachineToolNumber]
        var Data = this.CreateData('12', 'PDM_项目名称_增加组件数据_通过老合同', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('添加成功')
            this.searchProduct()
            this.dialogFormVisible6 = false
          } else {
            this.$message.error('添加失败')
          }
        })
      }
    },
    unprocessedContract() {
      this.searchNumberReturnedItems()
      this.searchReturnContract()
    },
    viewReturnedContracts() {
      this.dialogFormVisibleReturnContract = true
    },
    searchNumberReturnedItems() {
      var param = []
      var Data = this.CreateData('11', 'PDM_项目名称_订单打回_记录表_模块合同_未处理数查询', param)
      this.ExecDatabase(Data).then(response => {
        this.numberReturnedItems = response.data[0].未处理数
      })
    },
    searchReturnContract() {
      var param = []
      var Data = this.CreateData('11', 'PDM_项目名称_订单打回_记录表_模块合同_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.tableDataReturnContract = response.data
      })
    },
    viewIndividualContracts(row) {
      if (row.是否处理 === '否') {
        this.contractNoValue = row.项目流水号
        this.selectContract()
        this.dialogFormVisibleReturnContract = false
      } else {
        this.$message.warning('该订单已经处理')
      }
    },
    fetchData() {
      this.getCustomer('')
      this.getConsigneePeople()
      this.getPaymentMethod()
      this.searchContract()
      this.getTreeData()
      this.getPeople()
      this.getProvince()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    submitAddOldParts() {
      if (this.MachineToolNumber) {
        if (this.multipleSelection.length > 0) {
          this.NumberValue = []
          this.type = []
          this.multipleSelection_variable = this.multipleSelection
          this.multipleSelection = []
          for (let i = 0; i < this.multipleSelection_variable.length; i++) {
            this.NumberValue[i] = parseInt(this.multipleSelection_variable[i].流水号)
            this.type[i] = parseInt(this.multipleSelection_variable[i].零件类型)
          }
          var param = []
          param[0] = ['机床流水号', this.MachineToolNumber]
          param[1] = ['组件流水号', this.groupNumberValue]
          param[2] = ['产品流水号', this.productValue1]
          param[3] = ['流水号组', this.NumberValue]
          param[4] = ['类型组', this.type]
          var Data = this.CreateData('12', 'PDM_组件名称_老组件_增加数据_批量零件', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('添加成功')
              this.searchProduct()
              this.dialogFormVisible4 = false
              this.dialogFormVisible5 = false
            } else {
              this.$message.error('添加失败')
            }
          })
        }
      } else {
        this.$message.warning('请先添加机床清单')
      }
    },
    submitAddParts() {
      if (this.MachineToolNumber) {
        if (this.multipleSelection.length > 0) {
          this.NumberValue = []
          this.type = []
          this.multipleSelection_variable = this.multipleSelection
          this.multipleSelection = []
          for (let i = 0; i < this.multipleSelection_variable.length; i++) {
            this.NumberValue[i] = parseInt(this.multipleSelection_variable[i].流水号)
            this.type[i] = parseInt(this.multipleSelection_variable[i].零件类型)
          }
          var param = []
          param[0] = ['机床流水号', this.MachineToolNumber]
          param[1] = ['产品流水号', this.productValue1]
          param[2] = ['流水号组', this.NumberValue]
          param[3] = ['类型组', this.type]
          var Data = this.CreateData('12', 'PDM_组件名称_增加数据_批量零件', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('添加成功')
              this.searchProduct()
              this.dialogFormVisible4 = false
              this.dialogFormVisible5 = false
            } else {
              this.$message.error('添加失败')
            }
          })
        }
      } else {
        this.$message.warning('请先添加机床清单')
      }
    },
    addBom() {
      if (this.MachineToolNumber) {
        this.groupNumberValue = ''
        this.groupNumber = []
        var param = []
        param[0] = ['机床流水号', this.MachineToolNumber]
        var Data = this.CreateData('11', 'PDM_组件名称_查询数据', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.groupNumber.push({
              value: response.data[i].组件流水号,
              label: response.data[i].产品名称
            })
          }
        })
        this.dialogFormVisible4 = true
      } else {
        this.$message.warning('请先添加机床清单')
      }
    },
    addMaterial() {
      if (this.MachineToolNumber) {
        this.dialogFormVisible5 = true
      } else {
        this.$message.warning('请先添加机床清单')
      }
    },
    selectMaterial(row) {
      if (this.MachineToolNumber) {
        var param = []
        param[0] = ['机床流水号', this.MachineToolNumber]
        param[1] = ['物料流水号', row.物料流水号]
        var Data = this.CreateData('12', 'PDM_组件名称_增加数据_零件', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('添加成功')
            this.searchProduct()
            this.dialogFormVisible4 = false
            this.dialogFormVisible5 = false
          } else {
            this.$message.error('添加失败')
          }
        })
      } else {
        this.$message.warning('请先添加机床清单')
      }
    },
    searchMaterial() {
      let materialName_check, materialSpec_check
      this.materialName ? materialName_check = 1 : materialName_check = 0
      this.materialSpec ? materialSpec_check = 1 : materialSpec_check = 0
      var param = []
      param[0] = ['名称_check', materialName_check]
      param[1] = ['名称', this.materialName]
      param[2] = ['代号_check', materialSpec_check]
      param[3] = ['代号', this.materialSpec]
      var Data = this.CreateData('11', '物料信息_查询新', param, this.pageSize1, this.pageCurrent1)
      this.ExecDatabase(Data).then(response => {
        this.tableData11 = response.data.rows
        this.total1 = response.data.total
      })
    },
    payment() {
      this.searchTable3()
      this.dialogFormVisible2 = true
    },
    searchTable3() {
      var param = []
      var Data = this.CreateData('11', '合同管理_付款方式_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData2 = response.data
      })
    },
    addPayment() {
      this.title1 = '新增付款方式'
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.dialogFormVisible3 = true
    },
    submitAdd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['付款方式', this.form1.付款方式]
          var Data = this.CreateData('11', '合同管理_付款方式_判断是否存在', param)
          this.ExecDatabase(Data).then(response => {
            if (Number(response.data[0].条数) >= 1) {
              this.$message.warning('添加的付款方式已存在')
            } else {
              var param = []
              param[0] = ['付款方式', this.form1.付款方式]
              var Data = this.CreateData('12', '合同管理_付款方式_新增', param)
              this.ExecDatabase(Data).then(response => {
                if (response.data[0].result === '1') {
                  this.$message.success('添加成功')
                  this.getPaymentMethod()
                  this.searchTable3()
                  this.dialogFormVisible3 = false
                } else {
                  this.$message.error('添加失败')
                }
              })
            }
          })
        }
      })
    },
    updatePayment(row) {
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.title1 = '编辑付款方式'
      this.form1.付款方式 = row.付款方式
      this.paymentValue = row.付款方式流水号
      this.dialogFormVisible3 = true
    },
    submitUpdate1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['付款方式', this.form1.付款方式]
          param[1] = ['付款方式流水号', this.paymentValue]
          var Data = this.CreateData('12', '合同管理_付款方式_编辑', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.getPaymentMethod()
              this.searchTable3()
              this.dialogFormVisible3 = false
            } else {
              this.$message.error('编辑失败')
            }
          })
        }
      })
    },
    deletePayment(row) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['付款方式流水号', row.付款方式流水号]
        var Data = this.CreateData('12', '合同管理_付款方式_作废', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.searchTable3()
          } else {
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    callOff1(formName) {
      this.form1.付款方式 = ''
      this.dialogFormVisible3 = false
      this.$refs[formName].resetFields()
    },
    ContractPhoto() {
      if (this.contractNoValue) {
        this.hadFile = []
        var param = []
        param[0] = ['项目流水号', this.contractNoValue]
        var Data = this.CreateData('11', 'PDM_项目名称_客户提供资料_查询数据', param)
        this.ExecDatabase(Data).then(res => {
          this.suffix = res.data
          if (res.data.length > 0) {
            const server = `${MESDownloadFile}`.split('/')
            res.data.map(item => {
              this.hadFile.push({
                url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
                name: `${item.name}.${item.suffix}`,
                suffix: item.suffix,
                id: item.num
              })
            })
          }
        })
        this.dialogVisible1 = true
      } else {
        this.$message.warning('请选择合同')
      }
    },
    deleteFileData(id) {
      var param = []
      param[0] = ['num', id]
      var Data = this.CreateData('12', 'PDM_项目名称_客户提供资料_删除数据', param)
      this.ExecDatabase(Data).then(res => {
        if (res.data[0].result === '1') {
          this.$message.success('删除成功')
          this.hadFile = []
          var param = []
          param[0] = ['项目流水号', this.projectValue]
          var Data = this.CreateData('11', 'PDM_项目名称_客户提供资料_查询数据', param)
          this.ExecDatabase(Data).then(res => {
            this.suffix = res.data
            if (res.data.length > 0) {
              const server = `${MESDownloadFile}`.split('/')
              res.data.map(item => {
                this.hadFile.push({
                  url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
                  name: `${item.name}.${item.suffix}`,
                  suffix: item.suffix,
                  id: item.num
                })
              })
            }
          })
        } else {
          this.$message.success('删除失败')
        }
      })
    },
    ContractPhoto1() {
      if (this.contractNoValue) {
        this.hadFile1 = []
        var param = []
        param[0] = ['项目流水号', this.contractNoValue]
        var Data = this.CreateData('11', 'PDM_项目名称_合同留存信息_查询数据', param)
        this.ExecDatabase(Data).then(res => {
          this.suffix = res.data
          if (res.data.length > 0) {
            const server = `${MESDownloadFile}`.split('/')
            res.data.map(item => {
              this.hadFile1.push({
                url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
                name: `${item.name}.${item.suffix}`,
                suffix: item.suffix,
                id: item.num
              })
            })
          }
        })
        this.dialogVisible2 = true
      } else {
        this.$message.warning('请选择合同')
      }
    },
    deleteFileData1(id) {
      var param = []
      param[0] = ['num', id]
      var Data = this.CreateData('12', 'PDM_项目名称_合同留存信息_删除数据', param)
      this.ExecDatabase(Data).then(res => {
        if (res.data[0].result === '1') {
          this.$message.success('删除成功')
          this.hadFile1 = []
          var param = []
          param[0] = ['项目流水号', this.projectValue]
          var Data = this.CreateData('11', 'PDM_项目名称_合同留存信息_查询数据', param)
          this.ExecDatabase(Data).then(res => {
            this.suffix = res.data
            if (res.data.length > 0) {
              const server = `${MESDownloadFile}`.split('/')
              res.data.map(item => {
                this.hadFile1.push({
                  url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
                  name: `${item.name}.${item.suffix}`,
                  suffix: item.suffix,
                  id: item.num
                })
              })
            }
          })
        } else {
          this.$message.success('删除失败')
        }
      })
    },
    batchImportOfDrawings() {
      this.action = `${MESUploadFileProject}?&num=1&tableName=PDM_项目名称_客户提供资料&type=1&UploaderName=${this.id}&projectValue=${this.contractNoValue}`
    },
    uploadSuccess(res, file, fileList) {
      if (res[0].result === '1') {
        const index = fileList.indexOf(file)
        fileList.splice(index, 1)
      } else {
        this.$message.error(`${file.name}文件上传失败，请检查上传文件是否正确！`)
      }
      if (fileList.length === 0) {
        this.ContractPhoto()
        this.$message.success('文件上传成功')
      }
    },
    uploadFailure(res, file, fileList) {
      fileList.map(file => {
        this.$message.error(`${file.name}文件上传失败，请检查上传文件是否正确！`)
      })
    },
    batchImportOfDrawings1() {
      if (this.contractNoValue) {
        this.action1 = `${MESUploadFileProject}?&num=1&tableName=PDM_项目名称_合同留存信息&type=1&UploaderName=${this.id}&projectValue=${this.contractNoValue}`
      } else {
        this.$message.warning('请选择合同')
      }
    },
    uploadSuccess1(res, file, fileList) {
      if (res[0].result === '1') {
        const index = fileList.indexOf(file)
        fileList.splice(index, 1)
      } else {
        this.$message.error(`${file.name}文件上传失败，请检查上传文件是否正确！`)
      }
      if (fileList.length === 0) {
        this.ContractPhoto1()
        this.$message.success('文件上传成功')
      }
    },
    uploadFailure1(res, file, fileList) {
      fileList.map(file => {
        this.$message.error(`${file.name}文件上传失败，请检查上传文件是否正确！`)
      })
    },
    exportTable() {
      const htmlNode = $('#WGBLD').html()
      const body = $('body')
      body.children().hide()
      const printNode = $(htmlNode)
      body.append(printNode)
      window.print()
      body.children().not('script').show()
      body.children().not('#app').hide()
      printNode.remove()
    },
    getTreeData() {
      var param = []
      param[0] = ['子节点', 0]
      var Data = this.CreateData('11', '产品关系_查询节点', param)
      this.ExecDatabase(Data).then(response => {
        const data = response.data
        this.product = this.tree(data, 0)
      })
    },
    tree(data, pid) {
      const result = []
      let temp
      for (let i = 0; i < data.length; i++) {
        if (data[i].父节点 === pid) {
          const obj = { label: data[i].节点名称, value: data[i].子节点 }
          temp = this.tree(data, data[i].子节点)
          if (temp.length > 0) {
            obj.children = temp
          }
          result.push(obj)
        }
      }
      return result
    },
    getPeople() {
      var param = []
      var Data = this.CreateData('11', '人员信息_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.people.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
    },
    getProvince() {
      var param = []
      var Data = this.CreateData('11', '省份信息_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.province.push({
            label: response.data[i].省份,
            value: response.data[i].省份流水号
          })
        }
      })
    },
    getCustomer(query) {
      this.customerName = []
      var param = []
      param[0] = ['客户名称', query]
      var Data = this.CreateData('11', '合同管理_客户信息_查询数据_bak', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.customerName.push({
            label: response.data[i].客户名称,
            value: response.data[i].客户流水号
          })
        }
      })
    },
    getCustomerById(queryId) {
      this.customerName = []
      var param = []
      param[0] = ['客户流水号', queryId]
      var Data = this.CreateData('11', '合同管理_客户信息_查询数据_通过ID_bak', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.customerName.push({
            label: response.data[i].客户名称,
            value: response.data[i].客户流水号
          })
        }
        this.customerNameValue = queryId
      })
    },
    getConsigneePeople() {
      this.consigneePeople = []
      var param = []
      var Data = this.CreateData('11', '合同管理_客户信息_收货人_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.consigneePeople.push({
            label: response.data[i].收货人,
            value: response.data[i].客户流水号
          })
        }
      })
    },
    getPaymentMethod() {
      this.paymentMethod = []
      var param = []
      var Data = this.CreateData('11', '合同管理_付款方式_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.paymentMethod.push({
            label: response.data[i].付款方式,
            value: response.data[i].付款方式流水号
          })
        }
      })
    },
    searchContract() {
      this.contractNo = []
      var param = []
      var Data = this.CreateData('11', 'PDM_项目名称_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.contractNo.push({
            label: response.data[i].合同编号,
            value: response.data[i].项目流水号
          })
        }
      })
    },
    productList() {
      var param = []
      var Data = this.CreateData('11', '产品信息_基础表_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.product.push({
            label: response.data[i].产品名称,
            value: response.data[i].产品名称,
            name: response.data[i].产品流水号
          })
        }
      })
    },
    oldContract() {
      this.firstParty = ''
      this.partyB = ''
      this.addressA = ''
      this.number = ''
      this.date = ''
      this.returns2 = []
      this.TotalAmount1 = ''
      this.TotalAmount2 = ''
      this.taxRate1 = ''
      this.dialogFormVisible1 = true
    },
    addOldContract() {
      if (this.MachineToolNumber) {
        this.tableDataA = []
        this.dialogFormVisible6 = true
      } else {
        this.$message.warning('请先添加机床清单')
      }
    },
    handleSelectionChange1(val) {
      this.multipleSelection1 = val
    },
    searchOldContract() {
      let check, check1, consigneePeopleValue_check
      this.customerNameValue1 ? check = 1 : check = 0
      this.consigneePeopleValue ? consigneePeopleValue_check = 1 : consigneePeopleValue_check = 0
      this.dateRange ? check1 = 1 : (check1 = 0, this.dateRange = '')
      var param1 = []
      param1[0] = ['客户流水号_check', check]
      param1[1] = ['客户流水号', this.customerNameValue1]
      param1[2] = ['时间_check', check1]
      param1[3] = ['开始时间', this.dateRange[0]]
      param1[4] = ['结束时间', this.dateRange[1]]
      param1[5] = ['合同类型', 1]
      param1[6] = ['收货人_check', consigneePeopleValue_check]
      param1[7] = ['收货人', this.consigneePeopleValue]
      var Data1 = this.CreateData('11', 'PDM_项目名称_查询老合同', param1)
      this.ExecDatabase(Data1).then(response => {
        this.tableData1 = response.data
      })
    },
    searchTable2(row) {
      this.oldProject = row.项目流水号
      this.firstParty = row.甲方
      this.partyB = row.客户名称
      this.addressA = row.签署地点
      this.number = row.合同编号
      this.date = row.签订日期
      this.taxRate1 = row.税率
      var param = []
      param[0] = ['项目流水号', row.项目流水号]
      param[1] = ['类型', 1]
      var Data = this.CreateData('11', 'PDM_项目名称_文本_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.returns2 = []
        for (let i = 0; i < response.data.length; i++) {
          this.returns2.push({
            序号: response.data[i].序号,
            规格品名: response.data[i].规格品名,
            单位: response.data[i].单位,
            数量: response.data[i].数量,
            单价: response.data[i].单价.toFixed(2),
            金额: response.data[i].金额.toFixed(2)
          })
        }
        this.TotalAmount1 = response.data[0].总金额
        this.TotalAmount2 = response.data[0].总金额_文本
      })
    },
    searchTableA(row) {
      var param = []
      param[0] = ['项目流水号', row.项目流水号]
      param[1] = ['类型', 1]
      var Data = this.CreateData('11', 'PDM_项目名称_老合同组件_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.tableDataA = []
        for (let i = 0; i < response.data.length; i++) {
          this.tableDataA.push({
            组件流水号: response.data[i].组件流水号,
            规格品名: response.data[i].规格品名,
            单位: response.data[i].单位,
            数量: response.data[i].数量,
            单价: response.data[i].单价.toFixed(2),
            金额: response.data[i].金额.toFixed(2)
          })
        }
      })
    },
    newContract(row) {
      if (this.oldProject === row.项目流水号) {
        var param = []
        param[0] = ['老项目流水号', row.项目流水号]
        param[1] = ['操作者', this.id]
        var Data = this.CreateData('12', 'PDM_项目名称_增加数据_通过老合同', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('创建成功')
            this.dialogFormVisible1 = false
            this.tableData = []
            this.customerNameValue = ''
            this.signingDate = ''
            this.paymentMethodValue = ''
            this.taxRate = ''
            this.deliveryDate = ''
            this.customerRequirements = ''
            this.contractRemarks = ''
            this.MachineToolNumber = ''
            var param1 = []
            var Data1 = this.CreateData('11', 'PDM_项目名称_查询数据', param1)
            this.ExecDatabase(Data1).then(response => {
              this.contractNo = []
              for (let i = 0; i < response.data.length; i++) {
                this.contractNo.push({
                  label: response.data[i].合同编号,
                  value: response.data[i].项目流水号
                })
              }
              this.contractNoValue = response.data[0].项目流水号
              this.selectContract()
            })
          } else {
            this.$message.error('创建失败')
          }
        })
      } else {
        this.$message.warning('请确认是否点击正确')
      }
    },
    addCustomer() {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '新增客户'
      this.dialogFormVisible = true
    },
    handleEdit() {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '编辑客户'
      if (this.customerNameValue) {
        var param1 = []
        param1[0] = ['客户流水号', this.customerNameValue]
        var Data1 = this.CreateData('11', '客户管理_查询收货人', param1)
        this.ExecDatabase(Data1).then(response => {
          this.form.省份 = parseInt(response.data[0].省份流水号)
          this.form.客户名称 = response.data[0].客户名称
          this.form.简称 = response.data[0].简称
          this.form.联系人 = response.data[0].联系人
          this.form.经理电话 = response.data[0].经理电话
          this.form.收货人 = response.data[0].收货人
          this.form.联系电话 = response.data[0].电话
          this.form.邮寄地址 = response.data[0].地址
          this.form.电子邮箱 = response.data[0].电子邮箱
          this.form.备注 = response.data[0].备注
          this.dialogFormVisible = true
        })
      } else {
        this.$message.warning('请先选择买方名称')
      }
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.flag1 === 1) {
            var param = []
            param[0] = ['省份', this.form.省份]
            param[1] = ['客户名称', this.form.客户名称]
            param[2] = ['简称', this.form.简称]
            param[3] = ['联系人', this.form.联系人]
            param[4] = ['经理电话', this.form.经理电话]
            param[5] = ['收货人', this.form.收货人]
            param[6] = ['联系电话', this.form.联系电话]
            param[7] = ['邮寄地址', this.form.邮寄地址]
            param[8] = ['电子邮箱', this.form.电子邮箱]
            param[9] = ['备注', this.form.备注]
            var Data = this.CreateData('12', '客户管理_客户信息_增加', param)
            this.ExecDatabase(Data).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('新增成功')
                this.dialogFormVisible = false
                this.customerName = []
                var param10 = []
                param10[0] = ['客户名称', this.form.客户名称]
                var Data10 = this.CreateData('11', '合同管理_客户信息_查询数据_bak', param10)
                this.ExecDatabase(Data10).then(response => {
                  for (let i = 0; i < response.data.length; i++) {
                    this.customerName.push({
                      label: response.data[i].客户名称,
                      value: response.data[i].客户流水号
                    })
                    this.customerNameValue = response.data[0].客户流水号
                    if (this.customerNameValue < response.data[i].客户流水号) {
                      this.customerNameValue = response.data[i].客户流水号
                    }
                  }
                  this.consignee = this.form.收货人
                })
              } else {
                this.$message.success('新增失败')
              }
            })
            this.flag1 = ''
          } else if (this.flag1 === 2) {
            var param1 = []
            param1[0] = ['省份', this.form.省份]
            param1[1] = ['客户名称', this.form.客户名称]
            param1[2] = ['简称', this.form.简称]
            param1[3] = ['联系人', this.form.联系人]
            param1[4] = ['经理电话', this.form.经理电话]
            param1[5] = ['收货人', this.form.收货人]
            param1[6] = ['联系电话', this.form.联系电话]
            param1[7] = ['邮寄地址', this.form.邮寄地址]
            param1[8] = ['电子邮箱', this.form.电子邮箱]
            param1[9] = ['备注', this.form.备注]
            param1[10] = ['客户流水号', this.customerNameValue]
            var Data1 = this.CreateData('12', '客户管理_客户信息_编辑', param1)
            this.ExecDatabase(Data1).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.dialogFormVisible = false
                var param = []
                param[0] = ['项目流水号', this.contractNoValue]
                param[1] = ['收货人', this.form.收货人]
                var Data = this.CreateData('12', 'PDM_项目名称_编辑数据_收货人', param)
                this.ExecDatabase(Data)
                this.consignee = this.form.收货人
              } else {
                this.$message.success('编辑失败')
              }
            })
            this.flag1 = ''
          }
          /* var param1 = []
          param1[0] = ['省份', this.form.省份]
          param1[1] = ['客户名称', this.form.客户名称]
          param1[2] = ['简称', this.form.简称]
          param1[3] = ['联系人', this.form.联系人]
          param1[4] = ['经理电话', this.form.经理电话]
          param1[5] = ['收货人', this.form.收货人]
          param1[6] = ['联系电话', this.form.联系电话]
          param1[7] = ['邮寄地址', this.form.邮寄地址]
          param1[8] = ['电子邮箱', this.form.电子邮箱]
          param1[9] = ['备注', this.form.备注]
          param1[10] = ['客户流水号', this.customerNameValue]
          var Data1 = this.CreateData('12', '客户管理_客户信息_编辑', param1)
          this.ExecDatabase(Data1).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.dialogFormVisible = false
              var param = []
              param[0] = ['项目流水号', this.contractNoValue]
              param[1] = ['收货人', this.form.收货人]
              var Data = this.CreateData('12', 'PDM_项目名称_编辑数据_收货人', param)
              this.ExecDatabase(Data)
              this.consignee = this.form.收货人
            } else {
              this.$message.success('编辑失败')
            }
          })*/
        }
      })
    },
    callOff(formName) {
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    selectContract() {
      if (this.contractNoValue) {
        var param = []
        param[0] = ['项目流水号', this.contractNoValue]
        var Data = this.CreateData('11', 'PDM_项目名称_详情_查询数据', param)
        this.ExecDatabase(Data).then(response => {
          this.getCustomerById(response.data[0].客户流水号)
          this.signingDate = response.data[0].签订日期
          this.consignee = response.data[0].收货人员
          this.paymentMethodValue = response.data[0].付款方式流水号
          this.taxRate = response.data[0].税率
          this.deliveryDate = response.data[0].交货期限
          this.customerRequirements = response.data[0].客户要求
          this.contractRemarks = response.data[0].合同备注
          this.MachineToolNumber = response.data[0].机床流水号
          this.searchProduct()
        })
      } else {
        this.customerNameValue = ''
        this.signingDate = ''
        this.paymentMethodValue = ''
        this.taxRate = ''
        this.deliveryDate = ''
        this.customerRequirements = ''
        this.contractRemarks = ''
        this.MachineToolNumber = ''
        this.consignee = ''
        this.tableData100 = []
        this.tableData = []
      }
    },
    createContract() {
      if (!this.contractNoValue) {
        var param = []
        param[0] = ['合同类型', this.contractType]
        param[1] = ['操作者', this.id]
        var Data = this.CreateData('12', 'PDM_项目名称_增加数据', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('创建成功')
            this.tableData = []
            this.customerNameValue = ''
            this.signingDate = ''
            this.paymentMethodValue = ''
            this.taxRate = ''
            this.deliveryDate = ''
            this.customerRequirements = ''
            this.contractRemarks = ''
            this.MachineToolNumber = ''
            var param1 = []
            var Data1 = this.CreateData('11', 'PDM_项目名称_查询数据', param1)
            this.ExecDatabase(Data1).then(response => {
              this.contractNo = []
              for (let i = 0; i < response.data.length; i++) {
                this.contractNo.push({
                  label: response.data[i].合同编号,
                  value: response.data[i].项目流水号
                })
              }
              this.contractNoValue = response.data[0].项目流水号
              this.selectContract()
            })
          } else {
            this.$message.error('创建失败')
          }
        })
      } else {
        this.$confirm('当前合同还未提交, 是否继续新增合同?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          var param = []
          param[0] = ['合同类型', this.contractType]
          param[1] = ['操作者', this.id]
          var Data = this.CreateData('12', 'PDM_项目名称_增加数据', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('创建成功')
              this.tableData = []
              this.customerNameValue = ''
              this.signingDate = ''
              this.paymentMethodValue = ''
              this.taxRate = ''
              this.deliveryDate = ''
              this.customerRequirements = ''
              this.contractRemarks = ''
              this.MachineToolNumber = ''
              var param1 = []
              var Data1 = this.CreateData('11', 'PDM_项目名称_查询数据', param1)
              this.ExecDatabase(Data1).then(response => {
                this.contractNo = []
                for (let i = 0; i < response.data.length; i++) {
                  this.contractNo.push({
                    label: response.data[i].合同编号,
                    value: response.data[i].项目流水号
                  })
                }
                this.contractNoValue = response.data[0].项目流水号
                this.selectContract()
              })
            } else {
              this.$message.error('创建失败')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    },
    editContract() {
      if (this.customerNameValue) {
        var param1 = []
        param1[0] = ['客户流水号', this.customerNameValue]
        var Data1 = this.CreateData('11', '客户管理_查询收货人', param1)
        this.ExecDatabase(Data1).then(response => {
          this.consignee = response.data[0].收货人
          if (this.contractNoValue) {
            var param = []
            param[0] = ['项目流水号', this.contractNoValue]
            param[1] = ['客户流水号', this.customerNameValue]
            param[2] = ['签订日期', this.signingDate]
            param[3] = ['付款方式流水号', this.paymentMethodValue]
            param[4] = ['税率', this.taxRate]
            param[5] = ['交货期限', this.deliveryDate]
            param[6] = ['客户要求', this.customerRequirements]
            param[7] = ['合同备注', this.contractRemarks]
            param[8] = ['操作者', this.id]
            param[9] = ['收货人', this.consignee]
            var Data = this.CreateData('12', 'PDM_项目名称_编辑数据', param)
            this.ExecDatabase(Data).then(response => {
              if (response.data[0].result === '0') {
                this.$message.error('信息填充或更改失败')
              }
            })
          }
        })
      } else {
        this.consignee = ''
        if (this.contractNoValue) {
          var param = []
          param[0] = ['项目流水号', this.contractNoValue]
          param[1] = ['客户流水号', this.customerNameValue]
          param[2] = ['签订日期', this.signingDate]
          param[3] = ['付款方式流水号', this.paymentMethodValue]
          param[4] = ['税率', this.taxRate]
          param[5] = ['交货期限', this.deliveryDate]
          param[6] = ['客户要求', this.customerRequirements]
          param[7] = ['合同备注', this.contractRemarks]
          param[8] = ['操作者', this.id]
          param[9] = ['收货人', this.consignee]
          console.log(this.consignee, 456)
          var Data = this.CreateData('12', 'PDM_项目名称_编辑数据', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '0') {
              this.$message.error('信息填充或更改失败')
            }
          })
        }
      }
      console.log(this.contractNoValue, 789)
    },
    searchProduct() {
      this.tableData100 = []
      if (this.MachineToolNumber) {
        var param = []
        param[0] = ['机床流水号', this.MachineToolNumber]
        var Data = this.CreateData('11', 'PDM_组件名称_查询数据', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.tableData100.push({
              组件流水号: response.data[i].组件流水号,
              物料流水号: response.data[i].物料流水号,
              产品名称: response.data[i].产品名称,
              产品详情: response.data[i].产品详情,
              单位: response.data[i].单位,
              单价: response.data[i].单价,
              数量: response.data[i].数量,
              顺序: response.data[i].顺序,
              是否可选: response.data[i].是否可选,
              产品位置: response.data[i].产品位置 ? response.data[i].产品位置.split(',').map(Number) : [],
              产品流水号: response.data[i].产品流水号,
              原产品名称: response.data[i].产品名称,
              原产品流水号: response.data[i].产品流水号,
              原产品详情: response.data[i].产品详情,
              原单位: response.data[i].单位,
              原单价: response.data[i].单价,
              原数量: response.data[i].数量,
              原顺序: response.data[i].顺序,
              edit: false
            })
          }
        }).then(() => {
          this.tableData = this.tableData100
        })
      }
    },
    changeState(row) {
      this.productName = row.产品名称
      this.productValue = row.产品流水号
      row.edit = !row.edit
    },
    createProduct(val) {
      if (this.MachineToolNumber) {
        var param = []
        param[0] = ['机床流水号', this.MachineToolNumber]
        param[1] = ['是否可选', val]
        var Data = this.CreateData('12', 'PDM_组件名称_增加数据', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('添加成功')
            this.searchProduct()
          } else {
            this.$message.error('添加失败')
          }
        })
      } else {
        this.$message.warning('请先添加机床清单')
      }
    },
    getData(val) {
      this.productValue = val[val.length - 1]
      var param = []
      param[0] = ['产品流水号', this.productValue]
      var Data = this.CreateData('11', '产品关系_获取产品名称', param)
      this.ExecDatabase(Data).then(response => {
        this.productName = response.data[0].产品名称
      })
    },
    getData1(val) {
      this.productValue1 = val[val.length - 1]
      this.searchTable10()
    },
    searchTable10() {
      let productValue_check
      this.productValue1 ? productValue_check = 1 : productValue_check = 0
      var param = []
      param[0] = ['产品流水号_check', productValue_check]
      param[1] = ['产品流水号', this.productValue1]
      param[2] = ['时间_check', 0]
      param[3] = ['开始时间', '']
      param[4] = ['结束时间', '']
      param[5] = ['零件类型_check', 0]
      param[6] = ['零件类型', '']
      param[7] = ['排序名称', '']
      param[8] = ['排序方式', '']
      var Data = this.CreateData('11', '产品信息_BOM查询', param, this.pageSize, this.pageCurrent)
      this.ExecDatabase(Data).then(response => {
        this.tableData10 = response.data.rows
        this.total = response.data.total
      })
    },
    editProduct(row) {
      var param = []
      param[0] = ['组件流水号', row.组件流水号]
      if (row.是否可选 === 1) {
        param[1] = ['产品名称', this.productName]
        param[6] = ['产品流水号', this.productValue]
        param[7] = ['产品位置', row.产品位置.join(',')]
      } else {
        param[1] = ['产品名称', row.产品名称]
        param[6] = ['产品流水号', 0]
        param[7] = ['产品位置', '']
      }
      param[2] = ['产品详情', row.产品详情]
      param[3] = ['单位', row.单位]
      param[4] = ['数量', row.数量]
      param[5] = ['单价', row.单价]
      param[8] = ['配置数', row.数量]
      param[9] = ['顺序', row.顺序]
      var Data = this.CreateData('12', 'PDM_组件名称_编辑数据', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('编辑成功')
          this.searchProduct()
        } else {
          this.$message.error('编辑失败')
        }
      })
    },
    cancel(row) {
      row.产品名称 = row.原产品名称
      row.产品详情 = row.原产品详情
      row.单位 = row.原单位
      row.单价 = row.原单价
      row.数量 = row.原数量
      row.顺序 = row.原顺序
      row.edit = false
    },
    deleteProduct(row) {
      var param = []
      param[0] = ['组件流水号', row.组件流水号]
      var Data = this.CreateData('12', 'PDM_组件名称_删除数据', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('删除成功')
          this.searchProduct()
        } else {
          this.$message.error('删除失败')
        }
      })
    },
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        } else if (index === 3) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 6) {
          const values = data.map(item => Number(item['数量']) * Number(item['单价']))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        }
      })
      return sums
    },
    submitContract() {
      if (this.contractNoValue) {
        if (this.customerNameValue && this.paymentMethodValue && this.taxRate && this.tableData.length !== 0 && this.deliveryDate && this.signingDate) {
          for (let i = 0; i < this.tableData.length; i++) {
            if (this.tableData[i].产品名称 === null || this.tableData[i].产品名称 === '') {
              this.$message.warning('产品不能为空')
              return
            }
            if (this.tableData[i].单位 === null || this.tableData[i].单位 === '') {
              this.$message.warning('单位不能为空')
              return
            }
            if (this.tableData[i].数量 === null || this.tableData[i].数量 === '') {
              this.$message.warning('数量不能为空')
              return
            }
            if (this.tableData[i].单价 === null || this.tableData[i].单价 === '') {
              this.$message.warning('单价不能为空')
              return
            }
          }
          var param = []
          param[0] = ['项目流水号', this.contractNoValue]
          param[1] = ['合同类型', this.contractType]
          param[2] = ['提交人', this.id]
          var Data = this.CreateData('12', 'PDM_项目名称_提交数据', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('提交成功')
              this.tableData = []
              this.contractNoValue = ''
              this.customerNameValue = ''
              this.signingDate = ''
              this.paymentMethodValue = ''
              this.deliveryDate = ''
              this.customerRequirements = ''
              this.contractRemarks = ''
              this.MachineToolNumber = ''
              this.taxRate = ''
              this.consignee = ''
              this.searchContract()
              this.unprocessedContract()
            } else {
              this.$message.error('提交失败')
            }
          })
        } else {
          this.$message.warning('数据不完整')
        }
      } else {
        this.$message.warning('请先选择合同')
      }
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.searchMaterial()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchMaterial()
    },
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable10()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable10()
    }
  }
}
</script>
<style scoped lang="scss">
/deep/ .el-input__inner {
  border: none !important;
  border-radius: 0px;
  border-bottom: 1px solid #676767 !important
}
</style>
<style scoped>
.wrapper {
  width: 90%;
  height: 50px;
  overflow: hidden;
  border: 1px solid #b8c7d9;
  /*float: left;*/
  margin: 10px;
}

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

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

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

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

a {
  text-decoration: none;
}

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

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