index.vue 7.01 KB
<template>
    <div class="table-wrap">
        <table>
          <tr>
            <th rowspan="2">规格</th>
            <th rowspan="2">价格区间(万元)</th>
            <th rowspan="2">价格系数</th>
            <th colspan="2" v-for="(item, index) in tableData.salePeriodData" :key="index">{{item.servicePeriod}}年版</th>
          </tr>
          <tr>
            <template  v-for="(item, index) in tableData.salePeriodData">
              <th  :key="index">上架成本 
                <!-- <el-tooltip class="item" effect="dark" content="提示待运营提供" placement="top">
                  <img class="tip" :src="require('@/assets/tip.png')" />
                </el-tooltip> -->
              </th>
              <th  :key="index">销售成本
                <!-- <el-tooltip class="item" effect="dark" content="提示待运营提供" placement="top">
                  <img class="tip" :src="require('@/assets/tip.png')" />
                </el-tooltip> -->
              </th>
            </template>
          </tr>
          <tr>
            <td rowspan="4">{{ tableData.serviceGrade }}</td>
            <td>标准</td>
            <td>-</td>
            <template  v-for="(item, index) in tableData.salePeriodData">
              <td  :key="index"><el-input :placeholder="placeholder" @input="changePrice($event, item, 'standardShelfCost')" :disabled="disabled" v-model="item.standardShelfCost"></el-input></td>
              <td  :key="index"> <el-input :placeholder="placeholder"  @input="changePrice($event, item, 'standardSalesCost')" :disabled="disabled" v-model="item.standardSalesCost"></el-input></td>
            </template>
          </tr>
          <tr  v-for="(item, index) in tableData.gradeConfigList" :key="index">
            <td class="price">
              <el-input :placeholder="placeholder" @input="changePrice($event, item, 'minPrice')" @blur="formatPrice($event, item, 'minPrice', 200)" :disabled="disabled" v-model="item.minPrice"></el-input>
              <span class="sign">-</span>
              <el-input :placeholder="placeholder" @input="changePrice($event, item, 'maxPrice')" @blur="formatPrice($event, item, 'maxPrice', 200)" :disabled="disabled" v-model="item.maxPrice"></el-input>
            </td>
            <td><el-input :placeholder="placeholder" @input="changePrice($event, item, 'priceCoefficient')" :disabled="disabled" @blur="formatPrice($event, item, 'priceCoefficient', 100)" v-model="item.priceCoefficient"></el-input></td>
            <template  v-for="(ele, eIdx) in tableData.salePeriodData">
              <td  :key="eIdx">{{calcPrice(ele.standardShelfCost, item.priceCoefficient)}}</td>
              <td  :key="eIdx">{{calcPrice(ele.standardSalesCost, item.priceCoefficient)}}</td>
            </template>
          </tr>
          <tr class="desc-wrap">
            <td class="desc-td" :colspan="tableData.salePeriodData.length*2 + 3">
              <div class="desc">
                <label for="">服务条款概述:</label>
                <Editor :disabled="disabled" :editorOption="overviewOption"  v-model="tableData.serviceOverview"></Editor>
              </div>
            </td>
          </tr>
          <tr class="desc-wrap">
            <td class="desc-td" :colspan="tableData.salePeriodData.length*2+3">
              <div class="desc">
                <label for="">规格详细描述:</label>
                <Editor :disabled="disabled" :editorOption="DetailOption" v-model="tableData.serviceDetail"></Editor>
              </div>
            </td>
          </tr>
        </table>
    </div>
  </template>
 
  <script>
  import Editor from '@/components/Editor'
  export default {
    name: 'ServicesTable',
    components:{
        Editor,
    },
    props: {
      name: {
        type: String,
        default: ''
      },
      tableData: {
        type: String,
        default: ()=>{
          return {}
        }
      },
      disabled: {
        type: Boolean,
        default: false
      },
      url: {
        type: String,
        default: ''
      },
      key: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        placeholder: '请输入',
        overviewOption: {
            placeholder: '请输入服务条款概述',
            modules: {
              toolbar: false,
              clipboard: {
                  // 粘贴版,处理粘贴时候的自带样式
                  matchers: [[Node.ELEMENT_NODE, this.HandleCustomMatcher]],
              },
            }
        },
        DetailOption: {
          placeholder: '请输入规格详细描述',
          modules: {
            toolbar: false,
            clipboard: {
                // 粘贴版,处理粘贴时候的自带样式
                matchers: [[Node.ELEMENT_NODE, this.HandleCustomMatcher]],
            },
          }
        }
      }
    },
    methods: {
      changePrice(value, item , key){
        item[key] = value ? value.replace(/^0\d/g, '0').replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/^\d{6}\d+(\.\d+)?/g, value.substr(0,6)).replace(/\.{2,}/g, '').replace('.', '$#$')
                .replace(/\./g, '').replace('$#$', '.').replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3') : ''
      },   
      formatPrice(e, item, key, maxNum){
        let num = e.target.value
        if(num>maxNum){
          item[key] = maxNum
        }
      },
      calcPrice(price1, price2){
        price1 = price1 || 0
        price2 = price2 || 0
        return Number((price1 *  price2).toFixed(2))
      },
      HandleCustomMatcher(node, Delta) {
        // 文字、图片等,从别处复制而来,清除自带样式,转为纯文本
        let ops = []
        Delta.ops.forEach(op => {
            if (op.insert && typeof op.insert === 'string') {
                ops.push({
                    insert: op.insert,
                })
            }
        })
        Delta.ops = ops
        return Delta
      },
    }
  }
  </script>
  <style lang="scss" scoped>
  .table-wrap{
    .tip{
      width: 14px;
      vertical-align: middle;
      margin-bottom: 2px;
      cursor: pointer;
    }
    /deep/ .el-input__inner{
      padding: 0 2px;
      text-align: center;
    }
    th, td{
      border: 1px solid #E5E5E5;
      padding: 0 16px;
      vertical-align: middle;
      text-align: center;
    }
    th{
      background: #F4F6FC;
      font-weight: 600;
      font-size: 14px;
      color: #333333;
    }
    td{
      font-weight: 400;
      height: 56px;
      font-size: 14px;
      color: #666666;
    }
    .price{
      width: 136px;
      .sign{
          margin: 0 6px;
      }
      .el-input{
        width: 50px;
      }
    }
    .desc-wrap{
        height: 88px;
        .desc-td{
          padding: 12px 16px;
        }
        .desc{
          display: flex;
          height: 100%;
          label{
            white-space: nowrap;
          }
          /deep/ .editor-ctnr{
            height: 100%;
            .ql-container{
              border-radius: 4px;
              .ql-editor{
                padding: 8px;
              }
            }
          }
        }

    }
  }
  </style>