element UI form嵌套table,动态列渲染数据

工作中遇到form嵌套多层table,并渲染table的动态列

data中声明的结构

form: {
  tableList: [
     {
         id: 0,
         name: '',
         type: '', 
         tableListColList: [//动态列数据
           {
             id: 0,
             startDate: formatDate(new Date(), 'YYYY-MM-DD'),
             endDate: formatDate(new Date(), 'YYYY-MM-DD'),
             count: '', //数量
             money: '', //金额
            },
         ],
      },
   ],
},

html结构

 <el-form ref="formTable" :rules="formRules" :model="form" size="mini" :inline="true">
    <el-table 
        v-loading="!isTableShow" 
        element-loading-text="拼命加载中..." 
        element-loading-spinner="el-icon-loading"
        border 
        :data="form.tableList" 
        style="width: 100%">
      <el-table-column fixed prop="name" label="意向产品" width="150"></el-table-column>
      <el-table-column fixed label="预计收入金额" width="120">
          <template slot-scope="scope">
            <div>金额(万元)</div>
            <div>占比(%)</div>
          </template>
      </el-table-column>
      <!-- 动态列 -->
      <div v-if="isTableShow">
          <el-table-column
            v-for="(item, index) in form.tableList[0].tableListColList"
            :key="index"
            width="150"
          >
            <template slot="header" slot-scope="scope">
              <div slot="content">{{ item.endDate }}</div>
            </template>
            <template slot-scope="scope">
              <!-- ----{{scope.$index}}----{{index}} -->
              <!-- {{scope.row.tableListColList[index].money}}----{{scope.row.tableListColList[index].count}} -->
              <div>
                <el-form-item
                  label=" "
                  :prop="
                    'tableList.' +
                    scope.$index +
                    '.tableListColList.' +
                    index +
                    '.money'
                  "
                  :rules="formRules.money"
                >
                  <el-input-number
                    v-model="scope.row.tableListColList[index].money"
                    :controls="false"
                    @change="
                      handleChangeAmount(scope, scope.row.tableListColList[index].money, index)
                    "
                  ></el-input-number>
                </el-form-item>
              </div>
              <div>
                <el-form-item
                  label=" "
                  :prop="
                    'tableList.' + scope.$index + '.tableListColList.' + index + '.count'
                  "
                  :rules="formRules.count"
                >
                  <el-input-number
                    v-model="scope.row.tableListColList[index].count"
                    :max="100"
                    :precision="2"
                    :controls="false"
                    @change="handleChangeRatio(scope, scope.row.tableListColList[index].count, index)"
                  ></el-input-number>
                </el-form-item>
              </div>
            </template>
          </el-table-column>
        </div>
      </el-table>
    </el-form>

 rules规则

formRules: {
   count: [{ validator: this.checkNum }, { required: true, message: '请输入占比' }],
   money: [{ required: true, validator: this.checkMount }],
},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值