/* eslint-disable import/prefer-default-export */
import HTTPREQUEST from "./http"
import Taro from "@tarojs/taro";

// 登录
export const login = (res) => {
  return new Promise(async (resolve, reject) => {
    Taro.showLoading({
      title: '登录中...',
    })
    try {
      let msg = await HTTPREQUEST.post('/login', {
        username: res.username,
        password: res.password,
      });
      if (msg.code == 200) {
        Taro.setStorageSync('token', msg.token);
        Taro.hideLoading();
        Taro.showToast({ title: '登录成功', icon: 'success' })
        resolve(msg);
      } else {
        Taro.hideLoading();
        Taro.showToast({ title: msg.msg, icon: 'none' })
        reject();
      }
    } catch (err) {
      Taro.showToast({ title: '系统错误,请稍后重试', icon: 'none' });
      Taro.hideLoading();
      reject();
      // console.log(err,'login')
    }
  })
}

// 获取用户信息
export const getInfo = (postData = {}) => {
  return HTTPREQUEST.get('/getInfo', postData)
}

// 存储openId
export const setOpenId = (postData = {}) => {
  return HTTPREQUEST.get('/system/weChat/getOpenId', postData)
}

// 项目列表
export const getProjectList = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/list', postData)
}

// 新增项目
export const projectAdd = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/add', postData)
}

// 新增研发日志（打卡）
export const recordAdd = (postData = {}) => {
  return HTTPREQUEST.post('/api/project/addRecord', postData)
}

// 查询打卡剩余时间
export const myDuration = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/myDuration', postData)
}

// 研发日志列表
export const listRecord = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/listRecord', postData)
}

// 研发日志批量审核
export const batchExamineRecord = (postData = {}) => {
  return HTTPREQUEST.post('/api/project/batchExamineRecord', postData)
}

// 研发日志详情
export const recordDetails = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/recordDetails', postData)
}

// 研发项目详情
export const projectDetails = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/details', postData)
}

// 研发日志审核
export const examineRecord = (postData = {}) => {
  return HTTPREQUEST.post('/api/project/examineRecord', postData)
}

// 打卡审核日志
export const listRecordLog = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/listRecordLog', postData)
}

// 修改研发打卡
export const updateRecord = (postData = {}) => {
  return HTTPREQUEST.post('/api/project/updateRecord', postData)
}

// 查询打卡数据
export const myDurationMonth = (postData = {}) => {
  return HTTPREQUEST.get('/api/project/myDurationMonth', postData)
}