<!-- 我的仓储-我的库存 -->
<template>
    <app-view>
        <template #header>
            <app-filter v-bind="{ selectList, inputList, buttonList }" :loading="loading" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="columns" :loading="loading">
            <template #header>
                <app-auth-operation :menus="headerButtons" @closed="getDiamondList" />
            </template>
            <!-- 价格 -->
            <template #price="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.price) }}
            </template>
            <!-- 克拉单价 -->
            <template #priceper="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.priceper) }}
            </template>
            <!-- 颜色 -->
            <template #zscolortype="{ row }">
                {{ [row.zscolortype1display, row.zscolortype2display].join('-') }}
            </template>
            <!-- 净度 -->
            <template #zsclaritytype="{ row }">
                {{ [row.zsclaritytype1display, row.zsclaritytype2display].join('-') }}
            </template>
            <!-- 是否下架 -->
            <template #marketflag="{ value }">
                {{ value === 1 ? '是' : '否' }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation :menus="handleTableButtons(row)" :options="{ selectedRow: row }"
                    @closed="getDiamondList" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="getDiamondList" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { formatDecimal } from '@/filters'
import { useDiamond } from '@/business/goods'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'

const { loading, dataList, total, pageIndex, pageSize, columns, selectList, inputList, buttonList, getDiamondList } = useDiamond()
const headerButtons = ['add', 'sell']

const handleTableButtons = (row: Ermcp.MyWRPositionRsp) => {
    if (row.marketflag === 1) {
        return ['details', 'pull']
    }
    return ['details', 'put', 'delete']
}

getDiamondList().catch((err) => ElMessage.error(err))
</script>