<template>
  <div class="content">
    <el-descriptions :column="4" border  >
      <el-descriptions-item label="商品图片"  >
          <span v-if="product!=null">
            <el-popover
            placement="right"
            title=""
            trigger="hover"
          >
            <img slot="reference" :src="product.image" width="100">
            <img :src="product.image" style="max-width: 150px;">
          </el-popover>
          </span>
      </el-descriptions-item>
      <el-descriptions-item label="商品名称"  >
          <span v-if="product!=null">
            {{product.productName}}
          </span>
      </el-descriptions-item>
      <el-descriptions-item label="售价"  >
          <span v-if="product!=null">
            {{product.price}}
          </span>
      </el-descriptions-item>
      <el-descriptions-item label="原价"  >
          <span v-if="product!=null">
            {{product.otPrice}}
          </span>
      </el-descriptions-item>
      <el-descriptions-item label="销量"  >
          <span v-if="product!=null">
            {{product.sales}}
          </span>
      </el-descriptions-item>
      <el-descriptions-item label="库存"  >
          <span v-if="product!=null">
            {{product.stock}}
          </span>
      </el-descriptions-item>
      <el-descriptions-item label="类型"  >
          <span v-if="product!=null">
            <el-tag prop="productType" v-for="(item, index) in productTypeOptions"    v-if="product.productType==item.dictValue">{{item.dictLabel}}</el-tag>
          </span>
      </el-descriptions-item>
      <el-descriptions-item label="状态"  >
          <span v-if="product!=null">
            <el-tag prop="productType" v-for="(item, index) in isShowOptions"    v-if="product.isShow==item.dictValue">{{item.dictLabel}}</el-tag>
          </span>
      </el-descriptions-item>
    </el-descriptions>
    <div style="margin: 20px 0px"  v-if="items!=null">
        <span class="font-small">
          规格列表
        </span>
    </div>
    <el-table
      border
      v-if="items!=null"
      :data="items"
      size="small"
      style="width: 100%;margin-top: 20px" >
      <el-table-column label="ID"  align="center">
        <template slot-scope="scope">
          <p>{{scope.row.id}}</p>
        </template>
      </el-table-column>
      <el-table-column label="商品图片"   align="center">
          <template slot-scope="scope">
            <img :src="scope.row.image" style="height: 80px">
          </template>
        </el-table-column>
      <el-table-column label="规格"   align="center">
        <template slot-scope="scope">
          <p>{{scope.row.sku}}</p>
        </template>
      </el-table-column>
      <el-table-column label="售价"   align="center">
        <template slot-scope="scope">
          <p>￥{{scope.row.price.toFixed(2)}}</p>
        </template>
      </el-table-column>
      <el-table-column label="原价"   align="center">
        <template slot-scope="scope">
          <p>￥{{scope.row.otPrice.toFixed(2)}}</p>
        </template>
      </el-table-column>
      <el-table-column label="商品编码"   align="center">
        <template slot-scope="scope">
          {{scope.row.barCode}}
        </template>
      </el-table-column>
      <el-table-column label="库存"  align="center">
        <template slot-scope="scope">
          {{scope.row.stock}}
        </template>
      </el-table-column>
      <el-table-column label="销量" width="180" align="center">
        <template slot-scope="scope">
          {{scope.row.sales}}
        </template>
      </el-table-column>
    </el-table>
    <div v-html="product.description"></div>
  </div>
</template>

<script>
import {  getStoreProduct  } from "@/api/store/storeProduct";

export default {
  name: "product",
  data() {
    return {
      product:null,
      isShowOptions:[],
      productTypeOptions:[],
      items:[],
    };
  },
  created() {
    this.getDicts("store_product_type").then((response) => {
      this.productTypeOptions = response.data;
    });
    this.getDicts("store_product_is_show").then((response) => {
      this.isShowOptions = response.data;
    });
  },
  methods: {
    getStoreProduct(productId) {
      getStoreProduct(productId).then(response => {
        this.product = response.product;
        this.items=response.values
      });
    },
  }
};
</script>
<style scoped>
.content{
  margin: 10px;
}
 
</style>
