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

import NewZeroSellService from '../service/zero-service-new'
import commonService from '../service/commonService'
import {getUid,getStorageUserInfo, isLogin} from '../../../utils/index'
import router from '../router/router'

var app = null;

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.commonService = new commonService();
    this.newService = new NewZeroSellService();
  },

  /**
   * 组件的方法列表
   */
  methods: {
    fetchCode() {
      if (!isLogin()) {
        this.triggerEvent('requireauth');
        return;
      }
      
      wx.showLoading({
        mask: true
      });

      let userInfo = getStorageUserInfo();

      this.newService.fetchCode({
        shareUid: this.properties.shareUid,
        uid: getUid(),
        actPrizeId: this.properties.actPrizeId,
        userThumb: userInfo.avatarUrl,
        userName: userInfo.nickName
      }).then(result => {
        wx.hideLoading();
        this.setData({
          show: true,
          code: result.prizeCode
        });
      })
        .catch(error => {
          wx.hideLoading();
          this.setData({
            error: true,
            errorText: error ? error.message : ''
          });
        });
    },
    goShare() {
      this.triggerEvent('share');
    },

    goMyList() {
      router.go('myList');
    },

    goList() {
      router.go('index');
    },

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

      this.triggerEvent('getcode');
    },

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

    submitFormId(e) {
      return this.commonService.addWechatFormId({
        formId: e.detail.formId,
      });
    }
  }
})