<template>
  <view class="catstyle3" 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>

    <view style="height: calc(100% - 45px);background: #f5f5f5;">
      <scroll-view
        :scroll-y="true"
        @scrolltolower="lower"
        :enable-back-to-top="true"
        :enable-flex="true"
        style="
          height: 100%;
          padding: 10px;
          padding-bottom: 0px;
        "
      >
        <u-row gutter="20">
          <u-col span="6" v-for="(cx, ci) in g" :key="ci">
            <view class="good" @click="clickHandler(cx)">
              <view class="good-img" style="position: relative;">
				<image mode="aspectFit" :src="cx.cover_pic" style="width: 100%; height: 100%" >
					  <image src="../../static/images/icon/plugins-out.png" v-if="cx.totalStock==0"
					  style="width: 100%; height: 100%;position: absolute;left:0;top:0;background: #000;opacity: 0.6;" />
				</image>
              </view>
              <view class="good-name">
				<view
				  v-if="cx.marketingLogo.iswords && cx.marketingLogo.iswords==1&& cx.marketingLogo.words!=''"
				  class="Logo"
				  :style="{color: cx.marketingLogo.wordsColor,
							background:cx.marketingLogo.wordsBack ,}"
				>{{cx.marketingLogo.words}}</view>
				<image
				  v-if="cx.marketingLogo.iswords&&cx.marketingLogo.iswords==2&& cx.marketingLogo.ico!=''"
				  mode="heightFix"
				  :src="cx.marketingLogo.ico"
				  style=" height: 12px;margin-right: 5px"
				/>
				
				<view
				  style="color: #FF4048;background: #fdf6ec;padding: 0 5px;display: inline-block;height: 32rpx;font-size: 20rpx;margin-right: 5rpx;"
				  v-if="cx.freeShippingFullMoneyPinkage>0 || cx.freeShippingFullNumPinkage>0"
				>
				  {{cx.freeShippingFullMoneyPinkage>0 && cx.freeShippingFullNumPinkage==0?cx.freeShippingFullMoneyPinkage+'元包邮':''}}
				  {{cx.freeShippingFullMoneyPinkage==0 && cx.freeShippingFullNumPinkage>0?cx.freeShippingFullNumPinkage+'件包邮':''}}
				</view>
			  {{ cx.name }}</view>
              <view class="good-info">
                <view class="price" :style="{ color: mainColor }">{{
                  cx.price_content
                }}</view>
                <view class="sell">{{ cx.sales }}</view>
              </view>
            </view>
          </u-col>
        </u-row>
        <u-divider v-if="isover" bg-color="#F5f5f5"  :margin-top="20" :margin-bottom="20">没有更多商品了</u-divider>&nbsp;
      </scroll-view>
    </view>
  </view>
</template>

<script>
export default {
  props: ["d", "h"],
  data() {
    return {
      mainColor: "",
      msg:{
		  pageIndex: 1,
		  pageSize:14,
		  Name:'',
		  GoodsType:0,
		  CategoryIds:'',
		  OrderBy:1,
		  UserId:0,
	  },
      page_count: 1,
      mh: 0,
      g: [],
      isover: false,
      loading: false,
      tid: 0,
      active: 0,
    };
  },
  created() {
    this.mainColor = this.$uiConfig.mainColor;
  },
  mounted() {
    this.init();
  },
  methods: {
    changeHandler(i) {
      this.msg.CategoryIds= this.d[i].Id+'';
      this.msg.page = 1;
	  this.tid = i;
      this.g = [];
      this.init();
      this.active=i
    },
    clickHandler(item) {
      uni.navigateTo({ url: '/pages/goods/goods?GoodsId='+item.id });
    },
    init() {
      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){
				res.data.pageData.forEach(x=>{
					x.marketingLogo  = JSON.parse(x.marketingLogo)
					x.totalStock = 0;
					x.attr.forEach(j=>{
						x.totalStock+=j.stock
					})
				})
	  			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].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>
.catstyle3 .tabsbox {
  padding: 10px;
}
.catstyle3 .good {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
.catstyle3 .good .good-img {
  width: calc(50vw - 15px);
  height: calc(50vw - 15px);
  display: block;
}
.catstyle3 .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;
}
.catstyle3 .good .good-info {
  display: flex;
  margin: 7px 10px;
  margin-top: 0;
  align-items: center;
  padding-bottom: 5px;
}
.catstyle3 .good .good-info .price {
  font-size: 16px;
  color: #ff4544;
  flex: 1;
}
.catstyle3 .good .good-info .sell {
  font-size: 12px;
  color: gray;
  flex: 1;
  text-align: right;
}
.catstyle3 .Logo {
  padding: 1px 5px;
  display: inline-block;
  font-size: 22rpx;
  margin-right: 5rpx;
  border-radius: 4px;
}
</style>
