<template>
  <div>
    <!--顶栏结构-->
    <el-input v-model="TenderingEnterprise" clearable size="small" style="width:150px;margin: 3px 0" placeholder="请输入招标企业"/>
    <span style="font-size: 13px;margin-left: 10px">签订日期</span>
    <el-date-picker
      v-model="dateRange"
      :picker-options="pickerOptions"
      size="small"
      type="daterange"
      align="center"
      style="width: 240px;margin: 3px 0"
      value-format="yyyy-MM-dd"
      format="yyyy-MM-dd"
      range-separator="～"
      start-placeholder="开始日期"
      end-placeholder="结束日期"/>
    <!--      <el-select v-model="TypeOfGoldDepositValue" clearable filterable placeholder="请选择保金类型" size="small" style="width: 150px">-->
    <!--        <el-option-->
    <!--          v-for="item in TypeOfGoldDeposit"-->
    <!--          :key="item.value"-->
    <!--          :label="item.label"-->
    <!--          :value="item.value"/>-->
    <!--      </el-select>-->
    <!--      <el-input v-model="Bidder" clearable size="small" style="width:150px" placeholder="请选择投标人" @dblclick.native="dialogFormVisiblePeople = true;flag2 = 1;searchPer()" @clear="clear()"/>-->
    <!--      <el-date-picker-->
    <!--        v-model="startTime"-->
    <!--        style="width: 150px;margin: 3px 0"-->
    <!--        value-format="yyyy-MM-dd"-->
    <!--        size="small"-->
    <!--        type="date"-->
    <!--        placeholder="请选择开始日期"/>-->
    <!--      <el-date-picker-->
    <!--        v-model="endTime"-->
    <!--        style="width: 150px;"-->
    <!--        value-format="yyyy-MM-dd"-->
    <!--        size="small"-->
    <!--        type="date"-->
    <!--        placeholder="请选择结束日期"/>-->
    <el-button type="primary" icon="el-icon-search" size="small" style="margin-left: 10px" plain @click="PageSize = 30;PageCurrent = 1;fetchTableData1()">查询</el-button>
    <el-button type="distribution" icon="el-icon-circle-plus-outline" size="small" style="margin-left: 10px;margin-right: 15px" @click="addBidBond();flag1 = 2">保证金</el-button>
    <el-tooltip :open-delay="1200" effect="dark" content="导出" style="margin: 10px 0 0 590px;width: 50px" placement="top">
      <div style="display: inline-block">
        <el-button v-positive="'loading'" :disabled="false" type="primary" plain class="el-icon-download" size="small" style="" @click="exportExcel">导出</el-button>
      </div>
    </el-tooltip>

    <!--投标保证金表格-->
    <el-table
      v-loading="tableData1Loading"
      :data="tableData1"
      style="width: 100%; margin-top: 3px"
      height="770"
      highlight-current-row
      border
      stripe
      size="mini">
      <el-table-column align="center" label="投标结果" prop="投标结果" width="160">
        <template slot-scope="scope">
          <el-radio-group v-model="scope.row.投标结果" @change="changeTenderResult(scope.row)">
            <el-radio :disabled="scope.row.是否禁用已中标" label="1">中标</el-radio>
            <el-radio :disabled="scope.row.是否禁用未中标" label="2">未中</el-radio>
          </el-radio-group>
        </template>
      </el-table-column>
      <el-table-column align="center" label="公布日期" width="86">
        <template slot-scope="scope">
          {{ !scope.row.公布日期 ? '未公布' : scope.row.公布日期.substring(0 , scope.row.公布日期.length - 8) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="招标企业" prop="招标企业" width="160" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.招标企业 }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="项目名称" prop="项目名称" width="160" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.项目名称 }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="保证金金额(万元)" width="100">
        <template slot-scope="scope">
          <span style="width: 80px" size="mini">{{ Number(scope.row.保证金金额).toFixed(2) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="缴纳时间" width="86">
        <template slot-scope="scope">
          {{ scope.row.投标日期.substring(0, scope.row.投标日期.length - 8) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="投标人" prop="投标人" width="80">
        <template slot-scope="scope">
          {{ scope.row.投标人 }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="中标服务费(万元)" width="100">
        <template slot-scope="scope">
          {{ Number(scope.row.中标服务费).toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="转履约保证金(万元)" width="120">
        <template slot-scope="scope">
          {{ Number(scope.row.转履约保证金金额).toFixed(2) }}
        </template>
      </el-table-column>
      <!--        <el-table-column align="center" label="应收回(万元)" width="80">-->
      <!--          <template slot-scope="scope">-->
      <!--            {{ Number(scope.row.应收回金额).toFixed(2) }}-->
      <!--          </template>-->
      <!--        </el-table-column>-->
      <el-table-column align="center" label="已收回(万元)" width="80">
        <template slot-scope="scope">
          <span v-if="parseInt(scope.row.是否收回) === 2" size="mini" type="success" style="width: 66px">{{ scope.row.应收回金额 }}</span>
          <span v-else slot="reference" type="danger" size="mini" style="width: 66px">未收回</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="未收金额(万元)" width="90">
        <template slot-scope="scope">
          {{ Number(scope.row.未收金额).toFixed(2) }}
        </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="86">-->
      <!--<template slot-scope="scope">-->
      <!--{{ !scope.row.预计收回日期 ? '结果未公布' : scope.row.预计收回日期.substring(0, scope.row.预计收回日期.length - 8) }}-->
      <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="实际收回日期" width="86">-->
      <!--<template slot-scope="scope">-->
      <!--{{ !scope.row.实际收回日期 ? '未收回' : scope.row.实际收回日期.substring(0, scope.row.实际收回日期.length - 8) }}-->
      <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="状态" width="80">-->
      <!--<template slot-scope="scope">-->
      <!--<el-tag v-if="scope.row.预计收回日期===''||scope.row.预计收回日期===null" slot="reference" size="mini" style="width: 66px">未公布</el-tag>-->
      <!--<el-tag v-else-if="scope.row.预计收回日期!==''&&scope.row.预计收回日期!==null&&parseInt(scope.row.是否收回)===2" slot="reference" type="success" size="mini" style="width: 66px">已收回</el-tag>-->
      <!--<el-tag v-else-if="scope.row.预计收回日期!==''&&scope.row.预计收回日期!==null&&parseInt(scope.row.状态) ===0" slot="reference" type="primary" size="mini" style="width: 66px">未开始</el-tag>-->
      <!--<el-tag v-else-if="scope.row.预计收回日期!==''&&scope.row.预计收回日期!==null&&parseInt(scope.row.状态) ===1" slot="reference" type="warning" size="mini" style="width: 66px">即将拖期</el-tag>-->
      <!--<el-tag v-else-if="scope.row.预计收回日期!==''&&scope.row.预计收回日期!==null&&parseInt(scope.row.状态) ===2" slot="reference" type="danger" size="mini" style="width: 66px">已拖期</el-tag>-->
      <!--</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="100">
        <template slot-scope="scope">
          {{ scope.row.联系电话 }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="备注" width="100px" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.备注 }}
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="220">
        <template slot-scope="scope">
          <el-tooltip :open-delay="1000" effect="dark" content="收回" placement="top" style="margin-left: 0px">
            <div style="display: inline-block">
              <el-button
                :disabled="scope.row.是否禁用"
                size="mini"
                type="text"
                icon="el-icon-money"
                style="margin-left: 0px"
                @click.stop="TakeBack(scope.row);flag1 = 1">收回</el-button>
            </div>
          </el-tooltip>
          <el-tooltip :open-delay="1000" class="item" effect="dark" content="转入履约金" placement="top">
            <div style="display: inline-block">
              <el-button
                :disabled="scope.row.是否禁用履约"
                size="mini"
                type="text"
                style="margin-left: 8px"
                icon="el-icon-stopwatch"
                @click.stop="ComplianceGold(scope.row)">转入履约金</el-button>
            </div>
          </el-tooltip>
          <el-tooltip :open-delay="1000" class="item" effect="dark" content="编辑" placement="top">
            <div style="display: inline-block">
              <el-button
                :disabled="scope.row.是否禁用编辑"
                size="mini"
                type="text"
                style="margin-left: 8px"
                icon="el-icon-edit-outline"
                @click.stop="editBidBond(scope.row);flag1 = 3"/>
            </div>
          </el-tooltip>
          <el-tooltip :open-delay="1000" class="item" effect="dark" content="删除" placement="top">
            <div style="display: inline-block">
              <el-button
                :disabled="scope.row.是否禁用删除"
                size="mini"
                type="text"
                style="margin-left: 8px"
                icon="el-icon-delete"
                @click.stop="delBidBond(scope.row)"/>
            </div>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <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-dialog v-el-drag-dialog :visible.sync="dialogFormVisiblePeople" title="销售经理" center width="400px">
      <div style="height: 420px">
        <div style="float: left;margin-top: 10px;margin-left: 20px;overflow-y: scroll;height: 400px">
          <el-tree
            :data="dataPeople"
            :default-expanded-keys="treeData"
            node-key="id"
            style="width: 150px;float: left"
            height="400"
            accordion
            @node-click="handleNodeClick"
          />
        </div>
        <el-table :data="ListPeople" highlight-current-row height="400" size="mini" stripe style="width: 100px;float: left;margin-left: 30px" @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-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>
      <el-button size="small" style="margin-left: 90px" icon="el-icon-circle-close" @click="offName">取消</el-button>
      <el-button v-positive="'loading'" :disabled="false" type="distribution" size="small" icon="el-icon-circle-check" @click="getName">确认</el-button>
      <!--<el-button style="margin-left: 260px" @click="offName">取消</el-button>-->
      <!--<el-button type="primary" style="margin-top: 20px" @click="getName">确认</el-button>-->
    </el-dialog>

    <!--收回投标保证金-->
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible1" title="收回投标保证金" center style="min-height: 300px" width="320px">
      <el-form ref="form1" :model="form1" :rules="rules1" label-position="left" label-width="110px" class="demo-ruleForm">
        <el-form-item label="实际收回日期" prop="收回日期">
          <el-date-picker
            v-model="form1.收回日期"
            :picker-options="pickerOptions"
            style="width: 160px;"
            value-format="yyyy-MM-dd"
            size="small"
            type="date"
            placeholder="收回日期"/>
        </el-form-item>
        <el-form-item label="回收金额(万元)" prop="回收金额">
          <el-input
            v-model="form1.回收金额"
            :disabled =
              "size=&quot;small&quot;"
            style="width: 160px"
            placeholder=""/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" icon="el-icon-circle-close" @click="callOff('form1')">取消</el-button>
        <el-button v-positive="'loading'" :disabled="false" type="distribution" size="small" icon="el-icon-circle-check" @click="submit('form1')">确 定</el-button>
        <!--<el-button @click="callOff('form1')">取消</el-button>-->
        <!--<el-button type="primary" @click="submit('form1')">确 定</el-button>-->
      </div>
    </el-dialog>

    <!--投标保证金对话框-->
    <el-dialog v-el-drag-dialog :title="title" :visible.sync="dialogFormVisible2" center style="min-height: 300px" width="750px">
      <el-form ref="form2" :model="form2" :rules="rules2" label-position="left" label-width="130px" class="demo-ruleForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="招标企业" prop="招标企业">
              <el-input v-model="form2.招标企业" size="small" placeholder="请输入招标企业" style="width: 200px;"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="联系人">
              <el-input v-model="form2.联系人" size="small" placeholder="请输入联系人" style="width: 200px;"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="联系电话">
              <el-input v-model="form2.联系电话" size="small" placeholder="请输入联系电话" style="width: 200px;"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保证金金额(万元)" prop="保证金金额">
              <el-input-number v-model="form2.保证金金额" :precision="2" :min="0" :step="1" style="width: 200px" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="保证金类型" prop="保证金类型">
              <el-select v-model="form2.保证金类型" clearable filterable placeholder="请选择保证金类型" size="small" style="width: 200px;">
                <el-option
                  v-for="item in TypeOfGoldDeposit1"
                  :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="form2.投标人" size="small" placeholder="请选择投标人" style="width: 200px;" clearable readonly @dblclick.native="dialogFormVisiblePeople = true;flag2 = 2;searchPer()" @clear="clear()"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <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-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="备注">
              <el-input v-model="form2.备注" size="small" placeholder="请输入备注" style="width: 200px;"/>
            </el-form-item>
          </el-col>
        <!--<el-col :span="12">-->
        <!--<el-form-item label="公布后X天收回" prop="提前X天提醒我">-->
        <!--<el-input-number v-model="form2.提前X天提醒我" :step="1" style="width: 200px" size="small"/>-->
        <!--</el-form-item>-->
        <!--</el-col>-->
        <!--&lt;!&ndash;<el-col :span="12">&ndash;&gt;-->
        <!--&lt;!&ndash;<el-form-item label="计划收回日期" prop="计划收回日期">&ndash;&gt;-->
        <!--&lt;!&ndash;<el-date-picker&ndash;&gt;-->
        <!--&lt;!&ndash;v-model="form2.计划收回日期"&ndash;&gt;-->
        <!--&lt;!&ndash;style="width: 200px;"&ndash;&gt;-->
        <!--&lt;!&ndash;value-format="yyyy-MM-dd"&ndash;&gt;-->
        <!--&lt;!&ndash;size="small"&ndash;&gt;-->
        <!--&lt;!&ndash;type="date"&ndash;&gt;-->
        <!--&lt;!&ndash;placeholder="收回日期"/>&ndash;&gt;-->
        <!--&lt;!&ndash;</el-form-item>&ndash;&gt;-->
        <!--&lt;!&ndash;</el-col>&ndash;&gt;-->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" icon="el-icon-circle-close" @click="callOff('form2')">取消</el-button>
        <el-button v-positive="'loading'" :disabled="false" type="distribution" size="small" icon="el-icon-circle-check" @click="submit('form2')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :visible.sync="dialogTimeVisible" :show-close="false" :close-on-click-modal="false" title="请输入" center style="min-height: 300px" width="400px">
      <el-form ref="Timeform" :model="Timeform" :rules="TimeRules" label-width="150px">
        <el-form-item label="公布日期" prop="投标结果公布日期">
          <el-date-picker
            v-model="Timeform.投标结果公布日期"
            style="width: 200px;"
            value-format="yyyy-MM-dd"
            size="small"
            type="date"
            prop="投标结果公布日期"
            placeholder="请选择结果公布日期"/>
        </el-form-item>
        <el-form-item v-if="!tenderResultDisabled" label="中标服务费(万元)" prop="中标服务费">
          <el-input-number v-model="Timeform.中标服务费" :precision="2" :min="0.00" style="width: 200px" size="small"/>
          <!--:max="tenderResultMax"-->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" icon="el-icon-circle-close" @click="callOffTime('Timeform')">取消</el-button>
        <el-button v-positive="'loading'" :disabled="false" type="distribution" size="small" icon="el-icon-circle-check" @click="submitTime('Timeform')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :visible.sync="dialogPerformanceBondVisible" title="转履约保证金" center style="min-height: 300px" width="400px">
      <el-form ref="PerformanceBondform" :model="PerformanceBondform" :rules="PerformanceBondrules" label-position="left" label-width="130px" class="demo-ruleForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="项目名称">
              <el-select v-model="PerformanceBondform.项目名称" :disabled = "true" filterable clearable placeholder="请选择项目名称" style="width: 200px" size="small">
                <el-option
                  v-for="item in entryName"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="保证金金额(万元)" prop="保证金金额">
            <el-input-number v-model="PerformanceBondform.保证金金额" :precision="2" :step="1" :min="0" :max="PerformanceBondform.保证金金额max" style="width: 200px" size="small"/>
          </el-form-item>
        </el-row>
        <!--        <el-row>-->
        <!--          <el-form-item label="保证金类型" prop="保证金类型">-->
        <!--            <el-select v-model="PerformanceBondform.保证金类型" filterable placeholder="请选择保证金类型" style="width: 200px" size="small">-->
        <!--              <el-option-->
        <!--                v-for="item in TypeOfGoldDeposit1"-->
        <!--                :key="item.value"-->
        <!--                :label="item.label"-->
        <!--                :value="item.value"/>-->
        <!--            </el-select>-->
        <!--          </el-form-item>-->
        <!--        </el-row>-->
        <el-row>
          <el-form-item label="收回条件" prop="收回条件">
            <el-select v-model="PerformanceBondform.收回条件" filterable placeholder="请选择收回条件" style="width: 200px" size="small">
              <el-option
                v-for="item in plannedTime"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="截止时间(天)" prop="截止时间">
            <el-input v-positive="'int'" v-model="PerformanceBondform.截止时间" placeholder="请输入截止时间" type="number" style="width: 200px" size="small"/>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" icon="el-icon-circle-close" @click="callOffPerformanceBondform('PerformanceBondform')">取消</el-button>
        <el-button v-positive="'loading'" :disabled="false" type="distribution" size="small" icon="el-icon-circle-check" @click="submitPerformanceBondform('PerformanceBondform')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import elInput from 'element-ui/packages/input'
import { getNowShotTime } from '@/utils/tool'
import { initType, selectBidBond, getTree, tree, getTablePeople, TakeBack, addBidBond, editBidBond, delBidBond, winningBid, executionProgressID, intProject, submitPerformanceBond, selectBidBond_excel } from '@/api/MarketingCenter/BidBond'
export default {
  components: {
    elInput
  },
  data() {
    const validateValue = (rule, value, callback) => {
      console.log(value, 2222)
      if (value === 0.00) {
        callback(new Error('金额不能为0'))
      } else if (value) {
        // const reg = /^\-\d\.?\d*$/
        // const boolean = reg.test(value)
        const boolean = new RegExp(/^(\+)?\d+(\.\d+)?$/).test(value)
        console.log(boolean)
        if (!boolean) {
          callback(new Error('请输入正数'))
          this.form.contractAmount = ''
        } else {
          console.log(2222)
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      submitDisabled: false,
      dateRange: '',
      check1: '',
      pickerOptions: {
        shortcuts: [{
          text: '上季度',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(end.getTime() - 3600 * 1000 * 24 * 30 * 3)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '过去半年',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(end.getTime() - 3600 * 1000 * 24 * 366 / 2)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '过去一年',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(end.getTime() - 3600 * 1000 * 24 * 365)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      timetime: '',
      treeData: [7],
      entryName: [],
      plannedTime: [],
      disabled: false,
      tenderResultDisabled: false,
      dialogPerformanceBondVisible: false, // 转履约保证金对话框
      BidBondCode: '',
      MoneyTypeCode: '',
      TypeOfGoldDeposit1: [],
      flag2: '',
      title: '',
      dialogFormVisible2: false,
      code: '',
      flag1: '',
      startTime: '',
      startTime_check: '',
      endTime: '',
      endTime_check: '',
      tableData1Loading: false,
      TypeOfGoldDepositValue: '', // 保证金类型
      TypeOfGoldDepositValue_check: '',
      TypeOfGoldDeposit: [], // 保证金类型数组
      Bidder: '', // 投标人,
      Bidder_check: '',
      TenderingEnterprise: '', // 招标企业
      TenderingEnterprise_check: '',
      time: [], // 时间区间
      radio: '',
      tableData1: [],
      tenderResultMax: 0,
      PageSize: 30,
      PageCurrent: 1,
      total: null,
      dataPeople: [],
      dialogFormVisiblePeople: false,
      ListPeople: [],
      peopleid: '',
      peoplename: '',
      test: 9.00,
      dialogFormVisible1: false,
      dialogTimeVisible: false,
      form1: {
        收回日期: '',
        回收金额: 0
      },
      Timeform: {
        投标结果公布日期: getNowShotTime(),
        中标服务费: ''
      },
      PerformanceBondform: {
        项目名称: '',
        保证金类型: 1,
        收回条件: 1,
        截止时间: 15,
        保证金金额: '',
        保证金金额max: 0
      },
      form2: {
        招标企业: '',
        联系人: '',
        联系电话: '',
        保证金金额: '',
        保证金类型: 1,
        投标人: '',
        投标日期: '',
        计划收回日期: '',
        提前X天提醒我: 15,
        备注: ''
      },
      rules1: { // 表单验证规则
        收回日期: [{ required: true, message: '请输入收回日期', trigger: 'change' }]
      },
      PerformanceBondrules: { // 表单验证规则
        项目名称: [{ required: true, message: '请选择项目', trigger: 'change' }],
        保证金类型: [{ required: true, message: '请选择保证金类型', trigger: 'change' }],
        收回条件: [{ required: true, message: '请选择收回条件', trigger: 'change' }],
        截止时间: [{ required: true, message: '请选择截止日期', trigger: 'change' }],
        保证金金额: [{ required: true, message: '请输入保证金金额', trigger: 'change' }, { required: true, trigger: 'change', validator: validateValue }]
      },
      TimeRules: { // 表单验证规则
        投标结果公布日期: [{ required: true, message: '请选择投标结果公布日期', trigger: 'change' }],
        中标服务费: [{ required: true, message: '请输入中标服务费', trigger: 'change' }]
      },
      rules2: { // 表单验证规则
        招标企业: [{ required: true, message: '请输入招标企业', trigger: 'blur' }],
        联系人: [{ required: true, message: '请输入联系人', trigger: 'blur' }],
        联系电话: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
        保证金金额: [{ required: true, message: '请输入保证金金额', trigger: 'blur' }, { required: true, trigger: 'change', validator: validateValue }],
        保证金类型: [{ required: true, message: '请输入保证金类型', trigger: 'change' }],
        投标人: [{ required: true, message: '请输入投标人', trigger: 'change' }],
        // 投标日期: [{ required: true, message: '请选择收回日期', trigger: 'change' }],
        计划收回日期: [{ required: true, message: '请选择计划收回日期', trigger: 'change' }],
        提前X天提醒我: [{ required: true, message: '提前X天提醒我', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.init()
    this.fetchTableData1()
  },
  methods: {
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        return v[j]
      }))
    },
    exportExcel() {
      if (this.TypeOfGoldDepositValue === '' || this.TypeOfGoldDepositValue == null) {
        this.TypeOfGoldDepositValue_check = 0
      } else {
        this.TypeOfGoldDepositValue_check = 1
      }
      if (this.Bidder === '' || this.Bidder == null) {
        this.Bidder_check = 0
      } else {
        this.Bidder_check = 1
      }
      if (this.TenderingEnterprise === '' || this.TenderingEnterprise == null) {
        this.TenderingEnterprise_check = 0
      } else {
        this.TenderingEnterprise_check = 1
      }
      this.dateRange ? this.check1 = 1 : (this.check1 = 0, this.dateRange = '')
      selectBidBond_excel(this.TypeOfGoldDepositValue_check, this.TypeOfGoldDepositValue, this.Bidder_check, this.peopleid, this.TenderingEnterprise_check, this.TenderingEnterprise, this.check1, this.dateRange[0], this.check1, this.dateRange[1]).then(val => {
        console.log(val)
        for (let i = 0; i < val.data.length; i++) {
          // if (val.data[i].投标结果 !== '' && val.data[i].交付日期 !== null) {
          //   val.data[i].交付日期 = val.data[i].交付日期.substring(0, val.data[i].交付日期.length - 8)
          // }
          if (val.data[i].投标结果 === 0) {
            val.data[i].投标结果 = ''
          } else if (val.data[i].投标结果 === 1) {
            val.data[i].投标结果 = '已中标'
          } else if (val.data[i].投标结果 === 2) {
            val.data[i].投标结果 = '未中标'
          }
          if (val.data[i].公布日期 !== '' && val.data[i].公布日期 !== null) {
            val.data[i].公布日期 = val.data[i].公布日期.substring(0, val.data[i].公布日期.length - 8)
          }
          if (val.data[i].投标日期 !== '' && val.data[i].投标日期 !== null) {
            val.data[i].投标日期 = val.data[i].投标日期.substring(0, val.data[i].投标日期.length - 8)
          }
          // if (val.data[i].投标日期 !== '' && val.data[i].投标日期 !== null) {
          //   val.data[i].投标日期 = val.data[i].投标日期.substring(0, val.data[i].投标日期.length - 8)
          // }
          if (parseInt(val.data[i].是否收回) !== 2) {
            val.data[i].产品品种代码 = '未收回'
          } else {
            val.data[i].产品品种代码 = (val.data[i].应收回金额).toFixed(2)
          }
          val.data[i].应收回金额 = (val.data[i].应收回金额).toFixed(2)
          val.data[i].保证金金额 = (val.data[i].保证金金额).toFixed(2)
          val.data[i].中标服务费 = (val.data[i].中标服务费).toFixed(2)
          val.data[i].未收金额 = (val.data[i].未收金额).toFixed(2)
          val.data[i].转履约保证金金额 = (val.data[i].转履约保证金金额).toFixed(2)
        }
        if (val.length !== 0) {
          import('@/vendor/Export2Excel').then(excel => {
            const tHeader = ['投标结果', '公布日期', '招标企业', '项目名称', '保证金金额(万元)', '缴纳时间', '投标人', '中标服务费(万元)', '转履约保证金(万元)', '应收(万元)', '已收(万元)', '未收(万元)', '保金类型', '联系人', '联系电话', '保证金备注']
            const filterVal = ['投标结果', '公布日期', '招标企业', '项目名称', '保证金金额', '投标日期', '投标人', '中标服务费', '转履约保证金金额', '应收回金额', '产品品种代码', '未收金额', '保证金类型', '联系人', '联系电话', '备注']
            const list = val.data
            const data = this.formatJson(filterVal, list)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: getNowShotTime() + '投标保证金',
              autoWidth: true,
              bookType: 'xlsx'
            })
          })
        } else {
          this.$message.warning('没有导出内容')
        }
      })
    },
    changeTime() {
      this.pickerOptions = Object.assign({}, this.pickerOptions, {
        disabledDate: (time) => {
          console.log(this.timetime)
          return time.getTime() < Date.parse(this.timetime)
        }
      })
    },
    init() {
      this.getSelect(initType, ['保证金类型', '保证金类型流水号'], 'TypeOfGoldDeposit')
      this.getSelect(initType, ['保证金类型', '保证金类型流水号'], 'TypeOfGoldDeposit1')
      this.getSelect(executionProgressID, ['执行进度名', '执行进度ID'], 'plannedTime')
      this.getSelect(intProject, ['项目名称', '项目流水号'], 'entryName')
      getTree().then(response => { // 获取人员信息树
        const data = response.data
        this.dataPeople = tree(data, 0)
      })
    },
    fetchTableData1() {
      if (this.TypeOfGoldDepositValue === '' || this.TypeOfGoldDepositValue == null) {
        this.TypeOfGoldDepositValue_check = 0
      } else {
        this.TypeOfGoldDepositValue_check = 1
      }
      if (this.Bidder === '' || this.Bidder == null) {
        this.Bidder_check = 0
      } else {
        this.Bidder_check = 1
      }
      if (this.TenderingEnterprise === '' || this.TenderingEnterprise == null) {
        this.TenderingEnterprise_check = 0
      } else {
        this.TenderingEnterprise_check = 1
      }

      this.dateRange ? this.check1 = 1 : (this.check1 = 0, this.dateRange = '')
      // 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
      // }
      this.tableData1Loading = true
      selectBidBond(this.TypeOfGoldDepositValue_check, this.TypeOfGoldDepositValue, this.Bidder_check, this.peopleid, this.TenderingEnterprise_check, this.TenderingEnterprise, this.check1, this.dateRange[0], this.check1, this.dateRange[1], this.PageCurrent, this.PageSize).then(response => {
        this.tableData1Loading = false
        const data = response.data.rows
        for (let i = 0; i < data.length; i++) {
          data[i].公布日期 === '' || data[i].公布日期 === null || parseInt(data[i].履约金) === 1 || parseInt(data[i].投标结果) === 2 || parseInt(data[i].是否收回) === 2 ? data[i].是否禁用履约 = true : data[i].是否禁用履约 = false
          parseInt(data[i].是否收回) === 2 ? data[i].是否禁用编辑 = true : data[i].是否禁用编辑 = false
          parseInt(data[i].是否收回) === 2 ? data[i].是否禁用删除 = true : data[i].是否禁用删除 = false
          data[i].公布日期 === '' || data[i].公布日期 === null || parseInt(data[i].是否收回) === 2 ? data[i].是否禁用 = true : data[i].是否禁用 = false
          if (data[i].投标结果 === '1') {
            data[i].是否禁用已中标 = false
            data[i].是否禁用未中标 = true
          } else if (data[i].投标结果 === '2') {
            data[i].是否禁用已中标 = true
            data[i].是否禁用未中标 = false
          } else {
            data[i].是否禁用已中标 = false
            data[i].是否禁用未中标 = false
          }
        }
        this.tableData1 = data
        this.total = response.data.total
      })
    },
    handleSizeChange(val) {
      this.PageCurrent = 1
      this.PageSize = val
      this.fetchTableData1()
    },
    handleCurrentChange(val) {
      this.PageCurrent = val
      this.fetchTableData1()
    },
    searchPer() {
      this.getData(getTablePeople, 'ListPeople', 7)
    },
    handleNodeClick(data) { // 树节点点击
      this.getData(getTablePeople, 'ListPeople', data.id)
    },
    handleChange(row) {
      this.peopleid = row.人员编号
      this.peoplename = row.姓名
    },
    getName() {
      this.dialogFormVisiblePeople = false
      if (this.flag2 === 1) {
        this.Bidder = this.peoplename
      } else {
        this.form2.投标人 = this.peoplename
      }
    },
    offName() {
      this.dialogFormVisiblePeople = false
      this.peopleid = ''
      this.peoplename = ''
    },
    TakeBack(row) {
      this.addForm('form1')
      this.timetime = row.投标日期
      this.form1.回收金额 = row.应收回金额
      this.changeTime()
      this.dialogFormVisible1 = true
      this.code = row.招标保证金流水号
    },
    submitTakeBack() {
      TakeBack(this.code, this.form1.收回日期).then(response => {
        this.dialogFormVisible1 = false
        if (response.data[0].result === '1') {
          this.$message.success('信息更新成功')
          this.fetchTableData1()
        } else {
          this.$message.error('信息更新失败')
        }
        this.submitDisabled = false
      })
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.submitDisabled = true
          if (this.flag1 === 1) {
            this.submitTakeBack()
            this.flag1 = null
          } else if (this.flag1 === 2) {
            this.addTableData1()
            this.flag1 = null
          } else if (this.flag1 === 3) {
            this.editTableData1()
            this.flag1 = null
          }
        }
      })
    },
    callOff() {
      this.dialogFormVisible1 = false
      this.dialogFormVisible2 = false
    },
    ComplianceGold(row) {
      console.log(row, 999)
      if (row.项目流水号 === '') {
        this.$message.error('请先将保证金绑定合同')
        return
      }
      this.entryName = []
      console.log(this.entryName)
      this.addForm('PerformanceBondform')
      this.entryName.push({
        value: parseInt(row.项目流水号),
        label: row.项目名称
      })
      this.PerformanceBondform.项目名称 = parseInt(this.entryName[0].value)
      this.code = row.招标保证金流水号
      this.dialogPerformanceBondVisible = true
      this.PerformanceBondform.保证金金额 = row.应收回金额
      this.PerformanceBondform.保证金金额max = Number(row.应收回金额)
    },
    addBidBond() {
      this.addForm('form2')
      this.title = '新增投标保证金'
      this.dialogFormVisible2 = true
      this.submitDisabled = false
    },
    addTableData1() {
      addBidBond(this.form2.招标企业, this.form2.联系人, this.form2.联系电话, this.form2.保证金金额, this.peopleid, this.form2.保证金类型, this.form2.投标日期, this.form2.备注, this.form2.提前X天提醒我).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('添加成功')
          this.title = ''
          this.dialogFormVisible2 = false
          this.fetchTableData1()
        } else {
          this.$message.error('添加失败,请检查金额于提醒天数是否为数字')
        }
        this.submitDisabled = false
      })
    },
    editBidBond(row) {
      this.editForm(row, 'form2')
      this.title = '编辑投标保证金'
      this.submitDisabled = false
      this.dialogFormVisible2 = true
      this.form2.招标企业 = row.招标企业
      this.form2.联系人 = row.联系人
      this.form2.联系电话 = row.联系电话
      this.form2.保证金金额 = row.保证金金额
      this.form2.投标人 = row.投标人
      this.peopleid = row.人员流水号
      this.form2.保证金类型 = parseInt(row.保证金类型流水号)
      // this.MoneyTypeCode = row.保证金类型流水号
      this.form2.投标日期 = row.投标日期
      // this.form2.计划收回日期 = row.预计收回日期
      this.form2.备注 = row.备注
      this.form2.提前X天提醒我 = row.提前x天提醒
      this.BidBondCode = row.招标保证金流水号
    },
    editTableData1() {
      editBidBond(this.form2.招标企业, this.form2.联系人, this.form2.联系电话, this.form2.保证金金额, this.peopleid, this.form2.保证金类型, this.form2.投标日期, this.form2.备注, this.form2.提前X天提醒我, this.BidBondCode).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('编辑成功')
          this.title = ''
          this.dialogFormVisible2 = false
          this.fetchTableData1()
        } else {
          this.$message.error('编辑失败')
        }
        this.submitDisabled = false
      })
    },
    delBidBond(row) {
      function a() {
        this.fetchTableData1()
        this.dialogFormVisible2 = false
      }
      this.deleteRow(delBidBond, row.招标保证金流水号, a)
    },
    changeTenderResult(row) {
      this.code = row.招标保证金流水号
      // this.tenderResultMax = Number(row.应收回金额)).toFixed(2)
      this.Timeform.中标服务费 = 0
      this.tenderResultMax = parseFloat(row.应收回金额)
      if (row.投标结果 === '1') {
        this.radio = '1'
        this.dialogTimeVisible = true
        // this.Timeform.投标结果公布日期 = getNowShotTime()
        this.tenderResultDisabled = false
      } else if (row.投标结果 === '2') {
        this.radio = '2'
        this.dialogTimeVisible = true
        this.tenderResultDisabled = true
      }
    },
    callOffTime() {
      this.dialogTimeVisible = false
      this.fetchTableData1()
    },
    submitTime(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          winningBid(this.code, this.radio, this.Timeform.投标结果公布日期, this.Timeform.中标服务费).then(response => {
            if (response.data[0].result === '1') {
              this.fetchTableData1()
              this.dialogTimeVisible = false
              this.$message.success('操作成功')
            } else {
              this.$message.error('操作失败')
            }
          })
        }
      })
    },
    callOffPerformanceBondform() {
      this.dialogPerformanceBondVisible = false
    },
    submitPerformanceBondform(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          submitPerformanceBond(this.code, this.PerformanceBondform.项目名称, this.PerformanceBondform.保证金金额, this.PerformanceBondform.保证金类型, this.PerformanceBondform.收回条件, this.PerformanceBondform.截止时间).then(response => {
            if (response.data[0].result === '1') {
              this.fetchTableData1()
              this.dialogPerformanceBondVisible = false
              this.$message.success('操作成功')
            } else {
              this.$message.error('操作失败')
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>
  .el-form--label-left >>> .el-form-item__label {
    text-align: right;
  }
  >>>.el-dialog--center .el-dialog__body {
    text-align: initial;
    padding: 10px 20px 10px
  }
  >>>.el-dialog__header {
    padding: 20px 20px 0px;
  }
  >>>.el-dialog__footer {
    padding: 0px 20px 20px;
    /*text-align: right;*/
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }
  >>>.el-form-item {
    margin-bottom: 13px;
  }
</style>

