<template>
  <div class="app-container">
    <el-card>
      <span>项目名称：</span>
      <el-select v-model="entryNameValue" filterable placeholder="项目名称" style="margin: 3px " size="small" clearable>
        <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="MarketingManagerValue" clearable size="small" style="width:200px" placeholder="请双击选择营销经理" @dblclick.native="openName" @clear="clear()"/>
      <el-button type="success" icon="el-icon-search" size="small" style="margin-left: 10px" @click="PageSize = 30;PageCurrent = 1;tableData2=[];getTableData()">查询</el-button>
      <el-button type="primary" icon="el-icon-circle-plus-outline" size="small" style="margin-left: 10px" @click="ADD('form2')">新增</el-button>
      <el-badge :value="value" :max="99" class="item">
        <el-button size="small" plain @click="AccountsReceivable">查看收款信息</el-button>
      </el-badge>
    </el-card>
    <el-card>
      <el-table
        v-loading="listLoading"
        :row-key="getRowKeys"
        :expand-row-keys="expands"
        :data="tableData1"
        style="width: 100%;"
        height="500px"
        highlight-current-row
        border
        stripe
        size="mini"
        @expand-change="selectMachine"
        @row-click="getTableData2">
        <el-table-column type="expand" label="详情">
          <template slot-scope="scope">
            <el-table :data="tableData3" class="subTableHeader" border stripe style="width: 600px; text-align: center" size="mini">
              <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">
                  {{ parseInt(scope.row.运输状态) === 0 ? '运输中' : '已签收' }}
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column align="center" label="合同编号" width="140">
          <template slot-scope="scope">
            <el-tag size="mini" type="primary">{{ scope.row.合同编号 }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目名称" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="已完成进度" width="90">
          <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="130">
          <template slot-scope="scope">
            {{ scope.row.合同总金额 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="已到账金额（万元）" width="130">
          <template slot-scope="scope">
            {{ scope.row.已支付 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="未到账金额（万元）" width="130">
          <template slot-scope="scope">
            <el-tag size="mini" style="width: 100px" type="warning">{{ scope.row.未支付金额 }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="付款进度" width="150">
          <template slot-scope="scope">
            <div style="width: 130px">
              <el-progress :text-inside="true" :stroke-width="18" :percentage="parseFloat(scope.row.付款百分比)" size="mini" status="success" />
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="营销经理" width="70">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="客户名称" width="160" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.客户名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="联系人" width="60">
          <template slot-scope="scope">
            {{ scope.row.联系人 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="联系电话" width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.电话 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="银行账号" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.银行账号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="税号" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.税号 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="140">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="编辑" placement="top">
              <div style="display: inline-block">
                <el-button
                  :disabled="scope.row.是否禁用编辑"
                  type="text"
                  size="mini"
                  icon="el-icon-edit-outline"
                  @click.stop="EditTableData(scope.row)"/>
              </div>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除" placement="top">
              <div style="display: inline-block">
                <el-button
                  style="margin-left: 20px"
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click.stop="dellist(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-card>
    <el-card>
      <el-table
        v-loading="listLoading2"
        :row-style="tableRowClassName1"
        :row-key="getRowKeys1"
        :expand-row-keys="expands1"
        :data="tableData2"
        style="width: 100%;max-height: 440px;text-align: center"
        height="210"
        highlight-current-row
        border
        stripe
        size="mini"
        @expand-change="selectMachine1">
        <el-table-column type="expand" label="详情">
          <template slot-scope="scope">
            <el-table :data="tableData4" class="subTableHeader" border stripe style="width: 600px; text-align: center" size="mini">
              <el-table-column
                align="center"
                label="序号"
                type="index"
                width="100"/>
              <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="操作" fixed="right" align="center" width="250">
                <template slot-scope="scope">
                  <el-tooltip effect="dark" content="编辑" placement="top">
                    <div style="display: inline-block">
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit-outline"
                        @click="handleEdit2(scope.row);flag = 2"/>
                    </div>
                  </el-tooltip>
                  <el-tooltip effect="dark" content="删除" placement="top">
                    <div style="display: inline-block">
                      <el-button
                        size="mini"
                        type="text"
                        style="margin-left: 20px"
                        icon="el-icon-delete"
                        @click="handleDelete2(scope.row)"/>
                    </div>
                  </el-tooltip>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="付款批次"
          type="index"
          width="150"/>
        <el-table-column align="center" label="应收金额（万元）" width="180px">
          <template slot-scope="scope">
            {{ scope.row.应收金额 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="已收金额（万元）" width="180px">
          <template slot-scope="scope">
            {{ scope.row.已收金额 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="未收金额（万元）" width="200px">
          <template slot-scope="scope">
            <el-tag type="warning" style="width: 100px" size="small">{{ scope.row.未收金额 }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="转下阶段收款金额" width="200px">
          <template slot-scope="scope">
            {{ scope.row.转下阶段金额 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="收款阶段" width="200px">
          <template slot-scope="scope">
            <el-select v-model="scope.row.执行进度id" filterable placeholder="请选择收款阶段" style="width: 130px" size="mini" @change="changeTime(scope.row)">
              <el-option
                v-for="item in plannedTime"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" label="截止时间" width="200px">
          <template slot-scope="scope">
            <span>后</span>
            <el-input v-model="scope.row.提前x天提醒" size="mini" style="width:50px" placeholder="请输入提前X天提醒" @change="editDay(scope.row)"/>
            <span>天内完成</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="状态" >
          <template slot-scope="scope">
            <el-popover
              placement="top-start"
              title="收款计划"
              width="200"
              trigger="hover">
              <div v-show="(scope.row.计划付款时间 === '' || scope.row.计划付款时间 === null) && parseInt(scope.row.未收金额)!==0 " style="text-align: center">
                <h4>{{ scope.row.执行进度名 }} 未完成</h4>
              </div>
              <div v-show="scope.row.计划付款时间 !== '' && scope.row.计划付款时间 !== null && parseInt(scope.row.未收金额)!==0">
                <h4>{{ scope.row.执行进度名 }}于{{ scope.row.节点日期 }}完成，计划于{{ scope.row.计划付款时间 }}进行收款，距离计划截止还剩{{ parseInt(scope.row.剩余天数) > 0 ? scope.row.剩余天数 : 0 }}天</h4>
              </div>
              <div v-show="parseInt(scope.row.未收金额)=== 0 " style="text-align: center">
                <h4>{{ scope.row.执行进度名 }}阶段收款已完成</h4>
              </div>
              <el-tag v-if="scope.row.计划付款时间===''||scope.row.计划付款时间===null" slot="reference" size="small" style="width: 66px">进度未完</el-tag>
              <el-tag v-else-if="scope.row.计划付款时间!==''&&scope.row.计划付款时间!==null&&parseInt(scope.row.未收金额)===0" slot="reference" type="success" size="small" style="width: 66px">已完成</el-tag>
              <el-tag v-else-if="scope.row.计划付款时间!==''&&scope.row.计划付款时间!==null&&scope.row.状态==='未开始'" slot="reference" type="primary" size="small" style="width: 66px">未开始</el-tag>
              <el-tag v-else-if="scope.row.计划付款时间!==''&&scope.row.计划付款时间!==null&&scope.row.状态==='即将拖期'" slot="reference" type="warning" size="small" style="width: 66px">即将拖期</el-tag>
              <el-tag v-else-if="scope.row.计划付款时间!==''&&scope.row.计划付款时间!==null&&scope.row.状态==='已拖期'" slot="reference" type="danger" size="small" style="width: 66px">已拖期</el-tag>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="140">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="收款" placement="top">
              <div style="display: inline-block">
                <el-button
                  :disabled="scope.row.是否禁用收款"
                  size="mini"
                  type="text"
                  icon="el-icon-money"
                  @click="handleEdit1(scope.row);flag=1"/>
              </div>
            </el-tooltip>
            <el-tooltip effect="dark" content="收款转移" placement="top">
              <div style="display: inline-block">
                <el-button
                  :disabled="scope.row.是否禁用"
                  size="mini"
                  type="text"
                  style="margin-left: 20px"
                  icon="el-icon-sort"
                  @click="TransferPlan(scope.row)"/>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!--新增合同资金对话框-->
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible2" title="新增合同收款计划" center width="380px">
      <el-form ref="form2" :model="form2" :rules="rules" label-position="left">
        <el-form-item label="项目名称" prop="entryNameValue" label-width="100px">
          <el-select v-model="form2.entryNameValue" clearable filterable placeholder="请输入项目名称" style="margin-left: 2px; width: 200px" size="small" @change="searchProjectName">
            <el-option
              v-for="item in entryName2"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="合同编号" prop="ContractNumberValue" label-width="100px" size="small">
          <el-input v-model="form2.ContractNumberValue" :disabled="true" size="small" placeholder="请输入合同编号" style="width: 200px"/>
        </el-form-item>
        <el-form-item label="合同总金额" prop="TotalContractAmount" label-width="100px">
          <el-input v-model="form2.TotalContractAmount" size="small" placeholder="请输入合同总金额（万元）" style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff('form2')">取消</el-button>
        <el-button type="primary" @click="submit('form2')">确 定</el-button>
      </div>
    </el-dialog>
    <!--编辑合同资金对话框-->
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible4" title="编辑付款计划" center width="400px">
      <el-form ref="form2" :model="form2" :rules="rules" label-position="left">
        <el-form-item label="项目名称" prop="entryNameValue" label-width="100px">
          <el-select v-model="form2.entryNameValue" :disabled="true" clearable filterable placeholder="请输入项目名称" style="width: 200px" size="small" @change="searchProjectName">
            <el-option
              v-for="item in entryName"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="合同编号" prop="ContractNumberValue" label-width="100px" size="small">
          <el-input v-model="form2.ContractNumberValue" :disabled="true" size="small" placeholder="请输入合同编号" style="width: 200px"/>
        </el-form-item>
        <el-form-item label="合同总金额" prop="TotalContractAmount" label-width="100px">
          <el-input v-model="form2.TotalContractAmount" size="small" placeholder="请输入合同总金额（万元）" style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff('form2')">取消</el-button>
        <el-button type="primary" @click="editTableData('form2')">确 定</el-button>
      </div>
    </el-dialog>
    <!--付款对话框-->
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible1" title="更新付款" center width="400px">
      <el-form ref="form" :model="form" :rules="rules1" label-position="left">
        <el-form-item label="项目名称" prop="EntryName" label-width="100px">
          <el-input v-model="form.EntryName" :disabled="true" size="small" placeholder="请输入项目名称"/>
        </el-form-item>
        <el-form-item label="合同总金额" prop="TotalContractAmount" label-width="100px">
          <el-input v-model="form.TotalContractAmount" :disabled="true" size="small" placeholder="请输入合同总金额（万元）"/>
        </el-form-item>
        <el-form-item label="未付款金额" prop="AlreadyPaid1" label-width="100px">
          <el-input v-model="form.AlreadyPaid1 " :disabled="true" size="small" placeholder="请输入未付款金额（万元）"/>
        </el-form-item>
        <el-form-item label="本次付款" prop="ThisPayment" label-width="100px">
          <el-input-number v-model="form.ThisPayment" :min="0" :max="maxMoney" :precision="2" :step="1" controls-position="right" size="small" style="width: 232px" placeholder="请输入本次付款金额" @change="changeMoney"/>
        </el-form-item>
        <el-form-item label="付款时间" prop="payTime" label-width="97px">
          <el-date-picker
            v-model="form.payTime"
            value-format="yyyy-MM-dd"
            size="small"
            type="date"
            placeholder="请选择本次付款时间"/>
        </el-form-item>
        <el-form-item label="付款阶段" prop="PaymentPhaseValue" label-width="97px">
          <el-select v-model="form.PaymentPhaseValue" placeholder="请输入付款阶段" clearable size="small" style="width: 236px">
            <el-option
              v-for="item in PaymentPhase"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff()">取消</el-button>
        <el-button type="primary" @click="submit('form')">确 定</el-button>
      </div>
    </el-dialog>
    <!--营销经理选择-->
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisiblePeople" title="营销经理" center width="500px">
      <span>姓名：</span>
      <el-input v-model="name" clearable size="small" style="width: 200px"/>
      <el-button size="small" icon="el-icon-search" style="margin-left: 10px" type="success" @click="searchName">查询</el-button>
      <!--<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="dataPeople" border stripe size="mini" style="width: 100%; text-align: center;margin-top: 15px" 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 v-el-drag-dialog :title="title" :visible.sync="dialogFormVisible3" center width="450px">
      <el-form ref="form3" :model="form3" :rules="rules2" label-position="left">
        <el-form-item label="本次收款金额" prop="本次付款" label-width="110px">
          <el-input-number v-model="form3.本次付款" :min="0" :max="max1" :precision="2" :step="1" controls-position="right" size="small" style="width: 232px" placeholder="请输入本次付款金额" @change="changeMoney"/>
        </el-form-item>
        <el-form-item label="本次收款时间" prop="付款时间" label-width="110px">
          <el-date-picker
            v-model="form3.付款时间"
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd"
            size="small"
            type="date"
            placeholder="请选择本次付款时间"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff('form3')">取消</el-button>
        <el-button type="primary" @click="submitEdit('form3')">确 定</el-button>
      </div>
    </el-dialog>
    <!--转移收款-->
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible5" title="转下阶段收款" center width="400px">
      <el-form ref="form4" :model="form4" :rules="rules3" label-position="left">
        <el-form-item label="转移金额" prop="转移金额" label-width="110px">
          <el-input-number v-model="form4.转移金额" :min="0" :max="max1" :precision="2" :step="1" controls-position="right" size="small" style="width: 200px" placeholder="请输入本次付款金额" @change="changeMoney"/>
        </el-form-item>
        <el-form-item label="计划阶段" prop="计划阶段" label-width="110px">
          <el-select v-model="form4.计划阶段" clearable filterable placeholder="请选择计划转移到某阶段" style="width: 200px" size="small">
            <el-option
              v-for="item in Planning"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff('form4')">取消</el-button>
        <el-button type="primary" @click="submitTransPlanning('form4')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :visible.sync="AccountsReceivableVisible" width="60%" >
      <el-table :data="gridData" :row-style="tableRowClassName" height="260" size="mini" border stripe>
        <el-table-column property="date" label="项目名称" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column property="name" label="客户名称" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.客户名称 }}
          </template>
        </el-table-column>
        <el-table-column property="address" label="联系人" width="80px" align="center">
          <template slot-scope="scope">
            {{ scope.row.联系人 }}
          </template>
        </el-table-column>
        <el-table-column property="date" label="联系电话" align="center" width="200px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.电话 }}
          </template>
        </el-table-column>
        <el-table-column property="name" label="计划收款时间" width="130px" align="center">
          <template slot-scope="scope">
            {{ scope.row.计划付款时间 }}
          </template>
        </el-table-column>
        <el-table-column property="name" label="阶段" width="60" align="center">
          <template slot-scope="scope">
            {{ scope.row.付款批次 }}
          </template>
        </el-table-column>
        <el-table-column property="address" label="状态" width="70px" align="center">
          <template slot-scope="scope">
            {{ scope.row.状态 }}
          </template>
        </el-table-column>
        <el-table-column property="date" label="操作" align="center" width="150px">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="立即收款" placement="top">
              <div style="display: inline-block">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-money"
                  @click="Detail(scope.row)"/>
              </div>
            </el-tooltip>
            <el-tooltip effect="dark" content="不再提醒" placement="top">
              <div style="display: inline-block">
                <el-button
                  size="mini"
                  type="text"
                  style="margin-left: 20px"
                  icon="el-icon-circle-close"
                  @click="Never(scope.row)"/>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import elInput from 'element-ui/packages/input'
import { never, executionProgressID, searchProjectNumber2, SelectContractFunds, AccountsReceivable, editDay, TransPlanning, selectBatch, editList, delMoney, editTime, selectMax, editFukuan, fukuan, selectProvince, SelectMarketingManager, searchTable1, searchTable2, editBatchCapitalChar, deletechar, searchProjectNumber, searchProjectName, addList, PaymentPhase, dellist, selectMachine, selectBatchFundingDetails } from '@/api//MarketingCenter/ContractCapitalManagement'

export default {
  components: {
    elInput
  },
  data() {
    const validateValue = (rule, value, callback) => {
      if (value === 0) {
        callback(new Error('金额不能为0或大于未付款金额'))
      } else {
        callback()
      }
    }
    return {
      pickerOptions: {},
      timetime: '',
      name: '',
      plannedTime: [],
      entryName2: [],
      count1: 0,
      type: '',
      a: 1,
      b: 1,
      c: 1,
      d: 1,
      id: '',
      id1: '',
      id2: '',
      id3: '',
      max: 0,
      max1: 0,
      max2: 0,
      value: null,
      selectMax: '',
      flag: '',
      title: '',
      editFukuan: '',
      ProvinceValue: '',
      Province: [],
      expands1: [],
      expands: [],
      tableData3: [],
      tableData4: [],
      entryNameValue: '',
      entryName: [],
      peoplename: '',
      peopleid: '',
      dataPeople: [],
      ListPeople: [],
      list1: [], // 项目名称临时存储
      Planning: [],
      MarketingManagerValue: '', // 营销经理下拉框
      listLoading: false,
      listLoading2: false,
      tableData1: [],
      tableData2: [],
      gridData: [],
      PageCurrent: 1,
      PageSize: 30,
      total: null,
      PageCurrent2: 1,
      PageSize2: 30,
      total2: null,
      dialogFormVisible1: false, // 付款对话框可见性
      dialogFormVisible2: false, // 新增对话框可见性
      dialogFormVisible3: false,
      dialogFormVisible4: false,
      dialogFormVisible5: false,
      maxMoney: 0, // 批次付款最大数额
      zijinID: '', // 资金ID
      PaymentPhase: [],
      temp: null,
      moneyID: '',
      projectCode: '',
      contractNumber: [],
      num: '',
      contractTotal: '',
      dialogFormVisiblePeople: false,
      AccountsReceivableVisible: false,
      form: {
        EntryName: '', // 项目名称
        TotalContractAmount: '', // 合同总金额
        AlreadyPaid: '', // 已支付的金额
        ThisPayment: 0, // 本次付款
        payTime: '', // 本次付款时间
        PaymentPhaseValue: '', // 付款阶段
        AlreadyPaid1: ''
      },
      form2: {
        ContractNumberValue: '', // 合同编号
        EntryName: '', // 项目名称
        TotalContractAmount: '', // 合同总金额
        entryNameValue: '' // 项目名称下拉框
      },
      form3: {
        本次付款: '',
        付款时间: '',
        付款阶段id: null
      },
      form4: {
        转移金额: '',
        计划阶段: ''
      },
      rules: { // 表单验证规则
        ContractNumberValue: [{ required: true, message: '请输入合同编号', trigger: 'blur' }],
        TotalContractAmount: [{ required: true, message: '请输入合同总金额', trigger: 'blur' }],
        entryNameValue: [{ required: true, message: '请选择项目名称', trigger: 'change' }]
      },
      rules1: { // 表单验证规则
        ThisPayment: [
          { required: true, message: '请输入本次付款金额', trigger: 'blur' },
          { required: true, trigger: 'blur', validator: validateValue }],
        payTime: [{ required: true, message: '请输入付款时间', trigger: 'change' }],
        PaymentPhaseValue: [{ required: true, message: '请输入付款阶段', trigger: 'change' }]
      },
      rules2: { // 表单验证规则
        本次付款: [
          { required: true, message: '请输入本次付款金额' },
          { required: true, trigger: 'blur', validator: validateValue }],
        付款时间: [{ required: true, message: '请输入付款时间' }]
        // 付款阶段id: [{ required: true, message: '请输入付款阶段', trigger: 'change' }]
      },
      rules3: { // 表单验证规则
        转移金额: [
          { required: true, message: '请输入转移金额', trigger: 'blur' },
          { required: true, trigger: 'blur', validator: validateValue }],
        计划阶段: [{ required: true, message: '请选择计划阶段', trigger: 'change' }]
      }
    }
  },
  created() {
    this.getTableData()
    this.init()
  },
  methods: {
    searchName() { // 模糊查询姓名
      SelectMarketingManager(this.name).then(response => {
        this.dataPeople = response.data
      })
    },
    openName() {
      this.name = ''
      this.dataPeople = []
      this.dialogFormVisiblePeople = true
      this.searchName()
    },
    init() {
      this.getSelect(selectProvince, ['省份', '省份流水号'], 'Province')
      this.getSelect(searchProjectNumber, ['项目名称', '项目流水号'], 'entryName')
      this.getSelect(searchProjectNumber2, ['项目名称', '项目流水号'], 'entryName2')
      this.getSelect(PaymentPhase, ['付款阶段', '付款阶段ID'], 'PaymentPhase')
      this.getSelect(executionProgressID, ['执行进度名', '执行进度ID'], 'plannedTime')
      AccountsReceivable().then(response => {
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
          if (data[i].状态 === '1') {
            data[i].状态 = '即将拖期'
          }
          if (data[i].状态 === '2') {
            data[i].状态 = '已拖期'
          }
        }
        this.gridData = data
        this.value = response.data.length
      })
    },
    handleDelete2(row) {
      function a() {
        this.getTableData()
        AccountsReceivable().then(response => {
          const data = response.data
          for (let i = 0; i < data.length; i++) {
            data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
            if (data[i].状态 === '1') {
              data[i].状态 = '即将拖期'
            }
            if (data[i].状态 === '2') {
              data[i].状态 = '已拖期'
            }
          }
          this.gridData = data
          this.value = response.data.length
        })
        selectBatchFundingDetails(this.id).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            if (response.data[i].本次收款时间 !== null || response.data[i].本次收款时间 !== '') {
              response.data[i].本次收款时间 = response.data[i].本次收款时间.substring(0, response.data[i].本次收款时间.length - 9)
            }
          }
          this.tableData4 = response.data
        })
        searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
          this.listLoading2 = false
          const data = response.data.rows
          for (let i = 0; i < data.length; i++) {
            data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
            data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
            data[i].执行进度id = parseInt(data[i].执行进度id)
            if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
              data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
            }
            if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
              data[i].是否禁用收款 = true
              data[i].状态 = '进度未完'
            } else {
              data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
              data[i].是否禁用收款 = false
              if (data[i].未收金额 === '0') {
                data[i].状态 = '已完成'
              } else {
                if (data[i].状态 === '0') {
                  data[i].状态 = '未开始'
                }
                if (data[i].状态 === '1') {
                  data[i].状态 = '即将拖期'
                }
                if (data[i].状态 === '2') {
                  data[i].状态 = '已拖期'
                }
              }
            }
            data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
          }
          this.tableData2 = data
          this.total2 = response.data.total
        })
      }
      this.deleteRow(delMoney, row.批次付款明细ID, a)
    },
    changeTime(row) {
      const timeid = row.批次资金id
      const time = row.执行进度id
      editTime(timeid, time).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('信息更新成功')
          AccountsReceivable().then(response => {
            const data = response.data
            for (let i = 0; i < data.length; i++) {
              data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
              if (data[i].状态 === '1') {
                data[i].状态 = '即将拖期'
              }
              if (data[i].状态 === '2') {
                data[i].状态 = '已拖期'
              }
            }
            this.gridData = data
            this.value = response.data.length
          })
          searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
            const data = response.data.rows
            for (let i = 0; i < data.length; i++) {
              data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
              data[i].执行进度id = parseInt(data[i].执行进度id)
              if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
              }
              if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                data[i].是否禁用收款 = true
                data[i].状态 = '进度未完'
              } else {
                data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                data[i].是否禁用收款 = false
                if (data[i].未收金额 === '0') {
                  data[i].状态 = '已完成'
                } else {
                  if (data[i].状态 === '0') {
                    data[i].状态 = '未开始'
                  }
                  if (data[i].状态 === '1') {
                    data[i].状态 = '即将拖期'
                  }
                  if (data[i].状态 === '2') {
                    data[i].状态 = '已拖期'
                  }
                }
              }
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
            }
            this.tableData2 = data
            this.total2 = response.data.total
            this.dialogFormVisible4 = false
          })
        } else {
          this.$message.error('信息更新失败')
        }
      })
    },
    handleEdit2(row) {
      this.editForm(row, 'form3')
      this.title = '编辑阶段收款'
      this.max1 = parseFloat(this.max2) + parseFloat(row.本次收款金额)
      this.dialogFormVisible3 = true
      this.form3.本次付款 = row.本次收款金额
      this.form3.付款时间 = row.本次收款时间
      this.id2 = row.批次付款明细ID
      selectMax(this.id2).then(response => {
        this.max1 = parseFloat(response.data[0].应收金额) - parseFloat(response.data[0].已收金额) + row.本次收款金额
      })
    },
    handleChange(row) {
      this.peopleid = row.营销经理流水号
      this.peoplename = row.姓名
    },
    changeProvince() {
      SelectMarketingManager(this.ProvinceValue).then(response => {
        this.dataPeople = response.data
      })
    },
    selectMachine(row) {
      this.projectCode = row.项目流水号
      selectMachine(this.projectCode).then(response => {
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          data[i].发货日期 = data[i].发货日期.substring(0, data[i].发货日期.length - 8)
        }
        this.tableData3 = data
      })
      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.项目流水号
        }
      }
    },
    getRowKeys(row) {
      return row.项目流水号
    },
    getRowKeys1(row) {
      return row.批次资金id
    },
    selectMachine1(row) {
      this.id = row.批次资金id
      this.tableData4 = []
      selectBatchFundingDetails(row.批次资金id).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (response.data[i].本次收款时间 !== null || response.data[i].本次收款时间 !== '') {
            response.data[i].本次收款时间 = response.data[i].本次收款时间.substring(0, response.data[i].本次收款时间.length - 9)
          }
        }
        this.tableData4 = response.data
      })
      if (this.c === 1) {
        this.expands1.push(row.批次资金id)
        this.d = row.批次资金id
        this.c = 0
      } else {
        if (this.d === row.批次资金id) {
          this.expands1 = []
          this.c = 1
        } else {
          this.expands1 = []
          this.expands1.push(row.批次资金id)
          this.c = 0
          this.d = row.批次资金id
        }
      }
    },
    getName() {
      this.dialogFormVisiblePeople = false
      this.MarketingManagerValue = this.peoplename
    },
    offName() {
      this.dialogFormVisiblePeople = false
      this.peopleid = ''
      this.peoplename = ''
    },
    searchProjectName() {
      if (this.form2.entryNameValue !== '' && this.form2.entryNameValue !== null) {
        searchProjectName(this.form2.entryNameValue).then(response => {
          this.form2.ContractNumberValue = response.data[0].合同编号
        })
      }
    },
    handleEdit(row) {
      this.contractTotal = parseFloat(row.合同总金额)
      this.max = parseFloat(row.未支付金额)
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.temp = 2
      this.dialogFormVisible1 = true
      this.form.EntryName = row.项目名称
      this.zijinID = row.资金id
      this.form.TotalContractAmount = row.合同总金额
      this.form.AlreadyPaid1 = row.未支付金额
      this.form.AlreadyPaid = row.未支付金额
      this.maxMoney = parseFloat(row.未支付金额)
    },
    getTableData() {
      this.listLoading = true
      searchTable1(this.PageCurrent, this.PageSize, this.entryNameValue, this.peopleid).then(response => {
        this.listLoading = false
        const data = response.data.rows
        for (let i = 0; i < data.length; i++) {
          data[i].未支付金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
          data[i].已支付 === '0' ? data[i].是否禁用编辑 = false : data[i].是否禁用编辑 = true
          if (parseFloat(data[i].付款百分比) >= 99.9) {
            data[i].付款百分比 = 100
          }
        }
        this.tableData1 = data
        this.total = response.data.total
      })
    },
    getTableData2(row) {
      this.timetime = row.合同签订日期
      this.moneyID = row.资金id
      this.max = parseFloat(row.未支付金额)
      this.contractTotal = parseFloat(row.合同总金额)
      this.listLoading2 = true
      searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
        this.id3 = ''
        this.listLoading2 = false
        const data = response.data.rows
        console.log(data, 111)
        for (let i = 0; i < data.length; i++) {
          data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
          data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
          data[i].执行进度id = parseInt(data[i].执行进度id)
          if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
            data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
          }
          if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
            data[i].是否禁用收款 = true
            data[i].状态 = '进度未完'
          } else {
            data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
            data[i].是否禁用收款 = false
            if (data[i].未收金额 === '0') {
              data[i].是否禁用收款 = true
              data[i].状态 = '已完成'
            } else {
              if (data[i].状态 === '0') {
                data[i].状态 = '未开始'
              }
              if (data[i].状态 === '1') {
                data[i].状态 = '即将拖期'
              }
              if (data[i].状态 === '2') {
                data[i].状态 = '已拖期'
              }
            }
          }
          data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
        }
        this.tableData2 = data
        this.total2 = response.data.total
      })
    },
    handleSizeChange(val) {
      this.PageCurrent = 1
      this.PageSize = val
      this.getTableData()
    },
    handleCurrentChange(val) {
      this.PageCurrent = val
      this.getTableData()
    },
    handleSizeChange2(val) {
      this.PageCurrent2 = 1
      this.PageSize2 = val
      this.getTableData2()
    },
    handleCurrentChange2(val) {
      this.PageCurrent2 = val
      this.getTableData2()
    },
    // 重置表单
    callOff() {
      this.form2.ContractNumberValue = ''
      this.form2.EntryName = ''
      this.form2.TotalContractAmount = ''
      this.form3.付款阶段id = null
      this.form3.付款时间 = ''
      this.form3.本次付款 = ''
      this.form.PaymentPhaseValue = 1
      this.dialogFormVisible1 = false
      this.dialogFormVisible2 = false
      this.dialogFormVisible3 = false
      this.dialogFormVisible4 = false
      this.dialogFormVisible5 = false
    },
    chaEdit() {
      editBatchCapitalChar(this.zijinID, this.form.PaymentPhaseValue, this.form.ThisPayment, this.form.payTime).then(response => {
        this.dialogFormVisible1 = false
        if (response.data[0].result === '1') {
          this.$message.success('信息更新成功')
          this.getTableData()
          this.listLoading2 = true
          searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
            const data = response.data.rows
            for (let i = 0; i < data.length; i++) {
              data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
              data[i].执行进度id = parseInt(data[i].执行进度id)
              if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
              }
              if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                data[i].是否禁用收款 = true
                data[i].状态 = '进度未完'
              } else {
                data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                data[i].是否禁用收款 = false
                if (data[i].未收金额 === '0') {
                  data[i].状态 = '已完成'
                } else {
                  if (data[i].状态 === '0') {
                    data[i].状态 = '未开始'
                  }
                  if (data[i].状态 === '1') {
                    data[i].状态 = '即将拖期'
                  }
                  if (data[i].状态 === '2') {
                    data[i].状态 = '已拖期'
                  }
                }
              }
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
            }
            this.tableData2 = data
            this.total2 = response.data.total
            this.dialogFormVisible4 = false
          })
          this.maxMoney = 0
          this.form.PaymentPhaseValue = 1
        } else {
          this.$message.error('信息更新失败')
        }
      })
    },
    // 提交添加或者修改
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.temp === 1) {
            this.addTableData1()
            // this.form2.ContractNumberValue = ''
            // this.form2.EntryName = ''
            // this.form2.TotalContractAmount = ''
            this.temp = null
          } else if (this.temp === 2) {
            this.chaEdit()
            this.temp = null
          }
        }
      })
    },
    changeMoney() {
      this.form.AlreadyPaid1 = parseFloat(this.form.AlreadyPaid) - parseFloat(this.form.ThisPayment)
    },
    handleDelete(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletechar(row.批次资金id).then(response => {
          if (response.data[0].result === '1') {
            this.getTableData()
            searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
              const data = response.data.rows
              for (let i = 0; i < data.length; i++) {
                data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
                data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
                data[i].执行进度id = parseInt(data[i].执行进度id)
                if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                  data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
                }
                if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                  data[i].是否禁用收款 = true
                  data[i].状态 = '进度未完'
                } else {
                  data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                  data[i].是否禁用收款 = false
                  if (data[i].未收金额 === '0') {
                    data[i].状态 = '已完成'
                  } else {
                    if (data[i].状态 === '0') {
                      data[i].状态 = '未开始'
                    }
                    if (data[i].状态 === '1') {
                      data[i].状态 = '即将拖期'
                    }
                    if (data[i].状态 === '2') {
                      data[i].状态 = '已拖期'
                    }
                  }
                }
                data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
              }
              this.tableData2 = data
              this.total2 = response.data.total
              this.dialogFormVisible4 = false
            })
            this.$message.success('删除成功')
          } else {
            this.$message.error('数据占用')
          }
        })
      })
    },
    ADD(formName) {
      this.form2.entryNameValue = ''
      this.form2.ContractNumberValue = ''
      this.form2.TotalContractAmount = ''
      this.count1 = this.count1 + 1
      if (this.count1 !== 1) {
        this.$refs[formName].resetFields()
      }
      this.dialogFormVisible2 = true
      this.temp = 1
    },
    addTableData1() {
      addList(this.form2.entryNameValue, this.form2.TotalContractAmount).then(response => {
        this.dialogFormVisible2 = false
        if (response.data[0].result === '1') {
          this.$message.success('添加成功')
          this.form2.ContractNumberValue = ''
          this.form2.TotalContractAmount = ''
        } else {
          this.$message.error('添加失败')
        }
        this.getTableData()
      })
    },
    dellist(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        dellist(row.资金id).then(response => {
          if (response.data[0].result === '1') {
            this.getTableData()
            AccountsReceivable().then(response => {
              const data = response.data
              for (let i = 0; i < data.length; i++) {
                data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
                if (data[i].状态 === '1') {
                  data[i].状态 = '即将拖期'
                }
                if (data[i].状态 === '2') {
                  data[i].状态 = '已拖期'
                }
              }
              this.gridData = data
              this.value = response.data.length
            })
            this.$message.success('删除成功')
            this.tableData2 = []
          } else {
            this.$message.error('数据占用')
          }
        })
      })
    },
    changeTime1() {
      this.pickerOptions = Object.assign({}, this.pickerOptions, {
        disabledDate: (time) => {
          return time.getTime() < Date.parse(this.timetime)
        }
      })
    },
    handleEdit1(row) {
      this.addForm('form3')
      this.changeTime1()
      this.title = '收款'
      this.max1 = parseFloat(row.应收金额) - parseFloat(row.已收金额)
      this.dialogFormVisible3 = true
      this.id = row.批次资金id
      this.id1 = row.资金id
    },
    submitEdit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.flag === 1) {
            fukuan(this.id, this.form3.本次付款, this.form3.付款时间).then(response => {
              this.dialogFormVisible3 = false
              if (response.data[0].result === '1') {
                this.$message.success('收款成功')
                this.getTableData()
                searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
                  const data = response.data.rows
                  for (let i = 0; i < data.length; i++) {
                    data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
                    data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
                    data[i].执行进度id = parseInt(data[i].执行进度id)
                    if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                      data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
                    }
                    if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                      data[i].是否禁用收款 = true
                      data[i].状态 = '进度未完'
                    } else {
                      data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                      data[i].是否禁用收款 = false
                      if (data[i].未收金额 === '0') {
                        data[i].状态 = '已完成'
                      } else {
                        if (data[i].状态 === '0') {
                          data[i].状态 = '未开始'
                        }
                        if (data[i].状态 === '1') {
                          data[i].状态 = '即将拖期'
                        }
                        if (data[i].状态 === '2') {
                          data[i].状态 = '已拖期'
                        }
                      }
                    }
                    data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
                  }
                  this.tableData2 = data
                  this.total2 = response.data.total
                  this.dialogFormVisible4 = false
                })
                AccountsReceivable().then(response => {
                  const data = response.data
                  for (let i = 0; i < data.length; i++) {
                    data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
                    if (data[i].状态 === '1') {
                      data[i].状态 = '即将拖期'
                    }
                    if (data[i].状态 === '2') {
                      data[i].状态 = '已拖期'
                    }
                  }
                  this.gridData = data
                  this.value = response.data.length
                })
                selectBatchFundingDetails(this.id).then(response => {
                  for (let i = 0; i < response.data.length; i++) {
                    if (response.data[i].本次收款时间 !== null || response.data[i].本次收款时间 !== '') {
                      response.data[i].本次收款时间 = response.data[i].本次收款时间.substring(0, response.data[i].本次收款时间.length - 9)
                    }
                  }
                  this.tableData4 = response.data
                })
                this.flag = ''
              } else {
                this.$message.error('收款失败')
              }
            })
          } else {
            editFukuan(this.id2, this.form3.本次付款, this.form3.付款时间).then(response => {
              this.dialogFormVisible3 = false
              if (response.data[0].result === '1') {
                this.$message.success('更新信息成功')
                AccountsReceivable().then(response => {
                  const data = response.data
                  for (let i = 0; i < data.length; i++) {
                    data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
                    if (data[i].状态 === '1') {
                      data[i].状态 = '即将拖期'
                    }
                    if (data[i].状态 === '2') {
                      data[i].状态 = '已拖期'
                    }
                  }
                  this.gridData = data
                  this.value = response.data.length
                })
                this.getTableData()
                searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
                  const data = response.data.rows
                  for (let i = 0; i < data.length; i++) {
                    data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
                    data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
                    data[i].执行进度id = parseInt(data[i].执行进度id)
                    if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                      data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
                    }
                    if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                      data[i].是否禁用收款 = true
                      data[i].状态 = '进度未完'
                    } else {
                      data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                      data[i].是否禁用收款 = false
                      if (data[i].未收金额 === '0') {
                        data[i].状态 = '已完成'
                      } else {
                        if (data[i].状态 === '0') {
                          data[i].状态 = '未开始'
                        }
                        if (data[i].状态 === '1') {
                          data[i].状态 = '即将拖期'
                        }
                        if (data[i].状态 === '2') {
                          data[i].状态 = '已拖期'
                        }
                      }
                    }
                    data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
                  }
                  this.tableData2 = data
                  this.total2 = response.data.total
                  this.dialogFormVisible4 = false
                })
                selectBatchFundingDetails(this.id).then(response => {
                  for (let i = 0; i < response.data.length; i++) {
                    if (response.data[i].本次收款时间 !== null || response.data[i].本次收款时间 !== '') {
                      response.data[i].本次收款时间 = response.data[i].本次收款时间.substring(0, response.data[i].本次收款时间.length - 9)
                    }
                  }
                  this.tableData4 = response.data
                })
                this.flag = ''
              } else {
                this.$message.error('更新信息失败')
              }
            })
          }
        }
      })
    },
    EditTableData(row) {
      this.editForm(row, 'form2')
      this.dialogFormVisible4 = true
      this.form2.entryNameValue = parseInt(row.项目流水号)
      this.form2.ContractNumberValue = row.合同编号
      this.form2.TotalContractAmount = row.合同总金额
      this.zijinID = row.资金id
    },
    clear() {
      this.peopleid = ''
    },
    editTableData(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          editList(this.form2.entryNameValue, this.form2.TotalContractAmount, this.zijinID).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('更新信息成功')
              this.getTableData()
              searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
                const data = response.data.rows
                for (let i = 0; i < data.length; i++) {
                  data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
                  data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
                  data[i].执行进度id = parseInt(data[i].执行进度id)
                  if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                    data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
                  }
                  if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                    data[i].是否禁用收款 = true
                    data[i].状态 = '进度未完'
                  } else {
                    data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                    data[i].是否禁用收款 = false
                    if (data[i].未收金额 === '0') {
                      data[i].状态 = '已完成'
                    } else {
                      if (data[i].状态 === '0') {
                        data[i].状态 = '未开始'
                      }
                      if (data[i].状态 === '1') {
                        data[i].状态 = '即将拖期'
                      }
                      if (data[i].状态 === '2') {
                        data[i].状态 = '已拖期'
                      }
                    }
                  }
                  data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
                }
                this.tableData2 = data
                this.total2 = response.data.total
                this.dialogFormVisible4 = false
              })
            } else {
              this.$message.error('更新信息失败')
            }
          })
        }
      })
      // this.editTable(editTableData, [this.zijinID, this.form2.TotalContractAmount], 'form2', function() { this.getTableData(); this.dialogFormVisible4 = false })
    },
    TransferPlan(row) {
      console.log(row)
      this.id = row.批次资金id
      this.max1 = parseFloat(row.未收金额)
      this.form4.转移金额 = parseFloat(row.未收金额)
      this.form4.计划阶段 = parseInt(row.付款批次) + 1
      console.log(this.form4.转移金额, this.form4.计划阶段)
      this.dialogFormVisible5 = true
      this.Planning = []
      this.addForm('form4')
      var j = parseInt(row.付款批次)
      selectBatch(row.资金id).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (i >= j) {
            this.Planning.push({
              label: response.data[i].付款批次,
              value: response.data[i].批次资金ID
            })
          }
        }
      })
    },
    submitTransPlanning() {
      TransPlanning(this.id, parseInt(this.form4.计划阶段), this.form4.转移金额).then(response => {
        this.dialogFormVisible5 = false
        if (response.data[0].result === '1') {
          this.$message.success('更新信息成功')
          AccountsReceivable().then(response => {
            const data = response.data
            for (let i = 0; i < data.length; i++) {
              data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
              if (data[i].状态 === '1') {
                data[i].状态 = '即将拖期'
              }
              if (data[i].状态 === '2') {
                data[i].状态 = '已拖期'
              }
            }
            this.gridData = data
            this.value = response.data.length
          })
          this.getTableData()
          searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
            const data = response.data.rows
            for (let i = 0; i < data.length; i++) {
              data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
              data[i].执行进度id = parseInt(data[i].执行进度id)
              if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
              }
              if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                data[i].是否禁用收款 = true
                data[i].状态 = '进度未完'
              } else {
                data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                data[i].是否禁用收款 = false
                if (data[i].未收金额 === '0') {
                  data[i].状态 = '已完成'
                } else {
                  if (data[i].状态 === '0') {
                    data[i].状态 = '未开始'
                  }
                  if (data[i].状态 === '1') {
                    data[i].状态 = '即将拖期'
                  }
                  if (data[i].状态 === '2') {
                    data[i].状态 = '已拖期'
                  }
                }
              }
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
            }
            this.tableData2 = data
            this.total2 = response.data.total
            this.dialogFormVisible4 = false
          })
          // selectBatchFundingDetails(this.id).then(response => {
          //   for (let i = 0; i < response.data.length; i++) {
          //     response.data[i].本次收款时间 = response.data[i].本次收款时间.substring(0, response.data[i].本次收款时间.length - 9)
          //   }
          //   this.tableData4 = response.data
          // })
        } else {
          this.$message.error('更新信息失败')
        }
      })
    },
    editDay(row) {
      const Day = row.提前x天提醒
      editDay(row.批次资金id, Day).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('更新信息成功')
          AccountsReceivable().then(response => {
            const data = response.data
            for (let i = 0; i < data.length; i++) {
              data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
              if (data[i].状态 === '1') {
                data[i].状态 = '即将拖期'
              }
              if (data[i].状态 === '2') {
                data[i].状态 = '已拖期'
              }
            }
            this.gridData = data
            this.value = response.data.length
          })
          searchTable2(this.PageCurrent2, this.PageSize2, this.moneyID).then(response => {
            const data = response.data.rows
            for (let i = 0; i < data.length; i++) {
              data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
              data[i].执行进度id = parseInt(data[i].执行进度id)
              if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
                data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
              }
              if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
                data[i].是否禁用收款 = true
                data[i].状态 = '进度未完'
              } else {
                data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
                data[i].是否禁用收款 = false
                if (data[i].未收金额 === '0') {
                  data[i].状态 = '已完成'
                } else {
                  if (data[i].状态 === '0') {
                    data[i].状态 = '未开始'
                  }
                  if (data[i].状态 === '1') {
                    data[i].状态 = '即将拖期'
                  }
                  if (data[i].状态 === '2') {
                    data[i].状态 = '已拖期'
                  }
                }
              }
              data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
            }
            this.tableData2 = data
            this.total2 = response.data.total
          })
        } else {
          this.$message.error('更新信息失败')
        }
      })
    },
    AccountsReceivable() {
      this.AccountsReceivableVisible = true
      AccountsReceivable().then(response => {
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
          if (data[i].状态 === '1') {
            data[i].状态 = '即将拖期'
          }
          if (data[i].状态 === '2') {
            data[i].状态 = '已拖期'
          }
        }
        this.gridData = data
        this.value = response.data.length
      })
    },
    tableRowClassName({ row }) {
      if (row.状态 === '即将拖期') {
        return 'background: #ffff66'
      } else if (row.状态 === '已拖期') {
        return 'background: #ff6666'
      } else {
        return ''
      }
    },
    Detail(row) {
      this.moneyID = row.资金ID
      this.id3 = row.批次资金ID
      SelectContractFunds(row.资金ID, this.PageCurrent, this.PageSize).then(response => {
        this.AccountsReceivableVisible = false
        const data = response.data.rows
        for (let i = 0; i < data.length; i++) {
          data[i].未支付金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
          data[i].已支付 === '0' ? data[i].是否禁用编辑 = false : data[i].是否禁用编辑 = true
        }
        this.tableData1 = data
        this.total = response.data.total
      })
      searchTable2(this.PageCurrent2, this.PageSize2, row.资金ID).then(response => {
        const data = response.data.rows
        for (let i = 0; i < data.length; i++) {
          data[i].未收金额 === '0' ? data[i].是否禁用收款 = true : data[i].是否禁用收款 = false
          data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
          data[i].执行进度id = parseInt(data[i].执行进度id)
          if (data[i].节点日期 !== '' && data[i].节点日期 !== null) {
            data[i].节点日期 = data[i].节点日期.substring(0, data[i].节点日期.length - 8)
          }
          if (data[i].计划付款时间 === '' || data[i].计划付款时间 === null) {
            data[i].是否禁用收款 = true
            data[i].状态 = '进度未完'
          } else {
            data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 8)
            data[i].是否禁用收款 = false
            if (data[i].未收金额 === '0') {
              data[i].状态 = '已完成'
            } else {
              if (data[i].状态 === '0') {
                data[i].状态 = '未开始'
              }
              if (data[i].状态 === '1') {
                data[i].状态 = '即将拖期'
              }
              if (data[i].状态 === '2') {
                data[i].状态 = '已拖期'
              }
            }
          }
          data[i].未收金额 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
        }
        this.tableData2 = data
        this.total2 = response.data.total
      })
    },
    tableRowClassName1({ row }) {
      if (this.id3 === parseInt(row.批次资金id)) {
        return 'background: #ccffff'
      } else {
        return ''
      }
    },
    Never(row) {
      never(row.批次资金ID).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('信息更新成功')
          AccountsReceivable().then(response => {
            const data = response.data
            for (let i = 0; i < data.length; i++) {
              data[i].计划付款时间 = data[i].计划付款时间.substring(0, data[i].计划付款时间.length - 9)
              if (data[i].状态 === '1') {
                data[i].状态 = '即将拖期'
              }
              if (data[i].状态 === '2') {
                data[i].状态 = '已拖期'
              }
            }
            this.gridData = data
            this.value = response.data.length
          })
        } else {
          this.$message.error('信息更新失败')
        }
      })
    }
  }
}
</script>

<style scoped>
  /*.el-card {*/
  /*  !*margin-top: 15px;*!*/
  /*}*/

  .el-date-editor{
    width:237px;
  }
  .item {
    float: right;
    margin: 3px;
    margin-right: 40px;
  }
  .el-table td, .el-table th.is-leaf,
  .el-radio__inner,
  .el-input__inner{
    border: 1px solid black!important;
    width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /*.el-table .el-button{*/
  /*  font-size: 17px;*/
  /*}*/
</style>
<style lang="scss">
  .subTableHeader {
    th {
      background: #8ff4ea !important;
      color: black;
    }

    tr.el-table__row td {
      background-color: #d8e5f6 !important;
    }

    tr.el-table__row.el-table__row--striped td {
      background: #e9f0f9 !important;
    }
  }
</style>
