<template>
  <!-- 现货合同撤销-->
  <a-modal class="add-custom custom-detail commonModal addSpotVariety"
           title="现货合同撤销"
           v-model:visible="visible"
           centered
           :maskClosable="false"
           @cancel="cancel"
           width="890px">
    <template #footer>
      <a-button key="submit"
                class="cancelBtn"
                :loading="loading"
                :disabled="loading"
                @click="cancel">取消</a-button>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                :disabled="loading"
                @click="submit">确认撤销</a-button>
    </template>
    <InfoDetail :selectedRow="selectedRow"
                :businessManager="businessManager" />
  </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { Ermcp3ContractRsp } from '@/services/go/ermcp/spot-contract/interface';
import { Modal } from 'ant-design-vue';
import { SpotContractOperateReq } from '@/services/proto/spotcontract/interface';
import InfoDetail from '../infoDetail/index.vue';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { orderContract } from '@/services/proto/spotcontract';
import { ErmcpLoginUserEx } from '@/services/go/ermcp/account/interface';
import { _closeModal } from '@/common/setup/modal/modal';

export default defineComponent({
    name: 'spot-contract-detail',
    components: { InfoDetail },
    emits: ['cancel', 'update'],
    props: {
        selectedRow: {
            type: Object as PropType<Ermcp3ContractRsp>,
            default: {},
        },
        businessManager: {
            type: Array as PropType<ErmcpLoginUserEx[]>,
            default: [],
        },
    },
    setup(props, context) {
        const { visible, cancel } = _closeModal(context);
        const loading = ref<boolean>(false);
        const maskClosableFlag = ref<boolean>(false);
        function submit() {
            Modal.confirm({
                title: '是否确认撤销',
                okText: '确认撤销',
                cancelText: '取消',
                onOk() {
                    const reqParam: SpotContractOperateReq = {
                        SpotContractID: props.selectedRow.spotcontractid,
                        OperateType: 6,
                        Remark: '',
                    };
                    // Fixme 6/4 代码修改
                    // 撤销  操作类型-1:保存草稿2:提交申请3:删除4:审核通过5:审核拒绝6:撤销
                    requestResultLoadingAndInfo(orderContract, reqParam, loading, ['撤销成功', '撤销失败:']).then(() => {
                        cancel(true);
                    });
                },
                onCancel() {},
            });
        }
        return {
            visible,
            cancel,
            submit,
            loading,
            maskClosableFlag,
        };
    },
});
</script>

<style lang="less">
.custom-detail {
    .upload {
        .look {
            margin-left: 0;
        }
    }
}
</style>;
