<template>
  <div class="page-byh-service">
    <block-header title="搜索"/>
    <div class="page-search">
      <el-form size="small" label-suffix=":" :inline="true" ref="refForm" :model="searchInfo" class="demo-form-inline">
        <el-form-item prop="clientCell" label="手机号码">
          <el-input
              clearable
              v-model.trim="searchInfo.clientCell"
              @keyup.enter.native="onSubmit"
              placeholder="请输入手机号码"></el-input>
        </el-form-item>

        <el-form-item prop="clientNo" label="客户编号">
          <el-input
              clearable
              v-model="searchInfo.clientNo"
              @keyup.enter.native="onSubmit"
              placeholder="请输入客户编号"></el-input>
        </el-form-item>

        <el-form-item prop="certNo" label="身份证号">
          <el-input
              clearable
              v-model="searchInfo.certNo"
              @keyup.enter.native="onSubmit"
              placeholder="请输入身份证号"></el-input>
        </el-form-item>

        <el-form-item prop="productName" label="产品名称">
          <product-select
              v-model="searchInfo.productName"
              @handleSetting="(e)=>{ searchInfo.productName = e}"/>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button @click="onReset('refForm')">清空</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 列表 -->
    <div v-show="isShow">
      <block-header title="客户列表"/>
      <mc-table :data="list"></mc-table>

      <el-table
          border
          size="small"
          :data="loanApplyList" stripe style="width: 100%;">
        <el-table-column align="center" width="180" prop="clientNo" label="客户编号"></el-table-column>
        <el-table-column align="center" prop="clientName" label="姓名"></el-table-column>
        <el-table-column align="center" prop="clientCell" label="手机号"></el-table-column>
        <el-table-column align="center" width="160" prop="certNo" label="身份证号"></el-table-column>
        <el-table-column align="center" prop="level" label="授信级别"></el-table-column>
        <el-table-column align="center" prop="productNameStr" label="产品名称"></el-table-column>
        <el-table-column align="center" prop="userStatus" label="用户状态" :formatter="userStatusFormat"></el-table-column>
        <el-table-column align="center" prop="latestLoanStatus" label="最近一笔借款状态"></el-table-column>
        <el-table-column align="center" prop="latestLoanGmtCreated" label="最近一笔借款时间"></el-table-column>
        <el-table-column align="center" label="查看详情">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="loanDetail(scope.row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <br/>

    </div>
    <!-- 详情组件 -->


  </div>
</template>

<script>
import BlockHeader from "@/components/byh/componments/blockHeader";
import * as moment from "moment";

export default {
  name: "ByhService",
  components: {
    BlockHeader
  },
  data() {
    return {
      flag: false,
      isShow: false,
      isCancell: false,
      activeNames: ['1'],
      page: {
        current: 1,
        size: 10,
        total: 0
      },
      loanApplyList: [{
        clientNo: '',
        clientName: '',
        clientCell: '',
        certNo: '',
        loanNo: '',
      }],
      searchInfo: {
        clientCell: '',
        clientNo: '',
        loanNo: '',
        certNo: '',
        productName: '',
      },

    }
  },
  filters: {

    dateFilter: function (row) {
      var date = row
      if (typeof (date) == undefined || typeof (date) == null) {
        return ''
      }
      return moment(date).format("YYYY-MM-DD")
    },

  },
  created() {
    if (this.$route.query.clientCell != null) {
      this.searchInfo.clientCell = this.$route.query.clientCell
      this.page.current = this.$route.query.current;
      this.backedData()
    }
  },

  methods: {
    readDetail(record) {
      this.ui.readDetail = {
        visible: true,
        phone: record.phone,
        backedXi: record.backedXi,
      };
    },
    toggle: function () {
      this.isShow = !this.isShow;
    },
    handleSizeChange(row) {
      this.page.size = row
      this.page.current = 1;
      this.backedData();
    },

    /** 加载数据 */
    backedData() {
      if (this.searchInfo.clientCell == '' && this.searchInfo.clientNo == '' && this.searchInfo.certNo == '') {
        this.$message({message: '手机号或客户编号或身份证号不能为空', type: 'error'});
        return;
      }
      this.loanList()

    },
    // 列表数据

    loanList() {

      //console.log("角色" + this.$permissionUtils.rolePermission('admin'));
      /** 加载数据 */
      this.$$post('/customer/selectClientInfo', this.buildParam()).then(res => {
        if (res.data.code != 200) {
          this.isShow = false;
          this.$message.error(res.data.message);
          return
        }
        this.isShow = true;
        this.loanApplyList = res.data.result;

      }).catch(error => {
        this.$Message.error(error || '系统异常');
      });

    },

    //用户注销
    cancellation(record) {

      this.$confirm('注销后此账户将被限制登录', '确定注销？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

        this.$$post('/customer/cancellation', {clientNo: record.clientNo, clientCell: record.clientCell}).then(res => {
          if (res.data.code != 200) {
            this.isShow = false;
            this.$message.error(res.data.message);
            return
          }
          this.$message({
            type: 'success',
            message: '注销成功!'
          });
          this.backedData();

        }).catch(error => {
          this.$Message.error(error || '系统异常');
        });

        /*this.$message({
          type: 'success',
          message: '注销成功!'
        });*/

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消注销'
        });
      });


    },

    loanDetail(record) {
      this.$router.push({
        path: 'ByhServiceDetail',
        query: {
          clientNo: record.clientNo,
          clientName: record.clientName,
          clientProductName: record.productName,
          phoneNo: record.clientCell,
          clientCell: this.searchInfo.clientCell,
          certNo: this.searchInfo.certNo,
          productName: this.searchInfo.productName,
          loanNo: record.loanNo,
          orderNo: record.orderNo,
          current: this.page.current,
        }
      })

    },
    /*搜索条件*/
    onSubmit() {
      this.backedData();
    },

    /** 处理分页操作*/
    handleCurrentChange() {
      this.loanApplyList = this.backedData()
    },

    dateFormatText: function (param) {
      return moment(param).format("YYYY-MM-DD");
    },

    getDate(param, num) {
      if (param && param[num] !== '') {
        return moment(param[num]).format("YYYY-MM-DD")
      }
      return ""
    },

    mergeDate(param1, param2) {
      if (param1 == "") {
        return ""
      }
      var array = new Array();
      array[0] = new Date(param1)
      array[1] = new Date(param2)
      return array;
    },



    //产品名称
    productNameFormat: function (row, column) {
      var status = row['productName'];
      return this.$enumUtils.toMsg('BusinessType', status);
    },

    //用户状态
    userStatusFormat: function (row, column) {
      var status = row['userStatus'];
      return this.$enumUtils.toMsg('UserStatusType', status);
    },

    //借款单状态
    loanStatusFormat: function (row, column) {
      var status = row['status'];
      return this.$enumUtils.toMsg('LoanStatusEnum', status);
    },

    //参数
    buildParam() {
      var return_hash = {
        size: this.page.size,
        current: this.page.current,
      };
      if (this.searchInfo.certNo != '') {
        return_hash['certNo'] = this.searchInfo.certNo
      }
      if (this.searchInfo.clientCell != '') {
        return_hash['clientCell'] = this.searchInfo.clientCell
      }
      if (this.searchInfo.clientName != '') {
        return_hash['clientName'] = this.searchInfo.clientName
      }
      if (this.searchInfo.clientNo != '') {
        return_hash['clientNo'] = this.searchInfo.clientNo
      }
      if (this.searchInfo.loanNo != '') {
        return_hash['loanNo'] = this.searchInfo.loanNo
      }
      if (this.searchInfo.productName != '') {
        return_hash['productName'] = this.searchInfo.productName
      }
      return return_hash;
    },


  }
}


</script>

<style scoped>

</style>
