<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp"/>
    <script type="text/javascript">
        require("staff/userAppList.js");
    </script>
    <style type="text/css">
        .layui-table th {
            text-align: center;
        }
    </style>
</head>
<body>
<div class="row animated fadeInRight" style="margin: 0;">
    <div class="wrapper wrapper-content mt5 right-content ml5 mr5">
        <div class="toolbar-panel bdd">
            <div class="toolbar-box">
                <div class="toolbar-head clearfix lgraybg pt5 pb10 pl10 bdbd">
                    <!-- 顶部按钮 -->
                    <div class="fl">
                        查询条件
                    </div>
                    <div class="tools fr">
                        <a href="javascript:void(0);" class="collapse dblock f14 dgray mr5">
                            <i class="fa-2x fa fa-angle-double-up"></i>
                        </a>
                    </div>
                </div>
            </div>
            <!--搜索条件 -->
            <div class="toolbar-body">
                <form class="layui-form" action="" style="margin-top: 10px">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入用户ID" id="userId" name="userId"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">员工名称</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入员工名称" id="userName" name="userName"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入手机号" id="phone" name="phone"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商户手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入商户手机号" id="contactMobile" name="contactMobile"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">商户简称</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入商户简称" id="alias" name="alias"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="mb50 mt10">
        <div class="whitebg pl10 pr10">
            <table class="layui-hide" id="staffList" lay-filter="staffList"></table>
        </div>
    </div>
</div>
</body>

<script id="toolBar" type="text/html">
    <a class="layui-btn layui-btn-sm" href="javascript:void(0);"
       onclick="queryUserApp()">
        <i class="layui-icon layui-icon-search"></i>搜索
    </a>
    <a class="layui-btn layui-btn-sm" href="javascript:void(0);"
       onclick="initAddStaffUserApp()">
        <i class="layui-icon layui-icon-add-1"></i>添加
    </a>
    <a class="layui-btn layui-btn-sm layui-btn-danger"
       href="javascript:void(0);" onclick="initBatchDeleteUserApp()">
        <i class="layui-icon layui-icon-delete"></i>删除
    </a>
</script>

<script id="barDemo" type="text/html">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/javascript">
    var layer;
    var form;
    var table;
    var laydate;
    var dropdown;
    //form表单样式
    layui.use(['table', 'layer', 'form', 'laydate', 'mDropdown'], function () {
        layer = layui.layer;
        form = layui.form;
        table = layui.table;
        laydate = layui.laydate;
        dropdown = layui.mDropdown;
        form.render();

        //执行一个 table 实例
        table.render({
            elem: '#staffList'
            , id: 'staffList'
            , url: '${ctx}/staff/queryUserAppByPage' //数据接口
            , where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                userType: $("#userType").val(),
                phone: $("#phone").val(),
                userName: $("#userName").val(),
                storeId: $("#storeId").val(),
                alias: $("#alias").val(),
                phone: $("#phone").val(),
                contactMobile: $("#contactMobile").val(),
                userId: $("#userId").val()
            }
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
                , statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.userAppList //解析数据列表
                };
            }
            , title: '商户详情'
            , toolbar: '#toolBar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['filter']
            , cols: [[ //表头
                {type: 'numbers'}
                , {type: 'checkbox'}
                , {field: 'userId', title: '用户ID', align: "center"}
                , {field: 'userName', title: '员工名称', minWidth: 100, align: "center"}
                , {field: 'phone', title: '手机号', minWidth: 120, align: "center"}
                , {field: 'contactMobile', title: '商户手机号', minWidth: 100, align: "center"}
                , {field: 'loginName', title: '员工账号', minWidth: 100, align: "center",}
                , {field: 'alias', title: '商户简称', minWidth: 120, align: "center"}
                , {field: 'merchantName', title: '所属商户', minWidth: 120, align: "center"}
                , {
                    field: 'createDt', title: '创建日期', width: 160, align: "center",
                    templet: "<div>{{layui.util.toDateString(d.createDt, 'yyyy-MM-dd HH:mm:ss')}}</div>"
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
            ]]
            , page: true //开启分页
            , request: {
                pageName: 'currPage' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , done: function (res) {
                dropdown.suite();
            }
        });
        //监听行工具事件
        table.on('tool(staffList)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么?', function (index) {
                    obj.del(data);
                    layer.close(index);
                    initDeleteUserApp(obj);
                });
            } else if (obj.event === 'edit') {
                initAddStaffUserApp(obj.data);
            }
        });
    });

    //查询
    function queryUserApp() {
        table.reload('staffList', {
            page: {
                curr: 1
            }
            , where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                userType: $("#userType").val(),
                phone: $("#phone").val(),
                userName: $("#userName").val(),
                storeId: $("#storeId").val(),
                alias: $("#alias").val(),
                phone: $("#phone").val(),
                contactMobile: $("#contactMobile").val(),
                userId: $("#userId").val()
            }
        });
    }

    //增加
    function initAddStaffUserApp(obj) {
        var url = '${ctx}/staff/queryUserAppBaseInfo';
        if (obj != undefined) {
            url = "${ctx}/staff/queryUserAppBaseInfo/" + obj.id
        }
        var index = layer.open({
            type: 2
            , shade: 0.5
            , maxmin: true
            , content: url
            , area: ['550px', '500px']
        });
    }

    //删除
    function initDeleteUserApp(id) {
        $.ajax({
            url: ctx + '/staff/deleteStaff',
            data: [{
                name: 'id',
                value: id
            }],
            type: 'POST',
            dataType: 'json',
            success: function (result) {
                queryUserApp(pageIndex);
                if (result.code == '1') {
                    layer.msg('删除成功!');
                } else if (result.code == '0') {
                    layer.msg(result.msg);
                }
            }
        });
    }
</script>
</html>

