当前位置:   article > 正文

element-ui el-table 表格动态合并后,鼠标经过的高亮显示问题_el-table合并列后高亮问题

el-table合并列后高亮问题

element-ui el-table 表格动态合并后,鼠标经过的高亮显示问题

合并后高亮是这样的

1.png

目标效果

2.png

代码

<!DOCTYPE html>
<html lang="en">


<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
  <style>
    .el-table .success-row {
      background: #f5f7fa;
    }


    .el-table__header tr>th {
      background: #f8f8f8 !important;
    }


    .el-checkbox__input.is-checked .el-checkbox__inner {
      background-color: #dcdfe6;
      border-color: #dcdfe6;
    }


    .el-checkbox__input.is-focus .el-checkbox__inner {
      background-color: #dcdfe6;
      border-color: #dcdfe6;
    }
  </style>
</head>


<body>
  <div id="app">
    <div class="tables">
      <el-table ref="multipleTable" max-height="600" border :span-method="objectSpanMethod" :row-class-name="tableRowClassName"
        @cell-mouse-leave="cellMouseLeave" @cell-mouse-enter="cellMouseEnter" :data="tableData" style="width: 80%;margin:0 auto;">
        <el-table-column prop="order_number" label="订单编号" width="200px" align="center">
        </el-table-column>
        <el-table-column label="商品名称" align="center">
          <template slot-scope="scope" width="160">
            <div @click="orderdetail(scope.row.order_number,scope.row.status)">
              <div class="info">
                <div>
                  <div>{{scope.row.clothing_name}}</div>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="买家账号" align="center">
          <template slot-scope="scope">
            <p>{{scope.row.username}}</p>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" width="180px" align="center">
          <template slot-scope="scope">
            <p>{{scope.row.addtime.split(" ")[0]}}</p>
            <p>{{scope.row.addtime.split(" ")[1]}}</p>
          </template>
        </el-table-column>
        <el-table-column label="商品价格" align="center">
          <template slot-scope="scope">
            <p>¥{{scope.row.price}}</p>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="数量" align="center">
        </el-table-column>
        <el-table-column label="订单状态" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.status==0">待付款</div>
            <div v-if="scope.row.status==1">待发货</div>
            <div v-if="scope.row.status==2">已发货</div>
            <div v-if="scope.row.status==3">交易成功</div>
            <div v-if="scope.row.status==4">已取消订单</div>
            <div v-if="scope.row.status==5">交易完成</div>
            <div v-if="scope.row.status==6">交易关闭</div>
            <div v-if="scope.row.status==7">处理中</div>
            <div v-if="scope.row.status==8">退款成功</div>
            <div v-if="scope.row.status==9">交易OK</div>
            <div v-if="scope.row.status==10">已取消订单</div>
          </template>
        </el-table-column>
        <el-table-column label="总计" align="center">
          <template slot-scope="scope">
            <p>¥{{scope.row.total}}</p>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
  new Vue({
    el: '#app',
    data: {
      tableData: [{
          finish_time: "0",
          id: 1054,
          order_id: 688,
          order_number: "1523948882.879873",
          price: "36.00",
          amount: 2,
          clothing_id: 45,
          status: "4",
          total: "72.00",
          address_id: 119,
          user_id: 46,
          addtime: "2018-04-17 15:08:02",
          order_type: "2",
          username: 17621509577,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 1038,
          order_id: 660,
          order_number: "1523859982.1010",
          price: "36.00",
          amount: 2,
          clothing_id: 45,
          status: "4",
          total: "72.00",
          address_id: 109,
          user_id: 46,
          addtime: "2018-04-16 14:26:22",
          order_type: "2",
          username: 17621509577,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 1030,
          order_id: 635,
          order_number: "1523603188.1010",
          price: "36.00",
          amount: 20,
          clothing_id: 45,
          status: "2",
          total: "792.00",
          address_id: 140,
          user_id: 33,
          addtime: "2018-04-13 15:06:29",
          order_type: "2",
          username: 17737536671,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "2018-04-13 15:07:42",
          id: 1029,
          order_id: 635,
          order_number: "1523603188.1010",
          price: "36.00",
          amount: 2,
          clothing_id: 45,
          status: "7",
          total: "792.00",
          address_id: 140,
          user_id: 33,
          addtime: "2018-04-13 15:06:29",
          order_type: "2",
          username: 17737536671,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 1005,
          order_id: 606,
          order_number: "1523524708.1010",
          price: "36.00",
          amount: 2,
          clothing_id: 45,
          status: "4",
          total: "72.00",
          address_id: 109,
          user_id: 46,
          addtime: "2018-04-12 17:18:29",
          order_type: "2",
          username: 17621509577,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 1001,
          order_id: 602,
          order_number: "1523519854.659426",
          price: "36.00",
          amount: 2,
          clothing_id: 45,
          status: "4",
          total: "72.00",
          address_id: 109,
          user_id: 46,
          addtime: "2018-04-12 15:57:34",
          order_type: "2",
          username: 17621509577,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 988,
          order_id: 545,
          order_number: "1523326439.745645",
          price: "36.00",
          amount: 1,
          clothing_id: 45,
          status: "4",
          total: "36.00",
          address_id: 140,
          user_id: 33,
          addtime: "2018-04-10 10:13:59",
          order_type: "2",
          username: 17737536671,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 986,
          order_id: 543,
          order_number: "1523286363.197641",
          price: "36.00",
          amount: 3,
          clothing_id: 45,
          status: "4",
          total: "108.00",
          address_id: 109,
          user_id: 46,
          addtime: "2018-04-09 23:06:03",
          order_type: "2",
          username: 17621509577,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "2018-04-17 11:01:42",
          id: 970,
          order_id: 530,
          order_number: "1523245914.1010",
          price: "36.00",
          amount: 1,
          clothing_id: 45,
          status: "5",
          total: "108.00",
          address_id: 140,
          user_id: 33,
          addtime: "2018-04-09 11:51:54",
          order_type: "2",
          username: 17737536671,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "2018-04-17 11:07:07",
          id: 969,
          order_id: 530,
          order_number: "1523245914.1010",
          price: "36.00",
          amount: 2,
          clothing_id: 45,
          status: "5",
          total: "108.00",
          address_id: 140,
          user_id: 33,
          addtime: "2018-04-09 11:51:54",
          order_type: "2",
          username: 17737536671,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 907,
          order_id: 428,
          order_number: "1522755736.123802",
          price: "36.00",
          amount: 1,
          clothing_id: 45,
          status: "10",
          total: "36.00",
          address_id: 140,
          user_id: 33,
          addtime: "2018-04-03 19:42:16",
          order_type: "2",
          username: 17737536671,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 884,
          order_id: 405,
          order_number: "1522749320.739114",
          price: "36.00",
          amount: 1,
          clothing_id: 45,
          status: "10",
          total: "36.00",
          address_id: 140,
          user_id: 33,
          addtime: "2018-04-03 17:55:20",
          order_type: "2",
          username: 17737536671,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 823,
          order_id: 366,
          order_number: "1522659064.1010",
          price: "36.00",
          amount: 2,
          clothing_id: 45,
          status: "4",
          total: "2104.00",
          address_id: 137,
          user_id: 63,
          addtime: "2018-04-02 16:51:04",
          order_type: "2",
          username: 17737536677,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        },
        {
          finish_time: "0",
          id: 820,
          order_id: 365,
          order_number: "1522658505.1010",
          price: "36.00",
          amount: 3,
          clothing_id: 45,
          status: "4",
          total: "2260.00",
          address_id: 137,
          user_id: 63,
          addtime: "2018-04-02 16:41:45",
          order_type: "2",
          username: 17737536677,
          clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
          classify_name: "男童上装"
        }
      ],
      rowIndex: '-1',
      OrderIndexArr: [],
      hoverOrderArr: []
    },
    mounted: function () {
      this.getOrderNumber()
    },
    methods: {
      // 获取相同编号的数组
      getOrderNumber: function () {
        var OrderObj = {}
        this.tableData.forEach(function (element, index) {
          element.rowIndex = index
          if (OrderObj[element.order_number]) {
            OrderObj[element.order_number].push(index)
          } else {
            OrderObj[element.order_number] = []
            OrderObj[element.order_number].push(index)
          }
        }, this);


        for (var k in OrderObj) {
          if (OrderObj[k].length > 1) {
            this.OrderIndexArr.push(OrderObj[k])
          }
        }
      },


      // 合并单元格
      objectSpanMethod: function ({row,column,rowIndex,columnIndex}) {
        if (columnIndex === 0 || columnIndex === 3 || columnIndex === 4 || columnIndex === 7 || columnIndex ===8 || columnIndex === 9) {
          for (var i = 0; i < this.OrderIndexArr.length; i++) {
            var element = this.OrderIndexArr[i]
            for (var j = 0; j < element.length; j++) {
              var item = element[j]
              if (rowIndex == item) {
                if (j == 0) {
                  return {
                    rowspan: element.length,
                    colspan: 1
                  }
                } else if (j != 0) {
                  return {
                    rowspan: 0,
                    colspan: 0
                  }
                }
              }
            }
          }
        }
      },


      tableRowClassName: function ({row,rowIndex}) {
        var arr = this.hoverOrderArr
        for (var i = 0; i < arr.length; i++) {
          if (rowIndex == arr[i]) {
            return 'success-row'
          }
        }
      },


      cellMouseEnter: function (row, column, cell, event) {
        this.rowIndex = row.rowIndex
        this.hoverOrderArr = []
        this.OrderIndexArr.forEach(function (element) {
          if (element.indexOf(this.rowIndex) >= 0) {
            this.hoverOrderArr = element
          }
        }, this);
      },

      cellMouseLeave: function (row, column, cell, event) {
        this.rowIndex = '-1'
      }
    }
  })
</script>


</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/114490
推荐阅读
相关标签
  

闽ICP备14008679号