shop.js 52.9 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 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
//店铺装修
'use strict';
var $ = require('jquery'),
    common=require('../common/common');

var g;  //grid
var curDialogId;  //当前打开的编辑弹层ID
var curPlatform = "shopWeb-pc";   //当前渲染页面用的模板名称
var curTemplateType = "2";  //当前模板类型 1:基础模板,2:经典模板
var shopType = 1;  //店铺类型 1:单品牌,2:多品牌
var shopOperate = 'view';  //操作 editor:可编辑, view:查看不可编辑
var ENUM = {
    "editor-largePic":{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0},
    "editor-smallPic":{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0},
    "editor-brand":{"position":"", "name":"", "url":""},
    "editor-recommend": {"position":"", "name":"", "enName":"", "src":"", "url":"","isShowInApp":"Y"},
    "editor-hotRecommend":{"position":"", "src":"", "url":""},
    "editor-signboard":{"position":"", "src":"", "url":"","startTime": "","endTime": "","publishStatus": 0},
    "editor-newGoodTab":{"position":"", "name":"", "url":""},
    "editor-hotGoodTab":{"position":"", "name":"", "url":""},
    "editor-newProduct":{"productId":"", "position":"", "productName":"", "productPrice":"", "src":"", "url":""},
    "editor-hotProduct":{"productId":"", "position":"", "productName":"", "productPrice":"", "src":"", "url":""}
};  //添加一条不同弹层使用的初始化模板
var resourcesNew = {
    "shopTopBanner":{
        "id":"",
        "data": [{"shopSrc": "", "detailSrc": "", "isShowShopName": "Y"}]
    },
    "navigationBar":{
        "id":"",
        "data": [{"name":"",url:""}, {"name":"",url:""}, {"name":"",url:""}]
    },
    "largeSlideImg":{
        "id":"",
        "data": [
            {"position": 5, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
            {"position": 4, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
            {"position": 3, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
            {"position": 2, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
            {"position": 1, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]}
        ]
    },
    "oneRowTwoColImages":{
        "id":"",
        "data": [
            {"position": 2, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
            {"position": 1, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]}
        ]
    },
    "brandBrowse":{
        "id":"",
        "data": []
    },
    "recommend":{
        "id":"",
        "title":"经典推荐",
        "data": [{"position":1, "name":"", "enName":"", "src":"", "url":"","isShowInApp":"Y"}]
    },
    "hotRecommend":{
        "id":"",
        "title":"热销推荐",
        "data": [{"position":1, "src":"", "url":""}]
    },
    "signboard":{
        "id":"",
        "data": [{"position":1, "src":"", "url":"", "startTime": "", "endTime": "", "publishStatus": 0}]
    },
    "goodsTabBar":{
        "id":"",
        "data": {
            "new":[{"position":0, "name":"MORE", "url":""}],
            "hot":[{"position":0, "name":"MORE", "url":""}]
        }
    },
    "newProducts":{
        "id":"",
        "data": [{"productId":"0", "position":1, "productName":"默认商品", "productPrice":"默认价格", "src":"", "url":""}]
    },
    "hotProducts":{
        "id":"",
        "data": [{"productId":"0", "position":1, "productName":"默认商品", "productPrice":"默认价格", "src":"", "url":""}]
    }
}  //初始化装修信息json
var shopsId, _id, jsonMain, jsonClone, topNewProducts, topHotProducts;

getParams();
findDecoration();

/********************主流程*********************/

//URL获取参数
function getParams(){
    var paramUrl = location.href + "";
    var param = paramUrl.substring(paramUrl.indexOf("decorationDetail"));
    var paramList = param.split("/");

    if(paramList){
        shopsId = paramList[1];
        shopType = paramList[2];
        shopOperate = paramList[3];
        _id = paramList[4];
    }
    if(shopOperate == 'editor'){
        $(".moduleTypeSelect").show().find("#templateSelect").removeAttr("disabled");
        $(".moduleSubmite").show().siblings().hide();
    }else if(shopOperate == 'view'){
        $(".moduleTypeSelect").hide();
        $(".moduleView").show().siblings().hide();
    }else if(shopOperate == 'check'){
        $(".moduleTypeSelect").show().find("#templateSelect").attr("disabled","disabled");
        $(".moduleCheck").show().siblings().hide();
    }
}
//json渲染模板
function showMain(){
    $('#templateSelect').val(curTemplateType);
    $("input[name='brandLevel'][value='"+curTemplateType+"']").attr('checked',"checked");

    if(curPlatform == "shopWeb-pc"){
        $('#main').empty().html(common.util.__template2($("#"+curPlatform+"-"+curTemplateType).html(),jsonMain));
    } else if(curPlatform == "shopWeb-app"){
        $('#main').empty().html(common.util.__template2($("#"+curPlatform).html(),jsonMain));
    }
    //单品牌,多品牌
    if(shopType == 2){
        $(".model-brand").show();
    }else if(shopType == 1){
        $(".model-brand").hide();
    }
    showEditorIconEvent();
}
//弹窗编辑主流程
function editorIconEvent(title,id){
    $('.editorIcon').on('click',function(){
        curDialogId = id;
        common.dialog.confirm(
            title,
            "<div class='editorTitle'></div><div class='editor-dialog' id='"+ id +"'></div><div class='editorTip'></div> ",
            function(){
                if(editorCheck(id)){
                    if(!(curDialogId == "editor-largePic-app" || curDialogId == "editor-recommend-app" || curDialogId == "editor-brand-app")){
                        freshJson(id, g.__rows, 1);
                    }
                    showMain();
                }else{
                    return false;
                }
            },
            function(){
                if(!(curDialogId == "editor-largePic-app" || curDialogId == "editor-recommend-app" || curDialogId == "editor-brand-app")){
                    freshJson(id, g.__rows, 0);
                }
            }
        );
        gridInit(id);
        untilEditorEvent(id);
        editorTipInit(id);
    })
}

/********************接口Ajax*********************/

//Ajax查询
function findDecoration(){
    common.util.__ajax(
        {
            url:'/store/shop-decoration-find',
            data: {
                "shopsId": shopsId
            }
        },
        function(rs) {
            //console.log(rs.data);
            if(rs.data){
                jsonMain = rs.data;
            }
            if(jsonMain.templateName){
                curTemplateType = jsonMain.templateName;
            }
            //没有装修信息,初始化装修信息
            if($.isEmptyObject(jsonMain.resources)){
                jsonMain.resources = $.extend(true,{},resourcesNew);
            }
            //装修信息中品牌内容为空,初始化品牌
            if(jsonMain.resources.brandBrowse.data.length < 1 && jsonMain.brandList){
                cloneArr(jsonMain.brandList,jsonMain.resources.brandBrowse.data);
            }
            //装修json克隆
            jsonClone = $.extend(true,{},jsonMain);
            //最新上架,最热商品接口
            if(shopOperate == 'editor'){
                findTopNewProducts();
                findTopHotProducts();
            }
            showMain();
        },true);
}
//Ajax最新上架商品
function findTopNewProducts(){
    common.util.__ajax({
        url:'/store/shop-decoration-newProducts',
        data: {
            "shopsId": jsonMain.shopsId,
            "size": 20
        }
    },function(rs){
        topNewProducts = rs.data;
    },true);
}
//Ajax热销商品
function findTopHotProducts(){
    common.util.__ajax({
        url:'/store/shop-decoration-hotProducts',
        data: {
            "shopsId": jsonMain.shopsId,
            "size": 20
        }
    },function(rs){
        topHotProducts = rs.data;
    },true);
}
//Ajax保存,暂存:100,提交审核:200
function saveDecoration(submitStatus){
    common.util.__ajax({
        url:'/store/shop-decoration-save',
        data: {
            "submitStatus": submitStatus,
            "shopsId": jsonMain.shopsId,
            "platform": jsonMain.platform,
            "templateName": jsonMain.templateName,
            "resources": JSON.stringify(jsonMain.resources)
        }
    },function(rs){
        if(rs.data){
            //console.log(rs.data);
            if(submitStatus == 100){
                jsonMain = rs.data;
                jsonClone = $.extend(true,{},jsonMain);
                showMain();
            }else{
                setTimeout(function() {
                    location.href="/supplier/shop/decoration";
                }, 1000);
            }
        }
    });
}
//Ajax审核,审核通过:300,驳回:900
function checkDecoration(checkStatus,comment){
    if(comment){
        common.util.__ajax({
            url:'/store/shop-decoration-check',
            data: {
                "id": _id,
                "checkStatus": checkStatus,
                "comment": comment
            }
        },function(rs){
            common.util.__tip("审核通过成功!","success");
            setTimeout(function() {
                location.href="/supplier/check/index";
            }, 1000);
        },true);
    }else{
        common.util.__ajax({
            url:'/store/shop-decoration-check',
            data: {
                "id": _id,
                "checkStatus": checkStatus
            }
        },function(rs){
            common.util.__tip("审核驳回成功!","success");
            setTimeout(function() {
                location.href="/supplier/check/index";
            }, 1000);
        },true);
    }
}

/********************工具类*********************/

//弹层表单grid生成器
function gridInit(id){
    switch (id){
        //店铺顶部banner
        case "editor-banner":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"店铺banner图片", render:function(item){
                        return "<input type=file name='shopBannerImage' id='shopBannerImage_"+item.__index+"' value='"+item.shopSrc+"' />";
                    }},
                    {display:"是否显示店铺名称", render:function(item){
                        if(item.isShowShopName == "Y"){
                            return "<lable><input type='radio' name='isShowShopName' value='Y' checked='checked'>显示店铺名称</lable><br>" +
                                "<lable><input type='radio' name='isShowShopName' value='N'>不显示店铺名称</lable>";
                        }else{
                            return "<lable><input type='radio' name='isShowShopName' value='Y'>显示店铺名称</lable><br>" +
                                "<lable><input type='radio' name='isShowShopName' value='N' checked='checked'>不显示店铺名称</lable>";
                        }
                    }},
                    {display:"商品详情页banner图片", render:function(item){
                        return "<input type=file name='DetailbannerImage' id='DetailbannerImage_"+item.__index+"' value='"+item.detailSrc+"' />";
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.shopTopBanner.data;
            g.init(g.__rows);
            break;

        //店铺导航nav
        case "editor-nav":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"编号", render:function(item){
                       return item.__index+1;
                    }},
                    {display:"名称", render:function(item){
                        return "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' data-index='"+item.__index+"' maxlength='5' />";
                    }},
                    {display:"链接", render:function(item){
                        return "<input class='form-control inputChange' type=text name='url' value='"+item.url+"' data-index='"+item.__index+"' />";
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.navigationBar.data;
            g.init(g.__rows);
            break;

        //店铺大图资源位
        case "editor-largePic":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {
                        display:"<div class='row'><div class='col-sm-2'>图片</div><div class='col-sm-3'>链接</div><div class='col-sm-2'>开始时间</div><div class='col-sm-2'>结束时间</div> " +
                        "<div class='col-sm-1'>状态</div><div class='col-sm-2'>操作</div></div>",
                        render: function (item) {
                            return resourcesHtmlInit(item,"largePic");
                        }
                    }
                ]
            });
            g.__rows=""||jsonClone.resources.largeSlideImg.data;
            g.init(g.__rows);
            break;

        //店铺小图资源位
        case "editor-smallPic":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {
                        display:"<div class='row'><div class='col-sm-2'>图片</div><div class='col-sm-3'>链接</div><div class='col-sm-2'>开始时间</div><div class='col-sm-2'>结束时间</div> " +
                        "<div class='col-sm-1'>状态</div><div class='col-sm-2'>操作</div></div>",
                        render: function (item) {
                            return resourcesHtmlInit(item,"smallPic");
                        }
                    }
                ]
            });
            g.__rows=""||jsonClone.resources.oneRowTwoColImages.data;
            g.init(g.__rows);
            break;

        //品牌一览
        case "editor-brand":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        item.position=item.position || (item.__index+1);
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"名称", render:function(item){
                        return item.brandName;
                    }},
                ]
            });
            g.__rows=""||jsonClone.resources.brandBrowse.data;
            g.init(g.__rows);
            break;

        //经典推荐recommend
        case "editor-recommend":
            $('.editorTitle').html("<div class='form-inline' style='margin-bottom: 10px'><label>标题名称编辑:</label><input class='form-control' type=text name='title' value='"+ jsonMain.resources.recommend.title +"' /></div> ");
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        item.position=item.position || (item.__index+1);
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"名称", render:function(item){
                        return "<div style='width: 5%; float: left; line-height: 40px; color: #ff0000'>*</div><div style='width: 95%; float: left'>" +
                            "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' placeholder='中文' data-index='"+item.__index+"' />" +
                            "<input class='form-control inputChange' style='margin-top:10px' type=text name='enName' value='"+item.enName+"' placeholder='英文' data-index='"+item.__index+"' />" +
                            "</div>";
                    }},
                    {display:"图片", render:function(item){
                        return "<input type=file name='recommendImage' id='recommendImage_"+item.__index+"' value='"+item.src+"' />";
                    }},
                    {display:"链接", render:function(item){
                        return "<input class='form-control inputChange' type=text name='url' value='"+item.url+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"APP展示", render:function(item){
                        if(item.isShowInApp == "Y"){
                            return "<input class='form-control checkBoxChange' type=checkBox name='isShowInApp' data-index='"+item.__index+"' checked />";
                        }else{
                            return "<input class='form-control checkBoxChange' type=checkBox name='isShowInApp' data-index='"+item.__index+"' />";
                        }
                    }},
                    {display:"操作", render:function(item){
                        var htmlPic = "",i=item.__index;
                        if(g.__rows.length == 1){
                            htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
                        }
                        if(g.__rows.length > 1){
                            if(i == (g.__rows.length-1) && i < 15){
                                htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                                htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
                            }
                            if(i == (g.__rows.length-1) && i >= 15){
                                htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                            }
                            if(i < (g.__rows.length-1)){
                                htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
                            }
                        }
                        return htmlPic;
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.recommend.data;
            g.init(g.__rows);
            break;

        //热销推荐hotRecommend
        case "editor-hotRecommend":
            $('.editorTitle').html("<div class='form-inline' style='margin-bottom: 10px'><label>标题名称编辑:</label><input class='form-control' type=text name='title' value='"+ jsonMain.resources.hotRecommend.title +"' /></div> ");
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        item.position=item.position || (item.__index+1);
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"图片", render:function(item){
                        return "<input type=file name='signboardImage' id='signboardImage_"+item.__index+"' value='"+item.src+"' />";
                    }},
                    {display:"链接", render:function(item){
                        return "<input class='form-control inputChange' type=text name='url' value='"+item.url+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"操作", render:function(item){
                        var htmlPic = "",i=item.__index;
                        if(g.__rows.length == 1){
                            htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
                        }
                        if(g.__rows.length > 1){
                            if(i == (g.__rows.length-1) && i < 5){
                                htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                                htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
                            }
                            if(i == (g.__rows.length-1) && i >= 5){
                                htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                            }
                            if(i < (g.__rows.length-1)){
                                htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
                            }
                        }
                        return htmlPic;
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.hotRecommend.data;
            g.init(g.__rows);
            break;

        //水牌signboard
        case "editor-signboard":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        item.position=item.position || (item.__index+1);
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"图片", render:function(item){
                        return "<input type=file name='signboardImage' id='signboardImage_"+item.__index+"' value='"+item.src+"' />";
                    }},
                    {display:"链接", render:function(item){
                        return "<input class='form-control inputChange' type=text name='url' value='"+item.url+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"开始时间", render:function(item){
                        return "<input type=text class='form-control inputChange' readOnly='true' jsaction='time:end:endTime_"+item.__index+"' id='startTime_"+item.__index+"' name='startTime' value='"+item.startTime+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"结束时间", render:function(item){
                        return "<input type=text class='form-control inputChange' readOnly='true' jsaction='time:start:startTime_"+item.__index+"' id='endTime_"+item.__index+"' name='endTime' value='"+item.endTime+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"状态", render:function(item){
                        return "<span style='white-space: nowrap'>" + (item.publishStatus==0?"未发布":"已发布") + "</span>";
                    }},
                    {display:"操作", render:function(item){
                        var htmlPic = "",i=item.__index;
                        if(i == (g.__rows.length-1) && g.__rows.length > 1){
                            htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                            htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
                        }
                        if(i < (g.__rows.length-1) && g.__rows.length > 1){
                            htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
                        }
                        if(i == (g.__rows.length-1) && g.__rows.length == 1){
                            htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
                        }
                        return htmlPic;
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.signboard.data;
            g.init(g.__rows);
            break;

        //新品上架标签tab
        case "editor-newGoodTab":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        if(item.__index == 0){
                            return item.position;
                        }else{
                            item.position=item.position || (item.__index);
                            return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                        }
                    }},
                    {display:"名称", render:function(item){
                        if(item.__index == 0){
                            return item.name;
                        }else{
                            return "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' data-index='"+item.__index+"' maxlength='5' />";
                        }
                    }},
                    {display:"链接", render:function(item){
                        if(item.__index == 0){
                            return "http://店铺商品列表页(默认)";
                        }else{
                            return "<input class='form-control inputChange' type=text name='url' value='"+item.url+"' data-index='"+item.__index+"' />";
                        }
                    }},
                    {display:"操作", render:function(item){
                        var html = "";
                        if(item.__index == 0 && g.__rows.length == 1){
                            html += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
                        }else{
                            if(g.__rows.length > 1 && item.__index > 0){
                                html += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                                if(g.__rows.length > 1 && g.__rows.length < 5 && item.__index == g.__rows.length - 1){
                                    html += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
                                }
                            }
                        }
                        return html;
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.goodsTabBar.data.new;
            g.init(g.__rows);
            break;

        //人气单品标签tab
        case "editor-hotGoodTab":
            g = new common.grid({
                hash: false,
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        if(item.__index == 0){
                            return item.position;
                        }else{
                            item.position=item.position || (item.__index);
                            return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                        }
                    }},
                    {display:"名称", render:function(item){
                        if(item.__index == 0){
                            return item.name;
                        }else{
                            return "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' data-index='"+item.__index+"' maxlength='5' />";
                        }
                    }},
                    {display:"链接", render:function(item){
                        if(item.__index == 0){
                            return "http://店铺商品列表页(默认)";
                        }else{
                            return "<input class='form-control inputChange' type=text name='url' value='"+item.url+"' data-index='"+item.__index+"' />";
                        }
                    }},
                    {display:"操作", render:function(item){
                        var html = "";
                        if(item.__index == 0 && g.__rows.length == 1){
                            html += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
                        }else{
                            if(g.__rows.length > 1 && item.__index > 0){
                                html += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                                if(g.__rows.length > 1 && g.__rows.length < 5 && item.__index == g.__rows.length - 1){
                                    html += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
                                }
                            }
                        }
                        return html;
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.goodsTabBar.data.hot;
            g.init(g.__rows);
            break;

        //新品上架
        case "editor-newProduct":
            $("#"+id).html("<div id='editor-newProduct-grid' style='width: 500px; float: left'></div><div class='top20List' style='float: left;margin-left: 40px'></div> ");
            if(topNewProducts){
                $("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),topNewProducts));
            }else{
                $("#"+id+" .top20List").html("最新上架20条加载失败,请重新加载!");
            }

            g = new common.grid({
                hash: false,
                el:"#editor-newProduct-grid",
                columns:[
                    {display:"排序", render:function(item){
                        item.position=item.position || (item.__index+1);
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"图片", render:function(item){
                        return "<img src='"+item.src+"' style='width:75px; height:80px'>";
                    }},
                    {display:"操作", render:function(item){
                        var html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                        return html;
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.newProducts.data;
            g.init(g.__rows);
            productTopDataLink(g.__rows);
            break;

        //人气单品
        case "editor-hotProduct":
            $("#"+id).html("<div id='editor-hotProduct-grid' style='width: 500px; float: left'></div><div class='top20List' style='float: left;margin-left: 40px'></div> ");
            if(topHotProducts){
                $("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),topHotProducts));
            }else{
                $("#"+id+" .top20List").html("最新上架20条加载失败,请重新加载!");
            }

            g = new common.grid({
                hash: false,
                el:"#editor-hotProduct-grid",
                columns:[
                    {display:"排序", render:function(item){
                        item.position=item.position || (item.__index+1);
                        return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
                    }},
                    {display:"图片", render:function(item){
                        return "<img src='"+item.src+"' style='width:75px; height:80px'>";
                    }},
                    {display:"操作", render:function(item){
                        var html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                        return html;
                    }}
                ]
            });
            g.__rows=""||jsonClone.resources.hotProducts.data;
            g.init(g.__rows);
            productTopDataLink(g.__rows);
            break;

        default :
            break;
    }
}
//弹层表单确定后刷新json数据,status参数:1:确定,0:取消
function freshJson(id,data,status){
    switch (id){
        case "editor-banner":
            if(status == 1){
                data[0].isShowShopName = $("input[name='isShowShopName']:checked").val();
                cloneArr(data,jsonMain.resources.shopTopBanner.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.shopTopBanner.data,data);
            }
            break;

        case "editor-nav":
            if(status == 1){
                cloneArr(data,jsonMain.resources.navigationBar.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.navigationBar.data,data);
            }
            break;

        case "editor-largePic":
            if(status == 1){
                cloneArr(sortJson(data,1),jsonMain.resources.largeSlideImg.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.largeSlideImg.data,data);
            }
            break;

        case "editor-smallPic":
            if(status == 1){
                cloneArr(sortJson(data,1),jsonMain.resources.oneRowTwoColImages.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.oneRowTwoColImages.data,data);
            }
            break;

        case "editor-brand":
            if(status == 1){
                cloneArr(sortJson(data,1),jsonMain.resources.brandBrowse.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.brandBrowse.data,data);
            }
            break;

        case "editor-recommend":
            if(status == 1){
                jsonMain.resources.recommend.title = jsonClone.resources.recommend.title = $(".editorTitle input[name='title']").val();
                cloneArr(sortJson(data,1),jsonMain.resources.recommend.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.recommend.data,data);
            }
            break;

        case "editor-hotRecommend":
            if(status == 1){
                jsonMain.resources.hotRecommend.title = jsonClone.resources.hotRecommend.title = $(".editorTitle input[name='title']").val();
                cloneArr(sortJson(data,1),jsonMain.resources.hotRecommend.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.hotRecommend.data,data);
            }
            break;

        case "editor-signboard":
            if(status == 1){
                cloneArr(sortJson(data,1),jsonMain.resources.signboard.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.signboard.data,data);
            }
            break;

        case "editor-newGoodTab":
            if(status == 1){
                cloneArr(sortJson(data,0),jsonMain.resources.goodsTabBar.data.new);
            }else if(status == 0){
                cloneArr(jsonMain.resources.goodsTabBar.data.new,data);
            }
            break;

        case "editor-hotGoodTab":
            if(status == 1){
                cloneArr(sortJson(data,0),jsonMain.resources.goodsTabBar.data.hot);
            }else if(status == 0){
                cloneArr(jsonMain.resources.goodsTabBar.data.hot,data);
            }
            break;

        case "editor-newProduct":
            if(status == 1){
                cloneArr(sortJson(data,1),jsonMain.resources.newProducts.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.newProducts.data,data);
            }
            break;

        case "editor-hotProduct":
            if(status == 1){
                cloneArr(sortJson(data,1),jsonMain.resources.hotProducts.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.hotProducts.data,data);
            }
            break;

        default :
            break;
    }
}
//tip生成
function editorTipInit(id){
    var tipHtml = "";
    switch (id){
        case "editor-banner":
            if(curPlatform == "shopWeb-pc"){
                tipHtml = "<span>提示:请上传像素1150*150的图片。</span>";
            }
            if(curPlatform == "shopWeb-app"){
                tipHtml = "<span>提示:请上传像素640*120的图片。</span>";
            }
            break;
        case "editor-nav":
            tipHtml = "<span>提示:标题名称最多5个汉字。</span>";
            break;
        case "editor-largePic":
            tipHtml = "<span>提示:请上传像素660*358的图片,该图片会适配到APP端。</span>";
            break;
        case "editor-largePic-app":
            tipHtml = "<span>提示:由PC端适配,修改请到PC端修改。</span>";
            break;
        case "editor-smallPic":
            tipHtml = "<span>提示:请上传像素300*174的图片。</span>";
            break;
        case "editor-brand":
            tipHtml = "<span>提示:内容会适配到APP的【品牌一览】中。</span>";
            break;
        case "editor-brand-app":
            tipHtml = "<span>提示:【品牌一览】由PC端【品牌集合】适配,修改请到PC端【品牌集合】修改。</span>";
            break;
        case "editor-recommend":
            tipHtml = "<span>提示:请上传像素50*50的图片,图片和标题会适配到APP的【热门品类】中。</span>";
            break;
        case "editor-recommend-app":
            tipHtml = "<span>提示:【热门品类】由PC端【经典推荐】适配,修改请到PC端【经典推荐】修改。</span>";
            break;
        case "editor-signboard":
            tipHtml = "<span>提示:请上传像素160*240的图片。</span>";
            break;
        case "editor-hotRecommend":
            tipHtml = "<span>提示:请上传像素160*240的图片。</span>";
            break;
        case "editor-newGoodTab":
            tipHtml = "<span>提示:最多编辑5个标签,标题名称最多5个汉字。</span>";
            break;
        case "editor-hotGoodTab":
            tipHtml = "<span>提示:最多编辑5个标签,标题名称最多5个汉字。</span>";
            break;
        default :
            break;
    }
    $(".editorTip").html(tipHtml);
}
//弹出框编辑校验
function editorCheck(id){
    switch (id){
        case "editor-largePic":
            return (checkNumInput() && checkEndTime());
            break;

        case "editor-smallPic":
            return (checkNumInput() && checkEndTime());
            break;

        case "editor-brand":
            return checkNumInput();
            break;

        case "editor-recommend":
            var title = $(".editorTitle input[name='title']");
            if(title.val()){
                if(checkNumInput()){
                    var nameList = $(".grid input[name='name']");
                    for(var i=0; i<nameList.length; i++){
                        if(!nameList.eq(i).val()){
                            nameList.eq(i).focus().addClass("error");
                            common.util.__tip("中文名不能为空!");
                            return false;
                        }
                    }
                    return true;
                }
            }else{
                title.focus().addClass("error");
                common.util.__tip("模块标题不能为空!");
                return false;
            }
            break;

        case "editor-hotRecommend":
            return checkNumInput();
            break;

        case "editor-signboard":
            return (checkNumInput() && checkEndTime());
            break;

        case "editor-newGoodTab":
            return checkNumInput();
            break;

        case "editor-hotGoodTab":
            return checkNumInput();
            break;

        case "editor-newProduct":
            return checkNumInput();
            break;

        case "editor-hotProduct":
            return checkNumInput();
            break;

        default :
            return true;
            break;
    }
}
//排序序号校验
function checkNumInput(){
    var positionList = $(".grid input[name='position']");
    for(var i=0; i<positionList.length; i++){
        if(positionList.eq(i).val()){
            if(!isNaN(positionList.eq(i).val())){
                if(positionList.eq(i).val() <= 0){
                    positionList.eq(i).focus().select().addClass("error");
                    common.util.__tip("排序数字请大于0!");
                    return false;
                }
            }else{
                positionList.eq(i).focus().select().addClass("error");
                common.util.__tip("排序必须为数字!");
                return false;
            }
        }else{
            positionList.eq(i).focus().addClass("error");
            common.util.__tip("排序不能为空!");
            return false;
        }
    }
    return true;
}
//结束时间校验
function checkEndTime(){
    var endTimeList = $(".grid input[name='endTime']");
    for(var i=0; i<endTimeList.length; i++){
        if(!endTimeList.eq(i).val()){
            endTimeList.eq(i).focus().addClass("error");
            common.util.__tip("结束时间不能为空!");
            return false;
        }
    }
    return true;
}
//编辑动画事件
function showEditorIconEvent(){
    if(shopOperate == 'editor'){
        $(".contentpanel .model-editor").hover(
            function () {
                var _this = $(this);
                var editorModelId = $(this).attr("data-toggle");
                var editorModelTitle = $(this).attr("data-title");

                var editorIcon = "<div class='editorBorder'></div>" +
                    "<a class='editorIcon' href='javascrip:'>编辑</a>"
                _this.append(editorIcon);
                //编辑事件
                editorIconEvent(editorModelTitle,editorModelId);
            },
            function () {
                $(".editorIcon").remove();
                $(".editorBorder").remove();
            }
        );
    }
}
//工具类编辑表单初始化
function untilEditorEvent(id){
    var e = new common.edit("#"+id,{bucket:"yhb-img02"});
    e.init();
    e.on("callback",function(obj){
        if(/^file_onComplete_shopBannerImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_shopBannerImage_/,'');
            g.__rows[_index].shopSrc = obj.data;
        }
        if(/^file_onComplete_DetailbannerImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_DetailbannerImage_/,'');
            g.__rows[_index].detailSrc = obj.data;
        }
        if(/^file_onComplete_largePicImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_largePicImage_/,'');
            var _indexList = _index.split("_");
            g.__rows[_indexList[0]].data[_indexList[1]].src = obj.data;
        }
        if(/^file_onComplete_smallPicImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_smallPicImage_/,'');
            var _indexList = _index.split("_");
            g.__rows[_indexList[0]].data[_indexList[1]].src = obj.data;
        }
        if(/^file_onComplete_recommendImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_recommendImage_/,'');
            g.__rows[_index].src = obj.data;
        }
        if(/^file_onComplete_signboardImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_signboardImage_/,'');
            g.__rows[_index].src = obj.data;
        }
    });
    $("#"+id+" nav").hide();
    $(".modal-dialog").css("width","900px");
    $(".modal-dialog .modal-body .editor-dialog").css("max-height","650px");
    $(".modal-dialog .modal-body .editor-dialog").css("overflow-y","auto");
    $(".modal-dialog .modal-body .editor-dialog").css("overflow-x","hidden");
}
//资源位图片代码生成器
function resourcesHtmlInit(item,resName){
    var picList = item.data,
        htmlPic = "";
    for(var i=0; i<picList.length; i++){
        htmlPic += "<div class='row'>" +
        "<div class='col-sm-2'><input type=file name='"+ resName +"Image' id='"+ resName +"Image_"+item.__index+"_"+i+"' value='"+picList[i].src+"' /></div>" +
        "<div class='col-sm-3'><input type=text class='form-control inputChange' name='url' value='"+ picList[i].url +"' data-index='"+ item.__index +"_"+ i +"' /></div>" +
        "<div class='col-sm-2'>" +
        "<input type=text class='form-control inputChange' readOnly='true' jsaction='time:end:endTime_"+item.__index+"_"+ i +"' id='startTime_"+item.__index+"_"+ i +"' name='startTime' value='"+ picList[i].startTime +"' data-index='"+ item.__index +"_"+ i +"' /></div>" +
        "<div class='col-sm-2'>" +
        "<input type=text class='form-control inputChange' readOnly='true' jsaction='time:start:startTime_"+item.__index+"_"+ i +"' id='endTime_"+item.__index+"_"+ i +"' name='endTime' value='"+ picList[i].endTime +"' data-index='"+ item.__index +"_"+ i +"' /></div>" +
        "<div class='col-sm-1'><span style='white-space: nowrap;'>"+ (picList[i].publishStatus==0?"未发布":"已发布") +"</span></div>" +
        "<div class='col-sm-2'>";
        if(i == (picList.length-1) && picList.length > 1){
            htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+ item.__index +"_"+ i +"' /><br>";
            htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+ item.__index +"_"+ i +"' />";
        }
        if(i < (picList.length-1) && picList.length > 1){
            htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+ item.__index +"_"+ i +"' />";
        }
        if(i == (picList.length-1) && picList.length == 1){
            htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+ item.__index +"_"+ i +"' />";
        }
        htmlPic += "</div></div>";
    }
    return htmlPic;
}
//top20商品根据以展示商品自动勾选
function productTopDataLink(productList){
    $(".top20List li").removeClass("selected");
    for(var i=0; i<productList.length; i++){
        var productId = productList[i].productId;
        $(".top20List").find("li[data-productId = "+ productId +"]").addClass("selected");
    }
    $(".topTip span").text("已经勾选"+ g.__rows.length +"件,最多勾选8件商品!");
}
//json数组排序, dis参数:0:从小到大,1:从大到小
function sortJson(arr,dir){
    var len = arr.length, tmp;
    for(var i=0; i < len-1; i++){
        if(dir == 0){
            for(var j=0; j < len-1-i; j++){
                if(parseInt(arr[j].position) > parseInt(arr[j+1].position)){
                    tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
        if(dir == 1){
            for(var j=0; j < len-1-i; j++){
                if(parseInt(arr[j].position) < parseInt(arr[j+1].position)){
                    tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }

    }
    return arr;
}
//数组克隆
function cloneArr(arr1,arr2){
    arr2.length = 0;
    for(var i=0; i<arr1.length; i++){
        arr2.push($.extend(true,{},arr1[i]));
    }
    return arr2;
}

/********************事件绑定*********************/

//pc跟app的tab选项事件
$(document).on("click",".tabheader .nav-tabs li",function(){
    $(this).addClass('active').siblings('li').removeClass('active');
    curPlatform = $(this).attr("data-toggle");
    if(curPlatform == "shopWeb-app"){
        $(".moduleTypeView").hide();
    }else{
        $(".moduleTypeView").show();
    }
    showMain();
})
//基础模板,经典模板切换
$(document).on("click","input[name=brandLevel]",function(){
    curTemplateType = $("input[name=brandLevel]:checked").val();
    showMain();
})
//选择使用模板
$(document).on("change","#templateSelect",function(){
    jsonMain.templateName = $(this).val();
})
//暂存模板
$(document).on("click","#saveModule",function(){
    if(jsonMain.templateName == "0"){
        common.util.__tip("请选择展示使用模板!");
        return;
    }
    saveDecoration(100);
})
//提交审核
$(document).on("click","#submitModule",function(){
    if(jsonMain.templateName == "0"){
        common.util.__tip("请选择展示使用模板!");
        return;
    }
    saveDecoration(200);
})
//审核通过
$(document).on("click","#checkOk",function(){
    common.dialog.confirm(
        "审核确认",
        "你确认<strong style='color:#5cb85c'>审核通过</strong>么?",
        function(){
            checkDecoration(300);
        },
        function(){}
    );
})
//驳回
$(document).on("click","#checkNo",function(){
    common.dialog.confirm(
        "审核驳回",
        "你确认<strong style='color:#d9534f'>审核驳回</strong>么?如果确认,<strong style='color: #f0ad4e'>请填写驳回理由!</strong>" +
        "<textarea id='checkComment' class='form-control' rows='3' style='margin: 10px 0'></textarea>" +
        "<div class='editorTip' style='display: none'><span>提示:请填写驳回理由!</span></div>",
        function(){
            var comment = $("#checkComment").val();
            if(comment){
                checkDecoration(900,comment);
            }else{
                $(".editorTip").show();
                return false;
            }
        },
        function(){}
    );
})
//删除
$(document).on("click",".deleteBtn",function(){
    var _index = $(this).data("index")+"";
    var indexList = _index.split("_");

    if(indexList.length > 1){
        [].splice.call(g.__rows[indexList[0]].data,indexList[1],1);
    }else{
        [].splice.call(g.__rows,indexList[0],1);
    }
    g.init(g.__rows);
    untilEditorEvent(curDialogId);

    if(curDialogId == "editor-newProduct" || curDialogId == "editor-hotProduct"){
        productTopDataLink(g.__rows);
    }
});
//添加一条
$(document).on("click",".addBtn",function(){
    var _index = $(this).data("index")+"";
    var indexList = _index.split("_");

    if(indexList.length > 1){
        g.__rows[indexList[0]].data.push($.extend({},ENUM[curDialogId]));
    }else{
        g.__rows.push($.extend({},ENUM[curDialogId]));
    }
    g.init(g.__rows);
    untilEditorEvent(curDialogId);
});
//input change同时更新json
$(document).on("change",".inputChange",function(){
    var _index = $(this).attr("data-index");
    var indexList = _index.split("_");
    var _name = $(this).attr("name");

    if(indexList.length > 1){
        (g.__rows[indexList[0]].data)[indexList[1]][_name] = $(this).val();
    }else{
        g.__rows[indexList[0]][_name] = $(this).val();
    }
    $(this).removeClass("error");
});
//checkBox change同时更新json
$(document).on("change",".checkBoxChange",function(){
    var _index = $(this).attr("data-index");
    var _name = $(this).attr("name");
    if($(this).is(':checked')){
        g.__rows[_index][_name] = "Y";
    }else{
        g.__rows[_index][_name] = "N";
    }
});
//选择Top20
$(document).on("click",".topAdd",function(){
    if(g.__rows.length < 8){
        if(!$(this).hasClass("selected")){
            $(this).addClass("selected");
            var item = $.extend({},ENUM[curDialogId]);
            item.src = $(this).find('img').attr("src");
            item.productId = $(this).attr("data-productId");
            item.productName = $(this).attr("data-productName");
            item.productPrice = $(this).attr("data-productPrice");

            g.__rows.push(item);
            g.init(g.__rows);
            untilEditorEvent(curDialogId);

            $(".topTip span").text("已经勾选"+ g.__rows.length +"件,最多勾选8件商品!");
        }
    }else{
        $(".topTip span").text("商品数量已满8个,无法继续添加商品!");
    }
});