表格合并

element-ui el-table 表格合并后戴卜,鼠標(biāo)經(jīng)過的高亮顯示問題

合并后高亮是這樣的

1.png

目標(biāo)效果

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  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="數(shù)量" align="center">
        </el-table-column>
        <el-table-column label="訂單狀態(tài)" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.status==0">待付款</div>
            <div v-if="scope.row.status==1">待發(fā)貨</div>
            <div v-if="scope.row.status==2">已發(fā)貨</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">交易關(guān)閉</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: {
      // 獲取相同編號的數(shù)組
      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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末吴攒,一起剝皮案震驚了整個濱河市缝裁,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌攒驰,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,948評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件形帮,死亡現(xiàn)場離奇詭異肤无,居然都是意外死亡先蒋,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,371評論 3 385
  • 文/潘曉璐 我一進店門宛渐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來竞漾,“玉大人,你說我怎么就攤上這事窥翩∫邓辏” “怎么了?”我有些...
    開封第一講書人閱讀 157,490評論 0 348
  • 文/不壞的土叔 我叫張陵鳍烁,是天一觀的道長叨襟。 經(jīng)常有香客問我繁扎,道長幔荒,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,521評論 1 284
  • 正文 為了忘掉前任梳玫,我火速辦了婚禮爹梁,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘提澎。我一直安慰自己姚垃,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,627評論 6 386
  • 文/花漫 我一把揭開白布盼忌。 她就那樣靜靜地躺著积糯,像睡著了一般。 火紅的嫁衣襯著肌膚如雪谦纱。 梳的紋絲不亂的頭發(fā)上看成,一...
    開封第一講書人閱讀 49,842評論 1 290
  • 那天,我揣著相機與錄音跨嘉,去河邊找鬼川慌。 笑死,一個胖子當(dāng)著我的面吹牛祠乃,可吹牛的內(nèi)容都是我干的梦重。 我是一名探鬼主播,決...
    沈念sama閱讀 38,997評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼亮瓷,長吁一口氣:“原來是場噩夢啊……” “哼琴拧!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起嘱支,我...
    開封第一講書人閱讀 37,741評論 0 268
  • 序言:老撾萬榮一對情侶失蹤艾蓝,失蹤者是張志新(化名)和其女友劉穎力崇,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赢织,經(jīng)...
    沈念sama閱讀 44,203評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡亮靴,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,534評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了于置。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片茧吊。...
    茶點故事閱讀 38,673評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖八毯,靈堂內(nèi)的尸體忽然破棺而出搓侄,到底是詐尸還是另有隱情,我是刑警寧澤话速,帶...
    沈念sama閱讀 34,339評論 4 330
  • 正文 年R本政府宣布讶踪,位于F島的核電站,受9級特大地震影響泊交,放射性物質(zhì)發(fā)生泄漏乳讥。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,955評論 3 313
  • 文/蒙蒙 一廓俭、第九天 我趴在偏房一處隱蔽的房頂上張望云石。 院中可真熱鬧,春花似錦研乒、人聲如沸汹忠。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,770評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽宽菜。三九已至,卻和暖如春竿报,著一層夾襖步出監(jiān)牢的瞬間铅乡,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,000評論 1 266
  • 我被黑心中介騙來泰國打工仰楚, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留隆判,地道東北人。 一個月前我還...
    沈念sama閱讀 46,394評論 2 360
  • 正文 我出身青樓僧界,卻偏偏與公主長得像侨嘀,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子捂襟,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,562評論 2 349

推薦閱讀更多精彩內(nèi)容