goodsDetailCom.vue 7.33 KB
<template>
  <!-- <div>商品详情</div> -->
  <GLDialog destroy-on-close="true" :visible.sync="dialogShow" :hasFooter="false" mode="big" bigTitle="产品详情" :close-on-click-modal="false" @onOk="handleSubmit" @onCancel="handleDetailClose">
    <div class="detail-content">
      <!-- 商品详情 -->
      <div class="goodsInfoCom">
        <div class="goodsInfoCom__left">
          <img :src="goodsInfo.thumbUrl" alt="" />
        </div>
        <div class="goodsInfoCom__right">
          <p class="title two-line-ellipsis">{{ goodsInfo.goodsName }}</p>
          <div class="priceCon">
            <span class="price">
              价格:
              <span class="priceNum">¥{{ handleItemInfo.purchasePrice }}</span>
            </span>
            <span class="turnover">
              成交量:
              <span class="num">{{ goodsInfo.purchaseOrderCount || 0 }}笔</span>
            </span>
          </div>
          <div class="skuCon">
            <div class="label">规格:</div>
            <div class="itemCon">
              <div
                class="skuItem one-line-ellipsis pointer"
                :class="{ active: index === selectIndex }"
                v-for="(item, index) in goodsInfo.upgradeGoodsList"
                :key="index"
                @click="
                  selectIndex = index
                  setHandleItemInfo(item)
                "
              >
                {{ item.upgradeGoodsName }}
              </div>
            </div>
          </div>
          <div class="munCom">
            <div class="label">数量:</div>
            <div class="munItem">
              <el-input-number v-model="handleItemInfo.goodsNumber" :min="1" :max="9999"></el-input-number>
            </div>
            <div class="tips">
              <!-- goodsItem.goodsType == 1  -->
              {{ membraneTypeList.includes(goodsInfo.goodsType) ? `卷(1卷=${goodsInfo.convertedValue || 30}米)` : '件' }}
            </div>
          </div>
          <el-button class="carBtn" icon="carIcon" type="primary" @click="updateCarShopping">加入购物车</el-button>
        </div>
        <!-- <i class="carIcon"></i> -->
      </div>
      <h3 style="margin-top:20px;">产品详情</h3>
      <div class="goodsDescList">
        <div class="goodsDescItem" v-for="(item, index) in goodsInfo.goodsDescList" :key="index">
          <img :src="item.content" v-if="item.resType == 1" class="productDetailsImg" alt="" />
          <!-- <div class="goodsDescItem__title">{{ item.title }}</div> -->
          <div v-if="item.resType == 2" class="goodsDescItem__content" v-html="item.content"></div>
        </div>
      </div>
    </div>
  </GLDialog>
</template>

<script>
import { membraneTypeList } from '@/utils/constants.js'
export default {
  name: 'GoodsDetailCom',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    selectItemInfo: {
      type: Object,
      default: () => {}
    },
    goodsId: {
      type: [String, Number]
      // required: true
      // default: '24'
    }
  },

  data() {
    return {
      // dialogShow: false,
      membraneTypeList,
      goodsInfo: {},
      selectIndex: 0,
      handleItemInfo: {
        goodsNumber: 1,
        upgradeGoodsId: '',
        purchasePrice: 0
      }
    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
    // selectItemInfo(){
    //   // this.goodsInfo[]
    //   if (this.goodsInfo.upgradeGoodsList.length) {
    //     let item = this.goodsInfo.upgradeGoodsList[this.selectIndex]
    //     return {
    //       goodsNumber: this.goodsInfo.num,
    //       upgradeGoodsId: item.id
    //     }
    //   }
    //   // return this.selectItemInfo
    // }
  },
  watch: {
    visible(val) {
      if (val) {
        this.handleItemInfo.goodsNumber = 1
        this.getGoodsDetail()
      }
    }
  },
  methods: {
    getGoodsDetail() {
      this.$apis.product.getProductInfo({ id: this.goodsId }).then(res => {
        this.goodsInfo = res
        // 调试用
        // for (let index = 0; index < 12; index++) {
        //   this.goodsInfo.upgradeGoodsList[index] = this.goodsInfo.upgradeGoodsList[0]
        // }
        // 默认选中第一个
        const item = this.goodsInfo.upgradeGoodsList[0]
        // console.log(item)
        item && this.setHandleItemInfo(item)
      })
    },
    setHandleItemInfo(item) {
      console.log(item)
      const { id, purchasePrice } = item
      this.handleItemInfo = Object.assign(this.handleItemInfo, {
        upgradeGoodsId: id,
        purchasePrice
      })
    },
    handleDetailClose() {
      this.dialogShow = false
    },
    updateCarShopping() {
      const params = {
        goodsNumber: this.handleItemInfo.goodsNumber,
        upgradeGoodsId: this.handleItemInfo.upgradeGoodsId
      }
      // 判断是否有值
      params.upgradeGoodsId &&
        this.$apis.purchaseShopping.shoppingCarAdd(params).then(res => {
          // console.log(res)
          this.$message.success('加入购物车成功')
          this.$EventBus.$emit('updateCarShopping')
          this.dialogShow = false
        })
      // this.$message.success('加入购物车成功')
      // this.$EventBus.$emit('updateCarShopping')
    }
  }
}
</script>

<style lang="scss" scoped>
.goodsInfoCom {
  display: flex;

  .goodsInfoCom__left {
    width: 400px;
    height: 400px;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .goodsInfoCom__right {
    flex: 1;
    margin-left: 20px;

    .title {
      margin: 0;
      font-weight: 600;
      font-size: 20px;
      color: #333333;
    }

    .priceCon {
      box-sizing: border-box;
      width: 100%;
      height: 65px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 10px;
      margin: 16px 0 20px;
      background: #f2f5fb;
      border-radius: 2px;
      color: #666666;

      .price {
        display: flex;
        align-items: center;
        margin-left: 8px;
      }

      .num {
        margin-left: 8px;
      }

      .priceNum {
        font-weight: 600;
        font-size: 30px;
        color: #ee3040;
        margin-left: 8px;
      }
    }

    .skuCon {
      display: flex;

      // flex-wrap: wrap;
      // align-items: center;
      .itemCon {
        flex: 1;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
      }

      .skuItem {
        box-sizing: border-box;
        width: 234px;
        height: 36px;
        background: #ffffff;
        border: 1px solid #e7edf9;
        border-radius: 2px;
        color: #333333;
        text-align: center;
        line-height: 36px;
        padding: 0 10px;
        margin-bottom: 16px;

        &.active {
          border: 1px solid #5850ff;
        }
      }
    }

    .label {
      box-sizing: border-box;
      width: 60px;
      height: 36px;
      text-align: center;
      padding-left: 18px;
      line-height: 36px;
      color: #666666;
    }
  }
}

.productDetailsImg {
  max-width: fit-content;
}

.munCom {
  display: flex;
  margin-bottom: 20px;

  .tips {
    height: 36px;
    line-height: 36px;
    margin-left: 8px;
    font-size: 12px;
    color: #666666;
  }
}

.carBtn {
  display: flex;
  align-items: center;
  width: 168px;
  height: 40px;
  margin-left: 18px;
  background: #5850ff;
  border-radius: 4px;
}
</style>