fix(商品审核): 优化审核功能,使用FormData处理请求数据,提升代码可读性和维护性

This commit is contained in:
Ryan Ran
2025-09-23 14:01:53 +08:00
parent bb864e72b3
commit bb610a7cd8
2 changed files with 52 additions and 46 deletions

View File

@@ -78,25 +78,25 @@
<!-- 批量操作按钮 --> <!-- 批量操作按钮 -->
<div class="batch-operations" style="margin: 10px 0;"> <div class="batch-operations" style="margin: 10px 0;">
<Button <Button
type="success" type="success"
:disabled="selectedRows.length === 0" :disabled="selectedRows.length === 0"
@click="batchUpper" @click="batchUpper"
style="margin-right: 10px;" style="margin-right: 10px;"
> >
批量上架 批量上架
</Button> </Button>
<Button <Button
type="warning" type="warning"
:disabled="selectedRows.length === 0" :disabled="selectedRows.length === 0"
@click="batchLower" @click="batchLower"
style="margin-right: 10px;" style="margin-right: 10px;"
> >
批量下架 批量下架
</Button> </Button>
<Button <Button
v-if="currentStatus === 'TOBEAUDITED'" v-if="currentStatus === 'TOBEAUDITED'"
type="primary" type="primary"
:disabled="selectedRows.length === 0" :disabled="selectedRows.length === 0"
@click="batchAudit" @click="batchAudit"
> >
@@ -123,7 +123,7 @@
/> />
</div> </div>
</template> </template>
<!-- 商品栏目格式化 --> <!-- 商品栏目格式化 -->
<template slot="goodsSlot" slot-scope="{ row }"> <template slot="goodsSlot" slot-scope="{ row }">
<div style="margin: 5px 0px; padding: 10px 0px;"> <div style="margin: 5px 0px; padding: 10px 0px;">
@@ -179,9 +179,9 @@
<Radio :label="2">审核拒绝</Radio> <Radio :label="2">审核拒绝</Radio>
</RadioGroup> </RadioGroup>
</FormItem> </FormItem>
<FormItem label="审核备注" prop="reason" v-if="goodsAuditForm.auth_flag === 2"> <!-- <FormItem label="审核备注" prop="reason" v-if="goodsAuditForm.auth_flag === 2">
<Input v-model="goodsAuditForm.reason" type="textarea" :rows="3" placeholder="请输入拒绝原因" /> <Input v-model="goodsAuditForm.reason" type="textarea" :rows="3" placeholder="请输入拒绝原因" />
</FormItem> </FormItem> -->
</Form> </Form>
<div slot="footer"> <div slot="footer">
<Button type="text" @click="auditModalVisible = false">取消</Button> <Button type="text" @click="auditModalVisible = false">取消</Button>
@@ -622,7 +622,7 @@ export default {
query: { id: id }, query: { id: id },
}) })
}, },
// 商品状态筛选 // 商品状态筛选
goodsStatusClick(item) { goodsStatusClick(item) {
// 根据选择的状态设置搜索条件 // 根据选择的状态设置搜索条件
@@ -634,13 +634,13 @@ export default {
this.searchForm.goodsStatus = item; this.searchForm.goodsStatus = item;
} }
this.currentStatus = item; this.currentStatus = item;
// tab切换时清除选中内容 // tab切换时清除选中内容
this.selectedRows = []; this.selectedRows = [];
if (this.$refs.table) { if (this.$refs.table) {
this.$refs.table.selectAll(false); this.$refs.table.selectAll(false);
} }
this.getDataList(); this.getDataList();
}, },
examine(v, authFlag) { examine(v, authFlag) {
@@ -651,13 +651,18 @@ export default {
examine = "拒绝"; examine = "拒绝";
this.goodsAuditForm.authFlag = "REFUSE"; this.goodsAuditForm.authFlag = "REFUSE";
} }
this.$Modal.confirm({ this.$Modal.confirm({
title: "确认审核", title: "确认审核",
content: "您确认要审核" + examine + " " + v.goodsName + " ?", content: "您确认要审核" + examine + " " + v.goodsName + " ?",
loading: true, loading: true,
onOk: () => { onOk: () => {
this.goodsAuditForm.goodsIds=v.id; this.goodsAuditForm.goodsIds=v.id;
authGoods(this.goodsAuditForm).then((res) => { let formData = new FormData();
formData.append('goodsIds', v.id);
formData.append('authFlag', this.goodsAuditForm.authFlag);
authGoods(formData).then((res) => {
this.$Modal.remove(); this.$Modal.remove();
if (res.success) { if (res.success) {
this.$Message.success("审核成功"); this.$Message.success("审核成功");
@@ -668,7 +673,7 @@ export default {
}, },
}); });
}, },
// 打开审核弹框 // 打开审核弹框
openAuditModal(goods) { openAuditModal(goods) {
this.currentAuditGoods = goods; this.currentAuditGoods = goods;
@@ -676,7 +681,7 @@ export default {
this.goodsAuditForm.reason = ''; this.goodsAuditForm.reason = '';
this.auditModalVisible = true; this.auditModalVisible = true;
}, },
// 确认审核(二次确认) // 确认审核(二次确认)
confirmAudit() { confirmAudit() {
const auditText = this.goodsAuditForm.auth_flag === 1 ? '通过' : '拒绝'; const auditText = this.goodsAuditForm.auth_flag === 1 ? '通过' : '拒绝';
@@ -689,16 +694,13 @@ export default {
}, },
}); });
}, },
// 提交审核 // 提交审核
submitAudit() { submitAudit() {
const auditForm = { let formData = new FormData();
authFlag: this.goodsAuditForm.auth_flag === 1 ? 'PASS' : 'REFUSE', formData.append('goodsIds', this.currentAuditGoods.id);
reason: this.goodsAuditForm.reason || '', formData.append('authFlag', this.goodsAuditForm.auth_flag === 1 ? 'PASS' : 'REFUSE');
goodsId:this.currentAuditGoods.id authGoods(formData).then((res) => {
};
authGoods(auditForm).then((res) => {
this.$Modal.remove(); this.$Modal.remove();
if (res.success) { if (res.success) {
this.$Message.success('审核成功'); this.$Message.success('审核成功');
@@ -708,27 +710,27 @@ export default {
} }
}); });
}, },
// 选择框事件处理 // 选择框事件处理
onSelect(selection, row) { onSelect(selection, row) {
// 单行选择时触发 // 单行选择时触发
}, },
onSelectAll(selection) { onSelectAll(selection) {
// 全选时触发 // 全选时触发
}, },
onSelectionChange(selection) { onSelectionChange(selection) {
this.selectedRows = selection; this.selectedRows = selection;
}, },
// 批量上架 // 批量上架
batchUpper() { batchUpper() {
if (this.selectedRows.length === 0) { if (this.selectedRows.length === 0) {
this.$Message.warning('请先选择要上架的商品'); this.$Message.warning('请先选择要上架的商品');
return; return;
} }
const goodsNames = this.selectedRows.map(item => item.goodsName).join('、'); const goodsNames = this.selectedRows.map(item => item.goodsName).join('、');
this.$Modal.confirm({ this.$Modal.confirm({
title: '确认批量上架', title: '确认批量上架',
@@ -740,7 +742,7 @@ export default {
const params = { const params = {
goodsId: goodsIds // 传递ID数组 goodsId: goodsIds // 传递ID数组
}; };
upGoods(params).then((res) => { upGoods(params).then((res) => {
this.$Modal.remove(); this.$Modal.remove();
if (res.success) { if (res.success) {
@@ -756,14 +758,14 @@ export default {
} }
}); });
}, },
// 批量下架 // 批量下架
batchLower() { batchLower() {
if (this.selectedRows.length === 0) { if (this.selectedRows.length === 0) {
this.$Message.warning('请先选择要下架的商品'); this.$Message.warning('请先选择要下架的商品');
return; return;
} }
const goodsNames = this.selectedRows.map(item => item.goodsName).join('、'); const goodsNames = this.selectedRows.map(item => item.goodsName).join('、');
this.$Modal.confirm({ this.$Modal.confirm({
title: '确认批量下架', title: '确认批量下架',
@@ -776,7 +778,7 @@ export default {
goodsId: goodsIds, // 传递ID数组 goodsId: goodsIds, // 传递ID数组
reason: '批量下架操作' // 可以设置默认下架原因 reason: '批量下架操作' // 可以设置默认下架原因
}; };
lowGoods(params).then((res) => { lowGoods(params).then((res) => {
this.$Modal.remove(); this.$Modal.remove();
if (res.success) { if (res.success) {
@@ -792,14 +794,14 @@ export default {
} }
}); });
}, },
// 批量审核 // 批量审核
batchAudit() { batchAudit() {
if (this.selectedRows.length === 0) { if (this.selectedRows.length === 0) {
this.$Message.warning('请先选择要审核的商品'); this.$Message.warning('请先选择要审核的商品');
return; return;
} }
// 重置批量审核表单 // 重置批量审核表单
this.batchAuditForm = { this.batchAuditForm = {
auth_flag: 1, auth_flag: 1,
@@ -807,23 +809,23 @@ export default {
}; };
this.batchAuditModalVisible = true; this.batchAuditModalVisible = true;
}, },
// 提交批量审核 // 提交批量审核
submitBatchAudit() { submitBatchAudit() {
if (this.selectedRows.length === 0) { if (this.selectedRows.length === 0) {
this.$Message.warning('请先选择要审核的商品'); this.$Message.warning('请先选择要审核的商品');
return; return;
} }
// 如果是拒绝审核,必须填写原因 // 如果是拒绝审核,必须填写原因
if (this.batchAuditForm.auth_flag === 2 && !this.batchAuditForm.reason.trim()) { if (this.batchAuditForm.auth_flag === 2 && !this.batchAuditForm.reason.trim()) {
this.$Message.warning('审核拒绝时必须填写拒绝原因'); this.$Message.warning('审核拒绝时必须填写拒绝原因');
return; return;
} }
const actionText = this.batchAuditForm.auth_flag === 1 ? '通过' : '拒绝'; const actionText = this.batchAuditForm.auth_flag === 1 ? '通过' : '拒绝';
const goodsNames = this.selectedRows.map(item => item.goodsName).join('、'); const goodsNames = this.selectedRows.map(item => item.goodsName).join('、');
this.$Modal.confirm({ this.$Modal.confirm({
title: `确认批量审核${actionText}`, title: `确认批量审核${actionText}`,
content: `您确认要${actionText}以下商品的审核吗?\n${goodsNames}`, content: `您确认要${actionText}以下商品的审核吗?\n${goodsNames}`,
@@ -831,14 +833,14 @@ export default {
onOk: () => { onOk: () => {
// 提取所有选中商品的ID // 提取所有选中商品的ID
const goodsIds = this.selectedRows.map(item => item.id); const goodsIds = this.selectedRows.map(item => item.id);
const params = {
goodsId: goodsIds, // 传递ID数组 let formData = new FormData();
authFlag: this.batchAuditForm.auth_flag === 1 ? 'PASS' : 'REFUSE', formData.append('goodsId', goodsIds);
reason: this.batchAuditForm.reason || '' formData.append('authFlag', this.batchAuditForm.auth_flag === 1 ? 'PASS' : 'REFUSE');
}; formData.append('reason', this.batchAuditForm.reason || '');
// 修正直接调用authGoods不传递'batch'参数 // 修正直接调用authGoods不传递'batch'参数
authGoods(params).then((res) => { authGoods(formData).then((res) => {
this.$Modal.remove(); this.$Modal.remove();
if (res.success) { if (res.success) {
this.$Message.success(`批量审核${actionText}成功`); this.$Message.success(`批量审核${actionText}成功`);

View File

@@ -276,7 +276,11 @@ export default {
content: "您确认要审核" + examine + " " + v.goodsName + " ?", content: "您确认要审核" + examine + " " + v.goodsName + " ?",
loading: true, loading: true,
onOk: () => { onOk: () => {
authGoods(v.id, this.goodsAuditForm).then((res) => { let formData = new FormData();
formData.append('goodsIds', v.id);
formData.append('authFlag', this.goodsAuditForm.authFlag);
authGoods(formData).then((res) => {
this.$Modal.remove(); this.$Modal.remove();
if (res.success) { if (res.success) {
this.$Message.success("审核成功"); this.$Message.success("审核成功");