import { formatTime, formatDate, formatDateTime, BASE_URL, getHeaders } from './index.js'; // 引入时间格式化函数和BASE_URL

//@ts-ignore
import md5 from '@/utils/md5.js'

export function login(username: string, password: string): Promise<{
  code: number;
  msg: string;
  data: {
    token: string;
    userLoginRequestVO: {
      id: number;
      user_name: string;
      user_login_name: string;
      user_type: string;
      user_pic_path: string | null;
      role_id: number | null;
      role_name: string | null;
      hosp_id: number | null;
      hospName: string | null;
      hospPic: string | null;
      hospCenterX: number | null;
      hospCenterY: number | null;
      role: string[] | null;
      assetsRole: number | null;
      roles: string[] | null;
    }
  }
}> {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${BASE_URL}/myUser/login2`,
      method: 'POST',// 请求方法：POST
      data: {
        mobile: username,
        password: md5.hexMD5(username + password),
        role: '007'
      },

      header: getHeaders(),

      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data as any);
        } else {
          reject(res);
        }
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}