/**
 * 渠道付费未加V用户列表
 */
$(function(){

    $.form.render();

    var ffrom = $('#ffrom').val();

    $('#btn_export_channel').click(function(e){
        var startDate = $('#startDate').val();
        var endDate = $('#endDate').val();
        window.location.href = Config.ROOT + '/marketing/unJoinWxcorp/export?ffrom='+ffrom+'&startDate='+startDate+'&endDate='+endDate;
    });

    $('#btn_export').click(function(e){
        var startDate = $('#startDate').val();
        var endDate = $('#endDate').val();
        window.location.href = Config.ROOT + '/marketing/unJoinWxcorp/export?startDate='+startDate+'&endDate='+endDate;
    });

    $('#btn_search').click(function(e){
        var startDate = $('#startDate').val() || '';
        var endDate = $('#endDate').val() || '';
        var postData = {
            'startDate'	: startDate,
            'endDate'	: endDate
        };
        $table.search(postData);
    });

    AppWxmpAccessRecord = {
        Events : {'click .btn': function (e, value, row, index) {
            var event = $(e.target).data('event');
            if(event == 'edit'){
                AppWxmpAccessRecord.edit(value);
            }
        }},
        edit: function(wxmp_access_record_id){
            var updateWxmpAccessRecordUrl = $('#updateWxmpAccessRecordUrl').val();
            App.MsgBox.confirm('确定要设置为已召回吗', function(){
                App.Ajax.request({
                    url		: updateWxmpAccessRecordUrl,
                    headers : {
                        'ffrom' : ffrom
                    },
                    params  : JSON.stringify({
                        'wxmpAccessRecordId': wxmp_access_record_id,
                        'ifJoinWxcorp': true
                    }),
                    contentType: "application/json",
                    success: function(result){
                        $('#btn_search').click();
                    }
                });
            });
        }
    };
	
	//初始化表格
    var landingConfigExtendId = $('#landingConfigExtendId').val();
    var $table = new App.Table({
        url: Config.ROOT + '/marketing/unJoinWxcorp/list?ffrom='+ffrom+'&landingConfigExtendId='+landingConfigExtendId,
        search: false,
        showRefresh: false,
        showToggle: false,
        showColumns: false,
        searchPlaceholder: 'uid',
        columns	:[
            {checkbox: true},
            {field:'uid', title:'用户uid'},
            {field:'phone', title:'手机号'},
            {field:'pay_time', title:'付款时间', dateFormat: 'yyyy-MM-dd HH:mm:ss'},
            {field:'id', title:'订单号'},
            {field:'wxmp_access_record_id', title:'操作', width: 150, toolbar: 'tableRowToolbar', events: AppWxmpAccessRecord.Events}
        ],
        getQueryParam: function () {
            var startDate = $('#startDate').val() || '';
            var endDate = $('#endDate').val() || '';
            var postData = {
                'startDate'	: startDate,
                'endDate'	: endDate
            };
            return postData;
        }
    });

});