vue+el-table点击行多选

32 篇文章 1 订阅
30 篇文章 1 订阅
这是一个基于Vue.js的表格组件示例,包含了全选、单行选择、点击事件、样式设置等功能。表格数据显示了设备状态、作业状态、工单号等信息,并提供了预览、流程卡、开工等操作按钮。用户可以通过全选复选框来选择所有行,或者通过点击行来单独选择。此外,还实现了回到顶部的功能。
摘要由CSDN通过智能技术生成

<template>
<div class="wrap">
    <div class="wrap_con">
    <el-table
    ref="singleTable"
    :data="tableData"
    @row-click="changeRow"
    :row-style="isRed"
    class="table">
    <el-table-column
      property="status"
      label="设备状态"
      width="70">
    </el-table-column>
    <el-table-column
      property="name"
      label="作业状态"
      width="70">
    </el-table-column>
    <el-table-column
      property="address"
      label="工单号"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="产品"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="产出单位"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="工序"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="正品数量"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="废品数量"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="废品信息"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="时长"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="班组人员"
      width="70">
    </el-table-column>
     <el-table-column
      property="date"
      label="流程卡号"
      width="70">
    </el-table-column>
    <el-table-column
      property="date"
      label="开始时间"
      width="70">
    </el-table-column>
  </el-table>
    </div>
  <div class="botbut">
      <div class="botbutleft">
          <el-checkbox v-model="checked" @change="setCurrent()">全选</el-checkbox>
        <!-- <button class="but but1">领料</button>
        <button class="but but2">退料</button>
        <button class="but but3">进入任务</button> -->
      </div>
      <div class="botbutright">
        <button class="but but4" @click="backTop()">回到顶部</button>
        <button class="but but5">预览</button>
        <button class="but but6" @click="card()">流程卡</button>
        <button class="but but7">开工</button>
      </div>
  </div>
</div>
  
</template>

<script>
  export default {
    data() {
      return {
          checked:false,
        tableData: [{
          status:'生产中',
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄',
          index:0
        }, {
          status:'生产中',
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄',
          index:1
        }, {
          status:'生产中',
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄',
          index:2
        }, {
          status:'生产中',
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄',
          index:3
        },{
          status:'生产中',
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄',
          index:4
        },{
          status:'生产中',
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄',
          index:5
        },{
          status:'生产中',
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄',
          index:6
        }],
        currentRow: null,
        changeList:[]
      }
    },
    methods: {
      handleSelectionChange(val) {
        this.changeList = val;
        // console.log(this.changeList)
      },
      isRed({ row }) {
        //   console.log(row)
      const checkIdList = this.changeList.map((item) => item.index);
      if (checkIdList.includes(row.index)) {
          this.tableData = this.tableData
        return {
          backgroundColor: "rgba(249,168,11,0.20)"
        };
        
      }
    },
    setCurrent(){
        if(this.checked == false){
            this.handleSelectionChange([])
        }else{
            this.handleSelectionChange(this.tableData)
        }
        
    },
      changeRow(row){
        this.changeList.push(row)
        var newArr = []
        this.changeList.forEach((item,index)=>{
            if(newArr.indexOf(item)===-1){
                newArr.push(item)
            }else{
                var arrid=[]
                this.changeList.forEach((item1,index1)=>{
                    if(item1.index === row.index){
                        arrid.push(index1)
                    }
                })
                newArr.splice(arrid[0],1)
            }
        })
        this.changeList = newArr
      },
    //   流程卡
      card(){
          this.$router.push({
            path: '/home/flowCard',
            // query: {
            //     // title: encodeURIComponent(title),
            //     indexs: encodeURIComponent('ssss'),
            // }
          })
      },
    //   回到顶部
      backTop(){
          document.getElementsByClassName('wrap_con')[0].scrollTop = 0;
      }
    }
  }
</script>
<style lang="scss" scoped>
.wrap{
    width: 100%;
    height: 100%;
    font-family: Roboto, Roboto-Medium;
    padding: 12px 16px 89px 16px;
    box-sizing: border-box;
    // overflow-x: auto;'
    overflow: hidden;
    position: relative;
    .wrap_con{
        width: 100%;
        height: 100%;
        overflow: scroll;
    }
    .table{
        // width: 100%;
        // height: 100%;
    }
    .botbut{
        position: absolute;
        width: 100%;
        height: 90px;
        bottom: 0;
        left: 0;
        background: #f6f6f9;
        box-shadow: 0px 1px 0px 0px rgba(27,10,91,0.20) inset; 
        padding: 0px 7px 0px 7px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        .botbutleft{
            flex: 1;
             display: flex;
            align-items: center;
            .el-checkbox{
                font-size: 16px;
                font-family: PingFang SC, PingFang SC-Bold;
                font-weight: 700;
                color: #645df6;
            }
            
            ::v-deep .el-checkbox__input{
                width: 20px;
                height: 20px;
            }
            ::v-deep .el-checkbox__inner{
                width: 20px;
                height: 20px;
                border: 1px solid #645df6;
                border-radius: 4px;
            }
            ::v-deep .el-checkbox__inner::after{
                width: 2px;
                height: 7px;
                top: 3px;
                left: 6px;
            }
            button{
                margin-left: 9px;
            }
        }
        .botbutright{
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: right;
            button{
                margin-right: 9px;
            }
        }
        .but{
            width: 144px;
            height: 56px;
            border-radius: 8px;
            border: 0;
            font-size: 18px;
            font-family: PingFang SC, PingFang SC-Bold;
            font-weight: 700;
            text-align: CENTER;
            color: #ffffff;
        }
        .but1,.but2{
            background: #f9a80b;
            box-shadow: 0px 3px 3px 0px rgba(79,53,4,0.60), 0px -2px 2px 0px rgba(0,0,0,0.24) inset, 0px 4px 3px 0px rgba(255,255,255,0.45) inset; 
        }
        .but3{
            background: #00c2bb;
            box-shadow: 0px 3px 3px 0px rgba(6,82,79,0.57), 0px -2px 2px 0px rgba(0,0,0,0.24) inset, 0px 4px 3px 0px rgba(255,255,255,0.45) inset; 
        }
        .but4{
            width: 56px;
            height: 56px;
            background: #007cf1;
            box-shadow: 0px 3px 3px 0px rgba(0,44,86,0.65), 0px -2px 2px 0px rgba(0,0,0,0.24) inset, 0px 4px 3px 0px rgba(255,255,255,0.45) inset; 
        }
        .but5,.but6{
            background: #007cf1;
            box-shadow: 0px 3px 3px 0px rgba(0,44,86,0.65), 0px -2px 2px 0px rgba(0,0,0,0.24) inset, 0px 4px 3px 0px rgba(255,255,255,0.45) inset; 
        }
        .but7{
            float: right;
            background: #645df6;
            box-shadow: 0px 3px 3px 0px rgba(12,8,85,0.70), 0px -2px 2px 0px rgba(0,0,0,0.24) inset, 0px 4px 3px 0px rgba(255,255,255,0.45) inset; 
        }
    }
}
::v-deep .el-table th>.cell{
    font-size: 12px;
    font-weight: 500;
    text-align: LEFT;
    color: rgba(0,0,0,0.85);
    line-height: 22px;
}
::v-deep .el-table__body tr.current-row>td {
    background-color: transparent;
}
::v-deep .el-table--enable-row-hover .el-table__body tr:hover>td{
    background-color: transparent;
}
// ::v-deep .el-table .success-row {
//   background-color: rgba(249,168,11,0.20);;
// }
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值