"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 {pageInfoMap} from "../../../pageInfoMap.js";
import {khcModalSlide} from "../../../component/alert/khcModalSlide.js";
import {config} from "../../../config.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 sendSystemNotify(){
    let jsonConfig=this;
    let queryViewComponent = fullMap.getObj(jsonConfig.objID);
    let tableViewComponent = queryViewComponent.getTableObj();
    let pageComponent=fullMap.getObj(queryViewComponent.pageID);
    let content = tableViewComponent.getContentMap().get(jsonConfig.pkCode.toString());
    let data = {};
    data['title'] = '立即发送确认';
    data['confirmButtonColor'] = '#3085d6';
    data['cancelButtonColor'] = '#181C21E6';
    khcAlert.showConfirm(data, ()=>{
        let code = {};
        let componentArray = fullMap.getObj(queryViewComponent.pageID).componentArray;
        for (let i = 0; i < componentArray.length; i++) {
            if (componentArray[i].type == 'form') {
                code = componentArray[i].code;
            }
        }
        let formCode = code.formCode;
        let dsCode = code.dsCode;
        let version = code.version;
        let formValueArray=[];
        content.system_notify_status='1';//将状态2改为1：暂存 改成 立即发送
        formValueArray.push(content)
        let params = { "version": version, "dsCode": dsCode, "formCode": formCode, "saveData": formValueArray }
        let obj={url:config.getConfigJson().saveUrl,params:params}
        return httpUtil.post(obj, (response)=>{
            Swal.fire(
                '操作成功',
                '',
                'success'
            )
            pageComponent.queryComponent.getTableObj().refresh();
        })
    });
}
functionMap.set('sendSystemNotify', sendSystemNotify);// 将函数添加到 Map 中