<template>
  <div>
    <van-nav-bar
      @click-left="onClickLeft"
      @click-right="onClickRight"
      style="background-color: #1989fa"
    >
      <template #title>
        <van-col style="color: #ffffff">{{titleName}}</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.clientId"
          
        >
          <template #title>
            <van-col span="24" class="title1">{{item.name}}</van-col>
            <van-col span="24" class="title2">
                业务员：{{item.cUserName}}
             </van-col>
            </template>
            <template #default>
                <van-col span="24" class="star" > 
                   <span v-for="i in item.intention" :key="i+'x'" class="size">★</span>
                   <span v-for="i in 5-item.intention" :key="i" class="size">☆</span>
                </van-col>
                <van-col span="24" v-if="item.visitdate!=''" class="title3">
                   最后接待：{{item.visitdate}}
                </van-col>
            </template>
        </van-cell>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { GetSaClientSummaryList } 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);
  },
  computed:{  //计算属性
      titleName:function(){
          return this.$route.query.saleState+'客户';
      },
      
  },
  methods: {
    GetSaClientSummaryList: function () {
      var that = this;
      var data = {
        userCode: that.$store.state.data.userCode,
        projectId: that.$store.state.projectId,
        page: that.page,
        pageCount: "10",
        saleState:that.$route.query.saleState,
        jsonQuery: "",
        sortby: "",
      };
      console.info("data", data);
      GetSaClientSummaryList(data).then((res) => {
        console.info("GetSaClientSummaryList", 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.GetSaClientSummaryList()
        this.loading = true
      }, 500)
    },
    onRefresh () {
      setTimeout(() => {
        // 重新初始化这些属性
        this.isLoading = false
        this.listdata = []
        this.page = 1
        this.loading = false
        this.finished = false
        //this.noData = false
        // 请求信息
        this.GetSaClientSummaryList()
      }, 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;
    
    height:35px;
}
.title2{
    color:#999;
    text-align: left;
    height:25px;
}
.title3{
    color:#999;
    text-align: right;
    height:25px;
}
.star{
    height:35px;
}
.size{
    font-size:16px;
    color:orange;
}
</style>
