zrg
2024-10-15 4322ae28f78e1c393eb85eece4d8a4485bb23f7c
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>工作任务</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <script src="../../../layuiadmin/zgqCustom/zgqCustom.js"></script>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/Scripts/json2.js"></script>
    <script src="../../../layuiadmin/Scripts/jquery-1.4.1.js"></script>
    <script src="../../../layuiadmin/Scripts/webConfig.js"></script>
    <script src="../../../layuiadmin/PubCustom.js"></script>
    <script src="../../../layuiadmin/PageTitle.js"></script>
    <script src="../../../layuiadmin/BillMainAutoLoad.js"></script>
    <style>
        .main-btn { /*头部主按钮*/
            padding: 0 2px; /*调整按钮左右空隙大小*/
            height: 30px;
            line-height: 30px;
        }
 
        .btn-title {
            font-size: 16px;
        }
        /* 防止下拉框的下拉列表被隐藏---必须设置--- */
        .layui-table-cell {
            overflow: visible !important;
        }
        /* 使得下拉框与单元格刚好合适 */
        td .layui-form-select {
            margin-top: -10px;
            margin-left: -15px;
            margin-right: -15px;
        }
 
        .layui-form-item .layui-inline {
            margin-top: 5px;
            margin-bottom: 5px;
            margin-right: 0px;
        }
 
        .layui-form-label {
            width: 25%;
        }
    </style>
 
</head>
<body>
    <div class="layui-fluid" style="padding: 0;">
        <div class="layui-card" style="padding: 2px;background-color: #efefef;">
            <div class="layui-card-body" style="padding: 1px;">
                <form class="layui-form" action="" lay-filter="formData" style="background-color:white;">
                    <div style="padding: 2px; ">
                        <!--<button type="button" id="btnSearch" style="margin-left: 0px" class="layui-btn layui-btn-normal"  lay-submit="" lay-filter="btnSearch" >预览</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSearch" id="btnSearch">新增</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSearch" id="btnSearch">修改</button>-->
 
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSave" id="btnSave">保存</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnEdit" id="btnEdit">退出</button>
                        <!--<button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="set_CheckBill" id="set_CheckBill">审核</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="set_AbandonCheck" id="set_AbandonCheck">反审核</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="set_CloseBill" id="set_CloseBill">关闭</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="set_CancelCloseBill" id="set_CancelCloseBill">反关闭</button>-->
                    </div>
                    <div class="layui-tab" lay-filter="tab-POStockInBill" id="formElement">
 
                    </div>
                </form>
            </div>
        </div>
    </div>
 
    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'table', 'element','upload'], function () {
            //#region 公共变量
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , table = layui.table
                , form = layui.form
                , element = layui.element
                , upload = layui.upload;
 
            //模块名
            var HModName = "PM_WorkTaskBill";
            //获取参数
            var params = getUrlVars();
            var OperationType = params[params[0]]; //从参数中获取 数据类型  1添加 保存  2复制  3 编辑
            var linterid = params[params[1]]; //从参数中获取 单据内码
            var HEntryID = params[params[3]]; //工程项目子内码
            var HSouceBillType = params[params[2]]; //源单类型
            //#endregion
 
            //#region 判断是否登录 未登录则跳到登录页
            if (sessionStorage.login != "login") {
                layer.confirm("登录失效,请重新登录!", {
                    icon: 4, skin: 'layui-layer-lan', title: "温馨提示", closeBtn: 0, btn: ['重新登录']
                }, function () { window.location.href = "../../user/login.html"; });
            }
            //#endregion
 
            //#region 表头初始化
            init_BillMain(HModName, sessionStorage["HUserName"],form);
            //#endregion
 
            //#region 判断并设置操作类型、页面初始化
            if (OperationType == null || OperationType == 1) {                            //新增
                ////禁用组织选项
                //$("#HOrgID").attr("disabled", true);
                OperationType = 1;
                //生成并设置主表的内码和单据号
                createBillNo();
 
                //初始化制单人和制单时间
                $("#HMaker").val(sessionStorage["HUserName"]);
                $("#HMakerDate").val(Format(new Date(), "yyyy-MM-dd"));
 
 
                //初始化派单人
                getHEmpByHUserName();
 
                //文件选择初始化
                //PicUpload();
            }
            else if (OperationType == 3) {//如果修改则走下面 new     
                //初始化项目阶段表
                RoadBillMain(linterid);
 
                //文件选择初始化
                //PicUpload();
                //展示已上传的文件
                //getFileList_loaded();
            } else if (OperationType == 4 && HProjectStageID != null) {                     //下推
                ////禁用组织选项
                //$("#HOrgID").attr("disabled", true);
 
                //生成并设置主表的内码和单据号
                createBillNo();
                //初始化派单人
                getHEmpByHUserName();
 
                //初始化制单人和制单时间
                $("#HMaker").val(sessionStorage["HUserName"]);
                $("#HMakerDate").val(Format(new Date(), "yyyy-MM-dd"));
 
                //下推-页面设置
                //项目需求及问题清单 下推工作任务 页面赋值如果等于 4759  就是项目需求及问题清单的下推
                if (HSouceBillType == 4759) {
                    CustomerTaskRoadBillMain();
                } else {
                    set_WorkTaskReport();
                }
 
                //文件选择初始化
                //PicUpload();
            }
            //#endregion
 
            //#region 操作按钮触发事件
            //#region 保存提交
            form.on('submit(btnSave)', function (data) {//提交
                if (AllowLoadData_BillMain(data)) {
                    set_AddNew(data);
                }
            });
            //#endregion
 
            //#region 退出
            form.on('submit(btnEdit)', function (data) {
                if (params[1] != null) {
                    Pub_Close(1);
                } else if (params[1] == null) {
                    Pub_Close(2);
                }
            });
            //#endregion
            //#endregion
 
            //#region 页面其它方法
            //#region 获取参数
            function getUrlVars() {
                var vars = [], hash;
                var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                for (var i = 0; i < hashes.length; i++) {
                    hash = hashes[i].split('=');
                    vars.push(hash[0]);
                    vars[hash[0]] = hash[1];
                }
                return vars;
            }
            //#endregion
 
            //#region 生成单据号
            function createBillNo() {
                $.ajax({
                    url: GetWEBURL() + "/Web/GetMAXNum",
                    async: false,
                    type: "GET",
                    data: { "HBillType": '4753' },
                    success: function (d) {
                        //console.log(d.data);
                        $("#HInterID").val(d.data[0].HInterID);
                        $("#HBillNo").val(d.data[0].HBillNo);
                        $("#HDate").val(Format(new Date(), "yyyy-MM-dd"));
                    }
                });
            }
            //#endregion
 
            //#region 文件上传
            function PicUpload() {
                //多图片上传
                //多文件列表示例
                var ProImgByList = $('#ProImgByList')
                    , uploadListIns = upload.render({
                        elem: '#testList'
                        , url: GetWEBURL() + "/Cj_StationOutBill/UploadFile1"
                        , accept: 'file'
                        , multiple: true
                        , auto: false
                        //, bindAction: '#testListAction' //按扭绑定
                        , data: { "HBillNo": $("#HBillNo").val(), "HRemark": $("#HRemark").val(), "HUserName": sessionStorage["HUserName"] }
                        , choose: function (obj) {
                            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                            //读取本地文件
                            obj.preview(function (index, file, result) {
                                var tr = $(['<tr id="upload-' + index + '">'
                                    , '<td>' + file.name + '</td>'
                                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                                    , '<td>等待上传</td>'
                                    , '<td>'
                                    , '<button class="layui-btn layui-btn-xs demo-reload ">上传</button>'
                                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                                    , '</td>'
                                    , '</tr>'].join(''));
 
                                //单个重传
                                tr.find('.demo-reload').on('click', function () {
                                    obj.upload(index, file);
                                    return false;
                                });
 
                                //删除
                                tr.find('.demo-delete').on('click', function () {
                                    delete files[index]; //删除对应的文件
                                    tr.remove();
                                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
                                });
 
                                ProImgByList.append(tr);
                            });
                        }
                        , done: function (res, index, upload) {
                            if (res.code == 1) { //上传成功
                                var tr = ProImgByList.find('tr#upload-' + index)
                                    , tds = tr.children();
                                tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                                tds.eq(3).html(''); //清空操作
                                //tds.eq(3).find('.demo-reload').addClass('layui-hide'); //隐藏上传
 
                                //展示该单据全部上传的文件
                                getFileList_loaded();
                                return delete this.files[index]; //删除文件队列已经上传成功的文件
                            }
                            this.error(index, upload);
                        }
                        , error: function (index, upload) {
                            var tr = ProImgByList.find('tr#upload-' + index)
                                , tds = tr.children();
                            tds.eq(2).html('<span style="color: #FF5722;">上传失败[检查文件名及文件格式]</span>');
                            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示上传
                        }
                    });
            }
            //#endregion
 
            //#region 编辑时,获取已上传的文件列表
            function getFileList_loaded() {
                var HBillNo = $("#HBillNo").val();
                if (HBillNo != null || HBillNo != undefined) {
                    var ProImgByList = $('#ProImgByList1')
                    $.ajax({
                        url: GetWEBURL() + '/Cj_StationOutBill/Filelist',
                        async: false,
                        type: "GET",
                        data: { "HBillNo": HBillNo },
                        success: function (data1) {
                            if (data1.count == 1) {
                                var index = 0;
                                $('#ProImgByList1').empty();
                                for (var i = 0; i < data1.data.length; i++) {
                                    var tr = $(['<tr id="upload-' + i + '">'
                                        , '<td style="display:none">' + data1.data[i].HItemID + '</td>'
                                        , '<td style="display:none">' + data1.data[i].HSourceBillNo + '</td>'
                                        , '<td>' + data1.data[i].HFileName + '</td>'
                                        , '<td>' + (data1.data[i].HFileSize / 1014).toFixed(1) + 'kb</td>'
                                        , '<td style="color: #5FB878;">上传成功</td>'
                                        , '<td style="display:none">' + data1.data[i].url + '</td>'
                                        , '<td>'
                                        , '<button class="layui-btn layui-btn-xs  demo-dowload" type="button" id="deltefile" onclick="javascript:dowload(this)"><i class="layui-icon layui-icon-download-circle layuiadmin-button-btn"></i>下载</button>'
                                        , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" type="button" id="deltefile" onclick="javascript:toManager(this)"><i class="layui-icon layui-icon-delete layuiadmin-button-btn"></i>删除</button>'
                                        , '</td>'
                                        , '</tr>'].join(''));
                                    $('#ProImgByList1').append(tr);
                                }
                            } else {
                                layer.alert(data1.code + data1.Message, { icon: 5 });
                            }
                        }, error: function () {
                            layer.alert("接口请求失败!", { icon: 5 });
                        }
                    });
                }
            }
            //#endregion
 
            //#region 保存HMaker
            function set_AddNew(data) {
                //获取组织数据
                data.field.HPRDORGID = sessionStorage["OrganizationID"];//组织
                if (data.field.HOrderLevID == "") {
                    data.field.HOrderLevID = 0;
                }
                //若为编辑-保存,则更新修改人和修改时间
                if (OperationType == 3) {
                    data.field.HUpdater = sessionStorage["HUserName"];
                    data.field.HUpdaterDate = Format(new Date(), "yyyy-MM-dd");
                    $("#HUpdater").val(sessionStorage["HUserName"]);
                    $("#HUpdaterDate").val(Format(new Date(), "yyyy-MM-dd"));
                }
                //获取表头数据并序列化
                var sMainStr = JSON.stringify(data.field);              //主表数据
 
                //拼接序列化的数据
                var sMainSub = sMainStr + ';' + OperationType + ";" + sessionStorage["HUserName"];
 
                var index = layer.load();
                $.ajax({
                    type: "POST",
                    url: GetWEBURL() + "/PM_WorkTaskBill/AddBill",
                    async: true,
                    data: { "sMainSub": sMainSub },
                    dataType: "json",
                    success: function (data) {
                        if (data.count == 1) {
                            $('#btnSave').addClass("layui-btn-disabled").attr("disabled", true);
                            layer.close(index);
                            layer.msg("提交成功");
                        }
                        else {
                            layer.close(index);
                            layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                        }
                    },
                    error: function (err) {
                        layer.close(index);
                        layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    }
                });
            }
            //#endregion
 
            //#region 编辑 页面赋值
            function RoadBillMain(linterid)//加载表头
            {
                //#region 表头初始化
                var url = "/PM_WorkTaskBill/editInit";
                var user = sessionStorage["HUserName"];
                RoadBillMain_BillMain(url, linterid, user, form);
                //#endregion
            }
            //#endregion
 
            //#region 下推-页面赋值
            function set_WorkTaskReport() {
                $.ajax({
                    url: GetWEBURL() + "/PM_ProjectBill/set_WorkTask",
                    type: "GET",
                    async: false,
                    data: { "HInterID": linterid, "HEntryID": HEntryID, "user": sessionStorage["HUserName"] },
                    success: function (result) {
                        var tableMain = result.data;
                        if (result.data.length > 0) {
                            //主表 赋值
                            form.val("formData", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                                "HOrgID": tableMain[0]["HOrgID"]
                                , "HProjectID": tableMain[0]["HInterID"]
                                , "HProNumber": tableMain[0]["HProNumber"]
                                , "HProName": tableMain[0]["HProName"]
                                , "HProjectStageID": tableMain[0]["HProjectStageID"]
                                , "HProjectStageName": tableMain[0]["HProjectStageName"]
                                , "HMainSourceInterID": tableMain[0]["HInterID"]
                                , "HMainSourceEntryID": tableMain[0]["HEntryID"]
                                , "HMainSourceBillNo": tableMain[0]["HBillNo"]
                                , "HMainSourceBillType": tableMain[0]["HBillType"]
                            });
 
                            //组织的值HOrgID变化,重新渲染
                            HOrgIDBar = tableMain[0]["HOrgID"];
                        } else {
                            layer.alert("下推此数据,无工作任务存在!!!")
                        }
                    }
                })
            }
 
            // 项目需求及问题清单 下推工作任务 页面赋值
            function CustomerTaskRoadBillMain()//加载表头
            {
                $.ajax({
                    url: GetWEBURL() + "/PM_ProjectBill/PM_CustomerTaskBillMainEditList",
                    type: "GET",
                    async: false,
                    data: { "HInterID": linterid, "user": sessionStorage["HUserName"] },
                    success: function (result) {
                        var tableMain = result.data;
 
                        //主表 赋值
                        form.val("formData", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                            "HMainSourceInterID": tableMain[0]["HInterID"]
                            , "HMainSourceBillNo": tableMain[0]["单据号"]
                            , "HMainSourceBillType": tableMain[0]["单据类型"]
                            , "HProjectID": tableMain[0]["HProjectID"]
                            , "HProNumber": tableMain[0]["项目代码"]
                            , "HProName": tableMain[0]["项目名称"]
                            , "HProjectStageID": tableMain[0]["HProjectStageID"]
                            , "HProjectStageName": tableMain[0]["项目阶段"]
                            , "HName": tableMain[0]["需求名称"]
                            , "HDate": Format(new Date(tableMain[0]["日期"]), "yyyy-MM-dd")
                            , "HTaskNote": tableMain[0]["需求描述"]
                            , "HType": tableMain[0]["需求类型"]
                            , "HSendEmp": tableMain[0]["客户提出人"]
                            , "HReceiveEmp": tableMain[0]["接收人"]
                            , "HCopyEmp": tableMain[0]["抄送人"]
                            , "HRemark": tableMain[0]["表头备注"]
                            , "HTaskStatus": tableMain[0]["需求状态"]
                            , "HOrderLevID": tableMain[0]["HOrderLevID"]
                            , "HLastDate": Format(new Date(tableMain[0]["要求完成日期"]), "yyyy-MM-dd")
                            , "HOrgID": tableMain[0]["HOrgID"]
 
                        });
 
                    }
                })
            }
 
            //#endregion
 
            //#region 根据登录账户获取相应职员
            function getHEmpByHUserName() {
                var Czybm = sessionStorage["Czybm"];
 
                var wait = layer.load();
                $.ajax({
                    url: GetWEBURL() + '/PM_WorkTaskReportBill/getHEmpByHUserName',
                    type: "GET",
                    data: { "Czybm": Czybm, "user": sessionStorage["HUserName"] },
                    success: function (result) {
                        if (result.count == 1) {
                            var HSendEmp = result.data[0]["HEmpName"];
                            $("#HSendEmp").val(HSendEmp);
                            layer.close(wait);
                        } else {
                            layer.alert(result.code + result.Message, { icon: 5 });
                            layer.close(wait);
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                        layer.close(wait);
                    }
                });
            }
            //#endregion
            //#endregion
        });
        //#region 下载已上传的文件
        function dowload(r) {
            //得到当前所在行
            var rows = r.parentNode.parentNode.rowIndex;
            //得到所在行的第五列的内容:文件地址
            var url = $("#ProImgByList1 tr:eq(" + (rows - 1) + ") td:eq(5)").html();
            /*window.location.href = url;*/
            window.open(url)
        }
        //#endregion
 
        //#region 删除已上传的文件
        function toManager(r) {
            //得到当前所在行
            var rows = r.parentNode.parentNode.rowIndex;
            //得到所在行的第一列的内容:主键ID
            var HItemID = $("#ProImgByList1 tr:eq(" + (rows - 1) + ") td:eq(0)").html();
            //得到所在行的第二列的内容:单据号
            var HSourceBillNo = $("#ProImgByList1 tr:eq(" + (rows - 1) + ") td:eq(1)").html();
            //得到所在行的第三列的内容:文件名称
            var HFileName = $("#ProImgByList1 tr:eq(" + (rows - 1) + ") td:eq(2)").html();
            layer.confirm("确认要删除吗,删除后不能恢复", { title: "删除确认" }, function (index) {
 
                //删除已上传文件
                $.ajax({
                    url: GetWEBURL() + '/Cj_StationOutBill/DeleteFilelist',
                    type: "GET",
                    data: { "HItemID": HItemID, "HSourceBillNo": HSourceBillNo, "HFileName": HFileName },
                    success: function (data1) {
                        if (data1.count == 1) {
                            layer.alert(data1.Message, { icon: 1 });
                            $("#ProImgByList1 tr").eq((rows - 1)).remove();
                        }
                        else {
                            layer.alert(data1.code + data1.Message, { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            })
        }
            //#endregion
    </script>
</body>
</html>