import request from './fetcher/request'

export default {
  // 用户详情
  fetchUserInfo (user_id) {
    return request.get('user/detail', { user_id })
  },
  // 登录
  /*
  ** wx_code String
  ** phone_num String
  ** iv String
  */
  loginByPhoneCode (data) {
    return request.post(`guide/login`, data)
  },
  loginByUserInfo (data) {
    return request.post('viewer/login', data)
  },
  loginByPhoneCodeAgency (data) {
    let str = '?'
    Object.keys(data).forEach(item => {
      str += `${item}=${data[item]}&`
    })
    
    return request.post(`agency/login${str}`, data)
  },

  updateUserInfo (userinfo) {
    return request.post('viewer/updateInfo', userinfo)
  },

  getUserInfoById (viewerId ) {
    return request.get('viewer/getViewerDetail', {viewerId })
  },

  getVisitCardList (type=0) {
    let data = {
      viewerId: getApp().globalData.userinfo.viewerId,
      pageNum: 1,
      pageSize: 9999,
      type: type
    }
    return request.get('viewer/getVisitCardList', data)
  },

  getVisitCardDetail (viewerId) {
    return request.get('viewer/visitingCardDetail', { viewerId })
  },

  updateVisitCard (data) {
    return request.post('viewer/updateVisitingCard', data)
  },

  distingCard (filePath) {
    return new Promise((resolve, reject) => {
      wx.uploadFile({
        filePath: filePath,
        name: 'file',
        url: `http://39.108.220.65:8075/app/viewer/recognizeBusinessCard`,
        success (res) {
          resolve(res)
        },
        fail (err) {
          reject(err)
        }
      })
    })
  },
  createVisitCard (data) {
    return request.post('viewer/addVisitCard', data)
  }
}