import {stringify} from 'qs';
import request from './../utils/request';

export async function authLogin(params) {
    let formdata = new FormData();
    formdata.append("user_id", params.user_id);
    formdata.append("access_token", params.access_token);

    return request('/touchd/rn/auth_login/', {
        method: 'POST',
        body: formdata,
    });
}

export async function login(params) {
    let formdata = new FormData();
    formdata.append("username", params.username);
    formdata.append("password", params.password);

    return request('/touchd/rn/login/', {
        method: 'POST',
        body: formdata,
    });
}

export async function loginOut() {
    return request(`/touchd/rn/login_out/`);
}

export async function queryInfo() {
    return request(`/touchd/rn/get_userInfo/`);
}

export async function queryPermissions() {
    return request(`/touchd/rn/get_permissions/`);
}

//公告列表
export async function queryNoticeList(params) {
    return request(`/office/touch/notice/data/?${stringify(params.getParm)}`);
}

//公告详情
export async function queryNoticeDetail(params) {
    return request(`/office/notice/` + params.id + `/`);
}

//回复公告
export async function replyNotice(params) {
    let formdata = new FormData();
    formdata.append('content', params.content)
    return request(`/office/notice/` + params.id + `/reply/`, {
        method: 'POST',
        body: formdata,
    });
}

//收信列表
export async function queryReceiveMessageList(params) {
    return request(`/office/message/data/?${stringify(params.getParm)}`);
}

//发信列表
export async function querySendMessageList(params) {
    return request(`/office/message/send/data/?${stringify(params.getParm)}`);
}

//读私信
export async function readReceiveMessage(params) {
    return request(`/office/message/` + params.id + `/read/`);
}

//回复私信
export async function replyMessage(params) {
    let formdata = new FormData();
    formdata.append('content', params.content)
    formdata.append('title', params.title)
    formdata.append('to_user', params.to_user)
    return request(`/office/message/send/`, {
        method: 'POST',
        body: formdata,
    });
}

//修改密码
export async function changePassword(params) {
    let formdata = new FormData();
    formdata.append('old_password', params.old_password)
    formdata.append('new_password_repeat', params.new_password_repeat)
    formdata.append('new_password', params.new_password)
    formdata.append('user_id', params.user_id)
    return request(`/touchd/rn/change_password/`, {
        method: 'POST',
        body: formdata,
    });
}

//验证登录地址
export async function checkBaseURL(params) {
    return request(`/touchd/rn/echo/`);
}
