Apicloud——关于上传图片、视频(二)

2019-03-26  09:53:22

很多时候都佩服自己写的东西,相当的低劣了(T-T)。

重新整理一下上传图片与视屏,对我来说已经精简了很多了,实际应用中多个文件现在成了一个文件了。

虽然还是相当的低劣,但是收获还是挺多的,对操作数组和dom有了更多的认识。

效果:

数据结构:

 1 {
 2                 "code": 200,
 3                 "message": "获取成功!",
 4                 "data": [{
 5                         "type": 1,
 6                         "stage": "",
 7                         "list_content": [{
 8                                 "material_id": 1,
 9                                 "type": 1,
10                                 "type_name": "aaa",
11                                 "stage": "basic",
12                                 "material_content": [{
13                                         "name": "身份证正面",
14                                         "material_path": ""
15                                     },
16                                     {
17                                         "name": "身份证正面",
18                                         "material_path": ""
19                                     },
20                                     {
21                                         "name": "身份证正面",
22                                         "material_path": ""
23                                     }
24                                 ]
25                             },
26                             {
27                                 "material_id": 2,
28                                 "type": 1,
29                                 "type_name": "aaa",
30                                 "stage": "basic",
31                                 "material_content": [{
32                                         "name": "身份证反面",
33                                         "material_path": ""
34                                     },
35                                     {
36                                         "name": "身份证反面",
37                                         "material_path": ""
38                                     }
39                                 ]
40                             }
41                         ]
42                     }。。。。。。。。。。。。。。。
View Code

整个HTML部分:

 1 <body>
 2 
 3     <header style="display:flex;flex-direction:column-reverse;" class="buy_car_wrap00 mui-bar" id="header">
 4         <div style="width:100%;height:60px;display:flex;justify-content:space-around;align-items:center;">
 5             <div class="buy_car_arrowl" onclick="api.closeWin()"></div>
 6             <div style="height:100%;width:65%;display:flex;align-items:center;justify-content:center;">上传终审资料</div>
 7             <div></div>
 8         </div>
 9     </header>
10 
11     <div class="z" id="z" style="margin-bottom:50px;">
12 
13     </div>
14 
15     <nav class="mui-bar mui-bar-tab nav" id="nav" onclick="updata()" style="width:100%;height:50px;display:flex;justify-content: center;align-items: center;">
16         <div style="height:50px;display:flex;justify-content: center;align-items: center;">提交</div>
17     </nav>
18 
19     <div style="display:none;background-color:black;opacity: 0.9;position:absolute;z-index:9999!important;height:100%;width:100%" id="bigpic">
20         <img src="" alt="" style="height: 45%;width: 98%;margin-top:50%;border-radius: 4px;opacity: 1;">
21     </div>
22 
23 </body>

数据循环部分:

先循环了标题,然后在对应标题中循环了图片或者视屏。

 1 function xin() {
 2         api.ajax({
 3             url: 'http://xxxxx/index/repay/getRepayDataNew',
 4             method: 'post',
 5             data: {
 6                 values: {
 7                     order_id: upnames
 8                 }
 9             }
10         }, function(ret, err) {
11             if (ret) {
12                 // console.log(JSON.stringify(ret.data));
13                 var retData = ret.data;
14                 console.log(retData.length);
15 
16                 for (var i = 0; i < retData.length; i++) {
17                     // console.log(JSON.stringify(retData[i].list_content))
18                     var means = retData[i].list_content
19 
20 
21                     // xinstr.length = 0;
22                     for (var j = 0; j < means.length; j++) {
23                         // console.log(JSON.stringify(means[j].material_content[0].name))
24                         var biaoti = means[j].material_content[0].name;
25 
26                         var tj = means[j].material_content;
27                         // console.log(JSON.stringify(tj.length));
28                         biaotiid = means[j].material_id;
29                         types = means[j].type;
30 
31 
32                         xinstr.push(biaotiid)
33 
34                         var biaoti_html = ''
35                         biaoti_html += '<div class="fangku2">' +
36                             '<div class="customer">' +
37                             '<div class="top">' + biaoti + '</div>' +
38                             '<div class="kuang">' +
39 
40 
41                             '<div class="img">' +
42                             '<div style="margin:5px;" class="po" id="' + biaotiid + '" onclick="add(' + biaotiid + ',' + types + ',this)">' +
43                             '<img src="../icon/add.png" alt="" id="">' +
44                             '<div class="tzi" >添加</div>' +
45                             '</div>' +
46                             '</div>' +
47 
48 
49                             '<div class="c"></div>' +
50                             '</div>' +
51                             '</div>' +
52                             '</div>'
53 
54                         $('#z').append(biaoti_html);
55 
56 
57                         for (var z = 0; z < tj.length; z++) {
58                             // console.log(JSON.stringify(tj));
59                             var pss = tj[z].material_path;
60                             var wipelater = pss.replace(/http:\/\/[^\/]*/g, "").replace(/\"/g, "");
61                             str0 = pss.substring(pss.length - 5, pss.length - 9);
62                             var str = pss.substring(pss.length - 4, pss.length - 9);
63                             var pic_html = '';
64                             if (types == 3) {
65                                 pic_html += '<div style="margin:5px;" id="' + biaotiid + '" class="' + biaotiid + '">' +
66                                     '<img src="../icon/sp.png" alt="' + wipelater + '" id="' + str + '" name="' + pss + '" onclick="play(this,0)">' +
67                                     '<div class="tzi" style="color:red" onclick="deletePic(\'' + wipelater + '\',this)">删除</div>' +
68                                     '</div>'
69                             } else {
70                                 pic_html += '<div style="margin:5px;" id="' + biaotiid + '" class="' + biaotiid + '">' +
71                                     '<img src="' + tj[z].material_path + '" alt="' + wipelater + '" id="' + str + '" onclick="enlarge(this)">' +
72                                     '<div class="tzi" style="color:red" onclick="deletePic(\'' + wipelater + '\',this)">删除</div>' +
73                                     '</div>'
74                             }
75 
76                             if (tj[z].material_path != '') {
77                                 $('#' + biaotiid + '').before(pic_html);
78                             }
79 
80 
81                             var altimg = $('#' + str0 + '').children('img').attr("alt");
82 
83                             // console.log(altimg);
84                             altimgArr.push(altimg);
85                             list.push({
86                                 [biaotiid]: wipelater
87                             })
88 
89                         }
90 
91                     }
92 
93                 }
94 
95             } else {
96                 alert(JSON.stringify(err));
97             }
98         });
99     }
View Code

数组处理部分:

对push的新数组进行重新的整合。

 1 //操作数组
 2     function scy(roomNames) {
 3         // console.log(roomNames);
 4         // console.log(roomNames.length);
 5         allRoom = {};
 6         if (roomNames.length > 0) {
 7             for (var i = 0; i < roomNames.length; i++) {
 8                 var map = roomNames[i];
 9                 // console.log($api.strToJson(map));
10                 for (var k in map) {
11                     // console.log(k+','+map[k]);
12                     if (k != null && k != 'null') {
13                         if (allRoom.hasOwnProperty(k)) { //true
14                             allRoom[k] += ',' + map[k];
15                         } else {
16                             allRoom[k] = map[k];
17                         }
18                     }
19                 }
20             }
21         }
22         // console.log(JSON.stringify(allRoom));
23         // list.push(allRoom)
24     }

删除部分:

这里不仅需要删除div同时要删除数组中的数据。

 1 //删除图片、视频
 2     function deletePic(btid, ever) {
 3         // console.log(btid);
 4         var strbtid = JSON.stringify(btid);
 5         var strlist = JSON.stringify(list);
 6         // console.log();
 7         for (var i = 0; i < list.length; i++) {
 8             var ks = JSON.stringify(list[i]);
 9             if (ks.indexOf(strbtid) != -1) {
10                 list.splice(i, 1);
11                 i--;
12             }
13         }
14         // console.log(JSON.stringify(list));
15         ever.parentNode.parentNode.removeChild(ever.parentNode);
16     }
View Code

动态添加部分:

添加的图片视屏,同样是获取图片、视屏地址push入数组。

 1 //动态添加公用函数
 2     function addhtml(biaotiid, dynamic, change, typ) {
 3         console.log(change);
 4         str1 = change.substring(change.length - 4, change.length - 9);
 5         var dongtai_html = '';
 6 
 7         if (typ == 3) {
 8             console.log(JSON.stringify(dynamic));
 9             var vi = JSON.stringify(dynamic);
10             dynamic2 = vi.replace(/\"/g, "").replace(/\[/g, "").replace(/\]/g, "");
11             console.log(dynamic2);
12 
13             dongtai_html += '<div style="margin:5px;" id="' + biaotiid + '">' +
14                 '<img src="../icon/sp.png" alt="' + change + '"  name="' + change + '" onclick="play(this,1)">' +
15                 '<div class="tzi" style="color:red" onclick="deletePic(\'' + change + '\',this)">删除</div>' +
16                 '</div>'
17         } else {
18             dongtai_html += '<div style="margin:5px;display:block;"   id="' + biaotiid + '">' +
19                 '<img onclick="enlarge(this);" src="' + dynamic + '" alt="' + change + '">' +
20                 '<div class="tzi" onclick="deletePic(\'' + change + '\',this);" style="color:red;">删除' +
21                 '</div>' +
22                 '</div>'
23         }
24 
25         $('#' + biaotiid + '').before(dongtai_html);
26 
27         // console.log($('#z').html());
28         list.push({
29             [biaotiid]: change
30         });
31         // console.log(JSON.stringify(list));
32     }
View Code

全部内容:

  1 <!DOCTYPE HTML>
  2 <html>
  3 
  4 <head>
  5     <meta charset="utf-8">
  6     <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  7     <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  8     <title>业务员-终审上传资料</title>
  9     <link rel="stylesheet" type="text/css" href="../css/aui.css" />
 10     <link rel="stylesheet" type="text/css" href="../css/api.css" />
 11     <link rel="stylesheet" type="text/css" href="../css/style.css" />
 12     <link rel="stylesheet" type="text/css" href="../css/muimin.css" />
 13     <link rel="stylesheet" type="text/css" href="../css/finalupcss.css" />
 14     <style media="screen">
 15 
 16     </style>
 17 </head>
 18 
 19 <body>
 20 
 21     <header style="display:flex;flex-direction:column-reverse;" class="buy_car_wrap00 mui-bar" id="header">
 22         <div style="width:100%;height:60px;display:flex;justify-content:space-around;align-items:center;">
 23             <div class="buy_car_arrowl" onclick="api.closeWin()"></div>
 24             <div style="height:100%;width:65%;display:flex;align-items:center;justify-content:center;">上传终审资料</div>
 25             <div></div>
 26         </div>
 27     </header>
 28 
 29     <div class="z" id="z" style="margin-bottom:50px;">
 30 
 31     </div>
 32 
 33     <nav class="mui-bar mui-bar-tab nav" id="nav" onclick="updata()" style="width:100%;height:50px;display:flex;justify-content: center;align-items: center;">
 34         <div style="height:50px;display:flex;justify-content: center;align-items: center;">提交</div>
 35     </nav>
 36 
 37     <div style="display:none;background-color:black;opacity: 0.9;position:absolute;z-index:9999!important;height:100%;width:100%" id="bigpic">
 38         <img src="" alt="" style="height: 45%;width: 98%;margin-top:50%;border-radius: 4px;opacity: 1;">
 39     </div>
 40 
 41 </body>
 42 <script type="text/javascript" src="../script/api.js"></script>
 43 <script type="text/javascript" src="../script/jquerymin.js"></script>
 44 <script type="text/javascript" src="../script/muimin.js"></script>
 45 <script type="text/javascript" src="../script/finalup.js"></script>
 46 <script>
 47     var user_id = $api.getStorage('user_id');
 48     var str0;
 49     var biaotiid;
 50     var xinstr = [];
 51     var altimgArr = [];
 52     var list = [];
 53     var types;
 54     var video_vi;
 55 
 56 
 57     // var dd = '20180508171316363781'
 58     apiready = function() {
 59         upnames = api.pageParam.upname;
 60         upnums = api.pageParam.upnum;
 61         console.log(JSON.stringify(upnames));
 62         console.log(JSON.stringify(upnums));
 63         // zsreceive();
 64 
 65         xin();
 66 
 67         //加红点
 68         var newdiv = '<div style="color:red;">*</div>'
 69         $('.top').prepend(newdiv);
 70     };
 71 
 72     function xin() {
 73         api.ajax({
 74             url: 'http://xxxxx/index/repay/getRepayDataNew',
 75             method: 'post',
 76             data: {
 77                 values: {
 78                     order_id: upnames
 79                 }
 80             }
 81         }, function(ret, err) {
 82             if (ret) {
 83                 // console.log(JSON.stringify(ret.data));
 84                 var retData = ret.data;
 85                 console.log(retData.length);
 86 
 87                 for (var i = 0; i < retData.length; i++) {
 88                     // console.log(JSON.stringify(retData[i].list_content))
 89                     var means = retData[i].list_content
 90 
 91 
 92                     // xinstr.length = 0;
 93                     for (var j = 0; j < means.length; j++) {
 94                         // console.log(JSON.stringify(means[j].material_content[0].name))
 95                         var biaoti = means[j].material_content[0].name;
 96 
 97                         var tj = means[j].material_content;
 98                         // console.log(JSON.stringify(tj.length));
 99                         biaotiid = means[j].material_id;
100                         types = means[j].type;
101 
102 
103                         xinstr.push(biaotiid)
104 
105                         var biaoti_html = ''
106                         biaoti_html += '<div class="fangku2">' +
107                             '<div class="customer">' +
108                             '<div class="top">' + biaoti + '</div>' +
109                             '<div class="kuang">' +
110 
111 
112                             '<div class="img">' +
113                             '<div style="margin:5px;" class="po" id="' + biaotiid + '" onclick="add(' + biaotiid + ',' + types + ',this)">' +
114                             '<img src="../icon/add.png" alt="" id="">' +
115                             '<div class="tzi" >添加</div>' +
116                             '</div>' +
117                             '</div>' +
118 
119 
120                             '<div class="c"></div>' +
121                             '</div>' +
122                             '</div>' +
123                             '</div>'
124 
125                         $('#z').append(biaoti_html);
126 
127 
128                         for (var z = 0; z < tj.length; z++) {
129                             // console.log(JSON.stringify(tj));
130                             var pss = tj[z].material_path;
131                             var wipelater = pss.replace(/http:\/\/[^\/]*/g, "").replace(/\"/g, "");
132                             str0 = pss.substring(pss.length - 5, pss.length - 9);
133                             var str = pss.substring(pss.length - 4, pss.length - 9);
134                             var pic_html = '';
135                             if (types == 3) {
136                                 pic_html += '<div style="margin:5px;" id="' + biaotiid + '" class="' + biaotiid + '">' +
137                                     '<img src="../icon/sp.png" alt="' + wipelater + '" id="' + str + '" name="' + pss + '" onclick="play(this,0)">' +
138                                     '<div class="tzi" style="color:red" onclick="deletePic(\'' + wipelater + '\',this)">删除</div>' +
139                                     '</div>'
140                             } else {
141                                 pic_html += '<div style="margin:5px;" id="' + biaotiid + '" class="' + biaotiid + '">' +
142                                     '<img src="' + tj[z].material_path + '" alt="' + wipelater + '" id="' + str + '" onclick="enlarge(this)">' +
143                                     '<div class="tzi" style="color:red" onclick="deletePic(\'' + wipelater + '\',this)">删除</div>' +
144                                     '</div>'
145                             }
146 
147                             if (tj[z].material_path != '') {
148                                 $('#' + biaotiid + '').before(pic_html);
149                             }
150 
151 
152                             var altimg = $('#' + str0 + '').children('img').attr("alt");
153 
154                             // console.log(altimg);
155                             altimgArr.push(altimg);
156                             list.push({
157                                 [biaotiid]: wipelater
158                             })
159 
160                         }
161 
162                     }
163 
164                 }
165 
166             } else {
167                 alert(JSON.stringify(err));
168             }
169         });
170     }
171 
172     //操作数组
173     function scy(roomNames) {
174         // console.log(roomNames);
175         // console.log(roomNames.length);
176         allRoom = {};
177         if (roomNames.length > 0) {
178             for (var i = 0; i < roomNames.length; i++) {
179                 var map = roomNames[i];
180                 // console.log($api.strToJson(map));
181                 for (var k in map) {
182                     // console.log(k+','+map[k]);
183                     if (k != null && k != 'null') {
184                         if (allRoom.hasOwnProperty(k)) { //true
185                             allRoom[k] += ',' + map[k];
186                         } else {
187                             allRoom[k] = map[k];
188                         }
189                     }
190                 }
191             }
192         }
193         // console.log(JSON.stringify(allRoom));
194         // list.push(allRoom)
195     }
196 
197     //播放
198     function play(thisVid, szi) {
199         if (szi == 0) {
200             var thVideo = thisVid.parentNode.firstChild.name;
201             console.log(thVideo);
202             api.openVideo({
203                 url: thVideo
204             });
205         } else {
206             //'fs://res/1.mp4'  /storage/emulated/0/相机/video_20190325_131837.mp4
207             var thVideo = thisVid.parentNode.firstChild.name;
208 
209             var urls = 'http://xxxxxx/' + thVideo;
210             api.openVideo({
211                 url: urls
212             });
213 
214             console.log();
215         }
216 
217     }
218 
219 
220     //删除图片、视频
221     function deletePic(btid, ever) {
222         // console.log(btid);
223         var strbtid = JSON.stringify(btid);
224         var strlist = JSON.stringify(list);
225         // console.log();
226         for (var i = 0; i < list.length; i++) {
227             var ks = JSON.stringify(list[i]);
228             if (ks.indexOf(strbtid) != -1) {
229                 list.splice(i, 1);
230                 i--;
231             }
232         }
233         // console.log(JSON.stringify(list));
234         ever.parentNode.parentNode.removeChild(ever.parentNode);
235     }
236 
237     //点击图片放大
238     function enlarge(everPic, str0) {
239         // alert('点击放大')
240         var pics = (everPic.parentNode.firstChild.src) || ($('#' + str0 + '').attr('src'));
241         // console.log(pics);
242         $('#bigpic').show();
243         $('.z').hide();
244         $('#bigpic img').attr('src', pics);
245     }
246     $(function() {
247         $('#bigpic').click(function() {
248             $('#bigpic').hide();
249             $('.z').show();
250         })
251     })
252 
253     //添加弹窗
254     function add(biaotiid, typ) {
255         var divlength = $('.img').children('#' + biaotiid + '').length;
256         console.log(divlength);
257 
258         if (typ == 1 && divlength >= 2) {
259             api.toast({
260                 msg: '本栏只可添加一张图片!',
261                 duration: 1000,
262                 location: 'middle'
263             });
264         } else {
265 
266             if (typ == 3) {
267                 api.actionSheet({
268                     cancelTitle: '取消',
269                     buttons: ['视频']
270                 }, function(ret, err) {
271                     index = ret.buttonIndex;
272                     // console.log(JSON.stringify(index));
273                     if (ret) {
274                         //  console.log( JSON.stringify( ret ) );
275                         if (index == 1) {
276                             //视频
277                             api.getPicture({
278                                 sourceType: 'camera',
279                                 // encodingType: 'mp4',
280                                 mediaValue: 'video',
281                                 videoQuality: 'medium',
282                                 saveToPhotoAlbum: true,
283                                 destinationType: 'url'
284                             }, function(ret3, err) {
285                                 if (ret3) {
286                                     //console.log(JSON.stringify(ret));
287                                     video_vi = ret3.data;
288                                     console.log(JSON.stringify(video_vi));
289                                     // --------------------------------------------
290                                     if (video_vi) {
291                                         uploadVideo(biaotiid, video_vi, typ)
292                                     }
293                                 } else {
294                                     console.log(JSON.stringify(err));
295                                 }
296                             });
297                         }
298                     } else {
299                         console.log(JSON.stringify(err));
300                     }
301                 })
302 
303             } else {
304                 api.actionSheet({
305                     cancelTitle: '取消',
306                     buttons: ['拍照', '手机相册']
307                 }, function(ret, err) {
308                     index = ret.buttonIndex;
309                     if (ret) {
310                         console.log(JSON.stringify(ret));
311                         if (index == 1) {
312                             api.getPicture({
313                                 sourceType: 'camera',
314                                 encodingType: 'jpg',
315                                 mediaValue: 'pic',
316                                 destinationType: 'url',
317                                 allowEdit: false,
318                                 quality: 100,
319                                 saveToPhotoAlbum: false
320                             }, function(ret1, err1) {
321                                 if (ret1) {
322                                     console.log(JSON.stringify(ret1));
323                                     img_pic1 = ret1.data;
324                                     if (img_pic1) {
325                                         uploadPic(biaotiid, img_pic1, typ);
326                                     }
327                                 } else {
328                                     alert(JSON.stringify(err));
329                                 }
330                             });
331 
332                         } else if (index == 2) {
333                             api.getPicture({
334                                 sourceType: 'library',
335                                 encodingType: 'png',
336                                 mediaValue: 'pic',
337                                 destinationType: 'url',
338                                 allowEdit: true,
339                                 quality: 100,
340                                 preview: true,
341                                 saveToPhotoAlbum: false
342                             }, function(ret2, err2) {
343                                 if (ret2) {
344                                     // console.log(JSON.stringify(ret2));
345                                     img_pic2 = ret2.data;
346                                     if (img_pic2) {
347                                         uploadPic(biaotiid, img_pic2, typ);
348                                     }
349                                 } else {
350                                     alert(JSON.stringify(err));
351                                 }
352                             });
353                         }
354                     } else {
355                         alert(JSON.stringify(err));
356                     }
357                 });
358 
359             }
360 
361         }
362 
363     }
364 
365     //上传视频
366     function uploadVideo(biaotiid, video_vi, typ) {
367         api.showProgress({
368             title: '加载中...',
369             text: ''
370         });
371         api.ajax({
372             url: 'http://xxxxxxx/index/system/uploadVideo',
373             method: 'post',
374             data: {
375                 files: {
376                     video: video_vi
377                 }
378             }
379         }, function(ret, err) {
380             if (ret) {
381                 // console.log( JSON.stringify( ret ) );
382                 var uploadVideo_later = ret.data
383 
384                 // add_video(video_vi, idname, uploadVideo_later);
385                 addhtml(biaotiid, video_vi, uploadVideo_later, typ);
386 
387                 api.hideProgress();
388             } else {
389                 console.log(JSON.stringify(err));
390                 api.hideProgress();
391             }
392         });
393 
394     }
395 
396     //上传图片
397     function uploadPic(biaotiid, img_pic, typ) {
398         api.showProgress({
399             style: 'default',
400             animationType: 'fade',
401             title: '努力加载中...',
402             text: '请耐心等待...',
403             modal: false
404         });
405 
406         api.ajax({
407             url: 'http://xxxxxxxx/index/system/uploadImg',
408             method: 'post',
409             data: {
410                 files: {
411                     image: img_pic
412                 }
413             }
414         }, function(ret, err) {
415             if (ret) {
416                 // console.log(JSON.stringify(ret));
417                 var change = ret.data
418                 addhtml(biaotiid, img_pic, change, typ);
419 
420                 api.hideProgress();
421 
422             } else {
423                 console.log(JSON.stringify(err));
424                 api.hideProgress();
425             }
426         });
427     }
428 
429     //动态添加公用函数
430     function addhtml(biaotiid, dynamic, change, typ) {
431         console.log(change);
432         str1 = change.substring(change.length - 4, change.length - 9);
433         var dongtai_html = '';
434 
435         if (typ == 3) {
436             console.log(JSON.stringify(dynamic));
437             var vi = JSON.stringify(dynamic);
438             dynamic2 = vi.replace(/\"/g, "").replace(/\[/g, "").replace(/\]/g, "");
439             console.log(dynamic2);
440 
441             dongtai_html += '<div style="margin:5px;" id="' + biaotiid + '">' +
442                 '<img src="../icon/sp.png" alt="' + change + '"  name="' + change + '" onclick="play(this,1)">' +
443                 '<div class="tzi" style="color:red" onclick="deletePic(\'' + change + '\',this)">删除</div>' +
444                 '</div>'
445         } else {
446             dongtai_html += '<div style="margin:5px;display:block;"   id="' + biaotiid + '">' +
447                 '<img onclick="enlarge(this);" src="' + dynamic + '" alt="' + change + '">' +
448                 '<div class="tzi" onclick="deletePic(\'' + change + '\',this);" style="color:red;">删除' +
449                 '</div>' +
450                 '</div>'
451         }
452 
453         $('#' + biaotiid + '').before(dongtai_html);
454 
455         // console.log($('#z').html());
456         list.push({
457             [biaotiid]: change
458         });
459         // console.log(JSON.stringify(list));
460     }
461 
462     //提交
463     function updata() {
464         // arrClass();
465         var dialogBox = api.require('dialogBox');
466         dialogBox.alert({
467             texts: {
468                 title: '提示',
469                 content: '您确定提交所有内容吗?',
470                 leftBtnTitle: '取消',
471                 rightBtnTitle: '确认'
472             },
473             styles: {
474                 bg: '#fff',
475                 w: 300,
476                 corner: 2,
477                 title: {
478                     marginT: 20,
479                     icon: 'widget://res/gou.png',
480                     iconSize: 40,
481                     titleSize: 22,
482                     titleColor: '#000'
483                 },
484                 content: {
485                     color: '#000',
486                     size: 16
487                 },
488                 left: {
489                     marginB: 7,
490                     marginL: 20,
491                     w: 130,
492                     h: 35,
493                     corner: 2,
494                     bg: '#fff',
495                     color: '#F3544E',
496                     size: 14
497                 },
498                 right: {
499                     marginB: 7,
500                     marginL: 10,
501                     w: 130,
502                     h: 35,
503                     corner: 2,
504                     bg: '#fff',
505                     color: '#F3544E',
506                     size: 14
507                 }
508             }
509         }, function(ret) {
510             if (ret.eventType == 'left') {
511                 //取消
512                 var dialogBox = api.require('dialogBox');
513                 dialogBox.close({
514                     dialogName: 'alert'
515                 });
516 
517             } else if (ret.eventType == 'right') {
518                 //确定
519                 var dialogBox = api.require('dialogBox');
520                 dialogBox.close({
521                     dialogName: 'alert'
522                 });
523 
524                 var orid = {
525                     order_id: upnames
526                 }
527                 list.push(orid);
528                 scy(list);
529                 console.log(JSON.stringify(allRoom));
530 
531 
532                 //数据提交
533                 api.ajax({
534                     url: 'http://xxxxxxx/index/repay/dataUploadNew',
535                     method: 'post',
536                     data: {
537                         values: allRoom
538                     }
539                 }, function(ret, err) {
540                     if (ret) {
541                         console.log(JSON.stringify(ret));
542                         // api.closeWin({});
543                         //退出
544                         api.openWin({
545                             name: 'tab',
546                             url: './tab.html',
547                             reload: true
548                         });
549                         //刷新
550                         api.sendEvent({
551                             name: 'ywydsx',
552                             extra: {
553                                 key0: 'y'
554                             }
555                         });
556                     } else {
557                         alert(JSON.stringify(err));
558                     }
559                 });
560 
561             }
562         });
563 
564     }
565 
566 
567     // function arrClass() {
568     //     console.log(biaotiid);
569     //     $('.' + biaotiid + '').each(function() {
570     //         console.log($(this).children('img').attr("alt"));
571     //     });
572     // }
573 </script>
574 
575 </html>
View Code
posted @ 2019-03-26 10:32  吉吉国王丶  阅读(1028)  评论(0编辑  收藏  举报