<template>
    <!-- 关闭计划-->
    <a-modal class="commonModal fieldsetDialog plan_uncommitted_delete" title="关闭计划" centered v-model:visible="visible"
        :maskClosable="false" @cancel="cancel(false)" width="890px">
        <template #footer>
            <a-button key="cancel" class="cancelBtn" :loading="loading" @click="cancel(false)">取消</a-button>
            <a-button key="submit" type="primary" :loading="loading" @click="submit">关闭</a-button>
        </template>
        <a-form class="inlineForm">
            <fieldset class="formFieldSet">
                <legend>购销计划</legend>
                <a-row :gutter="24">
                    <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.hedgeplanno) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="现货品种">
                            <span class="white">{{ formatValue(selectedRow.deliverygoodsname) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="商品">
                            <span class="white">{{ formatValue(selectedRow.wrstandardname) }}</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-col :span="12" v-if="false">
                        <a-form-item label="交易用户">
                            <span class="white">{{ formatValue(selectedRow.tradeusername) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="结算币种">
                            <span class="white">{{ formatValue(selectedRow.currencyname) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="状态">
                            <span class="white">{{ formatValue(getPlanStatusName(selectedRow.hedgeplanstatus)) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="备注">
                            <span class="white">{{ formatValue(selectedRow.remark) }}</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="审核时间">
                            <span class="white">{{ formatValue(selectedRow.audittime) }}</span>
                        </a-form-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-item label="审核人">
                            <span class="white">{{ formatValue(selectedRow.auditname) }}</span>
                        </a-form-item>
                    </a-col>
                </a-row>
                <a-row :gutter="24">
                    <a-col :span="12">
                        <a-form-item label="审核意见">
                            <span class="white">{{ formatValue(selectedRow.auditremark) }}</span>
                        </a-form-item>
                    </a-col>
                </a-row>
            </fieldset>
        </a-form>
    </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { Ermcp3HedgePlan } from '@/services/go/ermcp/plan/interface';
import { formatValue } from '@/common/methods';
import { getPlanContractType, getPlanStatusName } from '@/views/business/plan/setup';
import { Modal } from 'ant-design-vue';
import { HedgePlanCloseReq } from '@/services/proto/hedgeplan/interface';
import * as Long from 'long';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { hedgePlanCloseReq } from '@/services/proto/hedgeplan';
import { getPayCurrencyTypeEnumList } from '@/common/constants/enumsList';
import { _closeModal } from '@/common/setup/modal/modal';
import { v4 } from "uuid";

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

        const submit = () => {
            Modal.confirm({
                title: '是否确认关闭',
                okText: '确认关闭',
                cancelText: '取消',
                onOk() {
                    const params: HedgePlanCloseReq = {
                        HedgePlanID: Long.fromString(props.selectedRow.hedgeplanid),
                        ClientTicket: v4(),
                    }
                    requestResultLoadingAndInfo(hedgePlanCloseReq, params, loading, ['关闭成功', '关闭失败:']).then(() => {
                        cancel(true);
                    })
                }
            })
        }

        return {
            visible,
            loading,
            cancel,
            submit,
            formatValue,
            getPlanContractType,
            getPayCurrencyTypeEnumList,
            getPlanStatusName,
        };
    },
});
</script>