import { B as te } from "./BasicForm-dL_oCSPM.js";
import { u as ae } from "./useForm-CKmgcynv.js";
import { _ as se } from "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { u as ie } from "./useModal-CO65vga3.js";
import { u as oe } from "./account-C850CBTF.js";
import { g as re, u as le, a as ce, d as ne } from "./certificate-6_B4mutd.js";
import { c as ue } from "./hook-C9rOLWu_.js";
import { y as de, O as pe } from "./template-rpthWlT9.js";
import { r as c, V as S, bk as fe, d as me, cq as he, u as ge, c as q, o as f, l as r, w as l, i as v, j as m, p as C, A as _, G as be, h as E, D as M, a9 as ye, B as qe, h9 as ve, N as _e, F as Ne, aH as ke, ac as N, __tla as __tla_0 } from "./index-9PRMimni.js";
import { g as we } from "./base64-BbY-I90a.js";
let Oe;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const R = fe(), { t: e } = S(), De = await de(), xe = await pe();
    function Ie() {
        const g = c(!1);
        return {
            schemas: [
                {
                    field: "shipId",
                    component: "NSelect",
                    label: e("hsqe.auditInspection.vesselInspection.formVessel"),
                    componentProps: ()=>({
                            disabled: !0,
                            placeholder: e("hsqe.auditInspection.vesselInspection.formVesselHint"),
                            options: xe,
                            "value-field": "id",
                            "label-field": R.getLocale === "en" ? "shipNameEn" : "shipName"
                        })
                },
                {
                    field: "categoryName",
                    label: e("hsqe.certificate.type"),
                    component: "NInput",
                    componentProps: {
                        disabled: !0
                    }
                },
                {
                    field: R.getLocale === "en" ? "certificateEnglishName" : "certificateChineseName",
                    label: e("hsqe.certificate.Certificatename"),
                    component: "NInput",
                    componentProps: {
                        disabled: !0
                    }
                },
                {
                    field: "validityUnit",
                    component: "NInput",
                    label: e("hsqe.certificate.certificateNon"),
                    componentProps: {
                        placeholder: e("hsqe.certificate.certificateNon"),
                        disabled: !0
                    },
                    hidden: ()=>!0
                },
                {
                    field: "certificateNo",
                    component: "NInput",
                    label: e("hsqe.certificate.certificateNon"),
                    giProps: {
                        span: 1
                    },
                    componentProps: {
                        placeholder: e("hsqe.certificate.certificateNon"),
                        disabled: !0
                    },
                    rules: [
                        {
                            required: !0,
                            message: e("hsqe.certificate.certificateNon"),
                            trigger: [
                                "blur"
                            ]
                        }
                    ]
                },
                {
                    field: "issueDate",
                    component: "NDatePicker",
                    label: e("hsqe.certificate.IssueDate"),
                    labelWidth: 100,
                    componentProps: {
                        placeholder: e("hsqe.certificate.IssueDate"),
                        type: "date",
                        valueFormat: "yyyy-MM-dd",
                        disabled: !0
                    },
                    rules: [
                        {
                            required: !0,
                            message: e("hsqe.certificate.IssueDate"),
                            trigger: [
                                "blur",
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "lastEndorse",
                    component: "NDatePicker",
                    label: e("hsqe.certificate.LastEndorse"),
                    labelWidth: 100,
                    componentProps: {
                        placeholder: e("hsqe.certificate.LastEndorse"),
                        type: "date",
                        valueFormat: "yyyy-MM-dd",
                        disabled: !0
                    },
                    rules: [
                        {
                            required: !0,
                            message: e("hsqe.certificate.LastEndorse"),
                            trigger: [
                                "blur",
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "expireDate",
                    component: "NDatePicker",
                    label: e("hsqe.certificate.ExpireDate"),
                    labelWidth: 100,
                    giProps: {
                        span: 2
                    },
                    componentProps: {
                        placeholder: e("hsqe.certificate.ExpireDate"),
                        type: "date",
                        valueFormat: "yyyy-MM-dd",
                        disabled: !0
                    },
                    hidden: ({ model: s })=>!(s.validityUnit == 2 || s.validityUnit == 3),
                    rules: [
                        {
                            required: !0,
                            message: e("hsqe.certificate.ExpireDate"),
                            trigger: [
                                "blur",
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "remark",
                    component: "NInput",
                    label: e("hsqe.certificate.remark"),
                    giProps: {
                        span: 2
                    },
                    componentProps: {
                        placeholder: e("hsqe.certificate.remark"),
                        type: "textarea",
                        disabled: !0
                    }
                },
                {
                    field: "issueBy",
                    component: "NInput",
                    label: e("hsqe.certificate.issueBy"),
                    giProps: {
                        span: 2
                    },
                    componentProps: {
                        placeholder: e("hsqe.certificate.issueBy"),
                        disabled: !0
                    },
                    rules: [
                        {
                            required: !0,
                            message: e("hsqe.certificate.issueBy"),
                            trigger: [
                                "blur"
                            ]
                        }
                    ]
                },
                {
                    field: "issueBy",
                    label: e("hsqe.certificate.issueBy"),
                    giProps: {
                        span: 2
                    },
                    component: "NSelect",
                    componentProps: {
                        multiple: !1,
                        options: De,
                        filterable: !0,
                        "label-field": "label",
                        "value-field": "label",
                        disabled: !0
                    },
                    hidden: !0,
                    rules: [
                        {
                            required: !0,
                            message: e("hsqe.certificate.issueBy"),
                            trigger: [
                                "blur",
                                "change"
                            ]
                        }
                    ]
                }
            ],
            methods: {
                setReadOnly: (s)=>{
                    g.value = s;
                }
            }
        };
    }
    let Be;
    Be = [
        "onClick"
    ];
    Oe = me({
        __name: "CreateModal",
        props: {
            title: {},
            isEdit: {}
        },
        emits: [
            "success"
        ],
        setup (g, { expose: k, emit: w }) {
            const { t: s } = S(), U = he(), n = ge(), { schemas: T, methods: V } = Ie(), u = c(!1), { setReadOnly: D } = V, x = g, L = w, O = c(), A = c(x.title), o = c([]), d = c(), [W, { submit: G, setFieldsValue: I, getFieldsValue: B }] = ae({
                gridProps: {
                    cols: 2
                },
                collapsed: !1,
                collapsedRows: 12,
                labelWidth: 80,
                layout: "horizontal",
                submitButtonText: s("common.okText"),
                showActionButtonGroup: !1,
                schemas: T
            }), [$, { openModal: z, closeModal: P, setSubLoading: h, setProps: H }] = ie({
                title: A,
                subBtuText: s("common.okText"),
                cancelText: s("common.cancelText"),
                width: 650
            });
            async function b(t, a) {
                if (console.log(a), O.value = t, await N(), t) {
                    const i = await re(t);
                    d.value = i, o.value = i.certificateAttachmentEntities, I({
                        ...i
                    });
                }
                a ? (D(!0), u.value = !1) : (D(!0), u.value = !0);
            }
            async function j() {
                const t = {
                    ...B()
                };
                if (!ue(t.issueDate, t.lastEndorse)) {
                    n.error(s("hsqe.certificate.IssueDateorExpireDate")), h(!1);
                    return;
                }
                if (t.attachment == 0 && o.value.length == 0) {
                    n.error(s("hsqe.certificate.AttachmentRequired")), h(!1);
                    return;
                }
                let a = B();
                if (a.issueDateStr = a.issueDate, a.expireDateStr = a.expireDate, delete a.issueDate, delete a.expireDate, await G()) {
                    const { isEdit: p } = x;
                    h(!1), await le({
                        ...a,
                        id: d.value?.id
                    }), n.success(s(p ? "hsqe.certificate.editsuccess" : "hsqe.certificate.addsuccess")), L("success"), P();
                } else n.error(s("hsqe.certificate.Verificationfailed")), h(!1);
            }
            async function J({ file: t }) {
                console.log(t), o.value = [];
                let a = {
                    id: "",
                    fileUrl: "",
                    fileName: "",
                    createTime: null,
                    certificateId: d.value?.id
                };
                const i = new FormData;
                i.append("file", t.file);
                const p = await oe(i);
                a.fileName = t.name, a.fileUrl = p.url, o.value.push(a), N(()=>{
                    K(o.value[0]);
                });
            }
            async function K(t) {
                await ce(t), N(()=>{
                    o.value = [], b(d.value?.id, !1);
                });
            }
            async function Q(t) {
                await ne(t), b(d.value?.id, !1);
            }
            function X(t) {
                if (t) {
                    const { previewUrl: a } = U;
                    window.open(a + encodeURIComponent(we.encode(t)), "_blank");
                } else n.error(s("hsqe.noticeCircular.fileError"));
            }
            return k({
                openModal: z,
                closeModal: P,
                setFieldsValue: I,
                setProps: H,
                getData: b
            }), (t, a)=>{
                const i = be, p = _e, F = qe, Y = ke;
                return f(), q(r(se), {
                    onRegister: r($),
                    ref: "modalRef",
                    onOnOk: j,
                    showAction: u.value
                }, {
                    default: l(()=>[
                            v("div", null, [
                                m(r(te), {
                                    onRegister: r(W)
                                }, null, 8, [
                                    "onRegister"
                                ])
                            ]),
                            m(i, {
                                "title-placement": "left"
                            }, {
                                default: l(()=>[
                                        C(_(r(s)("hsqe.certificate.Attachment")), 1)
                                    ]),
                                _: 1
                            }),
                            v("div", null, [
                                (f(!0), E(Ne, null, ye(o.value, (y, Z)=>(f(), E("div", {
                                        class: "stock-nav-item ml-4 mb-3",
                                        key: Z
                                    }, [
                                        v("a", {
                                            onClick: (ee)=>X(y.fileUrl || ""),
                                            target: "_blank"
                                        }, _(y.fileName), 9, Be),
                                        u.value ? (f(), q(F, {
                                            key: 0,
                                            text: "",
                                            class: "text-[20px] mt-1 ml-2",
                                            type: "error",
                                            onClick: (ee)=>Q(y.id || "")
                                        }, {
                                            default: l(()=>[
                                                    m(p, null, {
                                                        default: l(()=>[
                                                                m(r(ve))
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 2
                                        }, 1032, [
                                            "onClick"
                                        ])) : M("", !0)
                                    ]))), 128)),
                                u.value ? (f(), q(Y, {
                                    key: 0,
                                    action: "https://www.mocky.io/v2/5e4bafc63100007100d8b70f",
                                    headers: {
                                        "Content-Type": "multipart/form-data"
                                    },
                                    "show-file-list": !1,
                                    "custom-request": J
                                }, {
                                    default: l(()=>[
                                            m(F, null, {
                                                default: l(()=>[
                                                        C(_(r(s)("mdm.mou.uploadFile")), 1)
                                                    ]),
                                                _: 1
                                            })
                                        ]),
                                    _: 1
                                })) : M("", !0)
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister",
                    "showAction"
                ]);
            };
        }
    });
});
export { Oe as _, __tla };
