feat: 核销api
This commit is contained in:
+229
-76
@@ -38,32 +38,34 @@
|
||||
<view class="list">
|
||||
<view v-for="item in displayList" :key="item.id" class="card bg24">
|
||||
<view class="card-hd flex-center ju-between">
|
||||
<view class="status" :class="{ statusWait: Number(item.status) === 1 }">
|
||||
{{ item.statusName }}
|
||||
<view class="status-wrap">
|
||||
<view class="status" :class="{ statusWait: Number(item.status) === 1 }">
|
||||
{{ item.statusName }}
|
||||
</view>
|
||||
<view v-if="getOrderItems(item).length > 1" class="goods-total">
|
||||
共{{ getOrderItems(item).length }}件
|
||||
</view>
|
||||
</view>
|
||||
<view class="time c_999 size24">
|
||||
下单时间:{{ sheep.$helper.timeFormat(item.createTime, 'yyyy-mm-dd hh:MM') }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="card-bd flex-center al-flex-start">
|
||||
<view class="thumb-stack">
|
||||
<view
|
||||
v-for="(pic, picIndex) in getStackPics(item)"
|
||||
:key="`${item.orderId || item.id}-${picIndex}`"
|
||||
class="thumb-card"
|
||||
:style="{ left: `${picIndex * 22}rpx`, zIndex: getStackPics(item).length - picIndex }"
|
||||
>
|
||||
<image class="thumb-img" :src="resolvePicUrl(pic)" mode="aspectFill" />
|
||||
</view>
|
||||
<view v-if="!getStackPics(item).length" class="thumb-empty">
|
||||
暂无图片
|
||||
</view>
|
||||
<view v-if="getPicCount(item) > 1" class="thumb-count">
|
||||
{{ getPicCount(item) }}
|
||||
</view>
|
||||
<view class="goods-thumb">
|
||||
<image
|
||||
v-if="getItemPic(getMainItem(item))"
|
||||
class="goods-thumb__img"
|
||||
:src="getItemPic(getMainItem(item))"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view v-else class="goods-thumb__empty">暂无图片</view>
|
||||
</view>
|
||||
<view class="flex1">
|
||||
<view class="name lineTwo">{{ getOrderTitle(item) }}</view>
|
||||
<view class="name lineTwo">{{ getMainItem(item)?.spuName || '商品信息暂无' }}</view>
|
||||
<view v-if="getItemSpec(getMainItem(item))" class="meta c_999 size24 m-t-8">
|
||||
规格:{{ getItemSpec(getMainItem(item)) }}
|
||||
</view>
|
||||
<view class="meta c_999 size24 m-t-8">数量:x{{ getMainItem(item)?.count || 0 }}</view>
|
||||
<view class="meta c_999 size24 m-t-10">订单号:{{ item.orderNo }}</view>
|
||||
<view class="meta c_999 size24 m-t-6">取货码:{{ getPickUpCode(item) || '--' }}</view>
|
||||
</view>
|
||||
@@ -76,6 +78,49 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
v-if="getExtraItems(item).length"
|
||||
class="fold-box"
|
||||
:class="{ 'fold-box--active': isExpanded(item) }"
|
||||
>
|
||||
<view class="fold-trigger" @tap="toggleExpand(item)">
|
||||
<view class="fold-trigger__left">
|
||||
<view class="fold-trigger__badge">{{ getExtraItems(item).length }}</view>
|
||||
<view class="fold-trigger__text">
|
||||
{{ isExpanded(item) ? '收起其他商品' : `展开其他${getExtraItems(item).length}件商品` }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="fold-trigger__icon" :class="{ 'fold-trigger__icon--active': isExpanded(item) }">
|
||||
<uni-icons
|
||||
:type="isExpanded(item) ? 'top' : 'bottom'"
|
||||
size="14"
|
||||
color="#7b8494"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="isExpanded(item)" class="fold-panel">
|
||||
<view
|
||||
v-for="(goods, goodsIndex) in getExtraItems(item)"
|
||||
:key="goods.orderItemId || goodsIndex"
|
||||
class="fold-item"
|
||||
>
|
||||
<image
|
||||
v-if="getItemPic(goods)"
|
||||
class="fold-item__img"
|
||||
:src="getItemPic(goods)"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view v-else class="fold-item__empty">暂无图片</view>
|
||||
<view class="fold-item__info">
|
||||
<view class="fold-item__name lineTwo">{{ goods.spuName || '商品信息暂无' }}</view>
|
||||
<view v-if="getItemSpec(goods)" class="meta c_999 size24 m-t-8">
|
||||
规格:{{ getItemSpec(goods) }}
|
||||
</view>
|
||||
<view class="meta c_999 size24 m-t-8">数量:x{{ goods.count || 0 }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="displayList.length === 0" class="empty c_999">暂无数据</view>
|
||||
</view>
|
||||
@@ -101,6 +146,7 @@
|
||||
|
||||
const list = ref([]);
|
||||
const loading = ref(false);
|
||||
const expandedMap = ref({});
|
||||
const userStore = sheep.$store('user');
|
||||
|
||||
const displayList = computed(() => list.value);
|
||||
@@ -166,34 +212,40 @@
|
||||
return Array.isArray(item?.items) ? item.items.filter(Boolean) : [];
|
||||
};
|
||||
|
||||
const getPicList = (item) => {
|
||||
const pics = getOrderItems(item)
|
||||
.map((it) => sanitizeText(it?.picUrl))
|
||||
.filter(Boolean);
|
||||
const fallback = sanitizeText(item?.picUrl);
|
||||
return pics.length ? pics : [fallback].filter(Boolean);
|
||||
const getMainItem = (item) => {
|
||||
return getOrderItems(item)[0] || null;
|
||||
};
|
||||
|
||||
const getStackPics = (item) => {
|
||||
return getPicList(item).slice(0, 3);
|
||||
const getExtraItems = (item) => {
|
||||
return getOrderItems(item).slice(1);
|
||||
};
|
||||
|
||||
const getPicCount = (item) => {
|
||||
return getPicList(item).length;
|
||||
};
|
||||
|
||||
const resolvePicUrl = (url) => {
|
||||
const text = sanitizeText(url);
|
||||
const getItemPic = (goods) => {
|
||||
const text = sanitizeText(goods?.picUrl);
|
||||
if (!text) return '';
|
||||
if (/^https?:\/\//i.test(text)) return text;
|
||||
return sheep.$url.cdn(text);
|
||||
};
|
||||
|
||||
const getOrderTitle = (item) => {
|
||||
const firstName = getOrderItems(item)[0]?.spuName || item?.spuName || '';
|
||||
const totalCount = Number(item?.totalCount || getOrderItems(item).length || 0);
|
||||
if (!firstName) return '商品信息暂无';
|
||||
return totalCount > 1 ? `${firstName} 等${totalCount}件商品` : firstName;
|
||||
const getItemSpec = (goods) => {
|
||||
return goods?.spec || '';
|
||||
};
|
||||
|
||||
const getExpandKey = (item) => {
|
||||
return String(item?.orderId || item?.id || '');
|
||||
};
|
||||
|
||||
const isExpanded = (item) => {
|
||||
return Boolean(expandedMap.value[getExpandKey(item)]);
|
||||
};
|
||||
|
||||
const toggleExpand = (item) => {
|
||||
const key = getExpandKey(item);
|
||||
if (!key) return;
|
||||
expandedMap.value = {
|
||||
...expandedMap.value,
|
||||
[key]: !expandedMap.value[key],
|
||||
};
|
||||
};
|
||||
|
||||
const getPickUpCode = (item) => {
|
||||
@@ -288,6 +340,13 @@
|
||||
margin-bottom: 14rpx;
|
||||
}
|
||||
|
||||
.status-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.status {
|
||||
font-size: 24rpx;
|
||||
color: #2556ec;
|
||||
@@ -301,37 +360,32 @@
|
||||
background: rgba(107, 78, 255, 0.12);
|
||||
}
|
||||
|
||||
.thumb-stack {
|
||||
width: 184rpx;
|
||||
.goods-total {
|
||||
font-size: 22rpx;
|
||||
color: #8a8a8a;
|
||||
}
|
||||
|
||||
.goods-thumb {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
margin-right: 16rpx;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.thumb-card {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 18rpx;
|
||||
overflow: hidden;
|
||||
background: #f2f4f7;
|
||||
box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.08);
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.thumb-img {
|
||||
.goods-thumb__img,
|
||||
.goods-thumb__empty {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 18rpx;
|
||||
background: #f2f4f7;
|
||||
}
|
||||
|
||||
.goods-thumb__img {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.thumb-empty {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f2f4f7;
|
||||
.goods-thumb__empty {
|
||||
color: #bbb;
|
||||
font-size: 22rpx;
|
||||
display: flex;
|
||||
@@ -341,25 +395,6 @@
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.thumb-count {
|
||||
position: absolute;
|
||||
right: 45rpx;
|
||||
bottom: 0;
|
||||
min-width: 36rpx;
|
||||
height: 36rpx;
|
||||
padding: 0 10rpx;
|
||||
font-size: 22rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
border-radius: 18rpx;
|
||||
color: rgba(0, 0, 0, 0.75);
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 28rpx;
|
||||
color: #222;
|
||||
@@ -392,6 +427,124 @@
|
||||
color: #2556ec;
|
||||
}
|
||||
|
||||
.fold-box {
|
||||
margin-top: 16rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f7f8fc;
|
||||
border: 2rpx solid #eef1f6;
|
||||
overflow: hidden;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.fold-box--active {
|
||||
background: #f5f7ff;
|
||||
border-color: rgba(37, 86, 236, 0.18);
|
||||
box-shadow: 0 8rpx 24rpx rgba(37, 86, 236, 0.06);
|
||||
}
|
||||
|
||||
.fold-trigger {
|
||||
padding: 18rpx 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.fold-trigger__left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.fold-trigger__badge {
|
||||
min-width: 36rpx;
|
||||
height: 36rpx;
|
||||
padding: 0 10rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(37, 86, 236, 0.12);
|
||||
color: #2556ec;
|
||||
font-size: 22rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.fold-trigger__text {
|
||||
font-size: 25rpx;
|
||||
color: #4d5562;
|
||||
}
|
||||
|
||||
.fold-trigger__icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
border: 2rpx solid #eceff5;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.fold-trigger__icon--active {
|
||||
background: rgba(37, 86, 236, 0.1);
|
||||
border-color: rgba(37, 86, 236, 0.14);
|
||||
}
|
||||
|
||||
.fold-panel {
|
||||
padding: 0 20rpx 18rpx;
|
||||
border-top: 2rpx dashed #e6ebf4;
|
||||
}
|
||||
|
||||
.fold-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
padding-top: 16rpx;
|
||||
}
|
||||
|
||||
.fold-item + .fold-item {
|
||||
margin-top: 16rpx;
|
||||
padding-top: 16rpx;
|
||||
border-top: 2rpx solid #eceff5;
|
||||
}
|
||||
|
||||
.fold-item__img,
|
||||
.fold-item__empty {
|
||||
width: 104rpx;
|
||||
height: 104rpx;
|
||||
border-radius: 14rpx;
|
||||
flex-shrink: 0;
|
||||
background: #f2f4f7;
|
||||
}
|
||||
|
||||
.fold-item__img {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.fold-item__empty {
|
||||
color: #bbb;
|
||||
font-size: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 2rpx dashed #e3e6ee;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.fold-item__info {
|
||||
margin-left: 16rpx;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.fold-item__name {
|
||||
font-size: 26rpx;
|
||||
color: #222;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 80rpx 0;
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
<view class="scan-tip c_999 size24">或点击下方按钮开始扫码</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btnScan" @tap="startScan">开始扫码</view>
|
||||
<view class="btnScan" :class="{ btnScanDisabled: verifying }" @tap="startScan">
|
||||
{{ verifying ? '核销中...' : '开始扫码' }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="panel bg24" v-else>
|
||||
@@ -39,7 +41,9 @@
|
||||
:styles="{ fontSize: '34rpx' }"
|
||||
/>
|
||||
</view>
|
||||
<view class="btnScan" @tap="confirmManual">确认核销</view>
|
||||
<view class="btnScan" :class="{ btnScanDisabled: verifying }" @tap="confirmManual">
|
||||
{{ verifying ? '核销中...' : '确认核销' }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="records bg24">
|
||||
@@ -63,9 +67,13 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import modeSwitch from '@/components/mode_switch/mode_switch.vue';
|
||||
import sheep from '@/sheep';
|
||||
import OrderStoreApi from '@/sheep/api/trade/orderStore';
|
||||
|
||||
const tab = ref('scan');
|
||||
const manualCode = ref('');
|
||||
const verifying = ref(false);
|
||||
const userStore = sheep.$store('user');
|
||||
|
||||
const STORAGE_KEY = 'merchant.verify.records';
|
||||
const records = ref(uni.getStorageSync(STORAGE_KEY) || []);
|
||||
@@ -84,17 +92,50 @@
|
||||
uni.setStorageSync(STORAGE_KEY, next);
|
||||
};
|
||||
|
||||
const getVerifyIds = async () => {
|
||||
const localIds = Array.isArray(userStore?.userInfo?.ids) ? userStore.userInfo.ids : [];
|
||||
if (localIds.length) return localIds;
|
||||
const userInfo = await userStore.getInfo();
|
||||
return Array.isArray(userInfo?.ids) ? userInfo.ids : [];
|
||||
};
|
||||
|
||||
const verifyCode = async (code) => {
|
||||
const pickUpVerifyCode = String(code || '').trim();
|
||||
if (!pickUpVerifyCode) {
|
||||
uni.showToast({ title: '核销码不能为空', icon: 'none' });
|
||||
return false;
|
||||
}
|
||||
if (verifying.value) return false;
|
||||
const ids = await getVerifyIds();
|
||||
if (!ids.length) {
|
||||
uni.showToast({ title: '缺少核销ids', icon: 'none' });
|
||||
return false;
|
||||
}
|
||||
verifying.value = true;
|
||||
try {
|
||||
const { code: resCode } = await OrderStoreApi.verify(ids, pickUpVerifyCode);
|
||||
if (resCode !== 0) return false;
|
||||
pushRecord(pickUpVerifyCode);
|
||||
return true;
|
||||
} catch (error) {
|
||||
uni.showToast({ title: '核销失败,请稍后重试', icon: 'none' });
|
||||
return false;
|
||||
} finally {
|
||||
verifying.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const startScan = () => {
|
||||
if (verifying.value) return;
|
||||
uni.scanCode({
|
||||
scanType: ['qrCode', 'barCode'],
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
const code = String(res.result || '').trim();
|
||||
if (!code) {
|
||||
uni.showToast({ title: '未识别到内容', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
pushRecord(code);
|
||||
uni.showToast({ title: '核销成功', icon: 'success' });
|
||||
await verifyCode(code);
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '扫码失败', icon: 'none' });
|
||||
@@ -102,15 +143,16 @@
|
||||
});
|
||||
};
|
||||
|
||||
const confirmManual = () => {
|
||||
const confirmManual = async () => {
|
||||
const code = String(manualCode.value || '').trim();
|
||||
if (!code) {
|
||||
uni.showToast({ title: '请输入取货码', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
pushRecord(code);
|
||||
manualCode.value = '';
|
||||
uni.showToast({ title: '核销成功', icon: 'success' });
|
||||
const success = await verifyCode(code);
|
||||
if (success) {
|
||||
manualCode.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
const clear = () => {
|
||||
@@ -198,6 +240,10 @@
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.btnScanDisabled {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.input-row {
|
||||
border-radius: 24rpx;
|
||||
background: #f6f7fb;
|
||||
|
||||
@@ -35,6 +35,21 @@ const OrderStoreApi = {
|
||||
},
|
||||
});
|
||||
},
|
||||
verify: (ids, pickUpVerifyCode) => {
|
||||
const idText = Array.isArray(ids) ? ids.filter(Boolean).join(',') : String(ids || '');
|
||||
return request({
|
||||
url: '/trade/order-store/staff/verify',
|
||||
method: 'PUT',
|
||||
params: {
|
||||
ids: idText,
|
||||
pickUpVerifyCode: String(pickUpVerifyCode || '').trim(),
|
||||
},
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
successMsg: '核销成功',
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default OrderStoreApi;
|
||||
|
||||
Reference in New Issue
Block a user