<template>
  <view class="service">
    <view class="recommend">
      <view
        class="recommend-item"
        @click="onrecommend(index, item.value, '')"
        :class="{ red: activeIndex == index }"
        v-for="(item, index) in choice"
        :key="index"
      >
        {{ item.name }}
      </view>

      <view
        class="recommend-item"
        @click="onrecommend(index + 3, '', item.id)"
        :class="{ red: activeIndex == index + 3 }"
        v-for="(item, index) in cate"
        :key="index + 3"
      >
        {{ item.name }}
      </view>
    </view>

    <view class="content" v-if="good && good.length > 0">
      <view class="content-item" v-for="item in good" :key="item.id"  @click="
            goProductDetails(item.id)
          "> 
        <image :src="item.cover" mode="" class="neironga2"></image>
        <view class="name"> {{ item.title }} </view>
        <view class="number">
          <view class="large">
            <rich-text
              :nodes="$mUtil.priceBigSmall(item.sale_price)"
            ></rich-text>
          </view>

          <view class="small">￥{{ item.market_price }}</view>
        </view>
        <view class="sell"> 已售{{ item.result_sale_num }}件 </view>
      </view>
    </view>
    <nodata v-else :config="{ top: 1, content: '暂无商品~' }"></nodata>
  </view>
</template>

<script>
export default {
  data() {
    return {
      choice: [
        {
          id: 1,
          name: "推荐",
          value: "recommend",
        },
        {
          id: 2,
          name: "热销",
          value: "hot",
        },
        {
          id: 3,
          name: "新品",
          value: "new",
        },
      ],
      activeIndex: -1,
    };
  },
  props: {
    cate: {
      type: Array,
      default: [],
    },
    good: {
      type: Array,
      default: [],
    },
   isActive:{
	   type:Number,
	   default:0
   }
  },
  watch: {
	  cate(e){
  this.activeIndex =-1;
	  },
   
  },
  onLoad() {
    this.activeIndex = this.initNum;
  },
  methods: {
	  goProductDetails(id){
		  uni.navigateTo({
        url: this.isActive==0?'/pages/product/goods/serviceGood?id='+id:'/pages/product/goods/goods?id='+id,
      });
 
	  },
    onrecommend(index, type, groupId) {
      this.activeIndex = index;
      this.$emit("typeChange", { type: type, groupId: groupId });
    },
  },
};
</script>

<style scoped lang="scss">
.content {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 30rpx;
  background-color: #f5f5f5;
  .content-item {
    background-color: #ffffff;
    border-radius: 18rpx;
    overflow: hidden;
    margin-bottom: 30rpx;
    image {
      width: 336rpx;
      height: 336rpx;
      background-color: red;
    }
    .number {
      display: flex;
      align-items: center;
      padding: 0 30rpx;
      .large {
        color: #ed3d07;
        font-size: 20rpx;
        font-weight: Medium;
        text {
          font-size: 36rpx;
          font-weight: Bold;
        }
      }
      .small {
        font-size: 22rpx;
        color: #999999;
        font-weight: 400;
        text-decoration: line-through;
        margin-left: 16rpx;
      }
    }
    .sell {
      padding: 0 30rpx;
      font-size: 22rpx;
      font-weight: 400;
      color: #999999;
      margin-bottom: 36rpx;
      margin-top: 8rpx;
    }
    .name {
      width: 276rpx;
      padding: 0 30rpx;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      word-wrap: break-word;
      word-break: break-all;
      white-space: normal !important;
    }
  }
}
.recommend {
  display: flex;
  background-color: #f5f5f5;
  border-radius: 40rpx 40rpx 0 0;
  .recommend-item {
    font-weight: 500;
    padding: 15rpx 30rpx;
    background-color: #ffffff;
    margin: 40rpx 0 30rpx 30rpx;
    border-radius: 34rpx;
  }
  .red {
    background: #00321e;
    color: #d5c49b;
  }
}
</style>
