<template>
  <div class="content">
    <div class="search">
      <mobile-input label-width="10px" :reset="resetvalue" input-align="left" name="cusName" v-model="cusName" 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;display: block" size="small">重置</van-button>
        <van-button color="#FF574C" type="primary" @click="search" style="width: 70px;height: 34px;display: block" size="small">查询</van-button>
      </div>
    </div>
    <div class="Managementdata d-flex flex-column">
<!--      <base-list :data="itemDataList" finishedText="没有更多了" errorText="请求失败，点击重新加载" pageLines="10" @onLoad="onloaddata" @refresh="onrefreshdata">-->
<!--        <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.cusName }}</div>-->
<!--            <div>-->
<!--              <div class="labelDataStyle" v-if="item.cusType && item.cusType.length > 0" v-for="(itemcusType, index) in item.cusType" :key="index + 'a'">{{ itemcusType }}</div>-->
<!--            </div>-->
<!--          </div>-->
<!--          <div class="customer-bottom-list-bottom">-->
<!--            <div><div>最晚到期借据产品名称：</div><div>{{ item.zwdqJjCpmc }}</div></div>-->
<!--            <div><div>最晚到期借据金额(元)：</div><div>{{ item.zwdqJjJe }}</div></div>-->
<!--            <div><div>最晚到期借据到期日期：</div><div>{{ item.zwdqJjDqrq }}</div></div>-->
<!--          </div>-->
<!--        </div>-->
<!--      </base-list>-->
      <scroller-view 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>
              <div>
                <span style="color: #FF574C">{{ index + 1}}</span>
              </div>
            </div>
            <div>{{ item.cusName }}</div>
            <div class="labelStyle">
              <div v-if="item.cusType && item.cusType.length > 0" v-for="(itemcusType, index) in item.cusType" :key="index + 'a'">{{ itemcusType }}</div>
            </div>
          </div>
          <div class="customer-bottom-list-bottom">
            <div><div>最晚到期借据产品名称：</div><div>{{ item.zwdqJjCpmc }}</div></div>
            <div><div>最晚到期借据金额(元)：</div><div>{{ item.zwdqJjJe }}</div></div>
            <div><div>最晚到期借据到期日期：</div><div>{{ item.zwdqJjDqrq }}</div></div>
          </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';
import applicationApi from "@/constants/api/ms-application/application.api";
import { getText } from "@/stores";

Vue.use(Popup);

Vue.use(Search);
/**
 * @Description 中小营销
 * @Author JiangTao
 * @Date 2022-01-18 下午 04:06
 */
@Component({
  name: "SMEMarketingPool",
})
export default class SMEMarketingPool extends Vue {
  resetvalue = false;
  cusName = "";
  taskStatus = ""; //营销任务状态
  itemDataList = [];
  pageNo = 1;
  pullup = true;
  pulldown = true;
  nodata = true;

  mounted() {
    if (sessionStorage.getItem("businessType") == "Upcoming") {
      this.taskStatus = "1";
    } else if (sessionStorage.getItem("businessType") == "Common") {
      this.taskStatus = "";
    }
    this.selectMarketingList(1);
  }
  // activated() {
  //   if (sessionStorage.getItem("businessType") == "Upcoming") {
  //     this.taskStatus = "1";
  //   } else if (sessionStorage.getItem("businessType") == "Common") {
  //     this.taskStatus = "";
  //   }
  //   this.selectMarketingList(1);
  // }
  /**
   * @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: "/MarketingTask",
      query: {
        type: '续贷客户营销',
      }
    });
  }
  /**
   * @Description 查询
   * @Author JiangTao
   * @Date 2022-01-18 下午 04:17
   */
  search() {
    this.selectMarketingList(1);
  }
  /**
   * @Description 重置
   * @Author JiangTao
   * @Date 2022-01-18 下午 05:36
   */
  reset() {
    this.resetvalue = true;
    this.cusName = "";
    this.selectMarketingList();
  }
  /**
   * @Description 上拉加载
   * @Author JiangTao
   * @Date 2022-01-18 下午 04:04
   */
  onloaddata() {
    this.pageNo = Math.ceil(this.itemDataList.length / 10) + 1;
    return this.selectMarketingList(this.pageNo);
  }
  // onloaddata(pageNo: number, list: any) {
  //   this.selectMarketingList(this.pageNo).then(() => {
  //     list.onStoreLoad();
  //   });
  // }
  /**
   * @Description 下拉刷新
   * @Author JiangTao
   * @Date 2022-01-17 下午 05:14
   */
  onrefreshdata() {
    this.pageNo = 1;
    return this.selectMarketingList();
  }
  // onrefreshdata(list: any) {
  //   this.pageNo = 1;
  //   this.selectMarketingList(this.pageNo).then(() => {
  //     list.refreshing = false;
  //   });
  // }
  // computed() {
  //   ipaddrArray() {
  //     return this.ipaddr.split('@');
  //   }
  // }
  /**
   * @Description 中小营销
   * @Author JiangTao
   * @Date 2022-02-12 下午 04:51
   */
  selectMarketingList(pageNo = 1) {
    const param = {
      cusName: this.cusName,
      employeeId: sessionStorage.getItem('workcode'),
      pageNum: pageNo,
      pageSize: '10',
      taskStatus: this.taskStatus, //1.未完成2.已完成 空为全量
      tc: 'MCEP'
    };
    NativeUI.showWaiting('正在查询...');
    return new Promise((resolve, reject) => {
      IF.transferDataInter(applicationApi.selectMarketZxxdVisitTask, param).then((res: any) => {
        NativeUI.closeWaiting();
        if (res.code == '1') {
          if (res.data.records && res.data.records.length > 0) {
            if (pageNo == 1) {
              this.itemDataList = res.data.records;
            } else {
              this.itemDataList = this.itemDataList.concat(res.data.records);
            }
            for (let i = 0; i < this.itemDataList.length; i++) {
              (this.itemDataList as any)[i].cusType = (this.itemDataList as any)[i].cusType.split('@');
            }
            if (res.data.records.length < 10) {
              // 如果小于10条，说明没有更多数据了,去掉加载更多
              this.pullup = false;
              resolve(true);
            } else {
              //如果等于10条那么就保留加载更多
              this.pullup = true;
              resolve(false);
            }
          } else {
            // 如果查询无数据，则去掉加载更多功能
            this.pullup = false;
            resolve(true);
          }
        } else {
          // 如果查询失败，去掉加载更多
          this.pullup = false;
          NativeUI.toast(res.msg);
          reject();
        }
      });
    });
    // return IF.transferDataInter(applicationApi.selectMarketZxxdVisitTask, param).then((res: any) => {
    //   NativeUI.closeWaiting();
    //   if (res.code == '1') {
    //     if (res.data.records && res.data.records.length > 0) {
    //       if (this.pageNo > 1) {
    //         this.itemDataList = this.itemDataList.concat(res.data.records);
    //       } else {
    //         this.itemDataList = res.data.records;
    //       }
    //       // if (pageNo == 1) {
    //       //   this.itemDataList = res.data.records;
    //       // } else {
    //       //   this.itemDataList = this.itemDataList.concat(res.data.records);
    //       // }
    //       for (let i = 0; i < this.itemDataList.length; i++) {
    //         (this.itemDataList as any)[i].cusType = (this.itemDataList as any)[i].cusType.split('@');
    //       }
    //       // if (res.data.records.length < 10) {
    //       //   // 如果小于10条，说明没有更多数据了,去掉加载更多
    //       //   this.pullup = false;
    //       // } else {
    //       //   //如果等于10条那么就保留加载更多
    //       //   this.pullup = true;
    //       // }
    //     } else {
    //       // 如果查询无数据，则去掉加载更多功能
    //       this.pullup = false;
    //       // if (pageNo == 1) {
    //       //   this.itemDataList = [];
    //       // }
    //     }
    //   } else {
    //     // 如果查询失败，则保留刷新功能，去掉加载更多
    //     // this.pullup = false;
    //     // this.pulldown = true;
    //     NativeUI.toast(res.msg);
    //   }
    //   // if (res.data.records && res.data.records.length < 10) {
    //   //   console.log("无数据2");
    //   //   this.pullup = false;
    //   // } else if (!res.data.records) {
    //   //   this.pullup = false;
    //   // }
    //   // if (this.itemDataList.length == 0) {
    //   //   this.pulldown = false;
    //   //   this.nodata = false;
    //   // }
    // });
  }
}
</script>

<style scoped lang="scss">
::v-deep .van-cell__title,
::v-deep .van-field__label {
  display: flex;
  align-items: center;
}
.content {
  width: 100%;
  height: 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: 6%;
}
.customer-bottom-list-top > div:nth-child(1) > div {
  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) {
  width: auto;
  font-size: 115%;
  font-weight: bold;
  font-family: "微软雅黑 Bold", "微软雅黑 Regular", "微软雅黑";
  margin-left: 0.8%;
  white-space: nowrap;
}
.customer-bottom-list-top {
  width: 95%;
  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: 85%;
  display: flex;
  flex-wrap: wrap;
}
.customer-bottom-list-bottom {
  width: 95%;
  height: auto;
  display: flex;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-left: 50px;
}
.customer-bottom-list-bottom > div {
  width: auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-right: 10px;
}
.customer-bottom-list-bottom > div > div:nth-child(1) {
  color: #999999;
  word-break: keep-all;
}
.customer-bottom-list-bottom > div > div:nth-child(2) {
  word-break: keep-all;
}
.Managementdata {
  padding: 0 20px;
  height: calc(100vh - 130px);
}
::v-deep .Managementdata .bs-wrapper{
  height: 100%;
}
::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;
}
.labelStyle {
  display: flex;
  flex-wrap: wrap;
}
.labelStyle > div {
  width: fit-content;
  font-size: 12px;
  background-color: #E2F6FF;
  padding: 2px 5px;
  color: #0297D7;
  border-radius: 2px;
  word-break: keep-all;
  margin-left: 1%;
  margin-bottom: 5px;
}
</style>
