<template>
    <!-- 套期交易-套期项目关联-计划关联项目 -->
    <a-modal class="commonModal custom-detail" title="关联套期项目" v-model:visible="visible" centered @cancel="cancel(false)"
        :maskClosable="false" width="890px">
        <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.hedgeplanno }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="商品">
                            <span class="white">{{ selectedRow.wrstandardname }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="类型">
                            <span class="white">{{ getPlanContractType(selectedRow.contracttype) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="结算币种">
                            <span class="white">{{ formatValue(selectedRow.enumdicname) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="计划量">
                            <span class="white">{{ formatValue(selectedRow.planqty) }}</span>
                        </a-form-item>
                    </a-col>
                </a-row>
            </fieldset>
            <fieldset class="formFieldSet">
                <legend>关联信息</legend>
                <a-row :gutter="24">
                    <a-col :span="12">
                        <a-form-item label="现货市价" required>
                            <span class="white">
                                <a-input-number class="dialogInput" size="small" v-model:value="marketPrice"
                                    style="width:100px" />
                            </span>
                        </a-form-item>
                    </a-col>
                </a-row>
                <div class="tableDatas">
                    <a-table class="dialogTable" :columns="columns" :data-source="tableList" :pagination="false"
                        :loading="loading" :rowKey="(record, index) => index" :row-selection="rowSelection">
                        <!-- 套期类型 -->
                        <template #hedgedtype="{ text }">
                            <span>{{ getHedgedTypeName(text) }}</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 { UnLinkErmcpHedgePlanRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { getHedgedTypeName } from '@/@next/constants/enum/hedgedType'
import { getPlanContractType } from '@/views/business/plan/setup'
import { useForm } from './form'

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

        return {
            visible,
            loading,
            tableList,
            columns,
            marketPrice,
            cancel,
            formatValue,
            rowSelection,
            getPlanContractType,
            getHedgedTypeName,
            formSubmit,
        }
    }
})
</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>