layui.extend({
    common    :   'js/common'
}).use(['jquery','table','layer','form','common','util'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    //  弹窗插件
    var layer = layui.layer;
    //  表单插件
    var form = layui.form;
    var common = layui.common;
    ;

    //表格对象
    var layuiTable = common.layuiTable.render(table,{
        elem: '#table-id'  //页面table的id
        , url: '/implement/integrated/service/showList' //后台接口
        ,method: 'post'
        , cellMinWidth: 80 //全局定义常规单元格的最小宽度，
        , cols: [[
            { field: 'name', title: '综合服务方', align: 'center'}
            , { field: 'region', title: '区域', align: 'center' }
            , { field: 'contractNumber', title: '项目数量', align: 'center'}
            , { field: 'personName', title: '联系人', align: 'center' }
            , { field: 'personTel', title: '电话', align: 'center' }
            , { field: 'createDate', title: '添加时间', align: 'center' }
            , { field: 'edit',title: '操作', toolbar: '#table-operate-id', align: 'center',width:180}

        ]]
        //  开启分页功能
        , page: true
    });

    //监听行工具事件  lay-filter="table-id"
    table.on('tool(table-id)', function(obj){
        var data = obj.data;
        if(obj.event === 'del'){
            layer.confirm('是否确认删除？',{icon: 7, title:'提示'}, function(index){
                //obj.del();删除选中的数据
                console.info(data.id);
                common.sendAsyncRequest("/implement/integrated/service/delete/"+data.id,'GET',"",function (result){
                    //刷新表格
                    layuiTable.reload();
                    layer.msg("删除成功");
                    layer.close(index);//关闭弹窗提示
                });
            });
        } else if(obj.event === 'edit'){ //编辑
            common.openDefaultIframe({
                title: '编辑',
                content:   '/implement/integrated/service/edit/view?id='+data.id
            });
        }
    });

    //监听服务方添加
    form.on('submit(add)', function(){
        common.openDefaultIframe({
            title: '新增',
            content:  '/implement/integrated/service/insert/view'
        });
    });
});

