Index.js 36.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
'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,
        failAuditNum: 200,
        passAuditNum: 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;

        if (columnname == "all") {        
            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 {

            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;
                    }
                    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;
                    }
                    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;
                    }
                    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);


// 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();


var g = new common.grid({
    el: "#basicTable",
    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 : ""
        }
    },
    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.middle_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>预计上架时间:'+'<br>'+item.updateTime +'</p>';
                 html += '<p>最近入库:'+'<br>'+item.updateTime +'</p>';
                 html += '<p>最近一次变价时间:'+'<br>'+item.updateTime +'</p>';
                  if (item.checkState == '101' || item.checkState == '102' || item.checkState == '103') {
                    html += '<p>距离最近一次变价时间天数:'+'<br>'+0 +'</p>';
                  }
            return html;
        }},
        {display: '累计数据', render: function(item) {
             var html = '<p>进货量:'+'<br>'+ item.requestNums +'</p>';
                 html += '<p>售罄率:'+'<br>'+item.soldOutRate +'</p>';
            return html;
        }},
        {display: '近15天信息', render: function(item) {
             var html = '<p>销售量:'+'<br>'+ item.salesNums +'</p>';
                 html += '<p>成交均价:'+'<br>'+ item.salesPerPrice +'</p>';                
            return html;
        }},
        {display: '库存信息', render: function(item) {
            var html = '<p>库存量:'+'<br>'+ item.nums +'</p>';
                html += '<p>周转天数:'+'<br>'+ item.days +'</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价:'+item.vip_price +'</p>';
                html += '<p>白金:'+item.vip3_price +'</p>';
                html += '<p>金卡:'+item.vip2_price +'</p>';
                html += '<p>银卡:'+item.vip1_price +'</p>';
            return html;
        }},
        {display: '库存成本价', render: function(item) {    
            return item.storagePerPrice;
        }}, 
         {display: '参考信息', render: function(item) {    
            var html = '<p>库存成本:'+'<br>'+ item.storagePerPrice +'</p>';
                html += '<p>预估毛利率:'+'<br>'+ 0 +'</p>';  
                html += '<p>建议销售价:'+'<br>'+ 0 +'</p>';
                html += '<p>降价幅度:'+'<br>'+ 0 +'</p>';    
            return html;
        }}, 
         {display: '申请信息', render: function(item) {    
            var html = '<p>申请销售价:'+'<br>'+ item.expectSalesPrice +'</p>';
                html += '<p>申请销售价生效时间:'+'<br>'+ item.expectSalesPriceDate +'</p>';      
            return html;
        }},          
        {display: '状态', render: function(item) {  

            var html = '<p>'+TABENUM.statusStr[item.checkState]+'</p>';
                if(item.dealComment!="undefined"){
                    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.product_skn + '" 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.product_skn + '" 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.product_skn + '" 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.product_skn + '" 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.product_skn + '" style="margin-top: 10px">转三审</a><br>';
            } 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('click', '.modify-btn', function() {

    var skn = $(this).data('skn'),
        parentTr = $(this).parent().parent(),
        sknTd = parentTr.find('td').eq(0);

        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: {param: skn}
        },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');
            $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() {
                if($price.val() != 0){
                    common.util.__ajax({
                        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(),
                            interfaceResource:'1'
                        }
                    }, function(res) {
                        if (res.code == 200) {g.reload()}
                    })
                }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');

        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));
        }
    }
});

//关闭变价框                 
$(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"}]
    };
    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);
});
//回车筛选
$(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 == ''){
        $('#basicTable').show();
        $('#priceTab').show();
        $('#priceChangeSearch').show();
        $('.bulk_import').hide();
        $('.bulk_batch_autdit').hide();

    }else{
        location.href = '';
    }
});



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

var loadModal = null;

function batchExport(el, type) {
    return {
        params: {
            type: type,
            __type: "batch-import"
        },
        onStart: function(params) {            
            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'));