/**
* @Author Sean
* @Date 2019/6/14
*/
<template>
  <h-view class="public-style" style="height:100%;" title="启信宝">
    <div class="search">
      <div class="searchBox" @click="goSearch">
        <img src="@/assets/qixinbao/search@2x.png">
        <div class="searchInput">
          请输入企业名称
        </div>
      </div>
    </div>
      <scroll
        ref="scroll"
        :updateData="[dataList]"
        :pullUp="true"
        class="content-scroll"
        @pullingUp="loadMore">
        <list-item :item-height="80">
          <item
            v-for="(list,index) in dataList"
            :has-border="false" :key="index" :proportion="[5,1]" :show-arrow="true"
            @click.native="goDetail(index)">
            <img slot="left-icon" src="@/assets/qixinbao/custormer@2x.png" class="left-icon">
            <div slot="name" class="text">
              <div class="cont-name">项目编号：\{{ list.project_number }}</div>
              <div class="cont-type">客户姓名：\{{ list.bp_name }}</div>
            </div>
          </item>
        </list-item>
      </scroll>
  </h-view>
</template>

<script>
  export default {
    data () {
      return {
        dataList: [],
      }
    },
    created () {
      let vm = this
      this.offsize = 1
      this.pagesize = 10
      vm.init()
    },
    mounted () {

    },
    methods: {
      init () {
        let vm = this
        let url = process.env.basePath + 'risktorm_bp'
        let param = {'offsize': vm.offsize}
        hlsPopup.showLoading('请稍候')
        vm.$post(url, param).then(function (res) {
          hlsPopup.hideLoading()
          vm.dataList = res.prj_project_bp_list
          if (vm.dataList.length >= 0 && vm.dataList.length < 10) {
            vm.$refs.scroll.update(true) // 关闭上拉 ，为true  不再滚动
          }
        })
      },
      loadMore () {
        let vm = this
        vm.offsize = vm.offsize + 1
        var url = process.env.basePath + 'risktorm_bp'
        var param = {
          'offsize': vm.offsize,
        }
        vm.$post(url, param).then(function (res) {
          hlsPopup.hideLoading()
          var returnData = res.prj_project_bp_list
          if (returnData.length === 0) {
            vm.$refs.scroll.update(true) // 关闭上拉，不再滚动
          } else if (returnData.length > 0 && returnData.length < 10) {
            returnData.forEach(item => {
              vm.dataList.push(item)
            })
            vm.$refs.scroll.update(true)
          } else if (returnData.length === 10) {
            returnData.forEach(item => {
              vm.dataList.push(item)
            })
            vm.$refs.scroll.update(false)
          }
        })
      },
      goDetail (index) {
        let vm = this
        if (vm.dataList[index]['organization_code']) {
          vm.$router.push({
            name: 'QiXinDetail',
            params: {
              id: vm.dataList[index]['organization_code'],
              name: vm.dataList[index]['bp_name'],
            },
          })
        } else {
          hlsPopup.showLongCenter('暂无详情')
        }
      },
      goSearch () {
        this.$router.push({
          name: 'QiXinSearch',
        })
      },
    },
  }
</script>

<style scoped lang="less" rel="stylesheet">
  .public-style {
    .search {
      position: relative;
      z-index: 5;
      width: 100%;
      height: 45px;
      display: -webkit-flex;
      display: flex;
      -webkit-justify-content: center;
      justify-content: center;
      -webkit-align-items: center;
      align-items: center;
      padding: 0 15px;
      background-color: #fff;
      border-bottom:1px solid @background-color-gray;
      .searchBox {
        background-color: #fff;
        display: -webkit-flex;
        display: flex;
        -webkit-align-items: center;
        align-items: center;
        border-radius: 16px;
        border: 1px solid @hintColor;
        width: 100%;
        height: 30px;
        color: #cccccc;
        font-size: 14px;
        letter-spacing: -0.34px;
        img {
          width: 17px;
          height: 17px;
          margin: 0 13px 0 20px;
        }
        .searchInput {
          width: 100%;
          /*text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;*/
        }
      }
    }
    .content {
     // margin-top: 45px;
    }
  }
</style>
