<template>
  <view class="container">
    <!-- 基础信息 -->
    <view class="basic_info">
      <!-- 轮播图 -->
      <swiper
        class="swiperImage"
        :indicator-dots="true"
        :autoplay="true"
        :interval="4000"
        :duration="500"
      >
        <swiper-item
          v-for="(item, index) in carousel"
          :key="index"
        >
          <image
            :src="item"
            mode="scaleToFill"
          ></image>
        </swiper-item>
      </swiper>
      <!-- 产品价格及购买人数 -->
      <view class="info_pay">
        <view>￥{{goodsInfo.price || '暂无'}}<span
            v-if="goodsInfo.discountPrice"
            class="info_pay_discount"
          >¥{{goodsInfo.discountPrice}}</span></view>
        <span class="info_pay_number">{{goodsInfo.tradeNumber || '暂无'}}人购买过</span>
      </view>
      <!-- 产品名称 -->
      <view class="info_name">
        <text class="info_name_name">{{goodsInfo.name || '暂无'}}</text>
        <view class="info_name_share">
          <image src="/static/img/detail/share-icon.png"></image>
          <text>分享</text>
        </view>
      </view>
      <!-- 产品售后信息 -->
      <view class="info_after">
        <span>支持7天无理由退货</span>
        <span>顺丰发货</span>
        <span>30天质量保证</span>
      </view>
    </view>
    <!-- 详细信息 -->
    <view class="detail_info">
      <!-- 详细信息菜单 -->
      <view class="screen_bar">
        <view
          v-for="(item, index) in screenItems"
          :key="index"
          @click="tabChange(index)"
        >
          <view
            class="screen_item"
            v-bind:class="{ item_active: item_current === index }"
          >{{ screenItems[index] || '暂无' }}</view>
        </view>
      </view>
      <!-- 商品介绍 -->
      <view
        class="screen_item"
        v-if="item_current === 0"
      >
        <Introduce :tag="tag" />
      </view>
      <!-- 规格参数 -->
      <view
        class="screen_item"
        v-if="item_current === 1"
      >
        <view class="specification">
          <view
            class="spe_item"
            v-for="(item, index) in specification"
            :key="index"
          >
            <image
              class="spe_image"
              v-bind:src="item.img"
            ></image>
            <span>{{item.standard || '暂无'}}</span>
            <span>{{item.slength || '暂无'}}</span>
          </view>
        </view>
      </view>
      <!-- 售后保障 -->
      <view
        class="screen_item"
        v-if="item_current === 2"
      >
        <AfterSails />
      </view>
    </view>
    <!-- 评价 -->
    <template v-if="item_current !== 2">
      <view class="evaluate">
        <!-- 标题 -->
        <view class="evaluate_title">
          <view><span>宝贝好评率</span><span class="title_rate">{{evaluate.rate}}</span></view>
          <!-- 星星 -->
          <view class="evaluate_star">
            <view
              class="star"
              v-for="(item, index) in evaluate.star"
              :key="index"
            >
              <image
                src="../../static/img/detail/d_star.png"
                mode="aspectFill"
                style="height: 26rpx; width: 28rpx;"
              ></image>
            </view>
          </view>
        </view>
        <!-- 标签 -->
        <view class="evaluate_tag">
          <view
            v-for="(item, index) in evaluate.tag"
            :key="index"
          >{{item.name}}</view>
        </view>
      </view>
    </template>
    <!-- 商品详情页 -->
    <template v-if="current !==2">
      <view class="more_info">
        <view
          class="more_fixed1"
          @click="consolg(goodInfo.prodIntro1)"
        >
          <image src="/static/img/detail/hr.png"></image>
          <view>商品详情</view>
          <image src="/static/img/detail/hr.png"></image>
        </view>
        <view
          class="more_all"
          v-html="more"
        >
        </view>
      </view>
    </template>
    <!-- 底部菜单 -->
    <view class="menu">
      <view
        @tap="toCart()"
        class="menu_1"
      >
        <view class="cart_icon">
          <image src="/static/tab-cart.png" />
          <text>{{cartNumber}}</text>
        </view>
        <view class="menu_image">购物车</view>
      </view>
      <view class="menu_2">
        <view
          class="menu_input"
          @tap="showBottom(1)"
        >加入购物车</view>
        <view
          class="menu_now"
          @click="showBottom(2)"
        >立即购买</view>
      </view>
    </view>
  </view>
</template>

<script>
import store from '@/store'
import Introduce from './components/Introduce' // 商品介绍基本信息
import AfterSails from './components/AfterSails' // 售后保障组件
// import BottomSheet from '@/components/BottomSheet.vue'

export default {
  components: {
    Introduce,
    AfterSails,
  },
  data () {
    return {
      pid: 7, // 产品ID
      skId: undefined, // skuId
      // 详细信息菜单
      item_current: 0,
      screenItems: [
        '商品介绍',
        '规格参数',
        '售后保障',
      ],
    }
  },
  onLoad({ pid = this.pid, sk_id: skId }) {
    // 根据页面传参请求页面数据
    this.pid = pid
    this.skId = skId

    // 获取产品详情
    this.getDetails({ pid, skId })
    // 获取购物车数据
    this.getCartNum()
  },
  computed: {
    // 获取轮播图数据
    carousel() {
      return this.$store.state.details.carousel
    },
    // 商品基本信息
    goodsInfo() {
      return this.$store.state.details.goodsInfo
    },
    // 商品介绍商品标签
    tag() {
      return this.$store.state.details.tag
    },
    // 规格参数
    specification() {
      return this.$store.state.details.specification
    },
    // 评价
    evaluate() {
      return this.$store.state.details.evaluate
    },
    // 商品详情
    more() {
      return this.$store.state.details.more
    },
    // 购物车数目
    cartNumber() {
      return this.$store.state.details.cartNumber
    },
  },
  methods: {
    // 获取产品详情
    getDetails({ pid, skId }) {
      store.dispatch('details/details', {
        pid,
        sk_id: skId,
      })
    },
    // 获取购物车数目
    getCartNum() {
      store.dispatch('details/getCartNumber')
    },
    // 切换详细信息菜单
    tabChange (e) {
      if (this.current !== e) {
        this.item_current = e
      }
    },
  },
}
</script>

<style lang="scss">
.container {
  background-color: #f8f8f8;
  font-family: "PingFangSC-Regular";
  // 板块样式
  > view {
    background: #ffffff;
    margin-bottom: 10px;
    padding: 8px 20px 8px 20px;
    box-sizing: border-box;
  }
  // 基础信息板块
  .basic_info {
    // 轮播图
    .swiperImage {
      width: 684rpx;
      height: 480rpx;
      image {
        max-width: 100%;
        max-height: 100%;
        border-radius: 16rpx;
      }
    }
    // 产品价格及购买人数
    .info_pay {
      color: #eb5d3b;
      font-size: 18px;
      margin-top: 5px;
      font-family: "PingFangSC-Semibold";
      display: flex;
      justify-content: space-between;
      .info_pay_discount {
        text-decoration: line-through;
        margin-left: 8rpx;
        color: #999;
        font-size: 14px;
      }
      .info_pay_number {
        color: #999;
        font-size: 14px;
      }
    }
    // 产品名称
    .info_name {
      margin-top: 5px;
      display: flex;
      justify-content: space-between;
      .info_name_name {
        margin-right: 10px;
        font-size: 16px;
        font-family: "PingFangSC-Semibold";
        max-width: 592rpx;
      }
      .info_name_share {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        margin-top: 14rpx;
        > image {
          height: 40rpx;
          width: 40rpx;
        }
        > text {
          font-family: PingFangSC-Regular;
          font-size: 12px;
          color: #999;
          letter-spacing: -0.23px;
        }
      }
    }
    // 售后服务
    .info_after {
      font-size: 10px;
      color: #999;
      margin-top: 20rpx;
      > span {
        height: 14px;
        margin-right: 10px;
      }
    }
  }
  // 详细信息
  .detail_info {
    margin-bottom: 20rpx;
    .screen_bar {
      width: 670rpx;
      margin-top: 20rpx;
      margin-bottom: 24rpx;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      font-size: 14px;
      color: #333333;
      transition: all 0.2s;
    }
    .item_active {
      border-bottom: 4rpx solid #ff6b4a;
    }
    .screen_item {
      font-size: 32rpx;
      color: #333333;
      display: flex;
      transition: all 0.2s;
      // 规格参数
      .specification {
        margin-bottom: 4px;
        .spe_item {
          image {
            width: 50px;
            height: 25px;
            margin-right: 6px;
            vertical-align: middle;
          }
          span {
            margin-left: 24rpx;
          }
        }
      }
    }
    //
  }
  // 宝贝好评率
  .evaluate {
    .evaluate_title {
      font-size: 14px;
      color: #333333;
      display: flex;
      justify-content: space-between;
      .title_rate {
        margin-left: 10rpx;
      }
      .evaluate_star {
        width: 90px;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      view {
        font-size: 14px;
        color: #333333;
        font-weight: bold;
      }
    }
    .evaluate_tag {
      view {
        display: inline-block;
        margin-right: 20rpx;
        min-width: 180rpx;
        margin-top: 10px;
        height: 48rpx;
        background: #f2f2f2;
        border-radius: 2px;
        font-family: PingFangSC-Regular;
        font-size: 12px;
        color: #666666;
        letter-spacing: -0.23px;
        text-align: center;
        padding: 0 48rpx;
        line-height: 48rpx;
      }
    }
  }
  // 商品详情
  .more_info {
    .more_fixed1 {
      display: flex;
      justify-content: space-between;
      align-content: center;
      margin-bottom: 12px;
      view {
        font-size: 14px;
        color: #333333;
        font-weight: bold;
        font-family: "PingFangSC-Medium";
        line-height: 24px;
      }
      image {
        width: 240rpx;
        height: 3px;
        margin-top: 10px;
      }
    }
    .more_all {
      width: 100%;
      margin-top: 30rpx;
      margin-right: 30rpx;
      margin-bottom: 180rpx;
      font-family: "PingFangSC-Regular";
    }
  }
  // 菜单
  .menu {
    position: fixed;
    bottom: 0;
    height: 74px;
    width: 100%;
    background: #ffffff;
    padding: 20px 20px 8px 20px;
    font-family: "PingFangSC-Regular";
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-content: center;
    margin: 0;
    .menu_1 {
      width: 20%;
      height: 100%;
      text-align: center;
      color: #989898;
      .cart_icon {
        position: relative;
        text {
          position: absolute;
          color: white;
          font-size: 17px;
          background-color: red;
          min-height: 24px;
          min-width: 24px;
          line-height: 24px;
          right: -12%;
          top: -12px;
          text-align: center;
          border-radius: 24px;
          padding: 2px;
        }
      }
    }
    image {
      width: 42%;
      height: 26px;
    }
    .menu_image {
      font-size: 12px;
      text-align: center;
    }
    .menu_2 {
      width: 74%;
      height: 86%;
      display: grid;
      grid-template-columns: 50% 50%;
    }
    .menu_input {
      display: inline-flex;
      align-items: center;
      justify-content: space-around;
      background: #fff0ec;
      font-size: 16px;
      color: #ff6b4a;
      border-radius: 20px 0 0 20px;
    }
    .menu_now {
      display: inline-flex;
      align-items: center;
      justify-content: space-around;
      background: #ff6b4a;
      font-size: 16px;
      color: #ffffff;
      border-radius: 0 20px 20px 0;
    }
  }
}
</style>
