模态框获取id一直不变,都是同一个id值

本文介绍了一个使用Python实现的退款功能案例,重点展示了如何通过点击事件触发退款操作,并更新表单中的退款金额等信息。
$('.refund-btn').click(function(){
    //此处必须是$(this),否则$('.refund-btn')重新获取,导致值一直不变
    var id = $(this).attr('data-id');
    //var id = $('.refund-btn').attr('data-id');错误,这样会导致一直一个id值,一直不变,需要用$(this).attr('data-id')
    var form = $('#refund-order-form');
    form.attr('action', form.attr('action').replace('__order_id__', id));
    
    $.get('{$ajaxRefundInfoUrl}'.replace('__id__', id),function(rs){
        if(rs.status==200){
            //默认为订单金额
            $('#refundorderform-refund_amount').val(rs.model.price);
            $('#refundorderform-refund_reason').val(rs.model.refund_reason);
            $('#refundorderform-is_cancel').val(rs.model.is_cancel);
            $('#refundorderform-refund_explain').val(rs.model.refund_explain);
            $('#refundorderform-refund_remark').val(rs.model.refund_remark);
        }
    },'json');
    
});  

转载于:https://my.oschina.net/botkenni/blog/867180

// 模态框管理器 class ModalManager { constructor() { // 模态框类型注册表 this.modalTypes = { 'createOrder': { name: '创建订单', template: 'createOrderModal' }, 'addProduct': { name: '添加产品', template: 'addProductModal' }, 'editProduct': { name: '编辑产品', template: 'editProductModal' }, 'addComponent': { name: '添加组件', template: 'addComponentModal' }, 'addBancai': { name: '添加板材', template: 'addBancaiModal' }, 'bancaiDetail': { name: '板材详情', template: 'bancaiDetailModal' }, 'stockEdit': { name: '库存编辑', template: 'stockEditModal' }, 'materialDetail': { name: '材料详情', template: 'materialDetailModal' } }; // 模态框堆栈 this.modalStack = []; // 默认配置 this.defaultConfig = { title: '提示', content: '', buttons: [ { text: '取消', type: 'cancel', style: 'default' }, { text: '确定', type: 'confirm', style: 'primary' } ], maskClosable: true, zIndex: 1000, animation: true, customClass: '' }; } // 注册新的模态框类型 registerModalType(type, config) { this.modalTypes[type] = config; } // 显示模态框 showModal(pageContext, type, data = {}, config = {}) { // 合并配置 const modalConfig = { ...this.defaultConfig, ...config }; // 检查模态框类型 const modalType = this.modalTypes[type]; if (!modalType) { console.error(`未注册的模态框类型: ${type}`); return; } // 创建模态框对象 const modal = { id: Date.now(), // 唯一ID type, template: modalType.template, data: { ...data, ...modalConfig }, pageContext, zIndex: modalConfig.zIndex + this.modalStack.length * 10 }; // 添加到堆栈 this.modalStack.push(modal); // 更新页面数据 this.updatePageModals(pageContext); return modal.id; } // 关闭模态框 closeModal(pageContext, id, result = null) { const index = this.modalStack.findIndex(m => m.id === id); if (index !== -1) { const modal = this.modalStack.splice(index, 1)[0]; // 如果有回调函数,执行回调 if (modal.data.onClose) { modal.data.onClose(result); } // 更新页面 this.updatePageModals(pageContext); return true; } return false; } // 关闭所有模态框 closeAllModals(pageContext) { if (this.modalStack.length > 0) { this.modalStack = []; this.updatePageModals(pageContext); } } // 处理按钮点击 handleButtonClick(pageContext, id, buttonType) { const modal = this.modalStack.find(m => m.id === id); if (!modal) return; // 查找按钮配置 const buttonConfig = modal.data.buttons.find(b => b.type === buttonType); if (buttonConfig && buttonConfig.handler) { // 执行按钮处理函数 buttonConfig.handler({ modalId: id, modalType: modal.type, modalData: modal.data, close: (result) => this.closeModal(pageContext, id, result) }); } else if (buttonType === 'cancel') { // 默认取消行为 this.closeModal(pageContext, id); } } // 更新页面模态框数据 updatePageModals(pageContext) { if (!pageContext) return; // 获取当前页面可见的模态框 const visibleModals = this.modalStack.filter(modal => modal.pageContext === pageContext ); // 设置页面数据 pageContext.setData({ modals: visibleModals.map(modal => ({ id: modal.id, type: modal.type, template: modal.template, data: modal.data, zIndex: modal.zIndex })) }); } } // 创建单例 const modalManager = new ModalManager(); // 导出模块 module.exports = modalManager; 嵌套模态框中的数据在关闭时刷新父级模态框数据
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值