<template>
  <div class="app-container">
    <el-card>
      <div>
        <span>项目名称：</span>
        <el-select v-model="entryNameValue" clearable filterable placeholder="项目名称" size="small">
          <el-option
            v-for="item in entryName"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span style="margin-left: 10px">机床型号：</span>
        <el-input v-model="machine" clearable size="small" style="width:200px" placeholder="请输入机床型号"/>
        <span style="margin-left: 10px">销售经理：</span>
        <el-input v-model="MarketingManagerValue" readonly clearable size="small" style="width:200px" placeholder="请选择营销经理" @dblclick.native="openName();param = 1" @clear="clear()"/>
      </div>
      <div style="margin-top: 20px">
        <span style="margin-top: 20px">开始日期：</span>
        <el-date-picker
          v-model="startTime"
          style="width: 200px;"
          value-format="yyyy-MM-dd"
          size="small"
          type="date"
          placeholder="请选择开始日期"/>
        <span style="margin-left: 10px">结束日期：</span>
        <el-date-picker
          v-model="endTime"
          style="width: 200px;"
          value-format="yyyy-MM-dd"
          size="small"
          type="date"
          placeholder="请选择结束日期"/>
        <el-button type="success" icon="el-icon-search" size="small" style="margin-left: 10px" @click="PageSize = 10;PageCurrent = 1;fetchTableData1()">查询</el-button>
        <el-button type="primary" icon="el-icon-circle-plus-outline" size="small" style="margin-left: 10px" @click="ADD()">增加</el-button>
      </div>
    </el-card>
    <el-card>
      <el-table
        v-loading="listLoading"
        :data="tableData1"
        :row-key="getRowKeys"
        :expand-row-keys="expands"
        style="width: 100%"
        height="460"
        border
        size="mini"
        @row-click="fetchExecutionProgressdata"
        @expand-change="selectMachine">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-table :data="tableData2" border style="width: 491px; text-align: center" size="mini">
              <el-table-column label="设备型号" align="center" width="130">
                <template slot-scope="scope">
                  {{ scope.row.机床图号 }}
                </template>
              </el-table-column>
              <el-table-column label="设备名称" align="center" width="160">
                <template slot-scope="scope">
                  {{ scope.row.机床名称 }}
                </template>
              </el-table-column>
              <el-table-column label="操作" width="200" align="center">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="warning"
                    icon="el-icon-edit"
                    @click="editMachine(scope.row);flag = 2">编辑</el-button>
                  <el-button
                    size="mini"
                    type="danger"
                    icon="el-icon-delete"
                    @click="deleteMachine(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column align="center" label="合同编号" width="150">
          <template slot-scope="scope">
            <template>
              <el-popover
                placement="right"
                title="投标保证金情况"
                width="300"
                trigger="hover">
                <div v-show="!scope.row.招标企业" style="text-align: center">
                  <h4>未缴纳投标保证金</h4>
                </div>
                <div v-show="scope.row.招标企业">
                  <h4>招标企业： {{ scope.row.招标企业 }}</h4>
                  <h4>投标保证金金额： {{ scope.row.保证金金额 }}</h4>
                  <h4>是否收回： {{ parseInt(scope.row.是否收回) === 1 ? '未收回' : '已收回' }}</h4>
                </div>
                <el-tag slot="reference">{{ scope.row.合同编号 }}</el-tag>
              </el-popover>
            </template>
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目名称" width="200">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="付款方式" width="80">
          <template slot-scope="scope">
            {{ scope.row.付款方式 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="合同签订日期" width="150">
          <template slot-scope="scope">
            {{ scope.row.合同签订日期 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="图纸会签节点" width="150">
          <template slot-scope="scope">
            {{ scope.row.图纸会签节点 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="设备预验收节点" width="150">
          <template slot-scope="scope">
            {{ scope.row.设备预验收节点 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="发货节点" width="150">
          <template slot-scope="scope">
            {{ scope.row.发货节点 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="安装调试节点" width="150">
          <template slot-scope="scope">
            {{ scope.row.安装调试节点 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="销售经理" width="80">
          <template slot-scope="scope">
            {{ scope.row.营销经理 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="客户名称" width="260">
          <template slot-scope="scope">
            {{ scope.row.客户名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="联系人" width="80">
          <template slot-scope="scope">
            {{ scope.row.联系人 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="联系电话" width="150">
          <template slot-scope="scope">
            {{ scope.row.电话 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="合同信息备注" width="250">
          <template slot-scope="scope">
            {{ scope.row.合同信息备注 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="300">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              icon="el-icon-plus"
              @click.stop="addMachine(scope.row);flag = 1">机床</el-button>
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click.stop="handleEdit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              @click.stop="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="PageCurrent"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="PageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
    <el-card v-show="ExecutionProgressShow">
      <div>
        <h4 style="display: inline-block">项目进度</h4>
        <div style="display: inline-block; float:right">
          <span>已完成进度：</span>
          <el-select v-model="executionProgressID" placeholder="请输入目前执行进度" size="small" style="width: 130px;margin-left: 20px" @change="changeExecutionProgressID">
            <el-option
              v-for="item in executionProgress"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled ="item.disabled"/>
          </el-select>
        </div>
      </div>
      <div>
        <el-steps :active="ExecutionProgress" finish-status="success" process-status="process " style="margin-left: 10px">
          <el-step :description="time1" title="签订合同" icon="el-icon-edit-outline"/>
          <el-step :description="time2" title="图纸会签" icon="el-icon-picture-outline"/>
          <el-step :description="time3" title="加工制造" icon="el-icon-setting"/>
          <el-step :description="time4" title="预备验收" icon="el-icon-view"/>
          <el-step :description="time5" title="设备发货" icon="el-icon-sold-out"/>
          <el-step :description="time6" title="安装调试" icon="el-icon-time"/>
          <el-step :description="time7" title="项目终验收" icon="el-icon-circle-check-outline"/>
          <el-step :description="time8" title="质保阶段" icon="el-icon-service"/>
        </el-steps>
      </div>
    </el-card>
    <el-card v-show="uploader" style="min-height: 145px;">
      <h4>纪要文件</h4>
      <div style="float: right;">
        <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="primary">点击上传</el-button>
        </el-upload>
      </div>
      <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 :href="file.url"><div class="info">{{ file.name }}</div></a>
          </div>
        </div>
      </div>
    </el-card>
    <!--新增合同信息对话框-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible1" center style="min-height: 300px" width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-position="left" label-width="140px" class="demo-ruleForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="EntryName">
              <el-input v-model="form.EntryName" size="small" placeholder="请输入项目名称" style="width:200px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投标保证金" prop="">
              <el-input v-model="form.bidding" readonly clearable size="small" style="width:200px" placeholder="若缴纳保证金请选择" @dblclick.native="openBidding()" @clear="clearBidding()"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="已完成进度" prop="executionProgressID">
              <el-select v-model="form.executionProgressID" :disabled="infoDisable" placeholder="请输入目前执行进度" size="small" style="width: 200px">
                <el-option
                  v-for="item in executionProgress"
                  :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="MarketingManagerValue">
              <el-input v-model="form.MarketingManagerValue" readonly clearable size="small" style="width:200px" placeholder="请双击选择营销经理" @dblclick.native="openName()" @clear="clear()"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同签订日期" prop="contractSigningDate">
              <el-date-picker
                v-model="form.contractSigningDate"
                value-format="yyyy-MM-dd"
                size="small"
                type="date"
                placeholder="请选择图纸会签节点"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图纸会签节点" prop="drawingJointSignNode">
              <el-date-picker
                v-model="form.drawingJointSignNode"
                value-format="yyyy-MM-dd"
                size="small"
                type="date"
                placeholder="请选择图纸会签节点"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备预验节点" prop="EquipmentPreAcceptanceNode">
              <el-date-picker
                v-model="form.EquipmentPreAcceptanceNode"
                value-format="yyyy-MM-dd"
                size="small"
                type="date"
                placeholder="请选择设备预验收节点"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发货节点" prop="ConsignmentNode">
              <el-date-picker
                v-model="form.ConsignmentNode"
                value-format="yyyy-MM-dd"
                size="small"
                type="date"
                placeholder="请选择发货节点"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安装调试节点" prop="installDebugNode">
              <el-date-picker
                v-model="form.installDebugNode"
                value-format="yyyy-MM-dd"
                size="small"
                type="date"
                placeholder="请选择安装调试节点"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="customerName">
              <el-input v-model="form.customerName" readonly size="small" placeholder="请双击选择客户" style="width:200px" clearable @dblclick.native="CustomerChange()" @clear="clear1()"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款方式" prop="付款方式">
              <el-select v-model="form.付款方式" :disabled="disabled" placeholder="请选择付款方式" size="small" style="width: 200px">
                <el-option
                  v-for="item in money"
                  :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="remark">
              <el-input
                v-model="form.remark"
                style="width: 200px"
                type="textarea"
                autosize
                placeholder="请输入项目介绍"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff('form')">取消</el-button>
        <el-button type="primary" @click="submit('form')">确 定</el-button>
      </div>
    </el-dialog>

    <!--新增机床对话框-->
    <el-dialog :title="title1" :visible.sync="dialogFormVisible2" center style="min-height: 300px" width="450px">
      <el-form ref="form1" :model="form1" :rules="rules1" label-width="140px">
        <el-form-item label="设备型号" prop="设备型号">
          <el-input v-model="form1.设备型号" size="small" placeholder="请输入设备型号" style="width:200px"/>
        </el-form-item>
        <el-form-item label="设备名称" prop="设备名称">
          <el-input v-model="form1.设备名称" size="small" placeholder="请输入设备名称" style="width:200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff2('form1')">取消</el-button>
        <el-button type="primary" @click="submitMachine('form1')">确 定</el-button>
      </div>
    </el-dialog>

    <!--营销经理选择-->
    <el-dialog :visible.sync="dialogFormVisiblePeople" title="营销经理" center width="500px">
      <span>责权省份：</span>
      <el-select v-model="ProvinceValue" clearable filterable placeholder="请选择省份" style="margin-right: 10px" size="small" @change="changeProvince">
        <el-option
          v-for="item in Province"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <div style="margin-top: 15px">
        <el-table :data="tableData3" border style="width: 100%; text-align: center;" highlight-current-row @row-click="handleChange">
          <el-table-column label="销售经理" align="center" >
            <template slot-scope="scope">
              {{ scope.row.姓名 }}
            </template>
          </el-table-column>
          <el-table-column label="性别" align="center">
            <template slot-scope="scope">
              {{ scope.row.性别 }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="offName">取消</el-button>
        <el-button type="primary" @click="getName">确认</el-button>
      </div>
    </el-dialog>

    <!--投标保证金选择-->
    <el-dialog :visible.sync="dialogFormVisibleBidding" title="请选择投标保证金" center width="65%">
      <span>招标企业：</span>
      <el-input v-model="enterprise" size="small" style="width:200px" clearable/>
      <el-button type="success" icon="el-icon-search" size="small" style="margin-left: 10px" @click="searchBidding">查询</el-button>
      <div style="margin-top: 15px">
        <el-table
          :data="tableDataBidding"
          highlight-current-row
          style="width: 100%"
          height="400"
          border
          @row-click="biddingNum">
          <el-table-column align="center" label="招标企业" width="300">
            <template slot-scope="scope">
              {{ scope.row.招标企业 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="联系人" width="100">
            <template slot-scope="scope">
              {{ scope.row.联系人 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="联系电话" width="120">
            <template slot-scope="scope">
              {{ scope.row.联系电话 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="保证金金额" width="100">
            <template slot-scope="scope">
              {{ scope.row.保证金金额 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="投标人" width="100">
            <template slot-scope="scope">
              {{ scope.row.投标人 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="保金类型" width="150">
            <template slot-scope="scope">
              {{ scope.row.保证金类型 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="投标日期" width="150">
            <template slot-scope="scope">
              {{ scope.row.投标日期 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="备注">
            <template slot-scope="scope">
              {{ scope.row.备注 }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="offBidding">取消</el-button>
        <el-button type="primary" @click="getBidding">确认</el-button>
      </div>
    </el-dialog>

    <!--客户选择-->
    <el-dialog :visible.sync="dialogCustomerFormVisible" title="客户选择" center width="800px">
      <el-input v-model="Customer" clearable size="small" style="width:200px" placeholder="请输入客户名称"/>
      <el-button type="success" icon="el-icon-search" size="small" style="margin-left: 10px" @click="PageSize1 = 10;PageCurrent1 = 1;fetchCustomerData()">查询</el-button>
      <el-table v-loading="loading1" :data="CustomerData" highlight-current-row height="300" show-overflow-tooltip style="height: 330px; margin-top: 20px" @row-click="handleCustomerChange">
        <el-table-column label="省份" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.省份 }}
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center" >
          <template slot-scope="scope">
            {{ scope.row.客户名称 }}
          </template>
        </el-table-column>
        <el-table-column label="联系人" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.联系人 }}
          </template>
        </el-table-column>
        <el-table-column label="联系电话" align="center">
          <template slot-scope="scope">
            {{ scope.row.电话 }}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="PageCurrent1"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="PageSize1"
        :total="total1"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1"/>
      <div slot="footer" class="dialog-footer">
        <el-button @click="offCustomerChange">取消</el-button>
        <el-button type="primary" @click="getCustomerCode">确 定</el-button>
      </div>
    </el-dialog>

    <!--改变节点时间对话框-->
    <el-dialog :visible.sync="dialogTimeVisible" :show-close="false" :close-on-click-modal="false" title="进度完成时间" center style="min-height: 300px" width="400px">
      <el-form ref="form2" :model="form2" :rules="rules2" :disabled="disabledTime" label-width="140px">
        <el-form-item label="进度完成日期" prop="进度完成日期">
          <el-date-picker
            v-model="form2.进度完成日期"
            style="width: 200px;"
            value-format="yyyy-MM-dd"
            size="small"
            type="date"
            placeholder="请选择进度完成日期"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOffTime('form2')">取消</el-button>
        <el-button type="primary" @click="submitTime('form2')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import elInput from 'element-ui/packages/input'
import { searchTimeAll, searchTime, selectBidBond, changeExecutionProgressID, initProject, searchTable1, fetchExecutionProgress, delList, addList, executionProgressID, editchar, getTree, tree, getTablePeople, fetchCustomerData, getFileData, deleteFileData, selectMachine, selectProvince, SelectMarketingManager, submitMachine, editMachine, delMachine, money } from '@/api/MarketingCenter/ContractInformationManagement'
import { upload, download } from '@/utils/request'
export default {
  components: {
    elInput
  },
  data() {
    return {
      a: 1,
      b: 1,
      c: 1,
      time1: '',
      time2: '',
      time3: '',
      time4: '',
      time5: '',
      time6: '',
      time7: '',
      time8: '',
      machine: '',
      machine_check: '',
      disabledTime: false,
      dialogTimeVisible: false,
      executionProgressIDdisabled: false,
      enterpriseInput: '', // 表单承接招标企业的中间变量
      biddingNumber: '',
      dialogFormVisibleBidding: false,
      enterprise: '', // 招标企业
      startTime: '',
      startTime_check: null,
      endTime: '',
      endTime_check: null,
      money: [],
      expands: [],
      flag: '',
      title1: '',
      dialogFormVisible2: false,
      ProvinceValue: '',
      Province: [],
      CustomerCode: '',
      loading1: false,
      CustomerData: [],
      Customer: '',
      id1: '',
      action: '',
      peoplename: '',
      peopleid_check: null,
      peopleid: '',
      dataPeople: [],
      ListPeople: [],
      fileList: [],
      hadFile: [],
      disabled: false,
      projectNum: null,
      dialogFormVisiblePeople: false,
      dialogFormVisiblePeople1: false,
      dialogCustomerFormVisible: false,
      listLoading: false,
      showFileList: true,
      entryNameValue: '', // 项目名称下拉框
      entryNameValue_check: null,
      entryName: [], // 项目名称下拉框数据
      list1: [], // 项目名称临时存储
      MarketingManagerValue: '', // 营销经理下拉框
      MarketingManager: [], // 营销经理下拉框数据
      list2: [], // 营销经理临时存储
      tableData1: [], // 合同信息表
      tableData2: [], // 机床信息表
      tableData3: [], // 营销经理表
      PageCurrent: 1,
      PageSize: 10,
      total: null,
      PageCurrent1: 1,
      PageSize1: 10,
      total1: null,
      infoDisable: true,
      hetongID: '',
      ExecutionProgress: null, // 执行进度
      ExecutionProgressShow: false, // 执行进度可见性
      uploader: false, // 上传可见性
      dialogFormVisible1: false, // 新增对话框可见性
      form: {
        MarketingManagerValue: '',
        EntryName: '', // 项目名称
        contractSigningDate: '',
        drawingJointSignNode: '', // 图纸会签节点
        EquipmentPreAcceptanceNode: '', // 设备预验收节点
        ConsignmentNode: '', //  发货节点
        installDebugNode: '', // 安装调试节点
        executionProgressID: 1, // 执行进度ID
        customerName: '', // 客户名称
        remark: '',
        付款方式: 1,
        bidding: ''
      },
      tableDataBidding: [],
      executionProgressID: '',
      form1: {
        设备型号: '',
        设备名称: ''
      },
      form2: {
        进度完成日期: ''
      },
      title: '',
      param: 0,
      executionProgress: [], // 执行进度下拉框数据
      executionProgressID1: '', // 中间变量存储执行进度ID
      ProjectTypeIDV: [],
      temp: '', // 增加或修改的标志位
      rules: { // 表单验证规则
        EntryName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
        MarketingManagerValue: [{ required: true, message: '请选择营销经理', trigger: 'change' }],
        executionProgressID: [{ required: true, message: '请选择已完成进度', trigger: 'change' }],
        contractSigningDate: [{ required: true, message: '请选择合同签订日期', trigger: 'change' }],
        付款方式: [{ required: true, message: '请选择付款方式', trigger: 'change' }]
      },
      rules1: { // 表单验证规则
        设备型号: [{ required: true, message: '请输入设备型号', trigger: 'blur' }],
        设备名称: [{ required: true, message: '请输入设备名称', trigger: 'blur' }]
      },
      rules2: { // 表单验证规则
        进度完成日期: [{ required: true, message: '请选择进度完成日期', trigger: 'change' }]
      }
    }
  },
  created() {
    this.fetchData()
    this.fetchTableData1()
    this.fetchCustomerData()
  },
  methods: {
    fetchData() {
      getTree().then(response => { // 获取人员信息树
        const data = response.data
        this.dataPeople = tree(data, 0)
      })
      this.getSelect(initProject, ['项目名称', '项目流水号'], 'entryName')
      this.executionProgressID = this.form.executionProgressID
      this.getSelect(executionProgressID, ['执行进度名', '执行进度ID'], 'executionProgress')
      this.getSelect(selectProvince, ['省份', '省份流水号'], 'Province')
      this.getSelect(money, ['付款方式', '付款方式代码'], 'money')
    },
    openName() {
      this.dialogFormVisiblePeople = true
    },
    getRowKeys(row) {
      return row.项目流水号
    },
    handleNodeClick(data) { // 树节点点击
      getTablePeople(data.id).then(response => {
        this.ListPeople = response.data
      })
    },
    handleChange(row) {
      this.peopleid = row.营销经理流水号
      this.peoplename = row.姓名
    },
    getName() {
      if (this.param === 1) {
        this.dialogFormVisiblePeople = false
        this.MarketingManagerValue = this.peoplename
        this.param = 0
      } else {
        this.dialogFormVisiblePeople = false
        this.id1 = this.peopleid
        this.form.MarketingManagerValue = this.peoplename
      }
    },
    offName() {
      this.dialogFormVisiblePeople = false
      this.dialogFormVisiblePeople1 = false
      this.peopleid = ''
      this.peoplename = ''
    },
    fetchTableData1() {
      if (this.entryNameValue === '' || this.entryNameValue === null) { this.entryNameValue_check = 0 } else { this.entryNameValue_check = 1 }
      if (this.MarketingManagerValue === '' || this.MarketingManagerValue === null) { this.peopleid_check = 0 } else { this.peopleid_check = 1 }
      if (this.startTime === '' || this.startTime === null) { this.startTime_check = 0 } else { this.startTime_check = 1 }
      if (this.endTime === '' || this.endTime === null) { this.endTime_check = 0 } else { this.endTime_check = 1 }
      if (this.machine === '' || this.machine === null) { this.machine_check = 0 } else { this.machine_check = 1 }
      this.ExecutionProgressShow = false
      this.uploader = false
      this.ExecutionProgress = null
      this.listLoading = true
      this.getTable(searchTable1, [this.PageCurrent, this.PageSize, this.entryNameValue, this.peopleid, this.entryNameValue_check, this.peopleid_check, this.startTime_check, this.endTime_check, this.startTime, this.endTime, this.machine_check, this.machine], ['tableData1', 'total', 'listLoading'])
    },
    fetchExecutionProgressdata(row) {
      this.projectNum = row.项目流水号
      this.ExecutionProgressShow = true
      this.uploader = true
      this.action = `${upload}?&ProjectNum=${this.projectNum}`
      this.getFileData(this.projectNum)
      fetchExecutionProgress(row.项目流水号).then(response => {
        this.ExecutionProgress = response.data[0].执行进度流水号
        this.executionProgressID = response.data[0].执行进度流水号
        this.executionProgressID1 = response.data[0].执行进度流水号
        const time = []
        for (let i = 0; i < 8; i++) {
          if (parseInt(response.data[0].执行进度流水号) === i) {
            time.push('进行中')
          } else {
            time.push('未完成')
          }
        }
        this.time1 = time[0]
        this.time2 = time[1]
        this.time3 = time[2]
        this.time4 = time[3]
        this.time5 = time[4]
        this.time6 = time[5]
        this.time7 = time[6]
        this.time8 = time[7]
        return this.projectNum
      }).then(data => {
        searchTimeAll(data).then(response => {
          if (response.data[0].合同签订日期 !== '' && response.data[0].合同签订日期 !== null) {
            this.time1 = response.data[0].合同签订日期.substring(0, response.data[0].合同签订日期.length - 8)
          }
          if (response.data[0].图纸会签日期 !== '' && response.data[0].图纸会签日期 !== null) {
            this.time2 = response.data[0].图纸会签日期.substring(0, response.data[0].图纸会签日期.length - 8)
          }
          if (response.data[0].加工制造日期 !== '' && response.data[0].加工制造日期 !== null) {
            this.time3 = response.data[0].加工制造日期.substring(0, response.data[0].加工制造日期.length - 8)
          }
          if (response.data[0].预验收日期 !== '' && response.data[0].预验收日期 !== null) {
            this.time4 = response.data[0].预验收日期.substring(0, response.data[0].预验收日期.length - 8)
          }
          if (response.data[0].设备发货日期 !== '' && response.data[0].设备发货日期 !== null) {
            this.time5 = response.data[0].设备发货日期.substring(0, response.data[0].设备发货日期.length - 8)
          }
          if (response.data[0].安装调试日期 !== '' && response.data[0].安装调试日期 !== null) {
            this.time6 = response.data[0].安装调试日期.substring(0, response.data[0].安装调试日期.length - 8)
          }
          if (response.data[0].项目验收日期 !== '' && response.data[0].项目验收日期 !== null) {
            this.time7 = response.data[0].项目验收日期.substring(0, response.data[0].项目验收日期.length - 8)
          }
          if (response.data[0].质保期日期 !== '' && response.data[0].质保期日期 !== null) {
            this.time8 = response.data[0].质保期日期.substring(0, response.data[0].质保期日期.length - 8)
          }
        })
      })
    },
    selectMachine(row) {
      if (this.a === 1) {
        this.expands.push(row.项目流水号)
        this.b = row.项目流水号
        this.a = 0
      } else {
        if (this.b === row.项目流水号) {
          this.expands = []
          this.a = 1
        } else {
          this.expands = []
          this.expands.push(row.项目流水号)
          this.a = 0
          this.b = row.项目流水号
        }
      }
      this.projectNum = row.项目流水号
      this.ExecutionProgressShow = true
      this.uploader = true
      this.action = `${upload}?&ProjectNum=${this.projectNum}`
      this.getFileData(this.projectNum)
      fetchExecutionProgress(row.项目流水号).then(response => {
        this.ExecutionProgress = response.data[0].执行进度流水号
        this.executionProgressID = response.data[0].执行进度流水号
        this.executionProgressID1 = response.data[0].执行进度流水号
        const time = []
        for (let i = 0; i < 8; i++) {
          if (parseInt(response.data[0].执行进度流水号) === i) {
            time.push('进行中')
          } else {
            time.push('未完成')
          }
        }
        this.time1 = time[0]
        this.time2 = time[1]
        this.time3 = time[2]
        this.time4 = time[3]
        this.time5 = time[4]
        this.time6 = time[5]
        this.time7 = time[6]
        this.time8 = time[7]
        return this.projectNum
      }).then(data => {
        searchTimeAll(data).then(response => {
          if (response.data[0].合同签订日期 !== '' && response.data[0].合同签订日期 !== null) {
            this.time1 = response.data[0].合同签订日期.substring(0, response.data[0].合同签订日期.length - 8)
          }
          if (response.data[0].图纸会签日期 !== '' && response.data[0].图纸会签日期 !== null) {
            this.time2 = response.data[0].图纸会签日期.substring(0, response.data[0].图纸会签日期.length - 8)
          }
          if (response.data[0].加工制造日期 !== '' && response.data[0].加工制造日期 !== null) {
            this.time3 = response.data[0].加工制造日期.substring(0, response.data[0].加工制造日期.length - 8)
          }
          if (response.data[0].预验收日期 !== '' && response.data[0].预验收日期 !== null) {
            this.time4 = response.data[0].预验收日期.substring(0, response.data[0].预验收日期.length - 8)
          }
          if (response.data[0].设备发货日期 !== '' && response.data[0].设备发货日期 !== null) {
            this.time5 = response.data[0].设备发货日期.substring(0, response.data[0].设备发货日期.length - 8)
          }
          if (response.data[0].安装调试日期 !== '' && response.data[0].安装调试日期 !== null) {
            this.time6 = response.data[0].安装调试日期.substring(0, response.data[0].安装调试日期.length - 8)
          }
          if (response.data[0].项目验收日期 !== '' && response.data[0].项目验收日期 !== null) {
            this.time7 = response.data[0].项目验收日期.substring(0, response.data[0].项目验收日期.length - 8)
          }
          if (response.data[0].质保期日期 !== '' && response.data[0].质保期日期 !== null) {
            this.time8 = response.data[0].质保期日期.substring(0, response.data[0].质保期日期.length - 8)
          }
        })
      })
      selectMachine(row.项目流水号).then(response => {
        this.tableData2 = response.data
      })
    },
    handleDelete(row) {
      this.deleteRow(delList, row.项目流水号, function() { this.fetchTableData1() })
    },
    handleSizeChange(val) {
      this.PageCurrent = 1
      this.PageSize = val
      this.fetchTableData1()
    },
    handleCurrentChange(val) {
      this.PageCurrent = val
      this.fetchTableData1()
    },
    handleSizeChange1(val) {
      this.PageCurrent1 = 1
      this.PageSize1 = val
      this.fetchCustomerData()
    },
    handleCurrentChange1(val) {
      this.PageCurrent1 = val
      this.fetchCustomerData()
    },
    ADD() {
      this.addForm('form')
      this.dialogFormVisible1 = true
      this.temp = 1
      this.title = '增加'
      this.disabled = false
      this.biddingNumber = ''
      this.tableDataBidding = []
    },
    addTableData1() {
      addList(this.form.EntryName, this.form.drawingJointSignNode, this.form.EquipmentPreAcceptanceNode, this.form.ConsignmentNode, this.form.installDebugNode, this.id1, this.form.executionProgressID, this.CustomerCode, this.form.remark, this.form.付款方式, this.form.contractSigningDate, this.biddingNumber).then(response => {
        this.dialogFormVisible1 = false
        if (response.data[0].result === '1') {
          this.$message.success('添加成功')
          this.peopleid = ''
          this.title = ''
          this.fetchTableData1()
        } else {
          this.$message.error('添加失败')
        }
      })
    },
    // 重置表单
    callOff() {
      this.dialogFormVisible1 = false
      this.dialogFormVisible2 = false
    },

    // 提交添加或者修改
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.temp === 1) {
            this.addTableData1()
            this.temp = null
          } else if (this.temp === 2) {
            this.chaEdit()
            this.temp = null
          }
        }
      })
    },
    handleEdit(row) {
      this.editForm(row, 'form')
      this.title = '编辑'
      this.dialogFormVisible1 = true
      this.form.contractSigningDate = row.合同签订日期
      this.form.contractNumber = row.合同编号
      this.form.EntryName = row.项目名称
      this.form.drawingJointSignNode = row.图纸会签节点
      this.form.EquipmentPreAcceptanceNode = row.设备预验收节点
      this.form.ConsignmentNode = row.发货节点
      this.form.installDebugNode = row.安装调试节点
      this.form.MarketingManagerValue = row.营销经理
      this.id1 = row.营销经理流水号
      this.form.executionProgressID = parseInt(row.执行进度流水号)
      this.form.customerName = row.客户名称
      this.hetongID = row.项目流水号
      this.form.remark = row.合同信息备注
      this.CustomerCode = row.客户流水号
      this.form.付款方式 = parseInt(row.付款方式代码)
      this.biddingNumber = row.招标保证金流水号
      this.form.bidding = row.招标企业
      this.disabled = true
      this.temp = 2
    },
    chaEdit() {
      editchar(this.form.EntryName, this.form.drawingJointSignNode, this.form.EquipmentPreAcceptanceNode, this.form.ConsignmentNode, this.form.installDebugNode, this.id1, this.form.executionProgressID, this.CustomerCode, this.form.remark, this.hetongID, this.form.付款方式, this.form.contractSigningDate, this.biddingNumber).then(response => {
        this.dialogFormVisible1 = false
        if (response.data[0].result === '1') {
          this.$message.success('信息更新成功')
          this.peopleid = ''
          this.fetchTableData1()
        } else {
          this.$message.error('信息更新失败')
        }
      })
      this.getTable(searchTable1, [this.PageCurrent, this.PageSize, '', ''], ['tableData1', 'total', 'listLoading'])
      this.ExecutionProgressShow = true
      this.uploader = true
      this.action = `${upload}?&ProjectNum=${this.hetongID}`
      fetchExecutionProgress(this.hetongID).then(response => {
        this.ExecutionProgress = response.data[0].执行进度流水号
        this.executionProgressID = response.data[0].执行进度流水号
        this.executionProgressID1 = response.data[0].执行进度流水号
        const time = []
        for (let i = 0; i < 8; i++) {
          if (parseInt(response.data[0].执行进度流水号) === i) {
            time.push('进行中')
          } else {
            time.push('未完成')
          }
        }
        this.time1 = time[0]
        this.time2 = time[1]
        this.time3 = time[2]
        this.time4 = time[3]
        this.time5 = time[4]
        this.time6 = time[5]
        this.time7 = time[6]
        this.time8 = time[7]
        return this.hetongID
      }).then(data => {
        searchTimeAll(data).then(response => {
          if (response.data[0].合同签订日期 !== '' && response.data[0].合同签订日期 !== null) {
            this.time1 = response.data[0].合同签订日期.substring(0, response.data[0].合同签订日期.length - 8)
          }
          if (response.data[0].图纸会签日期 !== '' && response.data[0].图纸会签日期 !== null) {
            this.time2 = response.data[0].图纸会签日期.substring(0, response.data[0].图纸会签日期.length - 8)
          }
          if (response.data[0].加工制造日期 !== '' && response.data[0].加工制造日期 !== null) {
            this.time3 = response.data[0].加工制造日期.substring(0, response.data[0].加工制造日期.length - 8)
          }
          if (response.data[0].预验收日期 !== '' && response.data[0].预验收日期 !== null) {
            this.time4 = response.data[0].预验收日期.substring(0, response.data[0].预验收日期.length - 8)
          }
          if (response.data[0].设备发货日期 !== '' && response.data[0].设备发货日期 !== null) {
            this.time5 = response.data[0].设备发货日期.substring(0, response.data[0].设备发货日期.length - 8)
          }
          if (response.data[0].安装调试日期 !== '' && response.data[0].安装调试日期 !== null) {
            this.time6 = response.data[0].安装调试日期.substring(0, response.data[0].安装调试日期.length - 8)
          }
          if (response.data[0].项目验收日期 !== '' && response.data[0].项目验收日期 !== null) {
            this.time7 = response.data[0].项目验收日期.substring(0, response.data[0].项目验收日期.length - 8)
          }
          if (response.data[0].质保期日期 !== '' && response.data[0].质保期日期 !== null) {
            this.time8 = response.data[0].质保期日期.substring(0, response.data[0].质保期日期.length - 8)
          }
        })
      })
    },
    clear() {
      this.peopleid = ''
      this.tableData3 = []
      this.ProvinceValue = ''
    },
    clear1() {
      this.CustomerCode = ''
    },
    CustomerChange() {
      this.dialogCustomerFormVisible = true
    },
    offCustomerChange() {
      this.dialogCustomerFormVisible = false
    },
    fetchCustomerData() {
      this.loading1 = true
      this.getTable(fetchCustomerData, [this.PageCurrent1, this.PageSize1, this.Customer], ['CustomerData', 'total1', 'loading1'])
    },
    handleCustomerChange(row) {
      this.CustomerCode = row.客户流水号
      this.form.customerName = row.客户名称
    },
    getCustomerCode() {
      this.dialogCustomerFormVisible = false
    },
    async submitUpload() {
      await this.$refs.upload.submit()
    },
    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.$message.success('文件上传成功')
        this.getFileData(this.projectNum)
      }
    },
    uploadFailure(a, file, fileList) {
      fileList.map(file => {
        this.$message.error(`${file.name}文件上传失败，请检查上传文件是否正确！`)
      })
    },
    getFileData(row) {
      this.hadFile = []
      getFileData(row).then(res => {
        if (res.data.length > 0) {
          res.data.map(item => {
            this.hadFile.push({
              url: `${download}?id=${item.文件标识}.${item.文件后缀}&name=${item.文件名称}.${item.文件后缀}`,
              name: `${item.文件名称}.${item.文件后缀}`,
              suffix: item.文件后缀,
              id: item.文件标识
            })
          })
        }
      })
    },
    deleteFileData(id) {
      this.deleteRow(deleteFileData, id, function() { this.getFileData(this.projectNum) })
    },
    changeProvince() {
      SelectMarketingManager(this.ProvinceValue).then(response => {
        this.tableData3 = response.data
      })
    },
    addMachine(row) {
      this.projectNum = row.项目流水号
      this.dialogFormVisible2 = true
      this.title1 = '新增'
      this.addForm('form1')
    },
    editMachine(row) {
      this.editForm(row, 'form1')
      this.dialogFormVisible2 = true
      this.title1 = '编辑'
      this.c = row.机床流水号
      this.form1.设备型号 = row.机床图号
      this.form1.设备名称 = row.机床名称
    },
    callOff2() {
      this.dialogFormVisible2 = false
    },
    submitMachine() {
      function a() {
        selectMachine(this.projectNum).then(response => {
          this.tableData2 = response.data
        })
        this.dialogFormVisible2 = false
      }
      if (this.flag === 1) {
        this.addTable(submitMachine, [this.projectNum, this.form1.设备型号, this.form1.设备名称], 'form1', a)
      } else {
        this.editTable(editMachine, [this.c, this.form1.设备型号, this.form1.设备名称], 'form1', a)
      }
    },
    deleteMachine(row) {
      function a() {
        selectMachine(this.projectNum).then(response => {
          this.tableData2 = response.data
        })
      }
      this.deleteRow(delMachine, row.机床流水号, a)
    },
    changeExecutionProgressID() {
      this.dialogTimeVisible = true
      if (parseInt(this.executionProgressID) === 1) {
        this.disabledTime = true
      } else {
        this.disabledTime = false
      }
      searchTime(this.projectNum, this.executionProgressID).then(response => {
        this.form2.进度完成日期 = response.data[0].进度完成日期
      })
      // changeExecutionProgressID(this.executionProgressID, this.projectNum).then(response => {
      //   if (response.data[0].result === '1') {
      //     this.$message.success('信息更新成功')
      //     fetchExecutionProgress(this.projectNum).then(response => {
      //       this.ExecutionProgress = response.data[0].执行进度流水号
      //     })
      //   } else {
      //     this.$message.error('信息更新失败')
      //   }
      // })
    },
    openBidding() {
      this.dialogFormVisibleBidding = true
    },
    searchBidding() {
      selectBidBond(0, '', 0, '', 1, this.enterprise, 0, '', 0, '').then(response => {
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          if (data[i].投标日期 !== '' && data[i].投标日期 !== null) {
            data[i].投标日期 = data[i].投标日期.substring(0, data[i].投标日期.length - 8)
          }
        }
        this.tableDataBidding = data
      })
    },
    biddingNum(row) {
      this.biddingNumber = parseInt(row.招标保证金流水号)
      this.enterpriseInput = row.招标企业
    },
    clearBidding() {
      this.biddingNumber = ''
      this.tableDataBidding = []
    },
    getBidding() {
      this.form.bidding = this.enterpriseInput
      this.dialogFormVisibleBidding = false
    },
    offBidding() {
      this.dialogFormVisibleBidding = false
      this.biddingNumber = ''
    },
    callOffTime() {
      this.dialogTimeVisible = false
      this.executionProgressID = this.executionProgressID1
    },
    submitTime(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          changeExecutionProgressID(this.executionProgressID, this.projectNum, this.form2.进度完成日期).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('信息更新成功')
              this.dialogTimeVisible = false
              fetchExecutionProgress(this.projectNum).then(response => {
                this.ExecutionProgress = response.data[0].执行进度流水号
                this.executionProgressID = response.data[0].执行进度流水号
                this.executionProgressID1 = response.data[0].执行进度流水号
                const time = []
                for (let i = 0; i < 8; i++) {
                  if (parseInt(response.data[0].执行进度流水号) === i) {
                    time.push('进行中')
                  } else {
                    time.push('未完成')
                  }
                }
                this.time1 = time[0]
                this.time2 = time[1]
                this.time3 = time[2]
                this.time4 = time[3]
                this.time5 = time[4]
                this.time6 = time[5]
                this.time7 = time[6]
                this.time8 = time[7]
                return this.projectNum
              }).then(data => {
                searchTimeAll(data).then(response => {
                  if (response.data[0].合同签订日期 !== '' && response.data[0].合同签订日期 !== null) {
                    this.time1 = response.data[0].合同签订日期.substring(0, response.data[0].合同签订日期.length - 8)
                  }
                  if (response.data[0].图纸会签日期 !== '' && response.data[0].图纸会签日期 !== null) {
                    this.time2 = response.data[0].图纸会签日期.substring(0, response.data[0].图纸会签日期.length - 8)
                  }
                  if (response.data[0].加工制造日期 !== '' && response.data[0].加工制造日期 !== null) {
                    this.time3 = response.data[0].加工制造日期.substring(0, response.data[0].加工制造日期.length - 8)
                  }
                  if (response.data[0].预验收日期 !== '' && response.data[0].预验收日期 !== null) {
                    this.time4 = response.data[0].预验收日期.substring(0, response.data[0].预验收日期.length - 8)
                  }
                  if (response.data[0].设备发货日期 !== '' && response.data[0].设备发货日期 !== null) {
                    this.time5 = response.data[0].设备发货日期.substring(0, response.data[0].设备发货日期.length - 8)
                  }
                  if (response.data[0].安装调试日期 !== '' && response.data[0].安装调试日期 !== null) {
                    this.time6 = response.data[0].安装调试日期.substring(0, response.data[0].安装调试日期.length - 8)
                  }
                  if (response.data[0].项目验收日期 !== '' && response.data[0].项目验收日期 !== null) {
                    this.time7 = response.data[0].项目验收日期.substring(0, response.data[0].项目验收日期.length - 8)
                  }
                  if (response.data[0].质保期日期 !== '' && response.data[0].质保期日期 !== null) {
                    this.time8 = response.data[0].质保期日期.substring(0, response.data[0].质保期日期.length - 8)
                  }
                })
              })
            } else {
              this.$message.error('信息更新失败')
              this.executionProgressID = this.executionProgressID1
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>

.el-date-editor{
  width:200px;
}

.wrapper{
  width: 260px;
  height: 50px;
  overflow: hidden;
  border: 1px solid #b8c7d9;
  float: left;
  margin: 10px;
}
.content{
  position: relative;
  padding: 8px 8px 0 8px;
}
.action{
  position: absolute;
  top: 4px;
  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{
  position: absolute;
  left: 44px;
  line-height: 30px;
  display: inline-block;
  color: #999;
}
.el-table td, .el-table th.is-leaf,
.el-radio__inner,
.el-input__inner{
  border: 1px solid black!important;
}
</style>
