PhoneNumber.js 2.32 KB
/*
 * @Description: 
 * @Author: huyue
 * @Date: 2022-12-09 13:58:15
 * @LastEditors: huyue
 * @LastEditTime: 2022-12-13 10:36:15
 */
// components/Login/Login.js
import { ssoApi } from "../../api/api";
import { componentsMixin } from "../../mixins/index";
Component({
  externalClasses: ['custom-class'],
  behaviors: [componentsMixin],
  // options: {
  //   styleIsolation: 'isolated'
  // },
  /**
   * 组件的属性列表
   */
  properties: {
    phoneText: {
      type: String,
      value: '了解更多案例'
    },
    /** 
     * type: 场景类型: home.首页,整行;product.详情中的查看更多和申请合作切换;scenario场景详情:转发+合作申请;video 视频详情
     */
    type: {
      type: String
    },
    hasPhoneNumber: {
      type: Boolean,
      observer(n) {
        this.setData({
          hasPhone: n
        })
      }
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    hasPhone: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取手机号
    getPhoneNumber({detail}) {
      if ( detail.errMsg && detail.errMsg.indexOf('user deny') !== -1 ) {
        wx.hideLoading()
        return;
      }
      wx.$util.showLoading('正在授权...')
      delete detail.errMsg;
      if (detail.iv && detail.encryptedData) {
        ssoApi.authUserPhone(detail).then(({ data, code, message }) => {
          wx.hideLoading()
          if (code==0) {
            wx.$util.setUserInfo(data);
            // 其他操作
            this.triggerEvent("updatePhoneNumber", data.phone);
            this.setData({
              hasPhone: true
            })
          } else {
            wx.showToast({
              title: message,
              icon: 'none',
              duration: 2000
            })
          }
        });
      }
    },
    jump() {
      // this.triggerEvent('toApplication')
      console.log(333);
      wx.$router.go("/packagesList/pages/activityApply/activityApply");
    },
    forward() {
      this.triggerEvent('toForward')
    },
    downVideo() {
      let that = this
      wx.showModal({
        content: '是否下载视频',
        success (res) {
          if (res.confirm) {
            that.triggerEvent('videodown')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },
});