Index.js 44.1 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
'use strict';
var $ = require('jquery'),
    common = require('../../../common/common');

/***********************变价列表***********************/

new common.dropDown({
    el: '#shop',
    ajax: 'shopsRest'
});
new common.dropDown({
    el: '#supplier',
    ajax: 'querySupplier'
});
new common.dropDown({
    el: '#brand',
    ajax: 'brand',
    params:function(){
        return {userLimitFlag:true};
    }
});
new common.dropDown({
    el: '#cate',
    ajax: 'maxSort'
});
new common.dropDown({
    el: "#jit"
});
new common.dropDown({
    el: "#status"
});
new common.dropDown({
    el: "#stock"
});
new common.dropDown({
    el: "#sex"
});

var TABENUM = {
    status: {
        toFirstAuditNum: '待一审',
        toSecondAuditNum: '待二审',
        toThirdAuditNum: '待三审',
        failAuditNum: '驳回',
        passAuditNum: '通过',
        all: '全部'
    }, 
    tips: {
        "toFirstAuditNum": 0,
        "toSecondAuditNum": 0,
        "toThirdAuditNum": 0,
        "failAuditNum": 0,
        "passAuditNum": 0,
        "all": ""
    },
    statusStr: {
        101: '待一审',
        102: '待二审',
        103: '待三审',
        200: '通过',
        300: '驳回'
    }
}

// 审核状态枚举
var AuditEnum = {
    status: {
        toFirstAuditNum: 101,
        toSecondAuditNum: 102,
        toThirdAuditNum: 103,
        passAuditNum: 200,
        failAuditNum: 300
    }
}

var ENUM = {
    vipType: {
        1: '正常折扣',
        2: '统一折扣',
        3: '无折扣',
        4: '固定折扣',
        5: '自定义折扣'
    },
    gender: {
        1: '男',
        2: '女',
        3: '通用'
    },
    goodsSeason: {
        0: '四季',
        1: '春',
        2: '夏',
        3: '秋',
        4: '冬',
        5: '春夏',
        6: '秋冬'
    },
};

//多级菜单
var tabTree = new common.tabTree("#sortTree", {status: 1, sortLevel: 1});
tabTree.init();


var t = new common.tab2({
    el: "#priceTab",
    active:5,
    click: function() {
    var columnname=t.options.columns[t.options.active].name;
        g.options.columns[0].hidden = true;
        g.options.columns[13].hidden = true;
        g.options.columns[14].hidden = true;
        g.options.columns[15].hidden = true;
        g.options.columns[17].hidden = false;
        // 隐藏无权限的审核列表页操作
	    var authority = $("#authority").val();
		
        if (columnname == "all") {        
		    // 不支持导出
			//$("#batchExportChangePrice").css("display", "none");
			$("#batchExportChangePrice").hide();

            g.options.columns[0].hidden = true;
            g.options.columns[12].hidden = true;
            g.options.columns[13].hidden = true;
            g.options.columns[14].hidden = true;
            g.options.columns[15].hidden = true;

            g.options.columns[11].hidden = false;
            g.init('/goods/price/list');
        } else {
			// 支持批量导出
            $("#batchExportChangePrice").show();

            $("#batch_pass_btn").hide(); 
            $("#batch_reject_btn").hide(); 
            $("#batch_audit_btn").hide(); 
            switch (columnname) {
                case 'toFirstAuditNum':
                    {   
                        g.options.columns[0].hidden = false;
                        g.options.columns[12].hidden = false;
                        g.options.columns[13].hidden = false;
                        g.options.columns[14].hidden = false;
                        g.options.columns[15].hidden = false;
                        g.options.columns[11].hidden = true;
						
						 if (authority == 1) {
						     g.options.columns[17].hidden = false;
 
                             $("#batch_pass_btn").show(); 
                             $("#batch_reject_btn").show(); 
                             $("#batch_audit_btn").show(); 
                         }
						 else {
						     g.options.columns[17].hidden = true;
                         }
                    }
                    break;

                case 'toSecondAuditNum':
                    { 
                        g.options.columns[0].hidden = false;
                        g.options.columns[12].hidden = false;
                        g.options.columns[13].hidden = false;
                        g.options.columns[14].hidden = false;
                        g.options.columns[15].hidden = false;
                        g.options.columns[11].hidden = true;
						
						 if (authority == 2) {
						     g.options.columns[17].hidden = false;
                             $("#batch_pass_btn").show(); 
                             $("#batch_reject_btn").show(); 
                             $("#batch_audit_btn").show(); 
                         }
					     else {
						     g.options.columns[17].hidden = true;
                         }
                    }
                    break;  
               case 'toThirdAuditNum':
                    { 
                        g.options.columns[0].hidden = false;
                        g.options.columns[12].hidden = false;
                        g.options.columns[13].hidden = false;
                        g.options.columns[14].hidden = false;
                        g.options.columns[15].hidden = false;
                        g.options.columns[11].hidden = true;
						 if (authority == 3) {
						     g.options.columns[17].hidden = false;
                             $("#batch_pass_btn").show(); 
                             $("#batch_reject_btn").show(); 
                             $("#batch_audit_btn").show(); 
                         }
					     else {
						     g.options.columns[17].hidden = true;
                         }
                    }
                    break;
               case 'failAuditNum':
                    {  
                        g.options.columns[12].hidden = false;
                        g.options.columns[13].hidden = false;
                        g.options.columns[14].hidden = false;
                        g.options.columns[15].hidden = false;
                        g.options.columns[11].hidden = true;
                    }
                    break;
               case 'passAuditNum':
                    { 
                        g.options.columns[12].hidden = false;
                        g.options.columns[13].hidden = false;
                        g.options.columns[14].hidden = false;
                        g.options.columns[15].hidden = false;
                        g.options.columns[11].hidden = true;
                    }
                    break;                                                                                                  
                default:
                    {
                               
                    }
                    break;
            }
            g.init('/goods/price/queryProductPriceManageList');            

        }
    },
    columns: [{
        name: "toFirstAuditNum",
        display: "待一审({toFirstAuditNum})"
    },{
        name: "toSecondAuditNum",
        display: "待二审({toSecondAuditNum})"
    },{
        name: "toThirdAuditNum",
        display: "待三审({toThirdAuditNum})"
    },{
        name: "failAuditNum",
        display: "驳回({failAuditNum})"
    }, {
        name: "passAuditNum",
        display: "通过({passAuditNum})"
    }, {
        name: "all",
        display: "全部({all})"
    }]
}).init(TABENUM.tips);

// 页面按键初始化
var initAuditButton = function() {
	// 默认进入全部tab页,不支持导出、通过、驳回、批量审核导入
	$("#batchExportChangePrice").hide();   // attr("disabled", true);
	$("#batch_pass_btn").hide(); // attr("disabled", true);
	$("#batch_reject_btn").hide(); // attr("disabled", true);
	$("#batch_audit_btn").hide(); // attr("disabled", true);
}

initAuditButton();



// tab初始化
var loadTab = function() {
    setTimeout(function() {
        common.util.__ajax({
            url: "/goods/price/ajax/auditCount",
            data: g.options.parms()
        }, function(res) {
            var __dt = $.extend({}, TABENUM.tips, res.data);
            t.setData(__dt);
            t.render(__dt);
        }, true);
    }, 400);
}

loadTab();

// 对float数字进行精度控制,保留小数点后4位
// 暂只支持字符串
var formatFloat = function(num) {
	var number = parseFloat(num);
	if (isNaN(number))
	    return "";
		
	return  Math.round(number * 10000) / 10000;
}

// 对百分比数进行格式化: xx.xx%
// 只支持字符串
var formatPercent = function(persent) {
	var str = formatFloat(persent) * 100;
	if (typeof str == 'number') {
	   return str +'%';	
	}
	
	return "";
}

var g = new common.grid({
    el: "#basicTable",
    usepagesize:true,
    parms: function() {
        var select = tabTree.getAddress();
        return {
            product_skn: common.util.__input("skn"),
            shop_id: common.util.__input("shop"),
            brand_id: common.util.__input("brand"),
            supplier_id: common.util.__input("supplier"),
            is_jit: common.util.__input("jit"),
            is_auditing: common.util.__input("status"),
            stock: common.util.__input("stock"),
            gender: common.util.__input("sex"),
            checkState: AuditEnum.status[t.getData().name],
            max_sort_id: select[0] ? select[0].id : "",
            middle_sort_id: select[1] ? select[1].id : "",
            small_sort_id: select[2] ? select[2].id : "",
            cooperationType : common.util.__input("cooperationType")
        }
    },
    columns: [{
            display: '',
            type: 'checkbox'
        },
        {
            display: '图片',
            name: 'product_pic_url',
            render: function (item) {
                if (item.product_pic_url) {
                    return '<a class="list-img" target="_blank" href="' + item.product_pic_url + '">' +
                        '<img src="' + item.product_pic_url + '"></a>';
                } else {
                    return '';
                }

        }},
        {display: '商品信息', render: function(item) {
            var html = '<p>SKN:'+item.product_skn +'</p><p>名称:' + item.product_name + '</p><p>品牌:' + item.brand_name + '</p>' +
                '<div>类目:'+'<br>'+ item.max_sort_name;
            if(item.middle_sort_name) {html += '&nbsp;>&nbsp;' + item.middle_sort_name;}
            if(item.small_sort_name) {html += '&nbsp;>&nbsp;' + item.small_sort_name;}
            html += "</div><p>";
            html += '<p>性别:'+ENUM.gender[item.gender]+'</p>';
            html += '<p>货品年:'+item.goodsYears+'</p>';
            html += '<p>货品季:'+ENUM.goodsSeason[item.goodsSeason]+'</p>';
            return html;  
        }},
        {display: '供应商/店铺', render: function(item) {
            var html = '';
            if (item.supplier_name) {
                html += item.supplier_name;
                if (item.shop_name) {html += '/';}
            }
            if (item.shop_name) {html += item.shop_name;}
            return html;
        }},
        {display: '日期信息', render: function(item) {
            var html = '<p>首次上架时间:'; 
                if(item.firstShelveTime) html += item.firstShelveTime +'</p>';
                else html += '</p>';
				
                html += '<p>最近入库:'+'<br>';
                 if(item.latestInStorageTime) html += item.latestInStorageTime +'</p>';
                else html += '</p>';
				
                html += '<p>最近一次变价申请时间:'+'<br>';
                 if(item.latestChangePriceTime) html += item.latestChangePriceTime +'</p>';
                else html += '</p>';

                if (item.checkState == '101' || item.checkState == '102' || item.checkState == '103') {
                    html += '<p>距离最近一次变价时间天数:'+'<br>'+item.latestChangePriceDays +'</p>';
                }
            return html;
        }},
        {display: '累计数据', render: function(item) {
             var html = '<p>进货量:'+'<br>';
                if(item.requestNums) html += item.requestNums +'</p>';
                else html += '</p>';
                 html += '<p>售罄率:'+'<br>';
                if(item.soldOutRate) html += formatPercent(item.soldOutRate) +'</p>';
                else html += '</p>';
            return html;
        }},
        {display: '近15天信息', render: function(item) {
            var html = '<p>销售量:'+'<br>';
                if(item.salesNums) html += item.salesNums +'</p>';
                else html += '</p>';

                 html += '<p>成交均价:'+'<br>';
                if(item.salesPerPrice) html += formatFloat(item.salesPerPrice) +'</p>';
                else html += '</p>';
            return html;
        }},
        {display: '库存信息', render: function(item) {
            var html = '<p>库存量:'+'<br>';
                if(item.nums) html += item.nums +'</p>';
                else html += '</p>';
                 html += '<p>周转天数:'+'<br>';
                if(item.days) html += item.days.toFixed(0) +'</p>';
                else html += '</p>';
            return html;
        }},
        {display: '当前售价', render: function(item) {
            var html = '<p>吊牌价:'+item.retail_price +'</p>';
                html += '<p>销售价:'+item.sales_price +'</p>';
                if (item.student_price) {html += '<p>学生价:'+item.student_price +'</p>';}                                  
            return html;
        }},
        {display: 'VIP折扣类型', render: function(item) {    
            return ENUM.vipType[item.vip_discount_type];
        }},
        {display: '会员价', render: function(item) {
            var html = '<p>VIP价:';
                if(item.vip_price) html += item.vip_price +'</p>';
                else html += '</p>';
                html += '<p>白金:'+'<br>';
                 if(item.vip3_price) html += item.vip3_price +'</p>';
                else html += '</p>';
                html += '<p>金卡:'+'<br>';
                 if(item.vip2_price) html += item.vip2_price +'</p>';
                else html += '</p>';
                html += '<p>银卡:'+'<br>';
                 if(item.vip1_price) html += item.vip1_price +'</p>';
                else html += '</p>';
            return html;
        }},
        {display: '库存成本价', render: function(item) {    
            return formatFloat(item.storagePerPrice);
        }}, 
         {display: '参考信息', render: function(item) {    
            var html = '<p>库存成本:'+'<br>';
                if(item.storagePerPrice) html += formatFloat(item.storagePerPrice) +'</p>';
                else html += '</p>';
                 
                 html += '<p>预估毛利率:'+'<br>';
                if(item.expectGrossProfitRate) html += item.expectGrossProfitRate+"%" +'</p>'; 
                else html += '</p>';
                
                html += '<p>建议销售价:'+'<br>';
                if(item.nums) html += 0 +'</p>';
                else html += '</p>';
                 
                html += '<p>降价幅度:'+'<br>';
                if(item.reductExtent) html += item.reductExtent + '%' +'</p>';
                else html += '</p>'; 
            return html;
        }}, 
         {display: '申请信息', render: function(item) {    
            var html = '<p>申请销售价:'+'<br>'+ item.expectSalesPrice +'</p>';
                html += '<p>申请销售价生效时间:'+'<br>'+ item.expectSalesPriceDate +'</p>';   
                if(item.cgpriceEndTime) html += '<p>申请销售价结束时间:'+'<br>'+ item.cgpriceEndTime +'</p>';   
                  
            return html;
        }},          
        {display: '状态', render: function(item) {  

            var html = '<p>'+TABENUM.statusStr[item.checkState]+'</p>';
                if(item.dealComment){
                    html += '<p><font color="red">'+item.dealComment +'</font></p>';
                }
            return html;
        }},
        {display: '违规类型', render: function(item) {    
            return item.illegalType;
        }},
        {display: '操作信息', render: function(item) {
            var html = '';
            if (item.founder_name) {html += '<p>' + item.founder_name + '</p>';}
            if (item.updateTime) {html += '<div style="color: #999;font-size: 12px">' + item.updateTime + '</div>';}
            return html;
        }},
        {display: '操作', render: function(item) {
            var html = '';          
            if (item.checkState == '101' || item.checkState == '103') {
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-success btn-xs audit-passs-btn"  data-planid="' + item.planId + '" style="margin-top: 10px">通过</a><br>';
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-danger btn-xs audit-reject-btn" data-planid="' + item.planId + '" style="margin-top: 10px">驳回</a><br>';
            } else if (item.checkState == '102') {
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-success btn-xs audit-passs-btn" data-planid="' + item.planId + '" style="margin-top: 10px">通过</a><br>';
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-danger btn-xs audit-reject-btn" data-planid="' + item.planId + '" style="margin-top: 10px">驳回</a><br>';
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-info btn-xs audit-to-third-btn" data-planid="' + item.planId + '" style="margin-top: 10px">转三审</a><br>';
            }  else if (item.checkState == '300') {
                html += '<a data-index="' + item.__index + '" href="javascript:;" data-planid="' + item.planId + '" class="btn btn-info btn-xs modify-btn" data-skn="' + item.product_skn + '" style="margin-top: 10px">修改</a><br>';
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-primary btn-xs history-btn" data-skn="' + item.product_skn + '" style="margin-top: 10px">变价记录</a>';
            } else{
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-info btn-xs modify-btn" data-skn="' + item.product_skn + '" style="margin-top: 10px">修改</a><br>';
                html += '<a data-index="' + item.__index + '" href="javascript:;" class="btn btn-primary btn-xs history-btn" data-skn="' + item.product_skn + '" style="margin-top: 10px">变价记录</a>';
            }
            return html;    
            }
        }]
});
g.options.columns[0].hidden = true;
g.options.columns[12].hidden = true;
g.options.columns[13].hidden = true;
g.options.columns[14].hidden = true;
g.options.columns[15].hidden = true;
g.init('/goods/price/list');

//获取变价记录列表并渲染
function getHistoryList(skn) {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: '/goods/queryProductPriceListBySkn',
        data: {param: skn},
        success: function (rs) {
            var data = rs;
            $('.historyDetail').html($(common.util.__template2($("#template2").html(), data.data)));
            if(data.code != 200){
                common.util.__tip(rs.message);
            }
        },
        error: function (rs) {
            $('.historyDetail').html($(common.util.__template2($("#template2").html(), {})));
            common.util.__tip(rs.message);
        }
    });
}
		
//修改变价时自动生成预估毛利率
$(document).on('blur', '.sale-price', function() {
    var parentTr = $(this).parent().parent();
    var $wrap = parentTr.next('.product-detail');
   
})

//单个变价修改
$(document).on('click', '.modify-btn', function() {

    var skn = $(this).data('skn'),
        parentTr = $(this).parent().parent(),
        sknTd = parentTr.find('td').eq(0),
        planId = $(this).data('planid');
        if(parentTr.next().hasClass('product-detail')){
            return false;
        }

        parentTr.after('<tr class="product-detail"><td colspan="15">加载中...若长时间加载不出来,请重新刷新页面!</td>' +
            '</tr><tr class="extraTr"></tr>');

        common.util.__ajax({
            url:'/goods/getPrice',
            data: {
                product_skn: skn,
                planId:planId
            }
        },function(rs){
            var data = rs.data;
            parentTr.next('.product-detail').html($(common.util.__template($("#template").html(), data)));
            new common.edit(".product-detail").init();

            var $wrap = parentTr.next('.product-detail'),
                $price = $wrap.find('.sale-price'),
                $select = $wrap.find('.discount-select'),
                $vipPrice = $wrap.find('.vip-price'),
                $vip3Price = $wrap.find('.vip3-price'),
                $vip2Price = $wrap.find('.vip2-price'),
                $vip1Price = $wrap.find('.vip1-price'),
                $student_price = $wrap.find('.student_price'),
                $startDate = $wrap.find('.startDate'),
                $endDate = $wrap.find('.endDate'),
                $submitBtn = $wrap.find('.sure-modify'),
                $planId = $wrap.find('.plan-id'),
                $expectGrossProfitRate = $wrap.find('.expect_gross_profit_rate');
            $select.val(data.vip_discount_type);
			
            vipPrice($wrap);
            $select.on('change', function() {
                vipPrice($wrap);
            });
            $vipPrice.on('blur', function() {
                vipPrice($wrap);
            });
            $price.on('blur', function() {
                vipPrice($wrap);
            });
            $submitBtn.on('click', function() {
				$submitBtn.attr('disabled', true);
                if($price.val() != 0){
                    common.util.__ajax2({
                        url: '/goods/updatePrice',
                        data: {
                            product_skn: skn,
                            sales_price: $price.val(),
                            vip_discount_type: $select.val(),
                            vip_price: $vipPrice.val(),
                            vip1_price: $vip1Price.val(),
                            vip2_price: $vip2Price.val(),
                            vip3_price: $vip3Price.val(),
                            student_price: $student_price.val(),
                            cgpriceStartTime:$startDate.val(),
                            cgpriceEndTime:$endDate.val(),
                            planId:$planId.val(),
                            expectGrossProfitRate:$expectGrossProfitRate.val(),
                            interfaceResource:'1'
                        }
                    }, function(res) {
						$submitBtn.attr('disabled', false);
                        if (res.code == 200) {
                            common.util.__tip("变价成功","success");
                            g.reload();
                            loadTab();}
                    }, function(res) {
						$submitBtn.attr('disabled', false);
					})
                }else{
                    common.util.__tip("销售价不能为0!");
                }
            });
        },true);


  

    function vipPrice($wrap) {
        var $price = $wrap.find('.sale-price'),
            $select = $wrap.find('.discount-select'),
            $vipPrice = $wrap.find('.vip-price'),
            $vip3Price = $wrap.find('.vip3-price'),
            $vip2Price = $wrap.find('.vip2-price'),
            $vip1Price = $wrap.find('.vip1-price'),
            $expectGrossProfitRate = $wrap.find('.expect_gross_profit_rate'),
            $storagePerPrice = $wrap.find('.storage_per_price');
        var price = $price.val(),
            vipPrice = $vipPrice.val(),
            selectVal = $select.val() - 1,
            priceArr = [];

        priceArr.push([price * 0.95, price * 0.9, price * 0.88]);
        priceArr.push([price * 0.95, price * 0.95, price * 0.95]);
        priceArr.push([price, price, price]);
        priceArr.push([vipPrice, vipPrice, vipPrice]);

        if (selectVal == 4) {
            $vip1Price.removeAttr('disabled');
            $vip2Price.removeAttr('disabled');
            $vip3Price.removeAttr('disabled');
        } else {
            $vip1Price.attr('disabled', true).val(Number(priceArr[selectVal][0]).toFixed(2));
            $vip2Price.attr('disabled', true).val(Number(priceArr[selectVal][1]).toFixed(2));
            $vip3Price.attr('disabled', true).val(Number(priceArr[selectVal][2]).toFixed(2));
        }
        if($storagePerPrice.val()){        
            $expectGrossProfitRate.val(((parseFloat($price.val()) - parseFloat($storagePerPrice.val()))*100 / parseFloat($price.val())).toFixed(2) );    
        }
        
    }
});

//关闭变价框                 
$(document).on('click', '.cancel-modify', function () {
    $(this).parents(".product-detail").remove();
    $(this).parents(".extraTr").remove();
})

//变价记录
$(document).on('click', '.history-btn', function () {
    var skn = $(this).data('skn');
    var option = {
        title:'变价记录详情',
        content:"<div class='historyDetail'>加载变价记录...</div>",
        width:'70%',
        button:[{value:"关闭", css:"btn-primary", callback: function () {
                 loadTab();
            }}]
    };
    new common.dialog(option);
    getHistoryList(skn);
});

//删除变价记录
$(document).on('click', '.deleteHistory', function () {
    var skn = $(this).data('skn');
    var planId = $(this).data('planid');
    new common.dialog({
        title: "删除变价记录确认",
        width: "360px",
        content: '确认删除该变价记录么?',
        zIndex: 52,
        button: [
            {value: "确认", css:"btn-primary", callback: function () {
                common.util.__ajax({
                    url: '/goods/deletePricePlan',
                    data: {param:planId}
                }, function () {
                    getHistoryList(skn);
                });
            }},
            {value: "取消", css:"btn-default"}
        ]
    });
});
//筛选
$(document).on('click', '#filter-btn', function () {
    g.reload(1);
    loadTab();
});
//回车筛选
$(document).on('keyup', 'body', function (event) {
    if (event.keyCode == 13) {
        $("#filter-btn").trigger('click');
    }
});
//全部
$(document).on('click', '#all-btn', function () {
    location.href = '';
});


/***********************审核***********************/
// 通过
var pricePass = {
    toast: function(content, fn) {
        var $this = $(this);
        common.dialog.confirm("温馨提示", content, function() {
            common.util.__disButton.call($this);
            common.util.__ajax({
                url: '/goods/price/pass',
                data: fn()
            }, function() {
                g.reload();
                loadTab();
            });
        });
    }
}

// 转三审
var priceToThirdCheck = {
    toast: function(content, fn) {
        var $this = $(this);
        common.dialog.confirm("温馨提示", content, function() {
            common.util.__disButton.call($this);
            common.util.__ajax({
                url: '/goods/price/pass',
                data: fn()
            }, function() {
                g.reload();
                loadTab();
            });
        });
    }
}

// 驳回
var priceReject = {
    toast: function(content, fn) {
        var $this = $(this);

        common.dialog.confirm("温馨提示", content, function() {
            common.util.__disButton.call($this);
            common.util.__ajax({
                url: '/goods/price/reject',
                data: fn()
            }, function() {
                g.reload();
                loadTab();
            });
        });
    }
}

//单个通过
$(document).on("click", ".audit-passs-btn", function() {
    var item = g.rows[$(this).data("index")];
    var data = function() {
        return {
            planIdList: JSON.stringify([item.planId]),
            currentState:item.checkState
        };
    }
    pricePass.toast.call(this, "你确定审核通过吗?", data);
});

//转三审
$(document).on("click", ".audit-to-third-btn", function() {
    var item = g.rows[$(this).data("index")];

    var data = function() {
        return {
            planIdList: JSON.stringify([item.planId]),
            currentState:item.checkState,
            targetState:103
        };
    }
    priceToThirdCheck.toast.call(this, "你确定要转三审吗?", data);
});

//单个驳回
$(document).on("click", ".audit-reject-btn", function() {
    var item = g.rows[$(this).data("index")];
    var data = function() {
        var reason = $('#rejectResult').val();
        if (reason === '' || $.trim(reason) === '') {
            return "请填写驳回原因";
        }
        return {
            planIdList: JSON.stringify([item.planId]),
            dealComment: reason
        };
    }
    priceReject.toast.call(this, $("#template3").html(), data);
});

//批量通过
$(document).on("click", "#batch_pass_btn", function() {
    var count = 0,
        selectedArr = g.selected,
        len = selectedArr.length,
        data = g.options.parms();

    var filter=$(".wqt_all").prop("checked");

    $.each(data, function(key, value) {
        if (value && value != '' && key != 'size' && key != 'tab') {
            count++;
        }else{
            delete data[key];
        }
    });
    if ((count > 0&&filter) || len > 0) {
        var planIdList=[];
        var checkState="";
        if (len > 0) {
            $.each(selectedArr, function(i, value) {
                planIdList.push(value['planId']);
                checkState = value['checkState'];
            });
        }
        var result=function(){
            return{
                    planIdList:JSON.stringify(planIdList),
                    currentState:checkState
                };
        }
        
        pricePass.toast.call(this, "你确定审核通过吗?", result);
    }else{
        common.util.__tip('请选择待通过的记录', 'warning');
        return;
    }
    
});


//批量驳回
$(document).on("click", "#batch_reject_btn", function() {

    var count = 0,
        selectedArr = g.selected,
        len = selectedArr.length,
        data = g.options.parms();
        
    var filter=$(".wqt_all").prop("checked");

    $.each(data, function(key, value) {
        if (value && value != '' && key != 'size' && key != 'tab') {
            count++;
        }else{
            delete data[key];
        }
    });

     if ((count > 0&&filter) || len > 0) {
        var planIdList=[];
        if (len > 0) {
            $.each(selectedArr, function(i, value) {
                planIdList.push(value['planId']);
            });
        }
        var result=function(){
            var reason = $('#rejectResult').val();
            if (reason === '' || $.trim(reason) === '') {
                return "请填写驳回原因";
            }

            return {
                    dealComment: reason,
                    planIdList:JSON.stringify(planIdList)
            }; 
        }
        priceReject.toast.call(this, $("#template3").html(), result);
    }else{
        common.util.__tip('请选择待驳回的记录', 'warning');
        return;
    }
    
});


/***********************批量功能***********************/
//批量导入按钮点击事件
$(document).on('click', '#import-btn', function () {
    $('#basicTable').hide();
    $('#priceTab').hide();
    $('#priceChangeSearch').hide();
    $('.bulk_import').show();
});

//批量通过按钮点击事件
$(document).on('click', '#batch_audit_btn', function () {
    $('#basicTable').hide();
    $('#priceTab').hide();
    $('#priceChangeSearch').hide();
    $('.bulk_batch_autdit').show();
});



/***********************批量导入***********************/

var loadModal = null;
var importPriceChangeData;
var path = ''; //确定变价后返回的excel名
var p = new common.grid({
    el: "#importResultTable",
    columns: [
        {display: 'SKN', render: function(item) {
            return item.newProductPriceBo.product_skn;
        }},
        {display: '吊牌价', render: function(item) {
            return '<p>'+item.newProductPriceBo.retail_price + '</p><div style="color: #999;">' + item.oldProductPriceBo.retail_price + '</div>';
        }},
        {display: '销售价', render: function(item) {
            var newPrice = item.newProductPriceBo,
                newPriceHtml = '<p>'+newPrice.sales_price+'</p>';
            if (newPrice.sales_price < (newPrice.retail_price / 2)) {
                newPriceHtml = '<p style="color: red">' + newPrice.sales_price + '</p>';
            }
            return newPriceHtml + '<div style="color: #999;">' + item.oldProductPriceBo.sales_price + '</div>';
        }},
        /*{display: '学生价', render: function(item) {
            var newPrice = item.newProductPriceBo,
                newPriceHtml = '';
            if (newPrice.student_price) {
                if (newPrice.student_price < (newPrice.retail_price / 2)) {
                    newPriceHtml = '<p style="color: red">' + newPrice.student_price + '</p>';
                }else{
                    newPriceHtml = '<p>'+newPrice.student_price+'</p>';
                }
            } else {
                newPriceHtml = '<p>-</p>'
            }
            if(item.oldProductPriceBo.student_price){
                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.student_price + '</div>';
            }else{
                newPriceHtml += '<div>-</div>';
            }
            return newPriceHtml;
        }},*/
        {display: 'VIP折扣类型', render: function(item) {
            return '<p>'+ENUM.vipType[item.newProductPriceBo.vip_discount_type] + '</p>'+
                '<div style="color: #999;">' + ENUM.vipType[item.oldProductPriceBo.vip_discount_type] + '</div>';
        }},
        {display: 'VIP价', render: function(item) {
            var newPrice = item.newProductPriceBo,
                newPriceHtml = '';
            if (newPrice.vip_price) {
                if (newPrice.vip_price < (newPrice.retail_price / 2)) {
                    newPriceHtml = '<p style="color: red">' + newPrice.vip_price + '</p>';
                }else{
                    newPriceHtml = '<p>'+newPrice.vip_price+'</p>';
                }
            } else {
                newPriceHtml = '<p>-</p>'
            }
            if(item.oldProductPriceBo.vip_price){
                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip_price + '</div>';
            }else{
                newPriceHtml += '<div>-</div>';
            }
            return newPriceHtml;
        }},
        {display: '白金价', render: function(item) {
            var newPrice = item.newProductPriceBo,
                newPriceHtml = '';
            if (newPrice.vip3_price){
                if (newPrice.vip3_price < (newPrice.retail_price / 2)) {
                    newPriceHtml = '<p style="color: red">' + newPrice.vip3_price + '</p>';
                }else{
                    newPriceHtml = '<p>'+newPrice.vip3_price+'</p>';
                }
            }else{
                newPriceHtml = '<p>-</p>'
            }
            if(item.oldProductPriceBo.vip3_price){
                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip3_price + '</div>';
            }else{
                newPriceHtml += '<div>-</div>';
            }
            return newPriceHtml;
        }},
        {display: '金卡价', render: function(item) {
            var newPrice = item.newProductPriceBo,
                newPriceHtml = '';
            if (newPrice.vip2_price){
                if (newPrice.vip2_price < (newPrice.retail_price / 2)) {
                    newPriceHtml = '<p style="color: red">' + newPrice.vip2_price + '</p>';
                }else {
                    newPriceHtml = '<p>'+newPrice.vip2_price+'</p>';
                }
            }else{
                newPriceHtml = '<p>-</p>'
            }
            if(item.oldProductPriceBo.vip2_price){
                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip2_price + '</div>';
            }else{
                newPriceHtml += '<div>-</div>';
            }
            return newPriceHtml;
        }},
        {display: '银卡价', render: function(item) {
            var newPrice = item.newProductPriceBo,
                newPriceHtml = '';
            if (newPrice.vip1_price){
                if (newPrice.vip1_price < (newPrice.retail_price / 2)) {
                    newPriceHtml = '<p style="color: red">' + newPrice.vip1_price + '</p>';
                }else{
                    newPriceHtml = '<p>'+newPrice.vip1_price+'</p>';
                }
            }else{
                newPriceHtml = '<p>-</p>'
            }
            if(item.oldProductPriceBo.vip1_price){
                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip1_price + '</div>';
            }else{
                newPriceHtml += '<div>-</div>';
            }
            return newPriceHtml;
        }},
        {display: '操作', render: function(item) {
            return '<a class="btn btn-danger btn-xs deleteImport" data-index="' + item.__index + '" href="javascript:;">删除</a>';
        }}
    ]
});

common.edit.ajaxfileupload("#priceChangeUpload", {
    params: {
        type: "price",
        __type: "batch-import"
    },
    onStart: function() {
        loadModal = common.dialog.load();
        clearImportResult()
    },
    onComplete: function(response) {
        console.log("批量接口返回数据",response);
        if (loadModal) loadModal.close();

        if(response.code == 200){
            if(response.data.failFileReason && response.data.failFileReason.length > 0){
                showImportMessage(response.data.failFileReason.join('<br/>'), "error");
            }else {
                showImportMessage("批量导入全部成功!", "success");
            }
            if(response.data.successList && response.data.successList.length > 0){
                showImportTable(response.data);
            }
        }else{
            showImportMessage(response.message, "error");
            common.util.__tip(response.message);
        }
    }
});

//显示批量导入结果
function showImportMessage(message, statue){
    $("#priceChangeImportMessage").removeAttr("class").addClass(statue).show();
    $("#detailMassage").html(message);
}
//显示批量导入数据表
function showImportTable(data){
    importPriceChangeData = data.successList;

    p.init(importPriceChangeData);
    $("#priceChangeImportResultSet").show();
    $("#priceChangeImportResult").show();
    new common.edit("#priceChangeImportResultSet").init();
}
//清除批量导入结果及列表
function clearImportResult(){
    $("#detailMassage").empty();
    $("#importResultTable").empty();
    $("#priceChangeImportResultSet input").val('');

    $('#download-btn').hide();
    $("#priceChangeImportMessage").hide();
    $("#priceChangeImportResultSet").hide();
    $("#priceChangeImportResult").hide();
}

//全部删除
$(document).on('click', '#deleteAllImport', function () {
    common.dialog.confirm(
        '删除确认提示',
        '你确定<b><font color="#ff0000">全部删除</font></b>已成功导入的变价么?',
        function () {
            importPriceChangeData.length = 0;
            p.reload();
        }
    );
});
//单个删除
$(document).on('click', '.deleteImport', function () {
    common.dialog.confirm(
        '删除确认提示',
        '你确定<b><font color="#ff0000">删除</font></b>该变价么?',
        function () {
            var index = $(this).data("index");
            if(importPriceChangeData){
                [].splice.call(importPriceChangeData,index,1);
                p.reload();
            }
        }
    );
});
//确定提交批量
$(document).on('click', '.btn-submit-priceChange', function () {
    if(importPriceChangeData.length < 1){
        common.util.__tip("没有可提交的变价,请重新导入!");
        return false;
    }
    common.dialog.confirm(
        '提交确认提示',
        '你确定<b><font color="#449d44">提交并保存</font></b>成功导入的变价么?',
        function () {
            var arr = [];
            $.each(importPriceChangeData, function(i, value) {
                arr.push(value.newProductPriceBo);
            });
            common.util.__ajax({
                url: '/goods/batchUpdatePrice',
                data: {
                    batchList: JSON.stringify(arr),
                    cgpriceStartTime:$('#importStartDate').val(),
                    cgpriceEndTime:$('#importEndDate').val(),
                    interfaceResource:'1'
                }
            }, function(res) {
                path = res.data;
                importPriceChangeData.length = 0;
                clearImportResult();
                if(path && path != ''){
                    $('#download-btn').show();
                }
            });
        }
    );
});
//下载导入结果
$(document).on('click', '#download-btn', function() {
    location.href = '/ajax/download?path=' + path;
});
//返回列表
$(document).on('click', '.return-btn', function () {
    if(path == ''){
        $("#priceChangeImportMessage").hide();
        $('#basicTable').show();
        $('#priceTab').show();
        $('#priceChangeSearch').show();
        $('.bulk_import').hide();
        $('.bulk_batch_autdit').hide();
        $('#message').html("");
    }else{
        location.href = '';
    }
});


/***********************批量导出***********************/
$("#batchExportChangePrice").click(function(){
    var count = 0,
        selectedArr = g.selected,
        len = selectedArr.length,
        data = g.options.parms();
        data.isAuditing=200;
    
     var select = tabTree.getAddress(); 
     var getResult=function(){
            return {
                product_skn: common.util.__input("skn"),
                shop_id: common.util.__input("shop"),
                brand_id: common.util.__input("brand"),
                supplier_id: common.util.__input("supplier"),
                is_jit: common.util.__input("jit"),
                is_auditing: common.util.__input("status"),
                stock: common.util.__input("stock"),
                gender: common.util.__input("sex"),
                checkState: AuditEnum.status[t.getData().name],
                max_sort_id: select[0] ? select[0].id : "",
                middle_sort_id: select[1] ? select[1].id : "",
                small_sort_id: select[2] ? select[2].id : "",
                cooperationType : common.util.__input("cooperationType")
            }
    }
    window.open("/ajax/down?queryConf=" + JSON.stringify(getResult()) + "&type=changePriceExport");

});


/***********************批量审核***********************/

var loadModal = null;
var uploadParam = function() {
    var checkState = 0;
    var name = t.getData().name;
    if (name == "toFirstAuditNum") {
        checkState = 101;
    } else if (name == "toSecondAuditNum") {
        checkState = 102;
    } else if (name == "toThirdAuditNum") {
        checkState = 103;
    } 

    return checkState;
}

function batchExport(el, type) {
    // 根据当前tab页的名称获取状态
    // 批量审核只允许这三种状态,其它都异常
    
    return {
        params: {
            type: type,
            __type: "batch-import",
            args: uploadParam()
        },
        onStart: function(params) {            
            var checkState = uploadParam();
            params.args = uploadParam();
            console.log("params:", params);

            loadModal = common.dialog.load();
            $("#message").html('');

            //$(el).parents('td').find('.file-name').text($(el).val().replace("C:\\fakepath\\", ""));
        },
        onComplete: function(response) {
            console.log("批量接口返回数据",response);
            $("#message").html('');
            if (response.code == 200&&response.data.taskId) {
                // __ajaxExeclById(response.data.taskId);
                // common.util.__tip(response.message, 'success');
                return;
            }
            if (loadModal) {
                loadModal.close();
            }
            if(response.data&&response.data.failFileReason.length){
                $("#message").html(response.data.failFileReason.join('<br/>'));
                return false;
            }
            common.util.__tip(response.message, 'warning');
        }
    }
}

/*展示平台*/
common.edit.ajaxfileupload('#priceAuditUpload', batchExport('', 'productPriceAudit'));