<form id="theFrm">
    <input type="hidden" name="user_id" value="<?=$user_id?>">
    <input type="hidden" name="pay_date" value="<?=$pay_date?>">
    <input type="hidden" name="order_id" value="<?=$order_info->id?>">
    <table width="400" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <tr>
            <td colspan="9" class="bg_tr">
                <?php
                if($is_free)
                    echo '免费礼品';
                else
                    echo '自费礼品';
                if($type == 0)
                    echo '-实物';
                else
                    echo '-礼券';
                ?>
            </td>
        </tr>
            <?php
            $index = 0;
            foreach($order_gifts as $order_gift) {
                $index++;
                ?>
        <tr>
                <td width="150" class="bg_tr">
                    <input type="hidden" name="gift_ids[]" value="<?=$order_gift->id?>">
                    <?=$order_gift->gift->name?>
                </td>
            <?php
            if($type == 0) {
                ?>
                <td class="td_bg"><input name="gift_prices[]" id="gift_prices_<?=$order_gift->id?>" type="text" value="<?=$order_gift->price?>" style="width:60px;">元</td>
                <?php
            } else {
                ?>
                <td class="td_bg"><input name="gift_rates[]" id="gift_rates_<?=$order_gift->id?>" type="text" value="<?=$order_gift->rate?>" style="width:60px;" onblur="cal_money('gift_rates_<?=$order_gift->id?>','<?=$order_info->total1_clear?>','gift_prices_<?=$order_gift->id?>')">%</td>
                <td class="td_bg"><input name="gift_prices[]" id="gift_prices_<?=$order_gift->id?>" type="text" value="<?=$order_gift->price?>" style="width:60px;" onblur="cal_rate('gift_prices_<?=$order_gift->id?>','<?=$order_info->total1_clear?>','gift_rates_<?=$order_gift->id?>')">元</td>
                <?php
            }
            ?>
        </tr>
                <?php
            }
            ?>
    </table>
    <div align="center">
        <input id="submit-btn" type=button class="ACT_btn" name=Submit1 value=" 保存 "/>
    </div>
</form>
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript">
    //计算
    function cal_money(obj1,val,obj3) {
        var total = Number(val)/100 * Number($('#' + obj1).val());
        $('#' + obj3).val(total.toFixed(2));
    }
    function cal_rate(obj1,val,obj3) {
        var rate = Number($('#' + obj1).val())/Number(val) * 100 ;
        $('#' + obj3).val(rate.toFixed(2));
    }
    $(function () {
        //提交按钮
        $("#submit-btn").click(function(){
            if(confirm('是否确认保存?')) {
                var params = $("#theFrm").serialize();
                $.post('/finance/pay2-gift-save',params,function(obj){
                    alert(obj.msg);
                },'json');
            }
        });
    })
</script>
