<template>
  <!-- 现货合同正常完结-->
  <a-modal class="commonModal custom-finish"
           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 { spotContractStatus } from '@/services/proto/spotcontract';
import { _closeModal } from '@/common/setup/modal/modal';

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

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