admin
2021-01-23 c3e8c86d062fbac17758274156a4f18655bdd3a2
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
<!DOCTYPE html>
<html class="x-admin-sm" xmlns:v-bind="http://www.w3.org/1999/xhtml">
 
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./css/common.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/vue.min.js"></script>
    <script src="js/http.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <script src="js/http.js"></script>
 
    <![endif]-->
 
    <style>
        .poster {
            max-width: 150px;
            max-height: 150px;
        }
 
        .layui-input-inline {
            width: auto !important;
        }
 
        .btn-add-award {
            color: white !important;
            margin-left: 5px;
        }
 
        .award-type-list {
            display: flex;
        }
 
        .award-type-list .award-type {
            position: relative;
            margin-right: 20px;
        }
 
        .award-type-list img {
            position: absolute;
            right: -5px;
            width: 20px;
            height: 20px;
            top: -5px;
        }
 
        .desc {
            color: #999;
            padding-bottom: 5px;
        }
 
        textarea {
            width: 365px !important;
        }
 
        .banner-container {
            display: none;
        }
 
        .banner {
            display: flex;
        }
 
        .banner-image-container {
            position: relative;
            margin-right: 5px;
        }
 
        .banner-image-container i {
            position: absolute;
            top: 0;
            right: 0;
        }
 
        .hidden {
            display: none;
 
        }
 
 
    </style>
</head>
<body>
<div class="layui-fluid" id="main">
 
 
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <div class="layui-card">
            <div class="layui-card-header">抽奖信息</div>
            <div class="layui-card-body">
                <div class="layui-row">
                    <form class="layui-form" lay-filter="form-activity-info">
                        <div class="layui-form-item">
                            <label for="L_appName" class="layui-form-label">
                                <span class="x-red">*</span>抽奖活动封面</label>
                            <div class="layui-input-inline">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="choicePoster">选择图片</button>
                                    <div class="layui-upload-list">
                                        <img class="layui-upload-img poster" id="poster">
                                    </div>
                                </div>
 
 
                            </div>
                        </div>
 
 
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span class="x-red">*</span>抽奖活动详情页横幅设置</label>
                            <div>
 
                                <div>
 
                                    <!-- lay-filter="banner" -->
                                    <input type="radio" name="showBanner" value="0" title="和抽奖活动封面一致" checked=""
                                           lay-filter="banner">
                                    <input type="radio" name="showBanner" value="1" title="重新设置" lay-filter="banner">
                                </div>
 
                                <div class="layui-upload layui-input-inline banner-container">
                                    <button type="button" class="layui-btn" id="choiceBanner">选择图片</button>
                                    <div class="layui-upload-list banner">
 
                                    </div>
                                </div>
 
                            </div>
                        </div>
                        <button class="layui-btn layui-btn-radius layui-btn-normal hidden"
                                id="saveActivityInfo" lay-submit="">保存
                        </button>
 
                    </form>
                </div>
 
            </div>
        </div>
 
        <div class="layui-card">
            <div class="layui-card-header">奖品信息</div>
            <div class="layui-card-body">
                <!--奖品列表 -->
                <form class="layui-form" lay-filter="form-award-info">
 
 
                    <div class="layui-tab layui-tab-card" lay-filter="award">
                        <ul class="layui-tab-title">
                            <li v-for="(item,index) in tempAwardsList" v-bind:class="{'layui-this':item.selected}"
                                v-bind:lay-id="index">{{item.title}}
                            </li>
                            <button class="layui-btn btn-add-award" type="button" data-type="tabAdd"
                                    v-on:click="addAward"><i
                                    class="layui-icon"></i>增加奖项
                            </button>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item" v-for="(item,index) in tempAwardsList"
                                 v-bind:class="{'layui-show':item.selected}">
                                <div class="award-type-list">
                                    <div class="award-type">
                                        <button type="button" class="layui-btn layui-btn-primary layui-btn-lg"
                                                v-on:click="awardRedPacktRandom($event,index)">随机红包
                                        </button>
                                        <img src="img/icon_checked_round.png" v-if="item.data.type==2">
                                    </div>
                                    <div class="award-type">
                                        <button type="button" class="layui-btn layui-btn-primary layui-btn-lg"
                                                v-on:click="awardRedPacktDivide($event,index)">固定红包
                                        </button>
                                        <img src="img/icon_checked_round.png" v-if="item.data.type==1">
                                    </div>
                                </div>
 
 
                                <button type="button"
                                        class="layui-btn layui-btn-radius layui-btn-danger btn-award-delete"
                                        v-bind:lay-index="index" v-on:click="deleteAward(index)"
                                        style="margin-top: 10px;">
                                    删除
                                </button>
                            </div>
                        </div>
                    </div>
                    <button class="layui-btn layui-btn-radius layui-btn-normal hidden" id="saveAwardInfo" lay-submit="">保存
                    </button>
 
 
                </form>
 
            </div>
        </div>
 
 
        <div class="layui-card">
            <div class="layui-card-header">参与条件</div>
            <div class="layui-card-body">
                <form class="layui-form" lay-filter="form-join-info">
 
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>参与条件</label>
                        <div class="layui-input-block">
                            <div class="desc">
                                用户满足以下设置条件后方可参与抽奖
                            </div>
                            <div>
                                <input type="radio" name="must" value="0" title="不设置/无" checked="">
                                <input type="radio" name="must" value="1" title="用户必须要满足以下条件">
                            </div>
                        </div>
                    </div>
 
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>跳转链路</label>
                        <div>
 
                            <div class="award-type-list">
                                <div class="award-type">
                                    <button type="button" class="layui-btn layui-btn-primary layui-btn-lg"
                                            v-on:click="openAdEditDialog('alipayLife')">关注生活号
                                    </button>
                                    <img src="img/icon_checked_round.png" v-if="joinInfo.adInfo.type=='alipayLife'">
                                </div>
                                <div class="award-type">
                                    <button type="button" class="layui-btn layui-btn-primary layui-btn-lg">浏览小程序
                                    </button>
                                    <img src="img/icon_checked_round.png" v-if="false">
                                </div>
 
                                <div class="award-type">
                                    <button type="button" class="layui-btn layui-btn-primary layui-btn-lg">浏览直播间
                                    </button>
                                    <img src="img/icon_checked_round.png" v-if="false">
                                </div>
 
                            </div>
 
 
                        </div>
                    </div>
 
                    <div class="layui-form-item">
                        <label for="L_desc" class="layui-form-label">
                            参与条件说明</label>
                        <div class="layui-input-inline">
                    <textarea id="L_desc" name="desc" lay-verify="desc"
                              autocomplete="off" class="layui-textarea" maxlength="256"></textarea></div>
                    </div>
 
                    <button class="layui-btn layui-btn-radius layui-btn-normal hidden" id="saveJoinInfo"
                            lay-filter="save-activity" lay-submit="">保存
                    </button>
                </form>
            </div>
        </div>
 
        <div class="layui-card">
            <div class="layui-card-header">开奖条件</div>
            <div class="layui-card-body">
 
                <form class="layui-form" lay-filter="form-open-info">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>至少参与人数</label>
                        <div class="layui-input-inline">
                            <label class="desc">最少1000人,最多100000人,默认5000人(活动结束时止)</label>
                            <div class="flex-row flex-center">
                                <input type="text" name="minPersonCount" required="" lay-verify="integer"
                                       autocomplete="off" class="layui-input input-small" placeholder="正整数">&nbsp;人
                            </div>
                        </div>
                    </div>
 
 
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>开奖时间/活动有效期</label>
                        <div class="layui-input-inline">
                            <label class="desc">至少1天,最多7天,默认3天(活动发布时起)</label>
                            <div class="flex-row flex-center">
                                <input type="text" name="day" required="" lay-verify="integer"
                                       autocomplete="off" class="layui-input input-small" placeholder="正整数">&nbsp;天
                            </div>
                        </div>
                    </div>
 
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            开奖条件说明</label>
                        <div class="layui-input-inline">
                            <label class="desc">最多150个字符,可换行且兼容符号表情</label>
                            <div class="flex-row flex-center">
                                <textarea class="layui-textarea" name="desc" maxlength="150"></textarea>
                            </div>
                        </div>
                    </div>
 
                    <button class="layui-btn layui-btn-radius layui-btn-normal hidden" id="saveOpenInfo" lay-submit="">保存
                    </button>
                </form>
            </div>
        </div>
 
        <button class="layui-btn layui-btn-warm layui-btn-lg" v-on:click="submit">立即提交</button>
    </div>
</div>
 
<script src="js/lodash.js"></script>
<script src="js/common.js"></script>
 
<script>;
//验证管理器
var validManager = {
    //验证抽奖信息
    verifyActivityInfo() {
        console.log("验证抽奖信息");
        const field = common.layuiForm.val('form-activity-info');
        if (!$("#poster").attr("src")) {
            common.notify.error("请选择封面图片");
            return false;
        }
 
        //判断条件
        if (field.showBanner == 1 && $(".banner").find("img").length == 0) {
            common.notify.error("请选择banner图片");
            return false;
        }
 
        if (field.showBanner == 1 && $(".banner").find("img").length > 3) {
            common.notify.error("banner图最多3张");
            return false;
        }
        return true;
    },
    //验证奖品信息
    verifyAwardInfo() {
        console.log("验证奖品信息");
        if (app.tempAwardsList == null || app.tempAwardsList.length == 0) {
            common.notify.error("请添加奖项");
            return false;
        }
        var hasAward = false;
        for (var i = 0; i < app.tempAwardsList.length; i++) {
            if (app.tempAwardsList[i].data && app.tempAwardsList[i].data.type) {
                hasAward = true;
                break;
            }
        }
 
        if (!hasAward) {
            common.notify.error("请选择奖项类型");
            return false;
        }
 
        const field = common.layuiForm.val('form-award-info');
 
        return true;
    },
    //验证参与信息
    verifyJoinInfo() {
        console.log("验证参与条件");
        const field = common.layuiForm.val('form-join-info');
        console.log(field);
        if (!app.joinInfo.adInfo.data) {
            common.notify.error("请选择参与条件-跳转链路");
            return false;
        }
 
 
        return true;
    },
    //验证开奖条件
    verifyOpenInfo() {
        console.log("验证开奖条件");
        const field = common.layuiForm.val('form-open-info');
        console.log(field);
 
        if (!parseInt(field.minPersonCount)) {
            common.notify.error("请填写正确的参与人数");
            return false;
        }
 
        if (!parseInt(field.day)) {
            common.notify.error("请填写正确的天数");
            return false;
        }
 
        if (parseInt(field.minPersonCount) < 1000 || parseInt(field.minPersonCount) > 100000) {
            common.notify.error("至少参与人数的范围为:1000-100000");
            return false;
        }
 
        if (parseInt(field.day) < 1 || parseInt(field.day) > 7) {
            common.notify.error("活动有效期的范围为:1-7");
            return false;
        }
 
        return true;
    },
    verify(es) {
 
        for (var i = 0; i < es.length; i++) {
            if (!es[i]()) {
                return false;
            }
        }
        return true;
    },
    verifyAll() {
        return this.verify([this.verifyActivityInfo, this.verifyAwardInfo, this.verifyJoinInfo, this.verifyOpenInfo]);
    }
};
 
var formManager = {
 
    //保存到临时变量
    saveActivityInfoToTemp() {
        app.temp.activity = app.activity;
    },
    saveAwardInfoToTemp() {
        app.temp.awardInfo = app.tempAwardsList;
    },
    saveJoinInfoToTemp() {
        //赋值
        const field = common.layuiForm.val('form-join-info');
        var joinInfo = app.joinInfo;
        joinInfo.must = field.must;
        joinInfo.desc = field.desc;
        app.temp.joinInfo = joinInfo;
    },
    saveOpenInfoToTemp() {
        const field = common.layuiForm.val('form-open-info');
        var openInfo = app.openInfo;
        for (key in field) {
            openInfo[key] = field[key];
        }
        app.temp.openInfo = openInfo;
    },
    saveToTemp() {
        this.saveActivityInfoToTemp();
        this.saveAwardInfoToTemp();
        this.saveJoinInfoToTemp();
        this.saveOpenInfoToTemp();
    }
};
 
</script>
 
<script>
    //文件上传初始化
    var uploadPoster;
    var uploadBanner;
    var posterFileList;
    var bannerFileList;
    common.initLayui(function () {
        //layui相关初始化成功
        app.initData();
 
 
        const uploadPosterParams = {
            elem: "#choicePoster",
            showElem: "#poster",
            uploadUrl: "/admin/upload/image?from=activity",
            dir: 'poster',
            field: "image",
            choose(obj) {
                var files = posterFileList = obj.pushFile();
                obj.preview(function (index, file, result) {
                    $("#poster").attr("src", result);
                });
            },
            uploadSuccess: function (res) {
                app.posterUploadSuccess(res.data);
                //重置文件传输
                for (key in posterFileList) {
                    delete posterFileList[key];
                }
            }
        };
 
 
        uploadPoster = common.initUploadImagePlugin(uploadPosterParams);
 
        var bannerUrlList = new Array();
 
        var uploadBannerParams = {
            elem: "#choiceBanner",
            uploadUrl: "/admin/upload/image?from=activity",
            dir: 'banner',
            field: "image",
            multiple: true,
            choose(obj) {
                var files = bannerFileList = obj.pushFile();
 
                obj.preview(function (index, file, result) {
                    var item = getBannerItemHtml(result);
                    item.find("i").on('click', function () {
                        //删除当前数据
                        delete files[index]
                        item.remove();
                        uploadBanner.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
                    });
 
                    $(".banner").append(item);
                });
            },
            uploadSuccess: function (res) {
                //计算需要上传文件的数量
                var count = 0;
                for (key in bannerFileList) {
                    count++;
                }
                bannerUrlList.push(res.data);
            },
            allDone: function (res) {
                //文件上传完毕
                app.bannerUploadSuccess(bannerUrlList);
                for (key in bannerFileList) {
                    delete bannerFileList[key];
                }
            }
        }
 
        uploadBanner = common.initUploadImagePlugin(uploadBannerParams);
        console.log(uploadBanner);
 
    });
 
    function getBannerItemHtml(src) {
        var html = "<div class='banner-image-container'>";
        html += "<img class='layui-upload-img poster' src='" + src + "'>";
        html += "<i class='layui-icon'>&#xe640;</i>";
        html += "</div>";
        var item = $(html);
        return item;
    }
 
 
    var app = new Vue({
        el: '#main',
        data: {
            activity: {},
            tempAwardsList: [],
            openInfo: {
            },
            joinInfo: {
                adInfo: {}},
            temp: {//临时数据,用于提交到服务端
 
            },
            tempField: {//field临时存储
 
            }
        },
        watch: {
            tempAwardsList: function () {
                setTimeout(function () {
                    // layui.use(['form'], function () {
                    //     form = layui.form;
                    //     form.render();
                    // })
                    common.layuiForm.render();
                });
            }
        },
        created: function () {
 
        },
        mounted: function () {
            this.addAward();
        },
        methods: {
            //设置数据
            setTempData(temp) {
                //活动信息赋值(深拷贝)
                this.activity = _.cloneDeep(temp.activity);
                this.tempAwardsList = _.cloneDeep(temp.awardInfo);
                this.openInfo = _.cloneDeep(temp.openInfo);
                this.joinInfo = _.cloneDeep(temp.joinInfo);
            },
            //初始化数据
            initData() {
                $this = this;
                /**************初始化抽奖信息************/
 
                //删除所有选择的文件
                for (key in posterFileList) {
                    delete posterFileList[key];
                }
 
                for (key in bannerFileList) {
                    delete bannerFileList[key];
                }
 
 
                $(".banner").empty();
                if (this.activity.poster)
                    $("#poster").attr("src", this.activity.poster);
 
 
                //选择banner监听
                common.layuiForm.on('radio(banner)', function (data) {
                    if (data.value == 1) {
                        $(".banner-container").css("display", "block");
                    } else {
                        $(".banner-container").css("display", "none");
                    }
                });
 
                if (this.activity.bannerList && this.activity.bannerList.length > 0) {
                    for (var i = 0; i < this.activity.bannerList.length; i++) {
                        var url = this.activity.bannerList[i].url;
                        var item = getBannerItemHtml(url);
                        item.find("i").on('click', function () {
                            //删除当前数据
                            app.activity.bannerList.splice(i, 1);
                            item.remove();
                        });
                        $(".banner").append(item);
                    }
                    //设置选项
                    $("input[name=showBanner][value=1]").prop("checked", "true");
                } else {
                    console.log("选择banner");
                    $("input[name=showBanner][value=0]").prop("checked", "true");
                }
 
                common.layuiForm.on('submit(form-activity-info)',
                    function (data) {
                        field = common.layuiForm.val('form-activity-info');
                        if (!validManager.verifyActivityInfo()) {
                            app.finishSubmit();
                            return false;
                        }
                        // 数据暂存
                        app.tempField.activity = field;
                        //有封面图
                        if ($(".layui-upload-file").eq(0).val()) {
                            //上传封面图
                            uploadPoster.upload();
                        } else {
                            $this.posterUploadSuccess();
                        }
                        return false;
                    });
                /**************初始化奖品信息************/
                common.layuiForm.on('submit(form-award-info)',
                    function (data) {
                        console.log("提交奖品信息");
                        if (!validManager.verifyAwardInfo()) {
                            app.finishSubmit();
                            return false;
                        }
 
                        //暂存
                        formManager.saveAwardInfoToTemp()
 
                        //赋值
                        $("#saveJoinInfo").click();
 
                        return false;
                    });
 
                /**************初始化参与条件************/
                common.layuiForm.on('submit(form-join-info)',
                    function (data) {
                        console.log("提交参与条件");
                        if (!validManager.verifyJoinInfo()) {
                            app.finishSubmit();
                            return false;
                        }
                        //暂存
                        formManager.saveJoinInfoToTemp();
                        $("form[lay-filter=form-open-info]").submit()
                        return false;
                    });
 
                //初始化表单的值
                common.layuiForm.val("form-join-info", this.joinInfo);
 
 
                /**************初始化开奖条件************/
                common.layuiForm.on('submit(form-open-info)',
                    function (data) {
                        console.log("提交开奖条件");
                        if (!validManager.verifyOpenInfo()) {
                            app.finishSubmit();
                            return false;
                        }
                        //暂存
                        formManager.saveOpenInfoToTemp();
                        app.finishSubmit(true);
                        return false;
                    });
                common.layuiForm.val("form-open-info", this.openInfo);
 
                common.layuiForm.render();
            },
 
            //封面图上传成功
            posterUploadSuccess(res) {
                console.log("封面图上传成功");
                console.log(res);
                if (res) {//上传了文件
                    $("#poster").attr("src", res);
                    this.activity.poster = res;
                }
                //上传文件
                var bannerEmpty = true;
                for (key in bannerFileList) {
                    bannerEmpty = false;
                    break;
                }
                if (!bannerEmpty) {
                    //上传banner图片
                    uploadBanner.upload();
                } else {
                    this.bannerUploadSuccess();
                }
            },
            //banner图上传成功
            bannerUploadSuccess(res) {
                console.log(res);
                console.log("Banner图上传成功");
                if (res) {
                    for (var i = 0; i < res.length; i++) {
                        //添加新的数据
                        var banner = {};
                        banner.url = res[i];
                        if (!this.activity.bannerList) {
                            this.activity.bannerList = new Array();
                        }
                        this.activity.bannerList.push(banner);
                    }
                }
 
                //暂存活动信息
                formManager.saveActivityInfoToTemp();
 
                //提交奖项
                $("#saveAwardInfo").click();
 
            },
 
            //添加
            requestAdd: function (data,type) {
                var params = {
                    data: data,
                    type:type
                }
 
                //发异步,把数据提交给php
                ksapp.post('/admin/activity/addActivity', params, function (res) {
                    if (res.code == 0) {
                        layer.alert("增加成功", {
                                icon: 6
                            },
                            function () {
                             layer.close(this);
                            });
                    } else {
                        layer.msg(res.msg);
                    }
 
                }, function (res) {
                });
            },
            //提交
            submit: function () {
                //未验证通过
                if (!validManager.verifyAll()) {
                    return;
                }
                var loading = layer.load(0, {shade: false});
                app.submitLoading = loading;
                //触发表单提交
                $("#saveActivityInfo").click();
            },
            finishSubmit: function (finish) {
                console.log(JSON.stringify(this.temp));
                if (app.submitLoading) {
                    layer.close(app.submitLoading)
                }
                //所有数据已经取完
                if (finish) {
                    console.log("获取到的结果");
                    console.log(this.temp);
                    // app.setTempData(this.temp);
                    // app.initData();
                    this.requestAdd(JSON.stringify(this.temp),'publish');
                }
            },
 
            /**
             * 奖项
             */
 
            addAward: function () {
                var awardCount = this.tempAwardsList.length;
                if (awardCount >= 5) {
                    common.notify.error("奖项最多为5个");
                    return;
                }
                var awardTitle = "";
                switch (awardCount) {
                    case 0:
                        awardTitle = "奖项一"
                        break;
                    case 1:
                        awardTitle = "奖项二"
                        break;
                    case 2:
                        awardTitle = "奖项三"
                        break;
                    case 3:
                        awardTitle = "奖项四"
                        break;
                    case 4:
                        awardTitle = "奖项五"
                        break;
                }
 
                this.tempAwardsList.push({title: awardTitle, data: {}, selected: true});
                this.selectAward(this.tempAwardsList.length - 1);
            },
            selectAward(index) {
                for (var i = 0; i < this.tempAwardsList.length; i++) {
                    if (i == index) {//选中
                        var award = this.tempAwardsList[i];
                        award.selected = true;
                        this.$set(this.tempAwardsList, i, award);
                    } else {//不选中
                        if (this.tempAwardsList[i].selected) {
                            var award = this.tempAwardsList[i];
                            award.selected = false;
                            this.$set(this.tempAwardsList, i, award);
                        }
                    }
                }
            },
            deleteAward: function (index) {
                if (app.tempAwardsList.length <= 1) {
                    common.notify.error("最低保留一个奖项");
                    return;
                }
                //删除元素后选中的下标
                var selectedIndex;
                if (index == 0) {
                    selectedIndex = 0;
                } else if (index == app.tempAwardsList.length - 1) {
                    selectedIndex = index - 1;
                } else {
                    selectedIndex = index;
                }
 
                var list = app.tempAwardsList;
                list.splice(index, 1);
                for (var i = 0; i < list.length; i++) {
                    var awardTitle = "";
                    switch (i) {
                        case 0:
                            awardTitle = "奖项一"
                            break;
                        case 1:
                            awardTitle = "奖项二"
                            break;
                        case 2:
                            awardTitle = "奖项三"
                            break;
                        case 3:
                            awardTitle = "奖项四"
                            break;
                        case 4:
                            awardTitle = "奖项五"
                            break;
                    }
                    list[i].title = awardTitle;
                    app.tempAwardsList = list;
                }
                //选中的下表
                console.log("选中下标:" + selectedIndex);
                this.selectAward(selectedIndex);
            },
            awardRedPacktRandom: function (event, index) {
                app.openAwardEdit(index, 2);
            },
            awardRedPacktDivide: function (event, index) {
                app.openAwardEdit(index, 1);
            },
            //打开编辑弹框
            openAwardEdit(index, type) {
                var $this = this;
                var params = {};
                switch (type) {
                    case 1:
                        params.url = "./award-type-redpacket-divide.html";
                        params.title = "固定红包设置";
                        break;//固定红包
                    case 2:
                        params.url = "./award-type-redpacket-random.html";
                        params.title = "随机红包设置";
                        break;//随机红包
                }
                var award = {};
                if (app.tempAwardsList[index].data && app.tempAwardsList[index].data.type == type) {
                    award = app.tempAwardsList[index].data;
                }
                var dialogIndex = common.openEditDialog({
                    title: params.title,
                    width: 500,
                    height: 400,
                    content: params.url + "?data=" + escape(JSON.stringify(award)),
                    submit(res) {
                        var award = app.tempAwardsList[index];
                        award.type = "alipayRedPackage";
                        var data = award.data;
                        data.total = res.total;
                        data.count = res.count;
                        data.type = type;
                        $this.$set($this.tempAwardsList, index, award);
                        console.log(app.tempAwardsList)
                        common.closeDialog(dialogIndex);
                        // $(el).parent().find("input[type=radio]").eq(0).attr("checked", true);
                    },
                });
            },
 
            /**
             * 选择参与条件
             */
            openAdEditDialog(type) {
                var $this = this;
                var params = {};
                var data = {};
 
                switch (type) {
                    case 'alipayLife':
                        params.title = "生活号设置"
                        params.url = "./sponsor-ad-alipaylife.html"
                        if (this.joinInfo.adInfo.data) {
                            data = this.joinInfo.adInfo.data;
                        }
                        break;
                }
 
                var dialogIndex = common.openEditDialog({
                    title: params.title,
                    width: 500,
                    height: 450,
                    content: params.url + "?data=" + encodeURIComponent(JSON.stringify(data)),
                    submit(res) {
                        console.log("得到的值为:");
                        console.log(res);
                        var data = $this.joinInfo.adInfo.data;
                        if (data == undefined)
                            data = {};
                        data.icon = res.icon;
                        data.name = res.name;
                        data.sceneId = res.sceneId;
                        data.desc = res.desc;
                        $this.$set($this.joinInfo.adInfo, 'data', data);
                        $this.$set($this.joinInfo.adInfo, 'type', type);
 
                        common.closeDialog(dialogIndex);
                    },
                });
            }
 
        }
    });
</script>
</body>
 
</html>