forked from kidgrow-microservices-platform

zxh
2020-08-21 5d97b0934973737a903f45d1d89e095b2e255694
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">医院管理</h2>
        <span class="layui-breadcrumb pull-right">
            <a href="#!home_console">首页</a>
            <a><cite>医院管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            <select id="province" placeholder="省份" lay-filter="province">
            </select>
            <select id="city" placeholder="市" lay-filter="city">
                <option value="">选择市</option>
            </select>
            <select id="areas" placeholder="区县" lay-filter="areas">
                <option value="">选择区县</option>
            </select>
            <select id="isscreen" placeholder="选择筛查状态" lay-filter="isscreen">
                <option value="">-是否筛查-</option>
                <option value="1">-是-</option>
                <option value="0">-否-</option>
            </select>
            &emsp;
            <!-- <select id="isanswer" placeholder="选择医答状态" lay-filter="isanswer">
                <option value="">-是否医答-</option>
                <option value="1">-是-</option>
                <option value="0">-否-</option>
            </select>
             &emsp;
            <select id="hospitalstate" placeholder="选择医院状态" lay-filter="hospitalstate">
                <option value="">-医院状态-</option>
                <option value="0">试用</option>
                <option value="1">正式</option>
            </select> -->
            &emsp;
            <input id="hosName" class="layui-input search-input" type="text" placeholder="按医院名" />&emsp;
            <button id="hospita-btn-search" class="layui-btn icon-btn"><i
                    class="layui-icon permissions" permissions="hospital-get">&#xe615;</i>搜索</button>&emsp;
            <button id="hospital-btn-add" class="layui-btn icon-btn"><i class="layui-icon permissions" permissions="hospital-save">&#xe654;</i>添加医院/科室</button>
        </div>
 
        <!-- 数据表格 -->
        <table class="layui-table" id="hospital-table" lay-filter="hospital-table"></table>
    </div>
</div>
 
<!-- 表格操作列 -->
<script type="text/html" id="businessRecords-table-bar">
    <a class="layui-btn layui-btn-xs permissions" permissions="product-rechage" lay-event="pay">充值</a>
    <!-- <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看详情</a> -->
    <a class="layui-btn layui-btn-primary layui-btn-xs permissions" permissions="hospital-save" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs permissions" permissions="hospital-del" lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="hospital-tpl-state">
    <input type="checkbox" lay-filter="hospital-tpl-state" value="{{d.hospitalId}}" value2="{{d.departmentId}}" lay-skin="switch" lay-text="启用|禁用"
           {{d.enabled==true?'checked':''}}/>
</script>
<script>
    layui.use(['form', 'table', 'laydate', 'util', 'config', 'admin', 'autocomplete', 'area'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;
        var area = layui.area;
        
        // 渲染表格
        table.render({
            elem: '#hospital-table',
            url: config.base_server + 'api-user/syshospital',
            method: 'GET',
            headers: { 'Authorization': 'Bearer ' + config.getToken().access_token },
            page: true,
            cols: [[
                { field: 'hospitalName', width: 250, title: '医院名称', fixed: 'left' },
                { field: 'departmentName', width: 100, title: '科室/部门', fixed: 'left' },
                {
                    field: 'hospitalArea', width: 360, title: '所在地区', templet: function (d) {
                        return ((d.hospitalProvince == null) ? "" : d.hospitalProvince) + " "
                            + ((d.hospitalCity == null) ? "" : d.hospitalCity) + " " +
                            ((d.hospitalArea == null) ? "" : d.hospitalArea)
                    }
                },
                { field: 'hospitalLink', width: 100, title: '联系人' },
                { field: 'hospitalTel', width: 150, title: '联系方式' },
                // {
                //     field: 'enabled', width: 80,  title: '状态', templet: function (d) {
                //         return d.hospitalState == 0 ? "试用" : "正式"
                //     }
                // },
                {
                    field: 'isScreen', width: 80,  title: '筛查', templet: function (d) {
                        return d.isScreen ? "是" : "否"
                    }
                },
                // { field: 'isAnswer', width: 80,  title: '医答',templet:function (d) {
                //     return d.isScreen?"是":"否"
                // } },
 
                { field: 'serverUserName', width: 100, title: '服务人员' },
                { field: 'createTime', width: 150,  title: '创建时间', templet:function (d) {
                        return new Date(d.createTime).dateFormat("yyyy-MM-dd hh:mm");
                    } },
                { field: 'enabled', width: 100, templet: '#hospital-tpl-state',  title: '状态' },
                { field: 'hospitalId', width: 200, align: 'center', toolbar: '#businessRecords-table-bar', title: '操作', fixed: 'right' }
            ]],
            done:function(res){
                permissionsInput(res,config);
            }
        });
        //省份数据加载
        area.areaData("#province", 1, "", "");
        // 工具条点击事件
        table.on('tool(hospital-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'del') {
                layer.confirm('确定要删除吗?', function (i) {
                    layer.load(2);
                    var whereModel = {
                        id: obj.data.hospitalId,
                        departmentId: obj.data.departmentId
                    };
                    admin.req('api-user/syshospital/delete', whereModel, function (data) {
                        layer.closeAll('loading');
                        layer.msg(data.msg, { icon: 1, time: 2000 }, function () {
                            $('#hospita-btn-search').click();
                        });
                        obj.del();
                    }, 'GET');
                });
            }
            else if (layEvent === "edit") {
                //修改
                admin.putTempData("t_hospital", data);
                showEditModel("edit");
            }
            else if(layEvent==="pay")
            {
                //充值
                admin.putTempData("t_hospital", data);
                admin.popupCenter({
                title: '医院充值',
                path: 'pages/opration/recharge.html',
                area: '1200px',
                offset:'10px',
                finish: function () {
                    $('#hospita-btn-search').click();
                }
            });
            }
        });
        // 搜索按钮点击事件
        $('#hospita-btn-search').click(function () {
            var isscreen = $('#isscreen').val();
            var isanswer = $('#isanswer').val();
            var hospitalstate = $('#hospitalstate').val();
            var hospitalName = $('#hosName').val();
 
            var hospitalProvince = ($("#province").val() != "") ? $('#province option:selected').text() : "";
            var hospitalCity = ($("#city").val() != "") ? $('#city option:selected').text() : "";
            var hospitalArea = ($("#areas").val() != "") ? $('#areas option:selected').text() : "";
 
            var whereModel = {
                isScreen: isscreen,
                isAnswer: isanswer,
                hospitalState: hospitalstate,
                hospitalName: hospitalName,
                hospitalProvince: hospitalProvince,
                hospitalCity: hospitalCity,
                hospitalArea: hospitalArea
            };
            table.reload('hospital-table', { where: whereModel });
        });
 
        // // 显示编辑弹窗
        var showEditModel = function (data) {
            admin.popupCenter({
                title: (strUtil.isEmpty(data))?'添加医院':'编辑医院',
                path: 'pages/opration/hospital_form_base.html',
                area: '900px',
                finish: function () {
                    $('#hospita-btn-search').click();
                }
            });
        };
 
        //装载市区数据
        form.on("select(province)", function (data) {
            area.areasClear("#areas", 3);
            area.areaData("#city", 2, data.value, "");
        });
 
        //装载区县数据
        form.on("select(city)", function (data) {
            area.areaData("#areas", 3, data.value, "");
        });
        // 修改状态
        form.on('switch(hospital-tpl-state)', function (obj) {
            layer.load(2);
            admin.req('api-user/syshospital/updateEnabled', {
                id: obj.elem.value,
                departmentId: obj.elem.getAttribute("value2"),
                enabled: obj.elem.checked ? true : false
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, { icon: 1, time: 2000 });
                } else {
                    layer.msg(data.msg, { icon: 2, time: 2000 });
                    $(obj.elem).prop('checked', !obj.elem.checked);
                    form.render('checkbox');
                }
            }, 'GET');
        });
        // 添加按钮点击事件
        $('#hospital-btn-add').click(function () {
            admin.putTempData("t_hospital","");
            showEditModel();
        });
    });
</script>