goodsDetailCom.vue 8.57 KB
<template>
  <!-- <div>商品详情</div> -->
  <baseDialog :is-show.sync="dialogShow" :config="dialogConfig.setting" :dialog-config="dialogConfig.config"
              @closeDialog="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>
      <div class="table" v-if=" tableInfo.length ">
        <h3>适用门店</h3>
        <d2-table :has-num=" false " :has-page=" false " :table-params=" tableParams " :table-data=" tableInfo ">
        </d2-table>
      </div>
      <h3>产品详情</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>
  </baseDialog>
</template>

<script>
// import  from ''
import { getProductInfo } from '@/api/product'
import { shoppingCarAdd } from '@/api/purchaseShopping'
import { baseConfig } from '@/main'
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: baseConfig.membraneTypeList,
      dialogConfig: {
        setting: {
          showClose: true,
          appendToBody: false,
          // width: '720px',
          btnList: [
          ]
        },
        config: {
          title: '产品详情',
          width: '1008px'
        }

      },
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',

        tableColumns: [{
          label: '商户名称',
          prop: 'merchantName'
        }, {
          label: '商户号',
          prop: 'merchantId'
        }, {
          label: '商品别名',
          prop: 'goodsAlias'
        }]
      },
      tableInfo: [],
      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.getGoodsDetail()
      }
    }
  },
  methods: {
    getGoodsDetail() {
      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
      })
      console.log(item)
      this.tableInfo = item.merchantGoodsInfo.filter(item => item.goodsAlias)
    },
    handleDetailClose() {

    },
    updateCarShopping() {
      const params = {
        goodsNumber: this.handleItemInfo.goodsNumber,
        upgradeGoodsId: this.handleItemInfo.upgradeGoodsId
      }
      // 判断是否有值
      params.upgradeGoodsId && 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;
      }
    }

    .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 #185efe;
        }
      }
    }

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

.productDetailsImg {
  // width: 100%;
  // height: 338px;
  max-width: fit-content;
  // min-width: fit-content;
}

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

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

.carBtn {
  // color: #ffffff;
  // background-color: #185efe;
  display: flex;
  align-items: center;
}
</style>
<style>
.carIcon {
  display: inline-block;
  width: 22px;
  height: 22px;
  background: url(../images/shoppingCarIcon.webp) no-repeat;
  background-size: 100% 100%;
  margin-right: 4px;
}
</style>