element 表格套输入框

实现效果:

编辑:

 查看:点击平台补贴展示弹窗

   <el-table
        :data="tableData"
        border
        :header-cell-style="{background:'#D7D7D7',color:'#000'}"
        style="width: 100%"
        @row-dblclick="dbclick"
        :cell-class-name="tableCellClassName">      
        <!-- 平台端 -->
        <el-table-column
          prop="platformSubsidyPrice"
          align="center"
          label="平台补贴">
          <template slot-scope="scope">
            <!--v-if去判断双击的是不是当前单元格-->
            <el-input
             min="0"
             placeholder="填写平台补贴" 
             @change="hideInputOne(scope.row)"
             oninput="value=value.replace(/^([0-9-]\d*\.?\d{0,2})?.*$/,'$1')"
             size="mini" 
             :ref="scope.row.index + ',' + scope.column.index" 
             v-model="scope.row.platformSubsidyPrice" 
             v-if="scope.row.index + ',' + scope.column.index == currentCell && statusForm == 'update' ? disabled = true : disabled = false">
          </el-input>
          <span v-else style="color:red" @click="hideVisible" >{{scope.row.platformSubsidyPrice}}</span>
          </template>
        </el-table-column>
</el-table>

方法:

      // 给单元格绑定横向和竖向的index,这样就能确定是哪一个单元格
      tableCellClassName({row, column, rowIndex, columnIndex}){
            row.index=rowIndex;
            column.index=columnIndex;
        },
        // 获得当前双击的单元格的横竖index,然后拼接成一个唯一字符串用于判断,并赋给currentCell
        // 拼接后类似这样:"1,0","1,1",
        dbclick(row,column) {
            this.currentCell = row.index + ',' + column.index;
            if(statusForm == 'update'){ //防止不是编辑的时候点击报错
              return
            }
            // 这里必须要setTimeout,因为在点击的时候,input才刚被v-if显示出来,不然拿不到dom
            setTimeout(() => {
                // 双击后自动获得焦点
                this.$refs[row.index + ',' + column.index].focus();
            })
        },
        // 当input失去焦点的时候,隐藏input
        hideInputOne(row){
            this.formData.platformSubsidyPrice = row.platformSubsidyPrice
            this.currentCell = null;
            this.dialogplatformVisible = true;
            this.tableDatas = this.formData.platformSubsidyPriceRecords 
        },
        // 如果等于查看,子表单就展示
        hideVisible(){
          if(this.statusForm == 'create'){
            this.dialogplatformVisible = true;
          }
        },
        // 平台-关闭
        closePlatform(){
          this.dialogplatformVisible = false;
        },
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值