frontend/src/tools/apiTools.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-06-15 09:44:08 +08:00
import {
searchPendingOrderByObject,
searchPendingOrderByHash,
searchPendingOrderByKeys,
} from "@/assets/api.js";
import { Sweetalert } from "zent";
// === 公用接口函数 ===
/**
*
* @param {
* type值: 1key批次 2兑换码批次 3优惠券批次 4key码
* object_value:兑换id
* } data
2023-06-15 09:44:08 +08:00
* @param {1批量作废--文件上传, 2批量作废--列表选中 3普通查询(默认)} apiType
* @returns 0用户取消作废1订单下面没有待领取订单直接作废 2订单下面有待领取订单弹窗告知用户是否继续
*/
2023-06-15 09:44:08 +08:00
const commonSearchOrder = (data, apiType = 3) => {
return new Promise(async (res, rej) => {
let searchRes = null;
if (apiType === 1) {
searchRes = await searchPendingOrderByHash(data);
} else if (apiType === 2) {
searchRes = await searchPendingOrderByKeys(data);
} else {
searchRes = await searchPendingOrderByObject(data);
}
if (searchRes.code === 200) {
if (searchRes.data.have === true) {
Sweetalert.confirm({
type: "warning",
closeBtn: true,
title: "确认操作",
content: (
<p>该key批次(key兑换码)下面有待领取订单是否继续作废 </p>
),
onConfirm() {
res(2);
},
onCancel() {
res(0);
},
className: "questModal",
parentComponent: this,
});
} else {
2023-06-15 09:44:08 +08:00
res(1);
}
2023-06-15 09:44:08 +08:00
} else {
rej(searchRes);
}
});
};
export { commonSearchOrder };