quickNavigation.js 5.21 KB
// components/Dialog/dialog.js
import {
  logEvent,
  YB_TO_OPEN_APP_C,
  YB_OPEN_APP_RESULT_L
} from '../../libs/analytics.js'
import { API_HOST, SERVICE_HOST } from '../../libs/config';
import { GET, POST } from '../../libs/request';
import { postFormId } from '../../libs/formIdCollectRequest';

let app = getApp();

Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   * 用于组件自定义设置
   */
  properties: {
    isShowIndicator: {  //是否展示返回顶部按钮
      type: Boolean,
      value: false,
      observer: "_indicatorChange"
    },

    isShowShopCart: { //是否展示购物车
      type: Boolean,
      value: true
    },

    marginBottom: {   //底部边距
      type: Number,
      value: 100
    },

    isShowMenu: { 
      type: Boolean,
      value: true
    },

    isShare: { // 是否显示分享
      type: Boolean,
      value: false
    },
    isGuangShare: {
      type: Boolean,
      value: false
    },
    isUnionShare: {// 是否显示创建联盟分享按钮
      type: Boolean,
      value: false
    },
    isGoApp: { // 是否显示取app按钮
      type: Boolean,
      value: false
    },
    appParameter: {
      type: String,
      value: ''
    },
    isHome: { 
      type: Boolean,
      value: false
    }
  },

  attached: function () {
    app.showYOHOIconCount ++ ;
    if (app.showYOHOIconCount == 1 && (app.globalData.currentScene == 1007 || app.globalData.currentScene == 1012) && !this.properties.isHome){
    this.showYOHOIcon();
    }
  },

  /**
   * 私有数据,组件的初始数据
   * 可用于模版渲染
   */
  data: {
    // 弹窗显示控制
    isShow: true,
    isExpand: false,
    needYOHOIcon: false,
    menuOpacity: 0,
    funcItemAnimation: {},
    indicatorAnimation: {},
    isAnimation: false,
  },

  /**
   * 组件的方法列表
   * 更新属性和数据的方法与更新页面数据的方法类似
   */
  methods: {
    //上报formid
    formSubmit: function (e) {
      // console.log('####formID:', e.detail.formId)
      let formId = e.detail.formId;
      postFormId(formId)
    },

    /*
     * 公有方法
     */
    //隐藏
    hide() {
      this.setData({
        isShow: !this.data.isShow
      })
    },

    //展示
    show() {
      this.setData({
        isShow: !this.data.isShow
      })
    },

    switchMenu() {
      if(this.data.isAnimation){
        return;
      }
      var time = 150;
      if(this.data.isExpand){
        this.takeback(time);
      }else {
        this.popout(time);
      }

      this.setData({
        isAnimation: true
      });

      var delayTime = time;
      setTimeout(function () {
        this.setData({
          isAnimation: false
        })
      }.bind(this), delayTime);


      this.setData({
        isExpand: !this.data.isExpand,
      })
    },

    _indicatorChange: function(newVal, oldVal) {
      var animtionIndicator = wx.createAnimation({
        duration: 300,
        timingFunction: 'linear',
      });

      if(newVal){
        animtionIndicator.opacity(1).height(44).width(44).step();
      }else {
        animtionIndicator.opacity(0).height(0).width(0).step();
      }

      this.setData({
        indicatorAnimation: animtionIndicator.export(),
      })
    },

    // 动画
    popout(time) {
      var funcItemAnimation = wx.createAnimation({
        duration: time,
        timingFunction: 'ease-in-out' 
      });

      funcItemAnimation.opacity(1).width(44).height(44).step({ duration: time });
      this.setData({
        funcItemAnimation: funcItemAnimation.export(),
      });
    },

    takeback(time) {
      var funcItemAnimation = wx.createAnimation({
        duration: time,
        timingFunction: 'ease-in-out'
      });

      funcItemAnimation.opacity(0).width(0).height(0).step({ duration: time });
      this.setData({
        funcItemAnimation: funcItemAnimation.export(),
      });
    },

    showYOHOIcon() {
      this.setData({
        needYOHOIcon: 1,
      });
    },

    //事件
    jumpToHome() {
      wx.switchTab({
        url: '/pages/index/index',
      })
    },

    jumpToSearch() {
      wx.navigateTo({
        url: '/pages/search/search',
      })
    },

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

    backToTop() {
      this.triggerEvent("backToTop");
    },

    unionShare() {
      this.triggerEvent("unionShare");
    },

    share: function(event){
      this.triggerEvent("share");
    },

    goApp: function (e) {

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

      // let params = {
      //   PAGE_PATH: url,
      // };
      // logEvent(YB_TO_OPEN_APP_C, params);
    },

    launchAppError: function (e) {
      var pages = getCurrentPages()
      var currentPage = pages[pages.length - 1]
      var url = currentPage.route

      // let params = {
      //   PAGE_PATH: url,
      //   OPEN_RESULT: 2
      // };
      // logEvent(YB_OPEN_APP_RESULT_L, params);

      wx.showToast({
        title: '打开失败!您可能未安装Yoho!Buy官方APP,请下载后再尝试。',
        icon: 'none',
        duration: 3000
      })
    } 
  }
})