"use strict";
import { fullMap } from '../../../fullMap.js';
import { khcAlert } from '../../../component/alert/khcAlert.js'
import { form } from '../../../component/page/form/form.js';
import { util } from '../../../util/util.js'
import { khcModal } from '../../../component/alert/khcModal.js'
import {config} from "../../../config.js";
import {pageInfoMap} from "../../../pageInfoMap.js";
import {httpUtil} from "../../../util/httpUtil.js";
let functionMap=new Map();// 使用 Map 来存储多个函数。每个函数都通过 set 方法添加到 Map 中，键是函数名，值是对应的函数。
export function main(jsonConfig) {
    try {
        functionMap.get(jsonConfig.button_method).apply(jsonConfig);
    } catch (error) {
        khcAlert.showSystemError(error.message);
        console.log(error);
    }
}
function editRoleUser(){
    let jsonConfig=this;
    let code={dsCode:'ds_system_roleuser',formCode:'form_roleuser_role',queryCode:''}
    jsonConfig.button_method='editOneByModalSlide';
    jsonConfig.paramsAfterFunc=function (params){
        return util.clone(code);
    }
    jsonConfig.getKhcModalForFormAfterFunc=function (pageComponent){
        return pageComponent.editRoleUserByModalSlideForm
    }
    jsonConfig.setKhcModalForFormAfterFunc=function (pageComponent,khcModalForForm){
        pageComponent.editRoleUserByModalSlideForm=khcModalForForm;
    }
    jsonConfig.renderThenFunc=function (content){
        let queryViewComponent = fullMap.getObj(jsonConfig.objID);
        let khcModalForForm=fullMap.getObj(queryViewComponent.pageID).editRoleUserByModalSlideForm;
        let formComponent=khcModalForForm.formComponent;
        let eleMap = formComponent.getFormMap();
        let params=util.clone(code);
        params.roleId=content.role_id;
        params.methodName='getAllUserByRoleId';
        let obj={url:config.getConfigJson().myActionUrl,params:params}
        httpUtil.post(obj, (response)=>{
            eleMap.get('role_id').setValue(content.role_id)
            eleMap.get('user_id').setValue(response.data.data.data)
        })
        formComponent.setSaveAfter( ()=> {
            queryViewComponent.getTableObj().refresh();
            khcModalForForm.hide();
        })
        formComponent.formEdit();
        khcModalForForm.show();
    }
    util.import2023(config.getConfigJson().tableActionPath,jsonConfig);
}
functionMap.set('editRoleUser', editRoleUser);// 将函数添加到 Map 中