<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">{{ formatValue(selectedRow.hedgeditemnum) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="项目名称">
                            <span class="white">{{ formatValue(selectedRow.hedgeditemname) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="计划开始">
                            <span class="white">{{ formatValue(selectedRow.planstartdate) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="计划结束">
                            <span class="white">{{ formatValue(selectedRow.planenddate) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="套期类型">
                            <span class="white">{{ getHedgedTypeName(selectedRow.hedgedtype) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="套期主体">
                            <span class="white">{{ formatValue(selectedRow.accountname) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="现货市价" v-if="false">
                            <span class="white">0</span>
                        </a-form-item>
                    </a-col>
                </a-row>
            </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="submit">确认完结</a-button>
        </template>
    </a-modal>
</template>

<script lang="ts">
import { defineComponent, ref, PropType } from 'vue'
import { v4 } from 'uuid'
import Long from 'long'
import { _closeModal } from '@/common/setup/modal/modal'
import { formatValue } from '@/common/methods'
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo'
import { Ermcp2HedgedItemRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { getHedgedTypeName } from '@/@next/constants/enum/hedgedType'
import { hedgedItemEnd } from '@/services/proto/hedgedItem'
import { HedgedItemEndReq } from '@/services/proto/hedgedItem/interface'
import { Modal } from 'ant-design-vue'

export default defineComponent({
    emits: ['cancel'],
    props: {
        selectedRow: {
            type: Object as PropType<Ermcp2HedgedItemRsp>,
            default: () => ({})
        },
    },
    setup(props, context) {
        const { visible, cancel } = _closeModal(context);
        const loading = ref<boolean>(false);

        const submit = () => {
            Modal.confirm({
                title: '是否确认完结',
                okText: '确认完结',
                cancelText: '取消',
                onOk() {
                    const params: HedgedItemEndReq = {
                        HedgedItemID: Long.fromString(props.selectedRow.hedgeditemid),
                        ClientTicket: v4()
                    }
                    requestResultLoadingAndInfo(hedgedItemEnd, params, loading, ['套期项目完结成功', '套期项目完结失败：:']).then(() => {
                        cancel(true);
                    })
                }
            })
        }

        return {
            visible,
            loading,
            cancel,
            formatValue,
            getHedgedTypeName,
            submit,
        }
    }
})
</script>