2024-08-20 12:11:31 +00:00
|
|
|
|
<template>
|
|
|
|
|
<basic-table ref="table" :data="specList" v-bind="tableProps">
|
|
|
|
|
<slot></slot>
|
2024-08-21 01:17:14 +00:00
|
|
|
|
<el-table-column sortable v-for="item in columnProps" :prop="item.value" show-overflow-tooltip :label="item.label" :key="item.value" width="150px"> </el-table-column>
|
2024-08-20 12:11:31 +00:00
|
|
|
|
<el-table-column show-overflow-tooltip label="参考价格" v-if="showPrice">
|
2024-08-21 01:17:14 +00:00
|
|
|
|
<template v-slot="scope"> {{ getPrice(scope.row, mode) }} 元/ {{ modeUnitFilter(mode) }} </template>
|
2024-08-20 12:11:31 +00:00
|
|
|
|
</el-table-column>
|
|
|
|
|
<slot name="append"></slot>
|
|
|
|
|
<div slot="pagination"></div>
|
|
|
|
|
</basic-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { computed, defineComponent } from 'vue'
|
|
|
|
|
import { getPrice, modeUnitFilter } from './utils'
|
|
|
|
|
interface IColumnProps {
|
2024-08-21 01:17:14 +00:00
|
|
|
|
label: string
|
2024-08-20 12:11:31 +00:00
|
|
|
|
value: string
|
|
|
|
|
}
|
|
|
|
|
type IProps = {
|
2024-08-21 01:17:14 +00:00
|
|
|
|
skus: any[]
|
|
|
|
|
mode: string
|
2024-08-20 12:11:31 +00:00
|
|
|
|
columnProps: IColumnProps[]
|
|
|
|
|
}
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
props: {
|
|
|
|
|
skus: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: function () {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mode: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'Hour'
|
|
|
|
|
},
|
|
|
|
|
showPrice: {
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
columnProps: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: function () {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
label: 'CPU(核)',
|
|
|
|
|
value: 'cpu'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '内存(GB)',
|
|
|
|
|
value: 'memory'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-08-21 01:17:14 +00:00
|
|
|
|
setup(props: IProps, context: any) {
|
2024-08-20 12:11:31 +00:00
|
|
|
|
const specList = computed(() => {
|
2024-08-21 01:17:14 +00:00
|
|
|
|
return props.skus.map((item: any) => {
|
|
|
|
|
const result: any = {}
|
|
|
|
|
item.spec.forEach((cell: any) => {
|
2024-08-20 12:11:31 +00:00
|
|
|
|
result[cell.specName] = Number(cell.specValue)
|
|
|
|
|
})
|
|
|
|
|
return { ...item, ...result }
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
// 规格高度的计算
|
|
|
|
|
const tableProps = computed(() => {
|
2024-08-21 01:17:14 +00:00
|
|
|
|
const [{ value } = { value: '' }] = props.columnProps
|
2024-08-20 12:11:31 +00:00
|
|
|
|
const prop: any = {
|
|
|
|
|
defaultSort: {
|
|
|
|
|
prop: value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const length = props.skus.length
|
|
|
|
|
if (length >= 6) {
|
|
|
|
|
prop.height = '260'
|
|
|
|
|
}
|
|
|
|
|
return prop
|
|
|
|
|
})
|
|
|
|
|
return {
|
|
|
|
|
specList,
|
|
|
|
|
tableProps,
|
|
|
|
|
getPrice,
|
|
|
|
|
modeUnitFilter
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|