forked from kidgrow-microservices-platform

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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<form id="recharge-form" lay-filter="recharge-form" class="layui-form">
    <div class="layui-tab" style="margin-top: 5px;">
        <ul class="layui-tab-title">
            <li class="layui-this">合同信息</li>
        </ul>
        <div class="layui-tab-content" style="margin: 0px;">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item" style="padding: 0; margin-bottom: 0px;">
                    <div class="layui-row">
                        <div class="layui-col-sm5">
                            <label class="layui-form-label" style="padding: 0;">医院名称</label>
                            <div class="layui-input-block">
                                <input name="hospitalName" id="hospitalName" type="text" class="layui-input"
                                    style="border: none; margin-top:-10px" readonly />
                            </div>
                        </div>
                        <div class="layui-col-sm3">
                            <label class="layui-form-label" style="padding: 0;">科室名称</label>
                            <div class="layui-input-block">
                                <input name="departmentName" id="departmentName" style="border: none;  margin-top:-10px"
                                    readonly class="layui-input" />
                            </div>
                        </div>
                        <div class="layui-col-sm2">
                            <label class="layui-form-label" style="padding: 0;">服务人员</label>
                            <div class="layui-input-block">
                                <input name="serverUserName" id="serverUserName"
                                    style="border: none; margin-top:-10px;width: 120px;" readonly class="layui-input" />
                            </div>
                        </div>
                    </div>
                </div>
 
                <div class="layui-form-item" style="padding: 0; margin-bottom: 0px;">
                    <div class="layui-row">
                        <div class="layui-col-sm5">
                            <label class="layui-form-label" style="padding: 0 30px 0 0;">地区</label>
                            <input name="hospitalAreas" id="hospitalAreas" type="text"
                                style="border: none; width: 250px; margin-top:-10px" readonly class="layui-input" />
                        </div>
                        <div class="layui-col-sm3">
                            <label class="layui-form-label" style="padding: 0;">联系电话</label>
                            <div class="layui-input-block">
                                <input name="hospitalTel" id="hospitalTel" type="text" class="layui-input"
                                    style="border: none; margin-top:-10px" readonly />
                            </div>
                        </div>
                        <div class="layui-col-sm2">
                            <label class="layui-form-label" style="padding: 0;">联系人</label>
                            <div class="layui-input-block">
                                <input name="hospitalLink" type="text" class="layui-input"
                                    style="border: none; margin-top:-10px;width: 120px;" readonly />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="padding: 0; margin-bottom: 0px;">
                    <div class="layui-row">
                        <div class="layui-col-sm4">
                            <label class="layui-form-label" style="padding: 10px 30px 0 0px;">合同名称</label>
                            <div class="layui-input-block">
                                <input name="contractTitle" id="contractTitle" type="text" class="layui-input"
                                    maxlength="50" lay-verify="required" required autocomplete="off" />
                            </div>
                        </div>
                        <div class="layui-col-sm3">
                            <label class="layui-form-label">合同编号</label>
                            <div class="layui-input-block">
                                <input name="contractNo" id="contractNo" type="text" class="layui-input" maxlength="50"
                                    style="width: 185px;" autocomplete="off" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin: 10px 0px 0px 0px;">
                    <div class="layui-row">
                        <div class="layui-col-sm4">
                            <label class="layui-form-label" style="padding: 10px 30px 0 0px;">开始日期</label>
                            <input autocomplete="off" name="contractBeginTime" id="contractBeginTime" type="text"
                                class="layui-input" style="width: 182px;" maxlength="50" lay-verify="required"
                                required />
                        </div>
                        <div class="layui-col-sm4">
                            <label class="layui-form-label">截止日期</label>
                            <div class="layui-input-block">
                                <input autocomplete="off" name="contractEndTime" id="contractEndTime" type="text"
                                    class="layui-input" maxlength="50" lay-verify="required" required />
                            </div>
                        </div>
                        <div class="layui-col-sm4">
                            <label class="layui-form-label">签订日期</label>
                            <div class="layui-input-block">
                                <input autocomplete="off" name="contractTime" id="contractTime" type="text"
                                    class="layui-input" maxlength="50" lay-verify="required" required />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
 
    <div class="layui-tab" style="margin: 0px;">
        <ul class="layui-tab-title">
            <li class="layui-this">产品信息</li>
        </ul>
        <div class="layui-tab-content" style="margin: 0px;">
            <div class="layui-tab-item layui-show" style="padding-top: 0px;">
                <table class="layui-table" id="product-table" lay-filter="product-table" style="margin: 0px;"></table>
            </div>
        </div>
    </div>
 
    <div class="layui-tab" style="margin: 0px;">
        <ul class="layui-tab-title">
            <li class="layui-this">待充值产品</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show" style="padding-top: 0px;">
                <table class="layui-table" id="product-table-temp" lay-filter="product-table-temp" style="margin: 0px;">
                </table>
            </div>
        </div>
    </div>
    <div class="layui-form-item model-form-footer" style="margin-right: 20px;">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn permissions" permissions="product-rechage" lay-filter="recharge-form-submit" lay-submit>确定充值</button>
    </div>
    <input type="hidden" value="" id="departmentId" name="departmentId" />
    <input type="hidden" value="" id="hospitalId" name="hospitalId" />
    <input type="hidden" value="" id="orgId" name="orgId" />
    <input type="hidden" value="" id="serverUserId" name="serverUserId" />
</form>
<!-- 表格操作列 -->
<script type="text/html" id="product-tpl-bar">
    <a class="layui-btn layui-btn-xs" lay-event="pay">加入待充值</a>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="product-tpl-bar-temp">
    <a class="layui-btn layui-btn-danger" lay-event="del">移除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="product-tpl-isShare">
    <input type="checkbox" lay-filter="product-tpl-isShare" value="{{d.id}}" lay-skin="switch" lay-text="共享|不共享"/>
</script>
<script>
    layui.use(['form', 'table', 'util', 'config', 'laydate', 'admin'], 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 $ = layui.jquery;
        var laydate = layui.laydate;
 
        //执行一个laydate实例
        laydate.render({
            elem: '#contractBeginTime'//指定元素
        });
        laydate.render({
            elem: '#contractEndTime' //指定元素
        });
        laydate.render({
            elem: '#contractTime', //指定元素
            value: new Date().dateFormat("yyyy-MM-dd")
        });
        //现将临时数据清理
        admin.putTempData("t_tempProduct", "");
        //待充值列表
        var waitRecharge = function () {
            table.render({
                elem: '#product-table-temp',
                data: admin.getTempData("t_tempProduct"),
                page: false,
                height: '120px',
                cols: [[
                    { field: 'proName', width: 320, title: '产品名称', align: 'center', fixed: 'left' },
                    {
                        field: 'proType', align: 'center', width: 100, templet: function (d) {
                            if (d.proType === 0)
                                return "试用"
                            else
                                return "正式"
                        }, title: '类型'
                    },
                    {
                        field: 'proTime', width: 100, title: '时长', align: 'center', templet: function (d) {
                            switch (d.proTimeUnit) {
                                case 0:
                                    return d.proTime + "天";
                                    break;
                                case 1:
                                    return d.proTime + "月";
                                    break;
                                case 2:
                                    return d.proTime + "年";
                                    break;
                            }
                        }
                    },
                    { field: 'recordCount', width: 110, align: 'center', title: '报告数' },
                    { field: 'ailightCount', width: 100, align: 'center', title: '读片量' },
                    {
                        field: 'beginTime', align: 'center', width: 120, title: '开始日期'
                    },
                    {
                        field: 'endTime', align: 'center', width: 120, title: '结束日期'
                    },
                    {
                        field: 'isShare', fixed: 'right', align: 'center', width: 100, templet: function (d) {
                            if (d.isShare == 0)
                                return "不共享"
                            else
                                return "共享"
                        }, title: '共享'
                    },
                    { field: 'id', fixed: 'right', align: 'center', width: 80, toolbar: '#product-tpl-bar-temp', title: '操作' }
                ]]
            });
        }
 
        //回显医院基本数据
        let hospitalData = admin.getTempData('t_hospital');
        if (hospitalData != null) {
            form.val('recharge-form', hospitalData);
            $("#hospitalAreas").val(hospitalData.hospitalProvince + " " + hospitalData.hospitalCity + " " + hospitalData.hospitalArea);
        }
        //装载产品数据
        table.render({
            elem: '#product-table',
            url: config.base_server + 'api-opration/product',
            method: 'GET',
            headers: { 'Authorization': 'Bearer ' + config.getToken().access_token },
            page: false,
            height: '300px',
            where: { enabled: 1 },
            cols: [[
                { field: 'proName', sort: true, width: 300, title: '产品名称', align: 'center', fixed: 'left' },
                {
                    field: 'proType', sort: true, align: 'center', width: 80, templet: function (d) {
                        if (d.proType === 0)
                            return "试用"
                        else
                            return "正式"
                    }, title: '类型'
                },
                {
                    field: 'proTime', width: 100, title: '时长', align: 'center', templet: function (d) {
                        switch (d.proTimeUnit) {
                            case 0:
                                return d.proTime + "天";
                                break;
                            case 1:
                                return d.proTime + "月";
                                break;
                            case 2:
                                return d.proTime + "年";
                                break;
                        }
                    }
                },
                { field: 'recordCount', width: 100, align: 'center', title: '报告数' },
                { field: 'ailightCount', width: 100, align: 'center', title: '读片量' },
                {
                    field: 'beginTime', align: 'center', width: 130, title: '开始日期', templet: function (d) {
                        return getNowDate();
                    }, event: "date", edit: 'text'
                },
                {
                    field: 'endTime', align: 'center', width: 130, title: '结束日期', templet: function (d) {
                        return getNowDate(d.proTime, d.proTimeUnit);
                    }, event: "date", edit: 'text'
                },
                { field: 'isShare', fixed: 'right', align: 'center', width: 100, templet: '#product-tpl-isShare', title: '共享' },
                { field: 'id', fixed: 'right', align: 'center', width: 100, toolbar: '#product-tpl-bar', title: '操作' }
            ]],
            done:function(res){
                permissionsInput(res,config);
            }
        });
        //待充值列表功能操作
        table.on('tool(product-table-temp)', function (obj) {
            if (obj.event === "del") {
                if (!strUtil.isEmpty(obj.data.id)) {
                    delTempDataById(obj.data.id);
                    obj.del();
                }
            }
        });
        //单元格点击事件
        table.on('tool(product-table)', function (obj) {
            var data = obj.data;
            var selectData = {};
            if (obj.event === "pay") {
                data.beginTime = obj.tr.find("td[data-field='beginTime'] input").val();
                data.endTime = obj.tr.find("td[data-field='endTime'] input").val();
                data.beginTime = (!strUtil.isEmpty(data.beginTime)) ? data.beginTime : obj.tr.find("td[data-field='beginTime'] div").text();
                data.endTime = (!strUtil.isEmpty(data.endTime)) ? data.endTime : obj.tr.find("td[data-field='endTime'] div").text();
                data.isShare = obj.tr.find("td[data-field='isShare'] em").text();
                data.isShare = (data.isShare.indexOf("不") == 0) ? 0 : 1
                    ;
                if (!strUtil.isEmpty(data.beginTime) && !strUtil.isEmpty(data.endTime)) {
                    if (dateUtil.compareDate(data.endTime, data.beginTime)) {
                        tempDataList(data);
                        waitRecharge();
                    }
                    else {
                        layer.msg("结束时间必须大于开始时间!");
                        return false;
                    }
                }
                else {
                    layer.msg("时间格式有误!");
                    return false;
                }
            }
        });
        //监听单元格编辑 判断日期格式
        table.on('edit(product-table)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            if (dateUtil.isDate(value)) {
            }
            else {
                layer.msg("输入的日期格式无效!");
            }
        });
        //自动计算时间
        var getNowDate = function (proTime, proTimeUnit) {
            var now = new Date();
            if (strUtil.isEmpty(proTime) && strUtil.isEmpty(proTimeUnit)) {
                return now.dateFormat("yyyy-MM-dd");
            }
            else {
                proTime = strUtil.isEmpty(proTime) ? 0 : proTime;
                proTimeUnit = strUtil.isEmpty(proTimeUnit) ? 0 : proTimeUnit;
                switch (proTimeUnit) {
                    case 0:
                        return new Date(now.setDate(now.getDate() + proTime)).dateFormat("yyyy-MM-dd");
                        break;
                    case 1:
                        return new Date(now.setMonth(now.getMonth() + proTime + 1)).dateFormat("yyyy-MM-dd");
                        break;
                    case 2:
                        return new Date(now.setFullYear(now.getFullYear() + proTime)).dateFormat("yyyy-MM-dd");
                        break;
                }
            }
        }
        // 产品待充值数据
        var tempDataList = function (data) {
            if (!strUtil.isEmpty(data)) {
                var listData = admin.getTempData("t_tempProduct");
                if (strUtil.isEmpty(listData)) {
                    listData = new Array();
                }
                $.each(listData, function (index, value) {
                    if (value.id === data.id) {
                        //移除
                        listData.splice(index, 1);
                        return false;
                    }
                })
                listData.push(data);
                admin.putTempData("t_tempProduct", listData);
            }
            else {
                admin.putTempData("t_tempProduct", "");
            }
        }
        //移除指定数据
        var delTempDataById = function (id) {
            if (!strUtil.isEmpty(id)) {
                var listData = admin.getTempData("t_tempProduct");
                $.each(listData, function (index, value) {
                    if (value.id === id) {
                        //移除
                        listData.splice(index, 1);
                        return false;
                    }
                })
                admin.putTempData("t_tempProduct", listData);
            }
        }
        form.on('submit(recharge-form-submit)', function (data) {
            layer.load(2);
            var listData = admin.getTempData("t_tempProduct");
            if (listData != null) {
                if (data.field != null) {
                    layer.confirm("确定要将待充值列表中的" + listData.length + "个产品充值给当前医院吗?", { btn: ["确定", "返回"] }, function () {
                        data.field.contractBeginTime=data.field.contractBeginTime+" 00:00:00";
                        data.field.contractEndTime=data.field.contractEndTime+" 23:59:59";
                        data.field.contractTime=data.field.contractTime+" 00:00:00";
                        admin.req('api-opration/contract', JSON.stringify(data.field), function (data) {
                            layer.closeAll('loading');
                            if (data.code === 0) {
                                var orderData = data.data;
                                //处理订单明细数据
                                var listDetailData = new Array();
                                $.each(listData, function (index, item) {
                                    var detailData = {
                                        orderId: orderData.id,
                                        proId: item.id,
                                        proType: item.proType,
                                        proName: item.proName,
                                        isShare: item.isShare,
                                        ailightCount: item.ailightCount,
                                        recordCount: item.recordCount,
                                        proBegintime: item.beginTime + ' 00:00:00',
                                        proEndtime: item.endTime + ' 23:59:59'
                                    };
                                    listDetailData.push(detailData);
                                })
                                
                                if (listDetailData.length > 0) {
                                    //提交订单数据
                                    admin.req('api-opration/productorderdetail/saveall', JSON.stringify(listDetailData), function (data) {
                                        layer.closeAll('loading');
                                        if (data.code === 0) {
                                            //现将临时数据清理
                                            admin.putTempData("t_tempProduct", "");
                                            layer.msg(data.msg, { icon: 1, time: 20000 }, function () {
                                                admin.finishPopupCenter();
                                            });
                                        }
                                        else {
                                            layer.msg(data.msg, { icon: 2, time: 1000 });
                                        }
                                    }, 'POST');
                                }
                                else {
                                    layer.msg("充值数据异常为空!", { icon: 2, time: 1000 });
                                }
                            }
                            else {
                                layer.msg(data.msg, { icon: 2, time: 1000 });
                            }
                        }, 'POST');
                    })
                }
                else {
                    layer.msg("数据异常!", { icon: 2, time: 1000 });
                }
            }
            else {
                layer.msg("请先将要充值的产品加入待充值!", { icon: 2, time: 2000 });
            }
            layer.closeAll('loading');
            return false;
        });
    });
</script>