98 行
2.9 KiB
JavaScript
可执行文件
98 行
2.9 KiB
JavaScript
可执行文件
/**
|
|
* 药品管理工具类
|
|
*/
|
|
class GoodsUtils {
|
|
/**
|
|
* API请求封装
|
|
*/
|
|
static async apiRequest(url, data = {}, method = 'POST') {
|
|
const options = {
|
|
method: method,
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
},
|
|
};
|
|
|
|
if (method.toUpperCase() === 'POST') {
|
|
options.body = new URLSearchParams(data).toString();
|
|
} else if (method.toUpperCase() === 'GET') {
|
|
const queryString = new URLSearchParams(data).toString();
|
|
if (queryString) {
|
|
url += '?' + queryString;
|
|
}
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(url, options);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP Error: ${response.status}`);
|
|
}
|
|
return await response.json();
|
|
} catch (error) {
|
|
console.error(`Request to ${url} failed`, error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 打开弹窗
|
|
*/
|
|
static openDialog(config) {
|
|
return layer.open({
|
|
type: 2,
|
|
area: ["calc(100% - 160px)", "calc(100% - 65px)"],
|
|
offset: 'rb',
|
|
shade: 0,
|
|
resize: false,
|
|
move: false,
|
|
...config
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 格式化搜索参数
|
|
*/
|
|
static formatSearchParams(searchForm, pagination) {
|
|
return {
|
|
page: pagination.currentPage,
|
|
limit: pagination.currentLimit,
|
|
...searchForm
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 验证批量操作参数
|
|
*/
|
|
static validateBatchOperation(changeForm, checkedList) {
|
|
if (!changeForm.key) {
|
|
return { valid: false, message: '请选择修改的内容' };
|
|
}
|
|
|
|
if (changeForm.key === 'goods_class_id' && !changeForm.value) {
|
|
return { valid: false, message: '请完善分类' };
|
|
}
|
|
|
|
if (changeForm.key === 'delivery_type') {
|
|
if (!changeForm.value.length) {
|
|
return { valid: false, message: '请选择配送方式' };
|
|
}
|
|
if (changeForm.value.indexOf(3) >= 0 && !changeForm.delivery_template_id) {
|
|
return { valid: false, message: '请选择发货模板' };
|
|
}
|
|
}
|
|
|
|
// 验证价格设置
|
|
for (let i = 0; i < checkedList.length; i++) {
|
|
if (changeForm.key === 'retail_state' && !parseFloat(checkedList[i].retail_price)) {
|
|
return { valid: false, message: `第${i + 1}个药品未设置店内零售价,不可开启店内出售` };
|
|
}
|
|
if (changeForm.key === 'online_state' && !parseFloat(checkedList[i].online_price)) {
|
|
return { valid: false, message: `第${i + 1}个药品未设置商城零售价,不可开启商城出售` };
|
|
}
|
|
}
|
|
|
|
return { valid: true };
|
|
}
|
|
}
|
|
|
|
window.GoodsUtils = GoodsUtils; |