<template>
    <!-- 违约-->
    <Drawer :title="'违约'" :placement="'bottom'" :visible="visible" @cancel="cancel">
        <div class="listed">
            <a-form class="inlineForm dialogForm" ref="formRef" :model="formState" :rules="rules">
                <div class="formBar">
                    <a-row :gutter="24">
                        <a-col :span="12">
                            <a-form-item label="品种">
                                <span class="white">{{selectedRow.deliverygoodsname}}</span>
                            </a-form-item>
                        </a-col>
                        <a-col :span="12">
                            <a-form-item label="仓库">
                                <span class="white">{{selectedRow.warehousename}}</span>
                            </a-form-item>
                        </a-col>
                        <a-col :span="24">
                            <a-form-item label="履约商品">
                                <span class="white">{{selectedRow.wrtypename}}</span>
                            </a-form-item>
                        </a-col>
                        <a-col :span="24">
                            <a-form-item label="当前步骤">
                                <span class="white">{{selectedRow.curstepname}}</span>
                            </a-form-item>
                        </a-col>
                        <a-col :span="24">
                            <a-form-item label="关联单号">
                                <span class="white">{{selectedRow.relatedorderid}}</span>
                            </a-form-item>
                        </a-col>
                        <!--            <a-col :span="24">-->
                        <!--              <a-form-item label="附件"-->
                        <!--                           name="url">-->
                        <!--                <UploadImg :visible="visible"-->
                        <!--                           :imgList="uploadImgList"-->
                        <!--                           @upload="uploadImgAction" />-->
                        <!--              </a-form-item>-->
                        <!--            </a-col>-->
                        <a-col :span="24">
                            <a-form-item label="备注" name="remark">
                                <a-input
                                    class="commonInput"
                                    v-model:value="formState.remark"
                                    style="width: 100%"
                                />
                            </a-form-item>
                        </a-col>
                    </a-row>
                </div>
                <a-row :gutter="24">
                    <a-col :span="24" class="fixedBtns">
                        <a-form-item class="btnCenter">
                            <a-button
                                class="listedBtn"
                                :loading="loading"
                                :disabled="loading"
                                @click="submit"
                            >提交</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>
    </Drawer>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import Drawer from '@/common/components/drawer/index.vue';
import { WrPerformancePlan, WrPosition } from '@/services/go/wrtrade/interface';
import { ModalEnum } from '@/common/constants/modalNameEnum';
import { _closeModal } from '@/common/setup/modal/modal';
import { handleForm } from './setup';
import { validateAction } from '@/common/setup/form';
import { FormState } from './interface';
import UploadImg from '@/common/components/uploadImg/index.vue';
import { getUploadImg } from '@/common/setup/upload';
import { PerformanceContractedApplyReq, PerformanceDelayApplyReq } from '@/services/proto/performance/interface';
import { getSelectedAccount, getSelectedAccountId, getUserId } from '@/services/bus/account';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { performanceContractedApply, performanceDelayApply } from '@/services/proto/performance';
import { BuyOrSell } from '@/common/constants/enumCommon';
import { handlePerformancePlanStep } from '../setup';
import Long from 'long';

export default defineComponent({
    name: ModalEnum.performance_information_buy_performance_breach_contract,
    components: { Drawer, UploadImg },
    emits: ['cancel', 'update'],
    props: {
        selectedRow: {
            type: Object as PropType<WrPerformancePlan>,
            default: {},
        },
        buyOrSell: {
            type: Number as PropType<BuyOrSell>,
            default: BuyOrSell.buy,
        },
    },
    setup(props, context) {
        const { visible, cancel } = _closeModal(context);
        const loading = ref<boolean>(false);
        const { rules, formState, formRef } = handleForm();
        const { uploadImgAction, uploadImgList, handleImg } = getUploadImg();
        const { performancePlanStep } = handlePerformancePlanStep(props.selectedRow);
        function submit() {
            validateAction<FormState>(formRef, formState).then((param) => {
                // 违约申请
                const paramReq: PerformanceContractedApplyReq = {
                    PerformancePlanID: Long.fromString(props.selectedRow.performanceplanid), // uint64 履约计划ID
                    BreachType: props.selectedRow.buyaccountid === getSelectedAccountId() ? 2 : 1, // uint32 违约方类型 买履约是2 卖履约是1 （刘工说是黄工说的 ）
                    Applicant: getUserId(), // uint64 违约申请人
                    ApplyRemark: param.remark, // string 申请备注
                    Attachment: '', // string 附件
                };
                requestResultLoadingAndInfo(performanceContractedApply, paramReq, loading, ['申请违约成功', '申请违约失败:']).then(() => {
                    cancel(true);
                });
            });
        }
        return {
            visible,
            cancel,
            submit,
            loading,
            rules,
            formState,
            formRef,
            uploadImgAction,
            uploadImgList,
        };
    },
});
</script>

<style lang="less" scoped>
</style>;
