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]
            });
        }
    }
}