takeGoodDetail.vue 9.47 KB
<!-- 带货详情 -->
<!-- 商品编辑 - 带货 -->
<template>
  <div class="edit-product-dh marketing edit-box">
    <div class="container edit-container">
      <p class="edit-title">{{ title }}</p>
      <div class="flex" style="margin-top: 20px;">
        <div class="main-img-box">
          <el-carousel height="375px">
            <el-carousel-item v-for="item in editForm.goodsDetailImageList" :key="item">
              <video v-if="item.resType == 3" class="inner-img" :src="item.content"></video>
              <img class="inner-img" :src="item.content" />
            </el-carousel-item>
          </el-carousel>
        </div>
        <div style="width: calc(100% - 375px);">
          <p class="pro-name txt-ellipsis">{{ editForm.goodsName }}</p>
          <p v-show="!specificationDetailList.length" class="txt-ellipsis">
            供货价:
            <span class="supply-price">{{ editForm.retailPrice }}元</span>
          </p>
        </div>
      </div>
      <div v-if="specificationDetailList.length" style="margin: 20px;" id="specificationDetailList">
        <div class="spesc-label" :style="{ width: labelWidth }">规格明细:</div>
        <div style="width: 100%;">
          <table class="table-spesc">
            <tbody>
              <tr style="background: #F4F6FC; box-shadow: 0px 1px 5px 0px rgba(38, 38, 38, 0.1);">
                <td :style="{ width: specsWidth, padding: '17px 0' }" v-for="(subItem, subIndex) in specificationDetailList" :key="subIndex">{{ subItem.specificationName }}</td>
                <!-- <td :style="{ width: specsWidth }">零售价(元)</td> -->
                <td :style="{ width: specsWidth, padding: '17px 0' }">供货价</td>
                <!-- <td :style="{ width: specsWidth }">利润</td> -->
                <td :style="{ width: specsWidth, padding: '17px 0' }">库存</td>
              </tr>
            </tbody>
          </table>
          <div style="max-height: 400px; overflow: scroll;">
            <table class="table-spesc">
              <tbody>
                <tr style="border-bottom: 1px solid rgb(235, 235, 235); height: 54px; line-height: 54px;" v-for="(item, index) in nameToValSpecsList" :key="index">
                  <td :style="{ width: specsWidth }" v-for="(n, idx) in item.specsValueList" :key="idx">{{ n }}</td>
                  <td :style="{ width: specsWidth }">{{ item.supplyPrice }}元</td>
                  <td :style="{ width: specsWidth }">{{ item.stock }}件</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <glsx-combi-form v-if="!specificationDetailList.length" class="edit-form-container" ref="editFormRef" labelWidth="140px" defaultWidth="320px" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule"></glsx-combi-form>
    </div>
    <GLFooter>
      <el-button @click="handleCancel" size="medium">返回</el-button>
    </GLFooter>
  </div>
</template>

<script>
import { limitPrice } from '@/common/constant'
export default {
  name: 'takeGoodDetail',
  data() {
    return {
      size: 'small',
      title: '查看商品',
      editChildRef: 'editChildRef',
      // submitted: false,
      isDisabled: false,
      mainImgUrl: '',
      moveNum: 0,
      curMoveNum: 0,
      /* eslint-disable */
      reg: {
        priceReg: /^\d[\d\.]*$/,
        numReg: /^[1-9]\d*$/
      },
      /* eslint-enable */
      routeInfo: {
        // 1-新增;2-编辑;3-查看
        // addOrEdit: 1,
        id: ''
      },
      specificationDetailList: [],
      nameToValSpecsList: [],
      editForm: {
        retailPrice: ''
      },
      editFormData: [
        {
          label: '供货价',
          name: 'supplyPrice',
          type: 'input',
          isDisabled: true,
          width: '411px'
        },
        {
          label: '库存',
          name: 'goodsStock',
          type: 'input',
          isDisabled: true,
          width: '411px'
        }
      ]
    }
  },

  mounted() {
    this.setMinHeight()
    this.routeInfo = this.$route.query
    this.isDisabled = true
    this.editFormData[0].isDisabled = true
    this.getInfo()
  },

  methods: {
    getInfo() {
      this.$apis.proManage.getProInfoApi({ id: this.routeInfo.id }).then(res => {
        this.editForm = {
          ...res,
          retailPrice: '',
          supplyPrice: res.supplyPrice ? (res.supplyPrice / 100).toFixed(2) : ''
        }
        // 规格
        if (this.editForm.specificationList.length) {
          this.specificationDetailList = this.$common.utils.deepClone(this.editForm.specificationList)
          this.recoverySpec()
          // this.findSpeceMin()
        } else {
          // 零售价
          this.editForm.retailPrice = (res.retailPrice / 100).toFixed(2)
        }
        this.mainImgUrl = this.editForm.goodsDetailImageList[0].content
        this.moveNum = this.editForm.goodsDetailImageList.length > 4 ? this.editForm.goodsDetailImageList.length - 4 : 0
      })
    },
    // 规格值解构
    changeSpecs(isRecovery) {
      this.specsWidth = 100 / (this.specificationDetailList.length + 2) + '%'
      this.nameToValSpecsList = []
      var markIdx = 0
      for (var i = 0; i < this.specificationDetailList.length; i++) {
        markIdx = 0
        for (var j = 0; j < this.specificationDetailList[i].specificationValueList.length; j++) {
          if (i == 0) {
            this.nameToValSpecsList.push({
              specsValueList: [this.specificationDetailList[i].specificationValueList[j].specificationValue],
              retailPrice: '',
              stock: ''
            })
          } else {
            var targetValLen = this.specificationDetailList[i].specificationValueList.length
            var loopNum = 0
            var tempMarkIdx = 0
            if (j == 0 && targetValLen > 1) {
              var obj = JSON.parse(JSON.stringify(this.nameToValSpecsList))
              this.nameToValSpecsList = []
              obj.forEach((item, index) => {
                for (var k = 0; k < targetValLen; k++) {
                  this.nameToValSpecsList.push(JSON.parse(JSON.stringify(item)))
                }
              })
            }
            loopNum = this.nameToValSpecsList.length / targetValLen
            tempMarkIdx = markIdx
            for (var k = 0; k < loopNum; k++) {
              this.nameToValSpecsList[tempMarkIdx].specsValueList.push(this.specificationDetailList[i].specificationValueList[j].specificationValue)
              tempMarkIdx = tempMarkIdx + targetValLen
            }
            markIdx = markIdx + 1
          }
        }
      }
      if (isRecovery) {
        this.nameToValSpecsList.forEach((item, index) => {
          var specificationObj = {}
          item.specsValueList.forEach((subItem, subIndex) => {
            specificationObj[this.specificationDetailList[subIndex].specificationName] = subItem
          })
          item.specificationData = this.setLocaleCompare(specificationObj)
          for (var i = 0; i < this.editForm.specificationDetailList.length; i++) {
            var temp = this.editForm.specificationDetailList[i]
            if (temp.specificationData == item.specificationData) {
              item.retailPrice = (temp.retailPrice / 100).toFixed(2)
              item.specificationKey = temp.specificationKey
              item.stock = temp.stock
              item.supplyPrice = this.editForm.supplyPrice
              break
            }
          }
        })
      }
    },
    setLocaleCompare(params) {
      let keys = []
      let obj = []
      Object.keys(params).forEach(item => {
        keys.push(item)
      })
      keys.sort()
      keys.forEach(item => {
        obj.push([item, params[item]])
      })
      return obj.join('&').replace(/,/g, '-')
    },
    // 恢复规格值
    recoverySpec() {
      this.changeSpecs(true)
    },
    // 换图
    handleChangeImg(idx) {
      this.mainImgUrl = this.editForm.goodsDetailImageList[idx].content
    },
    handleCancel() {
      this.$router.push({
        path: '/takeGood/index'
      })
    }
  }
}
</script>
<style scoped>
.title {
  padding: 13px 20px;
  border-bottom: 1px solid #e5e5e5;
}

.edit-product-dh .inner-img {
  width: 100%;
  height: 100%;
}

.edit-product-dh .main-img-box {
  width: 375px;
  text-align: center;
  margin: 0 34px 0 20px;
}

.view {
  width: 375px;
  height: 667px;
  margin: 30px 45px 0 60px;
  background: #f6f6f6;
  position: relative;
}

.view img {
  width: 100%;
  vertical-align: top;
}

.edit-product-dh .pro-name {
  width: 100%;
  font-size: 16px;
  color: #3a3a3a;
  font-weight: 500;
  margin-bottom: 14px;
}

.edit-product-dh .supply-price {
  font-size: 26px;
  color: #ff6d00;
}

.edit-product-dh .border-red {
  border: 1px solid red;
}

.txt-ellipsis {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
/* 规格 */
.edit-product-dh .spesc-label {
  box-sizing: border-box;
  color: #666;
  font-weight: 600;
  margin-bottom: 10px;
}
.edit-product-dh .table-spesc {
  width: 100%;
  text-align: center;
  margin-bottom: 0;
}
.edit-product-dh .table-spesc tbody tr {
  border: 1px solid #e7e7e7;
}

.edit-product-dh .table-spesc tbody td {
  display: inline-block;
  box-sizing: border-box;
  width: 20%;
  border: none;
  padding: 2px 6px;
  vertical-align: center;
  text-align: center;
}
.edit-product-dh .table-spesc .el-input--small .el-input__inner {
  text-align: center !important;
}
.edit-product-dh .w-320 {
  width: 320px;
}
.color-red {
  color: #eb4e4e;
  cursor: pointer;
}
/* 规格 */
</style>