//config的设置是全局的
layui.config({
    base: '/static/js/extend/' //假设这是你存放拓展模块的根目录
}).extend({ //设定模块别名
    common: 'common' //如果 mymod.js 是在根目录，也可以不用设定别名
});


layui.use(['form','table','upload','common'], function() {
    var form = layui.form;
    var common = layui.common;
    var table = layui.table;
    var $ = layui.jquery,upload = layui.upload;
    table.render({
        elem: '#userTable'
        , url: '/user/getList'
        , id: 'id'
        , loading: true
        ,method:"post"
        ,contentType:"application/json;charset=UTF-8"
        , cols: [[
            {field: 'id', title: 'ID', sort: true, checkbox: true, fixed: 'left'}
            , {field: 'userNo', title: '服务编号'}
            , {field: 'name', title: '名字', sort: true}
            , {field: 'userCellphone', title: '用户手机号', sort: true}
            , {field: 'provinceId', title: '维修省份',templet:function (d) {
                return common.ajaxGetRequest("/lbs/getLbsMapById",{id:d.provinceId}).name;
            }}
            , {field: 'cityId', title: '维修市区',templet:function (d) {
                    return common.ajaxGetRequest("/lbs/getLbsMapById",{id:d.cityId}).name;
                }}
            , {field: 'servicesAreaId', title: '维修区域',templet:function (d) {
                var areaList="";
                if (d.servicesAreaId!=null &&d.servicesAreaId.length>0){
                    var servicesAreaIds= d.servicesAreaId.split(",");
                    for (var i = 0; i <servicesAreaIds.length ; i++) {
                        areaList += common.ajaxGetRequest("/lbs/getLbsMapById",{id:servicesAreaIds[i]}).name+",";
                    }
                }else{
                    return "暂无维修区域"
                }
                return areaList.substring(0,areaList.length-1);
            }}
            , {field: 'state', title: '状态',templet:function (d) {
                return d.state==1?"正常":"禁用";
            }}
            ,{field: 'createTime', title: '创建时间'}
        ]]
        , page: true
    });

    //指定允许上传的文件类型
    upload.render({
        elem: '#importUser'
        ,url: '/user/uploadUserFile'
        ,accept: 'file' //普通文件,
        ,data:""
        ,done: function(res,index,upload){
            if (res.code=="01"){
                table.reload("id");
                layer.alert('导入成功', {
                    icon: 1,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                });
            }else{
                layer.alert('导入失败，请联系管理员', {
                    icon: 2,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                });
            }
        }
    });

    $(document).on('click', '#queryForm', function() {
        table.reload("id",{
            where:{
                queryUserName:$("input[name='queryUserName']").val(),
                queryUserPhone:$("input[name='queryUserPhone']").val(),
                queryBusinessRegion:$("input[name='queryBusinessRegion']").val()
            }
        })
    });

});
