shop.js 58.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
//店铺装修
'use strict';
var $ = require('jquery'),
    common=require('../common/common');

var g;  //grid
var curDialogId;  //当前打开的编辑弹层ID
var currentModuleName;   //当前渲染页面用的模板ID
var curModuleTypy = "2";  //当前模板类型 m1:基础模板,m2:经典模板
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 jsonMain, jsonClone;

var jsonMain2 = {
    "shopsId":35,
    "platform": "APP",
    "templateName": "typical",
    "resources":{
        //店铺页面顶部banner
        "shopTopBanner":{
            "id":7,
            "data":
                [{
                    "shopsName":"阿迪达斯专卖店",
                    "shopSrc": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                    "detailSrc": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                    "isShowShopName": "Y"
                }]
        },
        //导航栏
        "navigationBar":{
            "id":81,
            "data":
                [
                    {"name":"1235",url:"dadasdad"},
                    {"name":"数据了",url:"dasda"},
                    {"name":"大健康",url:"gsdfdg"}
                ]
        },
        //资源位大图
        "largeSlideImg":{
            "id":9,
            "data": [
                {
                    "position": 1,
                    "data":[
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        },
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        },
                    ]
                },
                {
                    "position": 2,
                    "data":[
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        }
                    ]
                },
                {
                    "position": 3,
                    "data":[
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        },
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        }
                    ]
                },

            ]
        },
        //资源位小图
        "oneRowTwoColImages":{
            "id":9,
            "data": [
                {
                    "position": 1,
                    "data":[
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        }
                    ]
                },
                {
                    "position": 2,
                    "data":[
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        },
                        {
                            "src": "http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                            "url": "",
                            "startTime": "",
                            "endTime": "",
                            "publishStatus": 0
                        }
                    ]
                }
            ]
        },
        //品牌一览
        "brandBrowse":{
            "id":81,
            "data":
                [
                    {"position":1, "name":"VANQUISH", "src":"http://d.3987.com/kamcbz_130508/001.jpg", "url":""},
                    {"position":2, "name":"VISIBLE", "src":"", "url":""},
                    {"position":3, "name":"BLACKJACK", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                    {"position":4, "name":"HBA", "src":"", "url":""},
                    {"position":5, "name":"SANGELO", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""}
                ]
        },
        //经典推荐
        "recommend":{
            "id":81,
            "title":"经典推荐",
            "data":
                [
                    {"position":1, "name":"A", "enName":"addidas", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":"","isShowInApp":"Y"},
                    {"position":2, "name":"B", "enName":"nike", "src":"", "url":"","isShowInApp":"N"},
                    {"position":3, "name":"C", "enName":"", "src":"", "url":"","isShowInApp":"Y"},
                    {"position":4, "name":"D", "enName":"", "src":"", "url":"","isShowInApp":"N"},
                    {"position":5, "name":"E", "enName":"nike", "src":"", "url":"","isShowInApp":"Y"},
                    {"position":6, "name":"F", "enName":"", "src":"", "url":"","isShowInApp":"N"},
                ]
        },
        //热销推荐
        "hotRecommend":{
            "id":81,
            "title":"热销推荐",
            "data":
                [
                    {"position":1, "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                    {"position":2, "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                    {"position":3, "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""}
                ]
        },
        //水牌
        "signboard":{
            "id":81,
            "data":
                [
                    {
                        "position":1,
                        "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png",
                        "url":"",
                        "startTime": "",
                        "endTime": "",
                        "publishStatus": 0
                    },
                    {
                        "position":2,
                        "src":"",
                        "url":"",
                        "startTime": "",
                        "endTime": "",
                        "publishStatus": 1
                    },
                ]
        },
        //商品标签栏
        "goodsTabBar":{
            "id":81,
            "data": {
                "new":[
                    {"position":0, "name":"MORE", "url":""},
                    {"position":1, "name":"衣服", "url":""},
                    {"position":2, "name":"运动鞋", "url":""}
                ],
                "hot":[
                    {"position":0, "name":"MORE", "url":""},
                    {"position":1, "name":"休闲裤", "url":""},
                    {"position":2, "name":"帽子", "url":""}
                ]
            }
        },
        //新品上架
        "newProducts":{
            "id":9,
            "data": [
                {"productId":"A0", "position":1, "productName":"商品名称1", "productPrice":"100", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B", "position":2, "productName":"商品名称2", "productPrice":"200", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"C1", "position":3, "productName":"商品名称3", "productPrice":"1200", "src":"http://cdnweb.b5m.com/web/cmsphp/article/201403/f45e5eb4d576736b0cf2bb6459603ed3.jpg", "url":""},
                {"productId":"D1", "position":4, "productName":"商品名称4", "productPrice":"1600", "src":"http://cdnweb.b5m.com/web/cmsphp/article/201404/1fe993095bb81902068ff17ece1277db.jpg", "url":""},
            ]
        },
        //热销商品
        "hotProducts":{
            "id":9,
            "data": [
                {"productId":"A", "position":1, "productName":"商品名称1", "productPrice":"100", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B", "position":2, "productName":"商品名称2", "productPrice":"200", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"A2", "position":3, "productName":"商品名称3", "productPrice":"300", "src":"http://d.3987.com/kamcbz_130508/001.jpg", "url":""},
                {"productId":"A3", "position":4, "productName":"商品名称4", "productPrice":"400", "src":"http://img4.duitang.com/uploads/item/201309/23/20130923002030_cmQus.thumb.600_0.jpeg", "url":""},
            ]
        },
        //热销前20
        "topProducts":{
            "id":9,
            "data": [
                {"productId":"A", "productName":"商品名称1", "productPrice":"100", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"A1", "productName":"商品名称2", "productPrice":"200", "src":"http://f.hiphotos.baidu.com/lvpics/w=1000/sign=4d69c022ea24b899de3c7d385e361c95/f31fbe096b63f6240e31d3218444ebf81a4ca3a0.jpg", "url":""},
                {"productId":"A2", "productName":"商品名称3", "productPrice":"300", "src":"http://d.3987.com/kamcbz_130508/001.jpg", "url":""},
                {"productId":"A3", "productName":"商品名称4", "productPrice":"400", "src":"http://img4.duitang.com/uploads/item/201309/23/20130923002030_cmQus.thumb.600_0.jpeg", "url":""},
                {"productId":"A4", "productName":"商品名称5", "productPrice":"500", "src":"http://cdnq.duitang.com/uploads/item/201503/31/20150331135538_hYJKQ.jpeg", "url":""},
                {"productId":"B0", "productName":"商品名称6", "productPrice":"600", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B1", "productName":"商品名称7", "productPrice":"700", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B2", "productName":"商品名称8", "productPrice":"800", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B3", "productName":"商品名称9", "productPrice":"900", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B4", "productName":"商品名称10", "productPrice":"1000", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B5", "productName":"商品名称11", "productPrice":"1100", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"C1", "productName":"商品名称12", "productPrice":"1200", "src":"http://cdnweb.b5m.com/web/cmsphp/article/201403/f45e5eb4d576736b0cf2bb6459603ed3.jpg", "url":""},
                {"productId":"C2", "productName":"商品名称13", "productPrice":"1300", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"C3", "productName":"商品名称14", "productPrice":"1400", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"C4", "productName":"商品名称15", "productPrice":"1500", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D1", "productName":"商品名称16", "productPrice":"1600", "src":"http://cdnweb.b5m.com/web/cmsphp/article/201404/1fe993095bb81902068ff17ece1277db.jpg", "url":""},
                {"productId":"D2", "productName":"商品名称17", "productPrice":"1700", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D3", "productName":"商品名称18", "productPrice":"1800", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D4", "productName":"商品名称19", "productPrice":"1900", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D5", "productName":"商品名称20", "productPrice":"2000", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""}
            ]
        }
    }
}
var resourcesNew = {
    "shopsId":0,
    "platform": "APP",
    "templateName": "typical",
    "resources":{
        "shopTopBanner":{
            "id":7,
            "data": [{"shopsName":"", "shopSrc": "", "detailSrc": "", "isShowShopName": "Y"}]
        },
        "navigationBar":{
            "id":81,
            "data": [{"name":"",url:""}, {"name":"",url:""}, {"name":"",url:""}]
        },
        "largeSlideImg":{
            "id":9,
            "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":9,
            "data": [
                {"position": 2, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
                {"position": 1, "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
            ]
        },
        "brandBrowse":{
            "id":81,
            "data": [{"position":1, "name":"", "src":"", "url":""}]
        },
        "recommend":{
            "id":81,
            "data": [{"position":1, "name":"", "enName":"", "src":"", "url":"","isShowInApp":"Y"},]
        },
        "hotRecommend":{
            "id":81,
            "data": [{"position":1, "src":"", "url":""},]
        },
        "signboard":{
            "id":81,
            "data": [{"position":1, "src":"", "url":"", "startTime": "", "endTime": "", "publishStatus": 0}]
        },
        "goodsTabBar":{
            "id":81,
            "data": {
                "new":[{"position":0, "name":"MORE", "url":""},],
                "hot":[{"position":0, "name":"MORE", "url":""},]
            }
        },
        "newProducts":{
            "id":9,
            "data": [{"productId":"default", "position":1, "productName":"默认商品", "productPrice":"默认价格", "src":"", "url":""},]
        },
        "hotProducts":{
            "id":9,
            "data": [{"productId":"default", "position":1, "productName":"默认商品", "productPrice":"默认价格", "src":"", "url":""},]
        },
        "topProducts":{
            "id":9,
            "data": [
                {"productId":"A", "productName":"商品名称1", "productPrice":"100", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"A1", "productName":"商品名称2", "productPrice":"200", "src":"http://f.hiphotos.baidu.com/lvpics/w=1000/sign=4d69c022ea24b899de3c7d385e361c95/f31fbe096b63f6240e31d3218444ebf81a4ca3a0.jpg", "url":""},
                {"productId":"A2", "productName":"商品名称3", "productPrice":"300", "src":"http://d.3987.com/kamcbz_130508/001.jpg", "url":""},
                {"productId":"A3", "productName":"商品名称4", "productPrice":"400", "src":"http://img4.duitang.com/uploads/item/201309/23/20130923002030_cmQus.thumb.600_0.jpeg", "url":""},
                {"productId":"A4", "productName":"商品名称5", "productPrice":"500", "src":"http://cdnq.duitang.com/uploads/item/201503/31/20150331135538_hYJKQ.jpeg", "url":""},
                {"productId":"B0", "productName":"商品名称6", "productPrice":"600", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B1", "productName":"商品名称7", "productPrice":"700", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B2", "productName":"商品名称8", "productPrice":"800", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B3", "productName":"商品名称9", "productPrice":"900", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B4", "productName":"商品名称10", "productPrice":"1000", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"B5", "productName":"商品名称11", "productPrice":"1100", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"C1", "productName":"商品名称12", "productPrice":"1200", "src":"http://cdnweb.b5m.com/web/cmsphp/article/201403/f45e5eb4d576736b0cf2bb6459603ed3.jpg", "url":""},
                {"productId":"C2", "productName":"商品名称13", "productPrice":"1300", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"C3", "productName":"商品名称14", "productPrice":"1400", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"C4", "productName":"商品名称15", "productPrice":"1500", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D1", "productName":"商品名称16", "productPrice":"1600", "src":"http://cdnweb.b5m.com/web/cmsphp/article/201404/1fe993095bb81902068ff17ece1277db.jpg", "url":""},
                {"productId":"D2", "productName":"商品名称17", "productPrice":"1700", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D3", "productName":"商品名称18", "productPrice":"1800", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D4", "productName":"商品名称19", "productPrice":"1900", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""},
                {"productId":"D5", "productName":"商品名称20", "productPrice":"2000", "src":"http://img10.static.yhbimg.com/taobaocms/2016/01/25/12/0155598441256e46ec285a8ea64e762394.png", "url":""}
            ]
        }
    }
}

function reload(id,shopId){
    common.util.__ajax(
        {
            url:'/store/shop-decoration-find',
            data: {
                "id": id,
                "platform": "PC",
                "templateName": "typical"
            }
        },
        function(rs) {
            if(rs.data){
                jsonMain = rs.data;
            }else{
                jsonMain = $.extend(true,{},resourcesNew);
                jsonMain.shopsId = shopId;
            }
            jsonClone = $.extend(true,{},jsonMain);
            $('.tabheader .nav-tabs li:first-of-type').click();
        }
    );
}

reload(23,21);
//jsonMain = jsonMain2;

jsonClone = $.extend(true,{},jsonMain);

$(document).on("click","#saveModule",function(){
    saveDecoration(jsonMain);
})

/*保存模板*/
function saveDecoration(json){
    common.util.__ajax({
        url:'/store/shop-decoration-save',
        data: {
            "shopsId": json.shopsId,
            "platform": json.platform,
            "templateName": json.templateName,
            "resources": JSON.stringify(json.resources)
        }
    },function(rs){});
}

/*pc跟app的tab选项事件*/
$('.tabheader .nav-tabs li').on('click',function(){
    $(this).addClass('active').siblings('li').removeClass('active');
    currentModuleName = $(this).attr("data-toggle");
    if(currentModuleName == "shopWeb-app"){
        $(".moduleTypeSelect").hide();
    }else{
        $(".moduleTypeSelect").show();
    }
    showMain(currentModuleName,jsonMain,curModuleTypy);
});

/*模板类型切换*/
$("input[name=brandLevel]").click(function(){
    curModuleTypy = $("input[name=brandLevel]:checked").val();
    showMain(currentModuleName,jsonMain,curModuleTypy);
});

/*json渲染模板*/
function showMain(moduleName,json,moduleType){
    if(currentModuleName == "shopWeb-pc"){
        $('#main').empty().html(common.util.__template2($("#"+moduleName+"-"+moduleType).html(),json));
    } else if(currentModuleName == "shopWeb-app"){
        $('#main').empty().html(common.util.__template2($("#"+moduleName).html(),json));
    }
    /*
    if(moduleType == "multi"){
        $(".model-brand").show();
    }else if(moduleType == "single"){
        $(".model-brand").hide();
    }*/
    showEditorIconEvent();
}

/*编辑动画事件*/
function showEditorIconEvent(){
    $(".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){
        //console.log(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 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(!(curDialogId == "editor-largePic-app" || curDialogId == "editor-recommend-app" || curDialogId == "editor-brand-app")){
                    freshJson(id, g.__rows, 1);
                }
                showMain(currentModuleName,jsonMain,curModuleTypy);
            },
            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);
    })
}

/*删除*/
$(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保存*/
$(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();
    }
});
/*选择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个,无法继续添加商品!");
    }
});

/*弹层表单grid生成器*/
function gridInit(id){
    switch (id){
        //店铺顶部banner
        case "editor-banner":
            g = new common.grid({
                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({
                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({
                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({
                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({
                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:"名称", render:function(item){
                        return "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' data-index='"+item.__index+"' />";
                    }},
                    {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 html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                        if(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.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({
                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:"名称", render:function(item){
                        return "<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+"' />";
                    }},
                    {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' type=checkBox name='isShowInApp' value='"+item.isShowInApp+"' checked />";
                        }else{
                            return "<input class='form-control' type=checkBox name='isShowInApp' value='"+item.isShowInApp+"' />";
                        }
                    }},
                    {display:"操作", render:function(item){
                        var html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                        if(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.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({
                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:"图片", 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 html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                        if(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.hotRecommend.data;
            g.init(g.__rows);
            break;

        //水牌signboard
        case "editor-signboard":
            g = new common.grid({
                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:"图片", 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='date: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='date: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 html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
                        if(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.signboard.data;
            g.init(g.__rows);
            break;

        //新品上架标签tab
        case "editor-newGoodTab":
            g = new common.grid({
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        if(item.__index == 0){
                            return item.position;
                        }else{
                            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' style='margin-top: 10px' 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 && 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({
                el:"#"+id,
                columns:[
                    {display:"排序", render:function(item){
                        if(item.__index == 0){
                            return item.position;
                        }else{
                            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' style='margin-top: 10px' 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 && 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> ");
            $("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),jsonClone));

            g = new common.grid({
                el:"#editor-newProduct-grid",
                columns:[
                    {display:"排序", render:function(item){
                        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> ");
            $("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),jsonClone));

            g = new common.grid({
                el:"#editor-hotProduct-grid",
                columns:[
                    {display:"排序", render:function(item){
                        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),jsonMain.resources.largeSlideImg.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.largeSlideImg.data,data);
            }
            break;

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

        case "editor-brand":
            if(status == 1){
                cloneArr(sortJson(data),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),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),jsonMain.resources.hotRecommend.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.hotRecommend.data,data);
            }
            break;

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

        case "editor-newGoodTab":
            if(status == 1){
                cloneArr(sortJson(data),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),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),jsonMain.resources.newProducts.data);
            }else if(status == 0){
                cloneArr(jsonMain.resources.newProducts.data,data);
            }
            break;

        case "editor-hotProduct":
            if(status == 1){
                cloneArr(sortJson(data),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(currentModuleName == "shopWeb-pc"){
                tipHtml = "<span>提示:请上传像素1150*150的图片。</span>";
            }
            if(currentModuleName == "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个汉字。</span>";
            break;
        case "editor-hotGoodTab":
            tipHtml = "<span>提示:标题名称最多5个汉字。</span>";
            break;
        default :
            break;
    }
    $(".editorTip").html(tipHtml);
}

/*资源位图片代码生成器*/
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='date: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='date: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数组排序*/
function sortJson(arr){
    var len = arr.length, tmp;
    for(var i=0; i < len-1; i++){
        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;
}