<template>
  <!-- 整点秒杀 -->
  <view v-if="data.goodsList.data && data.goodsList.data.length" class="diy-sharp" :style="{ background: itemStyle.background }">
    <!-- 秒杀会场信息 -->
    <view class="sharp-top" @click="handleNavMore()">
      <view class="sharp-top--left">
        <view class="sharp-modular">
          <text class="iconfont icon-miaosha-b"></text>
          <text class="modular-name">限时秒杀</text>
        </view>
        <view class="sharp-active-status">
          <text>{{ data.active.sharp_modular_text }}</text>
        </view>
        <!-- 倒计时 -->
        <view v-if="data.active.status == GoodsStatusEnum.STATE_BEGIN.value" class="active-count-down">
          <count-down :date="data.active.count_down_time" separator="colon" theme="custom" />
        </view>
      </view>
      <view class="sharp-top--right">
        <view class="sharp-more">
          <text class="sharp-more-text">更多</text>
          <text class="sharp-more-arrow iconfont icon-arrow-right"></text>
        </view>
      </view>
    </view>
    <!-- 商品列表 -->
    <view class="goods-list display__list clearfix" :class="[`column__${itemStyle.column}`]">
      <view class="goods-item" v-for="(goods, idx) in data.goodsList.data" :key="idx"
        @click="handleNavDetail(goods.sharp_goods_id)">
        <!-- 单列商品 -->
        <block v-if="itemStyle.column == 1">
        </block>
        <!-- 两列三列 -->
        <block v-else>
          <!-- 商品图片 -->
          <view class="goods-image">
            <image class="image" mode="aspectFill" :src="goods.goods_image"></image>
          </view>
          <view class="detail">
            <!-- 商品标题 -->
            <view v-if="inArray('goodsName', itemStyle.show)" class="goods-name">
              <text class="twoline-hide"> {{ goods.goods_name }}</text>
            </view>
            <!-- 商品价格 -->
            <view class="detail-price">
              <text v-if="inArray('seckillPrice', itemStyle.show)" class="goods-price c-red">
                <text class="small-unit">¥</text>
                <text>{{ goods.seckill_price_min }}</text>
              </text>
              <text v-if="inArray('originalPrice', itemStyle.show) && goods.original_price > 0"
                class="line-price">￥{{ goods.original_price }}</text>
            </view>
          </view>
        </block>
      </view>
    </view>
  </view>
</template>

<script>
  import { inArray } from '@/utils/util'
  import CountDown from '@/components/countdown'
  import { ActiveStatusEnum, GoodsStatusEnum } from '@/common/enum/sharp'
  import mixin from '../mixin'

  export default {
    components: {
      CountDown
    },

    /**
     * 组件的属性列表
     * 用于组件自定义设置
     */
    props: {
      itemIndex: String,
      itemStyle: Object,
      params: Object,
      data: Object
    },

    data() {
      return {
        // 枚举类
        ActiveStatusEnum,
        GoodsStatusEnum,
        // 公共函数
        inArray
      }
    },

    mixins: [mixin],

    /**
     * 组件的方法列表
     * 更新属性和数据的方法与更新页面数据的方法类似
     */
    methods: {

      // 跳转到秒杀会场页
      handleNavMore() {
        this.$navTo('pages/sharp/index')
      },

      // 跳转到秒杀商品详情页
      handleNavDetail(sharpGoodsId) {
        const { data } = this
        this.$navTo('pages/sharp/goods/index', {
          activeTimeId: data.active.active_time_id,
          sharpGoodsId
        })
      }

    }

  }
</script>

<style lang="scss" scoped>
  // diy-秒杀商品组
  .diy-sharp {

    .sharp-top {
      display: flex;
      align-items: center;

      .sharp-top--left {
        flex: 1;
        display: flex;
        align-items: center;
      }

      .sharp-modular {
        font-size: 28rpx;
        color: #fff;
        background: #FB571D;
        padding: 10rpx 30rpx 10rpx 24rpx;
        border-bottom-right-radius: 30rpx;
        border-top-right-radius: 30rpx;

        .modular-name {
          margin-left: 10rpx;
        }
      }

      .sharp-active-status {
        color: #616161;
        font-size: 28rpx;
        margin-left: 20rpx;
        margin-right: 16rpx;
      }

      // 更多
      .sharp-more {
        display: flex;
        align-items: center;
        padding-right: 24rpx;
        color: #616161;
        font-size: 26rpx;

        .sharp-more-arrow {
          font-size: 24rpx;
        }
      }
    }

    // 商品列表
    .goods-list {
      padding: 4rpx;

      &.display__list {
        .goods-item {
          float: left;
        }
      }

      &.column__2 {
        .goods-item {
          width: 50%;
        }
      }

      &.column__3 {
        .goods-item {
          width: 33.33333%;
        }
      }

      .goods-item {
        padding: 6rpx;

        .goods-image {
          position: relative;
          width: 100%;
          height: 0;
          padding-bottom: 100%;
          overflow: hidden;
          background: #fff;

          &:after {
            content: '';
            display: block;
            margin-top: 100%;
          }

          .image {
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            object-fit: cover;
          }
        }

        .detail {
          padding: 4rpx;
          background: #fff;

          .goods-name {
            font-size: 26rpx;
            min-height: 68rpx;
            line-height: 1.3;
            overflow: hidden;
          }

          .detail-price {
            line-height: 40rpx;

            .goods-price {
              color: red;
              font-size: 30rpx;
              margin-right: 8rpx;
            }

            .line-price {
              font-size: 24rpx;
              text-decoration: line-through;
              color: #999;
            }
          }

          .small-unit {
            font-size: 26rpx;
            margin-right: 4rpx;
          }
        }
      }
    }
  }
</style>
