@page
@model Waste.Web.Entry.Pages.Business.IndexModel
@{
    ViewData["Title"] = "客户管理";
}
<div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="Name" id="Name" placeholder="请输入商户名称" />
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="Phone" id="Phone" placeholder="请输入商户手机号" />
                </div>
            </div>
            <div class="layui-inline">
                <button class="btn btn-primary btn-lg  js-search" type="button">查询</button>
                <button class="btn btn-primary btn-lg  js-add" type="button">添加</button>
            </div>
        </div>
    </div>
    <div class="layui-card-body">
        <table class="layui-table" id="list" lay-filter="list">
        </table>
    </div>
</div>
<script type="text/html" id="optpl">
    <a href="#" class="js-edit" title="编辑" data-id="{{d.id}}">编辑</a>&nbsp;
    <a href="#" class="js-return" title="密码重置" data-id="{{d.id}}">重置密码</a>
</script>
@section Scripts
{
    <script type="text/javascript">
        layui.use(['common'], function () {
            var common = layui.common;
            common.initTable({
                url: '/api/business/getlist'
                , method: 'post'
                , cols: [[
                    {
                        field: 'name', title: '商户'
                    },
                    {
                        field: 'phone', title: '手机号'
                    }
                    ,
                    {
                        field: 'businesscnt', title: '子商户数'
                    }
                    ,
                    {
                        field: 'devcnt', title: '设备数'
                    }
                    ,
                    {
                        field: 'todaycount', title: '今日测量'
                    }
                    ,
                    {
                        field: 'todaydevactivecnt', title: '今日设备活跃数'
                    }
                    ,
                    {
                        field: 'todayweight', title: '今日毛重'
                    }
                    ,
                    {
                        field: 'todaypureweight', title: '今日净重'
                    }
                    ,
                    {
                        field: 'totalcount', title: '累计称重'
                    }
                    ,
                    {
                        field: 'totalweight', title: '累计毛重'
                    }
                    ,
                    {
                        field: 'totalpureweight', title: '累计净重'
                    }
                    ,
                    {
                        field: 'status', title: '状态', templet: function (d) {
                            return StatusType[d.status];
                        }
                    }
                    ,
                    {
                        field: 'createtime', title: '注册时间'
                    },
                    {
                        title: '操作', templet: "#optpl"
                    }
                ]]
            });
            $(".js-search").on("click", function () {
                common.reloadtable("list", {
                    where: {
                        queryParam: [{
                            "Name": 'Name',
                            "Type": QueryCond.Like,
                            "Value": $("#Name").val()
                        }, {
                            "Name": 'Phone',
                            "Type": QueryCond.Like,
                            "Value": $("#Phone").val()
                        }]
                    }
                });
            });
            $(".js-add").on("click", function () {
                common.dialog({
                    title: '添加商户',
                    content: '/Business/Edit'
                });
            });
            $("body").on("click", ".js-edit", function () {
                var id = $(this).data('id');
                common.dialog({
                    title: '编辑商户',
                    content: '/Business/Edit?id=' + id
                });
            });
            $("body").on("click", ".js-return", function () {
                var id = $(this).data('id');
                common.prompt({
                    title: '请输入新密码',
                    formType: 1,
                    value: ''
                }, function (value) {
                    common.ajax({
                        url: "/api/business/resetpwd?id=" + id + "&pwd=" + value
                    });
                });
            });
        });
    </script>
}