forked from kidgrow-microservices-platform

zhaoxiaohao
2021-03-02 1a50269b1d072fe2da7e70ae48315ebeb4ef95f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">产品消费记录</h2>
        <span class="layui-breadcrumb pull-right">
            <a href="#!console">首页</a>
            <a><cite>产品消费记录</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">&emsp;
            <div  class="layui-col-sm10">
                <div class="layui-col-sm4">
                    <input type="text" class="layui-input search-input" id="startTime" placeholder="开始时间"> 至 <input type="text"
                    class="layui-input search-input" id="endTime" placeholder="结束时间"> &emsp;
                </div>
                <div class="layui-col-sm2">
                    <input id="product-search-value" autocomplete="off"  class="layui-input search-input" type="text" placeholder="按产品名" />&emsp;
                </div>
                <div class="layui-col-sm2">
                    <input id="hospital-search-value" autocomplete="off"  class="layui-input search-input" type="text" placeholder="按医院名" style="width: 100%;" />
                    <input type="hidden" id="hospitalId" value="">
                </div>
                <div class="layui-col-sm2">
                    &emsp;<button id="product-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                </div>
            </div>
        </div>
        <table class="layui-table" id="product-table" lay-filter="product-table"></table>
    </div>
</div>
<!-- 表格操作列 -->
<script type="text/html" id="product-table-bar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="product-tpl-state">
    <input type="checkbox" lay-filter="product-tpl-state" value="{{d.id}}" lay-skin="switch" lay-text="启用|已禁用"
           {{d.enabled==true?'checked':''}}/>
</script>
 
<script>
    layui.use(['table', 'util', 'admin', 'config', 'form', 'laydate', 'autocomplete'], function () {
        let table = layui.table;
        let util = layui.util;
        let admin = layui.admin;
        let form = layui.form;
        let config = layui.config;
        var autocomplete = layui.autocomplete;
        var laydate = layui.laydate;
 
        //执行一个laydate实例
        laydate.render({
            elem: '#startTime' //指定元素
        });
        laydate.render({
            elem: '#endTime' //指定元素
        });
 
        // 渲染表格
        var renderTable = function () {
            table.render({
                elem: '#product-table',
                url: config.base_server + 'api-opration/productorderrecord/all',
                method: 'GET',
                headers: { 'Authorization': 'Bearer ' + config.getToken().access_token },
                page: true,
                cols: [[
                    { field: 'hospitalName', width: 300, title: '医院名称' },
                    { field: 'departmentName', width: 100, title: '科室名称' },
                    { field: 'proName', width: 250, title: '产品名称' },
                    {
                    field: 'proType', sort: true, align: 'center', width: 80, templet: function (d) {
                        if (d.proType === 0)
                            return "试用"
                        else
                            return "正式"
                    }, title: '类型'
                },
                    { field: 'ailightCount', width: 100, title: '读片量' },
                    { field: 'recordCount', width: 100, title: '报告量' },
                    { field: 'isShare', width: 100, title: '是否共享',templet:function(d)
                    {
                        if(d.isShare)
                        return '共享'
                        else
                        return '私有'
                    }
                    },
                    { field: 'proBegintime', width: 120, title: '开始时间',templet:function(d){
                        return new Date(d.proBegintime).dateFormat("yyyy/MM/dd");
                    } },
                    { field: 'proEndtime', width: 120, title: '结束时间',templet:function(d){
                        return new Date(d.proEndtime).dateFormat("yyyy/MM/dd");
                    } },
                    // { field: 'createTime', width: 160, sort: true, title: '创建时间',templet:function(d){
                    //     return new Date(d.createTime).dateFormat("yyyy/MM/dd hh:mm:ss");
                    // } },
                    { field: 'createTime', width: 200, sort: true, title: '创建时间', templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy/MM/dd HH:mm')}}</div>" },
                    { align: 'center', width: 100, toolbar: '#product-table-bar', title: '操作' }
                ]]
            });
        }
        renderTable();
        // 工具条点击事件
        table.on('tool(product-table)', function (obj) {
            if (obj.event === 'del') { // 删除
                layer.confirm('您确定要删除这次充值吗?删除后不可恢复!', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('api-opration/productorderrecord/' + obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        layer.msg(data.msg, { icon: 1, time: 2000 }, function () {
                            renderTable();
                        });
                        obj.del();
                    }, 'DELETE');
                });
            }
        });
 
        // 搜索按钮点击事件
        $('#product-btn-search').click(function () {
            var startTime = $('#startTime').val();
            var endTime = $('#endTime').val();
            if (startTime != null && endTime != null) {
                var flag = compareDate(startTime, endTime);
                if (!flag) {
                    layer.msg('结束时间不得小于开始时间');
                    return;
                }
            }
            var proName = $('#product-search-value').val();
                var hospitalId = $('#hospitalId').val();
            table.reload('product-table', { where: { proName: proName,hospitalId: hospitalId,startTime: startTime, endTime: endTime } });
        });
       
        //比较日期大小
        function compareDate(logintime, logouttime) {
            var arys1 = new Array();
            var arys2 = new Array();
            if (logintime != null && logouttime != null) {
                arys1 = logintime.split('-');
                var logindate = new Date(arys1[0], parseInt(arys1[1] - 1), arys1[2]);
                arys2 = logouttime.split('-');
                var logoutdate = new Date(arys2[0], parseInt(arys2[1] - 1), arys2[2]);
                if (logindate > logoutdate) {
                    return false;
                } else {
                    return true;
                }
            }
        }
 
        //自动完成-医院名称
        autocomplete.render({
            elem: $('#hospital-search-value'),
            keywordsName: 'hospitalName',//查询关键字名称
            url: config.base_server + 'api-user/syshospital/findByName',
            template_val: '{{d.hospitalName}}',//选择后文本框显示的数据字段
            template_txt: "<div class='layui-table-cell'>{{d.hospitalName}}</div>",//下拉列表模板
            onselect: function (resp) {
                $("#hospitalId").val(resp.id);
            }
        });
    });
</script>