<template>
  <div class="app-container zap-main">
    <search-bar
      v-if="activeIndex === '0'"
      :checkList="checkList"
      :tableList="tableList"
      :selfDom="selfDom"
      :tableId="tableId"
      @query="handleQuery"
      @reset="resetQuery"
    >
      <el-form :model="queryParams" ref="queryForm" v-show="showSearch" label-width="80px">
        <el-row type="flex" style="flex-wrap:wrap;">
          <el-form-item class="zap-flex-1" label="类型" prop="type" size="medium">
            <el-select
              class="zap-form-input--samll"
              v-model="queryParams.type"
              placeholder="请选择查询字段"
              clearable
            >
              <el-option
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item class="zap-flex-1 ml24" prop="value" size="medium" label-width="0">
            <el-input
              class="zap-form-input--default"
              v-model="queryParams.value"
              placeholder="请输入关键字模糊查询"
              clearable
              maxlength="30"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item class="zap-flex-1" label="到期日期" prop="repaymentDate" size="medium">
            <el-date-picker
              class="zap-form-input--medium"
              clearable
              unlink-panels
              v-model="queryParams.repaymentDate"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-row>
      </el-form>
      <el-form
        :model="amountQueryParams"
        ref="amountQueryForm"
        :inline="true"
        v-show="showSearch"
        label-width="auto"
      >
        <el-row type="flex" align="middle">
          <div class="zap-repaid">
            <div class="zap-repaid__select" prop="day">
              <el-select v-model="amountQueryParams.day" size="mini" @change="change">
                <el-option
                  v-for="dict in dayOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
              <span class="zap-repaid__label">待还款</span>
            </div>
            <div class="zap-repaid__amount">¥{{amount}}</div>
          </div>
          <div class="zap-total">
            <div class="zap-total__label">总待还款</div>
            <div class="zap-total__amount">¥{{sumAmount}}</div>
          </div>
        </el-row>
      </el-form>
    </search-bar>
    <search-bar
      v-if="activeIndex === '1'"
      :checkList="checkList"
      :tableList="tableList"
      :selfDom="selfDom"
      :tableId="tableId"
      @query="secondQuery"
      @reset="resetSecondQuery"
    >
      <el-form
        :model="unRepayment"
        ref="queryForm1"
        :inline="true"
        v-show="showSearch"
        label-width="auto"
      >
        <el-form-item label="类型" prop="type" size="large">
          <el-select v-model="unRepayment.type" placeholder="请选择查询字段" clearable>
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item prop="value" size="large">
          <el-input
            v-model="unRepayment.value"
            placeholder="请输入关键字模糊查询"
            clearable
            maxlength="30"
            @keyup.enter.native="secondQuery"
          />
        </el-form-item>
        <el-form-item label="承诺还款日期" prop="repaymentDate" size="large">
          <el-date-picker
            clearable
            unlink-panels
            v-model="unRepayment.repaymentDate"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-form>
    </search-bar>
    <search-bar
      v-if="activeIndex === '2'"
      :checkList="checkList"
      :tableList="tableList"
      :selfDom="selfDom"
      :tableId="tableId"
      @query="thirdQuery"
      @reset="resetThirdQuery"
    >
      <el-form
        :model="repayment"
        ref="queryForm2"
        :inline="true"
        v-show="showSearch"
        label-width="auto"
      >
        <el-form-item label="类型" prop="type" size="large">
          <el-select v-model="repayment.type" placeholder="请选择查询字段" clearable prop="type">
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item prop="value" size="large">
          <el-input
            v-model="repayment.value"
            prop="value"
            placeholder="请输入关键字模糊查询"
            clearable
            maxlength="30"
            @keyup.enter.native="thirdQuery"
          />
        </el-form-item>
        <el-form-item label="承诺还款日期" prop="repaymentDate" size="large">
          <el-date-picker
            clearable
            unlink-panels
            v-model="repayment.repaymentDate"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-form>
    </search-bar>
    <search-bar
      v-if="activeIndex === '3'"
      :checkList="checkList"
      :tableList="tableList"
      :selfDom="selfDom"
      :tableId="tableId"
      @query="fouthQuery"
      @reset="resetFouthQuery"
    >
      <el-form
        :model="overdue"
        ref="queryForm3"
        :inline="true"
        v-show="showSearch"
        label-width="auto"
      >
        <el-form-item label="类型" prop="type" size="large">
          <el-select v-model=" overdue.type" placeholder="请选择查询字段" clearable prop="type">
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item prop="value" size="large">
          <el-input
            v-model=" overdue.value"
            prop="value"
            placeholder="请输入关键字模糊查询"
            clearable
            maxlength="30"
            @keyup.enter.native="fouthQuery"
          />
        </el-form-item>
        <el-form-item label="承诺还款日期" prop="repaymentDate" size="large">
          <el-date-picker
            clearable
            unlink-panels
            v-model=" overdue.repaymentDate"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-form>
    </search-bar>
    <el-tabs class="zap-bg zap-margin-top" v-model="activeIndex">
      <el-tab-pane label="全部">
        <div class="zap-form">
          <div>
            <el-button
              type="primary"
              icon="el-icon-export"
              @click="handleExport"
              v-hasPermi="['service:repayment:export']"
            >导出待还款数据</el-button>
          </div>

          <el-table
            v-loading="loading"
            :data="allRepaymentList"
            @selection-change="handleSelectionChange"
            stripe
            border
          >
            <el-table-column label="序号" type="index" width="50" align="center">
              <template slot-scope="scope">
                <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="融资编号"
              align="center"
              prop="zfrNumber"
              :show-overflow-tooltip="true"
              v-if="uncheckList.zfrNumber"
            />
            <el-table-column
              label="融信编号"
              align="center"
              prop="zfiNumber"
              :show-overflow-tooltip="true"
              v-if="uncheckList.zfiNumber"
            />
            <el-table-column
              label="最终还款方"
              align="center"
              prop="core"
              :show-overflow-tooltip="true"
              v-if="uncheckList.core"
            />
            <el-table-column
              label="融资方"
              align="center"
              prop="supplier"
              :show-overflow-tooltip="true"
              v-if="uncheckList.supplier"
            />
            <el-table-column
              label="资金方"
              align="center"
              prop="scyName"
              :show-overflow-tooltip="true"
              v-if="uncheckList.scyName"
            />
            <el-table-column
              label="还款金额（元）"
              align="center"
              prop="zfrLoanAmount"
              :formatter="moneyFormat"
              :show-overflow-tooltip="true"
              v-if="uncheckList.zfrLoanAmount"
            />
            <el-table-column
              label="还款银行账户"
              align="center"
              prop="zfpcrAccount"
              :show-overflow-tooltip="true"
              v-if="uncheckList.zfpcrAccount"
            />
            <el-table-column
              label="实际还款日期"
              align="center"
              prop="zfrPayDate"
              :show-overflow-tooltip="true"
              v-if="uncheckList.zfrPayDate"
            />
            <el-table-column
              label="承诺还款日期"
              align="center"
              prop="zfrRepaymentDate"
              :show-overflow-tooltip="true"
              v-if="uncheckList.zfrRepaymentDate"
            />
            <el-table-column
              label="还款状态"
              align="center"
              prop="zfrApplyStatus"
              :formatter="applyStatusFormat"
              :show-overflow-tooltip="true"
              v-if="uncheckList.zfrApplyStatus"
            />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
              fixed="right"
              width="200px"
            >
              <template slot-scope="scope">
                <el-button
                  class="zap-button-plain"
                  size="mini"
                  type="text"
                  @click="handleInfo(scope.row)"
                  v-hasPermi="['service:repayment:query']"
                >详情</el-button>
                <el-button
                  class="zap-button-warning"
                  size="mini"
                  type="text"
                  @click="handleDown(scope.row)"
                  v-hasPermi="['service:repayment:down']"
                >下载</el-button>
                <el-button
                  class="zap-button-primary"
                  size="mini"
                  type="text"
                  @click="handleUp(scope.row)"
                  v-hasPermi="['service:repayment:edit']"
                  v-if="scope.row.zfrApplyStatus != '01' && (company.scyType == '00'||
                  company.scyType == '03')"
                >还款登记</el-button>
              </template>
            </el-table-column>
          </el-table>
          <statistical-data>
            <span class="label">
              总合计:
              <span class="value">¥{{allAmount}}</span>
            </span>
            <span class="label">待还款:¥{{dhkAmount}}</span>
            <span class="label">已还款:¥{{yhkAmount}}</span>
            <span class="label">已逾期:¥{{yyqAmount}}</span>
          </statistical-data>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </el-tab-pane>
      <el-tab-pane label="待还款">
        <div class="zap-content">
          <el-button
            type="primary"
            icon="el-icon-export"
            @click="handleExport"
            v-hasPermi="['service:repayment:export']"
          >导出待还款数据</el-button>
        </div>
        <el-table
          v-loading="loading"
          :data="unRepaymentList"
          @selection-change="handleSelectionChange"
          border
          stripe
        >
          <el-table-column label="序号" type="index" width="50" align="center">
            <template slot-scope="scope">
              <span>{{(unRepayment.pageNum - 1) * unRepayment.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="融资编号"
            align="center"
            prop="zfrNumber"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrNumber"
          />
          <el-table-column
            label="融信编号"
            align="center"
            prop="zfiNumber"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfiNumber"
          />
          <el-table-column
            label="最终还款方"
            align="center"
            prop="core"
            :show-overflow-tooltip="true"
            v-if="uncheckList.core"
          />
          <el-table-column
            label="融资方"
            align="center"
            prop="supplier"
            :show-overflow-tooltip="true"
            v-if="uncheckList.supplier"
          />
          <el-table-column
            label="资金方"
            align="center"
            prop="scyName"
            :show-overflow-tooltip="true"
            v-if="uncheckList.scyName"
          />
          <el-table-column
            label="还款金额（元）"
            align="center"
            prop="zfrLoanAmount"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrLoanAmount"
          />
          <el-table-column
            label="还款银行账户"
            align="center"
            prop="zfpcrAccount"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfpcrAccount"
          />
          <el-table-column
            label="实际还款日期"
            align="center"
            prop="zfrPayDate"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrPayDate"
          />
          <el-table-column
            label="承诺还款日期"
            align="center"
            prop="zfrRepaymentDate"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrRepaymentDate"
          />
          <el-table-column
            label="还款状态"
            align="center"
            prop="zfrApplyStatus"
            :formatter="applyStatusFormat"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrApplyStatus"
          />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                class="zap-button-plain"
                size="mini"
                type="text"
                @click="handleInfo(scope.row)"
                v-hasPermi="['service:repayment:query']"
              >详情</el-button>
              <el-button
                class="zap-button-warning"
                size="mini"
                type="text"
                @click="handleDown(scope.row)"
                v-hasPermi="['service:repayment:down']"
              >下载</el-button>
              <el-button
                class="zap-button-primary"
                size="mini"
                type="text"
                @click="handleUp(scope.row)"
                v-hasPermi="['service:repayment:edit']"
                v-if="scope.row.zfrApplyStatus != '01'&&(company.scyType == '00'||
                  company.scyType == '03')"
              >还款登记</el-button>
            </template>
          </el-table-column>
        </el-table>
        <statistical-data>
          <span class="label">
            总合计:
            <span class="value">¥{{allAmount}}</span>
          </span>
          <span class="label">待还款:¥{{dhkAmount}}</span>
        </statistical-data>
        <pagination
          v-show="total>0"
          :total="total1"
          :page.sync="unRepayment.pageNum"
          :limit.sync="unRepayment.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="已还款">
        <div class="zap-content">
          <el-button
            type="primary"
            icon="el-icon-export"
            @click="handleExport"
            v-hasPermi="['service:repayment:export']"
          >导出待还款数据</el-button>
        </div>
        <el-table
          v-loading="loading"
          :data="repaymentList"
          @selection-change="handleSelectionChange"
          border
          stripe
        >
          <el-table-column label="序号" type="index" width="50" align="center">
            <template slot-scope="scope">
              <span>{{(repayment.pageNum - 1) * repayment.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="融资编号"
            align="center"
            prop="zfrNumber"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrNumber"
          />
          <el-table-column
            label="融信编号"
            align="center"
            prop="zfiNumber"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfiNumber"
          />
          <el-table-column
            label="最终还款方"
            align="center"
            prop="core"
            :show-overflow-tooltip="true"
            v-if="uncheckList.core"
          />
          <el-table-column
            label="融资方"
            align="center"
            prop="supplier"
            :show-overflow-tooltip="true"
            v-if="uncheckList.supplier"
          />
          <el-table-column
            label="资金方"
            align="center"
            prop="scyName"
            :show-overflow-tooltip="true"
            v-if="uncheckList.scyName"
          />
          <el-table-column
            label="还款金额（元）"
            align="center"
            prop="zfrLoanAmount"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrLoanAmount"
          />
          <el-table-column
            label="还款银行账户"
            align="center"
            prop="zfpcrAccount"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfpcrAccount"
          />
          <el-table-column
            label="实际还款日期"
            align="center"
            prop="zfrPayDate"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrPayDate"
          />
          <el-table-column
            label="承诺还款日期"
            align="center"
            prop="zfrRepaymentDate"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrRepaymentDate"
          />
          <el-table-column
            label="还款状态"
            align="center"
            prop="zfrApplyStatus"
            :formatter="applyStatusFormat"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrApplyStatus"
          />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                class="zap-button-plain"
                size="mini"
                type="text"
                @click="handleInfo(scope.row)"
                v-hasPermi="['service:repayment:query']"
              >详情</el-button>
              <el-button
                class="zap-button-warning"
                size="mini"
                type="text"
                @click="handleDown(scope.row)"
                v-hasPermi="['service:repayment:down']"
              >下载</el-button>
            </template>
          </el-table-column>
        </el-table>
        <statistical-data>
          <span class="label">
            总合计:
            <span class="value">¥{{allAmount}}</span>
          </span>
          <span class="label">已还款:¥{{yhkAmount}}</span>
        </statistical-data>
        <pagination
          v-show="total>0"
          :total="total2"
          :page.sync="repayment.pageNum"
          :limit.sync="repayment.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="已逾期">
        <div class="zap-content">
          <el-button
            type="primary"
            icon="el-icon-export"
            @click="handleExport"
            v-hasPermi="['service:repayment:export']"
          >导出待还款数据</el-button>
        </div>
        <el-table
          v-loading="loading"
          :data="overdueList"
          @selection-change="handleSelectionChange"
          border
          stripe
        >
          <el-table-column label="序号" type="index" width="50" align="center">
            <template slot-scope="scope">
              <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="融资编号"
            align="center"
            prop="zfrNumber"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrNumber"
          />
          <el-table-column
            label="融信编号"
            align="center"
            prop="zfiNumber"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfiNumber"
          />
          <el-table-column
            label="最终还款方"
            align="center"
            prop="core"
            :show-overflow-tooltip="true"
            v-if="uncheckList.core"
          />
          <el-table-column
            label="融资方"
            align="center"
            prop="supplier"
            :show-overflow-tooltip="true"
            v-if="uncheckList.supplier"
          />
          <el-table-column
            label="资金方"
            align="center"
            prop="scyName"
            :show-overflow-tooltip="true"
            v-if="uncheckList.scyName"
          />
          <el-table-column
            label="还款金额（元）"
            align="center"
            prop="zfrLoanAmount"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrLoanAmount"
          />
          <el-table-column
            label="还款银行账户"
            align="center"
            prop="zfpcrAccount"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfpcrAccount"
          />
          <el-table-column
            label="实际还款日期"
            align="center"
            prop="zfrPayDate"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrPayDate"
          />
          <el-table-column
            label="承诺还款日期"
            align="center"
            prop="zfrRepaymentDate"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrRepaymentDate"
          />
          <el-table-column
            label="还款状态"
            align="center"
            prop="zfrApplyStatus"
            :formatter="applyStatusFormat"
            :show-overflow-tooltip="true"
            v-if="uncheckList.zfrApplyStatus"
          />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                class="zap-button-plain"
                size="mini"
                type="text"
                @click="handleInfo(scope.row)"
                v-hasPermi="['service:repayment:query']"
              >详情</el-button>
              <el-button
                class="zap-button-warning"
                size="mini"
                type="text"
                @click="handleDown(scope.row)"
                v-hasPermi="['service:repayment:down']"
              >下载</el-button>
              <el-button
                class="zap-button-primary"
                size="mini"
                type="text"
                @click="handleUp(scope.row)"
                v-hasPermi="['service:repayment:edit']"
                v-if="scope.row.zfrApplyStatus != '01'&&(company.scyType == '00'||
                  company.scyType == '03')"
              >还款登记</el-button>
            </template>
          </el-table-column>
        </el-table>
        <statistical-data>
          <span class="label">
            总合计:
            <span class="value">¥{{allAmount}}</span>
          </span>
          <span class="label">已逾期:¥{{yyqAmount}}</span>
        </statistical-data>
        <pagination
          v-show="total>0"
          :total="total3"
          :page.sync="overdue.pageNum"
          :limit.sync="overdue.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>

      <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="zap-form">
          <el-form-item label="上传附件">
            <el-upload
              ref="upload"
              class="upload-demo"
              action
              :class="{showUoload:showBtnImg,uoloadSty:noneBtnImg}"
              :on-change="dealImgChange"
              accept=".jpg, .jpeg, .png"
              :http-request="httpRequest"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
              :before-upload="beforeAvatarUpload"
              multiple
              :limit="1"
              :on-exceed="handleExceed"
              list-type="picture-card"
              :file-list="fileList"
              :auto-upload="true"
            >
              <div slot="trigger" class="zap-contract-add__upload">
                <i class="el-icon-upload"></i>
                <div class="zap-upload__text">上传文件</div>
              </div>
            </el-upload>
          </el-form-item>
          <el-form-item label="融资id" prop="zfrId" label-width="90px" v-if="false">
            <el-input v-model="form.zfrId" style="width:284px" />
          </el-form-item>
          <!-- <el-form-item label="融信id" prop="zfrFinanceId" label-width="90px" v-if="false">
          <el-input v-model="form.zfrFinanceId"  style="width:284px"/>
          </el-form-item>-->
        </el-form>
        <el-row style="height: 109px;" type="flex" align="middle" justify="center">
          <el-button type="primary" plain @click="cancel">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </el-row>
      </el-dialog>
      <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt />
      </el-dialog>
    </el-tabs>
  </div>
</template>

<script>
import {
  listRepayment,
  RepaymentRegistration,
  repaymentAmount,
  listAmount
} from "@/api/service/repayment/repayment";
import ColumnSetting from "../../../components/Table/columnSetting.vue";
import { columnQuery, columnfilter } from "@/api/common/columnSetting";
import { getOwnCompany } from "@/api/common/company";
import Cookies from "js-cookie";
import { uploadFileNew } from "@/api/common/file";
import { getToken } from "@/utils/auth";
import SearchBar from "@/components/SearchBar/index.vue";
export default {
  name: "repayment",
  components: {
    ColumnSetting,
    SearchBar
  },
  data() {
    return {
      allAmount: "0.00",
      dhkAmount: "0.00",
      yhkAmount: "0.00",
      yyqAmount: "0.00",
      activeIndex: "",
      //总代还款金额
      sumAmount: 0.0,
      //带还款金额
      amount: 0.0,
      dayOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      total2: 0,
      total3: 0,
      //附件按钮
      showBtnImg: true,
      noneBtnImg: false,
      limitCountImg: 1,
      //上传使用
      dialogImageUrl: "",
      dialogVisible: false,
      //附件地址
      fileList: [],
      // 弹出层标题
      title: "",
      // 全部还款列表
      allRepaymentList: [],
      //待还款列表
      unRepaymentList: [],
      //已还款列表
      repaymentList: [],
      //已逾期列表
      overdueList: [],
      typeOptions: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        value: null,
        repaymentDate: [],
        status: null
      },
      unRepayment: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        value: null,
        repaymentDate: [],
        status: null
      },
      repayment: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        value: null,
        repaymentDate: [],
        status: null
      },
      overdue: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        value: null,
        repaymentDate: [],
        status: null
      },
      amountQueryParams: {
        day: "00"
      },
      // 表单参数
      form: {},
      amountQueryForm: {
        day: "00"
      },
      // 表单校验
      rules: {
        //  pptName:[
        //   { required: true, message: "项目类型不能为空", trigger: "blur" },
        // ]
      },
      tableList: [
        {
          label: "zfrNumber",
          value: "融资编号"
        },
        {
          label: "zfiNumber",
          value: "融信编号"
        },
        {
          label: "core",
          value: "最终还款方"
        },
        {
          label: "supplier",
          value: "融资方"
        },
        {
          label: "scyName",
          value: "资金方"
        },
        {
          label: "zfrLoanAmount",
          value: "还款金额（元）"
        },
        {
          label: "zfpcrAccount",
          value: "还款银行账户"
        },
        {
          label: "zfrPayDate",
          value: "实际还款日期"
        },
        {
          label: "zfrRepaymentDate",
          value: "承诺还款日期"
        },
        {
          label: "zfrApplyStatus",
          value: "还款状态"
        }
      ],
      checkList: [], //筛选列选中的数据列表--显示隐藏列用
      uncheckList: {}, //控制筛选列显示隐藏--显示隐藏列用
      selfDom: this,
      tableId: "/service/repayment/list"
    };
  },
  created() {
    //this.getRepaymentAmount();
    this.getDicts("zc_zfr_apply_status").then(response => {
      this.applyStatusOptions = response.data;
    });
    this.getDicts("zc_zfr_type").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("zc_repanyment_day").then(response => {
      this.dayOptions = response.data;
    });
    this.amountQueryParams.day = null;
    repaymentAmount(this.amountQueryParams).then(response => {
      this.sumAmount = response.data;
      this.amount = response.data;
    });
    this.getList().then(() => {
      this.queryParams.type = "00";
    });
    this.getUnpayList().then(() => {
      this.unRepayment.type = "00";
    });
    this.getRepayList().then(() => {
      this.repayment.type = "00";
    });
    this.getOverdueList().then(() => {
      this.overdue.type = "00";
    });
  },
  activated() {
    this.getList();
  },
  mounted() {
    this.columnQuery();
  },
  methods: {
    //列表格式化金额
    moneyFormat(row, column, cellValue) {
      if (cellValue == null || cellValue == undefined || cellValue == "") {
        cellValue = "0.00";
      }
      cellValue += "";
      if (!cellValue.includes(".")) {
        cellValue += ".00";
      }
      return cellValue
        .replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
          return $1 + ",";
        })
        .replace(/\.$/, "");
    },
    /** 查询所有还款列表 */
    getList() {
      this.loading = true;
      listAmount().then(response => {
        debugger;
        this.allAmount = response.data.allAmount;
        this.dhkAmount = response.data.dhkAmount;
        this.yhkAmount = response.data.yhkAmount;
        this.yyqAmount = response.data.yyqAmount;
      });
      return getOwnCompany().then(response => {
        this.company = response.data;
        return listRepayment(this.queryParams)
          .then(response => {
            this.allRepaymentList = response.data.records;
            this.total = response.data.total;
            this.loading = false;
            return Promise.resolve(response);
          })
          .catch(response => {
            this.loading = false;
            return Promise.reject("error");
          });
      });
    },
    /** 查询未还款列表 */
    getUnpayList() {
      this.loading = true;
      this.unRepayment.status = "00";
      listAmount().then(response => {
        debugger;
        this.allAmount = response.data.allAmount;
        this.dhkAmount = response.data.dhkAmount;
        this.yhkAmount = response.data.yhkAmount;
        this.yyqAmount = response.data.yyqAmount;
      });
      return getOwnCompany().then(response => {
        this.company = response.data;
        return listRepayment(this.unRepayment)
          .then(response => {
            this.unRepaymentList = response.data.records;
            this.total1 = response.data.total;
            this.loading = false;
            return Promise.resolve(response);
          })
          .catch(response => {
            this.loading = false;
            return Promise.reject("error");
          });
      });
    },
    /** 查询已还款列表 */
    getRepayList() {
      this.loading = true;
      this.repayment.status = "01";
      listAmount().then(response => {
        debugger;
        this.allAmount = response.data.allAmount;
        this.dhkAmount = response.data.dhkAmount;
        this.yhkAmount = response.data.yhkAmount;
        this.yyqAmount = response.data.yyqAmount;
      });
      return getOwnCompany().then(response => {
        this.company = response.data;
        return listRepayment(this.repayment)
          .then(response => {
            this.repaymentList = response.data.records;
            this.total2 = response.data.total;
            this.loading = false;
            return Promise.resolve(response);
          })
          .catch(response => {
            this.loading = false;
            return Promise.reject("error");
          });
      });
    },
    /** 查询已逾期列表 */
    getOverdueList() {
      this.loading = true;
      this.overdue.status = "02";
      listAmount().then(response => {
        debugger;
        this.allAmount = response.data.allAmount;
        this.dhkAmount = response.data.dhkAmount;
        this.yhkAmount = response.data.yhkAmount;
        this.yyqAmount = response.data.yyqAmount;
      });
      return getOwnCompany().then(response => {
        console.log(response, "企业数据");
        this.company = response.data;
        return listRepayment(this.overdue)
          .then(response => {
            this.overdueList = response.data.records;
            this.total3 = response.data.total;
            this.loading = false;
            return Promise.resolve(response);
          })
          .catch(response => {
            this.loading = false;
            return Promise.reject("error");
          });
      });
    },
    /** 查询带还款金额 */
    getRepaymentAmount() {
      repaymentAmount(this.amountQueryParams).then(response => {
        this.amount = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.fileList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */

    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    secondQuery() {
      this.unRepayment.pageNum = 1;
      this.getUnpayList();
    },
    thirdQuery() {
      this.repayment.pageNum = 1;
      this.getRepayList();
    },
    fouthQuery() {
      this.overdue.pageNum = 1;
      this.getOverdueList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    resetSecondQuery() {
      this.resetForm("queryForm1");
      this.secondQuery();
    },
    resetThirdQuery() {
      this.resetForm("queryForm2");
      this.thirdQuery();
    },
    resetFouthQuery() {
      this.resetForm("queryForm3");
      this.fouthQuery();
    },
    change(val) {
      this.amountQueryParams.day = val;
      repaymentAmount(this.amountQueryParams).then(response => {
        this.amount = response.data;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      /*  this.ids = selection.map(item => item.ptcId)
            this.single = selection.length!==1
            this.multiple = !selection.length */
    },
    /** 详情按钮操作 */
    handleInfo(row) {
      const zfrId = row.zfrId;
      this.resetForm("queryForm");
      this.resetForm("queryForm1");
      this.resetForm("queryForm2");
      this.resetForm("queryForm3");
      Cookies.set(
        "/repayment/detailRepayment/" + zfrId + "/",
        this.$route.fullPath
      );
      this.$router.push({
        path: "/repayment/detailRepayment/" + zfrId + "/"
      });
    },
    /** 下载按钮操作 */
    handleDown(row) {
      var zfrId = row.zfrId;
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.download(
        "sc-service/repayment/export/" + encodeURI(zfrId),
        {},
        `还款明细.doc`
      );
      setTimeout(() => {
        loading.close();
        this.create = false;
        this.end = true;
        this.active = 1;
      }, 3000);
    },
    //上传附件
    handleUp(row) {
      this.reset();
      this.form.zfrId = row.zfrId || this.ids;
      this.showBtnImg = true;
      this.noneBtnImg = this.fileList.length >= this.limitCountImg;
      this.open = true;
      this.title = "还款登记";
      this.handleQuery();
    },
    //上传前校验
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg" || file.type === "image/png";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传图片只能是 JPG/PNG 格式");
      }
      if (!isLt2M) {
        this.$message.error("上传图片大小不能超过 2MB");
      }
      return isJPG && isLt2M;
    },
    //还款状态字典反显
    applyStatusFormat(row, column) {
      return this.selectDictLabel(this.applyStatusOptions, row.zfrApplyStatus);
    },
    //获取当前客户是否之前设置过列展示隐藏
    columnQuery() {
      //获取页面路径
      var psfPagePath = window.location.pathname; //用请求后台的url作为唯一标识

      var psfTableName = this.tableId;
      var columnForm = {};
      columnForm.psfPagePath = psfPagePath;
      columnForm.psfTableName = psfTableName;
      columnQuery(columnForm).then(response => {
        if (response.data && response.data.psfShowData) {
          this.checkList = response.data.psfShowData;
        }
        this.filter();
      });
    }, //控制隐藏显示的函数
    filter(checkList) {
      if (!!checkList) {
        this.checkList = checkList;
      }
      columnfilter(this.selfDom);
    },
    /** 上传图片 */
    submitUpload() {
      this.$refs.upload.submit();
    },
    //文件移除提示
    handleRemove(file, fileList) {
      console.log(file);
      for (let i = 0; i < this.fileList.length; i++) {
        if (file.uid == this.fileList[i].uid) {
          this.fileList.splice(i, 1);
          break;
        }
      }
      this.noneBtnImg = fileList.length >= this.limitCountImg;
      //return this.$confirm(`确定移除 ${ file.name }？`);
    },

    dealImgChange(file, fileList) {
      this.noneBtnImg = fileList.length >= this.limitCountImg;
    },

    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件`);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    //手动上传文件触发
    httpRequest(param) {
      let fileObj = param.file; // 相当于input里取得的files
      let fd = new FormData(); // FormData 对象
      fd.append("file", fileObj); // 文件对象
      fd.append("fileType", "00"); //文件类型
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      uploadFileNew(fd)
        .then(response => {
          if (response) {
            // this.form.eeiImgUrl = response.url
            this.fileList.push({
              uid: response.fileId,
              url: response.url + "/" + getToken()
            });
            console.log(response.url);
            setTimeout(() => {
              loading.close();
            }, 2000);
          }
        })
        .catch(response => {
          loading.close();
        });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.zfrId != null) {
            this.form.zfrApplyFile = this.fileList;
            RepaymentRegistration(this.form).then(response => {
              this.msgSuccess("登记成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.download(
        "sc-service/repayment/export",
        {
          ...this.queryParams
        },
        `待还款列表.xls`
      );
      setTimeout(() => {
        loading.close();
        this.create = false;
        this.end = true;
        this.active = 1;
      }, 3000);
    }
  }
};
</script>

<style>
.uoloadSty .el-upload--picture-card {
  display: none;
}
</style>
<style lang="scss" scoped>
::v-deep .el-textarea__inner {
  width: 100%;
  height: 106px;
  background-image: linear-gradient(#f4f5f6, #f4f5f6),
    linear-gradient(#71befe, #71befe);
  background-blend-mode: normal, normal;
  border: solid 1px #ebebeb;
}

::v-deep .el-textarea .el-input__count {
  background-color: transparent;
}

::v-deep .el-upload--picture-card {
  border: none;
}

.zap-contract-add__upload {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 148px;
  height: 148px;
  border: dashed 1px #e0e0e0;
  background-color: #f4f5f6;
}

.el-icon-upload {
  font-size: 32px;
  color: #02c464;
}

.zap-upload__text {
  line-height: 1;
  margin-top: 12px;
  font-size: 12px;
  color: #333333;
}

.zap-repaid {
  position: relative;
  padding-right: 70px;
  padding-top: 10px;
  padding-left: 42px;
  padding-bottom: 24px;

  &::after {
    content: "";
    display: block;
    position: absolute;
    top: 10px;
    right: 0;
    width: 1px;
    height: calc(100% - 44px);
    border-right: 1px solid #ebebeb;
  }

  .el-form-item {
    margin-bottom: 0;
  }
}

.zap-repaid__label {
  margin-left: 16px;
  font-size: 14px;
  color: #333333;
}

.zap-repaid__amount {
  margin-top: 24px;
  font-size: 28px;
  font-weight: 500;
  color: #ff2f2f;
}

.zap-total {
  padding-top: 10px;
  padding-left: 70px;
  padding-bottom: 24px;
}

.zap-total__label {
  height: 28px;
  line-height: 28px;
  font-size: 14px;
  color: #333333;
}

.zap-total__amount {
  margin-top: 24px;
  font-size: 28px;
  font-weight: 500;
  color: #4280f2;
}

.zap-title {
}
::v-deep .zap-repaid__select .el-form-item--medium .el-form-item__content {
  line-height: 32px;
}
.zap-repaid__select {
  ::v-deep .el-select,
  ::v-deep .el-input__inner {
    width: 105px;
    color: #ff2f2f;
    border-color: #ff2f2f;
    background-color: #fff6f6;
    border-radius: 16px;
  }

  ::v-deep .el-select .el-input.is-focus .el-input__inner {
    border-color: #ff2f2f;
  }

  ::v-deep .el-input__icon,
  ::v-deep ::placeholder {
    color: #ff2f2f;
  }
}
</style>
