goodsDetail.js 30.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
import {API_HOST, SERVICE_HOST} from '../../common/config';
import {GET, POST} from '../../common/request';
import {getGoodInfo,getGoodSize,getGoodImages} from '../../utils/productDetail';
import {
  logEvent,
  YB_GDS_DT_BILL,
  YB_PAGE_OPEN_L,
  YB_GDS_ADD_TO_CART_C,
  YB_SHARE_RESULT_L,
} from '../../common/analytics.js'
import { formateTimestamp } from '../../utils/util';
import { decodePhoneNumberk, getUnionID} from '../../utils/login';

const { Actionsheet, extend } = require('../../vendors/zanui/index');

let app = getApp();
const  windowWidth = app.globalData.systemInfo.windowWidth;
const  windowHeight = app.globalData.systemInfo.windowHeight;

const DEVICE_WIDTH_RATIO = windowWidth / 320;

let imageWidth = windowWidth;
let imageHeight = windowWidth *1.25;

let PV_ID = new Date().getTime() + '';
var Picker = require('./picker/picker.js')

Page(extend({}, Actionsheet, {
  getPhoneNumber: function (e) {
    var that = this;
    if (e.detail.errMsg === 'getPhoneNumber:ok'){
      decodePhoneNumber(e.detail.iv, e.detail.encryptedData,function(result){
        // console.log('!!!!result',result)
        if (result.code!=200){
          that.wetoast.toast({
              title: result.message,
              titleClassName: 'wetoast-title',
              duration: 1000
            });
          that.loginAndRegisterTapped();
          }else{
          let uid = app.globalData.userInfo.uid > 0 ? app.globalData.userInfo.uid : 0;
          that.setData({ uid });
          }
      })
    }else{
      let needBind = true;
      that.setData({ needBind });
      that.loginAndRegisterTapped(true);
    }
  },
  data:{
    imageWidth,
    imageHeight,
    windowHeight,

    productSKN:'',
    //商品图片轮播
    bannerImgUrls:[],
    indicatorDots: true,
    autoplay: false,
    interval: 4000,
    duration: 1000,
    uid:0,
    
    //商品价格
    title:'',
    realPrice:'',
    price:'',

    //VIP价格
    vipPrice:[],

    //
    isLimitBuy:false,
    is_deposit_advance:"N",
    is_secKill:"N",
    is_advance:"N",
    sales_phrase: '',
    expect_arrival_time: '',
    bundle_type:0,
    
    //商品详细信息
    productDesc:[],
    productSizeTitle:[],
    productSizeContent:[],
    productMeasurementImage:'',
    productMaterialList: [],
    productWashTipsBoList: [],
    productIntroImageList:[],
    productModelList:[],
    productModelTitleList:['模特','身高','体重','三围','吊牌尺码','试穿描述'],

    productPromotionList: [],
    productPromotionListForAbbreviations: [],
    productSupportServiceList:[],
    showProductPromotionDetail:false,
    shoppingcartCount:0,

    product_id: '',//商品id

    storage_sum:1,
    is_supplyed:true,
    store_show_status:'',//是否是仅线下店可售商品

    //选中的sku
    selectedSKU:0,

    //选中sku的库存
    storageNumber:0,

    //判断是否选择了颜色
    colorSelected:false,

    isloadingForPayment:false,
    // 是否收藏
    isFavorite: false,

    from_page_name: '',
    from_page_param: '',
    current_page_name: 'productDetail',
    current_page_param: '',
    needBind:false,
    
    // 标志用户点击了立即购买还是加入购物车
    isBuyNow:false,

    //picker 需要的数据
    pickerData:{
      view:{
        isShow: false,  
        isSoldOutSoon: false, //是否展示即将售罄
        goodsList:[],
        sizeList:[],
        image:'',
		    goodPrice:'',
	    	price:'',
        buyNumber:1,
        minusButtonEnable:false,
        plusButtonEnable:true,
        buyButtonEnable:true,
        },
      sourceType: 'goodsDetail',
    },

    isShowIndicator: false,
    scrollTop: 0,
    actionsheet: {
      componentId: 'shareActionSheet',
      show: false,
      cancelText: '取消',
      actions: [{
        name: '分享给朋友',
        className: 'action-class',
        loading: false,
        openType: 'share'
      }, 
      {
        name: '生成卡片并分享',
        className: 'action-class',
        loading: false,
      }]
    },
    isShowSnapshoot: false,
    snapshootShareData: {},
  },
  
  getParameterByName: function (name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
      results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
  },

  onLoad:function(options){
    var app = getApp()
    var that = this
    let productSKN = options.productSkn ? options.productSkn : '';
    if (!productSKN) productSKN = options.product_skn ? options.product_skn : '';
    if (options.q && options.q.length >0){
      let urlstring = decodeURIComponent(options.q)
      let skn = that.getParameterByName('skn', urlstring)
      // console.log('###urlstring:', skn)
      if (skn.length > 0) productSKN= skn;
    }

    if (options && options.scene && options.scene.length>0){
      var scene = decodeURIComponent(options.scene)
      if (scene.length > 0) productSKN = scene;
    }
    
    let from_page_name = options.page_name ? options.page_name : '';
    let from_page_param = options.page_param ? options.page_param : '';
    let current_page_param = productSKN;
    let uid = app.globalData.userInfo.uid>0?app.globalData.userInfo.uid:0;

    this.setData({ productSKN, uid, from_page_name, from_page_param, current_page_param});
    Picker.init(that)
    if (app.globalData.p2SecretKey==null||app.globalData.p2SecretKey==''){
      setTimeout(function () { 
        that.fetchGoodInfo()
        that.fetchGoodPromotion()
        that.fetchGoodDetail()
        that.fetchSupportService()
        that.fetchShoppingCartCount()
        }, 1000);
    }else{
      that.fetchGoodInfo()
      that.fetchGoodPromotion()
      that.fetchGoodDetail()
      that.fetchSupportService()
      that.fetchShoppingCartCount()
    }

    new app.WeToast();
    that.showLoadingToast()

    var pages = getCurrentPages() 
    var currentPage = pages[pages.length - 1]
    var url = currentPage.route

    let params = {
        PAGE_NAME: that.data.current_page_name,
        PAGE_PARAM: that.data.current_page_param,
        FROM_PAGE_NAME: that.data.from_page_name,
        FROM_PAGE_PARAM: that.data.from_page_param,
        PV_ID: PV_ID,
        PAGE_PATH: url        
    };
    logEvent(YB_PAGE_OPEN_L, params);
  },

  onPullDownRefresh: function () {
    var that = this
    let params = {
      PAGE_NAME: that.data.current_page_name,
      PAGE_PARAM: that.data.current_page_param,
      FROM_PAGE_NAME: that.data.from_page_name,
      FROM_PAGE_PARAM: that.data.from_page_param,
      PV_ID: PV_ID,
    };
    logEvent(YB_PAGE_OPEN_L, params);
  },

  onShow:function(options){
   let uid = app.globalData.userInfo.uid>0?app.globalData.userInfo.uid:0;
   this.setData({uid});
  },

  onShareAppMessage: function (res) {
    var that = this

    let param = {
        FROM: res.from,
        SHARE_RESUIL:0,
        TITLE: that.data.title,
        DESC: '我在有货发现一个不错的商品赶快来看看吧!',
        PATH: '/pages/goodsDetail/goodsDetail?productSkn=' + that.data.productSKN,
    }

    // console.log('param:', param)

    // 用户点击右上角分享
    return {
      title: param.TITLE, // 分享标题
      //imageUrl: imageUrl,
      desc: param.DESC, // 分享描述
      path: param.PATH , // 分享路径
      success: function (res) {
        param.SHARE_RESUIL=1
        logEvent(YB_SHARE_RESULT_L, param);
      },
      fail: function (res) {
        param.SHARE_RESUIL = 2
        logEvent(YB_SHARE_RESULT_L, param);
      }
    }
  },

  share: function(event){
    this.setData({
      'actionsheet.show': true
    })
  },

  //立即购买
  buyAction:function(event){
    let that = this

    if (this.data.isLimitBuy == true || this.data.is_deposit_advance == "Y" || this.data.is_secKill == "Y" || this.data.is_advance == "Y" || this.data.bundle_type == 2 || this.data.store_show_status === 3 || this.data.store_show_status === 4) {
      this.wetoast.toast({
        title: '暂不支持该商品购买,请前往Yoho!Buy有货官方应用选购!',
        titleClassName: 'wetoast-title',
        duration: 3000
      });
      return;
    }

    if (that.data.storage_sum === 0)return;
    let isBuyNow = true;
    that.setData({ isBuyNow})
    // console.log('###uid', app.globalData.userInfo.uid)

    if (app.globalData.userInfo.uid) {
      Picker.pickerShow(event,that);
    }else {
      this.loginAndRegisterTapped();
    }
  },
  
  //加入购物车
  addToShoppingCartBtnTapped:function(event){
    let that = this

    if (this.data.isLimitBuy == true || this.data.is_deposit_advance == "Y" || this.data.is_secKill == "Y" || this.data.is_advance == "Y" || this.data.bundle_type == 2 || this.data.store_show_status === 3 || this.data.store_show_status === 4) {
      this.wetoast.toast({
        title: '暂不支持该商品购买,请前往Yoho!Buy有货官方应用选购!',
        titleClassName: 'wetoast-title',
        duration: 3000
      });
      return;
    }


    if (that.data.storage_sum === 0) return;
    let isBuyNow = false;
    that.setData({isBuyNow})
    if (app.globalData.userInfo.uid) {
      Picker.pickerShow(event, that);
    } else {
      this.loginAndRegisterTapped();
    }
  },

 //跳转到登录页面
  loginAndRegisterTapped:function(needBind) {
    let that = this;
    let app = getApp()
    if(wx.getSetting){
      wx.getSetting({
        success: (res) => {
          if (res && res.authSetting && res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === false) {
            wx.showModal({
              title: '',
              content: '检测到您未打开微信用户信息授权,开启后即可进行登录',
              confirmText: "去开启",
              confirmColor: "#000000",
              success: function (res) {
                if (res.confirm) {
                  wx.openSetting({
                    success: (res) => {
                      // console.log(res.authSetting["scope.userInfo"])
                      if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === true) {
                        getUnionID(app.getWechatThirdSession(), function (response) {
                          // console.log(response)
                        })
                      }
                    }
                  })
                } else {
                  wx.navigateTo({
                    url: '../bindPhoneNumber/bindPhoneNumber',
                  })
                }
              }
            })
          } else {
            wx.navigateTo({
              url: '../bindPhoneNumber/bindPhoneNumber',
            })
          }
        }
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
      })
    }
  },

 //减少购买数量
  bindMinus:function(event){
    let pickerData = this.data.pickerData;
    let buyNumber = parseInt(pickerData.view.buyNumber);
    if (buyNumber > 1) {
      buyNumber = buyNumber - 1;
    }
    pickerData.view.buyNumber = buyNumber;

    if (buyNumber == 1) {
      pickerData.view.minusButtonEnable = false;
    } else {
      pickerData.view.minusButtonEnable = true;
    }

    if (buyNumber < this.data.storageNumber) {
      pickerData.view.plusButtonEnable = true;
    }
    this.setData({pickerData});
  },

 //增加购买数量
  bindPlus:function(event){
    if (!this.data.colorSelected) {
      this.wetoast.toast({
          title: '请选择颜色',
          titleClassName: 'wetoast-title',
          duration: 1000
      });

      return;
    }

    if (!this.data.selectedSKU) {
      this.wetoast.toast({
          title: '请选择尺码',
          titleClassName: 'wetoast-title',
          duration: 1000
      });

      return;
    }

    let pickerData = this.data.pickerData;
    let buyNumber = pickerData.view.buyNumber;

    if (buyNumber >= this.data.storageNumber) {
      this.plusReachedMaxAction();
      return;
    }

    if (buyNumber < this.data.storageNumber) {
      pickerData.view.plusButtonEnable = true;
      buyNumber = parseInt(buyNumber) + 1;
    }

    if (buyNumber >= this.data.storageNumber) {
      pickerData.view.plusButtonEnable = false;
    }

    if (buyNumber > 1) {
      pickerData.view.minusButtonEnable = true;
    }

    pickerData.view.buyNumber = buyNumber;
    this.setData({pickerData});
  },

  plusReachedMaxAction: function () {
    this.wetoast.toast({
      title: '对不起,没有更多库存了',
      titleClassName: 'wetoast-title',
      duration: 1000
    });
  },

  // 立即支付
  goPayment:function(event){
    // console.log('######')
    if (this.data.isLimitBuy == true || this.data.is_deposit_advance == "Y" || this.data.is_secKill == "Y" || this.data.is_advance == "Y" || this.data.bundle_type == 2 || this.data.store_show_status === 3 || this.data.store_show_status === 4){
        this.wetoast.toast({
          title: '暂不支持该商品购买,请前往Yoho!Buy有货官方应用选购!',
          titleClassName: 'wetoast-title',
          duration: 3000
      });
      return;
    }

    if (!this.data.colorSelected) {
      this.wetoast.toast({
          title: '请选择颜色',
          titleClassName: 'wetoast-title',
          duration: 1000
      });
      return;
    }

    if (!this.data.selectedSKU) {
      this.wetoast.toast({
          title: '请选择尺码',
          titleClassName: 'wetoast-title',
          duration: 1000
      });
      return;
    }
    
    let that = this

    if(that.data.isloadingForPayment){
      return
    }

    that.setData({isloadingForPayment:true})
    let current = getCurrentPages()
    if(current.length>0){
      let item = current[current.length-1]
      if(item.__route__ == 'pages/statements/statements'){
        that.setData({isloadingForPayment:false})
        return
      }
    }
    
    let pickerData = that.data.pickerData;
    let params = {
                    PRD_SKN: that.data.productSKN>0?that.data.productSKN:0,
                    RPD_SKU: that.data.selectedSKU>0?that.data.selectedSKU:0, 
                    PRD_ID: that.data.product_id > 0 ? that.data.product_id : 0,
                    PV_ID: PV_ID,
                 };

    if (that.data.isBuyNow){
      logEvent(YB_GDS_DT_BILL, params);
      this.payNow(event)
    }else{
      logEvent(YB_GDS_ADD_TO_CART_C, params);
      this.addToShoppingCart(event)
    }
  },

  goShoppingCart:function(){
    wx.switchTab({
      url: '/pages/shopCart/shopCart'
    })
  },

  addToShoppingCart:function(event){
    let that2 = this;
    let param = {
      method: "app.Shopping.add",
      product_sku: that2.data.selectedSKU > 0 ? that2.data.selectedSKU : 0,
      buy_number: that2.data.pickerData.view.buyNumber,
      edit_product_sku: 0,
      promotion_id: "",
      goods_type: 0,
      selected: "Y",
      uid: app.getUid(),
    };

    that2.showLoadingToast()
    GET(API_HOST, param)
    .then(function (data) {
      that2.hideLoadingToast()
      Picker.pickerHide(event, that2);

      that2.setData({ isloadingForPayment: false })

      if (data && data.code == 200) {
        that2.fetchShoppingCartCount();
        that2.wetoast.toast({
          title: data.message,
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      } else {
        that2.wetoast.toast({
          title: data.message,
          titleClassName: 'wetoast-title',
          duration: 2000
        });
      }
    })
    .catch(function (error) {
      that2.setData({ isloadingForPayment: false })
      that2.wetoast.toast({
        title: error.code + error.message + '',
        titleClassName: 'wetoast-title',
        duration: 2000
      });
    });
  },

  payNow:function(event){
    let that = this;
    let param = {
      method: 'app.Buynow.payment',
      uid: app.getUid(),
      product_sku: that.data.selectedSKU > 0 ? that.data.selectedSKU : 0,
      sku_type: 'I',
      buy_number: that.data.pickerData.view.buyNumber,
      yoho_coin_mode: 0,
      is_support_apple_pay: 'N',
    }

    that.showLoadingToast()
    GET(API_HOST, param)
      .then(function (data) {
        that.hideLoadingToast()
        var timestamp = Date.parse(new Date());
        that.setData({ isloadingForPayment: false })
        Picker.pickerHide(event, that);
        if (data && data.code == 200) {
          that.setData({ isloadingForPayment: false })
          try {
            wx.setStorageSync(timestamp + '', data);
          } catch (e) {
          }
          wx.navigateTo({
            url: '../statements/statements?timestamp=' + timestamp + '&page_name=' + that.data.current_page_name + '&page_param=' + that.data.current_page_param,
          })
        } else {
          that.wetoast.toast({
            title: data.message,
            titleClassName: 'wetoast-title',
            duration: 2000
          });
        }
      })
      .catch(function (error) {
        that.setData({ isloadingForPayment: false })
        this.wetoast.toast({
          title: error.code + error.message + '',
          titleClassName: 'wetoast-title',
          duration: 2000
        });
      });
  },
 
  //点击背景,隐藏picker
  pickerTap: function(event){
    if(event.target.id=="picker-bg"){
      var that = this
      Picker.pickerHide(event,that);
    }
  },

  //点击选择颜色
  colorTap:function(event){
    //更新各个颜色的选中状态
    var that = this
    var tempData = that.data.pickerData;
    //先遍历将所有颜色、尺码置为未选中状态
    // console.log('color')
    // console.log(tempData.view.goodsList)

    tempData.view.goodsList && tempData.view.goodsList.map((item,index) => {
        item.selected = false
        item.size_list.map((subItem,index) =>{
          subItem.selected = false
          subItem.enable = subItem.storage_number>0?true:false
        });
    });
    
    //将当前颜色置为选中状态
    var tempItem = event.target.dataset.key
 
    //遍历颜色尺码,根据库存切换显示状态
    tempItem && tempItem.size_list && tempItem.size_list.map((item,index) => {
      item.enable = item.storage_number>0?true:false
    })

    tempItem.selected = true
    
    //设置标志位,表示已经选择颜色
    let colorSelected = true

    //重置库存、当前选中sku的值
    tempData.storageNumber = 0    
    tempData.selectedSKU = 0

    tempData.view.goodsList[Number(event.target.id)] = tempItem
    tempData.view.sizeList = tempItem.size_list

    tempData.view.minusButtonEnable = false
    //将购买数量设为初始状态
    tempData.view.buyNumber = 1

    this.setData({
      colorSelected,
      pickerData:tempData,
    });
  },

  //点击选择尺码
  sizeTap:function(event){
    var that = this
    var tempData = that.data.pickerData

    //现遍历将所有尺码置为未选中状态
    tempData.view.sizeList && tempData.view.sizeList.map((item,index) => {
      item.selected = false
    });
    
    //将当前尺码置为选中状态
    var tempItem = event.currentTarget.dataset.key
    tempItem.selected = true
    tempData.view.sizeList[parseInt(event.currentTarget.id)] = tempItem
    
    //设置数量加减按钮启用状态
    tempData.view.plusButtonEnable = tempItem.storage_number > 1
    tempData.view.minusButtonEnable = false
    tempData.view.buyButtonEnable=true
    //将购买数量设为初始状态
    tempData.view.buyNumber = 1
    // console.log(event)
    if(tempItem.storage_number<=0){
         this.wetoast.toast({
          title: '该尺码已经售罄',
          titleClassName: 'wetoast-title',
          duration: 1000
      });

      tempData.view.buyButtonEnable=false
    }
    this.setData({
        pickerData:tempData,
        selectedSKU:tempItem.storage_number>0?tempItem.product_sku:0,
        storageNumber:tempItem.storage_number,
    });
  },

   //获取商品基本信息(包括颜色、尺码)
  fetchGoodInfo:function(){
    let param = {
      method: 'app.product.data',
      product_skn:this.data.productSKN
    }
    var that = this
  
    GET(API_HOST, param)
    .then(function(data) {
    that.hideLoadingToast()
    if(!data||data.code != 200)
    return

    let ImgUrls = [];
    let color_length = 0;
    if (data.data.goods_list) {
      color_length = data.data.goods_list.length;
    }
    data.data.goods_list.map((item, index) => {
      let images = getGoodImages(item.images_list,imageWidth,imageHeight)
      ImgUrls = [...ImgUrls, ...images];
      if (index == 0 && color_length == 1) {
        item.selected = true;
        that.data.colorSelected = true;
      }
    });

    let isSoldOutSoon = false;
    let tags = data.data.tags;
    if (tags) {
      tags.map((item) => {
        if (item == "is_soon_sold_out") {
          isSoldOutSoon = true;
        }
      });
    }

   //pickerData
    var temData = that.data.pickerData;
    temData.view.goodsList = data.data.goods_list;
    temData.view.isSoldOutSoon = isSoldOutSoon;

    //默认显示第一种颜色的尺码
    temData.view.sizeList = data.data.goods_list.length>0?data.data.goods_list[0].size_list:[];

    let plusButtonEnable = false;
    let minusButtonEnable = false;
    //根据库存设置该尺码是否可以选择
    let size_length = 0;
    if (temData.view.sizeList) {
      size_length = temData.view.sizeList.length;
    }
    temData.view.sizeList && temData.view.sizeList.map((item,index) => {
      item.enable = item.storage_number>0?true:false;
      if (index == 0 && size_length == 1 && that.data.colorSelected) {
        //当颜色被选中 并且只有一个size 时 才会自动 做选中尺码操作
        temData.view.buyButtonEnable = item.enable;
        if (item.enable) {
          item.selected = true;
          plusButtonEnable = item.storage_number > 1;
          that.setData({
            selectedSKU: item.product_sku,
            storageNumber: item.storage_number,
          });
        }
      }
    });
    
    temData.view.plusButtonEnable = plusButtonEnable;
    temData.view.minusButtonEnable = minusButtonEnable;
    temData.view.image = ImgUrls.length>0?ImgUrls[0]:'';
    temData.view.price = data.data.format_market_price;
    temData.view.goodPrice = data.data.format_sales_price;

    let indicatorDots = ImgUrls.length == 1 ? false : true;

    var default_image = ImgUrls.length > 0 ? ImgUrls[0] : '';
    var product_qrCode = API_HOST + '/wechat/miniapp/img-check.jpg?param=' + data.data.product_skn;
    var shareData = {
      product_name : data.data.product_name,
      product_price: '¥'+data.data.sales_price,
      default_image,
      product_qrCode
    }

    that.setData({
        title:data.data.product_name,
        price:data.data.format_market_price,
        realPrice:data.data.format_sales_price,
        bannerImgUrls:ImgUrls,
        indicatorDots,
        isLimitBuy:data.data.isLimitBuy,
        is_deposit_advance:data.data.is_deposit_advance,
        is_secKill:data.data.is_secKill,
        is_advance:data.data.is_advance,
        sales_phrase: data.data.sales_phrase,
        expect_arrival_time: data.data.expect_arrival_time,
        isInstalment:data.data.isInstalment,
        pickerData:temData,
        product_id: data.data.product_id,
        vipPrice : data.data.vip,
        storage_sum: data.data.storage_sum,
        is_supplyed: data.data.is_supplyed,
        bundle_type: data.data.bundle_type,
        store_show_status: data.data.store_show_status,
        snapshootShareData: shareData
      });
    that.fetchGoodFavorite();
    })
    .catch(function(error) {
        this.wetoast.toast({
          title: error.code+error.message +'',
          titleClassName: 'wetoast-title',
          duration: 1000
      });
    });
  },
  
  fetchSupportService: function () {
    let param = {
      method: 'app.product.supportService',
      product_skn: this.data.productSKN,
      coupon_limit_status:0
    }
    var that = this
    GET(API_HOST, param)
      .then(function (data) {
        that.setData({
          productSupportServiceList: data.data,
        });
      })
      .catch(function (error) {
        this.wetoast.toast({
          title: error.code + error.message + '',
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      });
  },

  fetchShoppingCartCount: function () {
    let param = {
      method: 'app.Shopping.count',
      product_skn: this.data.productSKN
    }
    var that = this
    GET(API_HOST, param)
      .then(function (data) {
        that.setData({
          shoppingcartCount: data.data.cart_goods_count,
        });
      })
      .catch(function (error) {
        this.wetoast.toast({
          title: error.code + error.message + '',
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      });
  },

  //获取商品收藏状态
  fetchGoodFavorite: function () {
    let param = {
      method: 'app.favorite.isFavoriteNew',
      id: this.data.product_id
    }
    var that = this
    GET(API_HOST, param)
      .then(function (data) {
        that.setData({
          isFavorite: data.data,
        });
      })
      .catch(function (error) {
        that.wetoast.toast({
          title: error.code + error.message,
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      });
  },

  //添加收藏
  addFavoriteRequest: function () {
    let param = {
      method: 'app.favorite.add',
      id: this.data.product_id,
      type: 'product'
    }
    var that = this
    GET(API_HOST, param)
      .then(function (data) {
        that.setData({
          isFavorite: true,
        });
        that.wetoast.toast({
          title: data.message,
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      })
      .catch(function (error) {
        that.wetoast.toast({
          title: error.code + error.message,
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      });
  },

  //取消收藏
  cancelFavoriteRequest: function () {
    let param = {
      method: 'app.favorite.cancel',
      fav_id: this.data.product_id,
      type: 'product'
    }
    var that = this
    GET(API_HOST, param)
      .then(function (data) {
        that.setData({
          isFavorite: false,
        });
        that.wetoast.toast({
          title: data.message,
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      })
      .catch(function (error) {
        that.wetoast.toast({
          title: error.code + error.message,
          titleClassName: 'wetoast-title',
          duration: 1000
        });
      });
  },

  fetchGoodPromotion:function(){
    let param = {
      method: 'app.product.promotion',
      product_skn: this.data.productSKN
    }
    var that = this
    GET(API_HOST, param)

    .then(function(data) {
      that.hideLoadingToast()
      var list = data.data
      list.forEach(function (e) {
        e.time = formateTimestamp(e.startTime,e.endTime)
      });

      let productPromotionList = data.data;
      let productPromotionListForAbbreviations = [];

      productPromotionList.forEach(function (e) {
        let promotionType = e.promotionType;
        if (productPromotionListForAbbreviations.indexOf(promotionType) == -1){
          productPromotionListForAbbreviations.push(promotionType);
        }
      });

      that.setData({
        productPromotionList,
        productPromotionListForAbbreviations,
      });
    })
    .catch(function(error) {
        this.wetoast.toast({
          title: error.code+error.message +'',
          titleClassName: 'wetoast-title',
          duration: 1000
      });
    });
  },

   //商品详情
  fetchGoodDetail: function() {
    let param = {
      method: 'smallapp.product.intro',
      productskn:this.data.productSKN
    }
    var that = this
    GET(API_HOST, param)
    .then(function(data) {
      that.hideLoadingToast()
      let infoList = data.productDescBo
      infoList = getGoodInfo(infoList)
      let productPhrare = data.productDescBo.phrase
      let size = data.sizeInfoBo
      size = getGoodSize(size)

      // let modelList = data.modelBos
      // modelList = getModelList(modelList)
      that.setData({
        productDesc:infoList,
        productPhrare,
        productSizeTitle:size.titleList,
        productSizeContent:size.sizeList,
        productMeasurementImage:data.sizeImage,
        productWashTipsBoList:data.washTipsBoList,
        productMaterialList:data.productMaterialList,
        productIntroImageList:data.productIntroBo.imageList,
        // productModelList:modelList,
      });
    })
    .catch(function(error) {
        this.wetoast.toast({
          title: error.code+error.message +'',
          titleClassName: 'wetoast-title',
          duration: 1000
      });
    });
  },

  showLoadingToast: function() {
    wx.showToast({
        title: '加载中',
        icon: 'loading',
        duration: 10000,
      })
  },

  hideLoadingToast:function(){
    wx.hideToast()
  },

  catchtouchmove:function(event) {

  },

  hideModalTapped: function () {
    hideModal(this);
  },

  getVerifyKeyBtnTapped: function () {
    getVerifyCode(this, function (result) {
      // console.log(result);
    })
  },

  phoneInputChanged: function (event) {
    phoneInputChangedAction(event.detail.value, this)
  },

  bindBtnTapped: function () {
    let that = this
    bindBtnAction(that,that.data.needBind, function () {
      let uid = app.globalData.userInfo.uid > 0 ? app.globalData.userInfo.uid : 0;
      that.setData({ uid })
    });
  },

  showPromotionDetail:function(){
    let that = this
    let showProductPromotionDetail = !that.data.showProductPromotionDetail
    // console.log("showProductPromotionDetal", showProductPromotionDetail)
    that.setData({ showProductPromotionDetail})
  },

  verifyCodeInputChanged: function (event) {
    verifyCodeInputChangedAction(event.detail.value, this);
  },

  imgPreview: function (event) {
    var imgList = this.data.bannerImgUrls;
    var src = event.currentTarget.dataset.src;
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  },

  onScroll:function(e) {
    var {scrollTop} = e.detail;
    var isShow = scrollTop > windowHeight * 2 ? true : false;
    if (isShow != this.data.isShowIndicator){
      this.setData({
        isShowIndicator: isShow
      });
    }
  },

  backToTop:function() {
    this.setData({
      scrollTop: 0
    })
  },

  handleZanActionsheetCancel({ componentId }) {
    this.setData({
      'actionsheet.show': false
    })
  },

  // 当行动按钮中有一个被点击时触发
  // index 代表被点击按钮在传入参数 actions 中的位置
  handleZanActionsheetClick({ componentId, index }) {
    this.setData({
      'actionsheet.show': false
    })

    if(index === 1) {
      this.setData({
        isShowSnapshoot: true
      })
    }
  },

  backToTop: function () {
    this.setData({
      scrollTop: 0
    })
  },

  hiddenSheet: function () {
    this.setData({
      isShowSnapshoot: false
    })
  }

}))