<template>
    <!-- 套期交易-期货成交关联-补单关联 -->
    <a-modal class="commonModal custom-detail" title="期现单据关联" v-model:visible="visible" centered @cancel="cancel(false)"
        :maskClosable="false" width="1000px">
        <a-form class="inlineForm">
            <fieldset class="formFieldSet">
                <legend>成交单信息</legend>
                <a-row :gutter="24">
                    <a-col :span="12">
                        <a-form-item label="期货合约">
                            <span class="white">{{ selectedRow.accountname + '/' + selectedRow.accountid }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="方向">
                            <span class="white">{{ selectedRow.goodscode + '/' + selectedRow.goodsname }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="期货子账户">
                            <span class="white">{{ getChannelBuildName(selectedRow.channelbuildtype) }} {{
                                    getBuyOrSellName(selectedRow.buyorsell)
                            }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="建平">
                            <span class="white">{{ formatValue(selectedRow.tradeprice) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="成交价">
                            <span class="white">{{ formatValue(selectedRow.tradelot) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="成交数量">
                            <span class="white">{{ formatValue(selectedRow.tradetime) }}</span>
                        </a-form-item>
                    </a-col>
                </a-row>
            </fieldset>
            <fieldset class="formFieldSet">
                <legend>关联信息</legend>
                <div class="tableDatas">
                    <a-table class="dialogTable" :columns="columns" :data-source="tableList" :pagination="false"
                        :loading="loading" :rowKey="(record, index) => index" :row-selection="rowSelection">
                        <template #wrstandardname="{ record }">
                            <span>{{ record.deliverygoodsname }}/{{ record.wrstandardname }}</span>
                        </template>
                        <template #relatedlot="{ record, index }">
                            <a-input-number class="dialogInput" size="small"
                                :disabled="!selectedRowKeys.includes(index)" :precision="0"
                                v-model:value="record.relatedlot" style="width:80px" />
                        </template>
                        <template #relatedqty="{ record }">
                            <span>{{ calcRelatedqty(record) }}</span>
                        </template>
                    </a-table>
                </div>
            </fieldset>
        </a-form>
        <template #footer>
            <a-button key="submit" class="cancelBtn" :loading="loading" @click="cancel(false)">取消</a-button>
            <a-button key="submit" type="primary" :loading="loading" @click="formSubmit(() => cancel(true))">确定
            </a-button>
        </template>
    </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import { _closeModal } from '@/common/setup/modal/modal'
import { formatValue } from '@/common/methods'
import { getChannelBuildName, getBuyOrSellName } from '@/common/constants/enumsName'
import { InternalUncorrelatedTradeDetailRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { useForm } from './form'

export default defineComponent({
    emits: ['cancel'],
    props: {
        selectedRow: {
            type: Object as PropType<InternalUncorrelatedTradeDetailRsp>,
            required: true
        },
    },
    setup(props, context) {
        const { visible, cancel } = _closeModal(context);
        const { loading, tableList, columns, currentQty, selectedRowKeys, rowSelection, calcRelatedqty, formSubmit } = useForm(props.selectedRow);

        return {
            visible,
            loading,
            tableList,
            columns,
            cancel,
            formatValue,
            currentQty,
            selectedRowKeys,
            rowSelection,
            calcRelatedqty,
            formSubmit,
            getBuyOrSellName,
            getChannelBuildName,
        }
    }
})
</script>

<style lang="less">
.custom-detail {
    .ant-modal-body {
        padding-top: 0;
        padding-left: 0;
        padding-right: 0;
    }

    .tableDatas {
        margin-top: 26px;
        padding: 0;
        overflow: hidden;

        .dialogTable {
            width: 100%;
            max-height: 230px;
            overflow-x: auto !important;
        }
    }

    .ant-form.inlineForm {
        margin-top: 20px;
        padding: 0 24px;
    }
}
</style>