1
1
<template >
2
2
<el-table-column class-name =" order-table-col" >
3
3
<template #header >
4
- <!-- TODO @puhui999:小屏幕下,会有偏移,后续看看 -->
5
4
<div class =" flex items-center" style =" width : 100% " >
6
- <div class =" ml-100px mr-200px" >商品信息</div >
7
- <div class =" mr-60px" >单价(元)/数量</div >
8
- <div class =" mr-60px" >售后状态</div >
9
- <div class =" mr-60px" >实付金额(元)</div >
10
- <div class =" mr-60px" >买家/收货人</div >
11
- <div class =" mr-60px" >配送方式</div >
12
- <div class =" mr-60px" >订单状态</div >
13
- <div class =" mr-60px" >操作</div >
5
+ <div :style =" { width: orderTableHeadWidthList[0] + 'px' }" class =" flex justify-center" >
6
+ 商品信息
7
+ </div >
8
+ <div :style =" { width: orderTableHeadWidthList[1] + 'px' }" class =" flex justify-center" >
9
+ 单价(元)/数量
10
+ </div >
11
+ <div :style =" { width: orderTableHeadWidthList[2] + 'px' }" class =" flex justify-center" >
12
+ 售后状态
13
+ </div >
14
+ <div :style =" { width: orderTableHeadWidthList[3] + 'px' }" class =" flex justify-center" >
15
+ 实付金额(元)
16
+ </div >
17
+ <div :style =" { width: orderTableHeadWidthList[4] + 'px' }" class =" flex justify-center" >
18
+ 买家/收货人
19
+ </div >
20
+ <div :style =" { width: orderTableHeadWidthList[5] + 'px' }" class =" flex justify-center" >
21
+ 配送方式
22
+ </div >
23
+ <div :style =" { width: orderTableHeadWidthList[6] + 'px' }" class =" flex justify-center" >
24
+ 订单状态
25
+ </div >
26
+ <div :style =" { width: orderTableHeadWidthList[7] + 'px' }" class =" flex justify-center" >
27
+ 操作
28
+ </div >
14
29
</div >
15
30
</template >
16
31
<template #default =" scope " >
17
32
<el-table
33
+ :ref =" setOrderTableRef"
18
34
:border =" true"
19
35
:data =" scope.row.items"
20
36
:header-cell-style =" headerStyle"
21
37
:span-method =" spanMethod"
22
38
style =" width : 100% "
23
39
>
24
- <el-table-column class-name = " table-col-1 " min-width =" 300" prop =" spuName" >
40
+ <el-table-column min-width =" 300" prop =" spuName" >
25
41
<template #header >
26
42
<div
27
43
class =" flex items-center"
60
76
</div >
61
77
</template >
62
78
</el-table-column >
63
- <el-table-column class-name = " table-col-2 " label =" 商品原价*数量" prop =" price" width =" 150" >
79
+ <el-table-column label =" 商品原价*数量" prop =" price" width =" 150" >
64
80
<template #default =" { row } " >
65
81
{{ floatToFixed2(row.price) }} 元 / {{ row.count }}
66
82
</template >
67
83
</el-table-column >
68
- <el-table-column
69
- class-name =" table-col-3"
70
- label =" 售后状态"
71
- prop =" afterSaleStatus"
72
- width =" 120"
73
- >
84
+ <el-table-column label =" 售后状态" prop =" afterSaleStatus" width =" 120" >
74
85
<template #default =" { row } " >
75
86
<dict-tag
76
87
:type =" DICT_TYPE.TRADE_ORDER_ITEM_AFTER_SALE_STATUS"
77
88
:value =" row.afterSaleStatus"
78
89
/>
79
90
</template >
80
91
</el-table-column >
81
- <el-table-column
82
- align =" center"
83
- class-name =" table-col-4"
84
- label =" 实际支付"
85
- min-width =" 120"
86
- prop =" payPrice"
87
- >
92
+ <el-table-column align =" center" label =" 实际支付" min-width =" 120" prop =" payPrice" >
88
93
<template #default >
89
94
{{ floatToFixed2(scope.row.payPrice) + '元' }}
90
95
</template >
91
96
</el-table-column >
92
- <el-table-column class-name = " table-col-5 " label =" 买家/收货人" min-width =" 160" >
97
+ <el-table-column label =" 买家/收货人" min-width =" 160" >
93
98
<template #default >
94
99
<!-- 快递发货 -->
95
100
<div
122
127
</div >
123
128
</template >
124
129
</el-table-column >
125
- <el-table-column align =" center" class-name = " table-col-6 " label =" 配送方式" width =" 120" >
130
+ <el-table-column align =" center" label =" 配送方式" width =" 120" >
126
131
<template #default >
127
132
<dict-tag :type =" DICT_TYPE.TRADE_DELIVERY_TYPE" :value =" scope.row.deliveryType" />
128
133
</template >
129
134
</el-table-column >
130
- <el-table-column align =" center" class-name = " table-col-7 " label =" 订单状态" width =" 120" >
135
+ <el-table-column align =" center" label =" 订单状态" width =" 120" >
131
136
<template #default >
132
137
<dict-tag :type =" DICT_TYPE.TRADE_ORDER_STATUS" :value =" scope.row.status" />
133
138
</template >
134
139
</el-table-column >
135
- <el-table-column
136
- align =" center"
137
- class-name =" table-col-8"
138
- fixed =" right"
139
- label =" 操作"
140
- width =" 160"
141
- >
140
+ <el-table-column align =" center" fixed =" right" label =" 操作" width =" 160" >
142
141
<template #default >
143
142
<slot :row =" scope.row" ></slot >
144
143
</template >
@@ -154,7 +153,7 @@ import { formatDate } from '@/utils/formatTime'
154
153
import { floatToFixed2 } from ' @/utils'
155
154
import * as TradeOrderApi from ' @/api/mall/trade/order'
156
155
import { OrderVO } from ' @/api/mall/trade/order'
157
- import { TableColumnCtx } from ' element-plus'
156
+ import type { TableColumnCtx , TableInstance } from ' element-plus'
158
157
import { createImageViewer } from ' @/components/ImageViewer'
159
158
import type { DeliveryPickUpStoreVO } from ' @/api/mall/trade/delivery/pickUpStore'
160
159
@@ -208,6 +207,29 @@ const spanMethod = ({ row, rowIndex, columnIndex }: SpanMethodProps): spanMethod
208
207
}
209
208
}
210
209
210
+ /** 解决 ref 在 v-for 中的获取问题*/
211
+ const setOrderTableRef = (el : TableInstance ) => {
212
+ if (! el ) return
213
+ // 只要第一个表也就是开始的第一行
214
+ if (el .tableId !== ' el-table_2' ) {
215
+ return
216
+ }
217
+ tableHeadWidthAuto (el )
218
+ }
219
+ // 头部 col 宽度初始化
220
+ const orderTableHeadWidthList = ref ([300 , 150 , 120 , 120 , 160 , 120 , 120 , 160 ])
221
+ // 头部宽度自适应
222
+ const tableHeadWidthAuto = (el : TableInstance ) => {
223
+ const columns = el .store .states .columns .value
224
+ if (columns .length === 0 ) {
225
+ return
226
+ }
227
+ columns .forEach ((col : TableColumnCtx <TableInstance >, index : number ) => {
228
+ if (col .realWidth ) {
229
+ orderTableHeadWidthList .value [index ] = col .realWidth
230
+ }
231
+ })
232
+ }
211
233
/** 商品图预览 */
212
234
const imagePreview = (imgUrl : string ) => {
213
235
createImageViewer ({
0 commit comments