import { _ as $ } 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 j } from "./BasicForm-dL_oCSPM.js";
import { g as S } from "./storageLocation-CpgPSQOH.js";
import { a as v, o as G } from "./materialsStock-DZo3mecL.js";
import { V as M, gL as Z, r as l, bk as P, bi as z, bS as J, d as K, c as Q, o as X, l as w, w as x, j as _, W as Y, ac as ee, cZ as oe, gI as k, __tla as __tla_0 } from "./index-9PRMimni.js";
import { s as te } from "./some-vU4SVDLd.js";
import { u as ae } from "./useModal-CO65vga3.js";
import { u as ne } from "./useForm-CKmgcynv.js";
import { o as se } from "./omit-B2_8Y6O_.js";
let Ne;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const le = P(), { t: e } = M(), re = await Z("outInventory_Type"), ce = re.filter((o)=>![
            "7",
            "8",
            "9",
            "10"
        ].includes(o.value)), L = l(!1), ie = l([]);
    z(async (o)=>{
        L.value = !0, new Promise((r)=>{
            setTimeout(()=>{
                r([
                    {
                        label: "PR-001-这是一条假数据",
                        value: "PR-001"
                    }
                ]);
            }, 1e3);
        }).then((r)=>{
            ie.value = r;
        }).finally(()=>{
            L.value = !1;
        });
    }, 500);
    const g = l(), b = l(), y = l(), h = l();
    function ue({ storageLocationRoom: o, storageLocationShelf: r, storageLocationBox: m, validateStorageLocation: p, currentParams: f }) {
        return [
            {
                field: "materialId",
                hidden: !0
            },
            {
                field: "shipId",
                hidden: !0
            },
            {
                field: "poNo",
                hidden: !0
            },
            {
                field: "category",
                label: e("materialsStock.outStockModal.category"),
                component: "NInput",
                componentProps: {
                    disabled: !0,
                    placeholder: e("common.autoPlaceholderText")
                }
            },
            {
                field: "subCategory",
                label: e("materialsStock.outStockModal.subCategory"),
                component: "NInput",
                componentProps: {
                    disabled: !0,
                    placeholder: e("common.autoPlaceholderText")
                }
            },
            {
                field: "sectionCode",
                label: e("materialsStock.outStockModal.section"),
                component: "NInput",
                componentProps: {
                    disabled: !0,
                    placeholder: e("common.autoPlaceholderText")
                }
            },
            {
                field: "description",
                label: e("materialsStock.outStockModal.itemDescription"),
                component: "NInput",
                componentProps: {
                    disabled: !0,
                    placeholder: e("common.autoPlaceholderText")
                }
            },
            {
                field: "inboundType",
                label: e("materialsStock.outStockModal.outboundType"),
                component: "NSelect",
                componentProps: {
                    options: ce,
                    "label-field": le.getLocale === "en" ? "labelEn" : "label"
                },
                rules: [
                    {
                        required: !0,
                        message: e("materialsStock.outStockModal.outboundTypeRequired"),
                        trigger: "blur"
                    }
                ]
            },
            {
                field: "roomNo",
                label: e("materialsStock.outStockModal.storageLocationRoom"),
                component: "NSelect",
                componentProps: ({ formAction: c })=>{
                    const { setFieldsValue: n } = c;
                    return {
                        options: o.value,
                        onUpdateValue: async (i)=>{
                            g.value = i;
                            const { shipId: u, materialId: d } = f, t = await v({
                                materialId: d.value,
                                shipId: u.value,
                                roomNo: g.value,
                                shelfNo: b.value,
                                boxNo: y.value
                            });
                            h.value = t.quantity, t && n({
                                currencyInventory: t.quantity
                            });
                        }
                    };
                }
            },
            {
                field: "shelfNo",
                label: e("materialsStock.outStockModal.storageLocationShelf"),
                component: "NSelect",
                componentProps: ({ formAction: c })=>{
                    const { setFieldsValue: n } = c;
                    return {
                        options: r.value,
                        onUpdateValue: async (i)=>{
                            b.value = i;
                            const { shipId: u, materialId: d } = f, t = await v({
                                materialId: d.value,
                                shipId: u.value,
                                roomNo: g.value,
                                shelfNo: b.value,
                                boxNo: y.value
                            });
                            h.value = t.quantity, t && n({
                                currencyInventory: t.quantity
                            });
                        }
                    };
                },
                rules: [
                    {
                        validator: ()=>p() ? !0 : new Error(e("materialsStock.outStockModal.storageLocationRequired")),
                        trigger: "change"
                    }
                ]
            },
            {
                field: "boxNo",
                label: e("materialsStock.outStockModal.storageLocationBox"),
                component: "NSelect",
                componentProps: ({ formAction: c })=>{
                    const { setFieldsValue: n } = c;
                    return {
                        options: m.value,
                        onUpdateValue: async (i)=>{
                            y.value = i;
                            const { shipId: u, materialId: d } = f, t = await v({
                                materialId: d.value,
                                shipId: u.value,
                                roomNo: g.value,
                                shelfNo: b.value,
                                boxNo: y.value
                            });
                            h.value = t.quantity, t && n({
                                currencyInventory: t.quantity
                            });
                        }
                    };
                }
            },
            {
                field: "currencyInventory",
                label: e("materialsStock.outStockModal.currencyInventory"),
                component: "NInput",
                componentProps: {
                    placeholder: e("common.autoPlaceholderText"),
                    disabled: !0
                }
            },
            {
                field: "quantity",
                label: e("materialsStock.outStockModal.quantity"),
                component: "NInputNumber",
                componentProps: {
                    min: .01,
                    max: h,
                    precision: 2
                },
                rules: [
                    {
                        required: !0,
                        validator: (c, n)=>n == null || n === "" ? new Error(e("materialsStock.outStockModal.quantityRequired")) : n > h.value ? new Error(e("materialsStock.outStockModal.stockNotEnoughText")) : !0,
                        trigger: "blur"
                    }
                ]
            },
            {
                field: "remarks",
                label: e("materialsStock.outStockModal.remarks"),
                component: "NInput",
                giProps: {
                    span: 4
                },
                componentProps: {
                    type: "textarea"
                },
                rules: [
                    {
                        required: !0,
                        message: e("materialsStock.outStockModal.remarksRequired"),
                        trigger: "blur"
                    }
                ]
            }
        ];
    }
    const I = P();
    function de(o) {
        return {
            materialId: o.materialId,
            shipId: o.shipId,
            category: I.getLocale === "en" ? o.categoryLabelEn : o.categoryLabel,
            subCategory: I.getLocale === "en" ? o.subLabelEn : o.subLabel,
            sectionCode: I.getLocale === "en" ? o.sectionLabelEn : o.sectionLabel,
            description: o.description,
            quantity: 1
        };
    }
    function me({ fields: o, record: r }) {
        return te(o, (m)=>!!(J(r, m) ?? !1));
    }
    Ne = K({
        __name: "index",
        emits: [
            "refresh"
        ],
        setup (o, { expose: r, emit: m }) {
            const { t: p } = M(), f = oe(), c = m, n = l(), i = l(), u = l(), d = l(), t = l(), [T, { openModal: q, closeModal: B, setSubLoading: R }] = ae({
                title: p("materialsStock.outStockModal.title"),
                subBtuText: p("common.saveText"),
                width: 1200
            }), [C, { setFieldsValue: V, validate: F, getFieldsValue: N }] = ne({
                gridProps: {
                    cols: 4
                },
                schemas: ue({
                    storageLocationRoom: n,
                    storageLocationShelf: i,
                    storageLocationBox: u,
                    validateStorageLocation: A,
                    currentParams: {
                        materialId: d,
                        shipId: t
                    }
                }),
                showAdvancedButton: !1
            });
            async function E(a) {
                q(), ee(()=>{
                    t.value = a.shipId, d.value = a.materialId, D(), V(de(a));
                });
            }
            async function O() {
                try {
                    await F();
                    const a = N();
                    await G({
                        ...se(a, [
                            "category",
                            "subCategory",
                            "sectionCode",
                            "description",
                            "currencyInventory"
                        ])
                    }), f.success(p("common.optionsSuccessText")), c("refresh"), B();
                } catch  {
                    R(!1);
                }
            }
            async function D() {
                try {
                    await S({
                        shipId: t.value,
                        warehouseType: "0"
                    }).then((a)=>{
                        n.value = k(a.list, (s)=>({
                                label: s.warehouseName,
                                value: s.id,
                                item: s
                            }));
                    }), await S({
                        shipId: t.value,
                        warehouseType: "1"
                    }).then((a)=>{
                        i.value = k(a.list, (s)=>({
                                label: s.warehouseName,
                                value: s.id,
                                item: s
                            }));
                    }), await S({
                        shipId: t.value,
                        warehouseType: "2"
                    }).then((a)=>{
                        u.value = k(a.list, (s)=>({
                                label: s.warehouseName,
                                value: s.id,
                                item: s
                            }));
                    });
                } catch (a) {
                    console.error(a);
                }
            }
            function A() {
                const a = N();
                return me({
                    fields: [
                        "roomNo",
                        "shelfNo",
                        "boxNo"
                    ],
                    record: a
                });
            }
            return r({
                handleOpenModal: E
            }), (a, s)=>{
                const U = j, H = Y, W = $;
                return X(), Q(W, {
                    ref: "modalRef",
                    onRegister: w(T),
                    onOnOk: O
                }, {
                    default: x(()=>[
                            _(H, {
                                class: "proCard"
                            }, {
                                default: x(()=>[
                                        _(U, {
                                            onRegister: w(C),
                                            showActionButtonGroup: !1,
                                            showSubmitButton: !1,
                                            showResetButton: !1
                                        }, null, 8, [
                                            "onRegister"
                                        ])
                                    ]),
                                _: 1
                            })
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { Ne as _, __tla };
