<template>
  <div class="apply-wrap">
    <nav-bar title="申请列表"/>
    <div class="wrap">
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh" v-if="data.length">
        <van-list
          v-model="loading"
          :finished="finished"
          :immediate-check='false'
          :offset="200"
          @load="onLoad"
        >
          <div class="box" v-for="item in data" :key="item.applyCode" @click="detail(item)">
            <div class="header flex_sb align-c">
              <p>咨询编号：{{item.applyCode}}</p>
              <span>{{item.applyStatusText}}</span>
            </div>
            <div class="content">
              <div class="message">
                <div class="flex_sb align-c">
                  <p>姓名：</p>
                  <span>{{item.name}}</span>
                </div>
                <div class="flex_sb align-c">
                  <p>城市：</p>
                  <span>{{item.cityText}}</span>
                </div>
                <div class="flex_sb align-c">
                  <p>入住时间：</p>
                  <span>{{item.liveTime}}</span>
                </div>
                <div class="flex_sb align-c">
                  <p>提交时间：</p>
                  <span>{{item.createTimeText}}</span>
                </div>
              </div>
              <div class="room flex" v-if="item.houseInfo">
                <img v-if="item.houseInfo.imgUrl" :src='item.houseInfo.imgUrl' alt="">
                <img v-else src="//static.hoolihome.com/m/assets/img/buildings-img@2x.png" alt="">
                <div class="info">
                  <h5 class="lineTwoHidden">{{item.houseInfo.houseName}}</h5>
                  <div class="flex">
                    <p>{{item.houseInfo.moneySymbol}}</p>
                    <span>{{item.houseInfo.roomPrice}}</span>
                    <i>/{{item.houseInfo.rentTimeUnit}}</i>
                  </div>
                </div>
              </div>
            </div>
            <div class="footer flex_sb align-c">
              <p>申请详情</p>
              <i class="icon icon-jiantou-you"></i>
            </div>
          </div>
        </van-list>
        <is-empty v-if="isEmpty"></is-empty>
      </van-pull-refresh>
      <div class="room-detail-none" v-if="!data.length">暂无数据</div>
    </div>
  </div>
</template>

<script>
import NavBar from "@/components/common/NavBar";

export default {
  name: "Apply",
  components: {
    NavBar
  },
  data() {
    return {
      data: [],
      pages: {},
      page: 0,
      isEmpty: false,
      loading: false,
      finished: false,
      isLoading: false,
      itemsChecked: false,
      isEdit: false,
      lastId: 0
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // 上拉加载
    onLoad() {
      setTimeout(() => {
        this.getData("onLoad");
      }, 500);
    },
    // 下拉刷新
    onRefresh() {
      setTimeout(() => {
        this.page = 0;
        this.getData("onRefresh");
      }, 500);
    },
    // 获取数据
    getData(val) {
      let params = {};
      params.url = this.$apis.api_user_order_applied;
      this.page = this.page + 1;
      params.data = {
        page: this.page,
        limit: 10
      };
      this.$net.req(params, this).then(
        res => {
          if (Number(res.code) === 0) {
            this.lastId = this.data.slice(-1).id || 0;
            let data = res.data.list;
            this.pages = res.data.pages;
            if (this.page * params.data.limit >= this.pages.totalCount) {
              this.finished = true;
              this.isEmpty = true;
            }
            if (val === "onLoad") {
              this.loading = false;
              this.data = this.data.concat(data);
            } else {
              this.data = data;
            }
            if (val === "onRefresh") {
              this.finished = false;
              this.isEmpty = false;
              this.$toast("刷新成功");
              this.isLoading = false;
            }
          } else {
            this.$Toast(res.msg);
          }
        },
        e => {
          this.$Toast(e.msg);
        }
      );
    },
    // 查看详情
    detail(item) {
      let lang = this.$store.state.langStr;
      this.$router.push({
        path: `/${lang}/user/applyDetail/${item.id}`
      });
    }
  }
};
</script>

<style scoped lang='less'>
.apply-wrap {
  background: #f9f9f9;
  min-height: 100vh;
  .wrap {
    .van-pull-refresh {
      height: 100vh;
      overflow: auto;
    }
    .box {
      padding: 0 15px;
      border-radius: 8px;
      background: #fff;
      margin: 0 20px 15px;
      &:first-child {
        margin-top: 15px;
      }
      .header {
        height: 40px;
        border-bottom: 1px solid #ddd;
        p {
          color: #222;
          font-size: 14px;
        }
        span {
          color: #ff523d;
          font-size: 14px;
        }
      }
      .content {
        .room {
          padding: 0 0 10px;
          img {
            width: 133px;
            height: 100px;
            border-radius: 4px;
            margin-right: 15px;
            flex-shrink: 0;
          }
          .info {
            h5 {
              color: #222;
              font-size: 17px;
              max-height: 60px;
              line-height: 20px;
              overflow: hidden;
              margin: 0 0 12px;
            }
            div {
              align-items: baseline;
              p {
                color: #ff523d;
                font-size: 14px;
              }
              span {
                color: #ff523d;
                font-size: 24px;
                font-weight: bold;
              }
              i {
                color: #222;
                font-size: 14px;
              }
            }
          }
        }
        .message {
          color: #999;
          font-size: 14px;
          > div {
            margin: 10px 0;
          }
          .pay {
            color: #444;
          }
        }
      }
      .footer {
        height: 40px;
        border-top: 1px solid #ddd;
        p {
          color: #222;
          font-size: 14px;
        }
        i {
          color: #bbb;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
