goodsList.html 32.2 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
<include file="public/layout"/>
<link href="__PUBLIC__/static/css/base_add.css" rel="stylesheet" type="text/css">
<link href="__PUBLIC__/static/css/seller_center_add.css" rel="stylesheet" type="text/css">
<script src="__PUBLIC__/js/xlsx.core.min.js"></script>

<style type="text/css">
    .import{
        color:#ff3c3c;
    }
    .point{
        position: fixed;
        left: 50%;
        top: 50%;
        width: 300px;
        height: 200px;
        margin: -100px 0px 0px -150px;
        z-index: 1;
    }
    .rates{
        width: 100%;
        height: 40px;
        padding-top: 10px;
        text-align: center;
    }
    .rate{
        font-size: 30px;
        margin-left: 25px;
    }
    .rim{
        position: fixed;
        left: 50%;
        top: 64%;
        width: 478px;
        height: 176px;
        margin: -98px -240px;
        z-index: 1;

    }
    .name-coad{
        width:250px;
        height: 50px;
        border: 2px solid #D7D7D7;
        line-height: 50px;
    }
    .ht{
        width:250px;
        height: 250px;
    }
    .val{
        width: 98%;
        height: 127px;
        margin: 1px;
        line-height: 27px;
        padding-left: 5px;
        display: -webkit-inline-flex;
    }
    .name-coad{
        width:250px;
        height: 250px;
        border: 2px solid #D7D7D7;
    }
    .pop{
        width: 300px;
        height: 200px;
        background: #fff;
        padding: 20px;
        /* 重点样式 */
        border: 8px solid rgba(255,255,255,.5);
        background-clip: padding-box;
    }
    .mongolia{
        width:100%;
        height:100%;
        left:0;top:0;
        position:fixed;
        background:rgba(0,0,0,0.1);
        z-index: 999;
        display:none;
    }
    .dn {
        display: none;
    }

    .layermbox {
        text-align: center;
    }

    .layer_box {
        font-size: 0;
        background-color: #FFFFFF;
        text-align: center;
        position: absolute;
        left: 60%;
        border: 1px solid #D7D7D7;
        padding: 10px;
        z-index: 9999;
    }

    .contentTxt {
        width: 300px;
        height: 20px;
        line-height: 20px;
        resize: none;
        border: 1px solid #D7D7D7;
        background-color: #999;
    }

    .contentTxt:hover {
        border-color: #C4182E;
    }

    .layer_box input {
        vertical-align: middle;
    }

    .copySuccess {
        font-size: 14px;
        width: 150px;
        padding: 10px;
        background-color: #FFFFFF;
        border: 1px solid #D7D7D7;
        margin: auto;
    }

    .js-copy {
        font-size: 14px;
        vertical-align: middle;
        display: inline-block;
        *display: inline;
        *zoom: 1;
        cursor: pointer;
        border: 1px solid #D7D7D7;
        border-left: 0;
        height: 22px;
        padding: 0 5px;
    }

    .js-copy:hover {
        background-color: #EEEEEE;
    }

    .ware_ewm1 {
        padding: 10px;
        position: relative;
        border-bottom: 1px #f1f1f1 solid;
        border-top: 1px #f1f1f1 solid;
        display: inline-block;
        *zoom: 1;
        *display: inline;
        vertical-align: middle;
    }

    .ware_ewm1 .sjbox {
        position: absolute;
        width: 11px;
        height: 14px;
    }

    .ware_ewm1 .lt {
        left: 0;
        top: 0;
        border-top: 1px #000 solid;
        border-left: 1px #000 solid
    }

    .ware_ewm1 .rt {
        right: 0;
        top: 0;
        border-top: 1px #000 solid;
        border-right: 1px #000 solid
    }

    .ware_ewm1 .lb {
        left: 0;
        bottom: 0;
        border-bottom: 1px #000 solid;
        border-left: 1px #000 solid
    }

    .ware_ewm1 .rb {
        right: 0;
        bottom: 0;
        border-bottom: 1px #000 solid;
        border-right: 1px #000 solid
    }

    .ware_ewm1 .ewm1 {
        width: 170px;
        height: 170px;
    }
    .close{
        width: 30px;
        height: 30px;
        float: right;
    }
    .texts{
        margin-left: 42px;
        font-size: 15px;
        margin-top: 25px;
    }
    .fail{
        width: 55px;
        height: 55px;
        margin-top: 20px;
        margin-left: 32px;

    }
    .sure{
        width: 101%;
        height: auto;
        display: flex;

    }
    .download{
        width: 50%;
        height: 49px;
        line-height: 49px;
        text-align: center;
        background-color: #ee5050;
        color: #fff;
        font-size: 17px;
    }
    .cancel{
        width: 49%;
        height: 47px;
        line-height: 47px;
        text-align: center;
        font-size: 17px;

        border: 1px solid #b6b6b6;
    }

    .downloads{
        width: 30px;
        height:30px;
        position: relative;
        right: 14px;
        top: 4px;
    }

</style>

<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="ftitle">
                <h3>商品管理</h3>
                <h5>(共<span id="good_count"></span>条记录)</h5>
                <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            </div>
        </div>
    </div>

</div>
<div class="flexigrid">
    <div class="mDiv mDivHA">
        <form action="{:U('Admin/Goods/exportreport')}" id="search-form2" class="navbar-form form-inline" method="get"
              onSubmit="return false" style="float: right;">
            <input type="hidden" value="{$cur_page}" id="cur_page">
            <input type="hidden" value="{$iscontent}" id="iscontent" name="iscontent">
            <if condition="$Think.const.ACTION_NAME eq 'goodsList'">
                <input type="hidden" name="goods_state" value="{$_GET['goods_state']|default='0,2,3'}"/>
                <else/>
                <input type="hidden" name="goods_state" value="1"/>
            </if>
            <input type="hidden" name="order1" value="{$order1}"/>
            <input type="hidden" name="order2" value="{$order2}"/>
<input type="text" size="2" maxlength="3" name="pagenum" class="qsbox" style="vertical-align: middle;"
                    value="{$pagenum}">条/页&nbsp;&nbsp;
            所有分类
            <select name="cat_id" id="cat_id" class="select" onkeydown="strkeydown(event, this, 'submitBtn')">
                <option value="">所有分类</option>
                <foreach name="categoryList" item="v" key="k">
                    <option
                    <if condition="$cat_id eq $v['id']">selected="selected"</if>
                    value="{$v['id']}">{$v['name']}</option>
                    <foreach name="v.children" item="v1" key="k1">
                        <option <if condition="$cat_id eq $v1['id']">selected="selected"</if>  value="{$v1['id']}">&nbsp;&nbsp;&nbsp;&nbsp;|—&nbsp;{$v1['name']}</option>

                        <foreach name="v1.children" item="v2" key="k2">
                            <option <if condition="$cat_id eq $v2['id']">selected="selected"</if>  value="{$v2['id']}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|—&nbsp;{$v2['name']}</option>
                        </foreach>

                    </foreach>
                </foreach>
            </select>
            所有品牌
            <select name="brand_id" id="brand_id" class="select" onkeydown="strkeydown(event, this, 'submitBtn')">
                <option value="">所有品牌</option>
                <foreach name="brandList" item="v" key="k">
                    <option
                    <if condition="$brand_id eq $v['id']">selected="selected"</if>
                    value="{$v['id']}">{$v['name']}</option>
                </foreach>
            </select>
            上/下架
            <select name="is_on_sale" id="is_on_sale" class="select" onkeydown="strkeydown(event, this, 'submitBtn')">
                <option value="-1">全部</option>
                <option value="1"
                <if condition="$is_on_sale eq 1">selected="selected"</if>
                >上架</option>
                <option value="0"
                <if condition="$is_on_sale eq 0">selected="selected"</if>
                > 下架</option>
            </select>

            商品标签
            <select name="intro" class="select" onkeydown="strkeydown(event, this, 'submitBtn')">
                <option value="0">全部</option>
                <option value="is_new"
                <if condition="$intro eq is_new">selected="selected"</if>
                >新品</option>
                <option value="is_recommend"
                <if condition="$intro eq is_recommend">selected="selected"</if>
                >推荐</option>
                <option value="is_hot"
                <if condition="$intro eq is_hot">selected="selected"</if>
                >热卖</option>

                <option value="promtype1" <if condition="$intro eq promtype1">selected="selected"</if>
                >秒杀商品</option>
                <option value="promtype2" <if condition="$intro eq promtype2">selected="selected"</if>
                >团购商品</option>
                <option value="promtype3" <if condition="$intro eq promtype3">selected="selected"</if>
                >促销优惠(不查询全场)</option>
                <option value="promtype4" <if condition="$intro eq promtype4">selected="selected"</if>
                >积分购</option>
                <option value="promtype6" <if condition="$intro eq promtype6">selected="selected"</if>
                >天天拼单</option>


            </select>


            运费设置
            <select name="exp_sum_type" class="select" onkeydown="strkeydown(event, this, 'submitBtn')">
                <option value="0">全部</option>
                <option value="1">统一运费</option>
                <option value="2">按件数</option>
                <option value="3">按重量</option>
            </select>
            分销类型
            <select name="dis_type" class="select" onkeydown="strkeydown(event, this, 'submitBtn')">
                <option value="-1">全部</option>
                <option value="0"
                <if condition="$dis_type eq 0">selected="selected"</if>
                >主营</option>
                <option value="1"
                <if condition="$dis_type eq 1">selected="selected"</if>
                >可选 </option>

            </select>
            <div class="sDiv2">
                <input class="qsbox" style="width: 80px;" placeholder="搜索词" name="key_word"
                       value="{:urldecode($key_word)}" type="text">
                <input class="btn" value="搜索" type="submit" onclick="ajax_get_table('search-form2',1)">
            </div>
        </form>
        <div class="clear"></div>
    </div>
    <div class="tDiv">
        <div class="tDiv2">
            <div class="fbutton">
                <a href="{:U('Admin/goods/addEditGoods')}">
                    <div class="add" title="添加商品">
                        <span><i class="fa fa-plus"></i>添加商品</span>
                    </div>
                </a>
            </div>

            <div class="fbutton">
                <a href="javascript:ajax_exportreport('search-form2',1)">
                    <div class="add" title="导出数据">
                        <span><i class="fa fa-file-excel-o"></i>导出数据</span>
                    </div>
                </a>
            </div>

            <div class="fbutton">
                <a href="javascript:batchedit('search-form2',1)">
                    <div class="edit" title="批量修改">
                        <span><i class="fa fa-edit"></i>批量修改</span>
                    </div>
                </a>
            </div>

            <div class="fbutton">
               <select name="batchtype" id="batchtype" class="select" onkeydown="strkeydown(event, this, 'submitBtn')">
                    <option value="1">运费方式</option>
                    <option value="2">品牌</option>
                    <option value="3">国别</option>
                    <option value="4">类别</option>
                    <option value="5">上架/下架</option>
                    <option value="6">配送方式</option>
                   <option value="7">是否积分</option>
                </select>

                <a href="javascript:batchedit1()" style="float: right">
                    <div class="edit" title="选项修改">
                        <span><i class="fa fa-edit"></i>选项修改</span>
                    </div>
                </a>
            </div>

            <div class="fbutton" id="btnremove">
                <div class="edit" title="清除三级分成">
                    <span><i class="fa fa-remove"></i>清除三级分成</span>
                </div>
            </div>

            <div class="fbutton" id="goodslist">
                <div class="add" title="导入商品"style="position:relative">
                    <a data-toggle="modal" data-target="#adminModal">
                        <span class="import"><input type="file" id="excel-file" style="opacity:0;width:90px;height:100%;position:absolute;top:0;left:0;">导入商品</span></a>
                </div>
            </div>

            <div class="fbutton" >

                <a  href="__PUBLIC__/text_format.xls">
                    <div class="edit" title="下载导入格式" style="overflow:hidden;border-color:#fafafa;background:#fafafa; " >
                        <img class="downloads" src="__PUBLIC__/images/download.png">
                    </div>
                </a>


            </div>

            <div  class="mongolia" >
                <div class="point">
                    <div class="pop">
                        <div onclick="closess()">
                            <img class="close" src="__PUBLIC__/images/cancels.png" >
                        </div>
                        <img id="imgs"style=" margin: 10px 103px;width: 100px;height: 100px;" src="__PUBLIC__/images/timg.gif">
                        <div class="rates">
                            <text class="rate">0%</text>
                        </div>
                    </div>
                </div>
            </div>



        </div>
        <div style="clear:both"></div>
    </div>
    <div class="bDiv" style="height: auto;">
        <!--ajax 返回 -->
        <div id="ajax_return" cellpadding="0" cellspacing="0" border="0"></div>
    </div>
    <div class="sDiv" style="float:left;margin:10px 0 20px 0">
    </div>
    <div class="clear"></div>
</div>
</div>


<!--模板的预览界面-->
<div class="laybox1 dn">
    <dl style="text-align: center;color: #333;">
        <dt style="font-size: 16px;margin-top: 10px">请用微信扫一扫预览</dt>
        <dd style="margin-top: 20px">
            <div class="ware_ewm1">
                <div id="ewm_box11" class="ewm1">
                    <img id="ewm_box_img11" style="width: 100%; height: 100%" src="" alt=""/>
                </div>
                <span class="sjbox lt"></span>
                <span class="sjbox rt"></span>
                <span class="sjbox lb"></span>
                <span class="sjbox rb"></span>
            </div>
        </dd>
        <dt style="heihgt:10px">&nbsp;</dt>
    </dl>
</div>

<script>
    $(document).ready(function () {
        // 表格行点击选中切换
        $('#ajax_return').on('click', 'table>tbody >tr', function () {
            $(this).toggleClass('trSelected');
            var checked = $(this).hasClass('trSelected');
            $(this).find('input[type="checkbox"]').attr('checked', checked);
        });
        // 刷选条件 鼠标 移动进去 移出 样式
        $(".hDivBox > table > thead > tr > th").mousemove(function () {
            $(this).addClass('thOver');
        }).mouseout(function () {
            $(this).removeClass('thOver');
        });
    });
</script>
<script>
    $(document).ready(function () {
        // 点击刷新数据
        $('.fa-refresh').click(function () {
            location.href = location.href;
        });
        if ($("input[name='order1']").val() == "") {
            $("input[name='order1']").val("goods_id");
            $("input[name='order2']").val("desc");
        }
        // ajax 加载商品列表
        ajax_get_table('search-form2', $("#cur_page").val());

//            sort($("input[name='order1']").val());
    });

    // ajax 抓取页面 form 为表单id  page 为当前第几页
    function ajax_get_table(form, page) {
        cur_page = page; //当前页面 保存为全局变量
        layer.msg('加载中...', {
            icon: 16,
            shade: [0.5, '#f5f5f5'],
            scrollbar: false,
            offset: '200px',
            time: 100000
        });

        $.ajax({
            type: "POST",
            url: "/index.php?m=Admin&c=goods&a=ajaxGoodsList&p=" + page, //+tab,
            data: $('#' + form).serialize(), // 你的formid
            success: function (data) {
                $("#ajax_return").html('');
                $("#ajax_return").append(data);
                layer.closeAll();
            }
        });
    }

    // 点击排序
    function sort(field) {
        $("input[name='order1']").val(field);
        var v = $("input[name='order2']").val() == 'desc' ? 'asc' : 'desc';
        $("input[name='order2']").val(v);
        ajax_get_table('search-form2', cur_page);
    }
    // 同步条码
    function updatesku(erpwareid) {
        if (!confirm('确定同步线下商品条码、零售价及商品编号吗?'))
            return false;
        $.ajax({
            url: "/index.php?m=Admin&c=goods&a=updatesku&erpwareid=" + erpwareid,
            success: function (v) {
                var v = eval('(' + v + ')');
                if (v.hasOwnProperty('status') && (v.status == 1))
                {
                    layer.msg("同步成功", {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function () {
                        ajax_get_table('search-form2', cur_page);
                    },1000);
                }
                else {
                    layer.msg(v.msg, {
                        icon: 2,
                        time: 1000
                    }); //alert(v.msg);
                }
            }
        });
        return false;
    }

    // 按商品编码同步条码和ID
    function updatewareno(erpwareno) {
        if (!confirm('确定同步线下商品条码、零售价及商品ID吗?'))
            return false;
        $.ajax({
            url: "/index.php?m=Admin&c=goods&a=updatewareno&erpwareno=" + erpwareno,
            success: function (v) {
                var v = eval('(' + v + ')');
                if (v.hasOwnProperty('status') && (v.status == 1))
                {
                    layer.msg("同步成功", {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function () {
                        ajax_get_table('search-form2', cur_page);
                    },1000);
                }
                else {
                    layer.msg(v.msg, {
                        icon: 2,
                        time: 1000
                    }); //alert(v.msg);
                }
            }
        });
        return false;
    }
    // 删除操作
    function del(id) {
        if (!confirm('确定要删除吗?'))
            return false;
        get_event_log('1', '删除商品');
        $.ajax({
            url: "/index.php?m=Admin&c=goods&a=delGoods&id=" + id,
            success: function (v) {
                var v = eval('(' + v + ')');
                if (v.hasOwnProperty('status') && (v.status == 1))
                    ajax_get_table('search-form2', cur_page);
                else
                    layer.msg(v.msg, {
                        icon: 2,
                        time: 1000
                    }); //alert(v.msg);
            }
        });
        return false;
    }

    function changeTableVal3(tb, idn, id, cfield, ob) {
        //判断商品是否在做活动
        if ($(ob).hasClass('yes')) {
            $.ajax({
                url: "/index.php/admin/goods/isinactive/gid/" + id,
                dataType: "json",
                success: function (data) {
                    if (data.code == -1) {
                        changeTableVal(tb, idn, id, cfield, ob);
                    } else {
                        layer.msg("该商品正在" + data.msg, {icon: 2, time: 1000});
                    }

                }
            });
        } else {
            changeTableVal(tb, idn, id, cfield, ob);
        }
    }

    /*---修改库存时候---*/
    function changeTableVal5(tb, idn, id, cfield, ob) {
        var val = $(ob).val();
        //alert(val);
        //判断商品是否在做活动
        $.ajax({
            url: "/index.php/admin/goods/isstorage/gid/" + id + "/count/" + val,
            dataType: "json",
            success: function (data) {
                if (data.code == 1) {
                    changeTableVal(tb, idn, id, cfield, ob);
                } else {
                    $(ob).val(data.count)
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }
            }
        });
    }


    // 导出数据
    function ajax_exportreport(form, page) {
        cur_page = page; //当前页面 保存为全局变量
        location.href = "/index.php?m=Admin&c=goods&a=exportreport&p=" + page +"&"+ $('#' + form).serialize();
    }

    //批量修改价格,可售,已售
    function batchedit(form, page){
        cur_page = page; //当前页面 保存为全局变量
        page=$("#cur_page").val();
        var ids = get_select_goods_id_str();
        if (ids == false) {
            layer.alert('请勾选要操作的商品', {icon: 2});
            return;
        }
        var url = "/index.php?m=Admin&c=Goods&a=batchedit&p=" + page +"&ids=" + ids+"&"+ $('#' + form).serialize();

        layer.open({
            type: 2,
            title: '批量修改',
            shadeClose: true,
            shade: 0.3,
            area: ['550px', '200px'],
            content: url,
        });
    }
    //批量修改价格,可售,已售
    function batcheditclose() {
        layer.closeAll();
        ajax_get_table('search-form2', $("#cur_page").val());
    }

    //获取选中商品id
    function get_select_goods_id_str() {
        if ($('input[name="goods_id\[\]"]:checked').length == 0)
            return false;
        var goods_arr = Array();
        $('input[name="goods_id\[\]"]:checked').each(function () {
            goods_arr.push($(this).val());
        });
        var goods_id_str = goods_arr.join(',');
        return goods_id_str
    }

    //批量修改1
    function batchedit1(){

        var ids = get_select_goods_id_str();
        if (ids == false) {
            layer.alert('请勾选要操作的商品', {icon: 2});
            return;
        }

        var  page=$("#cur_page").val();
       var batchtype=$("#batchtype").val();
        var url = "/index.php?m=Admin&c=Goods&a=batchedit1&p=" + page +"&batchtype=" + batchtype+"&ids=" + ids;
        layer.open({
            type: 2,
            title: '批量修改',
            shadeClose: true,
            shade: 0.3,
            area: ['550px', '200px'],
            content: url,
        });
    }

    function show_mobile_man(ob) {

        var html="{:curHostURL()}"+$(ob).attr('b_href');
        var url="/index.php?m=home&c=index&a=qr_code&data="+encodeURIComponent(html);
        $("#ewm_box_img11").attr('src',url);
        var LayerId = layer.open({
            type: 1,
            title: ['二维码扫码', 'font-size:14px;'],
            skin: 'layui-layer-rim', //加上边框
            area: ['300px', 'auto'], //宽高
            content: $('.laybox1'),
            cancel: function () {},
        });
    }

    function updateerpinfo(erpwareid,erpwareno) {
        //询问框

        layer.confirm('您是如何看待前端开发?', {
            btn: ['重要','奇葩'] //按钮
        }, function(){
            layer.msg('的确很重要', {icon: 1});
        }, function(){
            layer.msg('也可以这样', {
                time: 20000, //20s后自动关闭
                btn: ['明白了', '知道了']
            });
        });
    }


    //导入商品表格
    $('#excel-file').change(function (e) {
        $(".rate").text("0%");
        var files = e.target.files;
        var fileReader = new FileReader();
        fileReader.onload = function (ev) {
            try {
                var data = ev.target.result
                var workbook = XLSX.read(data, {
                    type: 'binary'
                }) // 以二进制流方式读取得到整份excel表格对象
                var persons = []; // 存储获取到的数据
            } catch (e) {
                console.log('文件类型不正确');
                return;
            }

            // 表格的表格范围,可用于判断表头是否数量是否正确
            var fromTo = '';
            // 遍历每张表读取
            for (var sheet in workbook.Sheets) {

                if (workbook.Sheets.hasOwnProperty(sheet)) {
                    fromTo = workbook.Sheets[sheet]['!ref'];
                    console.log("数量", fromTo);
                    var file = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
                    persons = persons.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
                    var file = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
                    var p=0;

                    recursion(file,p);

                    break; // 如果只取第一张表,就取消注释这行
                }
            }
            //在控制台打印出来表格中的数据
            console.log("数据", persons.length);
        };
        // 以二进制方式打开文件
        fileReader.readAsBinaryString(files[0]);

    })

    var err_data=new Array();//商品编码
    var s=0;//控制清空的
    var uu;
    //点击关闭导入的进度弹层
    function closess() {
        $(".mongolia").hide();
        var p=6;
        var file=0;
        recursion(file,p);
    }

    // 选择本地表递归传到后台
    function recursion(file,p) {
        console.log("gaorr");
        if( file==0&&p==6) return ;
        $(".mongolia").show();
        if (file.length < p * 20) return;
        var is_last=0;
        var fir = p * 20;
        var end = (p + 1) * 20;
        //  console.log("数据8888888",file.length);
        if (end >= file.length){ end = file.length;is_last=1;}
        var persons = new Array();
        for (var i = fir; i < end; i++) {
            persons.push(file[i]);
        }
        var url = "/index.php?m=Admin&c=Goods&a=goodsImport";
        var json_str = JSON.stringify(persons);
        // console.log("传到后台的数据"+json_str);
        $.ajax({
            type: "POST",
            url:url,
            data:{data:json_str,page:p,is_last:is_last},// 你的formid
            dataType:"json",
            success: function (data){
                msg=data.arrs;
                console.log(data.lengths+"data.code是什么"+data.code+"data.err_data"+data.err_data);
                if(data.code==0){
                    console.log($("#rate").text()+Math.round(end / file.length * 10000) / 100.00+"%");
                    $(".rate").text(Math.round(end / file.length * 10000) / 100.00+"%");
                    if(data.err_data!=null){
                        for(var j=0;j<data.err_data.length;j++){
                            //装未插入的商品编号数据
                            err_data.push(data.err_data[j])
                        }
                    }
                    if(data.cat_data!=null){
                        for(var j=0;j<data.cat_data.length;j++){
                            //装未插入的品类数据
                            err_data.push(data.cat_data[j])
                        }
                    }
                    if(data.brand_data!=null){
                        for(var j=0;j<data.brand_data.length;j++){
                            //装未插入的品牌数据
                            err_data.push(data.brand_data[j])
                        }
                    }

                    if(data.nation_data!=null){
                        for(var j=0;j<data.nation_data.length;j++){
                            //装未插入的数据
                            err_data.push(data.nation_data[j])
                        }
                    }
                    if(err_data==0){
                        $(".mongolia").hide();//关闭转圈圈
                        console.log(err_data+"是什么");
                        alert("操作完成");
                        history.go(0);
                        return false;
                    }
                    console.log("还往下面走吗");

                    if(is_last==1){
                        $(".mongolia").hide();

                        //完成的
                        var htmls="<div class=\"rim\">";
                        htmls += "<div class=\"val\">";
                        htmls +=" <img class=\"fail\" src=\"__PUBLIC__/images/icon_no.png\" >";
                        htmls += "<text class=\"texts\">"+"导入完成,成功导入"+data.arrs+"个商品,另有"+err_data.length+"条信息"+'</br>'+'格式存在问题不能成功导入,您可以下载错误数'+'<br>'+'据,修改后重新上传!'+"</text>";
                        htmls += "</div>";
                        htmls += "<div class=\"sure\">";
                        htmls +="<div class=\"download\"  onclick=\"download()\">"+"下载"+"</div>";
                        htmls +="<div class=\"cancel\"  onclick=\"cancel()\">"+"取消"+"</div>";
                        htmls +="</div>";
                        htmls +="</div>";
                        uu=layer.open({
                            type:1,
                            title:"导入商品 ",
                            skin: 'layui-layer-demo',
                            area: ['480px', '220px'], //宽高

                            cancel: function(){
                                //右上角关闭回调
                                //return false 开启该代码可禁止点击该按钮关闭
                                history.go(0);
                            },content:htmls,
                        });


                        if(s==1) {
                            console.log("有进来清空吗"+s);
                            err_data = [];//清空
                        }
                        return false;
                    }
                    p++;
                    recursion(file,p)

                }else{
                    alert(data.msg);
                    return "";
                }
            }
        })


    }
    // 取消关闭layer
    function cancel() {
        layer.close(uu);
        history.go(0);
    }

    function download() {
        console.log("点击下载"+err_data);
        var str="导入商品失败的详细信息:"+"\n";
        for(var i = 0 ; i < err_data.length ; i++ ){

            str+=err_data[i]+ "\t";
            console.log("循环中"+str);
            str+='\n';

        }
        console.log("循环后的"+str);
        //encodeURIComponent解决中文乱码
        var uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
        //通过创建a标签实现
        var link = document.createElement("a");
        link.href = uri;
        //对下载的文件命名
        link.download =  "商品导入失败信息表.csv";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        s=1;

    }


    //清除三级分成
    $("#btnremove").click(function () {
        layer.confirm('确认清除所有商品的三级分成?', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                url: "/index.php/admin/goods/goodsThirRemove",
                dataType: "json",
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg('操作成功', {icon: 1});
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000});
                    }
                }
            });

        }, function () {
            layer.closeAll();
        });
    })


</script>
<script src="__PUBLIC__/js/clipboard.min.js"></script>

</body>

</html>