index.js 40.0 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
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
const app = getApp();
var qqmapsdk;
qqmapsdk = new QQMapWX({
        key: 'KLXBZ-KAFCF-6LVJZ-JQAAL-NCI65-XTF52'
});
Page({
        /**
         * 页面的初始数据
         */
        data: {
                st: 0,
                zhen: true,
                imgUrl: app.globalData.imgUrl,
                scrollLeft: 0, //tab标题的滚动条位置
                city: '',
                imgUrls: [
                        1, 2, 2
                ],
                num: 4,
                count: 2,
                erji: 3,
                current_index: 0,
                showad: true, //首页广告控制显示
                popup_state: false,
                nav: 0,
                flag: false,
                all: false,
                currentIndex: 0,
                hotList: [],
                category: [],
                photo: [],
                banner: {},
                special: [],
                state: 0,
                product_item: [],
                cookCategory: [],
                goods: [],
                two_banner: [],
                select: [],
                select_item: [],
                id: 0,
                currnetindexs: 0,
                mainindex: 0,
                main: 0,
                c: null,
                i: null,
                main_id: 0,
                ids: [],
                idss: [],
                new_person: [],
                banner_state: true,
                show_cart_mask: false,
                goods_id: 0,
                cart_goods: {},
                item: 1,
                goods_item: [],
                wangge: 0,
                flags: false,
                floorstatus: false,
                category_name_id: 0,
                status: 0,
                noticeList: [],
                showNotice: false,
                noticeCount: 0,
                skuid: 0,
                gohi: [],
                day: 0,
                hour: 0,
                minute: 0,
                second: 0,
                percent: 0,
                skuid_price: 0,
                old_skuid_price: 0,
                vip_skuid_price: 0,
                go_hi_flag: false,
                current: 0,
                maodianFlag: false,
                skuid_arr: [],
                commentList: [],

                packageCategories: [],
                navs: -1,
                navsPhotos: [],
                packageList: [],

                st: '',
                sku_values:'',
                ast:'',
                scrolltop:0,
                stock:-1
        },
        //获取购物车数量
        fetchCartNum() {
                let url = '/wxapp/cart/index'
                app.post(url).then(r => {
                        if (r.code == 1) {
                                if (r.data.cartNum > 0) {
                                        wx.showTabBarRedDot({
                                                index: 1,
                                                success: function(red) {
                                                        wx.setTabBarBadge({
                                                                index: 1,
                                                                text: r.data.cartNum.toString(),
                                                        })
                                                }
                                        })
                                } else {
                                        wx.hideTabBarRedDot({
                                                index: 1
                                        })
                                }
                        }
                })
        },
        //进入赔付保证
        go_pay_ensure() {
                wx.navigateTo({
                        url: './pay_ensure/pay_ensure',
                })
        },
        //进入优选源头
        go_selectSource() {
                wx.navigateTo({
                        url: './select_source/select_source',
                })
        },
        //进入安心监测
        go_mind_detect() {
                wx.navigateTo({
                        url: './safty/safty',
                })
        },
        //进入go_hi轮播
        go_hi_carousel() {
                this.setData({
                        go_hi_flag: true
                })
        },
        //退出go_hi轮播
        hide_back_shop() {
                this.setData({
                        go_hi_flag: false
                });
        },
        //bindChange
        bindChange(e) {
                let current = e.detail.current;
                this.setData({
                        current: current
                });
        },
        //跳转gohi
        jump_gohi(e) {
                let url = e.currentTarget.dataset.url
                wx.navigateTo({
                        url: url,
                })
        },
        //二级锚点跳转
        getStatus(e) {
                let index = e.currentTarget.dataset.index
                let that = this
                if (index == 0) {
                        that.setData({
                                status: index,
                                maodianFlag: false
                        })
                } else {
                        that.setData({
                                status: index,
                                maodianFlag: true
                        })
                }
                //       if(wx.pageScrollTo){
                //               wx.pageScrollTo({
                //                       scrollTop: 200,
                //               })
                //       }
        },
        //点击商品列表显示加购弹框
        show_cart_mask(e) {
                let id = e.currentTarget.dataset.goods;
                this.setData({
                        show_cart_mask: true,
                        goods_id: id
                });
                this.fetchGoodsData();
        },
        //点击加入购物车
        jump_cart_id(e) {
                let id = this.data.goods_id
                let limit=e.currentTarget.dataset.limit
                let stock=this.data.stock
                let url = '/wxapp/cart/addCart'
                let params = {
                        skuid: this.data.skuid,
                        num: this.data.item
                }
             if(stock>=this.data.item){
                     if (limit > this.data.item || limit == 0) {
                             app.post(url, params).then(r => {
                                     console.log(r)
                                     if (r.code == 1) {
                                             wx.showToast({
                                                     title: '添加购物车成功',
                                                     icon: 'none'
                                             })
                                     } else {
                                             wx.showToast({
                                                     title: r.msg,
                                                     icon: 'none'
                                             })
                                     }
                             });
                     } else {
                             wx.showToast({
                                     title: '限购' + limit + '件',
                                     icon: 'none'
                             })
                             return
                     }
             }else{
                     wx.showToast({
                             title: '库存不足',
                             icon:'none'
                     })
             }
                this.setData({
                        show_cart_mask: false
                });
        },
        //渲染商品列表
        fetchGoodsData() {
                let id = this.data.goods_id;
                let url = '/wxapp/product/getProductInfo?id=' + id
                let stock=this.data.stock
                app.post(url).then(r => {
              if(r.code==1){
                      console.log(r.data)
                      for (let i = 0; i < r.data.attr.attr_sku.length; i++) {
                              for (let x = 0; x < r.data.attr.attr_sku[i].item.length; x++) {
                                      r.data.attr.attr_sku[i].item[x].t = false;
                              }
                      }
                      let skuid = 0;
                      let skuid_price = 0
                      let old_skuid_price = 0
                      let vip_skuid_price = 0
                      let arr = []
                      r.data.attr.attr_sku.forEach(function (ele, index) {
                              ele.item[0].t = true;
                              arr.push(ele.item[0].id)
                      })
                      arr = arr.sort()
                      let str = arr.join('_');
                      let sys_attrprice = r.data.sys_attrprice
                      for (let i in sys_attrprice) {
                              if (i == str) {
                                      skuid = sys_attrprice[i].skuid
                                      skuid_price = sys_attrprice[i].price
                                      old_skuid_price = sys_attrprice[i].old_price
                                      vip_skuid_price = sys_attrprice[i].vip_price
                                      stock: sys_attrprice[i].stock
                              }
                      }
                      this.setData({
                              goods_item: r.data,
                              // skuid_price: r.data.info.price,
                              skuid_price: skuid_price,
                              // old_skuid_price: r.data.info.old_price,
                              old_skuid_price: old_skuid_price,
                              // vip_skuid_price: r.data.info.vip_price,
                              vip_skuid_price: vip_skuid_price,
                              skuid: skuid,
                              skuid_arr: arr,
                              stock:stock
                      });
              }else{
                      wx.showToast({
                              title: r.msg,
                              icon:'none'
                      })
              }
                });
        },
        //重置
        reset_select() {
                let that = this;
                let ids = that.data.ids
                ids = [];
                let select = this.data.select;
                select.forEach(function(ele, index) {
                        for (let i = 0; i < ele.item.length; i++) {
                                ele.item[i].t = false;
                        }
                });
                this.setData({
                        select: select,
                        ids: ids
                });
        },
        //点击添加购物车数量
        dec_item() {
                let item = this.data.item;
                if (item <= 1) {
                        wx.showToast({
                                title: '已经是最少了哦',
                                icon:'none'
                        })
                        return;
                }
                item--;
                this.setData({
                        item: item
                });
        },
        add_item() {
                let item = this.data.item;
                item++;
                this.setData({
                        item: item
                });
        },
        //跳转至专题列表
        jump_special_list(e) {
                var specialid = e.currentTarget.dataset.specialid
                wx.navigateTo({
                        url: './special_list/special_list?id=' + specialid,
                })
        },
        //切换筛选id
        changeId(e) {
                let t = this;
                let listAll = t.data.select;
                let list = listAll[e.currentTarget.dataset.parent].item;
                let x = e.currentTarget.dataset.index;

                // 当前点击Id
                let nowId = e.currentTarget.dataset.id;
                //  父级索引
                let parent = e.currentTarget.dataset.parent;
                // 子集索引
                let nowIndex = e.currentTarget.dataset.index;
                // 当前可否多选
                let is_checkMore = e.currentTarget.dataset.select;

                // 当前点击父级值
                let tempArry = JSON.parse(JSON.stringify(this.data.select[parent]));
                !tempArry.chooseIndex ? tempArry.chooseIndex = [] : '';

                // 是否多选
                if (is_checkMore) {
                        // 是否已经选择
                        if (tempArry.item[nowIndex].t) {
                                let temIndex = tempArry.chooseIndex.indexOf(nowId);
                                tempArry.item[nowIndex].t = false
                                tempArry.chooseIndex.splice(temIndex, 1);
                        } else {
                                tempArry.chooseIndex.push(nowId);
                                tempArry.item[nowIndex].t = true;
                        }
                } else {
                        // tempArry = JSON.parse(JSON.stringify(this.data.back_select[parent]));
                        // !tempArry.chooseIndex ? tempArry.chooseIndex = [] : '';
                        // tempArry.item[nowIndex].t = true;
                        tempArry.chooseIndex[0] = nowId;
                        for (let obj of tempArry.item) {
                                obj.t = false
                        }
                        tempArry.item[nowIndex].t = true;
                }
                this.data.select[parent] = tempArry;
                this.setData({
                        select: this.data.select
                })
                let select = this.data.select;
                let id_str = [];
                let new_arr = [];
                for (let v of select) {
                        console.log(v.chooseIndex);
                        console.log(id_str);
                        new_arr = new_arr.concat(v.chooseIndex);
                        console.log(new_arr);
                }
                this.setData({
                        ids: new_arr
                });
        },
        //加购筛选
        changeIds(e) { 
                let t = this;
                let goods_item = t.data.goods_item;
                let listAll = t.data.goods_item.attr.attr_sku;
                let list = listAll[e.currentTarget.dataset.parent].item;
                let x = e.currentTarget.dataset.index;
                // 当前点击Id
                let nowId = e.currentTarget.dataset.id;
                //当前点击value
                let nowValue = e.currentTarget.dataset.item;
                //  父级索引
                let parent = e.currentTarget.dataset.parent;
                // 子集索引
                let nowIndex = e.currentTarget.dataset.index;
                // 当前可否多选
                let is_checkMore = false
                let new_arr = t.data.skuid_arr
                let foo = new_arr.indexOf(nowId)
                if (foo > -1) {
                        new_arr.splice(foo, 1)
                } else {
                        goods_item.attr.attr_sku.forEach(function(ele, indexxxx) {
                                if (indexxxx == parent) {
                                        for (let i = 0; i < ele.item.length; i++) {
                                                let havId = goods_item.attr.attr_sku[indexxxx].item[i].id
                                                let have = new_arr.indexOf(havId)
                                                if (have > -1) {
                                                        new_arr.splice(have, 1)
                                                }
                                        }
                                }
                        })
                }
                // 当前点击父级值
                let tempArry = JSON.parse(JSON.stringify(this.data.goods_item.attr.attr_sku[parent]));
                !tempArry.chooseIndex ? tempArry.chooseIndex = [] : '';
                !tempArry.chooseValue ? tempArry.chooseValue = [] : '';
                // 是否多选
                if (is_checkMore) {} else {
                        tempArry.chooseValue.pop();
                        tempArry.chooseValue.push(nowValue);
                        tempArry.chooseIndex.pop();
                        console.log(tempArry.chooseIndex)
                        tempArry.chooseIndex.push(nowId);
                        for (let obj of tempArry.item) {
                                obj.t = false
                        }
                        tempArry.item[nowIndex].t = true;
                }
                this.data.goods_item.attr.attr_sku[parent] = tempArry;
                this.setData({
                        goods_item: this.data.goods_item
                })
                let sys_attrprice = goods_item.sys_attrprice;
                //     let new_arr = []
                // let new_arr_item=[];
                let str = ''
                let skuid = 0
                let skuid_price = 0
                let old_skuid_price = 0
                let vip_skuid_price = 0
                let sku_values=''
                goods_item.attr.attr_sku.forEach(function(ele, indexx) {
                        if (indexx == parent) {
                                new_arr = new_arr.concat(ele.chooseIndex);
                        }
                })
                new_arr = new_arr.sort()
                str = new_arr.join('_');
                console.log(new_arr)
                console.log(str + "组合后的str")
                for (let i in sys_attrprice) {
                        if (i == str) {
                                skuid = sys_attrprice[i].skuid
                                skuid_price = sys_attrprice[i].price
                                old_skuid_price = sys_attrprice[i].old_price
                                vip_skuid_price = sys_attrprice[i].vip_price
                                sku_values = sys_attrprice[i].sku_values
                        }
                }
                this.setData({
                        idss: new_arr,
                        skuid: skuid,
                        skuid_price: skuid_price,
                        old_skuid_price: old_skuid_price,
                        vip_skuid_price: vip_skuid_price,
                        skuid_arr: new_arr,
                        sku_values: sku_values
                });
                console.log(skuid + "组合后的id值")
        },
        //操作筛选
        operation_all() {
                this.setData({
                        all: !this.data.all
                });
        },
        //关闭筛选
        close_all() {
                this.setData({
                        flag: !this.data.flag
                });
                let ids = '';
                let arr = this.data.ids
                console.log(arr);
                if(arr.length==0){
                        console.log('是空的吗')
                        ids=0
                }else{
                        console.log('到底是不是')
                        ids=this.data.ids
                }

                wx.navigateTo({
                        url: './select_index/select_index?idss=' + ids,
                })
        },
        //关闭全部分类
        cancel_both_category() {
                this.setData({
                        all: !this.data.all
                });
        },
        //点击全部分类跳转至相应页面
        jump_category_nav(e) {
                let id = e.currentTarget.dataset.navid;
                let flag = e.currentTarget.dataset.flag
                let that = this
                if (flag) {
                        that.setData({
                                all: false,
                                navs: id,
                                nav: -1
                        });
                        that.packagecategories()
                } else {
                        that.setData({
                                all: false,
                                nav: id,
                                navs: -1
                        });
                        that.category();
                }
        },
        //关闭加购框
        close_jump_msk() {
                this.setData({
                        show_cart_mask: false
                });
        },
        //定时器
        st(cut) {
                function time(cut) {
                        var that = this
                        var a = new Date()
                        a = Math.floor(a / 1000)
                        var cut_time = cut.group_end_date * 1000 - a
                        cut.days = Math.floor((cut_time) / (60 * 60 * 24));
                        cut.hours = Math.floor((cut_time) / (60 * 60)) % 24;
                        cut.minutes = Math.floor((cut_time) / (60)) % 60;
                        cut.seconds = cut_time % 60;
                        cut.percent = Math.floor(cut.group_number * 100 / cut.group_min_number)
                        console.log(cut.seconds)
                        that.setData({
                                groupList: r.data.group
                        })
                }
                time(cut)
                let sst = setInterval(time, 1000)
                if (ele.minutes == 0 && ele.seconds == 0) {
                        clearInterval(sst)
                }
        },
        //   热卖
        hotList() {
                let url = '/portal/index/index';
                let that = this
                let sku_values=''
                app.post(url).then(r => {
                        for (let i = 0; i < r.data.screen.length; i++) {
                                if (r.data.screen[i].item.length>0){
                                       for (let x = 0; x < r.data.screen[i].item.length; x++) {
                                               r.data.screen[i].item[x].t = false;
                                       }
                                       // r.data.screen[i].item[0].t = true
                                       sku_values += r.data.screen[i].item[0].attribute_value
                               }
                        }

                        var percent = 0
                        r.data.group.forEach(function(ele, index) {
                                var current = Math.floor(new Date() / 1000)
                                var shengyu = ele.group_end_date - current
                                console.log(shengyu)
                                // if(shengyu>0){
                                function time() {
                                        var a = new Date().getTime()
                                        a = Math.floor(a / 1000)
                                        var cut_time = ele.group_end_date - a
                                        ele.days = Math.floor((cut_time) / ( 60 * 60 * 24));
                                        ele.hours = Math.floor((cut_time) / ( 60 * 60)) % 24;
                                        ele.minutes = Math.floor((cut_time) / ( 60)) % 60;
                                        if (ele.days < 10) {
                                                ele.days = '0'+ele.days
                                        }
                                        if (ele.days == 0) {
                                                ele.days = '00'
                                        }
                                        if (ele.hours < 10) {
                                                ele.hours = '0'+ele.hours
                                        }
                                        if (ele.hours == 0) {
                                                ele.hours = '00'
                                        }
                                        if(ele.minutes<10){
                                                ele.minutes='0'+ele.minutes
                                        }
                                        if (ele.minutes == 0) {
                                                ele.minutes = '00'
                                        }
                                        if (ele.seconds < 10) {
                                                ele.seconds = '0'+ele.seconds
                                        }
                                        if (ele.seconds == 0) {
                                                ele.seconds = '00'
                                        }
                                        ele.seconds = cut_time % 60
                                        if(ele.seconds < 0){
                                                clearInterval(sst)
                                        }
                                        ele.percent = ele.group_number * 100 / ele.group_min_number
                                        that.setData({
                                                groupList: r.data.group
                                        })
                                }
                                        time()
                                        let sst = setInterval(time, 1000)
                                        if (ele.minutes == 0 && ele.seconds < 0) {
                                                clearInterval(sst)
                                        }
                                        that.setData({
                                                st: sst
                                        })
                                // }
                        })
                        that.setData({
                                hotList: r.data.gohi,
                                category: r.data.categories,
                                special: r.data.special,
                                banner: r.data.welcome,
                                select: r.data.screen,
                                back_select: r.data.screen,
                                product_item: r.data.recommended,
                                new_person: r.data.first,
                                gohi: r.data.gohi,
                                groupList: r.data.group,
                                commentList: r.data.comment,
                                packageCategories: r.data.package_categories,
                                sku_values:sku_values,
                                message:r.data.messageCount
                        })
                        console.log(that.data.groupList,'groupList')
                })
        },
        //跳转至问题反馈
        jump_suggestion(){
                wx.navigateTo({
                        url: '../my/suggestion/suggestion',
                })
        },
        //关闭筛选
        close_flags() {
                this.setData({
                        flag: false
                })
        },
        //获取分类菜谱
        category() {
                let url = '/portal/index/getCookBookByCategory';
                let that = this
                let params = {
                        id: that.data.nav
                };
                app.post(url, params).then(r => {
                        for (var i = 0; i < r.data.categories.length; i++) {
                                if (r.data.categories[i].id === that.data.nav) {
                                        var two_banner = r.data.categories[i].more.photos;
                                        if (two_banner) {
                                                that.setData({
                                                        two_banner: r.data.categories[i].more.photos,
                                                        select: r.data.screen,
                                                });
                                        } else {
                                                that.setData({
                                                        two_banner: [],
                                                        select: r.data.screen,
                                                });
                                        }
                                        if (that.data.two_banner.length > 0) {
                                                that.setData({
                                                        banner_state: true
                                                });
                                        } else {
                                                that.setData({
                                                        banner_state: false
                                                });
                                        }
                                }
                        }
                        let goods = r.data.list.goods;
                        that.setData({
                                goods: goods,
                                child: r.data.list.child
                        });
                        let a = Object.getOwnPropertyNames(r.data.list.child).length
                });
        },
        //分类下面的轮播图跳转
        jump_web(e){
                wx.navigateTo({
                        url: '../navigate/navigate?url='+e.currentTarget.dataset.jump,
                })
        },
        //切换导航
        changeNav1() {
                this.setData({
                        nav: 0,
                        navs: -1,
                        floorstatuss:false
                });
                wx.pageScrollTo({
                        scrollTop: 0,
                })
                this.hotList();
                this.category();
        },
        changeNav2(e) {
                let id = e.currentTarget.dataset.id;
                this.setData({
                        maodianFlag: false,
                        nav: id,
                        navs: -1,
                        status: 0,
                });
                wx.pageScrollTo({
                        scrollTop: 0,
                })
                this.category();
        },
        changeNav3(e) {
                let id = e.currentTarget.dataset.id;
                this.setData({
                        maodianFlag: false,
                        status: 0,
                        navs: id,
                        nav: -1
                });
                wx.pageScrollTo({
                        scrollTop: 0,
                })
                this.packagecategories();
        },
        //获取食品包列表
        packagecategories() {
                let url = '/portal/index/getPackageByCategory'
                let that = this
                let id = that.data.navs
                console.log(id + "这个是导航id")
                let params = {
                        id: id
                }
                let navsPhotos = []
                app.post(url, params).then(r => {
                        if (r.code == 1) {
                                console.log(r)
                                r.data.categories.forEach(function(ele, index) {
                                        if (ele.id == id) {
                                                console.log(ele.more)
                                                if (ele.more.photos) {
                                                        navsPhotos = ele.more.photos
                                                } else {
                                                        navsPhotos = []
                                                }
                                        }
                                })
                                that.setData({
                                        navsPhotos: navsPhotos,
                                        packageList: r.data.list.goods
                                })
                                navsPhotos = []
                        }
                })
        },
        //切换网格列表状态
        changeWangGe0() {
                this.setData({
                        wangge: 0
                });
        },
        changeWangGe1() {
                this.setData({
                        wangge: 1
                });
        },
        changeWangGe2() {
                this.setData({
                        wangge: 2
                });
        },
        //筛选
        select() {
                this.setData({
                        flag: !this.data.flag
                });
        },
        //
        checkTop(e) {
                let that = this
                if (e.detail.scrollTop >0) {
                        that.setData({
                                floorstatuss:true,
                                scrolltop:e.detail.scrollTop
                        })
                }else{
                        that.setData({
                                floorstatuss: false,
                                scrolltop: e.detail.scrollTop
                        })
                }
        },
        upper(e) {
                this.setData({
                        maodianFlag: false
                })
                wx.pageScrollTo({
                        scrollTop: 170,
                        duration: 0
                })
        },
        //重置筛选完成
        close_success() {
                this.setData({
                        flag: !this.data.flag 
                });
        },
        // 获取滚动条当前位置
        onPageScroll: function(e) {
                let that = this
                that.setData({
                        ast: e.scrollTop
                })
                if (e.scrollTop > 200) {
                        that.setData({
                                floorstatus: true
                        });
                } else {
                        that.setData({
                                floorstatus: false
                        });
                }
                if (e.scrollTop > 180) {
                        that.setData({
                                maodianFlag: true
                        })
                }
                // if(that.data.nav!==0){
                //         const query = wx.createSelectorQuery()
                //         query.select('#swiperId').boundingClientRect()
                //         query.selectViewport().scrollOffset()
                //         query.exec(function(res){
                //                 console.log(res[0].top+"嗯,高度")
                //                 if(res[0].top <= 85){
                //                         that.setData({
                //                                 maodianFlag: true
                //                         })
                //                 }
                //         })
                // }
        },
        goTops(){
                this.setData({
                      maodianFlag:false
                })
                // wx.pageScrollTo({
                //         scrollTop: 0,
                //         duration: 1000
                // })
        },
        //回到顶部
        goTop: function(e) { // 一键回到顶部
                if (wx.pageScrollTo) {
                        wx.pageScrollTo({
                                scrollTop: 0,
                                duration: 100
                        })
                } else {
                        wx.showModal({
                                title: '提示',
                                content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
                        })
                }
        },
        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function(options) {
                this.getaddress();
                // this.category();
                this.fetchGoodsData();
                var sysInfo = wx.getSystemInfoSync();
                var winHeight = sysInfo.windowHeight;
                var winWidth = sysInfo.windowWidth;
                this.setData({
                        winHeight: winHeight,
                        winWidth: winWidth
                })
        },
        active_btn(e) {
                this.setData({
                        current_index: 1
                })
        },
        getaddress() {
                var that = this
                wx.getLocation({
                        type: 'gcj02', //返回可以用于wx.openLocation的经纬度
                        success: function(res) {
                                console.log(res)
                                var latitude = res.latitude
                                var longitude = res.longitude
                                qqmapsdk.reverseGeocoder({
                                        location: {
                                                latitude: latitude,
                                                longitude: longitude
                                        },
                                        success: function(res) {
                                                console.log(res)
                                                var ctiy = res.result.address_component.district
                                                that.setData({
                                                        city: ctiy
                                                })
                                        },
                                        fail: function(res) {
                                                console.log('地址失败');
                                                console.log(res);
                                        },
                                        complete: function(res) {}
                                });
                        }
                })
        },
        // 跳转至详情
        get_contant() {
                wx.navigateTo({
                        url: '../../pages/my/big/big',
                })
        },
        // 跳转商品详情
        get_goodsDetial(e) {
                wx.navigateTo({
                        url: '/pages/index/goodsDetial/goodsDetial?id=' + e.currentTarget.dataset.goods
                })
        },
        //跳转至食品包详情
        get_packageDetial(e) {
                wx.navigateTo({
                        url: '/pages/index/foodPackageDetial/foodPackageDetial?id=' + e.currentTarget.dataset.goods
                })
        },
        toMessage() {
                wx.navigateTo({
                        url: '/pages/my/activityInformation/activityInformation',
                })
        },
        chooseAdress() {
                wx.navigateTo({
                        url: '/pages/my/selectAddress/selectAddress',
                })
        },
        search() {
                wx.navigateTo({
                        url: '/pages/my/serach/serach',
                })
        },
        //控制广告一天只显示一次
        controller_ad() {

        },
        //控制广告
        show_ad() {
                this.setData({
                        showad: false
                })
        },
        //跳转至个人中心签到
        jump_index_sign() {
                wx.switchTab({
                        url: '../my/my',
                })
        },
        //广告页的跳转
        goad() {

        },


        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady: function() {

        },

        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function() {
                this.hotList();
                this.fetchCartNum();
        },

        /**
         * 生命周期函数--监听页面隐藏
         */
        onHide: function() {

        },

        /**
         * 生命周期函数--监听页面卸载
         */
        onUnload: function() {
                let st=this.data.st
                clearInterval(st)
        },

        /**
         * 页面相关事件处理函数--监听用户下拉动作
         */
        onPullDownRefresh: function() {

        },

        /**
         * 页面上拉触底事件的处理函数
         */
        onReachBottom: function() {

        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage: function() {

        }
})