当前位置:   article > 正文

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

element ui 合并单元格 鼠标划过

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

合并后高亮是这样的

目标效果

代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
  9. <style>
  10. .el-table .success-row {
  11. background: #f5f7fa;
  12. }
  13. .el-table__header tr>th {
  14. background: #f8f8f8 !important;
  15. }
  16. .el-checkbox__input.is-checked .el-checkbox__inner {
  17. background-color: #dcdfe6;
  18. border-color: #dcdfe6;
  19. }
  20. .el-checkbox__input.is-focus .el-checkbox__inner {
  21. background-color: #dcdfe6;
  22. border-color: #dcdfe6;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div id="app">
  28. <div class="tables">
  29. <el-table ref="multipleTable" max-height="600" border :span-method="objectSpanMethod" :row-class-name="tableRowClassName"
  30. @cell-mouse-leave="cellMouseLeave" @cell-mouse-enter="cellMouseEnter" :data="tableData" style="width: 80%;margin:0 auto;">
  31. <el-table-column prop="order_number" label="订单编号" width="200px" align="center">
  32. </el-table-column>
  33. <el-table-column label="商品名称" align="center">
  34. <template slot-scope="scope" width="160">
  35. <div @click="orderdetail(scope.row.order_number,scope.row.status)">
  36. <div class="info">
  37. <div>
  38. <div>{{scope.row.clothing_name}}</div>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="买家账号" align="center">
  45. <template slot-scope="scope">
  46. <p>{{scope.row.username}}</p>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="下单时间" width="180px" align="center">
  50. <template slot-scope="scope">
  51. <p>{{scope.row.addtime.split(" ")[0]}}</p>
  52. <p>{{scope.row.addtime.split(" ")[1]}}</p>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="商品价格" align="center">
  56. <template slot-scope="scope">
  57. <p>¥{{scope.row.price}}</p>
  58. </template>
  59. </el-table-column>
  60. <el-table-column prop="amount" label="数量" align="center">
  61. </el-table-column>
  62. <el-table-column label="订单状态" align="center">
  63. <template slot-scope="scope">
  64. <div v-if="scope.row.status==0">待付款</div>
  65. <div v-if="scope.row.status==1">待发货</div>
  66. <div v-if="scope.row.status==2">已发货</div>
  67. <div v-if="scope.row.status==3">交易成功</div>
  68. <div v-if="scope.row.status==4">已取消订单</div>
  69. <div v-if="scope.row.status==5">交易完成</div>
  70. <div v-if="scope.row.status==6">交易关闭</div>
  71. <div v-if="scope.row.status==7">处理中</div>
  72. <div v-if="scope.row.status==8">退款成功</div>
  73. <div v-if="scope.row.status==9">交易OK</div>
  74. <div v-if="scope.row.status==10">已取消订单</div>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="总计" align="center">
  78. <template slot-scope="scope">
  79. <p>¥{{scope.row.total}}</p>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. </div>
  84. </div>
  85. </body>
  86. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  87. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  88. <script>
  89. new Vue({
  90. el: '#app',
  91. data: {
  92. tableData: [{
  93. finish_time: "0",
  94. id: 1054,
  95. order_id: 688,
  96. order_number: "1523948882.879873",
  97. price: "36.00",
  98. amount: 2,
  99. clothing_id: 45,
  100. status: "4",
  101. total: "72.00",
  102. address_id: 119,
  103. user_id: 46,
  104. addtime: "2018-04-17 15:08:02",
  105. order_type: "2",
  106. username: 17621509577,
  107. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  108. classify_name: "男童上装"
  109. },
  110. {
  111. finish_time: "0",
  112. id: 1038,
  113. order_id: 660,
  114. order_number: "1523859982.1010",
  115. price: "36.00",
  116. amount: 2,
  117. clothing_id: 45,
  118. status: "4",
  119. total: "72.00",
  120. address_id: 109,
  121. user_id: 46,
  122. addtime: "2018-04-16 14:26:22",
  123. order_type: "2",
  124. username: 17621509577,
  125. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  126. classify_name: "男童上装"
  127. },
  128. {
  129. finish_time: "0",
  130. id: 1030,
  131. order_id: 635,
  132. order_number: "1523603188.1010",
  133. price: "36.00",
  134. amount: 20,
  135. clothing_id: 45,
  136. status: "2",
  137. total: "792.00",
  138. address_id: 140,
  139. user_id: 33,
  140. addtime: "2018-04-13 15:06:29",
  141. order_type: "2",
  142. username: 17737536671,
  143. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  144. classify_name: "男童上装"
  145. },
  146. {
  147. finish_time: "2018-04-13 15:07:42",
  148. id: 1029,
  149. order_id: 635,
  150. order_number: "1523603188.1010",
  151. price: "36.00",
  152. amount: 2,
  153. clothing_id: 45,
  154. status: "7",
  155. total: "792.00",
  156. address_id: 140,
  157. user_id: 33,
  158. addtime: "2018-04-13 15:06:29",
  159. order_type: "2",
  160. username: 17737536671,
  161. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  162. classify_name: "男童上装"
  163. },
  164. {
  165. finish_time: "0",
  166. id: 1005,
  167. order_id: 606,
  168. order_number: "1523524708.1010",
  169. price: "36.00",
  170. amount: 2,
  171. clothing_id: 45,
  172. status: "4",
  173. total: "72.00",
  174. address_id: 109,
  175. user_id: 46,
  176. addtime: "2018-04-12 17:18:29",
  177. order_type: "2",
  178. username: 17621509577,
  179. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  180. classify_name: "男童上装"
  181. },
  182. {
  183. finish_time: "0",
  184. id: 1001,
  185. order_id: 602,
  186. order_number: "1523519854.659426",
  187. price: "36.00",
  188. amount: 2,
  189. clothing_id: 45,
  190. status: "4",
  191. total: "72.00",
  192. address_id: 109,
  193. user_id: 46,
  194. addtime: "2018-04-12 15:57:34",
  195. order_type: "2",
  196. username: 17621509577,
  197. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  198. classify_name: "男童上装"
  199. },
  200. {
  201. finish_time: "0",
  202. id: 988,
  203. order_id: 545,
  204. order_number: "1523326439.745645",
  205. price: "36.00",
  206. amount: 1,
  207. clothing_id: 45,
  208. status: "4",
  209. total: "36.00",
  210. address_id: 140,
  211. user_id: 33,
  212. addtime: "2018-04-10 10:13:59",
  213. order_type: "2",
  214. username: 17737536671,
  215. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  216. classify_name: "男童上装"
  217. },
  218. {
  219. finish_time: "0",
  220. id: 986,
  221. order_id: 543,
  222. order_number: "1523286363.197641",
  223. price: "36.00",
  224. amount: 3,
  225. clothing_id: 45,
  226. status: "4",
  227. total: "108.00",
  228. address_id: 109,
  229. user_id: 46,
  230. addtime: "2018-04-09 23:06:03",
  231. order_type: "2",
  232. username: 17621509577,
  233. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  234. classify_name: "男童上装"
  235. },
  236. {
  237. finish_time: "2018-04-17 11:01:42",
  238. id: 970,
  239. order_id: 530,
  240. order_number: "1523245914.1010",
  241. price: "36.00",
  242. amount: 1,
  243. clothing_id: 45,
  244. status: "5",
  245. total: "108.00",
  246. address_id: 140,
  247. user_id: 33,
  248. addtime: "2018-04-09 11:51:54",
  249. order_type: "2",
  250. username: 17737536671,
  251. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  252. classify_name: "男童上装"
  253. },
  254. {
  255. finish_time: "2018-04-17 11:07:07",
  256. id: 969,
  257. order_id: 530,
  258. order_number: "1523245914.1010",
  259. price: "36.00",
  260. amount: 2,
  261. clothing_id: 45,
  262. status: "5",
  263. total: "108.00",
  264. address_id: 140,
  265. user_id: 33,
  266. addtime: "2018-04-09 11:51:54",
  267. order_type: "2",
  268. username: 17737536671,
  269. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  270. classify_name: "男童上装"
  271. },
  272. {
  273. finish_time: "0",
  274. id: 907,
  275. order_id: 428,
  276. order_number: "1522755736.123802",
  277. price: "36.00",
  278. amount: 1,
  279. clothing_id: 45,
  280. status: "10",
  281. total: "36.00",
  282. address_id: 140,
  283. user_id: 33,
  284. addtime: "2018-04-03 19:42:16",
  285. order_type: "2",
  286. username: 17737536671,
  287. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  288. classify_name: "男童上装"
  289. },
  290. {
  291. finish_time: "0",
  292. id: 884,
  293. order_id: 405,
  294. order_number: "1522749320.739114",
  295. price: "36.00",
  296. amount: 1,
  297. clothing_id: 45,
  298. status: "10",
  299. total: "36.00",
  300. address_id: 140,
  301. user_id: 33,
  302. addtime: "2018-04-03 17:55:20",
  303. order_type: "2",
  304. username: 17737536671,
  305. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  306. classify_name: "男童上装"
  307. },
  308. {
  309. finish_time: "0",
  310. id: 823,
  311. order_id: 366,
  312. order_number: "1522659064.1010",
  313. price: "36.00",
  314. amount: 2,
  315. clothing_id: 45,
  316. status: "4",
  317. total: "2104.00",
  318. address_id: 137,
  319. user_id: 63,
  320. addtime: "2018-04-02 16:51:04",
  321. order_type: "2",
  322. username: 17737536677,
  323. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  324. classify_name: "男童上装"
  325. },
  326. {
  327. finish_time: "0",
  328. id: 820,
  329. order_id: 365,
  330. order_number: "1522658505.1010",
  331. price: "36.00",
  332. amount: 3,
  333. clothing_id: 45,
  334. status: "4",
  335. total: "2260.00",
  336. address_id: 137,
  337. user_id: 63,
  338. addtime: "2018-04-02 16:41:45",
  339. order_type: "2",
  340. username: 17737536677,
  341. clothing_name: "象汉姆童装vc小象汉姆童装vc小象汉姆童装vc",
  342. classify_name: "男童上装"
  343. }
  344. ],
  345. rowIndex: '-1',
  346. OrderIndexArr: [],
  347. hoverOrderArr: []
  348. },
  349. mounted: function () {
  350. this.getOrderNumber()
  351. },
  352. methods: {
  353. // 获取相同编号的数组
  354. getOrderNumber: function () {
  355. var OrderObj = {}
  356. this.tableData.forEach(function (element, index) {
  357. element.rowIndex = index
  358. if (OrderObj[element.order_number]) {
  359. OrderObj[element.order_number].push(index)
  360. } else {
  361. OrderObj[element.order_number] = []
  362. OrderObj[element.order_number].push(index)
  363. }
  364. }, this);
  365. for (var k in OrderObj) {
  366. if (OrderObj[k].length > 1) {
  367. this.OrderIndexArr.push(OrderObj[k])
  368. }
  369. }
  370. },
  371. // 合并单元格
  372. objectSpanMethod: function ({row,column,rowIndex,columnIndex}) {
  373. if (columnIndex === 0 || columnIndex === 3 || columnIndex === 4 || columnIndex === 7 || columnIndex ===8 || columnIndex === 9) {
  374. for (var i = 0; i < this.OrderIndexArr.length; i++) {
  375. var element = this.OrderIndexArr[i]
  376. for (var j = 0; j < element.length; j++) {
  377. var item = element[j]
  378. if (rowIndex == item) {
  379. if (j == 0) {
  380. return {
  381. rowspan: element.length,
  382. colspan: 1
  383. }
  384. } else if (j != 0) {
  385. return {
  386. rowspan: 0,
  387. colspan: 0
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. },
  395. tableRowClassName: function ({row,rowIndex}) {
  396. var arr = this.hoverOrderArr
  397. for (var i = 0; i < arr.length; i++) {
  398. if (rowIndex == arr[i]) {
  399. return 'success-row'
  400. }
  401. }
  402. },
  403. cellMouseEnter: function (row, column, cell, event) {
  404. this.rowIndex = row.rowIndex
  405. this.hoverOrderArr = []
  406. this.OrderIndexArr.forEach(function (element) {
  407. if (element.indexOf(this.rowIndex) >= 0) {
  408. this.hoverOrderArr = element
  409. }
  410. }, this);
  411. },
  412. cellMouseLeave: function (row, column, cell, event) {
  413. this.rowIndex = '-1'
  414. }
  415. }
  416. })
  417. </script>
  418. </html>
  419. 复制代码

转载于:https://juejin.im/post/5adc0abb6fb9a07aa113c7a6

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/114421
推荐阅读
相关标签
  

闽ICP备14008679号