<template>
  <div class="content">
    <div class="search">
      <div class="time-box">
        生成时间范围:
        <div class="time-picker-block" @click="calendarShow = true">
          {{ startDate == "" ? "请选择" : startDate }}
        </div>
        <div>&nbsp;-&nbsp;</div>
        <div class="time-picker-block" @click="calendarShow2 = true">
          {{ endDate == "" ? "请选择" : endDate }}
        </div>
      </div>
      <mobile-input
        :reset="resetvalue"
        input-align="left"
        name="CUSTOMERNAME"
        v-model="searchContent"
        :value="searchContent"
        placeholder="请输入关键字"
        size="small"
      />
      <div
        style="
          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; margin-left: 20px"
          size="small"
          >搜索</van-button
        >
      </div>
      <van-popup
        v-model="calendarShow"
        position="bottom"
        :style="{ height: '50%' }"
      >
        <van-datetime-picker
          v-model="currentDate"
          type="date"
          title="选择年月日"
          :min-date="minDate"
          :max-date="maxDate"
          @confirm="onConfirmTime"
          @cancel="calendarShow = false"
        />
      </van-popup>
      <van-popup
        v-model="calendarShow2"
        position="bottom"
        :style="{ height: '50%' }"
      >
        <van-datetime-picker
          v-model="currentDate2"
          type="date"
          title="选择年月日"
          :min-date="minDate"
          :max-date="maxDate"
          @confirm="onConfirmTime2"
          @cancel="calendarShow2 = false"
        />
      </van-popup>
      <van-popup
        class="screenPopup"
        v-model="show"
        position="top"
        :style="{ height: '30%' }"
      >
        <div class="searchStyle">
          <mobile-input
            label="客户名称"
            label-width="10px"
            :reset="resetvalue"
            input-align="left"
            name="CUSTOMERNAME"
            v-model="searchContent"
            :value="searchContent"
            placeholder="请输入关键字"
            size="small"
          />
          <d-select
            label="审批状态"
            border="true"
            v-model="selectApproveStatus"
            :value="selectApproveStatus"
            sfield="approve_status"
            size="small"
          ></d-select>
          <d-select
            v-if="query_type == '1'"
            label="检查状态"
            border="true"
            v-model="selectCheckStatus"
            :value="selectCheckStatus"
            sfield="up_check_status"
            size="small"
          ></d-select>
          <d-select
          v-if="query_type == '2'"
            label="检查状态"
            border="true"
            v-model="selectCheckStatus"
            :value="selectCheckStatus"
            sfield="check_status"
            size="small"
          ></d-select>
          <d-select
            label="主管机构"
            border="true"
            v-model="selectOrgName"
            :value="selectOrgName"
            :options="orgList"
            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>
              <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-gongsimingcheng"></use>
              </svg>
            </div>
            <div>{{ item.cus_name }}</div>
          </div>
          <div class="customer-bottom-list-bottom">
            <span class="point-box" style="color: orange"
              ><div style="background: orange" class="point-rew"></div>
              &nbsp;{{ item.approve_status_cnName }}</span
            >
            <span class="point-box" style="color: orange; margin-left: 20px"
              ><div style="background: orange" class="point-rew"></div>
              &nbsp;{{ item.chk_state_cnName }}</span
            >
            <span
              class="dead-line-content"
              v-if="item.crt_date && item.crt_date != ''"
              >系统生成日期：{{ item.crt_date }}</span
            >
            <span class="manager-box"
              >{{ item.input_id_displayname }} | {{ item.input_br_name }}</span
            >
          </div>
        </div>
      </scroller-view>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Empty, 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";
import { log } from "mathjs";

Vue.use(Popup);
Vue.use(Search);
/**
 * @Description 对公贷后检查
 * @Author wanghang
 * @Date 2022-01-27 下午 04:06
 */
@Component({
  name: "UpcomingPeriodicInspection",
})
export default class UpcomingPeriodicInspection extends Vue {
  resetvalue = false;
  CUSTOMERNAME = "";
  orgList = []; //催收机构列表
  itemDataList = [];
  pageNo = 1;
  pullup = true;
  pulldown = true;
  nodata = true;
  show = false;
  showOrgPicker = false;
  minDate = new Date(2000, 1, 1);
  maxDate = new Date(2050, 12, 1);
  currentDate = new Date();
  currentDate2 = new Date();
  calendarShow: boolean = false; //日历1展开
  calendarShow2: boolean = false; //日历2展开
  startDate = ""; //开始时间
  endDate = ""; //结束时间
  searchContent = ""; //搜索内容
  selectTaskStatus = ""; //选中的任务状态
  selectApproveStatus = ""; //选中的审批状态
  selectCheckStatus = ""; //选中的检查状态
  selectOrgName = ""; //选中的主管机构
  colorList = ["red", "orange", "yellow", "blue"];
  query_type = '';

  activated() {
    this.calendarShow = false;
    this.calendarShow2 = false;
    this.show = false;
    if (sessionStorage.getItem("businessType") == "Upcoming") {
      this.query_type = "1";
    } else if (sessionStorage.getItem("businessType") == "Common") {
      this.query_type = "2";
    }
    this.reset();
  }
  // created() {
  //   this.selectDHJC();
  //   this.selectOrgList();
  // }
  mounted() {
    this.calendarShow = false;
    this.calendarShow2 = false;
    this.show = false;
    if (sessionStorage.getItem("businessType") == "Upcoming") {
      this.query_type = "1";
    } else if (sessionStorage.getItem("businessType") == "Common") {
      this.query_type = "2";
    }
    this.reset();
    this.selectDHJC();
    this.selectOrgList();
  }
  /**
   * @Description 点击列表事件
   * @Author wanghang
   * @Date 2022-01-27 下午 03:12
   */
  collection(item: any) {
    this.$store.commit("setEmpty");
    this.$store.commit("setCtfInstNo", {});
    this.$store.commit("setCtfInstNo", item);
    this.$router.push({
      path: "/LoanCheckDetailView",
    });
  }
  /**
   * @Description 筛选
   * @Author wanghang
   * @Date 2022-01-27 下午 04:16
   */
  screen() {
    this.show = true;
  }
  /**
   * @Description 搜索
   * @Author wanghang
   * @Date 2022-01-27 下午 04:17
   */
  search() {
    if (
      (this.startDate == "" && this.endDate == "") ||
      (this.startDate != "" && this.endDate != "")
    ) {
      this.selectDHJC();
    } else {
      NativeUI.toast("开始时间和结束时间不能只选一个");
    }
    this.show = false;
  }
  /**
   * @Description 重置
   * @Author wanghang
   * @Date 2022-01-27 下午 05:36
   */
  reset() {
    // location.reload();
    this.selectTaskStatus = "";
    this.selectApproveStatus = "";
    this.selectCheckStatus = "";
    this.searchContent = "";
    this.selectOrgName = "";
    this.startDate = "";
    this.endDate = "";
    this.selectDHJC(1);
  }
  /**
   * @Description 上拉加载
   * @Author wanghang
   * @Date 2022-01-26 下午 03:50
   */
  onloaddata() {
    this.pageNo = Math.ceil(this.itemDataList.length / 10) + 1;
    return this.selectDHJC(this.pageNo);
  }
  /**
   * @Description 下拉加载
   * @Author wanghang
   * @Date 2022-01-26 下午 03:50
   */
  onrefreshdata() {
    return this.selectDHJC();
  }
  /**
   * @Description 查询对公贷后检查
   * @Author wanghang
   * @Date 2022-01-26 下午 03:50
   */
  selectDHJC(pageNo = 1) {
    if (
      this.startDate != "" &&
      this.endDate != "" &&
      !this.compareTime(this.startDate, this.endDate)
    ) {
      NativeUI.toast("终止时间不能早于开始时间");
    } else {
      this.nodata = true;
      this.pullup = true;
      this.pulldown = true;
      let param = {
        cus_id: "",
        targetPage: pageNo,
        maxLine: 10,
        query_type: this.query_type, //1.待办查询 2.全量
        cus_name: this.searchContent, //用于模糊查询
        chk_state: this.selectCheckStatus,
        approve_status: this.selectApproveStatus,
        input_br_id: this.selectOrgName,
        crt_date_begin: this.startDate,
        crt_date_end: this.endDate,
        tc: nettyApi.TRADE_CODE.selectCompanylonaList,
      };
      NativeUI.showWaiting('正在查询...');
      return IF.transferDataInter(nettyApi.commonRq, param).then((res: any) => {
        console.log('查询状态',param);
        console.log(res);
        NativeUI.closeWaiting();
        if (res.rc == "1") {
          if (pageNo == 1) {
            this.itemDataList = res.PspCreditCheckTaskList;
          } else {
            this.itemDataList = this.itemDataList.concat(
              res.PspCreditCheckTaskList
            );
          }
        } else {
          NativeUI.toast(res.msg);
        }
        if (res.RewTaskList && res.RewTaskList.length < 10) {
          this.pullup = false;
        }
        if (this.itemDataList.length == 0) {
          this.nodata = false;
          this.pulldown = false;
        }
      });
    }
  }

  /**
   * @Description 查询机构列表
   * @Author wanghang
   * @Date 2022-01-27 下午 03:46
   */
  selectOrgList() {
    const params = {
      tc: nettyApi.TRADE_CODE.selectOrgList,
      QFLGE: "2", //1是登录，2是机构查询
    };
    NativeUI.showWaiting();
    return IF.transferDataInter(nettyApi.commonRq, params).then((res: any) => {
      NativeUI.closeWaiting();
      if (res.rc == 1) {
        // res.CustomerGRArray = res.CustomerGRArray;
        let temp = {};
        for (let i = 0; i < res.SOrgList.length; i++) {
          temp = {};
          (temp as any).text = res.SOrgList[i].organname;
          (temp as any).value = res.SOrgList[i].organno;
          this.orgList.push(temp as never);
        }
      } else {
        NativeUI.toast("查询机构失败");
      }
    });
  }
  onConfirmTime(date: Date) {
    this.calendarShow = false;
    this.startDate = this.formatDate(date);
    if (this.endDate != "") {
      if (!this.compareTime(this.startDate, this.endDate)) {
        console.log("结束时间不能早于开始时间");
        NativeUI.toast("结束时间不能早于开始时间");
        this.startDate = "";
      } else {
        this.selectDHJC();
      }
    }
  }
  onConfirmTime2(date: Date) {
    this.calendarShow2 = false;
    this.endDate = this.formatDate(date);
    if (this.startDate != "") {
      if (!this.compareTime(this.startDate, this.endDate)) {
        console.log("结束时间不能早于开始时间");
        NativeUI.toast("结束时间不能早于开始时间");
        this.endDate = "";
      } else {
        this.selectDHJC();
      }
    } else {
      NativeUI.toast("开始时间未选择");
    }
  }
  //处理时间格式
  formatDate(date: Date) {
    let month = (date.getMonth() + 1).toString();
    if (month.length == 1) {
      month = "0" + month;
    }
    let day = date.getDate().toString();
    // if (day.length == 1) {
    //   day = "0" + day;
    // }
    return date.getFullYear() + "-" + month + "-" + day;
  }
  //比较时间早晚
  compareTime(time1: any, time2: any) {
    let strs1 = time1.split("-");
    let strs2 = time2.split("-");
    let start = "";
    let end = "";
    for (let i = 0; i < strs1.length; i++) {
      start += strs1[i];
      end += strs2[i];
    }
    return parseFloat(start) <= parseFloat(end);
  }
  getOrgId() {
    var res = "";
    for (let i = 0; i < this.orgList.length; i++) {
      if ((this.orgList[i] as any).text === this.selectOrgName) {
        res = (this.orgList[i] as any).value;
      }
    }
    return res;
  }
}
</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: flex-start;
}
::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) 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: 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 {
  /* width: 60%; */
  height: 26px;
  display: flex;
  margin-top: 10px;
  padding-left: 70px;
  justify-content: flex-start;
  align-items: center;
}
.Managementdata {
  padding: 10px 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;
}
.searchStyle {
  display: grid;
  align-items: center;
  grid-template-columns: 1fr 1fr;
}
.searchStyle div {
  width: 90%;
}
.time-box {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 30px;
  height: auto;
  /* width: 200px; */
}
.time-picker-block {
  /* height: 50px; */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 110px;
  height: 30px;
  border-radius: 5px;
  background-color: #eee;
}
.point-box {
  width: 70px;
  display: flex;
  align-items: center;
}
.point-rew {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.manager-box {
  color: #9e9e9e;
  margin-left: 20px;
}
.dead-line-content {
  margin-left: 30px;
  color: #949596;
}
</style>
s
