优化网站导航模块

This commit is contained in:
2024-08-23 22:28:24 +08:00
parent 1d81fa9270
commit 13832d9de0
964 changed files with 90774 additions and 31362 deletions

View File

@@ -0,0 +1,190 @@
<template>
<a-card
:title="`收银员:${loginUser?.realName}`"
:bordered="false"
:body-style="{ minHeight: '60vh', width: '380px', padding: '0' }"
:head-style="{ className: 'bg-gray-500' }"
>
<template #extra>
<a-button danger @click="removeAll" size="small">整单取消</a-button>
</template>
<div class="goods-list overflow-x-hidden px-3 h-[600px]">
<a-empty v-if="cashier?.totalNums === 0" :image="simpleImage" />
<a-spin :spinning="spinning">
<template v-for="(item, index) in cashier?.cashiers" :key="index">
<div class="goods-item py-4 flex">
<div class="goods-image" v-if="item.image">
<a-avatar :src="item.image" shape="square" :size="42" />
</div>
<div class="goods-info w-full ml-2">
<div class="goods-bar flex justify-between">
<div class="goods-name flex-1">{{ item.name }}</div>
</div>
<div class="spec text-gray-400">{{ item.spec }}</div>
<div class="goods-price flex justify-between items-center">
<div class="flex">
<div class="price text-red-500">{{ item.price }}</div>
<div class="total-num ml-5 text-gray-400"
>x {{ item.cartNum }}</div
>
</div>
<div class="add flex items-center text-gray-500">
<MinusCircleOutlined class="text-xl" @click="subNum(item)" />
<div class="block text-center px-3">{{ item.cartNum }}</div>
<PlusCircleOutlined class="text-xl" @click="addNum(item)" />
</div>
</div>
</div>
<div class="total-nums"> </div>
</div>
<a-divider dashed />
</template>
</a-spin>
</div>
<template #actions>
<div class="flex flex-col">
<div class="text-left pb-4 pl-4 text-gray-500"
>共计 {{ cashier.totalNums }} 已优惠0.00
</div>
<div class="flex justify-between px-2">
<a-button size="large" class="w-full mx-1" @click="getListByGroup"
>取单</a-button
>
<a-button size="large" class="w-full mx-1" @click="onPack"
>挂单</a-button
>
<a-button
type="primary"
class="w-full mx-1"
size="large"
@click="onPay"
>收款{{ formatNumber(cashier.totalPrice) }}
</a-button>
</div>
</div>
</template>
</a-card>
</template>
<script lang="ts" setup>
import {
DeleteOutlined,
PlusCircleOutlined,
MinusCircleOutlined,
ExclamationCircleOutlined
} from '@ant-design/icons-vue';
import { ref, watch, createVNode } from 'vue';
import { Cashier, CashierVo } from '@/api/shop/cashier/model';
import { User } from '@/api/system/user/model';
import { formatNumber } from 'ele-admin-pro/es';
import {
subCartNum,
addCartNum,
removeBatchCashier,
removeCashier,
packCashier
} from '@/api/shop/cashier';
import { Empty, Modal, message } from 'ant-design-vue';
const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;
const props = withDefaults(
defineProps<{
value?: string;
placeholder?: string;
loginUser?: User;
cashier?: CashierVo;
count?: number;
spinning?: boolean;
}>(),
{
placeholder: undefined
}
);
const emit = defineEmits<{
(e: 'done'): void;
(e: 'reload'): void;
(e: 'group'): void;
(e: 'pay'): void;
(e: 'update:visible', visible: boolean): void;
}>();
const cashiers = ref<Cashier[]>([]);
/* 打开编辑弹窗 */
const onPay = () => {
emit('pay');
};
const subNum = (row: Cashier) => {
if (row.cartNum === 1) {
Modal.confirm({
title: '提示',
content: '确定要删除该商品吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeCashier(row?.id)
.then((msg) => {
hide();
message.success(msg);
emit('reload');
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
return false;
}
subCartNum(row).then(() => {
emit('reload');
});
};
const addNum = (row: Cashier) => {
addCartNum(row).then(() => {
emit('reload');
});
};
const removeAll = () => {
const ids = props.cashier?.cashiers?.map((d) => d.id);
if (ids) {
removeBatchCashier(ids)
.then(() => {})
.finally(() => {
emit('reload');
});
}
};
// 取单
const getListByGroup = () => {
emit('group');
};
// 挂单
const onPack = () => {
cashiers.value =
props.cashier?.cashiers?.map((d) => {
return {
id: d.id,
groupId: Number(d.groupId) + 1
};
}) || [];
if (cashiers.value.length === 0) {
return false;
}
packCashier(cashiers.value).then((res) => {
emit('reload');
});
};
watch(
() => props.count,
() => {}
);
</script>

View File

@@ -0,0 +1,252 @@
<template>
<a-card
class="w-full relative"
:bordered="false"
:body-style="{ padding: '16px' }"
>
<a-spin :spinning="spinning">
<div class="flex leading-7 mb-6">
<div class="w-[202px] text-gray-500">选择场馆</div>
<div class="list">
<a-radio-group v-model:value="where.merchantId" button-style="solid">
<a-radio-button
v-for="(item, index) in category"
:key="index"
:value="item.merchantId"
@click="onMerchant(item)"
>{{ item.merchantName }}</a-radio-button
>
</a-radio-group>
</div>
</div>
<div class="flex leading-7 mb-6">
<div class="w-[138px] text-gray-500">预定日期</div>
<div class="list">
<a-radio-group v-model:value="where.dateTime" button-style="solid">
<a-radio-button
v-for="(item, index) in next7day"
:key="index"
:value="item.dateTime"
>{{ item.label }}</a-radio-button
>
</a-radio-group>
</div>
</div>
<!-- <div class="flex leading-7 mb-6">-->
<!-- <div class="w-[138px] text-gray-500">选择时段</div>-->
<!-- <div class="list">-->
<!-- <a-radio-group v-model:value="where.timePeriod">-->
<!-- <a-radio-button-->
<!-- v-for="(item, index) in periods"-->
<!-- :key="index"-->
<!-- :value="item.merchantId"-->
<!-- @click="onMerchant(item)"-->
<!-- >{{ item.timePeriod }}</a-radio-button-->
<!-- >-->
<!-- </a-radio-group>-->
<!-- </div>-->
<!-- </div>-->
<div class="flex leading-7 mb-6">
<div class="w-[138px] text-gray-500">选择场地</div>
<div class="list flex-1">
<template v-for="(item, index) in periodList" :key="index">
<div class="time-period leading-7 text-gray-500 mb-2">
<a-tag color="blue">
<template #icon>
<ClockCircleOutlined />
</template>
{{ item.timePeriod }}</a-tag
>
</div>
<div class="field-list flex flex-wrap mb-2">
<a-button
class="w-[140px]"
v-for="(field, fieldIndex) in item.fieldList"
:key="fieldIndex"
:disabled="field.sold"
@click="add(field, item.timePeriod)"
>
<div class="flex justify-between">
<text>{{ field.fieldName }}</text>
<text>{{ item.price }}</text>
</div>
</a-button>
</div>
</template>
<!-- <div class="h-20 flex items-center m-auto w-full justify-center">-->
<!-- <a-pagination-->
<!-- v-model:current="page"-->
<!-- :total="count"-->
<!-- show-less-items-->
<!-- @change="reload"-->
<!-- />-->
<!-- </div>-->
</div>
</div>
</a-spin>
<!-- 编辑弹窗 -->
<SpecForm
v-model:visible="showSpecForm"
:data="current"
@done="addSpecField"
/>
</a-card>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import {
ShoppingCartOutlined,
ClockCircleOutlined
} from '@ant-design/icons-vue';
import SpecForm from './specForm.vue';
import { useRouter } from 'vue-router';
import { message } from 'ant-design-vue';
import { User } from '@/api/system/user/model';
import { listMerchant } from '@/api/shop/merchant';
import { getNext7day, getServerTime } from '@/api/layout';
import { getWeek } from '@/utils/common';
import { listPeriod, pagePeriod } from '@/api/booking/period';
import { Period, PeriodParam } from '@/api/booking/period/model';
import { Merchant } from '@/api/shop/merchant/model';
import { Field } from '@/api/booking/field/model';
import { addCashier } from '@/api/shop/cashier';
const { currentRoute } = useRouter();
withDefaults(
defineProps<{
value?: string;
placeholder?: string;
loginUser?: User;
}>(),
{
placeholder: undefined
}
);
const emit = defineEmits<{
(e: 'done'): void;
(e: 'reload'): void;
}>();
// 搜索表单
const where = reactive<PeriodParam>({
merchantId: undefined,
merchantName: undefined,
dateTime: undefined,
week: undefined,
half: 0,
isStatus: 0,
startTime: undefined,
timePeriod: undefined
});
// 加载中状态
const spinning = ref<boolean>(true);
// 当前编辑数据
const current = ref<Field | null>(null);
const form = ref<Field>({});
const category = ref<Merchant[]>([]);
const periods = ref<Period[]>([]);
const periodList = ref<Period[] | null>();
const specs = ref<string>();
const showSpecForm = ref<boolean>(false);
const next7day = ref<any[]>();
/* 打开编辑弹窗 */
const openSpecForm = (row?: Field) => {
current.value = row ?? null;
showSpecForm.value = true;
};
const add = (row?: Field, timePeriod?: string) => {
if (row?.merchantId == 3028) {
form.value = row;
form.value.cartNum = 1;
openSpecForm(row);
return false;
}
console.log(row);
addCashier({
goodsId: row?.fieldId,
name: `${where.merchantName} ${row?.fieldName}`,
price: row?.price,
spec: `${where.dateTime} ${getWeek(where.week)} ${timePeriod}`,
cartNum: 1,
isNew: true,
selected: true,
merchantId: row?.merchantId
})
.then((res) => {
console.log(res);
emit('reload');
})
.catch(() => {
message.error('该场地已有人预定');
});
};
const addSpecField = () => {
emit('reload');
};
const onMerchant = (e) => {
where.merchantId = e.merchantId;
reload();
};
const reload = async () => {
spinning.value = true;
await getNext7day().then((list) => {
next7day.value = list.map((d: any, i) => {
if (where.dateTime == undefined) {
where.dateTime = d.dateTime;
}
if (where.week == undefined) {
where.week = d.week;
}
d.label = `${getWeek(d.week)}(${d.date})`;
return d;
});
});
await listMerchant({}).then((list) => {
category.value = list;
if (where.merchantId == undefined) {
where.merchantId = list[0].merchantId;
where.merchantName = list[0].merchantName;
}
});
await getServerTime().then((res) => {
if (where.merchantId != 3028) {
where.startTime = res.hourMinute;
}
});
// await pagePeriod({ merchantId: where.merchantId }).then((res) => {
// if (res?.list) {
// periods.value = res.list;
// }
// });
await listPeriod(where)
.then((list) => {
periodList.value = list;
})
.catch(() => {
periodList.value = [];
})
.finally(() => {
spinning.value = false;
});
};
reload();
watch(currentRoute, () => {}, { immediate: true });
</script>
<script lang="ts">
export default {
name: 'PeriodField'
};
</script>

View File

@@ -0,0 +1,155 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="1000"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:footer="null"
:title="isUpdate ? '取单' : '取单'"
:body-style="{
paddingTop: '10px',
paddingBottom: '38px',
backgroundColor: '#f3f3f3'
}"
@update:visible="updateVisible"
@ok="save"
>
<a-space direction="vertical" class="w-full">
<div v-for="(item, index) in groups" :key="index">
<a-card
:title="`订单总价: ¥${formatNumber(item.totalPrice)}`"
:body-style="{ padding: '10px' }"
>
<div class="flex flex-wrap">
<div v-for="(v, i) in item.cashiers" :key="i" class="flex m-2">
<div class="item flex flex-col bg-gray-50 p-3 w-[215px]">
<text>{{ v.goodsName }}</text>
<text class="text-gray-400">规格{{ v.spec }}</text>
<text class="text-gray-400">数量{{ v.cartNum }}</text>
<text>小计{{ v.totalPrice }}</text>
</div>
</div>
</div>
<!-- <div class="comments p-2 text-gray-400">-->
<!-- {{ item.comments }}-->
<!-- </div>-->
<template #actions>
<div class="text-left px-3">
<a-space>
<a-button type="primary" @click="getCashier(item.groupId)"
>取单</a-button
>
<a-button danger type="primary" @click="remove(item.groupId)"
>删除</a-button
>
<!-- <a-button>备注</a-button>-->
</a-space>
</div>
</template>
</a-card>
</div>
</a-space>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue';
import { message } from 'ant-design-vue';
import { addMpMenu, updateMpMenu } from '@/api/cms/mp-menu';
import { MpMenu } from '@/api/cms/mp-menu/model';
import { FormInstance } from 'ant-design-vue/es/form';
import { getByGroup, listByGroupId, removeByGroup } from '@/api/shop/cashier';
import { formatNumber } from 'ele-admin-pro/es';
import { CashierVo } from '@/api/shop/cashier/model';
// 是否是修改
const isUpdate = ref(false);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 类型 0服务 1订单
type?: number;
// 页面ID
pageId?: number;
// 修改回显的数据
data?: MpMenu | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
const pageId = ref(0);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
//
const groups = ref<CashierVo[]>();
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
const getCashier = (groupId: number) => {
getByGroup(groupId).then(() => {
updateVisible(false);
emit('done');
});
};
const remove = (groupId: number) => {
removeByGroup(groupId).then(() => {
reload();
});
};
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
pageId: pageId.value
};
const saveOrUpdate = isUpdate.value ? updateMpMenu : addMpMenu;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
const reload = () => {
listByGroupId({}).then((data) => {
groups.value = data;
});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
reload();
}
}
);
</script>

View File

@@ -0,0 +1,262 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="1000"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '支付结算' : '支付结算'"
okText="确定收款"
:ok-button-props="{ disabled: !user }"
:body-style="{
padding: '0',
paddingBottom: '0',
backgroundColor: '#f3f3f3'
}"
@update:visible="updateVisible"
@ok="save"
>
<!-- {{ form }}-->
<div class="flex justify-between py-3 px-4 columns-3 gap-3">
<div class="payment flex flex-col bg-white px-4 py-2">
<div class="title text-gray-500 leading-10">请选择支付方式</div>
<template v-for="(item, index) in payments" :key="index">
<div
class="item border-2 border-solid px-3 py-1 flex items-center mb-2 cursor-pointer"
:class="
form.type === item.type
? 'active border-red-300'
: 'border-gray-200'
"
@click="onType(item)"
>
<a-avatar :src="item.image" />
<text class="pl-1">{{ item.name }}</text>
</div>
</template>
</div>
<div class="settlement flex flex-col bg-white px-4 py-2 flex-1">
<div class="title text-gray-500 leading-10">结算信息</div>
<div class="comments">
<a-textarea
:rows="4"
:maxlength="200"
placeholder="备注信息"
v-model:value="form.comments"
/>
</div>
<div class="discount flex mt-3">
<div class="item w-1/2">
折扣()
<div class="input">
<a-input-number
allow-clear
min="0"
max="10"
placeholder="请输入折扣"
style="width: 200px"
v-model:value="form.discount"
@input="onDiscount"
/>
</div>
</div>
<div class="item w-1/2">
立减
<div class="input">
<a-input-number
allow-clear
placeholder="请输入立减金额"
style="width: 200px"
v-model:value="form.reducePrice"
/>
</div>
</div>
</div>
<div class="discount flex mt-8 items-center h-20 leading-10">
<div class="item w-1/2"> 优惠金额0.00</div>
<div class="item w-1/2 text-xl">
实付金额<span class="text-red-500 text-2xl">{{
formatNumber(data.totalPrice)
}}</span>
</div>
</div>
</div>
<div class="user-bar flex flex-col bg-white px-4 py-2">
<div class="title text-gray-500 leading-10">会员信息</div>
<div class="user-info text-center" v-if="!user">
<a-empty :description="`当前为游客`" class="text-gray-300" />
<SelectUserByButton @done="selectUser" />
</div>
<view class="tox-user" v-if="user">
<div class="mb-2 flex justify-between items-center">
<div class="avatar">
<a-avatar :src="user.avatar" :size="40" />
<text class="ml-1 text-gray-500">{{ user.nickname }}</text>
</div>
<CloseOutlined @click="removeUser" />
</div>
<div
class="border-dashed py-1 px-2 border-gray-300 text-gray-500 mt-2"
>名称{{ user.realName }}
</div>
<div
class="border-dashed py-1 px-2 border-gray-300 text-gray-500 mt-2"
>手机号{{ user.mobile || '未绑定' }}
</div>
<div
class="border-dashed py-1 px-2 border-gray-300 text-gray-500 mt-2"
>可用余额{{ user.balance }}
</div>
<div
class="border-dashed py-1 px-2 border-gray-300 text-gray-500 mt-2"
>可用积分{{ user.points }}
</div>
</view>
</div>
</div>
<UserForm v-model:visible="showUserForm" :type="type" @done="reload" />
</ele-modal>
</template>
<script lang="ts" setup>
import { CloseOutlined } from '@ant-design/icons-vue';
import { ref, watch, reactive } from 'vue';
import { message } from 'ant-design-vue';
import { FormInstance } from 'ant-design-vue/es/form';
import { formatNumber } from 'ele-admin-pro/es';
import { listPayment } from '@/api/system/payment';
import { Payment } from '@/api/system/payment/model';
import { User } from '@/api/system/user/model';
import { Cashier } from '@/api/shop/cashier/model';
import { addOrder, updateOrder } from '@/api/shop/order';
import { Order } from '@/api/shop/order/model';
// 是否是修改
const isUpdate = ref(false);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 类型 0服务 1订单
type?: number;
// 修改回显的数据
data?: Cashier | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 用户信息
const form = reactive<Order>({
// ID
// 类型 0商城 1外卖
type: 4,
// 唯一标识
// 商品价格
price: undefined,
// 单商品合计
totalPrice: undefined,
// 商户ID
merchantId: undefined,
// 用户ID
userId: undefined,
// 租户id
tenantId: undefined,
// 创建时间
createTime: undefined,
// 修改时间
updateTime: undefined
});
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const disabled = ref<boolean>(true);
const payments = ref<Payment[]>();
const showUserForm = ref<boolean>(false);
const user = ref<User | null>();
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
const selectUser = (item: User) => {
user.value = item;
};
const onType = (item: Payment) => {
form.type = item.type;
};
const removeUser = () => {
user.value = null;
};
/* 保存编辑 */
const save = () => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? updateOrder : addOrder;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
};
const reload = () => {
listPayment({}).then((data) => {
payments.value = data;
});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
reload();
}
}
);
</script>
<style lang="less" scoped>
.active {
position: relative;
border: 2px solid #007cec;
&:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
border: 11px solid #007cec;
border-top-color: transparent;
border-left-color: transparent;
}
&:after {
content: '';
width: 4px;
height: 8px;
position: absolute;
right: 3px;
bottom: 4px;
border: 1px solid #fff;
border-top-color: transparent;
border-left-color: transparent;
transform: rotate(45deg);
}
}
</style>

View File

@@ -0,0 +1,52 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" class="flex-wrap mb-5">
<a-input-search
allow-clear
size="large"
style="width: 400px"
placeholder="商品名称"
v-model:value="where.goodsName"
@pressEnter="handleSearch"
@search="handleSearch"
/>
<a-button @click="handleSearch" size="large">搜索</a-button>
</a-space>
</template>
<script lang="ts" setup>
import { watch } from 'vue';
import useSearch from '@/utils/use-search';
import { GoodsParam } from '@/api/shop/goods/model';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GoodsParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 表单数据
const { where } = useSearch<GoodsParam>({
goodsId: undefined,
goodsName: undefined,
keywords: undefined
});
const handleSearch = () => {
emit('search', where);
};
watch(
() => props.selection,
() => {}
);
</script>

View File

@@ -0,0 +1,235 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '选择场地' : '选择场地'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
{{ form }}
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="名称" name="goodsName">
{{ form.name }}
</a-form-item>
<a-form-item label="价格" name="price">
<div class="text-red-500">{{ formatNumber(form.price) }}</div>
</a-form-item>
<a-form-item
label="购买数量"
name="cartNum"
v-if="data.merchantId == 3028"
>
<a-input-number
:min="1"
:max="9999"
placeholder="请输入排序号"
v-model:value="form.cartNum"
@pressEnter="save"
/>
</a-form-item>
<a-form-item v-if="form.specs === 1" label="规格" name="spec">
<template v-for="(item, index) in form?.goodsSpecValue" :key="index">
<div class="flex flex-col">
<span class="font-bold leading-8 text-gray-400">{{
item.value
}}</span>
<a-radio-group v-model:value="form.goodsSpecValue[index].spec">
<template v-for="(v, i) in item.detail" :key="i">
<a-radio-button :value="v">{{ v }}</a-radio-button>
</template>
</a-radio-group>
</div>
</template>
</a-form-item>
<a-form-item v-if="data.merchantId == 3028" label="规格" name="spec">
<template v-for="(item, index) in form?.goodsSpecValue" :key="index">
<div class="flex flex-col">
<span class="font-bold leading-8 text-gray-400">{{
item.value
}}</span>
<a-radio-group v-model:value="form.goodsSpecValue[index].spec">
<template v-for="(v, i) in item.detail" :key="i">
<a-radio-button :value="v">{{ v }}</a-radio-button>
</template>
</a-radio-group>
</div>
</template>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject } from 'ele-admin-pro';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FormInstance } from 'ant-design-vue/es/form';
import { Cashier } from '@/api/shop/cashier/model';
import { formatNumber } from 'ele-admin-pro/es';
import { addCashier, updateCashier } from '@/api/shop/cashier';
import { Field } from '@/api/booking/field/model';
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 类型 0服务 1订单
type?: number;
// 修改回显的数据
data?: Field | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const images = ref<ItemType[]>([]);
const spec = ref<string>();
// 用户信息
const form = reactive<Cashier>({
// ID
id: undefined,
// 类型 0商城 1外卖
type: undefined,
// 唯一标识
code: undefined,
// 商品ID
goodsId: undefined,
// 商品名称
goodsName: undefined,
// 商品封面图
image: undefined,
// 商品规格
spec: undefined,
// 商品价格
price: undefined,
// 商品数量
cartNum: undefined,
// 单商品合计
totalPrice: undefined,
// 0 = 未购买 1 = 已购买
isPay: undefined,
// 是否为立即购买
isNew: undefined,
// 是否选中
selected: undefined,
// 商户ID
merchantId: undefined,
// 用户ID
userId: undefined,
// 收银员ID
cashierId: undefined,
// 收银单分组ID
groupId: undefined,
// 租户id
tenantId: undefined,
// 创建时间
createTime: undefined,
// 修改时间
updateTime: undefined,
// 是否多规格
specs: undefined,
// 商品规格数据
goodsSpecValue: []
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({});
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
if (form.specs === 1) {
const text = form.goodsSpecValue.map((d) => d.spec).join(',');
if (text === ',') {
message.error('请选择规格');
return false;
}
spec.value = text;
}
console.log('>>>>>3');
const formData = {
...form,
goodsId: props.data?.fieldId,
name: props.data?.fieldName,
spec: spec.value
};
const saveOrUpdate = isUpdate.value ? updateCashier : addCashier;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
images.value = [];
spec.value = '';
isUpdate.value = !!props.data?.fieldId;
if (props.type) {
form.type = props.type;
}
if (props.data) {
assignObject(form, props.data);
form.name = props.data.fieldName;
form.cartNum = 1;
}
} else {
resetFields();
}
}
);
</script>

View File

@@ -0,0 +1,73 @@
<template>
<a-page-header :title="`收银台`" @back="() => $router.go(-1)">
<div class="flex gap-5">
<!-- 载入购物车 -->
<Cart
:spinning="spinning"
:loginUser="loginUser"
:cashier="cashier"
:count="cashier?.totalNums"
@group="openGroupForm"
@reload="reload"
@pay="onPay"
/>
<!-- 商品搜索 -->
<Goods :loginUser="loginUser" @reload="reload" />
<!-- 取单 -->
<GroupForm v-model:visible="showCashierForm" @done="reload" />
<!-- 支付结算 -->
<Pay v-model:visible="showPayForm" :data="cashier" @done="reload" />
</div>
</a-page-header>
</template>
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import GroupForm from './components/group.vue';
import Cart from './components/cashier.vue';
import Goods from './components/goods.vue';
import Pay from './components/pay.vue';
import * as CashierApi from '@/api/shop/cashier';
import { useUserStore } from '@/store/modules/user';
import { CashierVo } from '@/api/shop/cashier/model';
// 当前用户信息
const userStore = useUserStore();
const loginUser = computed(() => userStore.info ?? {});
const cashier = ref<CashierVo>({});
// 加载中状态
const spinning = ref<boolean>(true);
const showCashierForm = ref<boolean>(false);
const showPayForm = ref<boolean>(false);
const openGroupForm = () => {
showCashierForm.value = true;
};
const onPay = () => {
showPayForm.value = true;
};
/* 加载数据 */
const reload = () => {
spinning.value = true;
CashierApi.listCashier({ groupId: 0 })
.then((data) => {
if (data) {
cashier.value = data;
}
})
.finally(() => {
spinning.value = false;
});
};
watch(
() => {},
() => {
reload();
},
{ immediate: true }
);
</script>