<template>
  <div class="content">
    <div class="search">
      <mobile-input label-width="10px" :reset="resetvalue" input-align="left" name="CUSTOMERNAME" v-model="CUSTOMERNAME" placeholder="请输入关键字" size="small" />
      <div style="width: 200px; display: flex;justify-content: space-evenly;align-items: self-start">
        <van-button color="#FF574C" type="primary" @click="screen" plain style="width: 70px;height: 34px" size="small">筛选</van-button>
        <van-button color="#FF574C" type="primary" @click="search" style="width: 70px;height: 34px" size="small">查询</van-button>
      </div>
      <van-popup class="screenPopup" v-model="show" position="top" :style="{ height: '40%' }" >
        <div class="searchStyle">
          <mobile-input label="客户名称" label-width="10px" :reset="resetvalue" input-align="left" name="CUSTOMERNAME" v-model="CUSTOMERNAME" placeholder="请输入关键字" size="small" />
          <d-select placeholder="请选择" v-if="orgList.length != 0" :value="OPERATEORGID" label="催收机构" border="true" v-model="OPERATEORGID" :columns="orgList" size="small"></d-select>
          <d-select placeholder="请选择" label="催收方式" :value="COLLECTIONMETHOD" border="true" v-model="COLLECTIONMETHOD" sfield="CONTACTMETHOD" size="small"></d-select>
          <d-select placeholder="请选择" label="催收等级" :value="COLLECTIONLEVEL" border="true" v-model="COLLECTIONLEVEL" sfield="COLLECTIONLEVEL" size="small"></d-select>
        </div>
        <div class="screenbutton">
          <van-button color="#FF574C" type="primary" @click="search" style="width: 100px;height: 50px;display: block" size="small">查询</van-button>
          <van-button color="#FF574C" type="primary" @click="reset" plain style="width: 100px;height: 50px;display: block" size="small">重置</van-button>
        </div>
      </van-popup>
    </div>
    <div class="Managementdata">
      <scroller-view v-if="nodata" v-calculate-height :pulldown="pulldown" :pullup="pullup" :refresh-data="onrefreshdata" :load-data="onloaddata">
        <div v-for="(item, index) in itemDataList" :key="index" class="customer-bottom-list" @click="collection(item)">
          <div class="customer-bottom-list-top">
            <div>
              <span style="color: #FF574C">{{ index + 1}}</span>
            </div>
            <div>{{ item.CUSTOMERNAME }}</div>
          </div>
          <div class="customer-bottom-list-bottom">
            <span style="margin-left:20px;width:215px;" v-if="item.OPERATEDATE && item.OPERATEDATE != ''">最新催收执行日期：{{ item.OPERATEDATE }}</span>
            <span style="margin-left:20px;font-size:14px;">借据编号：{{ item.OBJECTNO }}</span>
          </div>
        </div>
      </scroller-view>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Search } from 'vant';
import nettyApi from "@/constants/api/ms-netty/netty.api.ts";
import IF from "@/public/factory/InterFaceFactory";
import { NativeUI } from "@/public/ts/NativeUI";
import { Popup } from 'vant';

Vue.use(Popup);

Vue.use(Search);
/**
 * @Description 贷款催收
 * @Author JiangTao
 * @Date 2022-01-18 下午 04:06
 */
@Component({
  name: "CollectionManagement",
})
export default class CollectionManagement extends Vue {
  resetvalue = false;
  CUSTOMERNAME = "";
  COLLECTIONMETHOD = ""; //催收方式
  OPERATEORGID = ""; //催收机构
  COLLECTIONLEVEL = ""; //催收等级
  orgList = [] //催收机构列表
  itemDataList = [];
  pageNo = 1;
  pullup = true;
  pulldown = true;
  nodata = true;
  show = false;
  CSFLAG = "";

  mounted() {
    //弹窗跳转时要隐藏
    this.show = false;

    if (sessionStorage.getItem("businessType") == "Upcoming") {
      this.CSFLAG = "1";
    } else if (sessionStorage.getItem("businessType") == "Common") {
      this.CSFLAG = "2";
    }
    this.selectContactList();
    this.selectOrgList();
  }
  activated() {
    //弹窗跳转时要隐藏
    this.show = false;

    if (sessionStorage.getItem("businessType") == "Upcoming") {
      this.CSFLAG = "1";
    } else if (sessionStorage.getItem("businessType") == "Common") {
      this.CSFLAG = "2";
    }
    this.selectContactList();
    this.selectOrgList();
  }
  /**
   * @Description 点击列表事件
   * @Author JiangTao
   * @Date 2022-01-18 下午 07:15
   */
  collection(item: any) {
    this.$store.commit("setEmpty");
    this.$store.commit("setCusInfo", item);
    this.$router.push({
      path: "/CollectionDetails",
    });
  }
  /**
   * @Description 筛选
   * @Author JiangTao
   * @Date 2022-01-18 下午 04:16
   */
  screen() {
    this.show = true;
  }
  /**
   * @Description 搜索
   * @Author JiangTao
   * @Date 2022-01-18 下午 04:17
   */
  search() {
    this.selectContactList(1);
    this.show = false;
  }
  /**
   * @Description 重置
   * @Author JiangTao
   * @Date 2022-01-18 下午 05:36
   */
  reset() {
    this.resetvalue = true;
    this.CUSTOMERNAME = "";
    this.OPERATEORGID = "";
    this.COLLECTIONMETHOD = "";
    this.COLLECTIONLEVEL = "";
    this.selectContactList();
  }
  /**
   * @Description 上拉加载
   * @Author JiangTao
   * @Date 2022-01-18 下午 04:04
   */
  onloaddata() {
    this.pageNo = Math.ceil(this.itemDataList.length / 10) + 1;
    return this.selectContactList(this.pageNo);
  }
  /**
   * @Description 下拉刷新
   * @Author JiangTao
   * @Date 2022-01-17 下午 05:14
   */
  onrefreshdata() {
    return this.selectContactList();
  }
  /**
   * @Description 查询催收列表
   * @Author JiangTao
   * @Date 2022-01-18 下午 03:46
   */
  selectContactList(pageNo = 1) {
    this.nodata = true;
    this.pullup = true;
    this.pulldown = true;
    let param = {
      ROWNUMSTART: (pageNo - 1) * 10,
      ROWNUMEND: pageNo * 10,
      CUSTOMERNAME: this.CUSTOMERNAME,
      COLLECTIONMETHOD: this.COLLECTIONMETHOD,
      OPERATEORGID: this.OPERATEORGID,
      COLLECTIONLEVEL: this.COLLECTIONLEVEL,
      CSFLAG: this.CSFLAG, //1 待处理 2 任务查询
      tc: nettyApi.TRADE_CODE.selectPersonalDebtList
    };
    NativeUI.showWaiting('正在查询...');
    return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
      console.log('状态',this.CSFLAG);
      NativeUI.closeWaiting();
      if (res.rc == '1') {
        if (pageNo == 1) {
          this.itemDataList = res.COLL_TASK_ARRAY;
        } else {
          this.itemDataList = this.itemDataList.concat(res.COLL_TASK_ARRAY);
        }
      } else {
        NativeUI.toast(res.msg);
      }
      if (res.COLL_TASK_ARRAY && res.COLL_TASK_ARRAY.length < 10) {
        this.pullup = false;
      }
      if (this.itemDataList.length == 0) {
        this.nodata = false;
        this.pulldown = false;
      }
    });
  }

  /**
   * @Description 查询机构列表
   * @Author JiangTao
   * @Date 2022-01-18 下午 03:46
   */
  selectOrgList() {
    const params = {
      tc: nettyApi.TRADE_CODE.selectGDOrgList,
      QFLGE: '2' //1是登录，2是机构查询
    };
    NativeUI.showWaiting();
    IF.transferDataInter(nettyApi.commonRq, params).then((res: any) => {
      console.log(res);
      NativeUI.closeWaiting();
      if (res.rc == 1) {
        res.CustomerGRArray = res.CustomerGRArray;
        let temp = {};
        for (let i = 0; i < res.CustomerGRArray.length; i++) {
          temp = {};
          (temp as any).text = res.CustomerGRArray[i].ORGNAME;
          (temp as any).value = res.CustomerGRArray[i].ORGCODE;
          this.orgList.push((temp as never));
        }
      } else {
        NativeUI.toast('查询用户失败，请重试');
      }
    });
  }
}
</script>

<style scoped>
::v-deep .van-cell__title,
::v-deep .van-field__label {
  display: flex;
  align-items: center;
}
.content {
  width: 100%;
}
.search {
  width: 100%;
  height: 70px;
  border: 1px solid #e1e2e3;
  display: flex;
  align-items: center;
  justify-content: center;
}
::v-deep .d-form-field {
  padding-bottom: 0;
  width: 70%;
  height: 50px;
}
::v-deep .van-field__control {
  height: 30px;
}
.customer-bottom-list {
  border-radius: 10px;
  background-color: #f8fdff;
  box-shadow: 0 0 6px #d7d7d7;
  margin: 0 10px 16px 10px;
  padding-bottom: 10px;
  position: relative;
}
.customer-bottom-list-top > div:nth-child(1) {
  width: 30px;
  height: 30px;
  border: 1px solid #FF574C;
  border-radius: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.customer-bottom-list-top > div:nth-child(2) {
  font-size: 115%;
  font-weight: bold;
  font-family: "微软雅黑 Bold", "微软雅黑 Regular", "微软雅黑";
  margin-left: 0.8%;
}
.customer-bottom-list-top {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding-top: 1.5%;
  margin-left: 1.5%;
}
.customer-bottom-list-top > div:nth-child(3) {
  width: 28%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  justify-content: space-around;
  grid-column-gap: 4px;
  align-items: center;
  margin-left: 1%;
}
.customer-bottom-list-top > div:nth-child(3) div {
  color: #ff6e0d;
  background-color: rgba(255, 247, 204, 1);
  font-size: 80%;
  padding-top: 2%;
  padding-bottom: 1.5%;
  border-radius: 2px;
  text-align: center;
  width: 100%;
}
.customer-bottom-list-bottom {
  height: 26px;
  display: flex;
  margin-top: 10px;
  padding-left: 32px;
  justify-content: flex-start;
  align-items: center;
}
.Managementdata {
  padding: 0 20px;
}
::v-deep .screenPopup {
  width: 75%;
  margin-left: 25%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 5% 5px 5%;
  z-index: 99 !important;
}
.screenPopup > div:nth-child(1) {
  width: 85%;
  height: 100%;
}
::v-deep .van-overlay {
  z-index: 90 !important;
}
.screenbutton {
  width: 15%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-content: center;
  justify-content: center;
}
::v-deep .screenbutton button {
  margin: 20px auto;
}
::v-deep .screenbutton .van-button__content {
  font-size: 18px;
}
::v-deep .van-picker {
  width: 75%;
  margin-left: 25%;
  border-top-left-radius: 15px;
}
::v-deep .van-popup--round {
  background-color: rgba(0, 0, 0, 0);
}
.searchStyle {
  display: grid;
  align-items: center;
  grid-template-columns: 1fr 1fr;
}
.searchStyle div {
  width: 90%;
}
::v-deep .scroller {
  margin-top: 10px;
}
</style>
