<template>
  <div>
    <title-bar :title="title" @clickLeft="onClick">
      <van-icon slot="left" name="cross" size="24" />
    </title-bar>
    <div class="text-content">
      <div class="addSearch">
        <mobile-input
          label-width="10px"
          :reset="resetvalue"
          input-align="left"
          name="value"
          v-model="value"
          placeholder="请输入关键字"
          size="small"
        />
        <div
          style="
            width: 200px;
            display: flex;
            justify-content: space-evenly;
            align-items: self-start;
          "
        >
          <van-button
            color="#FF574C"
            type="primary"
            @click="reset"
            plain
            style="width: 70px; height: 34px"
            size="small"
          >重置
          </van-button
          >
          <van-button
            color="#FF574C"
            type="primary"
            @click="onSearch"
            style="width: 70px; height: 34px"
            size="small"
          >查询
          </van-button
          >
        </div>
      </div>
      <div class="afterLoanData">
        <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"
          >
            <div>
              <div class="customer-bottom-list-top">
                <div>
                  <span style="color: #ff574c">{{ index + 1 }}</span>
                </div>
                <div>{{ item.CUSTOMERNAME }}</div>
                <div>{{ item.BUSINESSTYPENAME }}</div>
              </div>
              <div class="customer-bottom-list-bottom">
                <span>发放日期：{{ item.PUTOUTDATE }}</span>
                <span>到期日期：{{ item.MATURITYDATE }}</span>
              </div>
            </div>
            <div>
              <van-button
                @click="addCheckItem(item)"
                round
                color="#FF574C"
                type="primary"
                plain
                style="width: 70px; height: 34px"
                size="small"
              >添加
              </van-button
              >
            </div>
          </div>
        </scroller-view>
      </div>
    </div>
  </div>
</template>

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

Vue.use(Sidebar);
Vue.use(SidebarItem);
/**
 * @Description 待办任务
 * @Author JiangTao
 * @Date 2021-10-25 下午 08:55
 */
@Component({
  name: "AddContactCheckView",
  components: { TitleBar }
})
export default class AddContactCheckView extends Vue {
  INSPECTTYPE: any = "";
  title = "新增"; // 页面标题
  resetvalue = false;
  value = "";
  itemDataList = [];
  pageNo = 1;
  pullup = true;
  pulldown = true;
  nodata = true;
  ADDFLAG = "1"; //新增页面默认为新增，不用用户选择
  currentObjNo = ""; //要新增的对象的编号
  cusType = this.$route.query.cusType; //个贷客户还是网贷客户

  onClick() {
    console.log(111111);
  }

  mounted() {
    console.log(this.$route.query.cusType);
    if ((this.$route.query.type as any).text != undefined) {
      if (this.cusType == "1") {
        this.title = "个贷" + (this.$route.query.type as any).text + "新增";
      } else if (this.cusType == "2") {
        this.title = "网贷" + (this.$route.query.type as any).text + "新增";
      }
    }
    this.INSPECTTYPE = (this.$route.query.type as any).value;
    if (this.cusType == "1") {
      this.selectObjectList();
    } else if (this.cusType == "2") {
      this.selectNetObjectList();
    }
  }

  /**
   * @Description 添加数据
   * @Author JiangTao
   * @Date 2022-01-28 下午 02:58
   */
  addCheckItem(item: any) {
    NativeUI.confirm("", "确认添加?").then(() => {
      this.currentObjNo = item.OBJECTNO;
      if (this.cusType == "1") {
        this.addLoanCheckItem();
        this.selectObjectList(1);
      } else if (this.cusType == "2") {
        this.addNetLoanCheckItem();
        this.selectNetObjectList(1);
      }
    });
  }

  /**
   * @Description 重置
   * @Author JiangTao
   * @Date 2022-01-28 下午 03:04
   */
  reset() {
    this.resetvalue = true;
    this.value = "";
    this.selectObjectList();
  }

  /**
   * @Description 搜索
   * @Author JiangTao
   * @Date 2022-01-28 下午 03:06
   */
  selectObjectList(pageNo: any = 1) {
    this.nodata = true;
    this.pullup = true;
    this.pulldown = true;
    let param = {
      ROWNUMSTART: (pageNo - 1) * 10,
      ROWNUMEND: pageNo * 10,
      CUSTOMERNAME: this.value,
      INSPECTTYPE: this.INSPECTTYPE, //检查类型
      tc: nettyApi.TRADE_CODE.selectAfterLoanCheck
    };
    NativeUI.showWaiting("正在查询...");
    return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
      console.log(res);
      NativeUI.closeWaiting();
      if (res.rc == "1") {
        if (pageNo == 1) {
          this.itemDataList = res.AFTER_LOAN_CHECK_ADD_LIST;
        } else {
          this.itemDataList = this.itemDataList.concat(
            res.AFTER_LOAN_CHECK_ADD_LIST
          );
        }
      } else {
        NativeUI.toast(res.msg);
      }
      if (
        res.AFTER_LOAN_CHECK_ADD_LIST &&
        res.AFTER_LOAN_CHECK_ADD_LIST.length < 10
      ) {
        this.pullup = false;
      }
      if (this.itemDataList.length == 0) {
        this.nodata = false;
        this.pulldown = false;
      }
    });
  }

  /**
   *@description: //网贷借据/合作项目信息查询
   *@author: wanghang
   *@date: 2022-02-21
   */
  selectNetObjectList(pageNo: any = 1) {
    this.nodata = true;
    this.pullup = true;
    this.pulldown = true;
    let param = {
      ROWNUMSTART: (pageNo - 1) * 10,
      ROWNUMEND: pageNo * 10,
      CUSTOMERNAME: this.value,
      INSPECTTYPE: this.INSPECTTYPE, //检查类型
      tc: nettyApi.TRADE_CODE.selectNetLoanCheckSerial
    };
    NativeUI.showWaiting("正在查询...");
    return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
      console.log(res);
      NativeUI.closeWaiting();
      if (res.rc == "1") {
        if (pageNo == 1) {
          this.itemDataList = res.AFTER_LOAN_CHECK_ADD_LIST;
        } else {
          this.itemDataList = this.itemDataList.concat(
            res.AFTER_LOAN_CHECK_ADD_LIST
          );
        }
      } else {
        NativeUI.toast(res.msg);
      }
      if (
        res.AFTER_LOAN_CHECK_ADD_LIST &&
        res.AFTER_LOAN_CHECK_ADD_LIST.length < 10
      ) {
        this.pullup = false;
      }
      if (this.itemDataList.length == 0) {
        this.nodata = false;
        this.pulldown = false;
      }
    });
  }

  /**
   * @Description 新增个贷贷后检查任务
   * @Author JiangTao
   * @Date 2022-01-28 下午 03:52
   */
  addLoanCheckItem() {
    let param = {
      OBJECTNO: this.currentObjNo,
      ADDFLAG: this.ADDFLAG, //是否新增，默认为新增
      INSPECTTYPE: this.INSPECTTYPE, //检查类型
      tc: nettyApi.TRADE_CODE.addLoanCheckInfo
    };
    NativeUI.showWaiting("正在查询...");
    return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
      NativeUI.closeWaiting();
      if (res.rc == "1") {
        NativeUI.toast("新增成功！");
        this.selectObjectList();
      } else {
        NativeUI.toast(res.msg);
      }
    });
  }

  /**
   *@description: 新增网贷贷后检查任务
   *@author: wanghang
   *@date: 2022-02-21
   */
  addNetLoanCheckItem() {
    let param = {
      OBJECTNO: this.currentObjNo,
      ADDFLAG: this.ADDFLAG, //是否新增，默认为新增
      INSPECTTYPE: this.INSPECTTYPE, //检查类型
      tc: nettyApi.TRADE_CODE.addNetLoanCheckInfo
    };
    NativeUI.showWaiting("正在查询...");
    return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
      NativeUI.closeWaiting();
      if (res.rc == "1") {
        NativeUI.toast("新增成功！");
        this.selectNetObjectList();
      } else {
        NativeUI.toast(res.msg);
      }
    });
  }

  /**
   * @Description 上拉加载
   * @Author JiangTao
   * @Date 2022-01-18 下午 04:04
   */
  onloaddata() {
    if (this.cusType == "1") {
      this.pageNo = Math.ceil(this.itemDataList.length / 10) + 1;
      return this.selectObjectList(this.pageNo);
    } else if(this.cusType == "2"){
      this.pageNo = Math.ceil(this.itemDataList.length / 10) + 1;
      return this.selectNetObjectList(this.pageNo);
    }
  }

  /**
   * @Description 下拉刷新
   * @Author JiangTao
   * @Date 2022-01-17 下午 05:14
   */
  onrefreshdata() {
    if (this.cusType == "1") {
      return this.selectObjectList();
    } else if (this.cusType == "2"){
      return this.selectNetObjectList();
    }
  }
  /**
   *@description: 调整查询
   *@author: wanghang
   *@date: 2022-02-25
   */
  onSearch(){
    if (this.cusType == "1") {
      return this.selectObjectList();
    } else if (this.cusType == "2"){
      return this.selectNetObjectList();
    }
  }
}
</script>

<style scoped>
.text-content {
  height: calc(100vh - 60px);
}

.addSearch {
  height: 10%;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.afterLoanData {
  height: 89%;
}

::v-deep .scroller {
  padding-top: 10px;
  padding-left: 30px;
  padding-right: 30px;
}

::v-deep .d-form-field {
  width: 70%;
  padding-top: 1.5rem;
}

.customer-bottom-list {
  border-radius: 10px;
  box-shadow: 0 0 6px #d7d7d7;
  margin: 0 10px 16px 10px;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.customer-bottom-list > div:nth-child(1) {
  width: 80%;
}

.customer-bottom-list > div:nth-child(2) {
  width: 20%;
  display: flex;
  justify-content: center;
}

.customer-bottom-list-top > div:nth-child(1) svg {
  width: 40px;
  height: 40px;
}

.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: auto;
  padding: 3px 7px;
  font-size: 12px;
  margin-left: 1%;
  color: #ff6e0d;
  background-color: rgba(255, 247, 204, 1);
  border-radius: 2px;
}

.customer-bottom-list-bottom {
  width: 60%;
  height: 26px;
  display: flex;
  margin: 10px 0;
  padding-left: 50px;
  justify-content: flex-start;
  align-items: center;
}

.customer-bottom-list-bottom span {
  margin-right: 30px;
}

.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: 16px;
  font-weight: bold;
  width: auto;
  margin: 0 10px;
}

.customer-bottom-list-top > div:nth-child(3) {
  color: #f59a23;
}

.customer-bottom-list-top {
  width: 90%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding-top: 1.5%;
  margin-left: 1.5%;
}
</style>
