<template>
  <!-- 现货合同正常完结-->
  <a-modal class="commonModal custom-finish"
           title="现货合同正常完结"
           v-model:visible="visible"
           centered
           :maskClosable="maskClosableFlag"
           @cancel="cancel"
           width="890px">
    <template #footer>
      <a-button key="submit"
                class="cancelBtn"
                @click="cancel">取消</a-button>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                @click="submit">确认完结</a-button>
    </template>
    <InfoDetail :selectedRow="selectedRow" />
  </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { closeModal } from '@/common/setup/modal/index';
import { Ermcp3ContractRsp } from '@/services/go/ermcp/spot-contract/interface';
import { orderContractOperateControl } from '@/views/information/spot-contract/components/setup';
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, spotContractStatus} from "@/services/proto/spotcontract";

export default defineComponent({
    name: 'spot-contract-finish',
    components: { InfoDetail },
    props: {
        selectedRow: {
            type: Object as PropType<Ermcp3ContractRsp>,
            default: {},
        },
    },
    setup(props, context) {
        const { visible, cancel } = closeModal('spot_contract_btn_finish');
        const maskClosableFlag = ref<boolean>(false);
        const loading = ref<boolean>(false);
        function submit() {
            context.emit('refresh');
            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(() => {
                        context.emit('refresh');
                        cancel();
                    });
                },
                onCancel() {
                    console.log('Cancel');
                },
            });
        }
        return {
            visible,
            cancel,
            submit,
            loading,
            maskClosableFlag,
        };
    },
});
</script>

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