1
yhj
2025-03-31 9003044073373185511f1e2c901285a3287e7fa4
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
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title></title>
        <script src="../../js/mui.min.js"></script>
        <script src="../../js/api.js"></script>
        <script src="../../js/common.js"></script>
        <link href="../../css/mui.min.css" rel="stylesheet" />
        <link rel="stylesheet" type="text/css" href="../../css/iconfont.css" />
        <script src="../../js/template-web.js"></script>
 
        <style type="text/css">
            .mui-content {
                margin-top: 2px;
            }
 
            .search {
                border: 1px solid #e0e0e0;
                border-radius: 5px;
                display: flex;
                width: 100%;
                align-items: center;
                margin-top: 10px;
                /* padding:0px 10px 0;*/
                background-color: rgba(255, 255, 255, 1);
                padding-left: 10px;
                margin-bottom: 10px;
                height: 40px;
            }
 
            .search textarea {
                margin-bottom: 0px;
                padding: 0px 0px;
                background: none;
                border-radius: 5px;
            }
 
            .search input {
                margin-bottom: 2px;
                padding: 0px 0px;
                background: none;
            }
 
            .ulcss {
                padding: 5px 5px;
            }
 
            .title-right {
                float: right;
                line-height: 44px !important;
                position: absolute;
                display: block;
                width: 100%;
                margin: 0 0px !important;
                padding: 0 !important;
                text-align: center;
                white-space: nowrap;
                color: #000;
                display: inline-block;
                overflow: hidden;
                width: auto;
                margin: 0;
                text-overflow: ellipsis;
                color: #0062CC;
            }
 
            .close {
                position: absolute;
                top: 0;
                right: 0;
                z-index: 99;
                color: red;
            }
        </style>
    </head>
    <body class="mui-fullscreen">
        <header class="mui-bar mui-bar-nav">
            <button type="button" class="mui-left mui-action-back mui-btn  mui-btn-link mui-btn-nav mui-pull-left">
                <span class="mui-icon mui-icon-left-nav"></span>
            </button>
            <h1 class="mui-title">PQC检验录入-拍照</h1>
            <span class="title-right mui-icon mui-icon-image" id="moreBtn"></span>
        </header>
        <div class="mui-content">
            <div class="search">
                <button type="button" id="backBtn" class="mui-btn mui-icon mui-icon-undo">取消</button>
                <input type="search" disabled="disabled" class="mui-input-clear" placeholder="">
                <button type="button" data-loading-text="提交中" id="sureBtn" class="mui-btn mui-btn-green mui-icon  mui-icon-plus">确认</button>
            </div>
            <li class="search" style="height: 120px;">
                <textarea id="areaId" class="form" rows="5" placeholder="请输入备注"></textarea>
            </li>
            <ul class="mui-table-view mui-grid-view mui-grid-9 ulcss" id="list">
                <li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-2" name='addPictrue' id="addPictrue">
                    <span class="mui-icon iconfont icon-tianjiazhaopian"></span>
                </li>
            </ul>
        </div>
        </div>
        <script id='ui-template' type="text/template">
            <% for(var i in record){ var item=record[i]; %>
            <li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-2 ">
            <div class="close" data-index="<%=item.INDEX%>">X</div>
                <a href="#" style="height: 3.125rem;">
                    <img class="mui-media-object mui-pull-left" src="<%=item.URL%>" data-preview-src="<%=item.URL%>">
                </a>
            </li>
            <% } %>
        </script>
        <script id='video-template' type="text/template">
            <% for(var i in record){ var item=record[i]; %>
            <li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-2 ">
            <div class="close" data-index="<%=item.INDEX%>">X</div>
                <a href="#" style="height: 3.125rem;">
                    <video controls="" autoplay="" name="media"  >
                        <source src="<%=item.URL%>" type="video/mp4">
                    </video>
                </a>
            </li>
            <% } %>
        </script>
        <script id='add-template' type="text/template">
            <li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-2" id="addPictrue">
                <span class="mui-icon iconfont icon-tianjiazhaopian" ></span>
            </li>
        </script>
 
        <script type="text/javascript" charset="utf-8">
            //mui.previewImage();
            var mid = "";var type = "";
            mui.init();
            mui.plusReady(function() {
                mid = GetQueryString('mid');
                type = GetQueryString('type');
                clickPictrue(); //初始化拍照按钮
                //照片列表
                document.getElementById('moreBtn').addEventListener('tap', function(event) {
                    openList()
                });
                //返回
                document.getElementById('backBtn').addEventListener('tap', function(event) {
                    mui.back();
                });
                //确定
                document.getElementById('sureBtn').addEventListener('tap', function(event) {
                    //备注不能为空
                    var myTextarea = document.getElementById('areaId').value;
                    if (myTextarea == '') {
                        mui.toast('请先填写备注')
                        return;
                    }
                    var listImg = document.querySelectorAll("#list a")
                    if (listImg.length > 0) {
                        if (listImg.length > 9) {
                            mui.toast('不能超过9张图片!')
                            return;
                        }
                        mui(this).button('loading');
                        upload();
                        setTimeout(function() {
                            mui(this).button('reset');
                        }.bind(this), 2000); 
                    } else {
                        mui.toast('请先上传文件')
                    }
 
                });
                //删除
                mui("#list").on("tap", ".close", function(event) {
                    var i = this.getAttribute('data-index');
                    var elem = this;
                    var li = elem.parentNode;
                    li.parentNode.removeChild(li);
                    //delete files[i];
                    files[i] = "";
                    //files.splice(i,1);
                })
            });
            function openList(){
                mui.openWindow({
                    id: "sample_pic_list",
                    url: "sample_pic_list.html?mid=" + mid,
                    extras: {
                        //自定义扩展参数,可以用来处理页面间传值 
                    },
                    show: { //控制打开页面的类型
                        autoShow: true,
                        //页面loaded事件发生后自动显示,默认为true 
                        aniShow: 'slide-in-right', //页面显示动画,默认为”slide-in-right“;  页面出现的方式 左右上下
                        duration: '100' //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒; 
                    },
                    waiting: { // 控制 弹出转圈框的信息
                        autoShow: true, //自动显示等待框,默认为true 
                        title: '加载中' //等待对话框上显示的提示内容 
                    }
                });
            }
            var node;
            function clickPictrue() {
                document.getElementById('addPictrue').addEventListener('tap', function(event) {
                    var elem = this;
                    var li = elem;
                    node = elem;
                    //li.parentNode.removeChild(li); //先移除拍照图标
                    selectphto();
                });
 
            }
 
            //拍照
            function selectphto() {
                if (mui.os.plus) {
                    var a = [{
                        title: "拍照"
                    }, {
                        title: "录像"
                    }, {
                        title: "从手机相册选择"
                    }];
                    plus.nativeUI.actionSheet({
                        title: "上传检验照片",
                        cancel: "取消",
                        buttons: a
                    }, function(b) { /*actionSheet 按钮点击事件*/
                        switch (b.index) {
                            case 0:
                                break;
                            case 1:
                                getImages(); /*拍照*/
                                break;
                            case 2:
                                getVideo(); /*录像*/ 
                                break;
                            case 3:
                                galleryImages(); /*打开相册*/
                                break;
                            default:
                                break;
                        }
                    })
                }
            }
 
            function addPictrues(paths) {
                var listImg = document.querySelectorAll("#list a")
                if (listImg.length >= 9) {
                    mui.toast('不能超过9张图片!')
                    return;
                }
                var record = [];
                var j = files.length;
                for (var i in paths) {
                    var path = paths[i]
                    var temp = {
                        URL: path,
                        INDEX: j
                    };
                    record.push(temp);
                    files.push({
                        path: path
                    });
                    j++;
                }
                node.parentNode.removeChild(node); //先移除拍照图标
                var html = document.getElementById("list").innerHTML;
                document.getElementById('list').innerHTML = html + template('ui-template', {
                    "record": record
                });
                html = document.getElementById("list").innerHTML;
                document.getElementById('list').innerHTML = html + template('add-template', {});
                clickPictrue();
            }
            function addVideos(paths) {
                var listImg = document.querySelectorAll("#list a")
                if (listImg.length >= 9) {
                    mui.toast('不能超过9张图片!')
                    return;
                }
                var record = [];
                var j = files.length;
                for (var i in paths) {
                    var path = paths[i]
                    var temp = {
                        URL: path,
                        INDEX: j
                    };
                    record.push(temp);
                    files.push({
                        path: path
                    });
                    j++;
                }
                node.parentNode.removeChild(node); //先移除拍照图标
                var html = document.getElementById("list").innerHTML;
                document.getElementById('list').innerHTML = html + template('video-template', {
                    "record": record
                });
                html = document.getElementById("list").innerHTML;
                document.getElementById('list').innerHTML = html + template('add-template', {});
                clickPictrue();
            }
            var files = [];
            //拍照
            function getImages() {
                var c = plus.camera.getCamera();
                c.captureImage(function(e) {
                    plus.io.resolveLocalFileSystemURL(e, function(entry) {
                        var imgSrc = entry.toLocalURL() + "?version=" + new Date().getTime(); //拿到图片路径
                        //alert(imgSrc);
                        addPictrues([imgSrc]); //添加照片的本地列表
                    }, function(e) {
                        console.log("读取拍照文件错误:" + e.message);
                    });
                }, function(s) {
                    console.log("error" + s);
                }, {
                    filename: "_doc/camera/",
                })
            }
            /*这是打开录像的事件*/
        function getVideo(){
            var cmr = plus.camera.getCamera();
            var res = cmr.supportedVideoResolutions[0];//获取支持的分辨率,拿默认的第一个
            var fmt = cmr.supportedVideoFormats[0];//获取支持的录像文件格式,拿默认的第一个
            cmr.startVideoCapture( function( e ){//录像成功后会返回一个路径到e这里
                    plus.io.resolveLocalFileSystemURL(e, function(entry){//这个是根据路径读取文件信息,其实这步可以省略。
                        //uploadVideo(e);
                        var imgSrc = entry.toLocalURL() + "?version=" + new Date().getTime(); //拿到图片路径
                        //alert(imgSrc);
                        addVideos([imgSrc]); //添加照片的本地列表
                    }, function(e){
                        console.log("读取录像文件错误:" + e.message);
                    });
            },function( error ) {
                    mui.toast("取消录制");
                },
                {resolution:res,format:fmt}
            );
        }
 
            //从本地相册选择
            function galleryImages() {
                // 从相册中选择图片
                plus.gallery.pick(function(e) {
                    /* for (var i in e.files) {
                        var fileSrc = e.files[i]
                        addPictrue(fileSrc); //添加照片的本地列表
                    } */
                    addPictrues(e.files);
                }, function(e) {
                    console.log("取消选择图片");
                }, {
                    //filter: "video",
                    filter: "none",
                    multiple: true,
                    maximum: 9,
                    system: false,
                    onmaxed: function() {
                        plus.nativeUI.alert('最多只能选择9张图片');
                    }
                });
            };
            // 上传的方法
            function upload() {
                var url = storage["_basePath"] + 'ht_file_sign/uploadFilepqc';
                //var url = api_localStorageGet("webPath") + '/ht_file/uploadFilepqc';
                //console.log(api_localStorageGet("webPath"))
                var wt = plus.nativeUI.showWaiting();
                createUp();
 
                function createUp() {
                    var task = plus.uploader.createUpload(url, {
                            method: "POST"
                        },
                        function(t, status) { //上传完成
                            wt.close();
                            //console.log(status+"="+JSON.stringify(t)); 
                            if (status == 200) {
                                console.log("上传成功:" + t.responseText);
                                var btnArray = ['查看所有照片', '继续上传'];
                                mui.confirm('已经上传成功,请选择接下来的操作', '提示', btnArray, function(e) {
                                    if (e.index == 1) {
                                        //继续上传,清空原有数据
                                        files = []
                                        document.getElementById('areaId').value = "";
                                        document.getElementById('list').innerHTML = template('add-template', {});
                                        clickPictrue();
                                    } else {
                                        openList()
                                    }
                                })
                            } else {
                                console.log("上传失败:" + status);
                                mui.toast("上传失败:" + status)
                            }
                        }
                    );
                    console.log(type)
                    //添加其他参数
                    task.addData("type1", type);
                    task.addData("company", api_localStorageGet("company"));
                    task.addData("factory", api_localStorageGet("factory"));
                    task.addData("mid", mid);
                    task.addData("username", api_localStorageGet("code"));
                    task.addData("note", document.getElementById('areaId').value)
                    //file:///storage/emulated/0/0001_1_1_0_00_11.png
                    //file:///storage/emulated/0/$MuMu共享文件夹/MuMu20190812134501.png
                    for (var i = 0; i < files.length; i++) {
                        if (files[i] == "" || typeof(files[i]) == "undefined") {
                            files.splice(i, 1);
                            i = i - 1;
                        } else {
                            task.addFile(files[i].path.toString(), {
                                key: "file" + i + ""
                            });
                        }
                        console.log(files[i].path.toString())
                    }
                    task.start();
                }
            }
        </script>
    </body>
</html>