import {httpApi} from "../../request/httpApi";
import website from "@/config/index";
import md5 from 'js-md5'

export default {
    //分页数据
    async userLogin({tenantId, deptId, roleId, username, password, type, key, code}) {
        return httpApi({
            url: '/api/blade-auth/oauth/token',
            method: 'post',
            headers: {
                'Tenant-Id': tenantId,
                'Dept-Id': (website.switchMode ? deptId : ''),
                'Role-Id': (website.switchMode ? roleId : ''),
                'Captcha-Key': key,
                'Captcha-Code': code,
            },
            params: {
                tenantId,
                username,
                password: md5(password),
                grant_type: (website.captchaMode ? "captcha" : "password"),
                scope: "all",
                type
            }
        })
    },
    async refreshToken({token, tenantId, deptId, roleId}) {
        return httpApi({
            url: '/api/blade-auth/oauth/token',
            method: 'post',
            headers: {
                'Tenant-Id': tenantId,
                'Dept-Id': (website.switchMode ? deptId : ''),
                'Role-Id': (website.switchMode ? roleId : ''),
            },
            params: {
                tenantId,
                refresh_token: token,
                grant_type: 'refresh_token',
                scope: 'all',
            },
        })
    },
    async queryCurrentUserData() {
        return httpApi({
            url: '/api/blade-business/userViewProjectContract/queryCurrentUserData',
            method: 'post',
            data: {},
        })
    },
    //更新用户信息
    async updateUserInfo(form) {
        return httpApi({
            url: '/api/blade-user/update-info',
            method: 'post',
            data: form,
        })
    },
    async appQuerYownData(form) {
        return httpApi({
            url: '/api/blade-manager/managerHomePage/appqueryowndata',
            method: 'post',
            data: form,
        })
    },
    //修改密码
    async updatePassword(form) {
        return httpApi({
            url: '/api/blade-user/update-password',
            method: 'post',
            params: form,
        })
    },
    //用户配置详情
    async userConfigInfo(form) {
        return httpApi({
            url: '/api/blade-business/defaultConfig/detail',
            method: 'get',
            params: form,
        })
    },
    //用户配置保存
    async userConfigSave(form) {
        return httpApi({
            url: '/api/blade-business/defaultConfig/saveOrUpdate',
            method: 'post',
            data: form,
        })
    },
}
