<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>备件申请-已完成</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="YHGL_YHGL_YHGL" html='<a href="${ctx}/customer/customerList"><li class="layui-this">用户管理</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询</button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto">
            <form class="layui-form" action="" lay-filter="component-form-group" id="searchForm">
            <div class="layui-form-item">

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="psname" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站地址：</label>
                    <div class="layui-input-block">
                        <input type="text" name="location" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">用户账号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="userAccount" class="layui-input" >
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">手机号码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobileTel" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">有无保修卡：</label>
                    <div class="layui-input-block" >
                        <select name="isWarranty" >
                            <option value="">请选择</option>
                            <option value="1" >否</option>
                            <option value="2" >是</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">标注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="remarks" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">用户类型：</label>
                    <div class="layui-input-block" >
                        <select name="userType" >
                            <option value="">请选择</option>
                            <option value="1" >能辉</option>
                            <option value="2" >注册用户</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">建站时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="updateTimeSta" class="layui-input" id="endStartTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="updateTimeEnd" class="layui-input" id="endEndTime" placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出</button>
                </div>
            </script>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        //layui.use(['table','layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();

        //开始日期
        var endStartTime = laydate.render({
            elem: '#endStartTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新结束日期的最小日期
                endEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                endEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var endEndTime = laydate.render({
            elem: '#endEndTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新开始日期的最大日期
                endEndTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        tableExt.render({
            elem: '#test'
            , title:'用户管理'
            , height: 'full-180'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/customer/getCustomerList'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                , {field: 'id', title: '操作',minWidth:'230', sort: false, align: 'center', templet:function(d){
                       var type = d.user_type;
                        var remarks = d.remarks;
                        var html = "";
                        if(isBlank(remarks)){
                            //新增按钮
                            html += "<a href=\"#\" class=\"layui-table-link layui-icon layui-icon-add-1\" style='font-size:14px;' onclick=\"addRemark('"+d.cuId+"')\">新增标注</a> &nbsp;&nbsp;";
                        }else{
                            //编辑按钮
                            html += "<a href=\"#\" class=\"layui-table-link layui-icon layui-icon-edit\" style='font-size:14px;' onclick=\"updateRemark('"+d.cuId+"','"+d.remarks+"')\">编辑</a> &nbsp;&nbsp;";
                        }

                       if(type=='2'){
                           if(d.status=='2'){
                               return html;
                           }
                           html += "<a href=\"#\" class=\"layui-table-link layui-icon layui-icon-close-fill\" style='font-size:14px;' onclick=\"Prohibit('"+d.cuId+"')\">禁用</a>";
                           return html;
                       }else{
                           if(isBlank(d.ps_name)){
                               return html;
                           }
                           if("2"==d.is_warranty){
                               html += "<a href=\"#\" class=\"layui-table-link layui-icon layui-icon-delete\" style='font-size:14px;' onclick=\"deleteWarranty('"+d.cuId+"')\">删除保修卡</a>";
                               return html;
                           }
                           html += "<a href=\"#\" class=\"layui-table-link layui-icon layui-icon-add-1 \" style='font-size:14px;' onclick=\"addWarrantyCard('"+d.psId+"','"+d.user_id+"','"+d.cuId+"')\">添加保修卡</a>";
                           return html;
                       }
                    }}
                , {field: 'remarks', title: '标注',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'status', title: '状态',minWidth:'120', sort: false, align: 'center',exportable:true,  templet:function(d){
                        if(d.status=='2'){
                            return "禁用";
                        }else{
                            return "正常";
                        }
                    },expFormat:function(d){
                        if(d.status=='2'){
                            return "禁用";
                        }else{
                            return "正常";
                        }
                    }}
                , {field: 'user_type', title: '用户类型',minWidth:'130', sort: false, align: 'center',exportable:true,  templet:function(d){
                        if(d.user_type=='2'){
                            return "注册用户";
                        }else{
                            return "云用户";
                        }

                    },expFormat:function(d){
                        if(d.user_type=='2'){
                            return "注册用户";
                        }else{
                            return "云用户";
                        }
                    }}
                , {field: 'ps_name', title: '电站名称',minWidth:'130', sort: false, align: 'center',exportable:true,  templet:function(d){
                    if(isBlank(d.ps_name)){
                        return "";
                    }
                        var html = "";
                            html += "<a href=\"#\" class=\"layui-table-link\" onclick=\"psDetail('"+d.psId+"','"+d.user_id+"')\">"+d.ps_name+"</a>";
                        return html;
                    }}
                , {field: 'location', title: '电站地址',minWidth:'150', sort: false, align: 'center', exportable:true, templet:function(d){
                        if(isBlank(d.psId)){
                            return "";
                        }
                        return d.province+""+d.city+""+d.area+""+d.location;
                    },expFormat:function(d){
                        if(isBlank(d.psId)){
                            return "";
                        }
                        return d.province+""+d.city+""+d.area+""+d.location;
                    }}
                , {field: 'install_date', title: '建站时间',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'user_account', title: '用户账号',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'mobile_tel', title: '手机号码',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'login_times', title: '登录总数',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'login_last_date', title: '最后一次登录时间',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'psId', title: '关联工单',minWidth:'150', sort: false, align: 'center',templet:function(d){
                        var html = "";
                        html += "<a lay-href=\"${ctx}/order/getPlatformOrder?name="+d.ps_name+"\" lay-text=\"全部工单\" class=\"layui-table-link\">查看工单</a>";
                        return html;
                    }}
                , {field: 'site_price', title: '电子保修卡',minWidth:'150', sort: false, align: 'center',templet:function(d){
                        var html = "";
                        html += "<a href=\"#\" class=\"layui-table-link\" onclick=\"checkCard('"+d.ps_name+"','"+d.user_id+"')\">查看详情</a>";
                        return html;
                    }}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '用户管理',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '用户管理',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });


        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });
    })


    function searchOrder() {
        //执行重载
        table.reload('test', {
            where: function (){
                return _serializeJson($("#searchForm"));
            }
        });
    }

    //查看详情
    function psDetail(id,userId){
        layer.open({
            type: 2
            , title: '电站详情'
            , content: '${ctx}/customer/toPsDetail?id=' + id+"&userId="+userId
            , area: ['80%', '88%']
            , yes: function(index, layero){

            }
        });
    }
    function updateRemark(id,remark){
        layer.prompt({
            formType: 2,
            title: '备注',
            value:remark,
            area: ['380px', '160px'],
            btnAlign: 'c',
            id: 'prompt',
            yes: function (index, layero) {
                // 获取文本框输入的值
                var value = layero.find(".layui-layer-input").val();
                $.ajax({
                    type:"POST",
                    url:"${ctx}/customer/updateRemark",
                    async:false,
                    data:{
                        id:id,
                        remark:value
                    },
                    success:function(result){
                        console.log(result)
                        if(result.code =='200'){
                            layer.msg("保存成功！")
                            searchOrder();
                        }else{
                            layer.msg("保存失败！")
                        }
                        layer.close(index);//关闭弹框
                    }
                })

            }
        });
    }

    function addRemark(id){
        layer.prompt({
            formType: 2,
            title: '备注',
            area: ['380px', '160px'],
            btnAlign: 'c',
            id: 'prompt',
            yes: function (index, layero) {
                // 获取文本框输入的值
                var value = layero.find(".layui-layer-input").val();
                $.ajax({
                    type:"POST",
                    url:"${ctx}/customer/updateRemark",
                    async:false,
                    data:{
                        id:id,
                        remark:value
                    },
                    success:function(result){
                        if(result.code =='200'){
                            layer.msg("保存成功！")
                            searchOrder();
                        }else{
                            layer.msg("保存失败！")
                        }
                        layer.close(index);//关闭弹框
                    }
                })

            }
        });
    }

    function addWarrantyCard(psId,userId,id){
            layer.open({
                type: 2,
                content: "${ctx}/customer/addWarrantyCard?userId="+userId+"&psId="+psId+"&id="+id //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                ,area: ['1100px','96%']
                ,title: false //不显示标题栏
                ,shade: 0.8
                /*  ,btn: ['确认生成', '取消']*/
                ,btnAlign: 'c'
                ,scrollbar:false
                ,cancel: function(){
                    searchOrder();
                }
            });
    }

    function deleteWarranty(id){
        var indexla = layer.confirm('您确定要删除电子保修卡吗？', {
            icon: 3,
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "POST",
                url: "${ctx}/customer/deleteWarrantyCard",
                data: {
                    cusId: id
                },
                success: function (result) {
                    if(result.code=='200'){
                        layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                            searchOrder();
                        });
                    }else {
                        console.log(result)
                        layer.msg('删除失败!', {icon: 2});
                    }
                },
                error:{
                }
            })
        }, function () {
            layer.close(indexla);
        });
    }

    function Prohibit(id){
        var indexla = layer.confirm('您确定要禁用该用户吗？', {
            icon: 3,
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "POST",
                url: "${ctx}/customer/ProhibitCustomer",
                data: {
                    id: id
                },
                success: function (result) {
                    if(result.code=='200'){
                        layer.msg('禁用成功！', {icon: 1, time: 1000}, function () {
                            searchOrder();
                        });
                    }else {
                        layer.msg('禁用失败!', {icon: 2});
                    }
                },
                error:{
                }
            })
        }, function () {
            layer.close(indexla);
        });
    }

    //查看电子保修卡
    function checkCard(name,userId){
        $.ajax({
            type:"POST",
            url:"${ctx}/main/customer/checkLookWarranty",
            async:false,
            data:{
                userId:userId
            },
            success:function(result){
                if(result.code =="205"){
                    layer.msg(result.msg)
                    return;
                }
                parent.layer.open({
                    type: 2,
                    content: "${ctx}/customer/lookWarranty?name="+name+"&userId="+userId //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                    ,area: ['950px','96%']
                    ,title: false //不显示标题栏
                    ,shade: 0.8
                    ,btnAlign: 'c'
                    ,scrollbar:false
                });
            }
        });
    }


    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>

