match.js 58.6 KB
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 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
define(['jquery', 'bootstrap', 'backend', 'table', 'form','template', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form,Template, Echarts) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'match/match/index' + location.search,
                    add_url: 'match/match/add',
                    edit_url: 'match/match/edit',
                    del_url: 'match/match/del',
                    multi_url: 'match/match/multi',
                    change_match_level: 'match/match/change_match_level',
                    table: 'match',
                }
            });
            var table = $("#table");
            Template.helper("Moment", Moment);
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: false,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false,
                // //分页大小
                 pageSize: 2,
                templateView: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'school_id', title: __('School_id')},
                        {field: 'match_title', title: __('Match_title')},
                        {field: 'match_year', title: __('Match_year')},
                        {field: 'matchgroup_id', title: __('Matchgroup_id')},
                        {field: 'match_level', title: __('Match_level'), searchList: {"0":__('Match_level 0'),"1":__('Match_level 1'),"2":__('Match_level 2'),"3":__('Match_level 3')}, formatter: Table.api.formatter.normal},
                        {field: 'organizer', title: __('Organizer')},
                        {field: 'undertake', title: __('Undertake')},
                        {field: 'match_logo', title: __('Match_logo')},
                        {field: 'match_starttime', title: __('Match_starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'match_endtime', title: __('Match_endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'sign_num', title: __('Sign_num')},
                        {field: 'leader_sign_num', title: __('Leader_sign_num')},
                        {field: 'is_leader_num', title: __('Is_leader_num')},
                        {field: 'leader_to_mumber', title: __('Leader_to_mumber')},
                        {field: 'sign_public', title: __('Sign_public')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            //比赛设置
            $("#myTabContent").on('click', '.setMatch', function () {
                // Fast.api.open($.fn.bootstrapTable.defaults.extend.edit_url+"?ids="+id,"编辑比赛",{area:['100%','100%']});
                var id = $(this).data('id');
                var title = $(this).data('title');
                Fast.api.addtabs("match/match/match_container?idx="+id+"&type=set",title);
            });
            //比赛统计
            $('#myTabContent').on('click','.statistics',function () {
                var id = $(this).data('id');
                var title = $(this).data('title');
                Fast.api.addtabs("match/match/match_container?idx="+id+"&type=pro",title);
            });

            $("#myTabContent").on('change', '.match_level', function () {
                var match_level = $(this).val();
                var id = $(this).data('id');
                Fast.api.ajax({
                    url:$.fn.bootstrapTable.defaults.extend.change_match_level,
                    loading:true,
                    data:{id,match_level,type:'match_level'}
                },function (ret) {
                    console.log(ret)
                },function (err) {
                    layer.msg(err)
                })
            })
            $("#myTabContent").on('change', '.firmly_level', function () {
                var firmly_level = $(this).val();
                var id = $(this).data('id');
                Fast.api.ajax({
                    url:$.fn.bootstrapTable.defaults.extend.change_match_level,
                    loading:true,
                    data:{id,firmly_level,type:'firmly_level'}
                },function (ret) {
                    table.bootstrapTable('refresh')
                },function (err) {
                    layer.msg(err)
                })
            })
            //删除
            $("#myTabContent").on('click', '.del', function () {
                var ids = $(this).data('id');
                layer.confirm('确定要删除此比赛吗?', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    Fast.api.ajax({
                        url:$.fn.bootstrapTable.defaults.extend.del_url,
                        loading:true,
                        data:{ids}
                    },function (ret) {
                        layer.closeAll()
                        table.bootstrapTable('refresh')
                    },function (err) {
                        layer.msg(err)
                    })
                });
            });
            //新增比赛
            $("#myTabContent").on('click', '.addMatch', function () {
                var group_id = $(this).data('id');
                var title = $(this).data('title');
                Fast.api.open($.fn.bootstrapTable.defaults.extend.add_url+"?group_id="+group_id ,`赛事[${title}]新增比赛`,{area:['100%','100%']})
            });
            $("#myTabContent").on('click', '.tocantainer', function () {
                var title = $(this).data('title');
                var id = $(this).data('id');
                Fast.api.addtabs("match/match/match_container?idx="+id,title);
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'match/match/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'match/match/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'match/match/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {

            require(['school/match/fields'],function (fieldsMap) {
                $('.been_fields').val(JSON.stringify(fieldsMap.reg));
            });


            $("#faupload-rule_resources").data("upload-success", function (res) {
                console.log(res);
                var ul = $("#rule_resources_view");
                var names = $("#rule_resources_view li .resources_name");
                var flg = true;
                $.each(names,function(i,v){
                    if($(this).text() == res.file.name)  {
                        flg = false;
                    }
                });
                if(!flg) {
                    layer.msg('不能上传重复文件');
                    return false;
                }
                var str = '<li><a href="javascript:;" class="resources_name">'+res.file.name+'</a><input  size="50" name="row[rule_resources]['+res.file.name+']" type="hidden" value="'+res.url+'"> <a href="javascript:;" class="del_resources">删除</a></li>';
                ul.append(str);
                return false;
            });
            $(document).on("click",".del_resources",function(){
                $(this).parent().remove();
            });


            $('.match_typeChange').click(function () {
                var type = $(this).val();
                if(type == 0){
                    $('.match_type').hide();
                }else{
                    $('.match_type').show();
                }
            });

            Controller.api.bindevent();
        },
        edit: function () {
            require(['school/match/fields'],function (fieldsMap) {
                $('.been_fields').val(JSON.stringify(fieldsMap.reg));
            });

            $('.match_typeChange').click(function () {
                var type = $(this).val();
                if(type == 0){
                    $('.match_type').hide();
                }else{
                    $('.match_type').show();
                }
            });
            Controller.api.bindevent();
        },

        match_container:function() {
            //统计
            $(document).on("click", ".charts-custom a[data-toggle=\"tab\"]", function () {
                var that = this;
                setTimeout(function () {
                    var id = $(that).attr("href");
                    var chart = Echarts.getInstanceByDom($(id)[0]);
                    chart.resize();
                }, 0);
            });
             var app = window.$vm = new Vue({
                el: "#app",
                data() {
                    return {
                        tabIndex:Config.active,
                        homeMatchTypeIndex: Config.homeMatchTypeIndex,  //赛道id 传递默认赛道id
                        homeMatchType:[],
                        tableData: [],
                        value1: true,
                        matchTags:[], //比赛标签
                        matchTagItemAllCount :0, //对应标签的人数
                        matchTagItemSelected:'' , // 比赛标签默认选择
                        views:1, //浏览量
                        teams:2, //参赛组数
                        participants:3, //参赛人数
                        matchDataSearch:{
                            college :  null ,
                            specialty: null ,
                            student_name: null,
                            project_name:null
                        },
                        collageArray:[],
                        specialtyArray:[],
                        statistics_data:[],
                        collegeList:[],
                        statistics_val:'',
                        specialty_title:[],
                        specialty_val:[],
                        specialty_total:0,

                    }
                },
                created() {
                },
                mounted() {
                    $('#app').show();
                    this.getMatchType();
                    this.getFormTypes(this.homeMatchTypeIndex);
                    Controller.showDataTable();
                    this.statistics();
                },
                methods:{
                    statistics:function() {
                        var match_id = $("#statistics_match_id").val();
                        var _this = this;
                        //请求数据
                        $.ajax({
                            url:'/school/match/matchitems/getStatisticsData',
                            type:'post',
                            data:{match_id:match_id},
                            dataType:'json',
                            success:function(res){
                                if(res.code != 0) {
                                    _this.collegeList = res.data.collegeList;
                                    var collegeGroup = Echarts.init(document.getElementById('college_group')),
                                        specialtyGroup = Echarts.init(document.getElementById('specialty_group')),
                                        membersGroup = Echarts.init(document.getElementById('members_group'));
                                    var membersGroupOption = {
                                        title: {
                                            x:'center',
                                            text: res.data.match_title + '【各学院报名人次统计】【共' +res.data.members_group.total+'人次】',
                                            // subtext: 'college',
                                        },
                                        xAxis: {
                                            type: 'category',
                                            data: res.data.members_group.title,
                                            axisTick: {
                                                alignWithLabel: true
                                            },
                                            axisLabel: {
                                                interval:0,
                                                rotate:40//角度顺时针计算的
                                            },
                                            max:function (value) {
                                                if (value.max < 8 ){
                                                    value.max = 8;
                                                } else {
                                                    value.max = value.max;
                                                }
                                                return value.max;
                                            },

                                        },
                                        grid: { bottom: "35%" },
                                        yAxis: {
                                            type : 'value',
                                            axisLine: {
                                                lineStyle: {
                                                    color: "#272822"
                                                }
                                            }
                                        },
                                        series: [{
                                            data:res.data.members_group.value,
                                            type: 'bar',
                                            itemStyle: {
                                                normal: {
                                                    label: {
                                                        show: true,  //开启显示
                                                        position: 'top',  //在上方显示
                                                        textStyle: {  //数值样式
                                                            color: '#AAAAAA',
                                                            fontSize: 12
                                                        }
                                                    }
                                                }
                                            },
                                        }]
                                    };
                                    var collegeGroupOption = {
                                        title: {
                                            x:'center',
                                            text: res.data.match_title + '【各学院报名组数统计】【共' +res.data.college_group.total+'组】',
                                            // subtext: 'college',
                                        },
                                        xAxis: {
                                            type: 'category',
                                            data: res.data.college_group.title,
                                            axisTick: {
                                                alignWithLabel: true
                                            },
                                            axisLabel: {
                                                interval:0,
                                                rotate:40//角度顺时针计算的
                                            },
                                            max:function (value) {
                                                if (value.max < 8 ){
                                                    value.max = 8;
                                                } else {
                                                    value.max = value.max;
                                                }
                                                return value.max;
                                            },

                                        },
                                        grid: { bottom: "35%" },
                                        yAxis: {
                                            type : 'value',
                                            axisLine: {
                                                lineStyle: {
                                                    color: "#272822"
                                                }
                                            }
                                        },
                                        series: [{
                                            data:res.data.college_group.value,
                                            type: 'bar',
                                            itemStyle: {
                                                normal: {
                                                    label: {
                                                        show: true,  //开启显示
                                                        position: 'top',  //在上方显示
                                                        textStyle: {  //数值样式
                                                            color: '#AAAAAA',
                                                            fontSize: 12
                                                        }
                                                    }
                                                }
                                            },
                                        }]
                                    };
                                    var specialtyGroupOption = {
                                        title: {
                                            x:'center',
                                            text: res.data.match_title + '【各专业报名组数统计】【共'+_this.specialty_total+'组】',
                                            // subtext: 'specialty',
                                        },
                                        xAxis: {
                                            type: 'category',
                                            data: _this.specialty_title,
                                            axisTick: {
                                                alignWithLabel: true
                                            },
                                            axisLabel: {
                                                interval:0,
                                                rotate:40//角度顺时针计算的
                                            },
                                            max:function (value) {
                                                if (value.max < 8 ){
                                                    value.max = 8;
                                                } else {
                                                    value.max = value.max;
                                                }
                                                return value.max;
                                            },
                                        },
                                        grid: { bottom: "35%" },
                                        yAxis: {
                                            type : 'value',
                                            axisLine: {
                                                lineStyle: {
                                                    color: "#272822"
                                                }
                                            }
                                        },
                                        series: [{
                                            data:_this.specialty_val,
                                            type: 'bar',
                                            itemStyle: {
                                                normal: {
                                                    label: {
                                                        show: true,  //开启显示
                                                        position: 'top',  //在上方显示
                                                        textStyle: {  //数值样式
                                                            color: '#AAAAAA',
                                                            fontSize: 12
                                                        }
                                                    }
                                                }
                                            },
                                        }]
                                    };
                                    collegeGroup.setOption(collegeGroupOption);
                                    specialtyGroup.setOption(specialtyGroupOption);
                                    membersGroup.setOption(membersGroupOption);
                                }
                            }
                        });



                    },
                    getSpecialtyStatistics:function(val) {
                        var _this = this;
                        var match_id = $("#statistics_match_id").val();
                        $.ajax({
                            url:'/school/match/matchitems/getSpecialtyStatistics',
                            type:'post',
                            data:{college_id:val,match_id:match_id},
                            dataType:'json',
                            success:function(res){
                                if(res.code != 0) {
                                    _this.specialty_title = res.data.title;
                                    _this.specialty_val = res.data.val;
                                    _this.specialty_total = res.data.total;
                                    var specialtyGroup = Echarts.init(document.getElementById('specialty_group'));
                                    var specialtyGroupOption = {
                                        title: {
                                            x:'center',
                                            text: res.data.match_title + '【各专业报名组数统计】【共'+_this.specialty_total+'组】',
                                            subtext: 'specialty',
                                        },
                                        xAxis: {
                                            type: 'category',
                                            data: _this.specialty_title,
                                            axisTick: {
                                                alignWithLabel: true
                                            },
                                            axisLabel: {
                                                interval:0,
                                                rotate:40//角度顺时针计算的
                                            },
                                        },
                                        grid: { bottom: "35%" },
                                        yAxis: {
                                            type : 'value',
                                            axisLine: {
                                                lineStyle: {
                                                    color: "#272822"
                                                }
                                            }
                                        },
                                        series: [{
                                            data:_this.specialty_val,
                                            type: 'bar',
                                            itemStyle: {
                                                normal: {
                                                    label: {
                                                        show: true,  //开启显示
                                                        position: 'top',  //在上方显示
                                                        textStyle: {  //数值样式
                                                            color: '#AAAAAA',
                                                            fontSize: 12
                                                        }
                                                    }
                                                }
                                            },
                                        }]
                                    };
                                    specialtyGroup.setOption(specialtyGroupOption);
                                }
                            }
                        });
                    },
                    open_status:function(status,id){
                        var that = this;
                        $.ajax({
                            url: '/school/match/match/formSetStatus',
                            method: 'POST',
                            data: { id: id,status:status},
                            success: function (res) {
                                if (1 === res.code) {
                                    Toastr.success('操作成功')
                                    Controller.api.refreshTable(table);
                                } else {
                                    that.getFormTypes(this.homeMatchTypeIndex);
                                    Toastr.error(res.msg);
                                }
                            }
                        });
                    },
                    searchBtn:function(){
                        $("#showDataTable").bootstrapTable('refresh');
                    },
                    clickTabs:function (e) {
                        var that = this;
                        var index = e.name;
                        switch (index) {
                            case 'home':
                                that.getMatchType();
                                break;
                            case 'data':
                                that.getMatchTags();
                                $("#showDataTable").bootstrapTable('refresh');
                                //获取学院专业信息
                                that.getCollage('college')
                                break;
                        }
                    },
                    getCollage(type) {
                        var that = this;
                        Fast.api.ajax({
                            url:"ajax/getCollege",
                            data:{type:type || 'specialty' , college:that.matchDataSearch.college || null,flg:true}
                        }, function (ret) {
                            switch (type) {
                                case 'college':
                                    that.collageArray = ret;
                                    break;
                                case 'specialty':
                                    that.matchDataSearch.specialty = null;
                                    that.specialtyArray = [];
                                    that.specialtyArray = ret;
                                    break;
                            }
                            return false;
                        });
                        if(that.collageArray.length != 0) {
                            setTimeout(function () {
                                $("#showDataTable").bootstrapTable('refresh');
                            }, 200);
                        }

                    },
                    getMatchTypeForm(e){
                        var that = this;
                        var index = e.name;
                        that.getFormTypes(index);
                    },
                    //刷新当前的表格 [home]
                    getFormTypes(index){
                        var that = this;
                        Fast.api.ajax({
                            url:'match/match/getFormTypes',
                            data:{id:that.homeMatchTypeIndex}
                        },function (ret) {
                            that.tableData = ret.data;
                            return false;
                        });
                    },
                    // 设置自定义表单 form_set_id 设置表id  表单类型
                    setForm(form_set_id,type){
                        Fast.api.open("match/match/formData?form_set_id="+form_set_id+"&type="+type,"自定义表单",{area:['90%','90%']});
                    },
                    //设置
                    setFormApplication(ids,type){
                        Fast.api.open("match/match/setFormApplication?ids="+ids,"自定义表单",{area:['90%','90%']});
                    },
                    //获取首页赛道信息 [home]
                    getMatchType(){
                        var that  = this;
                        Fast.api.ajax({
                            url:'match/match/getMatchType',
                            data:{match_id:Config.id}
                        },function (ret) {
                            that.homeMatchType = ret;
                            return false;
                        });
                    },

                    //新增标签[data]
                    addTag(){
                        var that = this;
                        this.$prompt('请输入标签名称', '新增标签', {
                            confirmButtonText: '提交',
                            cancelButtonText: '取消',
                            inputPattern: /\S/,
                            inputErrorMessage: '标签名称不可为空'
                        }).then(({ value }) => {
                            Fast.api.ajax({
                                url:'match/match/newMatchTag',
                                data:{match_id:Config.id , tagValue:value,match_type_id:that.homeMatchTypeIndex}
                            },function (ret) {
                                that.getMatchTags();
                            },function (err) {
                                this.$message({
                                    type: 'error',
                                    message: err
                                });
                            });
                        }).catch(() => {

                        });
                    },
                    /**
                     *  获取比赛标签[data]
                     */
                    getMatchTags(){
                        var that = this;
                        var match_type_id = that.homeMatchTypeIndex; //选中的赛道id
                        Fast.api.ajax({
                            url:'match/match/getMatchTags',
                            data:{match_type_id:match_type_id,match_id:Config.id}
                        },function (ret) {
                            that.matchTags = ret.data;
                            that.matchTagItemAllCount = ret.item_total_count;
                            that.matchTagItemSelected = ''; //从新选到 全部数据
                            setTimeout(function () {
                                $("#showDataTable").bootstrapTable('refresh');
                            }, 200);
                            return false;
                        });
                    },
                    // 修改Tag时触发
                    changeTag(tag){
                        var that = this;
                        $("#showDataTable").bootstrapTable('refresh',{
                            query:
                                {
                                    tag:tag,
                                    match_type:that.homeMatchTypeIndex
                                }
                        });
                    },
                    //移动到(移动报名数据到赛道下的标签内)
                    moveto(match_tag_id){
                        var table = $("#showDataTable");
                        console.log('table',table)
                        //获取是否存在选中的数据
                        var rows = table.bootstrapTable('getAllSelections');
                        var ids = Table.api.selectedids(table);
                        if(ids.length == 0){
                            Toastr.info("请选中所要移动的数据!");
                            return;
                        }
                        //存在选中项 然后进行修改其所属标签
                        Fast.api.ajax({
                            url:'match/match/setMoveToTag',
                            type:'POST',
                            data:{ids:ids,match_tag_id:match_tag_id}
                        },function (ret) {
                            //刷新当前数据列表
                            table.bootstrapTable('refresh');
                        },function (err) {
                            layer.msg('移动失败!');
                        });
                    },
                    //修改赛道时触发
                    changeType(){
                        //修改赛道  修改的应该是分组数据
                        var that = this;
                        that.getMatchTags();
                    },
                    //删除赛道
                    delFormSet(id){

                        var that = this;
                        Fast.api.ajax( {
                            url:'match/match/delFormSet',
                            type:'POST',
                            data:{form_set_id:id}
                        },function (ret) {
                            //刷新当前数据列表
                            that.getFormTypes(0);
                        },function (err) {
                            layer.msg('移动失败!');
                        });

                    },
                    set_prize_level() {
                        var table = $("#showDataTable");
                        //获取是否存在选中的数据
                        var ids = Table.api.selectedids(table);
                        if(ids.length == 0){
                            Toastr.info("请选中所要设置的数据!");
                            return;
                        }
                        var jsonIds = JSON.stringify(ids);
                        Fast.api.open('/school/match/match_item_prize/set_level' + "/ids/"+ids, '批量设置获奖级别', {
                            callback: function (res) {
                                table.bootstrapTable('refresh');
                            },
                        });
                    },
                    set_prize_info() {
                        var table = $("#showDataTable");
                        //获取是否存在选中的数据
                        var ids = Table.api.selectedids(table);
                        console.log(ids);
                        if(ids.length == 0){
                            Toastr.info("请选中所要设置的数据!");
                            return;
                        }
                        var jsonIds = JSON.stringify(ids);
                        Fast.api.open('/school/match/match_item_prize/set_prize' + "/ids/"+ids, '批量导入获奖信息', {
                            callback: function (res) {
                                table.bootstrapTable('refresh');
                            },
                        });
                    },
                    //刷新按钮
                    refreshCustom:function () {
                        var that = this;
                        that.changeTag(that.matchTagItemSelected);
                    }
                }
            });
            //*************************** 自定义export开始
            var submitForm = function (ids, layero) {
                $("input[name=ids]", layero).val(ids);
                $("input[name=college_id]", layero).val($("#collageSearch").val());
                $("input[name=specialty_id]", layero).val($("#specialtySearch").val());
                $("input[name=student_name]", layero).val($("#student_name").val());
                $("input[name=match_tag_id]", layero).val(app.matchTagItemSelected);
                $("input[name=match_type_id]", layero).val(app.homeMatchTypeIndex);
                $("form", layero).submit();
            };
            $(document).on("click", ".btn-export", function () {
                var table = $("#showDataTable");
                var ids = Table.api.selectedids(table);
                var page = table.bootstrapTable('getData');
                var all = table.bootstrapTable('getOptions').totalRows;
                Layer.confirm("请选择导出的选项<form action='" + Fast.api.fixurl("match/match/registerExport") + "' method='post' target='_blank'><input type='hidden' name='ids' value='' /><input type='hidden' name='college_id' ><input type='hidden' name='specialty_id'><input type='hidden' name='student_name'><input type='hidden' name='match_tag_id'><input type='hidden' name='match_type_id'></form>", {
                    title: '导出报名数据',
                    btn: ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
                    // btn: ["选中项(" + ids.length + "条)"],
                    success: function (layero, index) {
                        $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
                    },
                    yes: function (index, layero) {
                        if(ids.length <= 0) {
                            layer.msg('请先勾选数据')
                            return false;
                        }
                        submitForm(ids.join(","), layero);
                        return false;
                    },
                    btn2: function (index, layero) {
                        var ids = [];
                        $.each(page, function (i, j) {
                            ids.push(j.id);
                        });
                        submitForm(ids.join(","), layero);
                        return false;
                    },
                    btn3: function (index, layero) {
                        submitForm("all", layero);
                        return false;
                    }
                })
            });
            //创建表单
            $(".closeToMatch").click(function(){
                var match_id = $('#match_id').val();
                var match_type_id = app.homeMatchTypeIndex;
                //页面层-自定义
                var url = 'match/match/create_form?match_id='+ match_id +'&match_type_id=' + match_type_id;
                Fast.api.open(url,"创建表单",{
                    'area':["1000px","600px"],
                    callback:function (value) {
                        $('#tab-'+match_type_id).click();
                    }
                });
            });
            $("#faupload-rule_resources").data("upload-success", function (res) {
                console.log(res);
                var ul = $("#rule_resources_view");
                var names = $("#rule_resources_view li .resources_name");
                var flg = true;
                $.each(names,function(i,v){
                    if($(this).text() == res.file.name)  {
                        flg = false;
                    }
                });
                if(!flg) {
                    layer.msg('不能上传重复文件');
                    return false;
                }
                var str = '<li><a href="javascript:;" class="resources_name">'+res.file.name+'</a><input  size="50" name="row[rule_resources]['+res.file.name+']" type="hidden" value="'+res.url+'"> <a href="javascript:;" class="del_resources">删除</a></li>';
                ul.append(str);
                return false;
            });
            $(document).on("click",".del_resources",function(){
                $(this).parent().remove();
            });

            $('.add-data').click(function(){
                var match_id = $('#match_id').val();
                var match_type_id = app.homeMatchTypeIndex;
                //页面层-自定义
                var url = 'match/match/addMatchRegistration?match_id='+ match_id +'&match_type_id=' + match_type_id;
                Fast.api.open(url,"创建表单",{
                    'area':["80%","80%"],
                    callback:function (value) {
                        $('#tab-'+match_type_id).click();
                    }
                });
            });

            //返回比赛列表
            $('.matchList').on('click',function (){
                $url = 'match/match/index';
                Backend.api.addtabs($url,'比赛列表');
            });

            require(['school/match/formData'],function (fieldsMap) {
                console.log('数据',fieldsMap);
                $('.been_fields').val(JSON.stringify(fieldsMap.reg))
            });
            $('.match_typeChange').click(function () {
                var type = $(this).val();
                if(type == 0){
                    $('.match_type').hide();
                }else{
                    $('.match_type').show();
                }
            });




            Controller.api.bindevent();
        },

        //创建表单弹框
        create_form : function (){
            //切换表单类型
            $('.item').on('click',function () {
                $('.item').removeClass('this');
                $(this).addClass('this');
                var stage_type = $(this).attr('stage_type');
                $('#stage_type').val(stage_type);
            });

            //通过这种方式进行关闭窗口, callback 才能检测到
            Form.api.bindevent($("form[role=form]"),function () {
                Fast.api.close();
            });
            // Controller.api.bindevent();
        },
        showDataTable(){
            $(document).on("click",".remark",function(){
                var id = $(this).attr('data-value');
                Fast.api.open('/school/match/matchitems/remark' + "/id/"+id);
            });
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'match/matchitems/index' + location.search,
                    add_url: 'match/matchitems/add',
                    edit_url: 'match/matchitems/edit',
                    del_url: 'match/matchitems/del',
                    multi_url: 'match/matchitems/multi',
                    table: 'matchItem',
                }
            });
            var table = $("#showDataTable");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                loading:true,
                // 是否显示快速搜索(搜索框)
                search: false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                commonSearch: true,
                showSearch: false,
                clickToSelect:false,
                pk: 'id',
                sortName: 'm.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'Id'},
                        {field: 'user_text', title: __('学生')},
                        {field: 'student_no', title: __('学号')},
                        {field: 'college_name', title: __('学院')},
                        {
                            field: 'remark', title: '评语', formatter: function (val, row) {

                                return "<a href='javascript:;' class='remark' data-review='' data-value="+row.id+">点击查看</a>";
                            }, operate: false,
                        },
                        {field: 'project_name', title: __('项目名称')},
                        {field: 'territory_name', title: __('所属技术')},
                        {field:'tag_name',title:'阶段'},
                        {
                            field: 'stage_fraction', title: '分数', formatter: function (val, row) {
                                return (row.result) ? row.result : '暂无';
                            }, operate: false
                        },
                        // {field:'stage_fraction',title:'分数'},
                        {field: 'match_type_text', title: __('赛道')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {
                            field: 'prize_type', title: '获奖等级', formatter: function (val, row) {
                                if(val) {
                                    var type = parseInt(row.prize_type);

                                    switch (type) {
                                        case 1:
                                            return "<a href='javascript:;' data-tag="+row.match_tag_id+" class='prize_type_edit' data-value="+row.id+">一等奖/"+row.get_time +"</a>";
                                        case 2:
                                            return "<a href='javascript:;' data-tag="+row.match_tag_id+" class='prize_type_edit'  data-value="+row.id+">二等奖/"+row.get_time +"</a>";
                                        case 3:
                                            return "<a href='javascript:;' data-tag="+row.match_tag_id+" class='prize_type_edit'  data-value="+row.id+">三等奖/"+row.get_time +"</a>";
                                    }
                                }else{
                                    return "<a href='javascript:;'  class='prize_type_add'  data-value="+row.id+">设置获奖信息</a>";
                                }
                            }, operate: false,
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name: 'projectView',
                                    text: '查看详情',
                                    classname: 'btn btn-xs btn-success btn-addtabs',
                                    url: function (row) {
                                        return '/school/match/match/register_detail/id/'+row.id
                                    }
                                },
                                {
                                    name: 'dels',
                                    text: __('删除'),
                                    icon: 'fa fa-trash',
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    url:function (row) {
                                        return '/school/match/match/del_items/id/' + row.id;
                                    },
                                    confirm: '删除作品后无法恢复,确认删除吗?',
                                    success: function (data, ret) {
                                        $(".fa-refresh").trigger("click");
                                    },
                                }
                            ]
                        },
                    ]
                ],
                queryParams: function (params) {
                    params.tag = $(".tag_query").val();
                    params.match_type = $(".matchtype_query").val();
                    params.collageSearch = $('#collageSearch').val();
                    params.specialtySearch = $('#specialtySearch').val();
                    params.student_name = $('#student_name').val();
                    params.project_name = $('#project_name').val();
                    return params;
                }

        });

            //奖项添加
            $(document).on("click",".prize_type_add",function(){
                var id = $(this).attr('data-value');
                Fast.api.open('/school/match/match_item_prize/add' + "/item_id/"+id, '设置获奖信息', {
                    callback: function (res) {
                        table.bootstrapTable('refresh');
                    },
                });
            });
            //奖项编辑
            $(document).on("click",".prize_type_edit",function(){
                var id = $(this).attr('data-value');
                var tag_id = $(this).attr('data-tag');
                Fast.api.open('/school/match/match_item_prize/edit' + "/item_id/"+id, '设置获奖信息', {
                    callback: function (res) {
                        table.bootstrapTable('refresh');
                    },
                });
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        //自定义表单
        formdata: function () {
            require(['custom-form', 'school/match/fields'], function (customForm,fieldsMap) {
                // $.ajax({
                //     // url: '/assets/js/school/match/formData.json',   'school/match/fields'
                //     url:  'school/match/fields.js',
                //     method: 'GET',
                //     success: function (fieldsMap) {
                //     }
                // })
                var beenSetFields = fieldsMap[Config.form_type] || []
                $.extend(beenSetFields, Config.fields_data || [])
                customForm.init({
                    beenSetFields: beenSetFields,
                    callback: function (fieldsArr) {
                        var is_full= 0;
                        for(var i=0;i<fieldsArr.length;i++){
                            if(fieldsArr[i].type === 'file'){
                                is_full +=1;
                            }
                        }
                     /*   if(is_full>1){
                            layer.alert("文件上传项,暂时只开放一次,请自行删除多余的文件上传项");
                            return false;
                        }*/
                        var data = {}
                        data.setting = JSON.stringify(fieldsArr);
                        data.form_set_id = Config.form_set_id
                        $.ajax({
                            url: 'match/match/formData',
                            type: 'POST',
                            data: data,
                            success: function (res) {
                                if (1 === res.code) {
                                    parent.Toastr.success(res.msg);
                                    parent.$('.btn-refresh').trigger('click');
                                    var index = parent.Layer.getFrameIndex(window.name);
                                    parent.Layer.close(index);
                                } else {
                                    Toastr.error(res.msg);
                                }
                            },
                            error: function (err) {
                                Toastr.error(err.msg);
                            }
                        })
                    }
                });
            })
        },
        //设置表单
        setformapplication(){

            var form = $("form[role=form]")
            // 监听单选按钮切换(限制报名人数js-countWrap)
            $('.radio').on('change', 'input[type="radio"]', function () {
                $(this).parents("label").siblings("span").children("input").val('');
                // 限制人数
                if ($(this).attr('limitCount')) {
                    $(this).parent().siblings('.js-countWrap').show()
                } else {
                    $(this).parent().siblings('.js-countWrap').hide()
                }
            })

            // 验证信息在表单项下方显示
            form.data('validator-options', { msgClass: 'n-bottom' })
            Form.api.bindevent(form, function () { }, function () { }, function () {
                // 校正限制次数字段
                $('input[limitCount]').each(function () {
                    if (!this.checked) {
                        var inputCount = $(this).parent().siblings('.js-countWrap').find('input')
                        inputCount.val('')
                    }
                })
                // 校正时间字段
                $('input[name="set_time"]').each(function () {
                    if (!this.checked) {
                        var inputDate = $(this).parents('.setTimeWrap').siblings().find('input.datetimepicker')
                        inputDate.val('')
                    }
                })
            });

        },
        register_detail: function() {
            var vm = new Vue({
                el:"#app",
                data() {
                    return {
                        teacherInfo:Config.teacherInfo || [],
                        studentInfo:Config.studentInfo || [],
                        regInfo:Config.regInfo || [],
                        defaultInfo:Config.defaultInfo || [],
                        formSets:Config.formSets || [],
                        row:Config.row,
                        cdn_url :Config.cdn_url ,
                        match_tag_id:Config.row.match_tag_id,
                        form: {
                            matchTag:Config.matchTag,
                        },
                        territory:Config.territory || [],
                   }
                },
                mounted() {
                    var _this = this;
                    $.each(_this.formSets,function (k,v) {
                        // $.each(v.form_data,function(i,val) {
                        //     let name = val.name;
                        //     if(val.type == 'checkbox') {
                        //         if(name in (v.stage_type == 'reg' ? _this.regInfo :_this.defaultInfo)) {
                        //             var checkobxV = (v.stage_type == 'reg' ? _this.regInfo[name] :_this.defaultInfo[name]);
                        //             _this.$set((v.stage_type == 'reg' ? _this.regInfo :_this.defaultInfo),name,checkobxV.split(","));
                        //         }else{
                        //             _this.$set((v.stage_type == 'reg' ? _this.regInfo :_this.defaultInfo),name,[]);
                        //         }
                        //     }
                        // });
                    });
                },
                methods: {
                    goBack(){
                        Backend.api.closetabs();
                    },
                    file_url(v) {
                        var v = Backend.api.cdnurl(v);
                        var exts = ['mp4','zip','pdf'];
                        var startIndex = v.lastIndexOf(".");
                        var ext =  v.substring(startIndex+1, v.length).toLowerCase();
                        var index = exts.indexOf(ext);
                        if(index != -1) {
                            return v;
                        }else{
                            return 'https://view.officeapps.live.com/op/view.aspx?src=' + v;
                        }
                    },
                    onSubmit() {
                        var that = this;
                        if(that.match_tag_id == '') {
                            layer.msg('请选择标签',{icon:2})
                            return false;
                        }
                        $.ajax({
                            url: '/school/match/match/edutItemTag',
                            method: 'POST',
                            data: { match_tag_id: that.match_tag_id,itemId:that.row.id},
                            success: function (res) {
                                if (1 === res.code) {
                                    layer.msg('操作成功',{icon:1});
                                    location.reload();
                                } else {
                                    layer.msg(res.msg,{icon:2})
                                    return false;
                                }
                            }
                        });
                    }
                }
            })
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});