import { _ as ce } 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 de } from "./BasicForm-dL_oCSPM.js";
import { B as me } from "./Table-0PViRYCf.js";
import { _ as fe } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { P as pe, Q as M, O as ve } from "./jobOrder-CGbsc7bp.js";
import { e as be, f as _e, __tla as __tla_0 } from "./index.vue_vue_type_style_index_0_scoped_b974e5ec_lang-_0QwzFKM.js";
import { d as ye, V as ge, f as Ie, r as i, a as he, Z as g, hp as we, cZ as Re, l as o, g as Oe, c as E, o as D, w as u, D as V, j as r, W as Ce, p as T, A as P, h as xe, N as De, ac as q, __tla as __tla_1 } from "./index-9PRMimni.js";
import { u as F } from "./useForm-CKmgcynv.js";
import { u as Te } from "./useModal-CO65vga3.js";
import { i as N } from "./isEmpty-BUg1OsQj.js";
let Je;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    let Pe;
    Pe = {
        key: 0,
        class: "text-red-600 ml-4"
    };
    Je = ye({
        __name: "index",
        props: {
            mode: {}
        },
        emits: [
            "success",
            "rowEditSuccess",
            "tableDataInit"
        ],
        setup (A, { expose: J, emit: Q }) {
            const v = A, b = Q, { t } = ge(), _ = Re(), W = Ie(), { columns: $ } = be(), [G, { setFieldsValue: I, getFieldsValue: h, setProps: Z, validate: z, resetFields: K }] = F({
                gridProps: {
                    cols: 16
                },
                layout: "horizontal",
                showActionButtonGroup: !1
            }), [L, { openModal: X, closeModal: H, setSubLoading: f }] = Te({
                title: t("jobOrder.outbound"),
                width: 1140
            }), w = W.query.shipId, S = i(), p = i(), s = i(), B = i(), j = i(), y = i(!1), c = i(!1), d = i(0), m = i(0), U = he({
                width: 100,
                title: t("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e, a) {
                    return g(fe, {
                        style: "text",
                        actions: Y(e, a)
                    });
                }
            });
            function Y(e, a) {
                return console.log(e), e.editable ? [
                    {
                        label: t("common.saveText"),
                        labelShow: !1,
                        icon: g("i", {
                            class: "iconfont icon-Save"
                        }),
                        onClick: oe.bind(null, {
                            record: e,
                            index: a
                        })
                    },
                    {
                        label: t("common.cancelText"),
                        labelShow: !1,
                        icon: g(we),
                        onClick: te.bind(null, e)
                    }
                ] : [
                    {
                        label: t("common.optionsEditText"),
                        labelShow: !1,
                        icon: g("i", {
                            class: "iconfont icon-a-Frame28"
                        }),
                        onClick: ae.bind(null, e)
                    }
                ];
            }
            function ee({ column: e, value: a, record: n }) {
                e.key === "id" && (n.editValueRefs.name4.value = `${a}`);
            }
            function ae(e) {
                try {
                    if (!s.value) return;
                    for (const a of s.value)if (a.editable) {
                        console.log(a), _.warning(t("jobOrder.editTip"));
                        return;
                    }
                    j.value = e.id, y.value = !0, e.onEdit(!0);
                } catch (a) {
                    console.log(a);
                }
            }
            function te(e) {
                j.value = "", e.onEdit?.(!1, !1), y.value = !1;
            }
            async function oe({ record: e, index: a }) {
                const n = async ()=>{
                    S.value?.reload(), _.success(t("common.saveSuccessText")), await e.onEdit(!1);
                };
                try {
                    if (await e.onEdit(!1, !0)) if (p.value = "", y.value = !1, v.mode === "unPlannedJob") b("rowEditSuccess", {
                        record: e,
                        index: a,
                        done: n
                    });
                    else {
                        const R = {
                            id: e.id,
                            jobPlanOrderMaterialItemId: e.JobPlanOrderMaterialItemId,
                            useQuantity: o(e.editValueRefs.useQuantity),
                            inventoryId: e.inventoryId
                        };
                        await pe(R);
                        const O = {
                            jobPlanOrderMaterialItemId: d.value,
                            shipId: w,
                            itemId: m.value
                        }, C = await M(O);
                        s.value = C.map((x)=>({
                                ...x,
                                editable: !1
                            })), await n();
                    }
                } catch (l) {
                    console.log(l);
                }
            }
            async function se(e, a) {
                X(), v.mode !== "unPlannedJob" && q(()=>{
                    I({
                        task: a
                    });
                }), N(e) ? (s.value = [], c.value = !1) : (q(()=>{
                    K();
                }), c.value = !0), p.value = "";
            }
            async function ne() {
                try {
                    if (!s.value) return;
                    await z(), await le();
                    const e = h();
                    if (N(e.itemCode)) {
                        _.warning(t("jobOrder.materialItemCodeRequired")), f(!1);
                        return;
                    }
                    const a = s.value.reduce((n, l)=>Number(n) + Number(o(l.editValueRefs.useQuantity)), 0);
                    if (e && a === 0) {
                        _.warning(t("jobOrder.sparePartInventoryRequired")), f(!1);
                        return;
                    }
                    if (e.quantity = a, v.mode === "unPlannedJob") b("success", {
                        isEdit: c.value,
                        resData: {
                            ...B.value,
                            ...e,
                            outboundType: "1",
                            id: d.value,
                            materialItemId: m.value,
                            materialId: m.value
                        },
                        tableData: s.value
                    });
                    else {
                        const n = {
                            ...e,
                            outboundType: "1",
                            id: d.value,
                            materialItemId: m.value
                        };
                        b("success", {
                            isEdit: c.value,
                            resData: n,
                            tableData: s.value
                        });
                    }
                } catch  {
                    f(!1);
                }
            }
            async function le() {
                if (s.value && s.value.length > 0) {
                    if (y.value) return p.value = t("jobOrder.saveOutboundDetailsRequired"), f(!1), Promise.reject(t("jobOrder.saveOutboundDetailsRequired"));
                } else return p.value = t("jobOrder.outboundDetailsRequired"), f(!1), Promise.reject(t("jobOrder.outboundDetailsRequired"));
            }
            async function k(e) {
                B.value = e;
                try {
                    if (v.mode === "unPlannedJob") d.value = e.id, m.value = e.materialItemId, b("tableDataInit", {
                        isEdit: c.value,
                        setInventoryDetailTableData: ie,
                        mainData: e,
                        setMaterialDetail: I
                    });
                    else {
                        c.value ? (d.value = e.id, e.ROB = e.rob) : d.value = await ve(), m.value = e.materialItemId;
                        const a = {
                            jobPlanOrderMaterialItemId: d.value,
                            shipId: w,
                            itemId: m.value
                        }, n = await M(a);
                        s.value = n.map((l)=>({
                                ...l,
                                editable: !1
                            })), I(e);
                    }
                } catch  {}
            }
            function ie(e) {
                s.value = e;
            }
            const { schemas: re } = _e({
                getMaterial: h,
                shipId: w,
                setMaterialFormData: k
            }), [ue] = F({
                gridProps: {
                    cols: 16
                },
                schemas: re,
                showAdvancedButton: !1
            });
            return J({
                handleOpenModal: se,
                setProps: Z,
                getMaterial: h,
                setMaterialFormData: k,
                closeModal: H,
                setSubLoading: f
            }), (e, a)=>{
                const n = de, l = Ce, R = Oe("WarningOutline"), O = De, C = ce;
                return D(), E(C, {
                    ref: "modalRef",
                    subBtuText: o(t)("common.confirmText"),
                    onRegister: o(L),
                    onOnOk: ne
                }, {
                    default: u(()=>[
                            o(c) ? V("", !0) : (D(), E(l, {
                                key: 0,
                                class: "proCard"
                            }, {
                                default: u(()=>[
                                        r(n, {
                                            onRegister: o(ue),
                                            showActionButtonGroup: !1,
                                            showSubmitButton: !1,
                                            showResetButton: !1
                                        }, null, 8, [
                                            "onRegister"
                                        ])
                                    ]),
                                _: 1
                            })),
                            r(l, {
                                class: "proCard mt-2",
                                "content-class": "pt-4 pb-0"
                            }, {
                                default: u(()=>[
                                        r(l, {
                                            bordered: !1,
                                            class: "proCard mt-2",
                                            "content-class": "p-0 text-[16px] font-bold"
                                        }, {
                                            default: u(()=>[
                                                    T(P(o(t)("jobOrder.detail")), 1)
                                                ]),
                                            _: 1
                                        }),
                                        r(l, {
                                            bordered: !1,
                                            class: "proCard mt-2",
                                            "content-class": "p-0"
                                        }, {
                                            default: u(()=>[
                                                    r(n, {
                                                        onRegister: o(G)
                                                    }, null, 8, [
                                                        "onRegister"
                                                    ])
                                                ]),
                                            _: 1
                                        }),
                                        r(l, {
                                            bordered: !1,
                                            class: "proCard mt-2",
                                            "content-class": "p-0"
                                        }, {
                                            default: u(()=>[
                                                    r(o(me), {
                                                        ref_key: "basicTableRef",
                                                        ref: S,
                                                        columns: o($),
                                                        dataSource: o(s),
                                                        "row-key": (x)=>x.id,
                                                        autoScrollX: !0,
                                                        actionColumn: o(U),
                                                        showTableSetting: !1,
                                                        pagination: !1,
                                                        "virtual-scroll": "",
                                                        onEditChange: ee
                                                    }, {
                                                        tableTitle: u(()=>[
                                                                T(P(o(t)("jobOrder.inventoryDetail")) + " ", 1),
                                                                o(p) ? (D(), xe("span", Pe, [
                                                                    r(O, {
                                                                        class: "text-red-600"
                                                                    }, {
                                                                        default: u(()=>[
                                                                                r(R)
                                                                            ]),
                                                                        _: 1
                                                                    }),
                                                                    T(" " + P(o(p)), 1)
                                                                ])) : V("", !0)
                                                            ]),
                                                        _: 1
                                                    }, 8, [
                                                        "columns",
                                                        "dataSource",
                                                        "row-key",
                                                        "actionColumn"
                                                    ])
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 1
                            })
                        ]),
                    _: 1
                }, 8, [
                    "subBtuText",
                    "onRegister"
                ]);
            };
        }
    });
});
export { Je as _, __tla };
