import http from "@/utils/request"
import common from "@/utils/common"

export default {
    adminRoleSelectList: {
        method: 'GetAdminRoleSelectList',
        name: "角色下拉列表",
        post: async function (data = {}) {
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    adminList: {
        method: 'GetAdminPagesAsync',
        name: "查询管理员列表",
        post: async function (params) {
            var queryType = params.queryType == null ? '' : params.queryType;
            var data = {
                'PageIndex': params.page,
                'PageSize': params.pageSize,
                'QueryType': queryType,
                'KeyWord': params.keyword,
                'RoleCode': params.roleCode
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    createAdmin: {
        method: 'CreateAdminAsync',
        name: "创建管理员",
        post: async function (req) {
            var roleCodes = [];
            if (req.roleCode != null || req.AdminRoleCode != '') {
                roleCodes.push(req.AdminRoleCode);
            }
            else {
                roleCodes = null;
            }
            var data = {
                'AdminName': req.AdminName,
                'FullName': req.AdminFullName,
                'SecretPassword': req.Password1,
                'RoleCodes': roleCodes,
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    modifyAdmin: {
        method: 'ModifyAdminAsync',
        name: "修改管理员",
        post: async function (req) {
            var roleCodes = [];
            if (req.roleCode != null || req.AdminRoleCode != '') {
                roleCodes.push(req.AdminRoleCode);
            }
            else {
                roleCodes = null;
            }
            var data = {
                'AdminCode': req.AdminCode,
                'AdminName': req.AdminName,
                'FullName': req.AdminFullName,
                'SecretPassword': req.Password1,
                'RoleCodes': roleCodes,
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    adminRoleList: {
        method: 'GetAdminRolePagesAsync',
        name: "查询管理员角色列表",
        post: async function (params) {

            var data = {
                'PageIndex': params.page,
                'PageSize': params.pageSize,
                'RoleName': params.keyword
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    adminFeatureList: {
        method: 'GetAdminFeatureList',
        name: "权限列表",
        post: async function (data = {}) {
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    createAdminRole: {
        method: 'CreateAdminRole',
        name: "创建管理员角色",
        post: async function (req) {
            var data = {
                'RoleName': req.RoleName,
                'Description': req.Description,
                'FeaturesCodeList': req.featuresCodeList
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    modifyAdminRole: {
        method: 'ModifyAdminRole',
        name: "修改管理员角色",
        post: async function (req) {
            var data = {
                'RoleCode': req.AdminRoleCode,
                'RoleName': req.RoleName,
                'Description': req.Description,
                'FeaturesCodeList': req.featuresCodeList
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
    },
    adminRoleDetail: {
		method: 'AdminRoleDetail',
		name: "角色详情",
		post: async function (roleCode) {
            var data = {
                'AdminRoleCode':roleCode
            }
            return await http.post({
                "jsonrpc": "2.0",
                "id": common.guid(),
                "method": this.method,
                "params": [data]
            });
        }
	},
}