<template>
  <view>
    <u-navbar :border-bottom="false" :is-back="true" title="浏览记录">
      <view slot="right" class="u-nav-slot" @click="clearHistory">
        <u-icon name="trash"></u-icon>
        清除
      </view>
    </u-navbar>
    <scroll-view scroll-y style="height: 100%;width: 100%;">
      <view class="page-box">
        <view v-if="houseHistory.length === 0">
          <view class="centre">
            <image :src="empty" mode=""></image>
            <view class="explain">
              您还没有浏览过的房源
              <view class="tips">可以去逛逛</view>
            </view>
            <view class="btn" @click="goHome">首页</view>
          </view>
        </view>
        <view v-for="(item, index) in houseHistory" v-else :key="index" class="order"
              @click="clickImage(item.id)">
          <view class="top">
            <view class="left">
              <view class="store">{{ item.code }}</view>
              <u-icon :size="26" color="rgb(203,203,203)" name="arrow-right"></u-icon>
            </view>
          </view>
          <view class="item">
            <view class="left">
              <image :src="item.faceUrl" mode="aspectFill"></image>
            </view>
            <view class="content">
              <view class="title u-line-2">
                {{ item.villageName }}
                {{ item.type == '整租' ? item.houseNum + item.houseHall + item.toiletNum : item.roomType }}
              </view>
              <view class="price">¥{{ item.price }}</view>
              <view class="type">
                {{ item.type }} | {{ item.type == '整租' ? item.houseArea : item.roomArea }}㎡ | {{ item.decoration }}
              </view>
            </view>
          </view>
          <view class="bottom">
            <view class="evaluate btn" @click="clickImage(item.id)">查看</view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import config from "@/common/config.js" // 全局配置文件
export default {
  data() {
    return {
      empty: '/static/empty/default.png',
      houseHistory: uni.getStorageSync('houseHistory').reverse()
    };
  },
  onLoad() {

  },
  methods: {
    clickImage(houseId) {
      this.$u.route({
        url: '/pages/detail/detail',
        params: {
          houseId: houseId
        }
      })
    },
    goHome() {
      uni.switchTab({
        url: '/pages/index/index'
      })
    },
    clearHistory() {
      // 清除搜索记录
      uni.showModal({
        title: '提示',
        content: '是否清除浏览记录？',
        cancelText: '取消',
        confirmText: '确认',
        success: res => {
          if (res.confirm) {
            uni.removeStorageSync('houseHistory');
            this.houseHistory = []
            this.$mytip.toast('清除成功')
          }
        }
      });
    }
  }
};
</script>

<style>
/* #ifndef H5 */
page {
  height: 100%;
  background-color: #f2f2f2;
}

/* #endif */
</style>

<style lang="scss" scoped>
.u-nav-slot {
  color: $u-tips-color;
  font-weight: normal;
  font-size: 28 rpx;
  margin-right: 30 rpx;
}

.container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;

  .empty {
    overflow: hidden;

    .tip {
      color: #909399;
    }

    .btn {
      color: #fff;
      background-color: #909399;
      width: 200 rpx;
      padding: 15 rpx 28 rpx;
      border-radius: 130 rpx;
      margin: 30 rpx 0 0 100 rpx;
    }
  }
}

.order {
  width: 710 rpx;
  background-color: #ffffff;
  margin: 20 rpx auto;
  border-radius: 20 rpx;
  box-sizing: border-box;
  padding: 20 rpx;
  font-size: 28 rpx;

  .top {
    display: flex;
    justify-content: space-between;

    .left {
      display: flex;
      align-items: center;

      .store {
        // margin: 0 10rpx;
        font-size: 32 rpx;
      }
    }

    .right {
      color: #2979ff;
    }
  }

  .item {
    display: flex;
    margin: 20 rpx 0 0;

    .left {
      margin-right: 30 rpx;

      image {
        width: 150 rpx;
        height: 150 rpx;
        border-radius: 10 rpx;
      }
    }

    .content {
      .title {
        font-weight: bold;
        font-size: 28 rpx;
        line-height: 50 rpx;
      }

      .price {
        margin: 10 rpx 0;
        font-size: 30 rpx;
      }

      .type {
        margin: 10 rpx 0;
        font-size: 24 rpx;
        color: $u-tips-color;
      }
    }
  }

  .bottom {
    display: flex;
    // margin-top: 40rpx;
    padding: 0 10 rpx;
    justify-content: flex-end;
    align-items: center;

    .btn {
      margin-left: 20 rpx;
      line-height: 52 rpx;
      width: 160 rpx;
      border-radius: 26 rpx;
      border: 2 rpx solid $u-border-color;
      font-size: 26 rpx;
      text-align: center;
      color: $u-type-info-dark;
    }

    .evaluate {
      color: $u-tips-color;
      border-color: $u-tips-color;
    }
  }
}

.centre {
  text-align: center;
  margin: 200 rpx auto;
  font-size: 32 rpx;

  image {
    width: 164 rpx;
    height: 164 rpx;
    border-radius: 50%;
    margin-bottom: 20 rpx;
  }

  .tips {
    font-size: 24 rpx;
    color: #999999;
    margin-top: 20 rpx;
  }

  .btn {
    margin: 80 rpx auto;
    width: 200 rpx;
    border-radius: 32 rpx;
    line-height: 64 rpx;
    color: #ffffff;
    font-size: 26 rpx;
    background-image: linear-gradient(to left, #2979ff, rgba(#2979ff, 0.6));
  }
}
</style>
