<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-cell
          v-for="item in info"
          :key="item.hcode"

          border
        >
          <template #default>

            <van-row class="borderTop"  >
              <van-col span="24">
                <van-row>
                  <van-col span="5" class="title1">业主</van-col>
                  <van-col span="19">{{ item.ownername }}</van-col>
                </van-row>
                  <van-row>
                  <van-col span="5" class="title1">房屋</van-col>
                  <van-col span="19">{{ item.hname }}</van-col>
                </van-row>
                 <van-row>
                  <van-col span="5" class="title1">楼栋</van-col>
                  <van-col span="19">{{ item.bname }}</van-col>
                </van-row>

               <van-row>
                  <van-col span="24" class="title1">
                      <van-button @click="bind(item.hcode)" type="info">绑定</van-button>
                  </van-col>
                </van-row>
              </van-col>

            </van-row>
          </template>
        </van-cell>

  </div>
</template>

<script>
import { BindHouse } from '@/common/api/loginApi.js'
export default {
  name: 'login',
  data () {
    return {
      info: [] // 房产信息

    }
  },
  created: function () {
    console.info('created')
    // console.info(this.$util);
    this.$util.persistLogin(this)
    this.BindHouse()
  },
  methods: {
    BindHouse: function () { // 获取房产信息
      var that = this
      let phone = that.$store.state.data.tel
      if (that.$util.isEmpty(phone)) {
        that.$router.push('/')
        return
      }
      BindHouse(phone).then((res) => {
        console.info('BindHouse', res)
        if (!res.isSuccess) {
          that.$toast(res.errMsg)
          return
        }
        res.data.forEach(function (item, index, arr) {
          that.$set(that.info, index, item)
        })

        // that.loading = false;
        // that.finished = true;
      })
    },

    onClickLeft () {
      // this.$toast('返回')
      console.info('left')
      this.$router.go(-1)
    },
    onClickRight () {
      this.$router.go(0)
    },
    bind: function (hcode) { // 绑定房屋信息
      let that = this
      this.info.forEach(function (item, index, arr) {
        // eslint-disable-next-line eqeqeq
        if (item.hcode == hcode) {
          var obj = JSON.parse(that.$cookie.get('obj'))
          console.info('bind obj', obj)
          // 设置状态中的各种值
          that.$store.commit('setResult', obj.isSuccess)
          that.$store.commit('setCode', obj.code)
          that.$store.commit('setMsg', obj.errMsg)
          that.$store.commit('setData', item)
          that.$store.commit('setToken', obj.tnToken)
          // console.info('cookie',this.$cookie)
          that.$cookie.set('obj', JSON.stringify(obj)) // 设置cookie
          that.$router.push('/saleindex')
        }
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.title1 {
  color: #999;
}
.value1 {
  color: #999;
  font-size: 15px;
}
.borderTop{
    margin-top:50px;
}
.paddingLeft15{
    padding-left: 15px;
    text-align: left;
    height: 50px;
    line-height: 50px;
    font-size: 28px;
}
</style>
