layui.define(['form', 'laydate', 'table', 'channelApi' ], function(exports) {
	var form = layui.form;
	var laydate = layui.laydate;
	var table = layui.table;
	var channelUrlApi=layui.channelUrlApi;
	var channelTable = null;
	var view = {
		init: function(){
			this.initTable();
			this.initSearchForm();
			this.initToolBar();
			window.dataReload = function(){
				Lib.doSearchForm($("#searchForm"), channelTable)
			}
		},
		initTable:function() {
			channelTable = table.render({
				elem : '#channelTable',
				height : Lib.getTableHeight(2),
				method : 'post',
				url : Common.ctxPath + '/directed/channel/list.json' //数据接口
				,page : true //开启分页
				,limit : 10,
				cols : [[ //表头
                    {
                        type : 'checkbox'
                    }, {
                        field : 'id',
                        title : 'ID',
                        width : 80,
                    }, {
                        field : 'orderchannel',
                        title : '渠道编码',
                        width : 100,
                    }, {
                        field : 'channelname',
                        title : '渠道名称',
                        width : 220,
                    }, {
                        field : 'channeltype',
                        title : '渠道类型',
                        width : 220,
                    }, {
                         field : 'newtype',
                         title : '渠道归类',
                         width : 220,
                    }, {
                        field : 'smschannel',
                        title : '短信归类',
                        width : 220,
                     }, {
                        field : 'sou',
                        title : 'sou',
                        width : 100,
                    }, {
                        field : 'inserttime',
                        title : '插入时间',
                        width : 200,
                        sort : true,
                    }, {
                        field : 'updatetime',
                        title : '更新时间',
                        width : 200,
                        sort : true,
                    }
				]],done: function (res, curr, count) {
	               	 layer.closeAll('loading');
	            }
			});
		},

		initSearchForm:function(){
			Lib.initSearchForm( $("#searchForm"), channelTable, form);
		},
		initToolBar:function(){
			toolbar = {
                add : function() { //获取选中数据
                    var url = "/directed/channel/add.do";
                    Common.openDlg(url,"渠道链接管理 > 新增活动");
                },
                edit : function() { //获取选中数目
                    var data = Common.getOneFromTable(table, "channelTable");
                    if(data == null){
                        return ;
                    }

                    var url = "/directed/channel/edit.do?id="+data.id;
                    Common.openDlg(url,"渠道链接管理 > 编辑");
                },
            };
			$('.ext-toolbar').on('click', function() {
				var type = $(this).data('type');
				toolbar[type] ? toolbar[type].call(this) : '';
			});
		}
	};

	 exports('index',view);

});
