import { _ as M } from "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { B as O } from "./BasicForm-dL_oCSPM.js";
import { u as T } from "./useForm-CKmgcynv.js";
import { r as u, V as v, a4 as C, l as P, aD as V, hc as B, d as E, c as L, o as A, w as G, j, ac as W, cZ as U, __tla as __tla_0 } from "./index-9PRMimni.js";
import { a as z } from "./jobOrder-CGbsc7bp.js";
import { u as Y } from "./useModal-CO65vga3.js";
import { i as Z } from "./isEmpty-BUg1OsQj.js";
import { i as $ } from "./isNumber-D5aBrEhN.js";
let me, se;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const F = await B(), H = F && F.length > 0 ? F[0].id : "", { t: e } = v();
    se = function() {
        const r = u(!1), p = u(0), s = [
            {
                field: "isRun",
                component: "NSelect",
                label: e("defectFormPage.comments.equipmentOperational"),
                giProps: {
                    span: 6
                },
                labelWidth: 200,
                componentProps: ({ formAction: i })=>{
                    const { getFieldsValue: o } = i;
                    return p.value = o().isRun, {
                        options: [
                            {
                                label: e("common.yes"),
                                value: 1
                            },
                            {
                                label: e("common.no"),
                                value: 0
                            }
                        ],
                        disabled: P(r),
                        onUpdateValue: (t)=>{
                            p.value = t;
                        },
                        labelWidth: 100
                    };
                }
            },
            {
                field: "backupCondition",
                component: "NRadioGroup",
                label: e("defectFormPage.comments.conditionOfRedundantEquipment"),
                giProps: {
                    span: 12
                },
                labelWidth: 360,
                componentProps: {
                    disabled: r,
                    options: [
                        {
                            label: "Good",
                            value: 1
                        },
                        {
                            label: "Fair",
                            value: 2
                        },
                        {
                            label: "Poor",
                            value: 3
                        }
                    ]
                },
                rules: [
                    {
                        required: C(()=>p.value == 0),
                        message: e("common.RequireTips")
                    }
                ]
            },
            {
                field: "equipmentRemark",
                component: "NInput",
                label: e("defectFormPage.comments.remarks"),
                giProps: {
                    span: 24
                },
                componentProps: {
                    type: "textarea",
                    disabled: r
                },
                rules: [
                    {
                        required: !0,
                        message: e("common.RequireTips"),
                        trigger: [
                            "blur",
                            "change"
                        ]
                    }
                ]
            },
            {
                field: "completeDate",
                component: "NDatePicker",
                label: e("defectFormPage.comments.estimatedRepairCompletionDate"),
                giProps: {
                    span: 8
                },
                componentProps: {
                    disabled: r,
                    valueFormat: "yyyy-MM-dd"
                },
                rules: [
                    {
                        required: !0,
                        message: e("common.RequireTips"),
                        trigger: [
                            "blur",
                            "change"
                        ]
                    }
                ]
            },
            {
                field: "riskAssessRequired",
                component: "NSelect",
                label: e("defectFormPage.comments.riskAssessmentRequired"),
                giProps: {
                    span: 4
                },
                componentProps: {
                    options: [
                        {
                            label: e("common.yes"),
                            value: 1
                        },
                        {
                            label: e("common.no"),
                            value: 0
                        }
                    ],
                    disabled: r
                },
                rules: [
                    {
                        required: !0,
                        message: e("common.RequireTips"),
                        trigger: [
                            "blur",
                            "change"
                        ],
                        type: "any"
                    }
                ]
            },
            {
                field: "workPermitRequired",
                component: "NSelect",
                label: e("defectFormPage.comments.workPermitRequired"),
                giProps: {
                    span: 4
                },
                componentProps: {
                    options: [
                        {
                            label: e("common.yes"),
                            value: 1
                        },
                        {
                            label: e("common.no"),
                            value: 0
                        }
                    ],
                    disabled: r
                },
                rules: [
                    {
                        required: !0,
                        message: e("common.RequireTips"),
                        trigger: [
                            "blur",
                            "change"
                        ],
                        type: "any"
                    }
                ]
            },
            {
                field: "remark",
                component: "NInput",
                label: e("defectFormPage.comments.remark"),
                giProps: {
                    span: 24
                },
                componentProps: {
                    type: "textarea",
                    disabled: r
                }
            },
            {
                field: "spareRequired",
                component: "NRadioGroup",
                label: e("defectFormPage.comments.sparePartsRequired"),
                giProps: {
                    span: 24
                },
                slot: "sparePartsRequiredSlot",
                componentProps: {
                    disabled: r,
                    options: [
                        {
                            label: "YES",
                            value: 1
                        },
                        {
                            label: "NO",
                            value: 0
                        }
                    ]
                },
                rules: [
                    {
                        required: !0,
                        message: e("common.RequireTips"),
                        trigger: [
                            "blur",
                            "change"
                        ],
                        type: "any"
                    }
                ]
            }
        ];
        return {
            formSchemas: s,
            getSchema: (i)=>s.find((o)=>o.field === i),
            methods: {
                updataReadOnly: (i)=>{
                    r.value = i;
                }
            }
        };
    };
    function J(r) {
        const p = V(async (o, t, b)=>{
            t.value = !0;
            try {
                const l = P(r.equipmentInfo), c = await z({
                    shipId: H,
                    equipmentCode: l ? l.equipmentCode : void 0,
                    model: l ? l.model : void 0,
                    ...o
                });
                if (console.log(c, 88888888), t.value = !1, c) {
                    console.log(c);
                    const h = c.list && c.list.length > 0 ? c.list.map((d)=>({
                            label: d.partNumber + "--" + d.partName + "--" + d.itemDescription,
                            value: d
                        })) : [];
                    return b && b(h), h;
                }
            } catch (l) {
                t.value = !1, console.error(l);
            }
        }, 1e3), { t: s } = v(), n = u(!1), g = u([]);
        return {
            approvalSchemas: [
                {
                    field: "itemId",
                    hidden: !0
                },
                {
                    field: "itemDescription",
                    hidden: !0
                },
                {
                    field: "specification",
                    hidden: !0
                },
                {
                    field: "equipmentCode",
                    component: "NInput",
                    label: s("defectFormPage.comments.equipmentCode"),
                    componentProps: {
                        disabled: !0
                    }
                },
                {
                    field: "equipmentName",
                    component: "NInput",
                    label: s("defectFormPage.comments.equipmentName"),
                    componentProps: {
                        disabled: !0,
                        placeholder: s("defectFormPage.comments.equipmentName")
                    }
                },
                {
                    field: "partNumber",
                    component: "NSelect",
                    label: s("jobOrder.partNumberItem"),
                    componentProps: {
                        filterable: !0,
                        options: g,
                        remote: !0,
                        loading: n,
                        clearable: !1,
                        onSearch: async (o)=>{
                            if (!o.length) {
                                n.value = !1;
                                return;
                            }
                            p({
                                NumOrDes: o
                            }, n, (t)=>{
                                console.log(t), t && (g.value = t);
                            });
                        },
                        onUpdateValue: (o)=>{
                            console.log(o);
                            const t = o;
                            t.sparePartNumber = o.partNumber, r.setSparePartsFormData({
                                ...t,
                                raw: o,
                                tableData: void 0,
                                rob: o?.ROB
                            });
                        }
                    }
                },
                {
                    field: "rob",
                    component: "NInput",
                    label: s("defectFormPage.comments.rob"),
                    componentProps: {
                        disabled: !0
                    }
                },
                {
                    field: "quantity",
                    component: "NInputNumber",
                    label: s("defectFormPage.comments.quantity"),
                    componentProps: {
                        min: 1,
                        precision: 0,
                        keyboard: {
                            ArrowUp: !1,
                            ArrowDown: !1
                        },
                        showButton: !1
                    },
                    rules: [
                        {
                            required: !0,
                            validator: (o, t)=>r.validateNumber(),
                            trigger: [
                                "blur"
                            ]
                        }
                    ]
                },
                {
                    field: "remark",
                    component: "NInput",
                    label: s("defectFormPage.comments.remarks"),
                    giProps: {
                        span: 4
                    },
                    componentProps: {
                        type: "textarea"
                    }
                }
            ]
        };
    }
    me = E({
        __name: "NewSparePartsModal",
        emits: [
            "submit-success"
        ],
        setup (r, { expose: p, emit: s }) {
            const { t: n } = v(), g = s, i = u(), o = U(), t = u(), b = u([]), [l, { openModal: c, closeModal: h, setProps: d, setSubLoading: q }] = Y({
                title: n("defectFormPage.comments.plannedOutbound"),
                subBtuText: n("common.okText"),
                cancelText: n("common.cancelText"),
                width: 700
            });
            async function N() {
                c();
            }
            async function R(a, f) {
                if (!a) return;
                b.value = f || [], t.value = {
                    equipmentCode: a.equipmentCode,
                    model: a.equipmentModel
                };
                const m = {
                    ...a
                };
                console.log(m), W(()=>{
                    y(m);
                });
            }
            async function S() {
                try {
                    const a = await I();
                    if (a === !1) {
                        o.warning(n("defectFormPage.comments.failForm")), q(!1);
                        return;
                    }
                    const f = {
                        ...a,
                        description: a.itemDescription
                    };
                    b.value.find((m)=>{
                        if (m.itemId === a.itemId) throw o.warning(n("defectFormPage.comments.partExist")), new Error(n("defectFormPage.comments.partExist"));
                    }), g("submit-success", f), h(), q(!1);
                } catch  {
                    q(!1);
                }
            }
            function w() {
                const a = _(), f = Number(a.rob) || 0, m = a.quantity;
                return Z(m) && !$(m) ? Promise.reject(new Error(n("common.inputText") + " " + n("defectFormPage.comments.quantity"))) : m > f ? Promise.reject(new Error(n("defectFormPage.comments.quantityValidate"))) : Promise.resolve();
            }
            function k(a) {
                y(a);
            }
            const { approvalSchemas: x } = J({
                validateNumber: w,
                setSparePartsFormData: k,
                equipmentInfo: t
            }), [D, { submit: I, setFieldsValue: y, getFieldsValue: _ }] = T({
                layout: "horizontal",
                showActionButtonGroup: !1,
                schemas: x,
                labelWidth: "auto",
                labelPlacement: "top",
                gridProps: {
                    cols: 3,
                    xGap: 45
                }
            });
            return p({
                showModal: N,
                setProps: d,
                getData: R
            }), (a, f)=>{
                const m = M;
                return A(), L(m, {
                    ref: "modalRef",
                    onRegister: P(l),
                    class: "basicModal basicFormModal",
                    onOnOk: S
                }, {
                    default: G(()=>[
                            j(P(O), {
                                ref_key: "contentFromRef",
                                ref: i,
                                onRegister: P(D)
                            }, null, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { me as _, se as c, __tla };
