<template>
  <div class="catstyle7" style="height: 100%;">
    <view class="tabsbox">
      <u-tabs
        :is-scroll="true"
        name="Name"
        :list="d"
        :active-color="mainColor"
        :current="active"
        @change="changeHandler"
        :type-style="2"
        :show-bar="false"
        :bold="false"
        height="50"
        duration="0"
      ></u-tabs>
    </view>
    <div class="second">
      <div
        class="item"
        :style="{
          'border-color': stid == i ? mainColor : '#999',
          color: stid == i ? mainColor : '#999',
        }"
        v-for="(x, i) in d[tid].ChildList"
        :key="i"
        @click="clickSecondHandler(i)"
      >
        {{ x.Name }}
      </div>
    </div>
    <div
      style="padding: 10px;padding-bottom:0; background: #f5f5f5;"
      :style="{ height: 'calc(100% - 45px - ' + sHeight + 'px)' }"
    >
      <scroll-view
        :scroll-y="true"
        @scrolltolower="lower"
        :enable-back-to-top="true"
        :enable-flex="true"
        style="height: 100%;"
      >
        <u-row gutter="10">
          <u-col span="6" v-for="(cx, ci) in g" :key="ci">
            <div class="good" @click="clickHandler(cx)">
              <div class="good-img">
                <image
                  mode="aspectFit"
                  :src="cx.cover_pic"
                  style="width: 100%; height: 100%;"
                />
              </div>
              <div class="good-name">{{ cx.name }}</div>
              <div class="good-info">
                <div class="price" :style="{ color: mainColor }">
                  {{ cx.price_content }}
                </div>
                <div class="sell">{{ cx.sales }}</div>
              </div>
            </div>
          </u-col>
        </u-row>
        <u-divider v-if="isover" :margin-top="20" bg-color="#F5f5f5" :margin-bottom="20"
          >没有更多商品了</u-divider
        >&nbsp;
      </scroll-view>
    </div>
  </div>
</template>

<script>
export default {
  props: ["d", "h"],
  data() {
    return {
      mainColor: "",
      page: 1,
      page_count: 1,
      mh: 0,
      g: [],
      isover: false,
      loading: false,
      tid: 0,
      active: 0,
      stid: 0,
      sHeight: 0,
	  msg:{
		  pageIndex: 1,
		  pageSize:14,
		  Name:'',
		  GoodsType:0,
		  CategoryIds:'',
		  OrderBy:1,
		  UserId:0,
	  },
    };
  },
  created() {
    this.mainColor = this.$uiConfig.mainColor;
  },
  mounted() {
	  this.CategoryIdsList=[];
	  this.CategoryIds1=this.d[0].Id;
	  this.CategoryIds2=this.d[0].ChildList[0].Id;
    this.init();
    setTimeout(() => {
      this.computSecondHeight();
    }, 500);
  },
  methods: {
    changeHandler(i) {
	 this.active=i;
	 this.CategoryIds1=this.d[i].Id;
	 this.CategoryIds2=this.d[i].ChildList[0].Id;
	 this.msg.page = 1;
	 this.tid = i;
	 this.stid = 0;
      this.g = [];
      this.init();
      setTimeout(() => {
        this.computSecondHeight();
      }, 500);
    },
    clickSecondHandler(i) {
	  let tid=this.tid;
	  this.CategoryIds2=this.d[tid].ChildList[i].Id;
	  this.stid = i;
	  this.msg.page = 1;
      this.g = [];
      this.init();
    },
    clickHandler(item) {
      uni.navigateTo({ url: '/pages/goods/goods?GoodsId='+item.id });
    },
    computSecondHeight() {
      const query = uni.createSelectorQuery().in(this);
      query
        .select(".second")
        .boundingClientRect((data) => {
            this.sHeight=data.height
        })
        .exec();
    },
    init() {
	  this.CategoryIdsList=[];
	  this.CategoryIdsList.push(this.CategoryIds1,this.CategoryIds2);
	  this.msg.CategoryIds=this.CategoryIdsList.join(',');
      this.isover = false;
      this.loading = true;
	  this.request2(
	  	{
	  		url: '/api/AppletGoods/GetAppletGoodsPageListForZY',
	  		data: this.msg
	  	},
	  	res => {
	  		this.loading = false;
	  		console.log("resggg",res);
	  		if(res.resultCode==1){
	  			this.g = this.g.concat(res.data.pageData);
	  			this.page_count = res.data.pageCount;
	  			if (this.page_count == 1 || this.page_count==0) {
	  			  this.isover = true;
	  			}
	  			
	  		}
	  		
	  		uni.hideNavigationBarLoading();
	  	}
	  );
      // this.request(
      //   {
      //     url: "",
      //     data: {
      //       r: "api/default/goods-list",
      //       page: this.page,
      //       cat_id: this.d[this.tid].ChildList[this.stid].id,
      //     },
      //   },
      //   (res) => {
      //     this.g = this.g.concat(res.data.list);
      //     this.page_count = res.data.pagination.page_count;
      //     if (this.page_count == 1) {
      //       this.isover = true;
      //     }
      //     this.loading = false;
      //   }
      // );
    },
    lower(e) {
      if (this.msg.pageIndex < this.page_count) {
        if (!this.loading) {
          this.msg.pageIndex++;
          this.init();
        }
      } else {
        this.isover = true;
      }
    },
  },
};
</script>

<style>
.catstyle7 .tabsbox {
  padding: 10px;
}
.catstyle7 .good {
  background: #fff;
  border-radius: 10px;
}
.catstyle7 .good .good-img {
  width: calc(50vw - 15px);
  height: calc(50vw - 15px);
  display: block;
}
.catstyle7 .good .good-name {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 3px;
  font-size: 14px;
  margin: 7px 10px;
}
.catstyle7 .good .good-info {
  display: flex;
  margin: 7px 10px;
  margin-top: 0;
  align-items: center;
  padding-bottom: 5px;
}
.catstyle7 .good .good-info .price {
  font-size: 16px;
  color: #ff4544;
  flex: 1;
}
.catstyle7 .good .good-info .sell {
  font-size: 12px;
  color: gray;
  flex: 1;
  text-align: right;
}
.catstyle7 .second {
  padding: 0 10px 10px 0;
}
.catstyle7 .second .item {
  margin-top: 10px;
  margin-left: 10px;
  display: inline-block;
  padding: 5px 10px;
  height: 23px;
  line-height: 23rpx;
  box-sizing: border-box;
  border-radius: 23px;
  border: 1px solid transparent;
  font-size: 12px;
}
</style>
