pay_view.js 2.9 KB
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            //人民币转换红包券
            $('.total').bind('input propertychange', function() {
                var total = $(this).val();
                if(total == ''){
                    $('.ticket').hide();
                }else{
                    var ratio = $('.ratio').val();
                    var number = ratio/0.01*total;
                    $('.ticket').show().children('span').text(number);
                }
            });
            //点击立即充值
            $('.pay').click(function (){
                var admin_id = $('.admin_id').val();
                var total = $('.total').val();
                if(total == ''){
                    top.window.Layer.open({
                        title:'温馨提示',
                        content:'请输入充值金额'
                    });
                    return false;
                }else if(total<100){
                    top.window.Layer.open({
                        title:'温馨提示',
                        content:'充值金额不得小于100元'
                    });
                    return false;
                }else if(!(/(^[1-9]\d*$)/.test(total))){
                    top.window.Layer.open({
                        title:'温馨提示',
                        content:'必须为整数'
                    });
                    return false;
                }
                $.ajax({
                    url:"pay_view/create_order",
                    type:"POST",
                    data:{'admin_id':admin_id,'total':total},
                    success:function(res){
                        if(res.code == 1){
                            $('.qrcode').show().find('img').first().attr('src',window.location.protocol+"//"+window.location.host+"/admin/pay_view/pay/order_id/"+res.data.order_id);
                        }else{
                            top.window.Layer.open({
                                title:'温馨提示',
                                content:'与服务器连接失败'
                            });
                        }
                    },
                    error:function(){
                        top.window.Layer.open({
                            title:'温馨提示',
                            content:'与服务器连接失败'
                        });
                    }
                })
            });

            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});