choose-attr-1.0.0.js 81.3 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
function chooseAttr(c, s, s2, r, d, cJson, sJson, s2Json) {
    if (!(this instanceof chooseAttr)) {
        return new chooseAttr(c, s, s2, r, d, cJson, sJson, s2Json);
    }
    var instance;
    chooseAttr = function () {
        return instance;
    };

    chooseAttr.setterS = function (obj) {
        $(document).unbind('click', chooseAttr.setterH);
        $('.attr-setter,.add-bar').not($(obj)).removeClass('on');
        $(obj).addClass('on');
        var _l = $(obj).position().left, _w = $('#g-attrs').width();
        if (_l <= 105) {
            $(obj).find('.add-bar-con').addClass('bl').removeClass('br');
        }
        else if ((_w - _l) < 200) {
            $(obj).find('.add-bar-con').addClass('br');
        }
        setTimeout(function () {
            $(document).bind('click', chooseAttr.setterH);
        });
        return false;
    };

    chooseAttr.setterH = function () {
        $('.attr-setter,.add-bar').removeClass('on').find('.add-bar-con').removeClass('bl br');
        $(document).unbind('click', chooseAttr.setterH);
    };

    chooseAttr.hc = function () {//thead 选择
        var _val =$(this).parents('th').find('input').val(), _td = $(this).parents('th').attr('class');
        if ($(this).attr('ato') == 'toall') {
            $('tbody td.' + _td + ' input:text', $('#result-con')).val(_val).blur();
        }
        else {
            $('tbody td.' + _td + ' input:text', $('#result-con')).each(function () {
                if ((/^\s*$/g).test($(this).val())) {
                    $(this).val(_val).blur();
                }
            });
        }
    };

    chooseAttr.bc = function (attr, obj) {
        var _val = $(obj).parent().parent().attr('fval'),
            _td = $(obj).parents('td').attr('class');
        $('tbody tr[' + attr + '=' + $(obj).parents('tr').attr(attr) + '] td.' + _td + ' input:text', $('#result-con')).val(_val).blur();
    };

    chooseAttr.validate = function (obj) {
        var $this = $(obj),
            type = $this.parent().attr('vali'),// 两种验证
            regs = {
                'float': /^\d+(\.\d+)?$/g,
                'string': /^[\u4e00-\u9fa5a-zA-Z0-9]/g,
                'int': /^\d+$/g
            };
        if ((/^\s*$/g).test($this.val())) {//空
            if ($this.attr('show') == 'on') {
                $this.parent().parent().removeClass('error')
            } else {
                $this.parent().parent().removeClass('error').end().next().addClass('unshow');
            }
        } else {//非空
            if (regs[type].test($this.val())) {//验证通过
                var $curInputParent = $this.parent().parent();
                $curInputParent.removeClass('error').end().next().removeClass('unshow').attr('fval', $this.val());
                if (!$this.parents('thead').length) {//存储修改的值 验证符合规则的数据后才能进行保存数据,否则会出现错误数据
                    var _fc = $this.parents('tr').attr('attrc') ? $this.parents('tr').attr('attrc') : 'none',
                        _fs = $this.parents('tr').attr('attrs') ? $this.parents('tr').attr('attrs') : 'none',
                        _fdate = instance.data.json[_fc + '|' + _fs] || {};
                    instance.data.json[_fc + '|' + _fs] = _fdate;
                    _fdate[$this.parents('td').attr('class')] = $this.val();
                }

                if ($curInputParent.has('font').length > 0) { //隐藏掉错误提示
                    $curInputParent.children("font").remove();
                }
            } else {//验证不通过
                if ($this.attr('show') == 'on') {
                    $this.parent().parent().addClass('error');
                } else {
                    $this.parent().parent().addClass('error').end().next().addClass('unshow');
                }
            }
        }


    };

    //保存原型属性
    chooseAttr.prototype = this;
    instance = new chooseAttr();
    //重置构造函数指针
    instance.constructor = chooseAttr;

    //所有功能
    this.data = {
        "colors": cJson,
        "sizes": sJson,
        "size2s": s2Json,
        "json": d
    };
    this.c = $('#' + c);
    this.s = $('#' + s);
    this.s2 = $('#' + s2);
    this.r = $('#' + r);

    this.addEve('color', c);
    this.addEve('size', s);
    this.addEve('size2', s2);

    this.txtFn();
    return instance;
}

chooseAttr.prototype = {
    txtFn: function () {
        $('thead .a-s-con a', this.r)
            .bind('click', chooseAttr.hc);
        $('thead input:text', this.r).blur();
    },
    addEve: function (type, id) { //添加颜色和尺寸CheckBox选项事件
        var that = this, con = $('#' + id);
        var tempClass = '';
        if (id === 'size-con') {
            tempClass = '.sizeAliasInput';
        } else {
            tempClass = '.colorAliasInput';
        }

        $(document).on('blur', '#' + id + ' ' + tempClass, function () {
            var _id = $(this).parent().find('input:checkbox').attr('id'), _val = $(this).val() || $(this).attr("init");
            if (type === 'color') {
                $("tr[attrc=" + _id + "] td.td-c .s-color").html(_val);
                // 更新图片管理前面的文案
                $("#picID_" + _id).find(".s-color").html(_val);
            } else {
                $("tr[attrs=" + _id + "] td.td-s").html(_val);
            }

            that.userBlur(type, _id);

            $(this).val(_val);
            if (that.checkAttrAlias($(this))) {
                $(this).css({"color": "", "background-color": ""}); //检查通过,恢复正常样式
            }
        });

        $(document).on('change', '#' + id + ' .i-chk', function () {
            if ($(this).prop("checked")) {
                $(this).parent().find('span').hide().end().next('input').attr("disabled", false).show();
                that.add(type, $(this).attr('id'));
            } else {
                $(this).parent().find('span').show().end().next('input').attr("disabled", true).hide();
                that.remove(type, $(this).attr('id'));
            }
        }).filter(':checked').each(function (index) {
            if (type === 'color') { //此处用于过滤用户选中未提交,但刷新页面的问题。
                if (that.data.colors.length) {
                    if ($(this).attr("checked")) {
                        var delColor_ = $(this).attr("id");
                        var temp = false;
                        for (var i = 0, l = that.data.colors.length; i < l; i++) {
                            var c_ = that.data.colors[i];
                            if (c_['id'] == delColor_) {
                                temp = true;
                                break;
                            }
                        }

                        if (!temp) {
                            $(this).attr("checked", false);
                        }
                    }
                } else {
                    $(this).attr("checked", false);
                }
            } else {
                if (that.data.sizes.length) {
                    if ($(this).attr("checked")) {
                        var delSize_ = $(this).attr("id");
                        var temp = false;
                        for (var i = 0, l = that.data.sizes.length; i < l; i++) {
                            var s_ = that.data.sizes[i];
                            if (s_['id'] == delSize_) {
                                temp = true;
                                break;
                            }
                        }

                        if (!temp) {
                            $(this).attr("checked", false);
                        }
                    }
                } else {
                    $(this).attr("checked", false);
                }
            }
        });
    },
    userBlur: function (type, id) {
        var _data = this.data[type + 's'];
        for (var i = 0 , l = _data.length; i < l; i++) {
            if (_data[i]['id'] == id) {
                _data[i]['txt1'] = $('#' + id).parent().next().val();
                return;
            }
        }
    },
    arrAdd: function (type, id) { //添加SKU属性信息
        var _arr = [],
            _done = false,
            arr = this.data[type + 's'],
            _fid = $('#' + id).attr('fid'),
            _temp = {},
            _flag,
            _isfirst = false;
        for (var i = 0, l = arr.length; i < l; i++) {
            if ((i > 0 ? arr[i - 1]['fid'] : -9999) < _fid && _fid < arr[i]['fid']) {
                _temp = {
                    'fid': _fid,//用户索引
                    'id': id, //checkbox id
                    'txt1': $('#' + id).parent().next().val() //用户输入的val
                };
                _arr.push(_temp);
                _flag = arr[i]['id'];
                if (i == 0) {
                    _isfirst = true
                }
                _done = true;
            }
            _arr.push(arr[i]);
        }
        if (!_done) {
            _temp = {
                'fid': _fid,
                'id': id,
                'txt1': $('#' + id).parent().next().val()
            };
            _arr.push(_temp);
            _flag = false;
        }
        this.data[type + "s"] = _arr;
        return $.extend({}, _temp, {next: _flag, isfirst: _isfirst})
    },
    arrRemove: function (type, id) { //移除SKU属性信息
        var _arr = [], arr = this.data[type + "s"];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i]['id'] != id) {
                _arr.push(arr[i]);
            }
        }
        this.data[type + "s"] = _arr;
    },
    add: function (type, id) { //添加SKU销售属性信息
        var spuCostPrice = $('#spuCostPrice').val(); //商品成本价
        var spuPrice = $('#spuPrice').val(); //商品分销价
        var spuMarketPrice = $('#spuMarketPrice').val(); //商品市场价价

        if (type === 'color') {//添加颜色
            if ($('tr[attrc =' + id + ']').length) {
                return;
            }
            var _temp = this.arrAdd(type, id);
            if (this.data.sizes.length) {//已经有了某尺寸
                if (this.data.colors.length > 1) {//有尺寸,也有颜色
                    var _tr = '';
                    for (var i = 0, l = this.data.sizes.length; i < l; i++) {
                        var k = this.data.sizes[i];
                        var skuCostPrice = ((this.data.json[(id + '|' + k['id'])] || {})['td-cost-price'] || ''); //默认将商品价格赋值给SKU价格
                        if (skuCostPrice == '' || skuCostPrice == null) {
                            skuCostPrice = spuCostPrice;
                        }

                        var skuPrice = ((this.data.json[(id + '|' + k['id'])] || {})['td-price'] || ''); //默认将商品价格赋值给SKU价格
                        if (skuPrice == '' || skuPrice == null) {
                            skuPrice = spuPrice;
                        }

                        var skuMarketPrice = ((this.data.json[(id + '|' + k['id'])] || {})['td-market-price'] || ''); //默认将商品价格赋值给SKU价格
                        if (skuMarketPrice == '' || skuMarketPrice == null) {
                            skuMarketPrice = spuMarketPrice;
                        }

                        var colorAttrData = $('#' + id).attr('value');
                        var sizeAttrData = $('#' + k['id']).attr('value');
                        var costPriceId = "cost_price_" + colorAttrData + "_" + sizeAttrData;
                        var priceId = "price_" + colorAttrData + "_" + sizeAttrData;
                        var marketPriceId = "market_price_" + colorAttrData + "_" + sizeAttrData;
                        if (i == 0) {
                            _tr += '<tr attrc="' + id + '" attrs="' + k['id'] + '">'
                                + '<td rowspan="' + l + '" class="td-c">' + $('#' + id).next()[0].outerHTML + '<span class="s-color">' + _temp.txt1 + '</span></td>'
                                + '<td class="td-s">' + k.txt1 + '</td>'
                                + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                + '<td class="td-internal-code"><input  type="text" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                + '<td class="td-skuName"><input type="hidden" value="' + colorAttrData + '" name="skuColorIds" /><input type="hidden" name="skuSizeIds" value="' + sizeAttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-skuId'] || '') + '" /></td>'
                                + '</tr>';
                        }
                        else {
                            _tr += '<tr attrc="' + id + '" attrs="' + k['id'] + '">'
                                + '<td class="td-s">' + k.txt1 + '</td>'
                                + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                + '<td class="td-internal-code"><input  type="text" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                + '<td class="td-skuName"><input type="hidden" value="' + colorAttrData + '" name="skuColorIds" /><input type="hidden" name="skuSizeIds" value="' + sizeAttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-skuId'] || '') + '" /></td>'
                                + '</tr>';
                        }
                    }
                    if (_temp.next) {
                        $(_tr).insertBefore($('tbody tr[attrc=' + _temp.next + ']:first', this.r));
                    } else {
                        $(_tr).appendTo($('tbody', this.r));
                    }
                }
                else {//有尺寸,无颜色
                    for (var i = 0, l = this.data.sizes.length; i < l; i++) {
                        var j = this.data.sizes[i];
                        if (i == 0) {
                            $('tr[attrs=' + j['id'] + ']').attr('attrc', id).find('.td-c').attr('rowspan', l).html($('#' + id).next()[0].outerHTML + '<span class="s-color">' + _temp.txt1 + '</span>');
                        }
                        else {
                            $('tr[attrs=' + j['id'] + ']').attr('attrc', id);
                            $('.td-c', 'tr[attrs=' + j['id'] + ']').remove();
                        }

                        var colorAttrData = $('#' + id).attr('value');
                        var sizeAttrData = $('#' + j['id']).attr('value');
                        var tColorIds = '<input type="hidden" value="' + colorAttrData + '" name="skuColorIds" />'; //追加颜色属性值编号
                        $(tColorIds).appendTo($('tr[attrs=' + j['id'] + ']').find('.td-skuName'));

                        $('tr[attrs=' + j['id'] + ']').find('.td-skuName').find('input[name="skuIds"]').val((this.data.json[(id + '|' + j['id'])] || {})['td-skuId'] || ''); //重新赋值SKUID

                        var costPriceId = "cost_price_" + colorAttrData + "_" + sizeAttrData;
                        $('tr[attrs=' + j['id'] + ']').find('.td-cost-price').find('input[name="skuCostPrices"]').attr('id', costPriceId); //重新赋值价格INPUT ID

                        var priceId = "price_" + colorAttrData + "_" + sizeAttrData;
                        $('tr[attrs=' + j['id'] + ']').find('.td-price').find('input[name="skuPrices"]').attr('id', priceId); //重新赋值价格INPUT ID

                        var marketPriceId = "market_price_" + colorAttrData + "_" + sizeAttrData;
                        $('tr[attrs=' + j['id'] + ']').find('.td-market-price').find('input[name="skuMarketPrices"]').attr('id', marketPriceId); //重新赋值价格INPUT ID
                    }
                }
            }
            else {//无尺寸,不需组合
                var skuCostPrice = ((this.data.json[(id + '|none')] || {})['td-cost-price'] || '');
                if (skuCostPrice == '' || skuCostPrice == null) {
                    skuCostPrice = spuCostPrice;
                }

                var skuPrice = ((this.data.json[(id + '|none')] || {})['td-price'] || '');
                if (skuPrice == '' || skPrice == null) {
                    skuPrice = spuPrice;
                }

                var skuMarketPrice = ((this.data.json[(id + '|none')] || {})['td-market-price'] || '');
                if (skuMarketPrice == '' || skuMarketPrice == null) {
                    skuMarketPrice = spuMarketPrice;
                }

                var colorAttrData = $('#' + id).attr('value');
                var costPriceId = "cost_price_" + colorAttrData;
                var priceId = "price_" + colorAttrData;
                var marketPriceId = "market_price_" + colorAttrData;
                var _tr = '<tr attrc="' + id + '">'
                    + '<td class="td-c">' + $('#' + id).next()[0].outerHTML + '<span class="s-color">' + _temp.txt1 + '</span></td>'
                    + '<td class="td-s"></td>'
                    + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                    + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                    + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                    + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(id + '|none')] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                    + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(id + '|none')] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                    + '<td class="td-internal-code"><input  type="text" value="' + ((this.data.json[(id + '|none')] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                    + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(id + '|none')] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                    + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                    + '<td class="td-skuName"><input type="hidden" value="' + colorAttrData + '" name="skuColorIds" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(id + '|none')] || {})['td-skuId'] || '') + '" /></td>'
                    + '</tr>';
                if (_temp.next) {
                    $(_tr).insertBefore($('tbody tr[attrc=' + _temp.next + ']', this.r));
                } else {
                    $(_tr).appendTo($('tbody', this.r));
                }
                $(".td-s").hide();
            }

            $(".td-c").show();
        }//添加颜色结束
        else if (type === 'size') {//添加尺寸
            if ($('tr[attrs =' + id + ']').length) return;
            var _temp = this.arrAdd(type, id);
            if (this.data.colors.length > 0) {//已有颜色
                if (this.data.sizes.length > 1) {//已有尺寸
                    for (var i = 0, l = this.data.colors.length; i < l; i++) {
                        var _c = this.data.colors[i];
                        var skuCostPrice = ((this.data.json[(_c['id'] + '|' + id)] || {})['td-cost-price'] || '');  //默认将商品价格赋值给SKU价格
                        if (skuCostPrice == '' || skuCostPrice == null) {
                            skuCostPrice = spuCostPrice;
                        }

                        var skuPrice = ((this.data.json[(_c['id'] + '|' + id)] || {})['td-price'] || '');  //默认将商品价格赋值给SKU价格
                        if (skuPrice == '' || skuPrice == null) {
                            skuPrice = spuPrice;
                        }

                        var skuMarketPrice = ((this.data.json[(_c['id'] + '|' + id)] || {})['td-market-price'] || '');  //默认将商品价格赋值给SKU价格
                        if (skuMarketPrice == '' || skuMarketPrice == null) {
                            skuMarketPrice = spuMarketPrice;
                        }

                        var colorAttrData = $('#' + _c['id']).attr('value');
                        var sizeAttrData = $('#' + id).attr('value');
                        var costPriceId = "cost_price_" + colorAttrData + "_" + sizeAttrData;
                        var priceId = "price_" + colorAttrData + "_" + sizeAttrData;
                        var marketPriceId = "market_price_" + colorAttrData + "_" + sizeAttrData;
                        if (_temp.next) {//
                            if (_temp.isfirst) {//第一行插入
                                var _tr = '<tr attrc="' + _c['id'] + '" attrs="' + id + '">'
                                    + '<td rowspan="' + this.data.sizes.length + '" class="td-c">' + $('#' + _c['id']).next()[0].outerHTML + '<span class="s-color">' + _c.txt1 + '</span></td>'
                                    + '<td class="td-s">' + _temp.txt1 + '</td>'
                                    + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                    + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                    + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                    + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                    + '<td class="td-internal-code"><input  type="text" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                    + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                    + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                    + '<td class="td-skuName"><input type="hidden" value="' + colorAttrData + '" name="skuColorIds" /><input type="hidden" name="skuSizeIds" value="' + sizeAttrData + '" /> <input type="hidden" name="skuIds" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                                    + '</tr>';
                                $("td.td-c", 'tr[attrc=' + _c['id'] + ']').remove();

                                $(_tr).insertBefore($('tr[attrc=' + _c['id'] + ']').first());

                                if($("#nationallySetWareType3").attr("checked")==true) {
                                    $(".td-stock").hide();
                                }
                            }
                            else {//中间插入
                                var _tr = '<tr attrc="' + _c['id'] + '" attrs="' + id + '">'
                                    + '<td class="td-s">' + _temp.txt1 + '</td>'
                                    + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                    + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                    + '<td class="td-internal-code"><input  type="text" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                    + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                    + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                    + '<td class="td-skuName"><input type="hidden" value="' + colorAttrData + '" name="skuColorIds" /><input type="hidden" name="skuSizeIds" value="' + sizeAttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                                    + '</tr>';
                                $(_tr).insertBefore($('tr[attrs=' + _temp.next + '][attrc=' + _c['id'] + ']'));
                                $('td:first', 'tr[attrs=' + this.data.sizes[0]['id'] + '][attrc=' + _c['id'] + ']').after('<td class="td-c" rowspan="' + this.data.sizes.length + '">' + $('#' + _c['id']).next()[0].outerHTML + '<span class="s-color">' + _c.txt1 + '</span></td>').remove();
                            }
                        }
                        else {//
                            var _tr = '<tr attrc="' + _c['id'] + '" attrs="' + id + '">'
                                + '<td class="td-s">' + _temp.txt1 + '</td>'
                                + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                + '<td class="td-internal-code"><input  type="text" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                + '<td class="td-skuName"><input type="hidden" value="' + colorAttrData + '" name="skuColorIds" /><input type="hidden" name="skuSizeIds" value="' + sizeAttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                                + '</tr>';

                            $('tr[attrc=' + _c['id'] + ']:last').after(_tr)
                            $('td:first', 'tr[attrs=' + this.data.sizes[0]['id'] + '][attrc=' + _c['id'] + ']').after('<td class="td-c" rowspan="' + this.data.sizes.length + '">' + $('#' + _c['id']).next()[0].outerHTML + '<span class="s-color">' + _c.txt1 + '</span></td>').remove();

                        }
                    }
                }
                else {//尚无尺寸
                    for (var i = 0, l = this.data.colors.length; i < l; i++) {
                        var skuCostPrice = (this.data.json[(_cc + '|' + id)] || {})['td-cost-price'] || ''; //默认将商品价格赋值给SKU价格
                        if (skuCostPrice == '' || skuCostPrice == null) {
                            skuCostPrice = spuCostPrice;
                        }

                        var skuPrice = (this.data.json[(_cc + '|' + id)] || {})['td-price'] || ''; //默认将商品价格赋值给SKU价格
                        if (skuPrice == '' || skuPrice == null) {
                            skuPrice = spuPrice;
                        }

                        var skuMarketPrice = (this.data.json[(_cc + '|' + id)] || {})['td-market-price'] || ''; //默认将商品价格赋值给SKU价格
                        if (skuMarketPrice == '' || skuMarketPrice == null) {
                            skuMarketPrice = spuMarketPrice;
                        }

                        var _cc = this.data.colors[i]['id'];
                        var colorAttrData = $('#' + _cc).attr('value');
                        var sizeAttrData = $('#' + id).attr('value');
                        var costPriceId = "cost_price_" + colorAttrData + "_" + sizeAttrData;
                        var priceId = "price_" + colorAttrData + "_" + sizeAttrData;
                        var marketPriceId = "market_price_" + colorAttrData + "_" + sizeAttrData;

                        $('tr[attrc=' + _cc + ']').attr('attrs', id).find('.td-s').html(_temp.txt1);
                        $('.td-cost-price input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).val(skuCostPrice);
                        $('.td-price input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).val(skuPrice);
                        $('.td-market-price input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).val(skuMarketPrice);

                        if($("#nationallySetWareType3").attr("checked")==true)
                            $('.td-stock input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).val((this.data.json[(_cc + '|' + id)] || {})['td-stock'] || '');

                        $('.td-plu input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).val((this.data.json[(_cc + '|' + id)] || {})['td-plu'] || '');

                        $('.td-skuName', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).find('input[name="skuIds"]').val((this.data.json[(_cc + '|' + id)] || {})['td-skuId'] || ''); //新添加SKUID
                        $('.td-cost-price input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).attr('id', costPriceId);
                        $('.td-price input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).attr('id', priceId);
                        $('.td-market-price input', $('tr[attrc=' + this.data.colors[i]['id'] + ']')).attr('id', marketPriceId);
                        var tSizeIds = '<input type="hidden" value="' + sizeAttrData + '" name="skuSizeIds" />';
                        $(tSizeIds).appendTo($('tr[attrc=' + _cc + ']').find('.td-skuName'));
                    }
                }
            }
            else if (this.data.size2s.length > 0) {//已有尺寸2
                if (this.data.sizes.length > 1) {//有尺寸1
                    var _tr = '';
                    for (var i = 0, l = this.data.size2s.length; i < l; i++) {
                        var k = this.data.size2s[i];
                        var skuCostPrice = ((this.data.json[(id + '|' + k['id'])] || {})['td-cost-price'] || ''); //默认将商品价格赋值给SKU价格
                        if (skuCostPrice == '' || skuCostPrice == null) {
                            skuCostPrice = spuCostPrice;
                        }

                        var skuPrice = ((this.data.json[(id + '|' + k['id'])] || {})['td-price'] || ''); //默认将商品价格赋值给SKU价格
                        if (skuPrice == '' || skuPrice == null) {
                            skuPrice = spuPrice;
                        }

                        var skuMarketPrice = ((this.data.json[(id + '|' + k['id'])] || {})['td-market-price'] || ''); //默认将商品价格赋值给SKU价格
                        if (skuMarketPrice == '' || skuMarketPrice == null) {
                            skuMarketPrice = spuMarketPrice;
                        }

                        var sizeAttrData = $('#' + id).attr('value');
                        var size2AttrData = $('#' + k['id']).attr('value');
                        var costPriceId = "cost_price_" + sizeAttrData + "_" + size2AttrData;
                        var priceId = "price_" + sizeAttrData + "_" + size2AttrData;
                        var marketPriceId = "market_price_" + sizeAttrData + "_" + size2AttrData;
                        if (i == 0) {
                            _tr += '<tr attrs="' + id + '" attrs2="' + k['id'] + '">'
                                + '<td rowspan="' + l + '" class="td-s">' + _temp.txt1 + '</td>'
                                + '<td class="td-s2">' + k.txt1 + '</td>'
                                + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                + '<td class="td-internal-code"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                + '<td class="td-skuName"><input type="hidden" value="' + sizeAttrData + '" name="skuSizeIds" /><input type="hidden" name="skuSize2Ids" value="' + size2AttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-skuId'] || '') + '" /></td>'
                                + '</tr>';
                        }
                        else {
                            _tr += '<tr attrs="' + id + '" attrs2="' + k['id'] + '">'
                                + '<td class="td-s2">' + k.txt1 + '</td>'
                                + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                + '<td class="td-internal-code"><input  type="text" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                + '<td class="td-skuName"><input type="hidden" value="' + sizeAttrData + '" name="skuSizeIds" /><input type="hidden" name="skuSize2Ids" value="' + size2AttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(id + '|' + k['id'])] || {})['td-skuId'] || '') + '" /></td>'
                                + '</tr>';
                        }
                    }
                    if (_temp.next) {
                        $(_tr).insertBefore($('tbody tr[attrs=' + _temp.next + ']:first', this.r));
                    } else {
                        $(_tr).appendTo($('tbody', this.r));
                    }
                } else {
                    for (var i = 0, l = this.data.size2s.length; i < l; i++) {
                        var j = this.data.size2s[i];
                        if (i == 0) {
                            $('tr[attrs2=' + j['id'] + ']').attr('attrs', id).find('.td-s').attr('rowspan', l).html( _temp.txt1);
                        }
                        else {
                            $('tr[attrs2=' + j['id'] + ']').attr('attrs', id);
                            $('.td-s', 'tr[attrs2=' + j['id'] + ']').remove();
                        }

                        var sizeAttrData = $('#' + id).attr('value');
                        var size2AttrData = $('#' + j['id']).attr('value');
                        var tSizeIds = '<input type="hidden" value="' + sizeAttrData + '" name="skuSizeIds" />'; //追加尺寸1属性值编号
                        $(tSizeIds).appendTo($('tr[attrs2=' + j['id'] + ']').find('.td-skuName'));

                        $('tr[attrs2=' + j['id'] + ']').find('.td-skuName').find('input[name="skuIds"]').val((this.data.json[(id + '|' + j['id'])] || {})['td-skuId'] || ''); //重新赋值SKUID

                        var costPriceId = "cost_price_" + sizeAttrData + "_" + size2AttrData;
                        $('tr[attrs2=' + j['id'] + ']').find('.td-cost-price').find('input[name="skuCostPrices"]').attr('id', costPriceId); //重新赋值价格INPUT ID

                        var priceId = "price_" + sizeAttrData + "_" + size2AttrData;
                        $('tr[attrs2=' + j['id'] + ']').find('.td-price').find('input[name="skuPrices"]').attr('id', priceId); //重新赋值价格INPUT ID

                        var marketPriceId = "market_price_" + sizeAttrData + "_" + size2AttrData;
                        $('tr[attrs2=' + j['id'] + ']').find('.td-market-price').find('input[name="skuMarketPrices"]').attr('id', marketPriceId); //重新赋值价格INPUT ID
                    }
                }
            }
            else {//尚无颜色,无尺寸2,不需组合
                var skuCostPrice = ((this.data.json[('none|' + id)] || {})['td-cost-price'] || ''); //默认将商品价格赋值给SKU价格
                if (skuCostPrice == '' || skuCostPrice == null) {
                    skuCostPrice = spuCostPrice;
                }

                var skuPrice = ((this.data.json[('none|' + id)] || {})['td-price'] || ''); //默认将商品价格赋值给SKU价格
                if (skuPrice == '' || skuPrice == null) {
                    skuPrice = spuPrice;
                }

                var skuMarketPrice = ((this.data.json[('none|' + id)] || {})['td-market-price'] || ''); //默认将商品价格赋值给SKU价格
                if (skuMarketPrice == '' || skuMarketPrice == null) {
                    skuMarketPrice = spuMarketPrice;
                }

                var sizeAttrData = $('#' + id).attr('value');
                var costPriceId = "cost_price_" + sizeAttrData;
                var priceId = "price_" + sizeAttrData;
                var marketPriceId = "market_price_" + sizeAttrData;
                var _tr = '<tr attrs="' + id + '">'
                    + '<td class="td-c"></td>'
                    + '<td class="td-s">' + _temp.txt1 + '</td>'
                    + '<td class="td-s2"></td>'
                    + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                    + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                    + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + costPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                    + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[('none|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                    + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[('none|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                    + '<td class="td-internal-code"><input  type="text"  value="' + ((this.data.json[('none|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                    + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[('none|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                    + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                    + '<td class="td-skuName"><input type="hidden" name="skuSizeIds" value="' + sizeAttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[('none|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                    + '</tr>';
                if (_temp.next) {
                    $(_tr).insertBefore($('tbody tr[attrs=' + _temp.next + ']', this.r));
                } else {
                    $(_tr).appendTo($('tbody', this.r));
                }
                $(".td-c").hide();
                $(".td-s2").hide();
            }

            $(".td-s").show();
        }//添加尺寸结束
        else if (type === 'size2') {//添加尺寸二
            if ($('tr[attrs2 =' + id + ']').length) return;
            var _temp = this.arrAdd(type, id);
            if (this.data.sizes.length > 0) {//已有尺寸1
                if (this.data.size2s.length > 1) {//已有尺寸2
                    for (var i = 0, l = this.data.sizes.length; i < l; i++) {
                        var _c = this.data.sizes[i];
                        var skuCostPrice = ((this.data.json[(_c['id'] + '|' + id)] || {})['td-cost-price'] || '');  //默认将商品价格赋值给SKU价格
                        if (skuCostPrice == '' || skuCostPrice == null) {
                            skuCostPrice = spuCostPrice;
                        }

                        var skuPrice = ((this.data.json[(_c['id'] + '|' + id)] || {})['td-price'] || '');  //默认将商品价格赋值给SKU价格
                        if (skuPrice == '' || skuPrice == null) {
                            skuPrice = spuPrice;
                        }

                        var skuMarketPrice = ((this.data.json[(_c['id'] + '|' + id)] || {})['td-market-price'] || '');  //默认将商品价格赋值给SKU价格
                        if (skuMarketPrice == '' || skuMarketPrice == null) {
                            skuMarketPrice = spuMarketPrice;
                        }

                        var sizeAttrData = $('#' + _c['id']).attr('value');
                        var size2AttrData = $('#' + id).attr('value');
                        var costPriceId = "cost_price_" + sizeAttrData + "_" + size2AttrData;
                        var priceId = "price_" + sizeAttrData + "_" + size2AttrData;
                        var marketPriceId = "market_price_" + sizeAttrData + "_" + size2AttrData;
                        if (_temp.next) {//
                            if (_temp.isfirst) {//第一行插入
                                var _tr = '<tr attrs="' + _c['id'] + '" attrs2="' + id + '">'
                                    + '<td rowspan="' + this.data.size2s.length + '" class="td-s">' + _c.txt1 + '</td>'
                                    + '<td class="td-s2">' + _temp.txt1 + '</td>'
                                    + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                    + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                    + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                    + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                    + '<td class="td-internal-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                    + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                    + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                    + '<td class="td-skuName"><input type="hidden" value="' + sizeAttrData + '" name="skuSizeIds" /><input type="hidden" name="skuSize2Ids" value="' + size2AttrData + '" /> <input type="hidden" name="skuIds" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                                    + '</tr>';
                                $("td.td-s", 'tr[attrs=' + _c['id'] + ']').remove();

                                $(_tr).insertBefore($('tr[attrs=' + _c['id'] + ']').first());
                            }
                            else {//中间插入
                                var _tr = '<tr attrs="' + _c['id'] + '" attrs2="' + id + '">'
                                    + '<td class="td-s2">' + _temp.txt1 + '</td>'
                                    + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                    + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                    + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                    + '<td class="td-internal-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                    + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                    + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                    + '<td class="td-skuName"><input type="hidden" value="' + sizeAttrData + '" name="skuSizeIds" /><input type="hidden" name="skuSize2Ids" value="' + size2AttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                                    + '</tr>';
                                $(_tr).insertBefore($('tr[attrs2=' + _temp.next + '][attrs=' + _c['id'] + ']'));
                                $('td.td-s', 'tr[attrs2=' + this.data.size2s[0]['id'] + '][attrs=' + _c['id'] + ']').after('<td class="td-s" rowspan="' + this.data.size2s.length + '">' +  _c.txt1 + '</td>').remove();
                            }
                        }
                        else {//
                            var _tr = '<tr attrs="' + _c['id'] + '" attrs2="' + id + '">'
                                + '<td class="td-s2">' + _temp.txt1 + '</td>'
                                + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                                + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + priceId + '" size="8" name="skuPrices">&#20803;</td>'
                                + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + marketPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                                + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                                + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                                + '<td class="td-internal-code"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                                + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                                + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                                + '<td class="td-skuName"><input type="hidden" value="' + sizeAttrData + '" name="skuSizeIds" /><input type="hidden" name="skuSize2Ids" value="' + size2AttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[(_c['id'] + '|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                                + '</tr>';

                            $('tr[attrs=' + _c['id'] + ']:last').after(_tr)
                            $('td.td-s', 'tr[attrs2=' + this.data.size2s[0]['id'] + '][attrs=' + _c['id'] + ']').after('<td class="td-s" rowspan="' + this.data.size2s.length + '">' + _c.txt1 + '</td>').remove();
                        }
                    }
                } else {
                    for (var i = 0, l = this.data.sizes.length; i < l; i++) {
                        var skuCostPrice = (this.data.json[(_cc + '|' + id)] || {})['td-cost-price'] || ''; //默认将商品价格赋值给SKU价格
                        if (skuCostPrice == '' || skuCostPrice == null) {
                            skuCostPrice = spuCostPrice;
                        }

                        var skuPrice = (this.data.json[(_cc + '|' + id)] || {})['td-price'] || ''; //默认将商品价格赋值给SKU价格
                        if (skuPrice == '' || skuPrice == null) {
                            skuPrice = spuPrice;
                        }

                        var skuMarketPrice = (this.data.json[(_cc + '|' + id)] || {})['td-market-price'] || ''; //默认将商品价格赋值给SKU价格
                        if (skuMarketPrice == '' || skuMarketPrice == null) {
                            skuMarketPrice = spuMarketPrice;
                        }

                        var _cc = this.data.sizes[i]['id'];
                        var sizeAttrData = $('#' + _cc).attr('value');
                        var size2AttrData = $('#' + id).attr('value');
                        var costPriceId = "cost_price_" + sizeAttrData + "_" + size2AttrData;
                        var priceId = "price_" + sizeAttrData + "_" + size2AttrData;
                        var marketPriceId = "market_price_" + sizeAttrData + "_" + size2AttrData;
                        $('tr[attrs=' + _cc + ']').attr('attrs2', id).find('.td-s2').html(_temp.txt1);
                        $('.td-cost-price input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).val(skuCostPrice);
                        $('.td-price input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).val(skuPrice);
                        $('.td-market-price input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).val(skuMarketPrice);
                        $('.td-stock input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).val((this.data.json[(_cc + '|' + id)] || {})['td-stock'] || '');
                        $('.td-sku-code input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).val((this.data.json[(_cc + '|' + id)] || {})['td-sku-code'] || '');
                        $('.td-internal-code input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).val((this.data.json[(_cc + '|' + id)] || {})['td-internal-code'] || '');
                        $('.td-plu input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).val((this.data.json[(_cc + '|' + id)] || {})['td-plu'] || '');
                        $('.td-skuName', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).find('input[name="skuIds"]').val((this.data.json[(_cc + '|' + id)] || {})['td-skuId'] || ''); //新添加SKUID
                        $('.td-cost-price input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).attr('id', costPriceId);
                        $('.td-price input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).attr('id', priceId);
                        $('.td-market-price input', $('tr[attrs=' + this.data.sizes[i]['id'] + ']')).attr('id', marketPriceId);
                        var tSizeIds = '<input type="hidden" value="' + size2AttrData + '" name="skuSize2Ids" />';
                        $(tSizeIds).appendTo($('tr[attrs=' + _cc + ']').find('.td-skuName'));
                    }
                }
            } else { //尚无尺寸1,不需组合
                var skuCostPrice = ((this.data.json[('none|' + id)] || {})['td-cost-price'] || ''); //默认将商品价格赋值给SKU价格
                if (skuCostPrice == '' || skuCostPrice == null) {
                    skuCostPrice = spuCostPrice;
                }

                var skuPrice = ((this.data.json[('none|' + id)] || {})['td-price'] || ''); //默认将商品价格赋值给SKU价格
                if (skuPrice == '' || skuPrice == null) {
                    skuPrice = spuPrice;
                }

                var skuMarketPrice = ((this.data.json[('none|' + id)] || {})['td-market-price'] || ''); //默认将商品价格赋值给SKU价格
                if (skuMarketPrice == '' || skuMarketPrice == null) {
                    skuMarketPrice = spuMarketPrice;
                }

                var size2AttrData = $('#' + id).attr('value');
                var costPriceId = "cost_price_" + size2AttrData;
                var priceId = "price_" + size2AttrData;
                var marketPriceId = "market_price_" + size2AttrData;
                var _tr = '<tr attrs2="' + id + '">'
                    + '<td class="td-s"></td>'
                    + '<td class="td-s1">' + _temp.txt1 + '</td>'
                    + '<td class="td-cost-price"><input   type="text" maxlength="12" value="' + skuCostPrice + '" id="' + costPriceId + '" size="8" name="skuCostPrices">&#20803;</td>'
                    + '<td class="td-price"><input   type="text" maxlength="12" value="' + skuPrice + '" id="' + costPriceId + '" size="8" name="skuPrices">&#20803;</td>'
                    + '<td class="td-market-price"><input   type="text" maxlength="12" value="' + skuMarketPrice + '" id="' + costPriceId + '" size="8" name="skuMarketPrices">&#20803;</td>'
                    + '<td class="td-stock"><input   type="text" maxlength="9" value="' + ((this.data.json[('none|' + id)] || {})['td-stock'] || '') + '" size="8" name="skuStocks">&#20214;</td>'
                    + '<td class="td-sku-code"><input  type="text"  value="' + ((this.data.json[('none|' + id)] || {})['td-sku-code'] || '') + '" size="12" name="skuCodes"></td>'
                    + '<td class="td-internal-code"><input  type="text"  value="' + ((this.data.json[('none|' + id)] || {})['td-internal-code'] || '') + '" size="12" name="internalCodes"></td>'
                    + '<td class="td-plu"><input  type="text"  value="' + ((this.data.json[('none|' + id)] || {})['td-plu'] || '') + '" size="16" name="skuBarCodes"></td>'
                    + '<td class="td-idcard"><label class="checkbox-inline"><input type="checkbox" name="skuIdcard" value="1"></label></td>'
                    + '<td class="td-skuName"><input type="hidden" name="skuSize2Ids" value="' + size2AttrData + '" /><input type="hidden" name="skuIds" value="' + ((this.data.json[('none|' + id)] || {})['td-skuId'] || '') + '" /></td>'
                    + '</tr>';
                if (_temp.next) {
                    $(_tr).insertBefore($('tbody tr[attrs=' + _temp.next + ']', this.r));
                } else {
                    $(_tr).appendTo($('tbody', this.r));
                }
                $(".td-s").hide();
            }
            $(".td-s2").show();
        }
        this.r.show();
    },
    remove: function (type, id) {
        if (type === 'color') {//移除颜色
            if (this.data.colors.length > 1) {//多个颜色,直接移除
                $('tr[attrc=' + id + ']', this.r).remove();
            } else {//单一颜色
                if (this.data.sizes.length) {//单一颜色有尺寸,清空尺寸单元格
                    for (var i = 0, l = this.data.sizes.length; i < l; i++) {
                        //this.data.sizes[i]
                        var m = this.data.sizes[i]['id'];
                        if ($('.td-c', 'tr[attrs=' + m + ']').length) {//第一行
                            $('.td-c', 'tr[attrs=' + m + ']').after('<td class="td-c"></td>').remove();
                        } else {//非第一行
                            $('<td class="td-c"></td>').prependTo($('tr[attrs=' + m + ']'));
                        }
                        $(".td-c").hide();
                        $('tr[attrs=' + m + ']').removeAttr('attrc');

                        $('tr[attrs=' + m + ']').find('.td-skuName').find('input[name="skuColorIds"]').remove(); //新增加称除颜色input属性值
                        $('tr[attrs=' + m + ']').find('.td-skuName').find('input[name="skuIds"]').val((this.data.json[('none|' + m)] || {})['td-skuId'] || '');
                        var sizeAttrData = $('#' + m).attr('value');
                        var costPriceId = "cost_price_" + sizeAttrData;
                        var priceId = "price_" + sizeAttrData;
                        var marketPriceId = "market_price_" + sizeAttrData;
                        $('tr[attrs=' + m + ']').find('.td-cost-price').find('input[name="skuCostPrices"]').attr('id', costPriceId);
                        $('tr[attrs=' + m + ']').find('.td-price').find('input[name="skuPrices"]').attr('id', priceId);
                        $('tr[attrs=' + m + ']').find('.td-market-price').find('input[name="skuPrices"]').attr('id', marketPriceId);
                    }
                    ;
                } else {//单一颜色无尺寸,直接移除
                    $('tr[attrc=' + id + ']', this.r).remove();
                }
            }
        }
        else if (type == 'size') {//移除尺寸
            if (this.data.colors.length) {//有颜色
                if (this.data.sizes.length > 1) {//有颜色,且多个尺寸
                    for (var i = 0, l = this.data.colors.length; i < l; i++) {
                        var y = this.data.colors[i], ytr = $('tr[attrc=' + y['id'] + ']').first();
                        if (ytr.attr('attrs') == id) {
                            $('<td class="td-c" rowspan="' + (this.data.sizes.length - 1) + '">' + $('#' + y['id']).next()[0].outerHTML + '<span class="s-color">' + y['txt1'] + '</span></td>').prependTo(ytr.next());
                            ytr.remove();
                        } else {
                            ytr.find('td:first').attr('rowspan', (this.data.sizes.length - 1));
                            $('tr[attrs=' + id + '][attrc=' + y['id'] + ']', this.r).remove();
                        }
                    }
                }
                else {//有颜色,一个尺寸
                    for (var i = 0, l = this.data.colors.length; i < l; i++) {
                        $('tr[attrc=' + this.data.colors[i]['id'] + ']').removeAttr('attrs').find('.td-s').empty();
                        $(".td-s").hide();

                        var tempColorId = this.data.colors[i]['id']; //新增加称除颜色input属性值
                        $('tr[attrc=' + tempColorId + ']').find('.td-skuName').find('input[name="skuSizeIds"]').remove();
                        $('tr[attrc=' + tempColorId + ']').find('.td-skuName').find('input[name="skuIds"]').val((this.data.json[(tempColorId + '|none')] || {})['td-skuId'] || '');

                        var colorAttrData = $('#' + tempColorId).attr('value');
                        var costPriceId = "cost_price_" + colorAttrData;
                        $('tr[attrc=' + tempColorId + ']').find('.td-cost-price').find('input[name="skuCostPrices"]').attr('id', costPriceId);
                        var priceId = "price_" + colorAttrData;
                        $('tr[attrc=' + tempColorId + ']').find('.td-price').find('input[name="skuPrices"]').attr('id', priceId);
                        var marketPriceId = "market_price_" + colorAttrData;
                        $('tr[attrc=' + tempColorId + ']').find('.td-market-price').find('input[name="skuMarketPrices"]').attr('id', marketPriceId);
                    }
                }
            }
            else if (this.data.size2s.length) {//有尺寸2
                if (this.data.sizes.length > 1) {//多个尺寸1,直接移除
                    $('tr[attrs=' + id + ']', this.r).remove();
                } else {//单一尺寸1
                    if (this.data.sizes.length) {//单一颜色有尺寸,清空尺寸单元格
                        for (var i = 0, l = this.data.size2s.length; i < l; i++) {
                            var m = this.data.size2s[i]['id'];
                            if ($('.td-s', 'tr[attrs2=' + m + ']').length) {//第一行
                                $('.td-s', 'tr[attrs2=' + m + ']').after('<td class="td-s"></td>').remove();
                            } else {//非第一行
                                $('<td class="td-s"></td>').prependTo($('tr[attrs2=' + m + ']'));
                            }
                            $(".td-s").hide();
                            $('tr[attrs2=' + m + ']').removeAttr('attrs');

                            $('tr[attrs2=' + m + ']').find('.td-skuName').find('input[name="skuSizeIds"]').remove(); //新增加称除颜色input属性值
                            $('tr[attrs2=' + m + ']').find('.td-skuName').find('input[name="skuIds"]').val((this.data.json[('none|' + m)] || {})['td-skuId'] || '');
                            var size2AttrData = $('#' + m).attr('value');
                            var costPriceId = "cost_price_" + size2AttrData;
                            var priceId = "price_" + size2AttrData;
                            var marketPriceId = "market_price_" + size2AttrData;
                            $('tr[attrs=' + m + ']').find('.td-cost-price').find('input[name="skuCostPrices"]').attr('id', costPriceId);
                            $('tr[attrs=' + m + ']').find('.td-price').find('input[name="skuPrices"]').attr('id', priceId);
                            $('tr[attrs=' + m + ']').find('.td-market-price').find('input[name="skuPrices"]').attr('id', marketPriceId);
                        }
                        ;
                    } else {//单一尺寸1无尺寸2,直接移除
                        $('tr[attrs=' + id + ']', this.r).remove();
                    }
                }
            } else {//无颜色、无尺寸2
                $('tr[attrs=' + id + ']', this.r).remove();
            }
        }
        else if (type == 'size2') {
            if (this.data.sizes.length) {//有尺寸1
                if (this.data.size2s.length > 1) {//有尺寸1,尺寸2
                    for (var i = 0, l = this.data.sizes.length; i < l; i++) {
                        var y = this.data.sizes[i], ytr = $('tr[attrs=' + y['id'] + ']').first();
                        if (ytr.attr('attrs2') == id) {
                            $('<td class="td-s" rowspan="' + (this.data.size2s.length - 1) + '">' + y['txt1'] + '</td>').prependTo(ytr.next());
                            ytr.remove();
                        } else {
                            ytr.find('td.td-s').attr('rowspan', (this.data.size2s.length - 1));
                            $('tr[attrs2=' + id + '][attrs=' + y['id'] + ']', this.r).remove();
                        }
                    }
                }
                else {//有尺寸1,无尺寸2
                    for (var i = 0, l = this.data.sizes.length; i < l; i++) {
                        $('tr[attrs=' + this.data.sizes[i]['id'] + ']').removeAttr('attrs2').find('.td-s2').empty();
                        $(".td-s2").hide();

                        var tempSizeId = this.data.sizes[i]['id'];
                        $('tr[attrs=' + tempSizeId + ']').find('.td-skuName').find('input[name="skuSize2Ids"]').remove();
                        $('tr[attrs=' + tempSizeId + ']').find('.td-skuName').find('input[name="skuIds"]').val((this.data.json[(tempSizeId + '|none')] || {})['td-skuId'] || '');

                        var sizeAttrData = $('#' + tempSizeId).attr('value');
                        var costPriceId = "cost_price_" + sizeAttrData;
                        $('tr[attrs=' + tempSizeId + ']').find('.td-cost-price').find('input[name="skuCostPrices"]').attr('id', costPriceId);
                        var priceId = "price_" + sizeAttrData;
                        $('tr[attrs=' + tempSizeId + ']').find('.td-price').find('input[name="skuPrices"]').attr('id', priceId);
                        var marketPriceId = "market_price_" + sizeAttrData;
                        $('tr[attrs=' + tempSizeId + ']').find('.td-market-price').find('input[name="skuMarketPrices"]').attr('id', marketPriceId);
                    }
                }
            }
            else {//无尺寸1
                $('tr[attrs2=' + id + ']', this.r).remove();
            }
        }
        this.arrRemove(type, id);
        if ((this.data.colors.length + this.data.sizes.length + this.data.size2s.length) <= 0) {
            this.r.hide();
        }
    },
    checkAttrAlias: function (inputer) { //验证销售属性别名
        var v = inputer.val();
        var msg = "";
        if (v.length > 25) {
            msg = "销售属性自定义名称过长,请调整为25字符以内。";
        }
        if (!checkAttributeValue(v)) {
            msg = "暂时只支持! @ # $ % & + - * / \\ _ ( ) = . 16种特殊字符,请重新输入。";
        }
        var repeated = false;
        var inputers = $("");

        if (inputer.hasClass("colorAliasInput")) {
            inputers = $(".colorAliasInput").not(inputer);
        } else if (inputer.hasClass("sizeAliasInput")) {
            inputers = $(".sizeAliasInput").not(inputer);
        }

        inputers.each(function () {
            if ($(this).val() == v) {
                repeated = true;
            }
        });
        if (repeated) {
            msg = "注意:销售属性值名称有重复,请重新进行自定义!";
        }

        if (msg) {
            alert(msg);
            inputer.css({"color": "red", "background-color": "#FFF4D7"});
            setTimeout('$("#' + inputer.attr("id") + '").focus()', 200);
            return false;
        }
        return true;
    }
};



function uploadImgs(o) {
    this.o = $(o);
}
uploadImgs.prototype = {
    init: function (cookieDomain) {
        var _this = this;
        $('.ftab-t li', this.o).bind('click', function () {
            if ($(this).hasClass("close_btn")) { // 关闭按钮标签被点击, 关闭自己
                $(".g-imgs.open").find('.upload-btn').click();
            } else if ($(this).hasClass("next_r_btn")) { // 设置下一行图片按钮被点击
                var nextRow = $(".g-imgs.open").next();
                if (nextRow.length > 0) {
                    nextRow.find('.upload-btn').click();
                }
            } else { // 普通标签被点击,切换选项卡
                $(this).addClass('curr').siblings().removeClass('curr');
                $($(this).attr('fid')).show().siblings('.ftab-con').hide();

                // 如果有cookie支持, 将选择结果在cookie中保持30天
                if (jQuery.cookie) {
                    jQuery.cookie.json = true;
                    jQuery.cookie("_cut_", {
                        "v": $(this).attr("fid") // cut == Current Upload box Tab
                    }, {
                        expires: 30,
                        path: "/ware/",
                        domain: cookieDomain
                    });
                }
            }
        });

        // 如果cookie中有上次的标签选择记录, 则使用上次的选择结果
        if (jQuery.cookie) {
            jQuery.cookie.json = true;
            try {
                var cut = jQuery.cookie("_cut_");
                if (cut) {
                    $(".ftab-t li[fid=" + cut.v + "]").click();
                }
            } catch (e) {
            }
        }
    }
};

function ctrlImgs(o) {
    this.o = $(o);
}
ctrlImgs.prototype = {
    init: function () {
        var _this = this;
        /**
         * 图片框上的hover效果
         */
        $('.g-m li', this.o).hover(function () {
            if ($(".p-img", this).html()) { // 位置上有图
                $(this).addClass('hover');
            } else { // 位置上无图
                if (!$(this).parents(".g-imgs").hasClass("open")) { // 位置无图且当前行未展开时,提示 点击可展开
                    $(this).css({
                        cursor: "pointer"
                    }).attr("title", "点击,展开图片上传");
                }
            }
        }, function () {
            $(this).removeClass('hover');
            $(this).css({
                cursor: "default"
            }).attr("title", "");
        });

        this.o.bind('click', function (e) {
            var _t = $(e.target), _that = this;

            /**
             * 交换两个图片的位置
             * @param sourceImgBox 原图片框
             * @param targetImgBox 目标图片框
             */
            function swapImg(sourceImgBox, targetImgBox) {
                var sourceImgObj = sourceImgBox.html();
                sourceImgBox.html(targetImgBox.html());
                targetImgBox.html(sourceImgObj);

                var sourceLoadError = sourceImgBox.hasClass("imgLoadError");
                var targetLoadError = targetImgBox.hasClass("imgLoadError");
                if (sourceLoadError) {
                    targetImgBox.addClass("imgLoadError");
                } else {
                    targetImgBox.removeClass("imgLoadError");
                }
                if (targetLoadError) {
                    sourceImgBox.addClass("imgLoadError");
                } else {
                    sourceImgBox.removeClass("imgLoadError");
                }
            }

            /**
             * 点击图片框
             */
            if (_t.hasClass("p-img")) {
                // 在当前行展开上传控件
                if (!$(this).hasClass('open')) {
                    $(this).find('.upload-btn').click();
                }
            }

            /**
             * 点击图片上传
             */
            if (_t.hasClass('upload-btn') || _t.parent().hasClass('upload-btn')) {
                // 显示/隐藏 图片上传控件
                toggleUploadBox($(this), true);
            }

            /**
             * 点击左移
             */
            if (_t.hasClass('to-l')) {
                var _prev = _t.parent().parent().prev(); // 前一张图的li
                if (_prev.length) {
                    if (_prev.hasClass("waiting")) {
                        return;
                    }
                    // 移除错误状态(如果有)
                    removeErrorState(_prev);
                    // 交换图片
                    swapImg(_t.parent().prev(), _prev.find('.p-img'));
                }

                // 如果移动完了之后,本位置,已经没有图片了,则将图片操作栏隐藏
                if (_t.parents("li").find(".p-img img").length <= 0) {
                    _t.parents("li").removeClass('hover');
                }
            }

            /**
             * 点击右移
             */
            if (_t.hasClass('to-r')) {
                var _next = _t.parent().parent().next();
                if (_next.length) {
                    if (_next.hasClass("waiting")) {
                        return;
                    }
                    // 移除错误状态(如果有)
                    removeErrorState(_next);
                    // 交换图片
                    swapImg(_t.parent().prev(), _next.find('.p-img'));
                }

                // 如果移动完了之后,本位置,已经没有图片了,则将图片操作栏隐藏
                if (_t.parents("li").find(".p-img img").length <= 0) {
                    _t.parents("li").removeClass('hover');
                }
            }

            /**
             * 点击移除
             */
            if (_t.hasClass('del')) {
                // 移除图片空间中该图片的选中状态
                var imgid = _t.parent().prev('.p-img').children("img").attr("imgid");
                $("#imgSpaceImgs").find("img[imgid=" + imgid + "]").parent("li").removeClass('sel');
                // 移除图片
                _t.parent().prev('.p-img').removeClass("imgLoadError").empty();
                // 在当前行展开上传控件
                if (!$(this).hasClass('open')) {
                    $(this).find('.upload-btn').click();
                }

                // 如果移动完了之后,本位置,已经没有图片了,则将图片操作栏隐藏
                if (_t.parents("li").find(".p-img img").length <= 0) {
                    _t.parents("li").removeClass('hover');
                }

                // ajax删除图片,不包括编辑状态下删除已存在的图片,避免刷洗以后图片丢失, By LCN
                $.ajax({
                    url: "/catalog/item-img/delete?id=" + imgid,
                    type: "get",
                    success: function (msg2) {


                    }
                });

            }

            /**
             * 点击使用商品图片
             */
            if (_t.hasClass('fbtn')) {
                $('#picID_zero').find(".p-img").each(function (i) {
                    removeErrorState($($('.p-img', _that)[i]).parents("li"));
                    $($('.p-img', _that)[i]).removeClass("imgLoadError").html($(this).html());
                });
            }
        });
    }
};
$.fn.extend({
    uploadImgs: function (cookieDomain) {
        this.each(function () {
            var _o = new uploadImgs(this);
            _o.init(cookieDomain);
        });
    },
    ctrlImgs: function () {
        this.each(function () {
            var _o = new ctrlImgs(this);
            _o.init();
        });
    }
});



/**
 * 移除商品图片上的错误状态
 * @param imgBox 图片框
 */
function removeErrorState(imgBox) {
    imgBox.removeClass("error").find(".error-txt").remove();
}




/**
 * 初始化商品图片部分界面
 */
function initImgPartOfPage(img10Url, cookieDomain) {
    // 上传控件初始化
    $('#uploadbox').uploadImgs(cookieDomain);
    $('.g-imgs').ctrlImgs();

    // 默认第一行上传控件展开
    toggleUploadBox($("#picID_zero"), false);

    // (编辑商品时)如果已经有图片,将图片初始化
    $(".imgInput").each(function (i, o) {
        var wareImg = $(this).val().split(",");
        var rowId = (wareImg[2] == "0000000000") ? "picID_zero" : "picID_checkColor_" + wareImg[2];
        $("#" + rowId + " .g-m .p-img").eq(wareImg[0] - 1).empty()
            .append('<img onerror="loadImgError(this)" ' +
                'imgId="' + wareImg[1] + '" ' +
                'imgUrl="' + wareImg[3] + '" ' +
                'src="' + img10Url + wareImg[3] + '">');
    });
}




/**
 * 图片加载出错时,显示小joy图片
 * @param img
 */
function loadImgError(img) {
    $(img).hide().parent().addClass("imgLoadError");
}

/**
 * 在某一行 显示/隐藏 图片上传控件
 * @param gImg 某一行图片
 * @param keepInView 是否让展开状态的行保持在视野内
 */
function toggleUploadBox(gImg, keepInView) {
    if (!gImg.hasClass('open')) { // 展开
        gImg.addClass('open').siblings().removeClass('open');
        var _pos = gImg.position();
        $('#uploadbox').css({
            'top': _pos.top + 100 + $('#pic-con').scrollTop(),
            'display': 'block'
        });
        if (keepInView) {
            // 保持打开状态的行在视野内
            var rowId = "#" + gImg.attr("id");
            window.location.href = window.location.href.substring(0, window.location.href.indexOf("#")) + rowId;
        }
    } else { // 关闭
        gImg.removeClass('open').siblings().removeClass('open');
        $('#uploadbox').css({
            'top': -9999,
            'display': 'none'
        });
    }
}