<template>
  <div>
    <br>
    <div class="top">
      <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
        <el-form-item label="姓名:">
          <el-input placeholder="请输入客户姓名" v-model="searchInfo.clientName"></el-input>
        </el-form-item>
        <el-form-item label="客户编号:">
          <el-input placeholder="请输入客户编号" v-model="searchInfo.clientNo"></el-input>
        </el-form-item>
        <el-form-item label="放款编号:">
          <el-input placeholder="请输入放款编号" v-model="searchInfo.bizNo"></el-input>
        </el-form-item>

        <el-form-item label="项目类型:">
          <el-select v-model="searchInfo.hangUp" clearable placeholder="全部">
            <el-option v-for="item in this.$enumUtils.toValue('SystemType')" :key="item.value"
                       :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="放款结果:">
          <el-select v-model="searchInfo.status" clearable placeholder="全部">
            <el-option v-for="item in this.$enumUtils.toValue('ResultSuccessFail')" :key="item.value"
                       :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="放款时间:">
          <el-date-picker v-model="searchInfo.date" type="daterange" range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期" :clearable="false"></el-date-picker>
        </el-form-item>
        <div class="btn">
          <el-button @click="reset" type="primary">重置</el-button>
          <el-button @click="querySearchRemind" type="primary">查询</el-button>
          <br/>
          <br/>
          <el-button @click="exportMoney()" type="primary">导出数据</el-button>
        </div>
      </el-form>
    </div>
    <div class="system-list">
      <!-- 数据统计 -->
      <el-row :gutter="20" style="margin-left:30px">
        <el-col :span="12">
          <strong>
            <div class="grid-content bg-purple">
              {{ this.countRaise.dateDate }} 应放款款金额:{{ this.countRaise.allRaise }} 元<br/><br/>
              {{ this.countRaise.dateDate }} 实际放款总金额:{{ this.countRaise.realRaise }} 元
            </div>
          </strong>
        </el-col>
      </el-row>
      <el-table :data="tablePlanRemindData" style="width: 100%" :default-sort="{prop: 'date', order: 'descending'}"
                :highlight-current-row="true">
        <el-table-column prop="raiseNo" label="放款流水号"></el-table-column>
        <el-table-column prop="bizTypeStr" label="项目类型"></el-table-column>
        <el-table-column prop="clientNo" label="客户编号"></el-table-column>
        <el-table-column prop="cardOwnerName" label="姓名"></el-table-column>
        <el-table-column prop="loanCreateTime" label="申请时间" :formatter="transDateFormat" sortable
        ></el-table-column>
        <el-table-column prop="raiseAmt" label="放款金额"></el-table-column>
        <el-table-column prop="cardBankAccount" label="放款银行卡"></el-table-column>
        <el-table-column prop="raiseDate" label="放款时间" :formatter="transDateFormat" sortable
        ></el-table-column>
        <el-table-column prop="resultStr" label="放款结果"></el-table-column>
        <el-table-column prop="confirmDesc" label="确认信息"></el-table-column>

        <!-- <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="checkDetails(scope.row)">查看详情</el-button>
          </template>
        </el-table-column> -->
      </el-table>
    </div>
    <div class="page">
      <el-pagination
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :current-page.sync="page.current"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="page.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">

      </el-pagination>

    </div>

  </div>
</template>

<script>
import * as moment from "moment";

export default {
  name: "ByhPlanRemindList",
  components: {},
  data() {
    return {
      flag: false,
      fold: true,
      ui:
          {
            jumpUserDetail: {
              visible: false,
              bizNo: '',
              clientNo: ''
            },
            byhExportMoney: {
              visible: false,
              clientNo: '',
              raiseNo: '',
              clientName: '',
              result: '',
              bizType: '',
              raiseDateStart: '',
              raiseDateEnd: '',
              type: '2',
            },
          },
      page: {
        current: 1,
        size: 10,
        total: 0
      },
      countRaise: {
        allRaise: '',
        realRaise: '',
        dateDate: ''
      },
      activeName: '',
      searchInfo: {
        date: [],
        bizNo: '',
        clientNo: '',
        clientName: '',
        status: '',
        hangUp: '',
      },
      tablePlanRemindData: [],
      record: '',
      allUser: [],
    }

  },

  created() {
    if (this.$route != null && this.$route.query != null && this.$route.query.flag) {
      this.flag = this.$route.query.flag;
      this.searchInfo.bizNo = this.$route.query.bizNo;
      this.searchInfo.clientNo = this.$route.query.clientNo;
      this.searchInfo.clientName = this.$route.query.clientName;
      this.searchInfo.followUser = this.$route.query.followUser;
      this.searchInfo.status = this.$route.query.status;
      this.page.current = parseInt(this.$route.query.current);
      this.searchInfo.date = this.mergeDate(this.$route.query.planDateStart, this.$route.query.planDateEnd);
    }
    // 统计数据请求
    this.$$get(`/raise/countRaise`)
        .then(res => {
          console.log(res)
          if (res.data.code != 200) {
            throw res.data.message;
          }
          this.countRaise = res.data.result;
          this.countRaise.dateDate = moment(new Date()).format("YYYY-MM-DD");
        })

  },

  mounted: function () {
    this.tablePlanRemindData = this.remindData();
  },

  methods: {

    exportMoney() {
      var end = new Date(this.searchInfo.date[1])
      end = end.setDate(end.getDate() + 1);
      end = new Date(end);
      this.ui.byhExportMoney = {
        visible: true,
        type: 2,
        clientNo: this.searchInfo.clientNo,
        raiseNo: this.searchInfo.bizNo,
        clientName: this.searchInfo.clientName,
        result: this.searchInfo.status,
        bizType: this.searchInfo.hangUp,
        raiseDateStart: this.searchInfo.date[0],
        raiseDateEnd: end,
      };
    },
    formatter(row, column) {
      return row.address;
    },
    selected: function (gameName) {
      this.activeName = gameName
    },
    /** 加载数据 */
    remindData(params) {
      var listsData = [];
      this.$$post('/raise/getRaiseList', this.buildParam()).then(res => {
        if (res.data.code != 200) {
          this.$message.error(res.data.message);
          return
        }
        listsData = res.data.result.data;
        this.tablePlanRemindData = listsData;
        this.page.total = res.data.result.total;
      }).catch(error => {
        this.$Message.error(error || '系统异常');
      });
    },

    // 分配后不刷新页面加载数据
    getMyMarket(msg) {
      if (msg) {
        this.tablePlanRemindData = this.remindData();
      }
    },

    //搜索查询
    querySearchRemind() {
      this.remindData();
    },

    /*提醒期数*/
    planIndexFormat: function (row, column) {
      var planIndex = row[column.property]
      if (planIndex == undefined) {
        return ''
      }
      return planIndex + '/3'
    },

    //查看详情
    checkDetails(record) {

      this.$$get(`/repayRemind/getByhRemindDetail/${record.clientNo}/${record.planNo}`)
          .then(res => {
            if (res.data.code != 1)
              throw res.data.msg;
          })
          .catch(err => this.$$msg.err(err))
      this.$router.push({
        path: 'ByhPlanRemindDetails',
        query: {
          orderNo: record.orderNo,
          planNo: record.planNo,
          loanNo: record.loanNo,
          certNo: record.certNo,
          clientCell: record.clientCell,
          clientNo: record.clientNo,
          clientName: record.clientName,
          idCard: this.searchInfo.idCard,
          followUser: this.searchInfo.followUser,
          phoneNo: this.searchInfo.phoneNo,
          name: this.searchInfo.name,
          status: this.searchInfo.status,
          current: this.page.current,
          type: 1,
          planDateStart: this.getDate(this.searchInfo.date, 0),
          planDateEnd: this.getDate(this.searchInfo.date, 1),
        }
      })
    },

    /* 逾期期数 */
    planIndexFormat: function (row) {
      var planIndex = row.planIndex
      var allIndex = row.allIndex
      if (planIndex == undefined || allIndex == undefined) {
        return ''
      }
      return planIndex + '/' + allIndex
    },

    handleFold() {
      this.fold = !this.fold;
    },
    handleSizeChange(row) {
      this.page.size = row
      this.page.current = 1;
      this.remindData();
    },

    //参数
    buildParam() {
      var return_hash = {
        size: this.page.size,
        current: this.page.current,
      };
      if (this.searchInfo.clientNo != '') {
        return_hash['clientNo'] = this.searchInfo.clientNo
      }
      if (this.searchInfo.bizNo != '') {
        return_hash['raiseNo'] = this.searchInfo.bizNo
      }
      // 修改手机号查询为客户编号查询
      if (this.searchInfo.clientName != '') {
        return_hash['clientName'] = this.searchInfo.clientName
      }
      if (this.searchInfo.status != '') {
        return_hash['result'] = this.searchInfo.status
      }
      // 系统类型
      if (this.searchInfo.hangUp != '') {
        return_hash['bizType'] = this.searchInfo.hangUp
      }

      if (this.searchInfo.date != null && this.searchInfo.date.length > 0) {
        var end = new Date(this.searchInfo.date[1])

        end = end.setDate(end.getDate() + 1);
        end = new Date(end);

        return_hash['raiseDateStart'] = this.searchInfo.date[0];
        return_hash['raiseDateEnd'] = end
      }

      return return_hash;
    },



    //重置
    reset() {
      this.searchInfo.date = '';
      this.searchInfo.clientNo = '';
      this.searchInfo.bizNo = '';
      this.searchInfo.clientName = '';
      this.searchInfo.status = '';
      this.searchInfo.followUser = '';
      this.searchInfo.followUserZh = '';
      this.searchInfo.hangUp = '';
    },

    /** 处理分页操作*/
    handleCurrentChange() {
      this.tablePlanRemindData = this.remindData();
    },

    getStatus(row) {
      let value = row.status;
      if (value === 'BACKING') {
        return '回款中';
      } else if (value === 'SETTLED') {
        return '已结清';
      } else if (value === 'OVERDUED') {
        return '已逾期';
      }
    },
    hangUpStatus(row) {
      let value = row.hangUp;
      if (value === 'service-loess') {
        return '工薪贷后台';
      } else if (value === 'service-midgard') {
        return '南宁app';
      }
    },

    loanChannelStatus: function (row, column) {
      var status = row['channelSign'];
      return this.$enumUtils.toMsg('loanChannel', status);
    },

    mergeDate(param1, param2) {
      if (param1 == "") {
        return ""
      }
      var array = new Array();
      array[0] = new Date(param1)
      array[1] = new Date(param2)
      return array;
    },
    getDate(param, num) {
      if (param && param[num] !== '') {
        return moment(param[num]).format("YYYY-MM-DD")
      }
      return ""
    },

  }

}
</script>

<style>

/* 用来设置当前页面element全局table 选中某行时的背景色*/
.system-list .el-table__body tr.current-row > td {
  background-color: #e0f144 !important;
  /* color: #f19944; */ /* 设置文字颜色,可以选择不设置 */
}

/* 用来设置当前页面element全局table 鼠标移入某行时的背景色*/
.system-list .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: #d7f144;
  /* color: #f19944; */ /* 设置文字颜色,可以选择不设置 */
}

.container {
  width: 120px;
  height: 50;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.container.fold {
  -webkit-line-clamp: 3;
}

.container.unfold {
  -webkit-line-clamp: 100;
}

</style>