action-bar.js 2.67 KB
// page/subPackage/pages/zeroSell/components/action-bar.js

import ZeroSellService from '../service/zero-sell'
import CommonService from '../service/common'
import router from '../router/router'

const event = global.event;

var app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    status: {
      type: Number,
      value: 1
    },
    num: {
      type: Number,
      value: 2
    },
    shareUid: {
      type: Number,
      value: 0
    },
    actPrizeId: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    code: '',
    error: false,
    fellow: false
  },

  ready() {
    this.service = new ZeroSellService();
    this.commonService = new CommonService();
  },

  /**
   * 组件的方法列表
   */
  methods: {
    fetchCode() {
      wx.showLoading({
        mask: true
      });
      event.emit('user-is-login', {logged: this.logged.bind(this), loginSuccess: function(){}});
    },
    logged(userInfo) {
      this.service.fetchCode({
        shareUid: this.properties.shareUid,
        uid: app.getUid(),
        actPrizeId: this.properties.actPrizeId,
        userThumb: userInfo.avatarUrl,
        userName: userInfo.nickName
      }).then(result => {
        wx.hideLoading();
        if (result.code === 200) {
          this.setData({
            show: true,
            code: result.data.prizeCode
          });
          this.triggerEvent('gaincodesuccess', this.properties.actPrizeId);
        } else {
          this.setData({
            error: true,
            errorText: result.message
          });
        }
      });
    },
    goShare() {
      this.triggerEvent('share');
      this.setData({
        show: false,
        error: false,
        fellow: false
      });
    },

    goMyList() {
      wx.reLaunch({
        url: '/pages/zeroSell/index?tabIndex=3&reload=0',
      })
    },

    goList() {
      wx.navigateTo({
        url: '/pages/zeroSell/index?reload=0',

      })

    },

    cancelAlert() {
      this.setData({
        show: false,
        error: false,
        fellow: false
      });

      this.triggerEvent('getcode');
    },

    openFellowAlert() {
      this.setData({
        fellow: true
      });
    },

    hiddenAlert(e) {
      this.setData({
        show: false,
        error: false,
        fellow: false
      });
      console.log('隐藏');
      this.triggerEvent('getcode');
    },

    submitFormId(e) {
      console.log(e.detail);
      return this.commonService.addWechatFormId({
        formId: e.detail.formId,
        uid: app.getUid() || 0,
        openId: app.getOpenID() || '',
        miniapp_type: app.getMiniappType()
      });
    }
  }
})