songjun
2024-09-05 a3302fda10ff21ed3700be462ad560163ca13f14
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
@model sbcLabSystem.Models.Backstage.QCDistributionPageViewModel
@{
    ViewBag.Title = "质控发布";
    Layout = "~/Views/Shared/Master.cshtml";
}
<style>
    .modal-lg {
        width: 1500px;
    }
</style>
<script type="text/javascript">
    var viewModel;
    $(function () {
        viewModel = new myViewModel_QC(@Html.Raw(Json.Encode(Model)));
        ko.applyBindings(viewModel, $(".container")[0]);
        InitDateTimePicker();
    });
 
    function myViewModel_QC(data) {
        var self = this;
        self.isShowModel = ko.observable(false);
        self.isProcessing = ko.observable(false);
        self.Projects = ko.observableArray([
                    { Name: "Dock", Id: 1, Text: "I类项目" },
                    { Name: "G5", Id: 2, Text: "II类项目" },
                    { Name: "Amicus", Id: 3, Text: "III类项目" },
                    { Name: "Amicus", Id: 4, Text: "IV类项目" },
        ]);
        self.selectAll = function (dataInfo) {
            for (var i = 0; i < dataInfo.LabList().length ; i++) {
                dataInfo.LabList()[i].IsSelected(true);
            }
        }
        self.switchPage = function (page, dataInfo) {
            $.bootstrapLoading.start();
            SaveLabList(function () {
                if (page == "First") {
                    self.CurrentPageIndex(1);
                }
                else if (page == "Previous") {
                    var index = self.CurrentPageIndex() - 1;
                    if (index <= 1) {
                        index = 1;
                    }
                    self.CurrentPageIndex(index);
                }
                else if (page == "Next") {
                    var index = self.CurrentPageIndex() + 1;
                    self.CurrentPageIndex(index);
                }
                else if (page == "Last") {
                    self.CurrentPageIndex(999);
                }
                self.modifyLab(self.CurrentQCDistribution);
            });
            $.bootstrapLoading.end();
        };
        self.modifyLab = function (dataInfo) {
            DoAjaxPost('@Url.Action("GetLabList", "Backstage")'
                , "{\"qcDistNo\":" + ko.mapping.toJS(dataInfo).Id + ",\"pageIndex\":" + self.CurrentPageIndex() + "}"
                , function (json) {
                    viewModel.isShowModel(true);
                    ko.mapping.fromJS(json, {}, viewModel.CurrentQCDistribution);
                    $("#dialog_ManageLab").dialog({
                        title: "管理实验室",
                        backdrop: "static",
                        dialogClass: "modal-lg",
                        onClose: function () {
                            viewModel.isShowModel(false);
                            $(this).dialog("destroy");
                        }
                    });
                    $(".dialog").css("overflow-y", "scroll");
                });
 
        };
        self.addNewQcDistribution = function (dataInfo) {
            $.bootstrapLoading.start();
            $.ajax({
                type: "post",
                url: '@Url.Action("addNewQcDistribution", "Backstage")',
                dataType: 'json',
                cache: false,
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(ko.toJS(dataInfo)),
                success: function (json) {
                    $.bootstrapLoading.end();
                    ko.mapping.fromJS(json, {}, viewModel);
                    InitDateTimePicker();
                },
                error: function (err) {
                }
            });
        };
        self.saveDistribution = function (dataInfo) {
            $.bootstrapLoading.start();
            $.ajax({
                type: "post",
                url: '@Url.Action("saveDistribution", "Backstage")',
                dataType: 'json',
                cache: false,
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(ko.toJS(self)),
                success: function (json) {
                    ko.mapping.fromJS(json, {}, viewModel);
                    InitDateTimePicker();
                    $.bootstrapLoading.end();
                    $.messager.popup("保存成功!");
                },
                error: function (err) {
                }
            });
        };
        self.deleteDistribution = function (dataInfo) {
            $.messager.confirm("提示", "是否要删除该条记录?", function () {
                $.bootstrapLoading.start();
                $.ajax({
                    type: "post",
                    url: '@Url.Action("deleteDistribution", "Backstage")',
                    dataType: 'json',
                    cache: false,
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(ko.mapping.toJS(dataInfo)),
                    success: function (json) {
                        ko.mapping.fromJS(json, {}, viewModel);
                        InitDateTimePicker();
                        $.bootstrapLoading.end();
                        $.messager.popup("删除完成!");
                    },
                    error: function (err) {
                        $.messager.alert(JSON.stringify(err));
                    }
                });
            });
        }
        ko.mapping.fromJS(data, myViewModel_QC.mapping, self);
    }
    myViewModel_QC.mapping = {
        CurrentQCDistribution: {
            create: function (options) {
                return new QCDistributionInfo(options.data);
            }
        },
        QCDistributions: {
            create: function (options) {
                return new QCDistributionInfo(options.data);
            }
        }
    }
    function QCDistributionInfo(data) {
        var self = this;
        data.IssuedDate = moment(data.IssuedDate).format("YYYY-MM-DD");
        data.CloseDate = moment(data.CloseDate).format("YYYY-MM-DD");
        self.doManageLab = ko.pureComputed(function () {
            return "@Url.Action("QCDistributionLabs","Backstage")" + "?qcDistId={0}&pageIndex=1".format(self.Id());
        }, self);
        self.saveLabList = function (LabInfo) {
            SaveLabList(function () {
                alert("保存成功!");
            });
        }
        self.deleteLabInfo = function (dataInfo) {
            if (dataInfo.QCDistributionRegisterId() == 0) {
                return;
            }
            $.messager.confirm("提示", "是否要删除该条记录?", function () {
                $.ajax({
                    type: "post",
                    url: '@Url.Action("deleteDistributionRegisterInfo", "Backstage")',
                    dataType: 'json',
                    cache: false,
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(ko.mapping.toJS(dataInfo)),
                    success: function (json) {
                        alert("删除完成!");
                        dataInfo.IsSelected(false);
                        dataInfo.QCDistributionRegisterId(0);
                    },
                    error: function (err) {
                        $.messager.alert(JSON.stringify(err));
                    }
                });
            });
        }
        self.sendMail = function (dataInfo) {
            if (dataInfo.QCDistributionRegisterId() == 0) {
                return;
            }
            $.messager.confirm("提示", "是否要发送邮件?", function () {
                $.ajax({
                    type: "post",
                    url: '@Url.Action("sendEMSEmail", "Backstage")',
                    dataType: 'json',
                    cache: false,
                    contentType: 'application/json; charset=utf-8',
                    data: "{\"labInfoId\":{0},\"qcDistributionId\":{1}}".format(dataInfo.Id(), viewModel.CurrentQCDistribution.Id()),
                    success: function (json) {
                        alert("发送完成!");
                    },
                    error: function (err) {
                        $.messager.alert(JSON.stringify(err));
                    }
                });
            });
        }
        self.printMail = function (dataInfo) {
            $.messager.confirm("提示", "是否要打印快递单?", function () {
                var form = $("<form>");   //定义一个form表单
                form.attr('style', 'display:none');   //在form表单中添加查询参数
                form.attr('target', '');
                form.attr('method', 'post');
                form.attr('action', "@Url.Action("PrintEMS", "Backstage")");
 
                var input1 = $('<input>');
                input1.attr('type', 'hidden');
                input1.attr('name', 'labInfoId');
                input1.attr('value', dataInfo.Id());
                var input2 = $('<input>');
                input2.attr('type', 'hidden');
                input2.attr('name', 'qcDistributionId');
                input2.attr('value', viewModel.CurrentQCDistribution.Id());
                $('body').append(form);  //将表单放置在web中
                form.append(input1);   //将查询参数控件提交到表单上
                form.append(input2);
                form.submit();
            });
        }
        self.printLetter = function (dataInfo) {
            $.messager.confirm("提示", "是否要打印信封?", function () {
                var form = $("<form>");   //定义一个form表单
                form.attr('style', 'display:none');   //在form表单中添加查询参数
                form.attr('target', '');
                form.attr('method', 'post');
                form.attr('action', "@Url.Action("PrintEnvelope", "Backstage")");
 
                var input1 = $('<input>');
                input1.attr('type', 'hidden');
                input1.attr('name', 'labInfoId');
                input1.attr('value', dataInfo.Id());
                var input2 = $('<input>');
                input2.attr('type', 'hidden');
                input2.attr('name', 'qcDistributionId');
                input2.attr('value', viewModel.CurrentQCDistribution.Id());
                $('body').append(form);  //将表单放置在web中
                form.append(input1);   //将查询参数控件提交到表单上
                form.append(input2);
                form.submit();
            });
        }
        ko.mapping.fromJS(data, {}, self);
    }
    function SaveLabList(event) {
        viewModel.isProcessing(true);
        DoAjaxPost('@Url.Action("SaveLabList", "Backstage")'
            , ko.mapping.toJSON(viewModel.CurrentQCDistribution)
            , function (json) {
                event();
                ko.mapping.fromJS(json, {}, viewModel.QCDistributions);
                viewModel.isProcessing(false);
            });
    }
</script>
 
<div class="container">
    <div class="row" style="margin-top:10px;">
        <div class="col-xs-12">
            <a href="javascript:void(0);" class="btn btn-default" data-bind="click:addNewQcDistribution">发布新质评</a>
            <a href="javascript:void(0);" class="btn btn-primary" data-bind="click:$root.saveDistribution">保存</a>
        </div>
    </div>
    <div class="row" style="margin-top:10px;">
        <div class="col-xs-12">
            <table class="table table-bordered table-responsive table-condensed">
                <thead>
                    <tr>
                        <th>质评号</th>
                        <th>发布时间</th>
                        <th>结束时间</th>
                        <th>备注</th>
                        <th>参与实验室</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody data-bind="foreach:QCDistributions">
                    <tr>
                        <td>
                            <input type="text" class="form-control" data-bind="textInput:DistNo" />
                        </td>
                        <td>
                            <input type='text' class="input-date form-control" id='datetimepicker1' data-bind="value:IssuedDate" />
                        </td>
                        <td>
                            <input type='text' class="input-date form-control" id='datetimepicker2' data-bind="value:CloseDate" />
                        </td>
                        <td>
                            <input type="text" class="form-control" data-bind="textInput:Remark" />
                        </td>
                        <td class="text-center">
                            <span data-bind="text:UsedLabCount"></span>
                        </td>
                        <td data-bind="visible:Id()>0">
                            <a href="javascript:void(0);" class="btn btn-danger"
                               data-bind="click:$root.deleteDistribution">删除</a>
                            <a href="javascript:void(0);" class="btn btn-success"
                               data-bind="attr:{href:doManageLab}">管理实验室</a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div id="dialog_ManageLab" data-bind="visible:$root.isShowModel">
        <h3 class="text-center">管理实验室</h3>
        <div class="row">
            <div class="col-xs-12">
                <form>
                    <div class="form-group form-inline">
                        <span>关键字:</span>
                        <input type="text" data-bind="textInput:$root.KeyWord" class="form-control" />
                    </div>
                </form>
 
            </div>
        </div>
        <div data-bind="with:CurrentQCDistribution">
            <div class="row">
                <div class="col-xs-12">
                    <table class="table table-responsive table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>选择</th>
                                <th>实验室代码</th>
                                <th>单位名称</th>
                                <th>实验室名称</th>
                                <th>城市(地区)</th>
                                <th>质评项目</th>
                                <th>已收费</th>
                                <th>样本号</th>
                                <th>已发快递</th>
                                <th>快递单号</th>
                                <th>快递包内容</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody data-bind="foreach:LabList">
                            <tr>
                                <td>
                                    <input type="checkbox" class="form-control" data-bind="checked:IsSelected" />
                                </td>
                                <td data-bind="text:LabCode"></td>
                                <td data-bind="text:CompanyName"></td>
                                <td data-bind="text:LabName"></td>
                                <td data-bind="text:Province"></td>
                                <td>
                                    <select data-bind="options:$root.Projects,optionsText:'Text',optionsValue:'Id',value:ProjectId"></select>
                                </td>
                                <td>
                                    <input type="checkbox" class="form-control" data-bind="checked:IsCharged" />
                                </td>
                                <td>
                                    <input type="text" class="form-control" data-bind="textInput:SampleNo" />
                                </td>
                                <td>
                                    <input type="checkbox" class="form-control" data-bind="checked:IsSendEMS" />
                                </td>
                                <td>
                                    <input type="text" class="form-control" data-bind="textInput:EMSNo" />
                                </td>
                                <td>
                                    <input type="text" class="form-control" data-bind="textInput:PacketContent" />
                                </td>
                                <td>
                                    <div class="row">
                                        <div class="col-xs-6">
                                            <a href="javascript:void(0);" data-bind="click:$parent.deleteLabInfo,visible:QCDistributionRegisterId()>0" class="btn btn-danger glyphicon glyphicon-remove">删除</a>
                                        </div>
                                        <div class="col-xs-6">
                                            <a href="javascript:void(0);" data-bind="click:$parent.sendMail,visible:QCDistributionRegisterId()>0" class="btn btn-primary glyphicon glyphicon-envelope">发送邮件</a>
                                        </div>
                                    </div>
                                    <div class="row" style="margin-top:5px;">
                                        <div class="col-xs-6">
                                            <a href="javascript:void(0);" data-bind="click:$parent.printMail,visible:QCDistributionRegisterId()>0" class="btn btn-default glyphicon glyphicon-print">打印快递单</a>
                                        </div>
                                        <div class="col-xs-6">
                                            <a href="javascript:void(0);" data-bind="click:$parent.printLetter,visible:QCDistributionRegisterId()>0" class="btn btn-default glyphicon glyphicon-print">打印信封</a>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <form>
                        <div class="form-group form-inline">
                            <a href="javascript:void(0);" class="btn btn-default" data-bind="click:$root.selectAll">全选</a>
                            <a href="javascript:void(0);" class="btn btn-info" data-bind="click:function(data){ $root.switchPage('First',data) }">首页</a>
                            <a href="javascript:void(0);" class="btn btn-info" data-bind="click:function(data){ $root.switchPage('Previous',data) }">上页</a>
                            <a href="javascript:void(0);" class="btn btn-info" data-bind="click:function(data){ $root.switchPage('Next',data) }">下页</a>
                            <a href="javascript:void(0);" class="btn btn-info" data-bind="click:function(data){ $root.switchPage('Last',data) }">未页</a>
                            <span data-bind="text:CurrentPageIndex"></span>/
                            <span data-bind="text:LastPageIndex"></span>
                        </div>
                    </form>
                    <a href="javascript:void(0);" class="btn btn-primary center-block" data-bind="click:saveLabList">确定</a>
                </div>
            </div>
        </div>
    </div>
</div>