HEX
Server: Apache/2.4.6 (CentOS) PHP/5.6.39
System: Linux izj6c6ukj0hyugxsgmuxz3z 3.10.0-514.6.2.el7.x86_64 #1 SMP Thu Feb 23 03:04:39 UTC 2017 x86_64
User: root (0)
PHP: 5.6.39
Disabled: NONE
Upload Files
File: /web/data/www.tbbprovision.com/static/manage/js/coupon.js
/**
 *  author      : liaoyaping
 *  createTime  : 2017/9/8
 *  description : 优惠券
 */
var couponobj = {
    list : function(){
        var post_data;
        window.$bootstrapTable = $('#table2').bootstrapTable({
            url:'/admin/coupon/list_json/',
            method:'post',
            striped:true,
            search:true,
            height:'530',
            toolbar:'#toolbar',
            sortOrder:'desc',
            showColumns:true,
            showRefresh:true,
            idField:'coupon_id',
            showToggle:false,
            sidePagination:'server',
            selectItemName:'id',
            clickToSelect:true,
            totalRows:5,
            pageList:[20,50,100],
            pageSize:50,
            queryParams:function(data){
                post_data = data;
                return data;
            },
            columns: [{
                field: 'coupon_id',
                title: 'ID',
                checkbox:true,
                formatter: function(value,row){
                    row['post_id'] = value;
                }
            },{
                title: '序号',
                width:'5%',
                align:'center',
                formatter:function(value,row,index){
                    return post_data.offset + (++index);
                }
            },{
                field: 'name',
                title: '优惠券名称',
            },{
                field: 'coupon_code',
                title: '优惠券号码',
                formatter:function(value){
                    return value;
                }
            },{
                field: 'amount',
                title: '面额',
                formatter:function(value){
                    return "$"+parseFloat(value);
                }
            },{
                field: 'coupon_type',
                title: '使用类型'
            },{
                title: '有效期',
                formatter:function(value,row){
                    return row['start_time'] + '~' + row['end_time'];
                }
            },{
                title: '生成时间',
                formatter:function(value,row){
                    return row['add_time'];
                }
            },{
                field: 'status',
                title: '状态'
            },{
                field: '',
                title: '操作',
                width: '3%',
                formatter: function(value,row,index){
                    return "<a href='javascript:void(0)'  class='item-edit-btn btn btn-info btn-list' title='编辑' data-id='"+row.post_id+"'><span class='fa fa-pencil'></span></a>";
                }
            }],
            onLoadSuccess: function(){
                $('.item-edit-btn').click(function(){
                    var coupon_id = $(this).attr('data-id');
                    var index = layer.open({
                        type: 2,
                        title: ['编辑优惠券'],
                        shadeClose: true,
                        shift:2,
                        shade: [true,'rgba(0,0,0,.5)'],
                        offset:['0','20%'],
                        maxmin: true,
                        area: ['80%', '100%'],
                        content: '/admin/coupon/coupon_edit/?coupon_id='+coupon_id
                    });
                });
            }
        });

        //删除
        $('#remove').click(function(){
            //询问框
            layer.confirm('确定删除此记录?', {
                'title':'<strong class="">提示</strong>',
                btn: ['删除','关闭'] //按钮
            }, function(){
                jQuery.ajax({
                    method:'post',
                    url:'/admin/coupon/del/',
                    data:global.get_selected_str('input[name="id"]:checked','id'),
                    dataType:'json',
                    timeout:50000,
                    beforeSend: function(){layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});},
                    success:function($d){
                        $bootstrapTable.bootstrapTable('refresh');
                        layer.msg($d.response_content, {icon: 1,time:1000});
                    },
                    error:function(xhrData){
                        layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
                    }
                });
            });
        });

        //新增
        $('#add').click(function(){
            var index = layer.open({
                type: 2,
                title: ['创建优惠券'],
                scrollbar:false,
                shadeClose: true,
                offset:[0,'20%'],
                queryParames:{},
                shade: [true,'rgba(0,0,0,.5)'],
                maxmin: true,
                shift:2,
                area: ['80%', '100%'],
                content: '/admin/coupon/add/'
            });
        });
    },
    add : function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });
        $('#defaultForm').bootstrapValidator({
            message: '这是个无效值',
            feedbackIcons: {/*input状态样式图片*/
                //valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {/*验证:规则*/
                name: {//验证input项:验证规则
                    validators: {
                        notEmpty: { message: '名称不能为空'},
                        stringLength: { min: 2, max: 50, message: '名称长度必须在2到50之间'}
                    }
                }
            }
        })
        .on('success.form.bv', function(e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            $.ajax({
                type: "post",
                url: $('#defaultForm').attr('action'),
                dataType: 'json',
                timeout:5000,
                data: $('body').find('form').serialize(),//表单数据
                beforeSend:function(){
                    $('#validateBtn').button('loading');
                    window.parent.layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
                },
                success: function (d) {
                    window.parent.layer.msg(errorMessage(d.response_content), {icon: 1,time:1000});
                    window.parent.$bootstrapTable.bootstrapTable('refresh');
                    window.parent.layer.closeAll('iframe');
                },
                error:function(xhrData){
                    window.parent.layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
                    $('#validateBtn').button('reset');
                }
            });
        });
        $('#validateBtn').click(function(){
            $('#defaultForm').bootstrapValidator('validate');
        });
        //时间选择
        if($('#datetimepicker').length){$('#datetimepicker').datetimepicker({timepicker:false,format:'Y/m/d'});}
        //时间选择
        if($('#datetimepicker2').length){$('#datetimepicker2').datetimepicker({timepicker:false,format:'Y/m/d'});}
    },
    edit : function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });
        $('#defaultForm').bootstrapValidator({
            message: '这是个无效值',
            feedbackIcons: {/*input状态样式图片*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {/*验证:规则*/
                name: {//验证input项:验证规则
                    validators: {
                        notEmpty: { message: '名称不能为空'},
                        stringLength: { min: 2, max: 50, message: '名称长度必须在2到50之间'}
                    }
                }
            }
        })
            .on('success.form.bv', function(e) {//点击提交之后
                e.preventDefault();
                var $form = $(e.target);
                var bv = $form.data('bootstrapValidator');
                $.ajax({
                    type: "post",
                    url: $('#defaultForm').attr('action'),
                    dataType: 'json',
                    timeout:5000,
                    data: $('body').find('form').serialize(),//表单数据
                    beforeSend:function(){
                        $('#validateBtn').button('loading');
                        window.parent.layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
                    },
                    success: function (d) {
                        window.parent.layer.msg(errorMessage(d.response_content), {icon: 1,time:1000});
                        window.parent.$bootstrapTable.bootstrapTable('refresh');
                        window.parent.layer.closeAll('iframe');
                    },
                    error:function(xhrData){
                        window.parent.layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
                        $('#validateBtn').button('reset');
                    }
                });
            });
        $('#validateBtn').click(function(){
            $('#defaultForm').bootstrapValidator('validate');
        });
        //时间选择
        if($('#datetimepicker').length){$('#datetimepicker').datetimepicker({timepicker:false,format:'Y/m/d'});}
        //时间选择
        if($('#datetimepicker2').length){$('#datetimepicker2').datetimepicker({timepicker:false,format:'Y/m/d'});}
    }
}