import request from "@/utils/request.js";
import { ElMessage } from "element-plus";

export function login(data) {
  return request({
    method: "post",
    url: "login/login",
    data,
  });
}

/**
 * 获取版本
 * @returns
 */
export function findVersion() {
  return request({
    method: "post",
    url: "login/findVersion",
  });
}

/**
 * 获取是否显示密码
 * @param {*} params
 * @returns
 */
export function queryPwdInfo() {
  let userInfo = JSON.parse(localStorage.getItem("userInfo"));
  return request({
    method: "get",
    url: "/shopInfo/queryPwdInfo",
    params: {
      shopId: userInfo.shopId,
    },
  });
}

/**
 * 查询店铺信息
 * @param {*} params
 * @returns
 */
export function queryShopInfo() {
  let userInfo = JSON.parse(localStorage.getItem("userInfo"));
  return request({
    method: "get",
    url: "/shopInfo/queryShopInfo",
    params: {
      shopId: userInfo.shopId,
    },
  });
}

/**
 * 查询员工是否拥有权限
 * @param {*} params
 * @returns
 */
export async function staffPermission(code) {
  let userInfo = JSON.parse(localStorage.getItem("userInfo"));
  if (userInfo.isStaff) {
    const res = await request({
      method: "get",
      url: "/staffPermission",
      params: {
        staffId: userInfo.staffId,
        code: code,
      },
    });

    if (res) {
      return Promise.resolve();
    } else {
      ElMessage.error("无权操作");
      return Promise.reject('无权操作');
    }
  } else {
    return Promise.resolve();
  }
}
