feat: 核销api
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user