<!-- 预售大厅-我参与的预售-详情 -->
<template>
    <app-drawer title="详情" :width="960" v-model:show="show">
        <app-table-details title="预售信息" :label-width="140" :data="selectedRow" :cell-props="details1" :column="2">
            <!-- 认购数量 -->
            <template #orderqty="{ value }">
                {{ value }} (克拉)
            </template>
            <!-- 预售价格 -->
            <template #tradeprice="{ value }">
                {{ value }} (元/克拉)
            </template>
            <!-- 采购保证金比例 -->
            <template #marginvalue="{ value }">
                {{ parsePercent(value) }}
            </template>
            <!-- 履约方式 -->
            <template #performancetemplateid="{ value }">
                <app-performance-rule :item="getPerformanceTemplateById(value)" />
            </template>
        </app-table-details>
        <app-table-details title="钻石参考信息" :label-width="140" :data="selectedRow" :cell-props="details2" :column="2">
            <!-- 生产方式 -->
            <template #ysproductionmode="{ value }">
                {{ handleNumberValue(getYSProductionModeName(value)) }}
            </template>
            <!-- 图片 -->
            <template #pictureurls>
                <template v-for="(url, index) in imageUrl" :key="index">
                    <el-image :src="url" :preview-src-list="imageUrl" fit="cover" />
                </template>
            </template>
        </app-table-details>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, reactive, PropType, onMounted } from 'vue'
import { getFileUrl, parsePercent, handleNumberValue } from '@/filters'
import { getYSProductionModeName } from '@/constants/presale'
import { usePerformanceStore } from '@/stores'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTableDetails from '@pc/components/base/table-details/index.vue'
import AppPerformanceRule from '@pc/components/modules/performance-rule/index.vue'

const props = defineProps({
    selectedRow: {
        type: Object as PropType<Ermcp.GZMyTradingPreSellRsp>,
        required: true
    },
})

const { getPerformanceTemplateById } = usePerformanceStore()
const show = shallowRef(true)
const imageUrl = reactive<string[]>([])

const details1 = [
    { prop: 'wrstandardname', label: '商品名称：' },
    { prop: 'customername', label: '发售方：' },
    { prop: 'orderqty', label: '认购数量：' },
    { prop: 'tradeprice', label: '预售价格：' },
    { prop: 'tradeamount', label: '认购货款：' },
    { prop: 'marginvalue', label: '保证金比例：' },
    { prop: 'freezemargin', label: '保证金：' },
    { prop: 'ordertime', label: '认购时间：' },
    { prop: 'performancetemplateid', label: '履约方式：', entireRow: true },
]

const details2 = [
    { prop: 'zscolortypestr', label: '颜色：' },
    { prop: 'sizestr', label: '尺寸：' },
    { prop: 'zsclaritytypestr', label: '净度：' },
    { prop: 'yieldrate', label: '成品率：' },
    { prop: 'qtydesc', label: '数量描述：' },
    { prop: 'weightdesc', label: '重量描述：' },
    { prop: 'ysproductionmode', label: '生产方式：' },
    { prop: 'pictureurls', label: '图片：', entireRow: true },
    { prop: 'remark', label: '备注：', entireRow: true },
]

onMounted(() => {
    const images = props.selectedRow.pictureurls.split(',')
    images.forEach((url) => {
        if (url) {
            imageUrl.push(getFileUrl(url))
        }
    })
})
</script>

<style lang="less" scoped>
.el-image {
    width: 64px;
    height: 64px;
    border: 1px solid #ccc;

    +.el-image {
        margin-left: 10px;
    }
}
</style>