<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-list
      v-model="loading"
      :finished="finished"
      finished-text="已显示所有数据"
      @load="GetSaBuildingSelectList"
    >
      <van-cell
        v-for="item in listdata"
        :key="item.keyId"
        :title="item.keyValue"
        title-class="title1"
        is-link
        size="large"
        @click="click1($event, item.keyId,item.keyValue)"
      >
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import { GetSaBuildingSelectList } from "@/common/api/loginApi.js";
export default {
  name: "login",
  data() {
    return {
      listdata: [], 
      loading: false,
      finished: false,
    };
  },
  created: function () {
    console.info("created");
    //console.info(this.$util);
    this.$util.persistLogin(this);
  },
  methods: {
    GetSaBuildingSelectList: function () {
      var that = this;
      var data = {
        projectId: that.$store.state.projectId
      };
      console.info("data", data);
      GetSaBuildingSelectList(data).then((res) => {
        console.info("GetSaBuildingSelectList", res);
        if (!res.result) {
          that.$toast(res.msg);
          return;
        }
        res.data.forEach(function (item, index, array) {
          that.$set(that.listdata, index, item);
        });
        that.loading = false;
        that.finished = true;
      });
    },
    // 行选择事件
    click1: function (event, id,name) {
      //console.info("click1 event", event);
      //跳转到楼栋详情
      this.$router.push({path:'/getsabuildingstruct',query:{id:id,name:name}});
      
    },
    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: #999;
  text-align: left;
}

</style>
