import { V as C, d as v, bk as A, f as q, r as R, a4 as O, a as B, Z as S, e_ as Q, ac as f, c as j, o as E, X as F, w as l, j as m, c6 as L, aI as M, p as g, A as P, l as d, B as V, N as $, iD as z, hj as H, S as Z, cZ as W, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as X } from "./Table-0PViRYCf.js";
import { _ as G } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import "./ImageUpload.vue_vue_type_style_index_0_scoped_cb086928_lang-D-28kXvw.js";
import "./vuedraggable.umd-Co2xEC3p.js";
import "./BasicUpload.vue_vue_type_style_index_0_scoped_a4d0e930_lang-DxRbtP01.js";
import "./BasicForm.vue_vue_type_style_index_0_scoped_b9e995ec_lang-CEvcLwxD.js";
import "./BasicSelect.vue_vue_type_style_index_0_scoped_772d51cc_lang-Brp6PjEU.js";
import "./index-DkvzUEqh.js";
import { b as K, __tla as __tla_1 } from "./index.vue_vue_type_style_index_0_scoped_b974e5ec_lang-_0QwzFKM.js";
import { _ as U, __tla as __tla_2 } from "./index.vue_vue_type_script_setup_true_lang-BaiGZfx5.js";
import "./schemas-BmKi-UM9.js";
import "./props-CLtNejQT.js";
import { c as Y, e as ee } from "./unPlannedJob-BvCurP2n.js";
import { b as te } from "./sparePartsStock-8NzBm-vI.js";
import { i as ae } from "./isEmpty-BUg1OsQj.js";
let Pe;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_2;
        } catch  {}
    })()
]).then(async ()=>{
    let p, ne;
    ({ t: p } = C());
    ne = [
        {
            key: "No",
            width: "50px",
            title: p("unPlannedJob.unPlannedJobComp.tableA.no"),
            render (b, _) {
                return _ + 1;
            }
        },
        {
            key: "partNumber",
            title: p("unPlannedJob.unPlannedJobComp.tableA.partNumber")
        },
        {
            key: "itemDescription",
            title: p("unPlannedJob.unPlannedJobComp.tableA.itemDescription")
        },
        {
            key: "specification",
            title: p("unPlannedJob.unPlannedJobComp.tableA.specification")
        },
        {
            key: "drawingNumber",
            title: p("unPlannedJob.unPlannedJobComp.tableA.plateDrawingNumber")
        },
        {
            key: "quantity",
            title: p("unPlannedJob.unPlannedJobComp.tableA.qty")
        },
        {
            key: "units",
            title: p("unPlannedJob.unPlannedJobComp.tableA.units")
        }
    ];
    Pe = v({
        __name: "index",
        props: {
            dataSource: {
                type: Array,
                default: []
            },
            disabled: {
                type: Boolean,
                default: !1
            },
            mainData: {
                type: Array,
                default: []
            },
            basicTabContext: {
                type: Object,
                default: {}
            }
        },
        emits: [
            "remove",
            "add-ok"
        ],
        setup (b, { emit: _ }) {
            const { t: r } = C(), h = W();
            A();
            const y = _, u = b, D = q(), s = R();
            O(()=>D.query.shipId);
            const x = B({
                width: 160,
                title: r("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e, n) {
                    return S(G, {
                        style: "text",
                        actions: [
                            {
                                label: r("common.optionsDelText"),
                                labelShow: !1,
                                icon: S("i", {
                                    class: "iconfont icon-Delete red"
                                }),
                                onPositiveClick: async ()=>{
                                    e.id && await Y([
                                        e.id
                                    ]), w(n);
                                },
                                onNegativeClick: ()=>{},
                                isConfirm: !0,
                                confirmContent: r("common.dialogContentDeleteText")
                            },
                            {
                                label: r("common.optionsEditText"),
                                labelShow: !1,
                                icon: S(Q),
                                onClick () {
                                    N(e);
                                }
                            }
                        ]
                    });
                }
            });
            async function N(e) {
                const n = u.basicTabContext.getFieldsValue();
                if (e) {
                    if (e.id) {
                        const a = await ee(e.id);
                        f(()=>{
                            const c = {
                                ...a?.partsDetailsInfo,
                                id: e.id,
                                sparePartNumber: e.partNumber,
                                ROB: a?.partsDetailsInfo.rob,
                                remarks: e.remarks || a?.partsDetailsInfo.remarks,
                                task: u.mainData?.basic?.jobCode,
                                tableData: ae(e.tableData) ? a.partsDetails.map((o)=>({
                                        ...o,
                                        normalQuantity: Number(o.outNormalStock || 0),
                                        reconditionedQuantity: Number(o.outAbnormalStock || 0),
                                        reconditionedStock: Number(o.abnormalStock || 0),
                                        normalStock: Number(o.normalStock || 0)
                                    })) : e.tableData.map((o)=>{
                                    const i = a?.partsDetails.find((k)=>k.id === o.id);
                                    return {
                                        ...o,
                                        normalQuantity: Number(i.outNormalStock || 0),
                                        reconditionedQuantity: Number(i.outAbnormalStock || 0),
                                        reconditionedStock: Number(i.abnormalStock || 0),
                                        normalStock: Number(i.normalStock || 0)
                                    };
                                })
                            };
                            s.value?.setSparePartsFormData(c);
                        });
                    } else f(()=>{
                        s.value?.setSparePartsFormData({
                            ...e,
                            ...e.raw,
                            task: u.mainData?.basic?.jobCode
                        });
                    });
                    s.value?.handleOpenModal(e);
                } else {
                    const a = {
                        equipmentCode: n?.equipmentCode || u.mainData?.basic?.equipmentCode,
                        model: n?.model || u.mainData?.basic?.model
                    };
                    s.value?.handleOpenModal(null, a), s.value?.setSparePartsFormData({
                        equipmentName: n?.equipmentName || u.mainData?.basic?.equipmentName,
                        task: u.mainData?.basic?.jobCode
                    });
                }
                const { formSchemas: t } = await K();
                s.value.setProps({
                    schemas: t
                });
            }
            function w(e) {
                y("remove", e);
            }
            function J(e) {
                s.value.setSubLoading(!1);
                const { isEdit: n, resData: t, tableData: a } = e;
                if (console.log(a), a.reduce((o, i)=>!i.normalQuantity && !i.reconditionedQuantity ? Number(o) : Number(o) + Number(i.normalQuantity) + Number(i.reconditionedQuantity), 0) === 0) return h.warning(r("pms.unPlannedJob.sparePartTotalZero"));
                y("add-ok", {
                    mainData: t,
                    tableData: a,
                    isEdit: n,
                    close: ()=>{
                        s.value.closeModal();
                    }
                });
            }
            function I({ index: e, record: n, done: t }) {
                t();
            }
            async function T({ isEdit: e, setInventoryDetailTableData: n, mainData: t, setSparePartsDetail: a }) {
                if (e) f(()=>{
                    n(t?.tableData), a({
                        ...t,
                        ...t.raw
                    });
                });
                else if (t.raw) {
                    const c = await te({
                        pageNum: 1,
                        pageSize: 1e3,
                        shipId: t.shipId,
                        itemId: t.raw.itemId
                    });
                    f(()=>{
                        n(c.list), a({
                            ...t,
                            ...t.raw,
                            tableData: c.list
                        });
                    });
                } else f(()=>{
                    n([]), a(t);
                });
            }
            return (e, n)=>{
                const t = Z, a = H, c = $, o = V, i = M, k = F;
                return E(), j(k, null, {
                    default: l(()=>[
                            m(d(X), {
                                columns: d(ne),
                                ref: "basicTableRef",
                                autoScrollX: !0,
                                "virtual-scroll": "",
                                showTableSetting: !1,
                                pagination: !1,
                                dataSource: b.dataSource,
                                actionColumn: !b.disabled && x,
                                canResize: !1
                            }, L({
                                tableTitle: l(()=>[
                                        m(a, {
                                            prefix: "bar",
                                            "align-text": ""
                                        }, {
                                            default: l(()=>[
                                                    m(t, null, {
                                                        default: l(()=>[
                                                                g(P(d(r)("unPlannedJob.sparePart")), 1)
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 2
                            }, [
                                b.disabled ? void 0 : {
                                    name: "toolbar",
                                    fn: l(()=>[
                                            m(i, {
                                                trigger: "hover"
                                            }, {
                                                trigger: l(()=>[
                                                        m(o, {
                                                            strong: "",
                                                            secondary: "",
                                                            type: "primary",
                                                            class: "pl-[5px] pr-[5px] h-[28px]",
                                                            onClick: n[0] || (n[0] = (oe)=>N(void 0))
                                                        }, {
                                                            icon: l(()=>[
                                                                    m(c, {
                                                                        size: "18"
                                                                    }, {
                                                                        default: l(()=>[
                                                                                m(d(z))
                                                                            ]),
                                                                        _: 1
                                                                    })
                                                                ]),
                                                            _: 1
                                                        })
                                                    ]),
                                                default: l(()=>[
                                                        g(" " + P(d(r)("common.addText")), 1)
                                                    ]),
                                                _: 1
                                            })
                                        ]),
                                    key: "0"
                                }
                            ]), 1032, [
                                "columns",
                                "dataSource",
                                "actionColumn"
                            ]),
                            m(d(U), {
                                ref_key: "modalSpareRef",
                                ref: s,
                                onSuccess: J,
                                title: d(r)("jobOrder.sparePartsRequired"),
                                mode: "unPlannedJob",
                                onRowEditSuccess: I,
                                onTableDataInit: T
                            }, null, 8, [
                                "title"
                            ])
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { Pe as _, __tla };
