mitao
2025-03-31 ce396f73fa41c66cbdb02c61cafa90b08f41ab48
cloud-server-management/src/main/webapp/WEB-INF/view/system/tHuiminAgreement/tHuiminAgreement_add.html
@@ -13,7 +13,7 @@
                        <div class="tab-content">
                            <div id="tab-1" class="tab-pane active">
                                <div class="panel-body">
                                    <textarea id="editor_1" type="text/plain" style="width:1200px;height:400px;"></textarea>
                                    <textarea id="editor_1" type="text/plain" style="width:1200px;height:400px;">${item.addUserRemark!}</textarea>
                                    <!--<div class="row btn-group-m-t">
                                        <div class="col-sm-10 col-sm-offset-5">
                                            <#button btnCss="info" name="保存" id="ensure" icon="fa-check" clickFun=""/>
@@ -23,7 +23,7 @@
                            </div>
                            <div id="tab-2" class="tab-pane">
                                <div class="panel-body">
                                    <textarea type="text/plain" id="editor_2" style="width:1200px;height:400px;"></textarea>
                                    <textarea type="text/plain" id="editor_2" style="width:1200px;height:400px;"${item.selectUserRemark!}</textarea>
                                    <!--<div class="row btn-group-m-t">
                                        <div class="col-sm-10">
                                            <#button btnCss="info" name="保存" id="ensure" icon="fa-check" clickFun=""/>
@@ -37,12 +37,16 @@
                @}
                <div class="form-group">
                    <label class="col-sm-1 control-label" for="operator">所属运营商:</label>
                    <div class="col-sm-9">
                    <div class="col-sm-3">
                        <select id="operator" class="form-control">
                            <option value="" selected>默认</option>
                            <option value="">默认</option>
                            @if(isNotEmpty(operatorList)){
                            @for(item in operatorList){
                            <option value="${item.id}">${item.name}</option>
                                @if(objectType == 2){
                                    <option value="${item.id}" ${operatorId == item.id ? 'selected disabled' : ''}>${item.name}</option>
                                @}else{
                                    <option value="${item.id}">${item.name}</option>
                                @}
                            @}
                            @}
                        </select>
@@ -50,10 +54,14 @@
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">门店无惠民卡介绍页</label>
                    <div class="col-sm-9">
                        <textarea id="editor_3" type="text/plain" style="width:1200px;height:400px;">${item.storeNoHuiminCardIntro!}</textarea>
                    </div>
                </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label" for="agreement">协议配置:</label>
                    <div class="col-sm-9">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" id="agreement" name="agreement" class="form-control" placeholder="请输入协议配置标题">
                            <span class="input-group-btn">
@@ -90,6 +98,7 @@
<script>
    var editor_1 = null;
    var editor_2 = null;
    var editor_3 = null;
    var dynamicEditors = []; // 存储动态创建的编辑器实例
    var editorCounter = 0; // 用于生成唯一ID
@@ -97,7 +106,8 @@
        //初始化编辑器
        editor_1 = UE.getEditor('editor_1');
        editor_2 = UE.getEditor('editor_2');
        editor_3 = UE.getEditor('editor_3');
        // 绑定添加按钮的点击事件
        $("#agreementAdd").click(function() {
            var title = $("#agreement").val().trim();
@@ -107,15 +117,76 @@
            }
            
            // 创建新的编辑器区域
            addNewEditor(title);
            addNewEditor(title,"");
            
            // 清空输入框
            $("#agreement").val("");
        });
        //协议配置回显
        let settingList = '${tHuiminAgreementSettingList}';
        if (settingList != "" && typeof settingList != "undefined"){
            let settingArr = JSON.parse(settingList);
            review(settingArr);
        }
        //经营商切换事件
        $("#operator").change(function() {
            //清空协议配置
            removeAll()
            //调用接口获取协议配置数据
            //提交信息
            var ajax = new $ax(Feng.ctxPath + "/tHuiminAgreement/selectAgreementByOperationId", function(data){
                if (data.data != "" && data.data != null){
                    console.log("协议配置数据:"+data.data);
                    let settingArr = JSON.parse(data.data);
                    review(settingArr);
                }
            },function(data){
            });
            ajax.set("operatorId",$("#operator").val());
            ajax.start();
        });
    });
    // 添加新的编辑器函数
    function addNewEditor(title) {
    // 清空所有编辑器实例和UI元素
    function removeAll(){
        console.log("清空协议配置");
        $("#dynamic-tabs-container").hide();
        // 彻底清空容器内容,确保没有残留
        $("#agreement-tabs").empty();
        $("#agreement-content").empty();
        // 销毁所有编辑器实例
        for(var i = 0; i < dynamicEditors.length; i++) {
            try {
                if(dynamicEditors[i].editor) {
                    dynamicEditors[i].editor.destroy();
                    dynamicEditors[i].editor = null;
                }
            } catch(e) {
                console.error("销毁编辑器出错:", e);
            }
        }
        editorCounter = 0;
        //清空动态创建的编辑器实例
        dynamicEditors=[];
        console.log("dynamicEditors",dynamicEditors)
    }
    // 协议配置回显
    function review(settingArr){
        if (typeof settingArr !== 'undefined' && settingArr.length > 0) {
            settingArr.forEach(function(item) {
                addNewEditor(item.title, item.content || "");
            });
        }
    }
    // 添加新的编辑器函数 - 修改为接受内容参数
    function addNewEditor(title, content) {
        editorCounter++;
        var editorId = "dynamic-editor-" + editorCounter;
        var tabId = "agreement-tab-" + editorCounter;
@@ -157,24 +228,41 @@
        
        // 确保编辑器已准备好
        editor.ready(function() {
            // 初始化为空内容
            editor.setContent("");
            // 存储编辑器实例和标题信息
            dynamicEditors.push({
                id: editorId,
                tabId: tabId,
                counter: editorCounter,
                title: title,
                editor: editor
            });
            // 绑定删除按钮事件
            $(".delete-tab[data-editor-id='" + editorId + "']").click(function(e) {
                e.preventDefault();
                e.stopPropagation();
                deleteEditor($(this).data("counter"));
            });
            try {
                // 检查编辑器是否已准备好接收内容
                if(editor.body) {
                    // 初始化内容
                    editor.setContent(content || "");
                } else {
                    // 如果编辑器body未准备好,延迟设置内容
                    setTimeout(function() {
                        try {
                            editor.setContent(content || "");
                        } catch(e) {
                            console.error("延迟设置编辑器内容出错:", e);
                        }
                    }, 500);
                }
                // 存储编辑器实例和标题信息
                dynamicEditors.push({
                    id: editorId,
                    tabId: tabId,
                    counter: editorCounter,
                    title: title,
                    editor: editor,
                    content: content || ""
                });
                // 绑定删除按钮事件
                $(".delete-tab[data-editor-id='" + editorId + "']").click(function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                    deleteEditor($(this).data("counter"));
                });
            } catch(e) {
                console.error("编辑器初始化出错:", e);
            }
        });
        
        // 手动激活新添加的标签页
@@ -239,9 +327,22 @@
    collectDynamicEditors = function() {
        var agreements = [];
        for(var i = 0; i < dynamicEditors.length; i++) {
            var content = "";
            try {
                // 确保编辑器实例存在且可用
                if(dynamicEditors[i].editor && dynamicEditors[i].editor.isReady) {
                    content = dynamicEditors[i].editor.getContent();
                } else {
                    content = dynamicEditors[i].content || "";
                }
            } catch(e) {
                console.error("获取编辑器内容出错:", e);
                content = dynamicEditors[i].content || "";
            }
            agreements.push({
                title: dynamicEditors[i].title,
                content: dynamicEditors[i].editor.getContent()
                content: content
            });
        }
        return agreements;
@@ -256,6 +357,7 @@
        });
        ajax.set("addUserRemark", editor_1.getContent());
        ajax.set("selectUserRemark", editor_2.getContent());
        ajax.set("storeNoHuiminCardIntro", editor_3.getContent());
        ajax.set("operatorId", $("#operator").val());
        ajax.set("agreementSettings", JSON.stringify(collectDynamicEditors()));
        ajax.set("id", $("#id").val());