"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_globalState = require("../../utils/globalState.js"); const api_index = require("../../api/index.js"); const utils_session = require("../../utils/session.js"); if (!Math) { AppIcon(); } const AppIcon = () => "../../components/AppIcon.js"; const _sfc_main = { __name: "Staff", emits: ["change-page"], setup(__props, { emit: __emit }) { const storeInfo = utils_session.getStoreSession(); const navSafeStyle = (() => { var _a, _b, _c, _d; const statusBarHeight = ((_b = (_a = common_vendor.index).getSystemInfoSync) == null ? void 0 : _b.call(_a).statusBarHeight) || 20; let navHeight = statusBarHeight + 44; const menuRect = (_d = (_c = common_vendor.index).getMenuButtonBoundingClientRect) == null ? void 0 : _d.call(_c); if (menuRect && menuRect.top && menuRect.height) { const verticalGap = Math.max(menuRect.top - statusBarHeight, 4); navHeight = statusBarHeight + verticalGap * 2 + menuRect.height; } return `padding-top:${statusBarHeight}px;height:${navHeight}px;`; })(); const staffList = common_vendor.ref([]); const showAddStaff = common_vendor.ref(false); const newStaff = common_vendor.ref({ name: "", phone: "" }); const swipedId = common_vendor.ref(null); const touchStartX = common_vendor.ref(0); const touchCurrentX = common_vendor.ref(0); const COLORS = ["#ff7c43", "#07c160", "#8b6914", "#e06040", "#5090d0", "#9b59b6"]; const avatarStyle = (s) => { var _a; if (s.avatar) return { background: "transparent" }; const idx = (((_a = s.name) == null ? void 0 : _a.charCodeAt(0)) || 0) % COLORS.length; return { background: COLORS[idx] }; }; const loadStaff = async () => { const res = await api_index.getStaffList(storeInfo.id); if (res.code === 200) staffList.value = res.data; }; const copyCode = () => { common_vendor.index.setClipboardData({ data: storeInfo.inviteCode, success: () => common_vendor.index.showToast({ title: "邀请码已复制", icon: "none" }) }); }; const confirmAddStaff = async () => { if (!newStaff.value.name) { common_vendor.index.showToast({ title: "请输入员工姓名", icon: "none" }); return; } if (!newStaff.value.phone || newStaff.value.phone.length !== 11) { common_vendor.index.showToast({ title: "请输入正确的手机号", icon: "none" }); return; } const res = await api_index.createStaff({ storeId: storeInfo.id, name: newStaff.value.name, phone: newStaff.value.phone }); if (res.code === 200) { common_vendor.index.showToast({ title: `添加成功,密码:${res.data.password}`, icon: "none", duration: 3e3 }); showAddStaff.value = false; newStaff.value = { name: "", phone: "" }; loadStaff(); } else { common_vendor.index.showToast({ title: res.message || "添加失败", icon: "none" }); } }; const getTouchX = (e) => { var _a, _b; if ((_a = e == null ? void 0 : e.touches) == null ? void 0 : _a[0]) return e.touches[0].pageX; if ((_b = e == null ? void 0 : e.changedTouches) == null ? void 0 : _b[0]) return e.changedTouches[0].pageX; return 0; }; const onSwipeStart = (e, staff) => { const x = getTouchX(e); touchStartX.value = x; touchCurrentX.value = x; if (swipedId.value && swipedId.value !== staff.id) { swipedId.value = null; } }; const onSwipeMove = (e) => { touchCurrentX.value = getTouchX(e); }; const onSwipeEnd = (e, staff) => { if (staff.role === "boss") return; const endX = getTouchX(e) || touchCurrentX.value; const deltaX = endX - touchStartX.value; if (deltaX < -40) { swipedId.value = staff.id; return; } if (deltaX > 24 && swipedId.value === staff.id) { swipedId.value = null; } }; const onRowTap = (staff) => { if (swipedId.value && swipedId.value !== staff.id) { swipedId.value = null; } }; const deleteStaff = async (staffId) => { common_vendor.index.showModal({ title: "提示", content: "确定删除该员工?", success: async (res) => { if (!res.confirm) return; const r = await api_index.deleteStaff(staffId); if (r.code === 200) { swipedId.value = null; common_vendor.index.showToast({ title: "已删除", icon: "success" }); loadStaff(); } } }); }; common_vendor.onMounted(() => loadStaff()); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.p({ name: "back", size: 18, color: "#ffffff" }), b: common_vendor.o(($event) => common_vendor.unref(utils_globalState.navigateTo)("mine")), c: common_vendor.s(common_vendor.unref(navSafeStyle)), d: common_vendor.t(common_vendor.unref(storeInfo).inviteCode), e: common_vendor.o(copyCode), f: common_vendor.o(($event) => showAddStaff.value = true), g: common_vendor.f(staffList.value, (s, k0, i0) => { return common_vendor.e({ a: s.role !== "boss" }, s.role !== "boss" ? { b: common_vendor.o(($event) => deleteStaff(s.id), s.id) } : {}, { c: s.avatar }, s.avatar ? { d: s.avatar } : { e: common_vendor.t(s.name ? s.name[0] : "?") }, { f: common_vendor.s(avatarStyle(s)), g: common_vendor.t(s.name), h: common_vendor.t(s.phone), i: common_vendor.t(s.role === "boss" ? "店长" : "员工"), j: common_vendor.o(($event) => onSwipeStart($event, s), s.id), k: common_vendor.o(($event) => onSwipeMove($event), s.id), l: common_vendor.o(($event) => onSwipeEnd($event, s), s.id), m: s.id, n: swipedId.value === s.id && s.role !== "boss" ? 1 : "", o: common_vendor.o(($event) => onRowTap(s), s.id) }); }), h: staffList.value.length === 0 }, staffList.value.length === 0 ? {} : {}, { i: showAddStaff.value }, showAddStaff.value ? { j: common_vendor.o(($event) => showAddStaff.value = false), k: newStaff.value.name, l: common_vendor.o(($event) => newStaff.value.name = $event.detail.value), m: newStaff.value.phone, n: common_vendor.o(($event) => newStaff.value.phone = $event.detail.value), o: common_vendor.o(($event) => showAddStaff.value = false), p: common_vendor.o(confirmAddStaff), q: common_vendor.o(() => { }), r: common_vendor.o(($event) => showAddStaff.value = false) } : {}); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-07da24cf"]]); wx.createPage(MiniProgramPage);