feat(purchase): 采购申请批量审批(解决循环提交需多次审批)

问题: 一次提交 10 个物品生成 10 条独立申请,审批人需操作 10 次

后端:
- 新增 POST /api/v1/purchase/batch-approve 批量审批接口
  接收 ids + action,循环审批,成功/失败分别返回

前端:
- 待审批列表加多选列(仅 status=0 可勾选)
- 顶部批量操作栏:批量通过 / 批量驳回 / 取消选择
- 批量驳回弹窗统一填写驳回原因
This commit is contained in:
yueli
2026-08-31 13:41:25 +08:00
parent b68dfbf23d
commit 4b62c81baa
3 changed files with 176 additions and 2 deletions

View File

@ -205,6 +205,61 @@ def approve_purchase_request(purchase_id):
# 5. 获取可选审批人列表
# GET /api/v1/purchase/approvers
# --------------------------------------------------------
@purchase_bp.route('/batch-approve', methods=['POST'])
@jwt_required()
@permission_required('inbound_purchase:operation')
def batch_approve_purchase():
"""
批量审批采购申请(解决循环提交导致的多条记录需多次审批问题)
请求体:
{
"ids": [1, 2, 3],
"action": "approve" | "reject",
"reject_reason": "驳回原因reject 时必填)"
}
"""
try:
user_id = get_current_user_id()
data = request.get_json() or {}
ids = data.get('ids', [])
action = data.get('action', 'approve')
reject_reason = data.get('reject_reason')
if not ids or not isinstance(ids, list):
return jsonify({'code': 400, 'msg': 'ids 不能为空'}), 400
if action not in ('approve', 'reject'):
return jsonify({'code': 400, 'msg': '无效的审批操作'}), 400
if action == 'reject' and not reject_reason:
return jsonify({'code': 400, 'msg': '驳回时必须提供原因'}), 400
success_ids = []
error_items = []
for pid in ids:
try:
purchase = PurchaseService.approve_purchase_request(
purchase_id=pid,
user_id=user_id,
action=action,
reject_reason=reject_reason
)
success_ids.append(purchase.id)
except ValueError as e:
error_items.append({'id': pid, 'msg': str(e)})
except Exception as e:
traceback.print_exc()
error_items.append({'id': pid, 'msg': str(e)})
msg = f'批量审批完成: 成功 {len(success_ids)}'
if error_items:
msg += f', 失败 {len(error_items)}'
return jsonify({'code': 200, 'msg': msg, 'data': {'success_ids': success_ids, 'errors': error_items}}), 200
except Exception as e:
traceback.print_exc()
return jsonify({'code': 500, 'msg': f'服务器内部错误: {str(e)}'}), 500
@purchase_bp.route('/approvers', methods=['GET'])
@jwt_required()
def get_purchase_approvers():