import request from '@/utils/request';

/**
 * 通知列表
 * @param params 查询条件
 */
export async function pageNotice(params) {
  const res = await request.get('/user/notice/page', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取未读消息数
 * @param params
 * @returns {Promise<*>}
 */
export async function unRead(params) {
  const res = await request.get('/user/notice/unRead', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function setRead(data) {
  const res = await request.post('/user/notice/read', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
