vue+el-table 可输入表格使用上下键进行input框切换

在这里插入图片描述
使用上下键进行完工数量这一列的切换

<el-table :data="form.detailList" @selection-change="handleChildSelection" ref="bChangeOrderChild" max-height="500">
 <!-- <el-table-column type="selection" width="50" align="center"/> -->
 <el-table-column label="序号" align="center" prop="index" width="50"/>

 <el-table-column label="产品名称">
   <template slot-scope="scope">
     <el-input v-model="scope.row.materialName" readonly/>
   </template>
 </el-table-column>
 <el-table-column label="完工数量" prop="wrastNum">
   <template slot-scope="scope">
     <el-input v-model="scope.row.wrastNum" placeholder="请输入完工数量" @focus="wrastNumFocus(scope.row)" @keyup.native="show($event,scope.$index)" class="table_input badY_input"/>
   </template>
 </el-table-column>
 <el-table-column label="入库批次号" prop="productBatchNum">
   <template slot-scope="scope">
     <el-input v-model="scope.row.productBatchNum" placeholder="请输入入库批次号" />
   </template>
 </el-table-column>
 <el-table-column label="开始时间" prop="planStartTime" width="230">
   <template slot-scope="scope">
     <el-date-picker clearable
       style="width: 100%;"
       v-model="scope.row.planStartTime"
       type="datetime"
       value-format="yyyy-MM-dd HH:mm:ss"
       placeholder="请选择开始时间">
     </el-date-picker>
   </template>
 </el-table-column>
 <el-table-column label="结束时间" prop="planEndTime" width="230">
   <template slot-scope="scope">
     <el-date-picker clearable
       style="width: 100%;"
       v-model="scope.row.planEndTime"
       type="datetime"
       value-format="yyyy-MM-dd HH:mm:ss"
       placeholder="请选择结束时间">
     </el-date-picker>
   </template>
 </el-table-column>
 <el-table-column label="备注" prop="note">
   <template slot-scope="scope">
     <el-input v-model="scope.row.note" placeholder="请输入备注" />
   </template>
 </el-table-column>
</el-table>
//键盘触发事件
show(ev,index){
  let newIndex;
  let inputAll = document.querySelectorAll('.table_input input');

  //向上 =38
  if (ev.keyCode == 38) {

    if( index==0 ) {// 如果是第一行,回到最后一个
      newIndex = inputAll.length - 1
    }else if( index == inputAll.length ) {// 如果是最后一行,继续向上
      newIndex = index - 1
    }else if( index > 0 && index < inputAll.length ) {// 如果是中间行,继续向上
      newIndex = index - 1
    }

    if (inputAll[newIndex]) {
      inputAll[newIndex].focus();
    }
  }

  //下 = 40
  if (ev.keyCode == 40) {

    if( index==0 ) {// 如果是第一行,继续向下
      newIndex = index+1
    }else if( index == inputAll.length-1 ) {// 如果是最后一行,回到第一个
      newIndex = 0
    }else if( index > 0 && index < inputAll.length ) {// 如果是中间行,继续向下
      newIndex = index + 1
    }

    if (inputAll[newIndex]) {
      inputAll[newIndex].focus();
    }
  }
}
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以通过在 `el-table` 中使用 `el-input-number` 组件来实现购物车功能。以下是一个简单的示例代码: 首先,需要在组件中引入所需的组件: ```vue <template> <div> <el-table :data="cartData" style="width: 100%"> <el-table-column prop="name" label="商品名称"></el-table-column> <el-table-column prop="quantity" label="数量"> <template slot-scope="scope"> <el-input-number v-model="scope.row.quantity" @change="updateTotalPrice"></el-input-number> </template> </el-table-column> <el-table-column prop="price" label="单价"></el-table-column> <el-table-column prop="totalPrice" label="总价"></el-table-column> </el-table> </div> </template> <script> export default { data() { return { cartData: [ { name: '商品1', quantity: 1, price: 10, totalPrice: 10 }, { name: '商品2', quantity: 2, price: 20, totalPrice: 40 }, { name: '商品3', quantity: 3, price: 30, totalPrice: 90 } ] }; }, methods: { updateTotalPrice() { this.cartData.forEach(item => { item.totalPrice = item.quantity * item.price; }); } } }; </script> ``` 在上述代码中,`cartData` 数组是购物车中的数据源,包含商品名称、数量、单价和总价等信息。在 `el-table` 中的 `el-table-column` 中,使用 `el-input-number` 组件来编辑商品的数量,并通过 `v-model` 绑定到 `cartData` 数组中的 `quantity` 属性上。当数量发生变化时,通过 `@change` 事件触发 `updateTotalPrice` 方法,更新对应商品的总价。 注意:以上代码仅为示例,实际应用中,您可能需要从后端动态获取购物车数据,并与后端进行交互来更新购物车信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值