<template>
  <div class="classification-con">
    <div class="search flex-default">
      <div class="search-bar flex-default" @click="handleSearch">
        <m-icon icon="icon-search2" className="logo" :size="14" />
        <span class="placeholder">搜索数字藏品</span>
      </div>
    </div>
    <div class="content flex-default">
      <left-side v-model="currentIndex" :list="leftList" />
      <classification-content :categoryId="categoryId" :list="list" :show="show" :cover="contentCover" />
    </div>
  </div>
</template>

<script>
import LeftSide from "./left-side.vue";
import ClassificationContent from "./classification-content.vue";
import { mapGetters } from "vuex";
export default {
  components: {
    LeftSide,
    ClassificationContent,
  },
  watch: {
    currentIndex(val) {
      if (this.leftList && this.leftList.length != 0) {
        this.categoryId  = this.leftList[val].categoryId;
        setTimeout(() => {
          this.contentCover = this.leftList[val].thumb;
        }, 500);
        this.requestData(this.categoryId);
      }
    },
  },
  data() {
    return {
      currentIndex: -1,
      leftList: [],
      categoryId: "",
      list: [],
      show: false,
      contentCover: "",
    };
  },
  onShow() {
    // if (this.hasLogin) {
    //   this.$store.dispatch("getShoppingCart");
    // }
  },
  computed: {
    ...mapGetters(["hasLogin"]),
  },
  methods: {
    requestData(id) {
      this.$showLoading();
      this.show = false;
      this.$api({
        apiName: "getCategory",
        postData: id,
        success: (res) => {
          setTimeout(() => {
            if (!id) {
              this.leftList = res;
              this.currentIndex = 0;
            } else {
              this.list = res;
            }
            this.$hideLoading();
            this.show = true;
          }, 500);
        },
      });
    },

    handleSearch() {
      this.$router.push({name: "search"})
    },
  },
  mounted() {
    this.requestData("");
  },
};
</script>

<style lang="less">
.classification-con {
  height: 100vh;
  @search-height: 52px;

  > .search {
    padding: 0 16px;
    height: @search-height;
  }

  > .search .search-bar {
    height: 36px;
    width: 100%;
    background: #f8f8f8;
    border-radius: 20px;
    padding: 0 14px;
    line-height: 36px;
    align-items: center;

    .logo {
      margin-right: 10px;
    }

    .placeholder {
      color: #aeaeae;
      font-size: 14px;
    }
  }

  > .content {
    height: calc(100% - @search-height);
    padding-top: 13px;
    background: #f0f2f5;

    .left-side-con {
      width: 100px;
    }

    .classification-content-con {
      flex: 1;
    }
  }
}
</style>
