import { V as L, d as H, r as h, ay as O, a as j, Z as k, cZ as A, c as g, o as m, X, w as n, j as s, D as C, H as Z, h as z, a9 as U, c9 as W, p as b, A as P, F as G, c8 as J, l, aI as K, B as Q, N as Y, iD as D, S as ee, hj as te, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as ne } from "./Table-0PViRYCf.js";
import { _ as ae } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { _ as se, __tla as __tla_1 } from "./NewSparePartsModal.vue_vue_type_script_setup_true_lang-B9o2yLPr.js";
import { b as oe, c as ie, e as le } from "./defectList-JLVZ8qtV.js";
let _e;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    let _, ce;
    ({ t: _ } = L());
    ce = [
        {
            title: _("defectFormPage.attachmentController.no"),
            width: 60,
            key: "num",
            render: (w, y)=>y + 1
        },
        {
            key: "partNumber",
            title: _("defectFormPage.attachmentController.partNumber")
        },
        {
            key: "description",
            title: _("defectFormPage.attachmentController.itemDescription")
        },
        {
            key: "specification",
            title: _("defectFormPage.attachmentController.specification")
        },
        {
            key: "quantity",
            title: _("defectFormPage.attachmentController.quantity")
        }
    ];
    _e = H({
        __name: "SparePartsRequiredController",
        props: {
            sparePartsList: {},
            value: {},
            options: {},
            key: {},
            id: {},
            type: {},
            canEdit: {},
            defectDetail: {}
        },
        emits: [
            "change",
            "update:sparePartsList"
        ],
        setup (w, { emit: y }) {
            const v = A(), { t: a } = L(), t = w, c = h(), r = h(null), u = h();
            O(()=>t.sparePartsList, ()=>{
                c.value?.reload?.();
            });
            const f = y, S = (e)=>{
                f("change", e);
            }, N = j({
                width: 120,
                title: a("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e) {
                    return k(ae, {
                        style: "text",
                        actions: [
                            {
                                label: a("common.optionsEditText"),
                                labelShow: !1,
                                icon: k("i", {
                                    class: "iconfont icon-a-Frame28"
                                }),
                                onClick: ()=>T(e),
                                ifShow: ()=>t.canEdit !== "false" || t.type !== "view"
                            },
                            {
                                label: a("common.optionsDelText"),
                                labelShow: !1,
                                icon: k("i", {
                                    class: "iconfont icon-Delete red"
                                }),
                                onPositiveClick: async ()=>{
                                    await oe(e.id);
                                    const i = t.sparePartsList.filter((o)=>o.id !== e.id);
                                    f("update:sparePartsList", i), c.value?.reload?.(), v.success(a("common.optionsDelSuccessText"));
                                },
                                onNegativeClick: ()=>{},
                                isConfirm: !0,
                                confirmContent: a("common.dialogContentDeleteText"),
                                ifShow: ()=>t.canEdit !== "false" || t.type !== "view"
                            }
                        ]
                    });
                }
            });
            async function x(e) {
                let i;
                if (r.value) {
                    i = t.sparePartsList.map((p)=>p.id === r.value.id ? {
                            ...r.value,
                            ...e
                        } : p);
                    const o = {
                        id: Number(r.value.id),
                        quantity: e.quantity,
                        remark: e.remark
                    };
                    await ie(o), v.success(a("common.optionsEditSuccessText")), f("update:sparePartsList", i), c.value?.reload?.();
                } else {
                    e.id = t.id, i = [
                        ...t.sparePartsList,
                        e
                    ], console.log(e);
                    let o = {
                        defectId: t.id,
                        itemId: e.itemId ? String(e.itemId).split("-")[0] : null,
                        partNumber: e.partNumber ? e.partNumber : "",
                        description: e.description ? e.description : "",
                        specification: e.specification ? e.specification : "",
                        quantity: e.quantity ? e.quantity : null,
                        remark: e.remark ? e.remark : "",
                        equipmentName: e.equipmentName ? e.equipmentName : "",
                        rob: e.rob ? e.rob : null
                    };
                    console.log(o), await le(o), v.success(a("common.optionsAddSuccessText")), f("update:sparePartsList", i), c.value?.reload?.();
                }
            }
            function q() {
                return console.log(t), {
                    list: t.sparePartsList || [],
                    total: t.sparePartsList ? t.sparePartsList.length : 0
                };
            }
            function T(e) {
                r.value = e, u.value?.showModal(), u.value.getData(e);
            }
            function F() {
                u.value?.showModal(), u.value.getData(t.defectDetail, t.sparePartsList);
            }
            return (e, i)=>{
                const o = W, p = Z, E = J, B = ee, I = te, M = Y, R = Q, V = K, $ = X;
                return m(), g($, null, {
                    default: n(()=>[
                            s(E, {
                                value: e.value,
                                name: e.key,
                                onUpdateValue: S
                            }, {
                                default: n(()=>[
                                        s(p, null, {
                                            default: n(()=>[
                                                    (m(!0), z(G, null, U(e.options, (d)=>(m(), g(o, {
                                                            key: d.value,
                                                            value: d.value
                                                        }, {
                                                            default: n(()=>[
                                                                    b(P(d.label), 1)
                                                                ]),
                                                            _: 2
                                                        }, 1032, [
                                                            "value"
                                                        ]))), 128))
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 1
                            }, 8, [
                                "value",
                                "name"
                            ]),
                            e.value === 1 ? (m(), g(l(ne), {
                                key: 0,
                                ref_key: "tableRef",
                                ref: c,
                                columns: l(ce),
                                request: q,
                                actionColumn: l(N),
                                pagination: !1,
                                "row-key": (d)=>d.id,
                                "virtual-scroll": "",
                                autoScrollX: !0
                            }, {
                                tableTitle: n(()=>[
                                        s(I, {
                                            prefix: "bar",
                                            class: "ml-6 mb-0 mt-2",
                                            "align-text": ""
                                        }, {
                                            default: n(()=>[
                                                    s(B, null, {
                                                        default: n(()=>[
                                                                b(P(l(a)("defectFormPage.attachmentController.sparePartsConsumed")), 1)
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                toolbar: n(()=>[
                                        s(p, null, {
                                            default: n(()=>[
                                                    t.canEdit !== "false" || t.type !== "view" ? (m(), g(V, {
                                                        key: 0,
                                                        trigger: "hover"
                                                    }, {
                                                        trigger: n(()=>[
                                                                s(R, {
                                                                    strong: "",
                                                                    secondary: "",
                                                                    type: "primary",
                                                                    class: "pl-[5px] pr-[5px] h-[28px]",
                                                                    onClick: F
                                                                }, {
                                                                    icon: n(()=>[
                                                                            s(M, {
                                                                                size: "18"
                                                                            }, {
                                                                                default: n(()=>[
                                                                                        s(l(D))
                                                                                    ]),
                                                                                _: 1
                                                                            })
                                                                        ]),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        default: n(()=>[
                                                                b(" " + P(l(a)("pms.material.add")), 1)
                                                            ]),
                                                        _: 1
                                                    })) : C("", !0)
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 1
                            }, 8, [
                                "columns",
                                "actionColumn",
                                "row-key"
                            ])) : C("", !0),
                            s(se, {
                                ref_key: "newSparePartsModalRef",
                                ref: u,
                                onSubmitSuccess: x
                            }, null, 512)
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { _e as _, __tla };
