shop.js 64.7 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 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
//店铺装修
'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 defaultSrc = "http://img01.yohoboys.com/staticimg/2016/05/19/15/01091c21f2317a64f123f1649fbbccf7ba.png"; //初始化默认图片路径
var ENUM = {
    "editor-largePic":{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0},
    "editor-largePic2":{"position":"", "data":[{"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":"", "productSkn":"", "salesPrice":"", "src":"", "url":""},
    "editor-hotProduct":{"productId":"", "position":"", "productName":"", "productSkn":"", "salesPrice":"", "src":"", "url":""}
};  //添加一条不同弹层使用的初始化模板
var resourcesNew = {
    "shopTopBanner":{
        "id":"",
        "data": [{"shopSrc": defaultSrc, "detailSrc": defaultSrc, "isShowShopName": "N"}]
    },
    "navigationBar":{
        "id":"",
        "data": [{"name":"",url:""}, {"name":"",url:""}, {"name":"",url:""}]
    },
    "largeSlideImg":{
        "id":"",
        "data": [{"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}]
    },
    "oneRowTwoColImages":{
        "id":"",
        "data": [
            {"position": 2, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]},
            {"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}
        ]
    },
    "brandBrowse":{
        "id":"",
        "data": []
    },
    "recommend":{
        "id":"",
        "title":"经典推荐",
        "data": [{"position":1, "name":"默认商品", "enName":"", "src":defaultSrc, "url":"","isShowInApp":"Y"}]
    },
    "hotRecommend":{
        "id":"",
        "title":"",
        "data": [{"position":1, "src":defaultSrc, "url":""}]
    },
    "signboard":{
        "id":"",
        "data": [{"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}]
    },
    "goodsTabBar":{
        "id":"",
        "data": {
            "new":[{"position":0, "name":"MORE", "url":""}],
            "hot":[{"position":0, "name":"MORE", "url":""}]
        }
    },
    "newProducts":{
        "id":"",
        "data": []
    },
    "hotProducts":{
        "id":"",
        "data": []
    },
    "allNewProducts":{
        "id":"",
        "data":[]
    },
    "allHotProducts":{
        "id":"",
        "data":[]
    },
    "shopTopBanner_APP":{
        "id":"",
        "isUsed":"N",
        "data": [{"shopSrc": defaultSrc, "detailSrc": defaultSrc, "isShowShopName": "N"}]
    },
    "oneRowTwoColImages_APP":{
        "id":"",
        "isUsed":"N",
        "data": [
            {"position": 2, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]},
            {"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}
        ]
    },
    "hotProducts_APP":{
        "id":"",
        "isUsed":"N",
        "data": []
    },
    "allHotProducts_APP":{
        "id":"",
        "data":[]
    }
}  //初始化装修信息json
var shopsId, _id, jsonMain, jsonClone;

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(jsonMain.templateType);
    $("input[name='brandLevel'][value='"+curTemplateType+"']").attr('checked',"checked");

    if(curPlatform == "shopWeb-pc"){
        //console.log(jsonMain);
        $('#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();
    }
    //标签长度样式自适应
    $.each($(".contentpanel-pc .model-showTitle .showTab"),function(){
        if($(this).width() > 280){
            $(this).css("right",(280-($(this).width()))+"px");
        }
    })
    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:'/shop/ShopsDecoratorRest/findShopsDecoratorDetail',
            data: {
                "shopsId": shopsId
            }
        },
        function(rs) {
            console.log(rs.data);
            if(rs.data){
                jsonMain = rs.data;
            }
            //没有装修信息,初始化装修信息
            if($.isEmptyObject(jsonMain.resources)){
                jsonMain.resources = $.extend(true,{},resourcesNew);
            }
            //装修信息中品牌内容为空,初始化品牌
            if(jsonMain.brandList){
                if(jsonMain.resources.brandBrowse.data.length < 1){
                    cloneArr(jsonMain.brandList,jsonMain.resources.brandBrowse.data);
                }
            }else{
                common.util.__tip("店铺没有品牌,无法装修,请返回添加品牌!");
                return;
            }
            if(jsonMain.templateType && jsonMain.templateType != "0"){
                curTemplateType = jsonMain.templateType;
            }
            //装修json克隆
            jsonClone = $.extend(true,{},jsonMain);

            //最新上架,最热商品接口
            if(shopOperate == 'editor'){
                if(!jsonMain.resources.allNewProducts.data || jsonMain.resources.allNewProducts.data.length < 1){
                    findTopNewProducts();
                }
                if(!jsonMain.resources.allHotProducts.data || jsonMain.resources.allHotProducts.data.length < 1){
                    findTopHotProducts();
                }
                if(!jsonMain.resources.allHotProducts_APP.data || jsonMain.resources.allHotProducts_APP.data.length < 1){
                    findTopHotProducts_APP();
                }
                /*
                 findTopNewProducts();
                 findTopHotProducts();
                 findTopHotProducts_APP();
                 */
            }
            showMain();
        },true);
}
//Ajax最新上架商品
function findTopNewProducts(){
    common.util.__ajax({
        url:'/shop/ShopsDecoratorRest/findNewProductList',
        data: {
            "shopsId": jsonMain.shopsId,
            "size": 20
        }
    },function(rs){
        if(rs.data.product_list){
            jsonMain.resources.allNewProducts.data = rs.data.product_list;
        }
    },true);
}
//Ajax热销商品
function findTopHotProducts(){
    common.util.__ajax({
        url:'/shop/ShopsDecoratorRest/findHotProductList',
        data: {
            "shopsId": jsonMain.shopsId,
            "size": 20
        }
    },function(rs){
        if(rs.data.product_list){
            jsonMain.resources.allHotProducts.data = rs.data.product_list;
        }
    },true);
}
//Ajax热销商品---APP
function findTopHotProducts_APP(){
    common.util.__ajax({
        url:'/shop/ShopsDecoratorRest/findHotProductList',
        data: {
            "shopsId": jsonMain.shopsId,
            "size": 20
        }
    },function(rs){
        if(rs.data.product_list){
            jsonMain.resources.allHotProducts_APP.data = rs.data.product_list;
        }
    },true);
}
//Ajax保存,暂存:100,提交审核:200
function saveDecoration(submitStatus){
    console.log(jsonMain);
    common.util.__ajax({
        url:'/shop/ShopsDecoratorRest/saveShopsDecorator',
        data: {
            "submitStatus": submitStatus,
            "shopsId": jsonMain.shopsId,
            "platform": jsonMain.platform,
            "templateType": jsonMain.templateType,
            "resources": JSON.stringify(jsonMain.resources)
        }
    },function(rs){
        if(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:'/shop/ShopsDecoratorRest/auditShopsDecorator',
            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:'/shop/ShopsDecoratorRest/auditShopsDecorator',
            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":
            if(curPlatform == "shopWeb-pc"){
                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;
            }
            if(curPlatform == "shopWeb-app"){
                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>";
                            }
                        }}
                    ]
                });
                g.__rows=""||jsonClone.resources.shopTopBanner_APP.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":
            $('.editorTitle').html("<a href='javascript:' class='btn btn-success addBtn2' style='margin-right: 20px'><i class='fa fa-plus'></i> 添加资源大图</a><span class='largePicAddTip'></span>").css("margin-bottom","10px");
            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:"<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");
                        }
                    },
                    {display:"操作", render:function(item){
                        if(g.__rows.length > 1){
                            return "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
                        }
                    }}
                ]
            });
            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");
                        }
                    }
                ]
            });
            if(curPlatform == "shopWeb-pc"){
                g.__rows=""||jsonClone.resources.oneRowTwoColImages.data;
            }
            if(curPlatform == "shopWeb-app"){
                g.__rows=""||jsonClone.resources.oneRowTwoColImages_APP.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='hotRecommendImage_"+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":
            $('.editorTitle').html("<a href='javascript:' class='btn btn-success addBtn2' style='margin-right: 20px'><i class='fa fa-plus'></i> 添加水牌</a><span class='largePicAddTip'></span>").css("margin-bottom","10px");
            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:"<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,"signboard");
                        }
                    },
                    {display:"操作", render:function(item){
                        if(g.__rows.length > 1){
                            return "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
                        }
                    }}
                ]
            });
            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> ");
            //左侧已选商品
            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);
            //右侧热销排名前20商品
            if(jsonMain.resources.allNewProducts.data && jsonMain.resources.allNewProducts.data.length > 0){
                $("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),jsonMain.resources.allNewProducts));
                productTopDataLink(g.__rows);
            }else{
                $("#"+id+" .top20List").html("<font color='red'>*&nbsp;&nbsp;最新上架20条加载失败,请重新加载页面!</font>");
            }
            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> ");
            //左侧已选商品
            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;
                    }}
                ]
            });
            if(curPlatform == "shopWeb-pc"){
                g.__rows=""||jsonClone.resources.hotProducts.data;
                //右侧热销排名前20商品
                if(jsonMain.resources.allHotProducts.data && jsonMain.resources.allHotProducts.data.length > 0){
                    $("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),jsonMain.resources.allHotProducts));
                    productTopDataLink(g.__rows);
                }else{
                    $("#"+id+" .top20List").html("<font color='red'>*&nbsp;&nbsp;最新上架20条加载失败,请重新加载页面!</font>");
                }
            }
            if(curPlatform == "shopWeb-app"){
                g.__rows=""||jsonClone.resources.hotProducts_APP.data;
                //右侧热销排名前20商品
                if(jsonMain.resources.allHotProducts_APP.data && jsonMain.resources.allHotProducts_APP.data.length > 0){
                    $("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),jsonMain.resources.allHotProducts_APP));
                    productTopDataLink(g.__rows);
                }else{
                    $("#"+id+" .top20List").html("<font color='red'>*&nbsp;&nbsp;最新上架20条加载失败,请重新加载页面!</font>");
                }
            }
            g.init(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();
                if(curPlatform == "shopWeb-app"){
                    jsonMain.resources.shopTopBanner_APP.isUsed = "Y";  //  用于提交审核时候校验app端是否维护店招
                    cloneArr(data,jsonMain.resources.shopTopBanner_APP.data);
                }
                if(curPlatform == "shopWeb-pc"){
                    cloneArr(data,jsonMain.resources.shopTopBanner.data);
                    /*  app端与pc端单独配置,不取pc端的大图了
                     if(jsonMain.resources.shopTopBanner_APP.isUsed == "N"){
                     cloneArr(data,jsonMain.resources.shopTopBanner_APP.data);
                     cloneArr(data,jsonClone.resources.shopTopBanner_APP.data);
                     }
                     */
                }
            }else if(status == 0){
                if(curPlatform == "shopWeb-app"){
                    cloneArr(jsonMain.resources.shopTopBanner_APP.data,data);
                }
                if(curPlatform == "shopWeb-pc"){
                    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){
                if(curPlatform == "shopWeb-app"){
                    jsonMain.resources.oneRowTwoColImages_APP.isUsed = "Y";
                    cloneArr(sortJson(data,1),jsonMain.resources.oneRowTwoColImages_APP.data);
                }
                if(curPlatform == "shopWeb-pc"){
                    cloneArr(sortJson(data,1),jsonMain.resources.oneRowTwoColImages.data);
                    if(jsonMain.resources.oneRowTwoColImages_APP.isUsed == "N"){
                        cloneArr(sortJson(data,1),jsonMain.resources.oneRowTwoColImages_APP.data);
                        cloneArr(sortJson(data,1),jsonClone.resources.oneRowTwoColImages_APP.data);
                    }
                }
            }else if(status == 0){
                if(curPlatform == "shopWeb-app"){
                    cloneArr(jsonMain.resources.oneRowTwoColImages_APP.data,data);
                }
                if(curPlatform == "shopWeb-pc"){
                    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){
                if(curPlatform == "shopWeb-app"){
                    jsonMain.resources.hotProducts_APP.isUsed = "Y";
                    cloneArr(sortJson(data,1),jsonMain.resources.hotProducts_APP.data);
                }
                if(curPlatform == "shopWeb-pc"){
                    cloneArr(sortJson(data,1),jsonMain.resources.hotProducts.data);
                    if(jsonMain.resources.hotProducts_APP.isUsed == "N"){
                        cloneArr(sortJson(data,1),jsonMain.resources.hotProducts_APP.data);
                        cloneArr(sortJson(data,1),jsonClone.resources.hotProducts_APP.data);
                    }
                }
            }else if(status == 0){
                if(curPlatform == "shopWeb-app"){
                    cloneArr(jsonMain.resources.hotProducts_APP.data,data);
                }
                if(curPlatform == "shopWeb-pc"){
                    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的图片,图片大小不能大于500KB。</span>";
            }
            if(curPlatform == "shopWeb-app"){
                tipHtml = "<span>提示:请上传像素640*200的图片,图片大小不能大于500KB。</span>";
            }
            break;
        case "editor-nav":
            tipHtml = "<span>提示:标题名称最多5个汉字。</span>";
            break;
        case "editor-largePic":
            tipHtml = "<span>提示:请上传像素660*358的图片,图片大小不能大于500KB,该图片会适配到APP端。</span>";
            break;
        case "editor-largePic-app":
            tipHtml = "<span>提示:由PC端适配,修改请到PC端修改。</span>";
            break;
        case "editor-smallPic":
            if(curPlatform == "shopWeb-app"){
                tipHtml = "<span>提示:请上传像素275*160的图片,图片大小不能大于500KB。</span>";
            }else{
                tipHtml = "<span>提示:请上传像素300*174的图片,图片大小不能大于500KB。</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>提示:请上传像素150*150的图片,图片大小不能大于500KB,图片和标题会适配到APP的【热门品类】中。</span>";
            break;
        case "editor-recommend-app":
            tipHtml = "<span>提示:【热门品类】由PC端【经典推荐】适配,修改请到PC端【经典推荐】修改。</span>";
            break;
        case "editor-signboard":
            tipHtml = "<span>提示:请上传像素160*240的图片,图片大小不能大于500KB。</span>";
            break;
        case "editor-hotRecommend":
            tipHtml = "<span>提示:请上传像素160*240的图片,图片大小不能大于500KB。</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 = "";
                if(editorModelId == "editor-brand-app" || editorModelId == "editor-largePic-app" || editorModelId == "editor-recommend-app"){
                    editorIcon += "<div class='editorBorder' style='border: 5px solid #ff69b4'></div>"
                }else{
                    editorIcon += "<div class='editorBorder'></div>"
                }
                editorIcon += "<a class='editorIcon' href='javascript:'>编辑</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_hotRecommendImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_hotRecommendImage_/,'');
            g.__rows[_index].src = obj.data;
        }
        if(/^file_onComplete_signboardImage_/.test(obj.key)){
            var _index = obj.key.replace(/^file_onComplete_signboardImage_/,'');
            var _indexList = _index.split("_");
            g.__rows[_indexList[0]].data[_indexList[1]].src = obj.data;
        }
    });
    $("#"+id+" nav").hide();
    $(".modal-dialog").css("width","960px");
    $(".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'>";
        if(i>0){
            htmlPic += "<input type=text class='form-control' disabled jsaction='time:end:endTime_"+item.__index+"_"+ i +"' id='startTime_"+item.__index+"_"+ i +"' name='startTime' value='"+ picList[i].startTime +"' />" +
            "<span style='color: #999; font-size: 12px'>*上一条结束时间</span>";
        }else{
            htmlPic += "<input type=text class='form-control inputChange' style='background-color:#fff' 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 +"' />";
        }
        htmlPic += "</div><div class='col-sm-2'>" +
        "<input type=text class='form-control inputChange' style='background-color:#fff' 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 class='publishStatus' style='white-space: nowrap; line-height: 40px'>"+ checkdate(picList[i].startTime,picList[i].endTime) +"</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("已经勾选"+ productList.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;
}
//时间校验
function checkdate(startDate,endDate){
    if (endDate) {
        var endDateTemp = endDate.split(" ");
        var arrEndDate = endDateTemp[0].split("-");
        var arrEndTime = endDateTemp[1].split(":");
        var allEndDate = new Date(arrEndDate[0], parseInt(arrEndDate[1])-1, arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);
    }
    if(startDate){
        var startDateTemp = startDate.split(" ");
        var arrStartDate = startDateTemp[0].split("-");
        var arrStartTime = startDateTemp[1].split(":");
        var allStartDate = new Date(arrStartDate[0], parseInt(arrStartDate[1])-1, arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
    }
    var nowDate = new Date();

    if(startDate && endDate){
        if(nowDate > allEndDate) {
            return "<b style='color: #ec971f'>已过期</b>";
        }else if(allStartDate > nowDate){
            return "<b style='color: #428bca'>未发布</b>";
        }else{
            return "<b style='color: #5cb85c'>发布中</b>";
        }
    }else if(!startDate && endDate){
        if(nowDate > allEndDate) {
            return "<b style='color: #ec971f'>已过期</b>";
        }else{
            return "<b style='color: #5cb85c'>发布中</b>";
        }
    }else{
        return "<b style='color: #428bca'>未发布</b>";
    }
    return true;
}

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

//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.templateType = $(this).val();
    $(this).removeClass("error");
})
//暂存模板
$(document).on("click","#saveModule",function(){
    saveDecoration(100);
})
//提交审核
$(document).on("click","#submitModule",function(){
    if(jsonMain.resources.shopTopBanner.data[0].shopSrc == defaultSrc){
        common.util.__tip("PC端没有维护顶部banner!");
        return;
    }
    if(jsonMain.resources.shopTopBanner_APP.isUsed == "N"){
        common.util.__tip("APP端没有维护顶部banner!");
        return;
    }
    if(jsonMain.templateType == "0"){
        common.util.__tip("请选择展示使用模板!");
        $("#templateSelect").focus().addClass("error");
        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]));
        if(curDialogId == "editor-largePic" || curDialogId == "editor-smallPic" || curDialogId == "editor-signboard"){
            (g.__rows[indexList[0]].data)[(parseInt(indexList[1]) + 1)].startTime = (g.__rows[indexList[0]].data)[indexList[1]].endTime;
        }
    }else{
        g.__rows.push($.extend({},ENUM[curDialogId]));
    }
    g.init(g.__rows);
    untilEditorEvent(curDialogId);
});
//资源位大图,水牌添加一条资源位
$(document).on("click",".addBtn2",function(){
    if( curDialogId == "editor-largePic" && g.__rows.length > 4){
        $(".largePicAddTip").text("* 最多只能添加5个资源位大图!").css("color","#ff0000");
        return;
    }else{
        $(".largePicAddTip").empty();
        g.__rows.push($.extend(true,{},ENUM["editor-largePic2"]));
        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();
    }
    if(curDialogId == "editor-largePic" || curDialogId == "editor-smallPic" || curDialogId == "editor-signboard"){
        if($(this).attr("name") == "endTime"){
            if(g.__rows[indexList[0]].data.length - 1 > indexList[1]){
                (g.__rows[indexList[0]].data)[(parseInt(indexList[1]) + 1)].startTime = $(this).val();
                $(this).parents(".row").next().children().find("input[name='startTime']").val($(this).val());

                var endDate = $(this).parents(".row").next().children().find("input[name='endTime']").val();
                $(this).parents(".row").next().children().find(".publishStatus").html(checkdate($(this).val(),endDate));
            }
            var startDate = $(this).parents(".row").find("input[name='startTime']").val();
            $(this).parents(".row").find(".publishStatus").html(checkdate(startDate,$(this).val()));
        }
        if($(this).attr("name") == "startTime"){
            var endDate = $(this).parents(".row").find("input[name='endTime']").val();
            $(this).parents(".row").find(".publishStatus").html(checkdate($(this).val(),endDate));
        }
    }
    $(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($(this).hasClass("selected")){
        $(this).removeClass("selected");
        var cutProductId = $(this).attr("data-productId");
        for(var i=0; i<g.__rows.length; i++){
            if(g.__rows[i].productId == cutProductId){
                [].splice.call(g.__rows,i,1);
                break;
            }
        }
        g.init(g.__rows);
        untilEditorEvent(curDialogId);
        productTopDataLink(g.__rows);
    }else{
        if(g.__rows.length < 8){
            $(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.salesPrice = $(this).attr("data-productPrice");
            item.productSkn = $(this).attr("data-productSkn");
            item.goodsId = $(this).attr("data-goodsId");
            item.cnAlphabet = $(this).attr("data-cnAlphabet");
            g.__rows.push(item);

            g.init(g.__rows);
            untilEditorEvent(curDialogId);
            productTopDataLink(g.__rows);
        }else{
            $(".topTip span").text("商品数量已满8个,无法继续添加商品!");
        }
    }
});