<template>
  <div>
    <van-nav-bar
      @click-left="onClickLeft"
      @click-right="onClickRight"
      style="background-color: #1989fa"
    >
      <template #title>
        <van-col style="color: #ffffff">联系信息</van-col>
      </template>
      <template #left>
        <i
          class="fa fa-arrow-circle-left"
          aria-hidden="true"
          style="color: #ffffff; font-size: 18px"
        ></i>
      </template>
      <template #right>
        <van-icon name="replay" size="18" color="#ffffff" />
      </template>
    </van-nav-bar>

    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        loading-text="加载中..."
        finished-text="我是有底线的~"
        @load="onLoad"
      >
        <van-cell
          v-for="item in listdata"
          :key="item.ccId"
          :to="'/getsaclientcontactinfo?id='+item.ccId"
        >
          <template #title>
            <van-col span="24" class="title1">{{item.ClientName}}</van-col>
            <van-col span="24">
                <van-row>
                    <van-col span="9" class="title2">接待日期</van-col>
                    <van-col span="15" class="title2">{{item.ccVisitDate}} {{item.ccVisitTime}}</van-col>
                </van-row>
                </van-col>
            </template>
            <template #default>
                <van-col span="24" class="star" > 
                   <span v-for="i in item.ccIntention" :key="i+'x'" class="size">★</span>
                   <span v-for="i in 5-item.ccIntention" :key="i" class="size">☆</span>
                </van-col>
                <van-col span="24">
                    <van-row>
                        <van-col span="24">业务员：{{item.UserName}}</van-col>
                    </van-row>
                </van-col>
            </template>
        </van-cell>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { GetSaClientContactList } from "@/common/api/loginApi.js";
export default {
  name: "login",
  data() {
    return {
      listdata: [], 
      loading: false,
      finished: false,
      isLoading: false,
      page:"1"
    };
  },
  created: function () {
    console.info("created");
    //console.info(this.$util);
    this.$util.persistLogin(this);
  },
  methods: {
    GetSaClientContactList: function () {
      var that = this;
      var data = {
        userCode: that.$store.state.data.userCode,
        projectId: that.$store.state.projectId,
        page: that.page,
        pageCount: "10",
        jsonQuery: "",
        sortby: "",
      };
      console.info("data", data);
      GetSaClientContactList(data).then((res) => {
        console.info("GetSaClientContactList", res);
        if (!res.result) {
          that.$toast(res.msg);
          return;
        }
        if(res.data!=null&&res.data.listdata.length>0){
          that.loading=false;
          res.data.listdata.forEach(function (item, index, array) {
            that.listdata.push(item);
            //console.info('length:'+res.data.listdata.length,'index:'+index);
            if(res.data.listdata.length-1==index){
              that.page++;
              if(res.data.page.totalPages==that.page-1){
                that.finished=true;
              }
            }
          });
          if(res.data==null||res.data.listdata==null||res.data.listdata.length==0){
            that.finished = true;
          }
          
        }
         else{
          that.finished=true;
        }
      });
    },
    // 列表加载
    onLoad () {
      setTimeout(() => {
        this.GetSaClientContactList()
        this.loading = true
      }, 500)
    },
    onRefresh () {
      console.info('onRefresh');
      setTimeout(() => {
        // 重新初始化这些属性
        this.isLoading = false
        this.listdata = []
        this.page = 1
        this.loading = false
        this.finished = false
        //this.noData = false
        // 请求信息
        this.GetSaClientContactList()
      }, 500)
    },
    onClickLeft() {
      // this.$toast('返回')
      console.info("left");
      this.$router.go(-1);
    },
    onClickRight() {
      this.$router.go(0);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.title1 {
   color:#0f0fa7;
    font-size:16px;
    font-weight:900;
    text-align: left;
    margin-left:15px;
    height:35px;
}
.star{
    height:35px;
}
.size{
    font-size:16px;
    color:orange;
}
.title2{
    color:#999;
    
}
</style>
