import request from '../utils/request.js'

class activity extends request {

/**
 * 获取活动列表
 * @param {*} nextPage 
 * @param {*} pageSize 
 * @param {*} status 
 */
  static async getActivityList(nextPage,pageSize,status) {
    let params = {
      nextPage:nextPage,
      pageSize:pageSize,
      condition:{
        statusList:[status],
        source:"FREE_MINI_APP",
      }
    };
    const res = await this.postRequest(`${this.BASE_URL}open/activity/get-list`, params)

    return res.data
  }

  static async isShareByMobile(mobile) {
    let params = {
      mobile:mobile
    };
    const res = await this.postRequest(`${this.BASE_URL}open/activity/is-share-by-mobile`, params)

    return res.data
  }
  /**
   * 获取支付参数
   * @param {*} orderSn 
   */
  static async getOrderParams(orderSn,activityName='') {
    let params = {
      orderSn:orderSn,
      source:"FREE_MINI_APP",
      thirdPartyName:activityName,
      openId:wx.getStorageSync('loginInfo').openId,
      payCode:'',
    };
    const res = await this.postRequest(`${this.BASE_URL}open/activity/get-order-params`, params)
    return res.data
  }

  /**
   * 获取活动详情
   * @param {*} activityId 活动id
   */
  static async getActivityDetail(activityId) {
    let params = {
      activityId:activityId
    };
    const res = await this.getRequest(`${this.BASE_URL}open/activity/get`, params)

    return res.data
  }

  /**
   * 领券
   * @param {*} activityId 
   * @param {*} memberMobile 
   * @param {*} number 
   * @param {*} shopId 
   */
  static async createOrder(activityId,memberMobile,num=1,shopId='') {
    let params = {
      activityId:activityId,
      memberMobile:memberMobile,
      num:num,
      shopId:shopId
    };
    console.log('参数');
    console.log(params);
    const res = await this.postRequest(`${this.BASE_URL}open/activity/create-order`, params)
    return res.data
  }

  /**
   * 分享活动的分享码
   * @param {*} activityId 
   * @param {*} mobile 
   */
  static async createShareActivityCode(activityId,mobile) {
    let params = {
      activityId:activityId,
      mobile:mobile
      // activityId:'Bg5740r78w',
      // mobile:13205528979
    };
    const res = await this.postRequest(`${this.BASE_URL}open/activity/create-share-activity-code`, params)
    return res.data
  }
  //根据codeId 获取 分享活动的详细信息
  static async getShareActivityCode(codeId) {
    let params = {
      codeId:codeId,
    };
    console.log(params)
    const res = await this.postRequest(`${this.BASE_URL}open/activity/get-share-activity-code`, params)
    return res.data
  }

  /**
   * 获取我的券列表
   * @param {*} nextPage 
   * @param {*} pageSize 
   * @param {*} mobile 
   */
  static async getSnListMember(nextPage,pageSize,mobile) {
    let params = {
      nextPage:nextPage,
      pageSize:pageSize,
      condition:{
        mobile:mobile
      }
    };
    const res = await this.postRequest(`${this.BASE_URL}open/activity/sn-list-member`, params)
    return res.data
  }

  //绑定券与codeId之间的关系
  static async bindShareCode(orderSn,codeId) {
    let params = {
      orderSn:orderSn,
      codeId:codeId
    };
    const res = await this.postRequest(`${this.BASE_URL}open/activity/bind-share-code`, params)
    return res.data
  }
  
  static async getSessionKeyFromApi(code) {
    let params = {
      appCode:getApp().globalData.appCode,
      sessionCode:code
    };
   
    const res = await this.postRequest(`${this.BASE_URL}open/wxapp/wx-login`, params)
    return res.data
  }

  /**
   * 解锁手机号
   * @param {*} orderSn 
   */
  static async getAuthMobile(params) {
   
    const res = await this.postRequest(`${this.BASE_URL}open/wxapp/auth-mobile`, params)
    return res.data
  }

    /**
   * 解锁手机号  新接口
   * @param {*} orderSn 
   */
  static async getAuthMobileNew(params) {
   
    const res = await this.postRequest(`${this.BASE_URL}open/wxapp/auth-mobile-new`, params)
    return res.data
  }

  /**
   * 保存用户信息
   * @param {*} openId 
   * @param {*} mobile 
   */
  static async saveUser(openId,mobile,headerImg="",nickName="") {
    let params = {
      openid:openId,
      mobile:mobile,
      source:'FREE_MINI_APP'
    };
    if(headerImg){
      params.headerImg = headerImg;
    }
    if(nickName){
      params.nickName = nickName;
    }

    const res = await this.postRequest(`${this.BASE_URL}open/activity/save-user`, params)
    return res.data
   
  }

  static async getUserInfo(mobile) {
    let params = {
      mobile:mobile,
      source:'FREE_MINI_APP'
    };
   
    const res = await this.postRequest(`${this.BASE_URL}open/activity/get-user`, params)
    return res.data
   
  }

  

  /**
   * 设置手机缓存
   * @param {*} mobile 
   */
  static setMobileCache(mobile) {
    let data = {
      mobile:mobile,
    }
    wx.setStorageSync('userInfo',data);
  }

  static getMobileCache() {
    let userInfo = wx.getStorageSync('userInfo');
    if(userInfo) {
      return userInfo.mobile;
    }
    return '';
  }

  // static getSessionKey() {
  //   return wx.getStorageSync('loginInfo').sessionKey;
  // }

  /**
   * 获取用户openid
   */
  static getOpenId() {
    return wx.getStorageSync('loginInfo').openId;
  }

  /**
  * 卡券详情数据
  */
  static getCouponDetailData(params) {
    return this.postRequest(`${this.BASE_URL}open/coupon/get-coupon-data`, params);
  }

  static getFoodListByCoupon(params) {
    return this.postRequest(`${this.BASE_URL}open/coupon/get-food-list-by-coupon`, params);
  }

  static getStoreListByCoupon(params) {
    return this.postRequest(`${this.BASE_URL}open/coupon/get-store-list-by-coupon`, params);
  }
}

export default activity