detail.vue 7.17 KB
<!-- 采购上架详情 -->
<template>
  <div class="purchase-grounding-detail purchase-grounding edit-box">
    <div class="container edit-container">
      <p class="edit-title">基础信息</p>
      <glsx-combi-form class="edit-form-container m-r-20" ref="editFormRef" :isEdit="isEdit" :pageThat="this" :labelWidth="defaultLabelWidth" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
        <div slot="sourceStrSpan">{{ editForm['goodsSourceStr'] }}</div>
        <div slot="groundingGoodsInfo">
          <div class="goodsInfo-box">
            <div class="item" v-for="(subItem, subIndex) in goodsDetailForm" :key="subIndex">
              <div v-if="subItem.addHtml" class="item_box">
                <div class="label">{{ (membraneTypeList.includes(editForm.groundingGoodsInfo['goodsType']) ? subItem.label + `(元)/卷` : (subItem.label + '(元)/件')) }}:</div>
                <div class="value">{{ priceFilter(editForm.groundingGoodsInfo[subItem.value]) }}</div>
              </div>
              <div v-else class="item_box">
                <div class="label">{{ subItem.label + ':' }}</div>
                <div class="value">{{ editForm.groundingGoodsInfo[subItem.value] || '-' }}</div>
              </div>
            </div>
          </div>
        </div>
        <div slot="purchasePriceSpan">{{ priceFilter(editForm['shopPurchasePrice']) }}</div>
      </glsx-combi-form>
    </div>
    <div class="container edit-container">
      <p class="edit-title">上架门店</p>
      <glsx-combi-form class="edit-form-container" ref="editFormMerchantRef" :isEdit="isEdit" :labelWidth="defaultLabelWidth" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="merchantEditFormData" :formRules="editRule">
        <div slot="merchantTable" :style="{ width: `calc(100% - ${defaultLabelWidth} )` }">
          <div class="table-title">
            上架门店列表
          </div>
          <GLTable ref="warehousListRef" :hasPage="false" :tableParams="tableParams" :tableData="editForm.merchantList"></GLTable>
        </div>
      </glsx-combi-form>
    </div>
    <GLFooter>
      <el-button type="primary" @click="cancelJump" size="medium" :loading="loading">返回</el-button>
    </GLFooter>
  </div>
</template>

<script>
import { goodsSourceOptions, membraneTypeList } from '@/utils/constants.js'
export default {
  name: 'purchaseGroundingDetail',
  data() {
    return {
      editChildRef: 'editChildRef',
      routeInfo: {},
      editForm: {
        goodsSourceStr: '',
        groundingGoodsInfo: {},
        shopPurchasePrice: '',
        merchantList: []
      },
      isEdit: true,
      editRule: {
        goodsSourceStr: [{ required: true, message: '请选择商品来源', trigger: 'change' }],
        upgradeGoodsId: [{ required: true, message: '请选择上架商品', trigger: 'change' }],
        shopPurchasePrice: [
          { required: true, message: '请输入门店采购价', trigger: 'blur' }
        ]
      },
      editFormData: [
        {
          label: '商品来源',
          name: 'goodsSourceStr',
          addHtml: 'sourceStrSpan'
        },
        {
          label: '上架商品',
          name: 'upgradeGoodsId',
          addHtml: 'groundingGoodsInfo'
        },
        {
          label: '门店采购价(元)/件',
          name: 'shopPurchasePrice',
          addHtml: 'purchasePriceSpan'
        }
      ],
      merchantEditFormData: [
        {
          addHtml: 'merchantTable'
        }
      ],
      // 门店表格
      tableParams: {
        tableColumns: [
          {
            label: '门店名称',
            prop: 'merchantName'
          },
          {
            label: '商户号',
            prop: 'merchantId'
          }
        ]
      },
      goodsDetailForm: [
        {
          label: '商品名称',
          value: 'upgradeGoodsName',
        },
        {
          label: '商品编码',
          value: 'type'
        },
        {
          label: '嘀加采购价',
          addHtml: 'DJPurchasePrice',
          value: 'purchasePrice'
        },
        {
          label: '所属分类',
          value: 'goodsTypeName'
        },
        {
          label: '所属系列',
          value: 'goodsName'
        }
      ],
      membraneTypeList // 膜类code集合
    }
  },

  mounted() {
    this.keyDown()
    this.routeInfo = this.$route.query
    this.getInfo()
  },

  methods: {
    keyDown() {
      document.onkeydown = function() {
        var evt = window.event || arguments[0]
        if (evt && evt.keyCode == 13) {
          if (typeof evt.cancelBubble != 'undefined') evt.cancelBubble = true
          if (typeof evt.stopPropagation == 'function') evt.stopPropagation()
          return false
        }
        return true
      }
    },
    priceFilter(num) {
      var pow = Math.pow(10, 2)
      if ((num ?? '') === '') return '-'
      return (Math.round(num * pow) / pow).toFixed(2)
    },
    getInfo() {
      let params = {
        id: this.routeInfo?.id
      }
      this.$apis.grounding.getPurchaseGroundingDetail(params).then(res => {
        res.goodsSourceStr = !((res.goodsSource ?? '') === '') ? goodsSourceOptions[res.goodsSource - 0]?.label : '-'
        let index = this.editFormData.findIndex(val => val.name == 'shopPurchasePrice')
        if (this.membraneTypeList?.includes(res?.goodsInfo?.goodsType)) { // 膜类商品 单位是卷
          if(index > -1) this.editFormData[index].label = '门店采购价(元)/卷'
        }
        if (res?.goodsSource == 1) { // 自营
          let index = this.goodsDetailForm.findIndex(val => val.value == 'purchasePrice')
          if (index > -1) {
            this.goodsDetailForm.splice(index, 1)
          }
        }
        res.groundingGoodsInfo = {
          ...res.goodsInfo,
          ...res.upgradeGoods
        }
        this.editForm = res
      })
    },
    cancelJump() {
      this.$router.push({
        path: '/purchaseGrounding/index'
      })
    }
  }
}
</script>
<style scoped lang="scss">
.purchase-grounding{
  .container{
    padding: 0 0 20px;
    background: #fff;
    .edit-title {
      font-size: 16px;
      font-weight: 600;
      height: 58px;
      line-height: 58px;
      border-bottom: 1px solid #e7eaec;
      margin: 0 0;
      padding: 0 0 0 20px;
    }
    .goodsInfo-box{
      background: #F9F9F9;
      display: flex;
      flex-wrap: wrap;
      padding: 15px 0;
      .item{
        flex: 0 0 33%;
        .item_box{
          display: flex;
          align-items: start;
          .label{
            flex-shrink: 0;
            color: #666666;
            width: 150px;
            text-align: right;
          }
        }
      }
    }
  }
  .edit-container{
    margin-bottom: 16px;
  }
  .edit-form-container {
    margin:20px 20px 0 0;
    .table-title {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
    }
  }
  .m-r-20 {
    /deep/.glsx-combi-form-block{
      color: #666666;
      &:nth-child(1){
        .el-form-item__content{
          width: calc(100% - 154px);
        }
      }
    }
  }
}
.purchase-grounding.purchase-grounding-detail .select-merchant {
  /* width: calc(98% - 140px); */
  width: 98%;
}
.merchant-table {
  margin: 0 20px;
}
</style>