/**
* @Author think
* @Date 2019-06-17 09:31
*/

<template>
  <h-view class="public-style risk-home">
    <div class="search">
      <div class="searchBox" @click="go()">
        <img src="@/assets/image/risk/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="70">
        <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/image/risk/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>
import riskDetailService from './riskDetailService'
export default {
  name: 'RiskHome',
  data () {
    return {
      offsize: 1,
      dataList: [],
    }
  },
  watch: {},
  created: function () {

  },
  mounted () {
    let vm = this
    vm.init()
  },
  methods: {
    init () {
      let vm = this
      let url = $config.basePath + 'risktorm_bp'
      let param = { 'offsize': vm.offsize }
      vm.hlsHttp.post(url, param).then(function (res) {
        vm.hlsPopup.hideLoading()
        vm.dataList = res.prj_project_bp_list
        if (vm.dataList.length >= 0 && vm.dataList.length < 10) {
          vm.$refs.scroll.update(true)
        }
      })
    },
    loadMore () {
      let vm = this
      vm.offsize++
      let url = $config.basePath + 'risktorm_bp'
      let param = {
        'offsize': vm.offsize,
      }
      vm.hlsHttp.post(url, param).then(function (res) {
        vm.hlsPopup.hideLoading()
        let returnData = res.prj_project_bp_list
        if (returnData.length === 0) {
          vm.$refs.scroll.update(true)
        } else if (returnData.length > 0 && returnData.length < 10) {
          vm.$refs.scroll.update(true)
          returnData.forEach((data, index, array) => {
            vm.dataList.push(array[index])
          })
        } else if (returnData.length === 10) {
          vm.scrollBusy = true
          returnData.forEach((data, index, array) => {
            vm.dataList.push(array[index])
          })
        }
      })
    },

    goDetail (num) {
      let vm = this
      if (vm.dataList[num]['organization_code']) {
        let name = vm.dataList[num]['bp_name']
        let organizationCode = vm.dataList[num]['organization_code']
        riskDetailService.setCompanyName(name)
        riskDetailService.setOrganizationCode(organizationCode)
        vm.$router.push({
          name: 'RiskSearchDetail',
          params: {
            id: organizationCode,
            name: name,
          },
        })
      } else {
        vm.hlsPopup.showLongBottom('暂无详情')
      }
    },
    go () {
      this.$router.push({
        name: 'RiskSearch',
      })
    },
  },
}
</script>

<style scoped lang="less">
  .risk-home {
    background-color: #fafafa;

    .search {
      position: relative;
      z-index: 5;
      width: 100%;
      height:45px;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 0 15px;
      background-color: #fff;
      border-bottom:1px solid @background-color-gray; /*no*/
      .searchBox {
        background-color: #fff;
        display: flex;
        align-items: center;
        border-radius: 8px;
        border: 1px solid @hintColor;
        width: 100%;
        height: 30px;
        color: #cccccc;
        font-size: @font-size-middle;
        letter-spacing: -0.34px;
        img {
          width: 17px;
          height: 17px;
          margin: 0 13px 0 20px;
        }
        .searchInput {
          width: 80%;
          line-height: 28px;
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
        }
      }
    }
    .content {

      .add-name {
        .left-icon {
          width: 36px;
        }
      }
      .hls-item {
        &:nth-child(odd){
          background-color: #EFF1F3;
        }
        &:nth-child(even){
          background-color: #fff;
        }
      }
    }
  }
</style>
