<template>
    <div>
        <el-container class="_fc-designer" :style="setBodyHeight()" id="mainBody">
            <el-main style="padding:0px;">
                <el-container style="height: 100%;">
                    <el-aside class="_fc-l" :style="asideStyle.defaultStyle">
                        <div id="collapseList" style="position: fixed;top: 60px;z-index:1000;width:17%;">
                            <el-collapse style="margin-top: -1px;" v-model="activeNames" v-for="(item, index) in moduleList" :id="item.title" 
                                :key="index">
                                <el-collapse-item :title="$t(item.title)" :name="index" class="_fc-l-group">
                                    <draggable filter=".forbid" item-key="id"
                                        :group="{ name: 'people', pull: 'clone', put: false }" :disabled="dragDisabled"
                                        :sort="false" :list="item.list" :fallback-tolerance="100" :touchStartThreshold="100"
                                        :clone="cloneDrag" :move="onMove">
                                        <template #item="{ element }">
                                            <div :class="element.disabledMove ? 'forbid _fc-l-item' : '_fc-l-item'"
                                                :key="element.name" v-if="element.name == 'custom'"
                                                @click="operateClick(element)">
                                                <div class="_fc-l-icon">
                                                    <el-icon :size="25" :title="item.label">
                                                        <sc-icon-addfour />
                                                    </el-icon>
                                                </div>
                                                <span class="_fc-l-name">{{ $t(element.label) }}</span>
                                            </div>
                                            <div :class="element.disabledMove ? 'forbid _fc-l-item' : '_fc-l-item'"
                                                v-else-if="element.name == 'footer' || element.name == 'header'"
                                                @click="attachClick(element.name)">
                                                <div class="_fc-l-icon">
                                                    <el-icon :size="25" :title="item.label">
                                                        <sc-icon-addfour />
                                                    </el-icon>
                                                </div>
                                                <span class="_fc-l-name">{{ $t(element.label) }}</span>
                                            </div>
                                            <div :class="element.disabledMove ? 'forbid _fc-l-item' : '_fc-l-item'" v-else>
                                                <div class="_fc-l-icon">
                                                    <i class="fc-icon" :class="element.icon || 'icon-input'"></i>
                                                </div>
                                                <span class="_fc-l-name">{{ $t(element.label) }}</span>
                                            </div>
                                        </template>
                                    </draggable>
                                </el-collapse-item>
                            </el-collapse>
                        </div>
                    </el-aside>
                    <el-container class="_fc-m">
                        <el-header class="_fc-m-tools" id="headerTools"
                            style="justify-content: flex-start;height:40px;background: #F6F8F9;position: fixed;top: 60px;z-index:1000;width:85%;">
                            <sc-designer-style ref="scStyleTool" :config="fontStyleList" @footerStyleEventClick="footerStyleEventClick" 
                                @styleEventClick="headerStyleEventClick" @operateEventClick="headerOperateEventClick"
                                @loadDefaultData="loadDefaultData" @manualEventClick="manualEventClick" />
                        </el-header>
                        <div style="height:10px;">
                        </div>
                        <el-main class="_fc-main-location" style="background: #F5F5F5;padding: 0px;display: flex;justify-content: center;">
                            <div class="_fc-m-drag" id="dragMainContent" :style="draggableContentStyle()">
                                <div :style="setPaperTextStyle(activeTemplateSet.paperHeaderFooter.usePaperHeader)" id="headerDragToolDiv">
                                    <sc-designer-header ref="scDragHeaderTool"
                                        :defaultConfig="cloneDrag({ name: 'header' })"
                                        @dragAttributeEvent="dragHeaderAttributeEventClick"
                                        @dragActiveEventClick="setActiveEventClick" 
                                        @dragSetScrollToTop = "dragSetScrollToTopClick"
                                        @headerAndFooterRenderEvent="headerAndFooterRender" />
                                </div>
                                <div :style="contentDragStyle" id="contentDragToolDiv" :title="setContentStyle()">
                                    <sc-designer-drag ref="scDragTool" :defaultConfig="cloneDrag({ name: 'grid' })" :offsetPageWidth="factPageWidth"
                                        @dragAttributeEvent="dragAttributeEventClick"
                                        @dragSetHeightEvent = "dragSetHeightEventClick"
                                        @dragSetScrollToTop = "dragSetScrollToTopClick"
                                        @dragActiveEventClick="setActiveEventClick" />
                                </div>
                                <div :style="setPaperTextStyle(activeTemplateSet.paperHeaderFooter.usePaperFooter)" id="footerDragToolDiv">
                                    <sc-designer-footer ref="scDragFooterTool"
                                        :defaultConfig="cloneDrag({ name: 'footer' })"
                                        @dragAttributeEvent="dragFooterAttributeEventClick"
                                        @dragActiveEventClick="setActiveEventClick" 
                                        @dragSetScrollToTop = "dragSetScrollToTopClick"
                                        @headerAndFooterRenderEvent="headerAndFooterRender" />
                                </div>
                            </div>
                        </el-main>
                        <div style="height:10px;">
                        </div>
                        <el-header class="_fc-m-tools" id="footerScroll" :style="footerButtomStyle">
                            <el-button type="primary" size="default" icon="sc-icon-save" @click="saveTemplate">{{$t("reportDesigner.save")}}
                            </el-button>
                            <el-button size="default" icon="el-icon-view" @click="previewClick">{{$t("reportDesigner.Preview")}}
                            </el-button>
                            <el-button size="default" icon="el-icon-delete" @click="clearDragRule">{{$t("reportDesigner.Clear")}}
                            </el-button>
                        </el-header>
                    </el-container>
                    <el-aside class="_fc-r" style="width:20%;border-left: 1px solid #e6e6e6;min-width:350px;position: relative;z-index:1000;">
                        <el-container style="height: 100%;">
                            <div style="position: fixed;top: 60px;z-index:1000;min-width:20%;" id="rightPropertyMenu">
                                <el-header height="40px" class="_fc-r-tabs">
                                    <div class="_fc-r-tab" :class="{ active: activeTab === 'moduleProperty' }"
                                        v-if="activeModuleList.length > 0" @click="activeTab = 'moduleProperty'">
                                        {{$t("reportDesigner.moduleProperty")}}
                                    </div>
                                    <div class="_fc-r-tab" :class="{ active: activeTab === 'moduleStyle' }"
                                        v-if="activeModuleList.length > 0" @click="activeTab = 'moduleStyle'">
                                        {{$t("reportDesigner.moduleStyle")}}
                                    </div>
                                    <div class="_fc-r-tab" :class="{ active: activeTab === 'form' }"
                                        v-if="(activeModuleList.length <= 0 || isShowPageForm)" @click="activeTab = 'form'">
                                        {{$t("reportDesigner.TemplateSetting")}}
                                    </div>
                                </el-header>
                                <el-main v-show="activeTab === 'form'">
                                    <sc-designer-setting ref="scSetting" :pageConfig="activeTemplateSet"
                                        @pageSetEventClick="pageSettingEventClick" />
                                </el-main>
                                <el-main v-show="activeTab === 'moduleStyle'">
                                    <sc-designer-pattern ref="scPattern" :patternConfig="activeModule"
                                        @patternEventClick="patternChangeEventClick" />
                                </el-main>
                                <el-main v-show="activeTab === 'moduleProperty'" style="padding: 0 20px;"
                                    :key="activeModule ? activeModule._id : ''">
                                    <sc-designer-property ref="scProperty" :propertyConfig="activeModule"
                                        @propertyEventClick="propertyChangeEventClick" />
                                </el-main>
                            </div>
                        </el-container>
                    </el-aside>
                </el-container>
            </el-main>
        </el-container>
    </div>
</template>

<script>

import '@/style/index.css';
import draggable from 'vuedraggable'
import designerInfo from '@/config/designer';
import initPatternData from '@/config/designer/style';
import initPageData from '@/config/designer/page';
import tool from '@/utils/tool';
import common from "@/utils/common"
import ultrasoundImageListInfo from '@/config/designer/group/ultrasoundImageList';
import imageList from '@/config/designer/imageList';
import transfer from '@/utils/transfer';
import api from "@/api"
import load from '@/utils/load';

export default {
    name: 'scDesigner',
    components: {
        draggable,
    },
    data() {
        return {
            dialog: {
                preview: false
            },
            //默认展开折叠面板
            activeNames: [0, 1, 2],
            activeTab: "form",
            activeModule: {},
            asideStyle: {
                defaultStyle: "width:17%;min-width:330px;",
                defaultScreenWidth: document.body.clientWidth, // 屏幕宽度
            },
            activeModuleList: [],
            activeHeaderModuleList: [],
            activeFooterModuleList: [],
            moduleList: designerInfo.createMoudle(),
            activeTemplateSet: initPageData,
            fontStyleList: initPatternData(),
            isLoading: false,
            isShowPageForm: false,
            noBindFieldList: ['space', 'label', 'divider', 'image'],
            dragDisabled: false,
            reportDragControls: ["grid", "replenish", "ultrasoundImageList"],
            reportTableDragControls: ["table", "scanTable", "reportHeader", "doctorInfo", "patientInfo", "diagnosis", "footer", "header"],
            basicDragControls: ["checkbox", "datetime", "divider", "image", "input", "label", "radio", "select", "space", "textarea", "ultrasoundImage"],
            //绑定内容组件列表
            mustbindFieldList: ["checkbox", "datetime", "input", "radio", "select", "textarea", "ultrasoundImage", "ultrasoundImageList", "scanTable"],
            forwardList: [],//前进
            fallbackList: [],//后撤
            lastActiveModule: { curActiveModule: {}, curActiveModuleList: [], parentId: "" },//上一步操作
            copyModule: {
                isCut: false,
                controls: {}
            },//copy的模块
            //内容列表，注释项用
            labelContentList: [],
            templateModelInfo: {},
            queryInfo: {},
            factPageWidth:0,
            measureDataJson: {},
            isShowHeader: false,
            isShowFooter: false,
            factPageHeight:0,
            headerAndFooterHeight:0,
            contentDragStyle: {},
            customCalculationData:{},
            CustomizeCalculations:[],
            unitOptions: [],
            footerButtomStyle:"position: fixed;width:85%;bottom:31px;z-index:600;background: #F6F8F9;height:40px;justify-content: flex-end;border-top: 1px solid #e6e6e6;border-bottom: 0px none;padding-right:45.5%;",
        };
    },
    created() {
        window.addEventListener('keydown', this.keyOperateClick, false);
        // window.addEventListener("scroll", this.scrollToTop,true);
        // this.$nextTick(() => {
        //     document.getElementById("collapseList").style.top = "1px";
        //     document.getElementById("headerTools").style.top = "1px";
        // })
    },
    watch:{
        isShowHeader(){
            this.headerAndFooterRender();
        },
        isShowFooter(){
            this.headerAndFooterRender();
        },
    },
    unmounted() {
        window.removeEventListener('keydown', this.keyOperateClick, false);
        //window.removeEventListener("scroll", this.scrollToTop,true);
    },
    methods: {
        footerStyleEventClick(flag) {
            if (flag) 
            {
                //this.footerButtomStyle = "position: absolute;width:62.7%;bottom:1px;z-index:1000;background: #F6F8F9;height:40px;justify-content: flex-end;border-top: 1px solid #e6e6e6;border-bottom: 0px none;padding-right:27.5%;";
            }
            else
            {
                //this.footerButtomStyle = "position: absolute;width:80%;bottom:1px;z-index:1000;background: #F6F8F9;height:40px;justify-content: flex-end;border-top: 1px solid #e6e6e6;border-bottom: 0px none;padding-right:30.5%;";
            }
        },
        dragSetScrollToTopClick()
        {
            this.scrollToTop();
        },
        scrollToTop() {
            // let that = this;
            // let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
            // that.scrollTop = scrollTop;
            // if (scrollTop <= 0)
            // {
            //     scrollTop = 1;
            // }
            // if (scrollTop > 61) 
            // {
            //     scrollTop = scrollTop - 60;
            // }
            // document.getElementById("collapseList").style.top = scrollTop + "px";
            // document.getElementById("rightPropertyMenu").style.top = scrollTop + "px";
            // document.getElementById("headerTools").style.top = scrollTop + "px";
            // let scrollBottom = document.body.scrollHeight - document.documentElement.clientHeight - scrollTop - 90;
            // if (scrollBottom < 1)
            // {
            //     scrollBottom = 1;
            // }
            // if (scrollTop < 40) 
            // {
            //     scrollBottom = document.body.scrollHeight - document.documentElement.clientHeight - 30;
            // }
            // document.getElementById("footerScroll").style.bottom = scrollBottom + "px";
        },
        headerAndFooterRender() {
            var contentHeight = this.factPageHeight;
            var oriContentHeight = this.factPageHeight;
            var curHeaderAndFooterHeight = 0;
            if (this.isShowHeader) {
                var headerOffsetHeight = document.getElementById("headerDragToolDiv").offsetHeight;
                if (headerOffsetHeight <= 0) {
                    headerOffsetHeight = 38;
                }
                contentHeight -= headerOffsetHeight;
                curHeaderAndFooterHeight += headerOffsetHeight;
            }
            if (this.isShowFooter) {
                var footerOffsetHeight = document.getElementById("footerDragToolDiv").offsetHeight;
                if (footerOffsetHeight <= 0) {
                    footerOffsetHeight = 38;
                }
                contentHeight -= footerOffsetHeight;
                curHeaderAndFooterHeight += footerOffsetHeight;
            }
            this.headerAndFooterHeight = curHeaderAndFooterHeight;
            if (contentHeight === this.factPageHeight) {
                //表示无需处理
            }
            else {
                if (this.isShowHeader || this.isShowFooter) 
                {
                    var dragContentPercentage = Math.floor((contentHeight / oriContentHeight) * 100);
                    var contentHeightStr = (dragContentPercentage - 1).toString() + "%";
                    if (this.contentDragStyle["height"] != contentHeightStr) {
                        this.contentDragStyle["height"] = contentHeightStr;
                    }
                }
            }
        },
        setBodyHeight() {
            var headerHeight = 60;
            var footerHeight = 30;
            var factHeight = document.body.offsetHeight - footerHeight - headerHeight;
            var styleInfo = {
                "height": factHeight + 'px'
            }
            return styleInfo;
        },
        //设置默认数据
        setDefaultParam(data, modelInfo, jsonData, unitOptionList) {
            if (data) {
                if (data.name && data.name.length > 0) {
                    this.activeTemplateSet.name = data.name;
                }
                if (data.type === 0 || data.type === "0") {
                    this.activeTemplateSet.applicable = "Person";
                }
                else {
                    this.activeTemplateSet.applicable = "Animal";
                }
                if (data.userId && data.userId.length > 0) {
                    this.activeTemplateSet.author = data.userId;
                }
                this.queryInfo = data;
            }
            if (unitOptionList && unitOptionList.length > 0) {
                this.unitOptions = unitOptionList;
            }
            if (modelInfo) {
                this.templateModelInfo = modelInfo;
                //加载load的数据
                if (modelInfo.ReportTemplateJson && modelInfo.ReportTemplateJson.length > 0) {
                    var fileContent = JSON.parse(modelInfo.ReportTemplateJson);
                    var templateContent = load.oldJsonTransferNewJson(fileContent);
                    this.loadJsonData(templateContent);
                }
                else
                {
                    this.$refs.scSetting.loadData(this.activeTemplateSet);
                }
            }
            else
            {
                this.$refs.scSetting.loadData(this.activeTemplateSet);
            }
            if (jsonData) {
                this.measureDataJson = jsonData;
                this.$refs.scProperty.loadMeasureDataJson(this.measureDataJson);
            }
        },
        //自定义计算项数据
        setCustomCalculationData(data, customizeCalculationsData) {
            if (customizeCalculationsData) {
                this.CustomizeCalculations = customizeCalculationsData;
            }
            if (data) {
                this.customCalculationData = data;
                this.$refs.scProperty.loadCustomMeasureItemData(this.customCalculationData);
            }
        },
        //设置页眉页脚显示与隐藏
        setPaperTextStyle(type) {
            var styleInfo = {
                "min-height": '35px',
                "margin-bottom": '1px',
                "background": "#D3D3D3"
            };
            if (type) {
                styleInfo["display"] = 'block';
            }
            else {
                styleInfo["display"] = 'none';
            }
            if (this.activeTemplateSet.invertColor === false) {
                styleInfo["filter"] = "invert(0%)";
            }
            else {
                styleInfo["filter"] = "invert(100%)";
            }
            // this.$nextTick(() => {
            //     this.headerAndFooterRender();
            // });
            return styleInfo;
        },
        //附加控件
        attachClick(name) {
            if (name === "header") {
                this.activeTemplateSet.paperHeaderFooter.usePaperHeader = !this.activeTemplateSet.paperHeaderFooter.usePaperHeader;
                this.isShowHeader = this.activeTemplateSet.paperHeaderFooter.usePaperHeader;
            }
            else if (name === "footer") {
                this.activeTemplateSet.paperHeaderFooter.usePaperFooter = !this.activeTemplateSet.paperHeaderFooter.usePaperFooter;
                this.isShowFooter = this.activeTemplateSet.paperHeaderFooter.usePaperFooter;
            }
            this.setActiveEventClick(name);
        },
        setContentStyle() {
            // if (this.headerAndFooterHeight < 38) {
            //     this.contentDragStyle["height"] = "100%";
            // }
            if (this.activeTemplateSet.invertColor === false) {
                this.contentDragStyle["filter"] = "invert(0%)";
            }
            else {
                this.contentDragStyle["filter"] = "invert(100%)";
            }
            return "";
        },
        //预览
        previewClick() {
            var templateContent = {
                currentPageInfo: this.activeTemplateSet,
                currentModuelList: this.activeModuleList,
                currentHeaderModuelList: this.activeTemplateSet.paperHeaderFooter.usePaperHeader ? this.activeHeaderModuleList : [],
                currentFooterModuelList: this.activeTemplateSet.paperHeaderFooter.usePaperFooter ? this.activeFooterModuleList : []
            };
            var gridControls = ["grid", "diagnosis","replenish","header","footer"];
            if (templateContent.currentHeaderModuelList && templateContent.currentHeaderModuelList.length > 0)
            {
                templateContent.currentHeaderModuelList.some(e => {
                    if (gridControls.some(f => f === e.name)) 
                    {
                        if (e.result && e.result.tasks && e.result.tasks.length > 0 ) 
                        {
                            e.result.tasks.forEach(g => {
                                var newLblWidth = document.getElementById(g.id).offsetWidth - 0.9;
                                this.$refs.scDragHeaderTool.setHFGridModuleWidthClick(g.id, newLblWidth, e.id);
                            })
                        }
                    }
                    else
                    {
                        if (e.result && e.result.tasks && e.result.tasks.length > 0) {
                            e.result.tasks.forEach(z => {
                                var colWidthList = e.result.base.columnWidth;
                                var addHeight = this.caculateCellContentFactHeight(z, colWidthList);
                                z.result.offsetHeight = addHeight;
                            });
                        }
                        this.$refs.scDragHeaderTool.setHFTableModuleHeightClick(e.id, e.result.tasks);
                    }
                });
            }
            if (templateContent.currentFooterModuelList && templateContent.currentFooterModuelList.length > 0)
            {
                templateContent.currentFooterModuelList.some(e => {
                    if (gridControls.some(f => f === e.name)) 
                    {
                        if (e.result && e.result.tasks && e.result.tasks.length > 0 ) 
                        {
                            e.result.tasks.forEach(g => {
                                var newLblWidth = document.getElementById(g.id).offsetWidth - 0.9;
                                this.$refs.scDragFooterTool.setHFGridModuleWidthClick(g.id, newLblWidth, e.id);
                            })
                        }
                    }
                    else
                    {
                        if (e.result && e.result.tasks && e.result.tasks.length > 0) {
                            e.result.tasks.forEach(z => {
                                var colWidthList = e.result.base.columnWidth;
                                var addHeight = this.caculateCellContentFactHeight(z, colWidthList);
                                z.result.offsetHeight = addHeight;
                            });
                        }
                        this.$refs.scDragFooterTool.setHFTableModuleHeightClick(e.id, e.result.tasks);
                    }
                });
            }
            tool.data.set("CurrentTemplateContent", templateContent);
            window.open("./reportTemplatePreview",'_blank');
        },
        //快捷键操作
        keyOperateClick(e) {
            if (document.activeElement.tagName === "BODY") {
                if ((e.ctrlKey || e.metaKey) && e.key === 's') {
                    // 保存
                    this.saveTemplate();
                    // 阻止默认事件
                    e.preventDefault();
                }
                else if ((e.ctrlKey || e.metaKey) && e.key === 'd') {
                    // 清空
                    this.clearDragRule();
                    // 阻止默认事件
                    e.preventDefault();
                }
                else if ((e.ctrlKey || e.metaKey) && e.key === 'p') {
                    // 预览
                    this.previewClick();
                    // 阻止默认事件
                    e.preventDefault();
                }
                else if ((e.ctrlKey || e.metaKey) && e.key === 'z') {
                    // 撤销
                    this.manualEventClick(0);
                }
                else if ((e.ctrlKey || e.metaKey) && e.key === 'y') {
                    // 回退
                    this.manualEventClick(1);
                }
                else if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
                    // 复制
                    this.manualEventClick(2);
                }
                else if ((e.ctrlKey || e.metaKey) && e.key === 'x') {
                    // 复制
                    this.manualEventClick(3);
                }
                else if ((e.ctrlKey || e.metaKey) && e.key === 'v') {
                    // 复制
                    this.manualEventClick(4);
                }
            }
            else if (document.activeElement.tagName === "INPUT") {
                if (e.key === 'Enter') {
                    // 阻止默认事件
                    e.preventDefault();
                }
            }
        },
        //普通操作
        manualEventClick(type) {
            var parentId = "";
            if (type === 0) {
                //撤销
                if (this.fallbackList && this.fallbackList.length > 0) {
                    this.forwardList.splice(0, 0, this.lastActiveModule);
                    this.lastActiveModule = this.fallbackList[0];
                    this.activeModuleList = this.fallbackList[0].curActiveModuleList;
                    this.activeModule = this.fallbackList[0].curActiveModule;
                    parentId = this.fallbackList[0].parentId;
                    this.fallbackList.splice(0, 1);
                    this.dragDisabled = false;
                }
            }
            else if (type === 1) {
                //回退
                if (this.forwardList && this.forwardList.length > 0) {
                    this.fallbackList.splice(0, 0, this.lastActiveModule);
                    this.lastActiveModule = this.forwardList[0];
                    this.activeModuleList = this.forwardList[0].curActiveModuleList;
                    this.activeModule = this.forwardList[0].curActiveModule;
                    parentId = this.forwardList[0].parentId;
                    this.forwardList.splice(0, 1);
                    this.dragDisabled = false;
                }
            }
            else if (type === 2) {
                //表格单元格不能复制
                if (this.activeModule.name === "cell") {
                    this.$message.warning(this.$t("reportDesigner.noCopyTableCellMsg"));
                    return;
                }
                if (this.mustbindFieldList.some(c => c === this.activeModule.name)) {
                    if (this.activeModule.result.property.bindField && this.activeModule.result.property.bindField.length > 0) {
                        //有值，继续执行
                    }
                    else {
                        //必须绑定值，才能继续执行
                        this.$message.warning(this.$t("reportDesigner.validateBindContent"));
                        return;
                    }
                }
                //复制,添加到剪切版
                this.copyModule.controls = tool.objCopy(this.activeModule);
                this.copyModule.isCut = false;
            }
            else if (type === 3) {
                //表格单元格不能剪切
                if (this.activeModule.name === "cell") {
                    this.$message.warning(this.$t("reportDesigner.noCutTableCellMsg"));
                    return;
                }
                if (this.mustbindFieldList.some(c => c === this.activeModule.name)) {
                    if (this.activeModule.result.property.bindField && this.activeModule.result.property.bindField.length > 0) {
                        //有值，继续执行
                    }
                    else {
                        //必须绑定值，才能继续执行
                        this.$message.warning(this.$t("reportDesigner.validateBindContent"));
                        return;
                    }
                }
                //剪切,添加到剪切版
                this.copyModule.controls = tool.objCopy(this.activeModule);
                this.copyModule.isCut = true;
                //从列表里面移除
                //操作的是基础组件
                if (this.basicDragControls.some(d => d === this.activeModule.name)) {
                    //判断基础组件的父级是啥
                    if (this.reportDragControls.some(c => c === this.activeModule.result.parentName)) {
                        //表示是grid，找到当前基础组件在grid中的位置，然后加载其后面
                        this.activeModuleList.forEach(m => {
                            if (m.id === this.activeModule.result.parentId) {
                                m.result.tasks.splice(m.result.tasks.indexOf(this.activeModule), 1);
                            }
                        });
                    }
                    else {
                        //表示是表格的cell，找到基础组件在cell中的位置，然后加到其后面，并且要找到cell的table才能操作，及循环两层
                        //单元格组件，加到单元格的最后
                        this.activeModuleList.forEach(m => {
                            if (this.reportTableDragControls.some(p => p === m.name)) {
                                //循环table
                                m.result.tasks.forEach(o => {
                                    //表示cell
                                    if (o.id === this.activeModule.result.parentId) {
                                        o.result.tasks.splice(o.result.tasks.indexOf(this.activeModule), 1);
                                    }
                                });
                            }
                        });
                    }
                }
                else {
                    //grid或者table
                    this.activeModuleList.splice(this.activeModuleList.indexOf(this.activeModule), 1);
                }
                //添加step
                this.addStep();
            }
            else if (type === 4) {
                if (this.copyModule && this.copyModule.controls && this.copyModule.controls.id && this.copyModule.controls.id.length > 0) {
                    //粘贴,这里要判断组件是父还子组件
                    //添加，还要修改parentId，还要判断组件类型，不能随便添加，粘贴
                    //表示复制，要重新赋值id
                    this.assignCommonId();
                    var curCopyModule = tool.objCopy(this.copyModule);
                    if (this.basicDragControls.some(c => c === curCopyModule.controls.name)) {
                        //粘贴的是基础组件
                        if (this.basicDragControls.some(d => d === this.activeModule.name)) {
                            //粘贴位置是基础组件,判断基础组件的父级是啥
                            if (this.reportDragControls.some(c => c === this.activeModule.result.parentName)) {
                                //表示是grid，找到当前基础组件在grid中的位置，然后加载其后面
                                this.activeModuleList.forEach(m => {
                                    if (m.id === this.activeModule.result.parentId) {
                                        var curIndex = m.result.tasks.indexOf(this.activeModule);
                                        m.result.tasks.splice((curIndex + 1), 0, curCopyModule.controls);
                                        parentId = this.activeModule.result.parentId;
                                    }
                                });
                            }
                            else {
                                //表示是表格的cell，找到基础组件在cell中的位置，然后加到其后面，并且要找到cell的table才能操作，及循环两层
                                //单元格组件，加到单元格的最后
                                this.activeModuleList.forEach(m => {
                                    if (this.reportTableDragControls.some(p => p === m.name)) {
                                        //循环table
                                        m.result.tasks.forEach(o => {
                                            //表示cell
                                            if (o.id === this.activeModule.result.parentId) {
                                                var curIndex = o.result.tasks.indexOf(this.activeModule);
                                                o.result.tasks.splice((curIndex + 1), 0, curCopyModule.controls);
                                                parentId = m.id;
                                            }
                                        });
                                    }
                                });
                            }
                        }
                        else if (this.reportDragControls.some(d => d === this.activeModule.name)) {
                            //直接加到最后
                            this.activeModuleList.forEach(m => {
                                if (m.id === this.activeModule.id) {
                                    m.result.tasks.push(curCopyModule.controls);
                                    parentId = m.id;
                                }
                            });
                        }
                        else {
                            if (this.reportTableDragControls.some(d => d === this.activeModule.name)) {
                                return;
                            }
                            else {
                                //单元格组件，加到单元格的最后
                                this.activeModuleList.forEach(m => {
                                    if (m.id === this.activeModule.result.parentId) {
                                        //循环table
                                        m.result.tasks.forEach(o => {
                                            //表示cell
                                            if (o.id === this.activeModule.id) {
                                                o.result.tasks.push(curCopyModule.controls);
                                                parentId = m.id;
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    }
                    else {
                        //表格 或者 grid
                        var curIndex = this.activeModuleList.indexOf(this.activeModule);
                        this.activeModuleList.splice((curIndex + 1), 0, curCopyModule.controls);
                        parentId = this.activeModule.id;
                    }
                    if (this.copyModule.isCut) {
                        //剪切在粘贴完成后，置空
                        this.copyModule.isCut = false;
                        this.copyModule.controls = {};
                    }
                    //添加step
                    this.addStep();
                }
            }
            else if (type === 5) {
                this.saveTemplate()
                return;
            }
            else if (type === 6) {
                this.previewClick();
                return;
            }
            else if (type === 7) {
                this.clearDragRule();
                return;
            }
            this.$refs.scDragTool.reloadDynamicObj(this.activeModule, this.activeModuleList, parentId);
        },
        //重新赋值新的id
        assignCommonId() {
            //必须是新的id
            this.copyModule.controls.id = common.guid();
            if (this.reportDragControls.some(c => c === this.copyModule.controls.name)) {
                //找到的是grid组件
                if (this.copyModule.controls.result && this.copyModule.controls.result.tasks && this.copyModule.controls.result.tasks.length > 0) {
                    this.copyModule.controls.result.tasks.forEach(d => {
                        d.id = common.guid();
                        d.result.parentId = this.copyModule.controls.id;
                    });
                }
            }
            else if (this.reportTableDragControls.some(e => e === this.copyModule.controls.name)) {
                //找到的是table组件
                if (this.copyModule.controls.result && this.copyModule.controls.result.tasks && this.copyModule.controls.result.tasks.length > 0) {
                    //这里是cell
                    this.copyModule.controls.result.tasks.forEach(f => {
                        f.id = common.guid();
                        f.result.parentId = this.copyModule.controls.id;
                        if (f.result.tasks && f.result.tasks.length > 0) {
                            f.result.tasks.forEach(g => {
                                g.id = common.guid();
                                g.result.parentId = f.id;
                            });
                        }
                    });
                }
            }
        },
        //头部操作按钮回调
        headerOperateEventClick(item, asideStyle) {
            if (item && item.type === "foldone") {
                if (!item.show) {
                    //点击收起按钮时，应该显示展开按钮
                    this.asideStyle.defaultStyle = "width:17%;min-width:330px;display:none";
                }
                else {
                    //点击展开按钮时，应该显示收起按钮
                    this.asideStyle.defaultStyle = "width:17%;min-width:330px;";
                }
            }
            if (asideStyle) {
                Object.assign(this.asideStyle, asideStyle)
            }
        },
        //页面模板设置样式
        draggableContentStyle() {
            //页面大小，宽度和高度
            var styleInfo = "width:" + tool.mmToPx(this.activeTemplateSet.defaultPageType.width) + "px;";
            styleInfo += "min-height:" + tool.mmToPx(this.activeTemplateSet.defaultPageType.height) + "px;";
            styleInfo += "padding-top:" + tool.mmToPx(this.activeTemplateSet.defaultPagePadding.top) + "px;";
            styleInfo += "padding-bottom:" + tool.mmToPx(this.activeTemplateSet.defaultPagePadding.bottom) + "px;";
            styleInfo += "padding-left:" + tool.mmToPx(this.activeTemplateSet.defaultPagePadding.left) + "px;";
            styleInfo += "padding-right:" + tool.mmToPx(this.activeTemplateSet.defaultPagePadding.right) + "px;";
            if (this.activeTemplateSet.invertColor === false) {
                styleInfo += "background:#FFF";
            }
            else {
                styleInfo += "background:#000";
            }
            this.factPageWidth = tool.mmToPx(this.activeTemplateSet.defaultPageType.width) - tool.mmToPx(this.activeTemplateSet.defaultPagePadding.left) - tool.mmToPx(this.activeTemplateSet.defaultPagePadding.right);
            this.factPageHeight = tool.mmToPx(this.activeTemplateSet.defaultPageType.height) - tool.mmToPx(this.activeTemplateSet.defaultPagePadding.top) - tool.mmToPx(this.activeTemplateSet.defaultPagePadding.bottom);
            return styleInfo;
        },
        //头部样式回调
        headerStyleEventClick(styleSet) {
            if (styleSet) {
                if (this.activeModule.name === "input" || this.activeModule.name === "label" || this.activeModule.name === "select"
                    || this.activeModule.name === "textarea" || this.activeModule.name === "datetime" || this.activeModule.name === "checkbox"
                    || this.activeModule.name === "radio") {
                    this.activeModule.result.pattern.fontName = styleSet.font;
                    this.activeModule.result.pattern.fontSize = styleSet.size;
                    if (styleSet.strong) {
                        this.activeModule.result.pattern.fontWeight = 800;
                    }
                    else {
                        this.activeModule.result.pattern.fontWeight = 400;
                    }
                    this.activeModule.result.pattern.fontItalic = styleSet.italic;
                    this.activeModule.result.pattern.fontUnderLine = styleSet.underline;
                    this.activeModule.result.pattern.fontColor = styleSet.color;
                    if (styleSet.rows && parseInt(styleSet.rows) > 0) {
                        this.activeModule.result.pattern.rows = styleSet.rows;
                    }
                    if (styleSet.top) {
                        this.activeModule.result.pattern.verticalAlignment = "Top";
                    }
                    else if (styleSet.bottom) {
                        this.activeModule.result.pattern.verticalAlignment = "Bottom";
                    }
                    else if (styleSet.middle)  {
                        this.activeModule.result.pattern.verticalAlignment = "Middle";
                    }
                }
                else if (this.activeModule.name === "cell")
                {
                    var typeValue = "";
                    if (styleSet.top) {
                        this.activeModule.result.pattern.verticalAlignment = "Top";
                        typeValue = "top";
                    }
                    else if (styleSet.bottom) {
                        this.activeModule.result.pattern.verticalAlignment = "Bottom";
                        typeValue = "bottom";
                    }
                    else if (styleSet.middle)  {
                        this.activeModule.result.pattern.verticalAlignment = "Middle";
                        typeValue = "middle";
                    }
                    if (typeValue && typeValue.length > 0) 
                    {
                        if (this.$refs.scDragTool) {
                            this.$refs.scDragTool.setCellMarginTop(this.activeModule, typeValue);
                        }
                        if (this.$refs.scDragHeaderTool) {
                            this.$refs.scDragHeaderTool.setCellMarginTop(this.activeModule, typeValue);
                        }
                        if (this.$refs.scDragFooterTool) {
                            this.$refs.scDragFooterTool.setCellMarginTop(this.activeModule, typeValue);
                        }
                    }
                }
                if (styleSet.right) {
                    this.activeModule.result.pattern.horizontalAlignment = "Right";
                }
                else if (styleSet.center) {
                    this.activeModule.result.pattern.horizontalAlignment = "Center";
                }
                else if (styleSet.bothends) {
                    this.activeModule.result.pattern.horizontalAlignment = "Bothends";
                }
                else if (styleSet.left) {
                    this.activeModule.result.pattern.horizontalAlignment = "Left";
                }
                if (this.$refs.scDragTool) {
                    this.$refs.scDragTool.loadDynamicObj(this.activeModule);
                }
                if (this.$refs.scDragHeaderTool) {
                    this.$refs.scDragHeaderTool.loadDynamicObj(this.activeModule);
                }
                if (this.$refs.scDragFooterTool) {
                    this.$refs.scDragFooterTool.loadDynamicObj(this.activeModule);
                }
                if (this.$refs && this.$refs.scPattern) {
                    this.$refs.scPattern.reloadPattern(this.activeModule);
                }
                this.addStep()
            }
        },
        //组件样式回调绑定事件
        patternChangeEventClick(patternSet) {
            if (patternSet) {
                if (this.activeModule.name === "input" || this.activeModule.name === "label" || this.activeModule.name === "select"
                    || this.activeModule.name === "textarea" || this.activeModule.name === "datetime" || this.activeModule.name === "checkbox"
                    || this.activeModule.name === "radio") {
                    //this.activeModule.result.pattern.fontName = patternSet.font;
                    this.activeModule.result.pattern.fontSize = patternSet.size;
                    if (patternSet.strong) {
                        this.activeModule.result.pattern.fontWeight = 800;
                    }
                    else {
                        this.activeModule.result.pattern.fontWeight = 400;
                    }
                    this.activeModule.result.pattern.fontItalic = patternSet.italic;
                    this.activeModule.result.pattern.fontUnderLine = patternSet.underline;
                    this.activeModule.result.pattern.fontColor = patternSet.color;
                    this.activeModule.result.pattern.rows = patternSet.rows;
                    if (patternSet.top) {
                        this.activeModule.result.pattern.verticalAlignment = "Top";
                    }
                    else if (patternSet.bottom) {
                        this.activeModule.result.pattern.verticalAlignment = "Bottom";
                    }
                    else if (patternSet.middle) {
                        this.activeModule.result.pattern.verticalAlignment = "Middle";
                    }
                }
                else if (this.activeModule.name === "divider") {
                    this.activeModule.result.pattern.borderStyle = patternSet.borderStyle;
                    this.activeModule.result.pattern.borderColor = patternSet.borderColor;
                    this.activeModule.result.pattern.borderWeight = patternSet.borderWeight;
                    this.activeModule.result.pattern.borderWidth = patternSet.borderWidth;
                }
                else if (this.activeModule.name === "image") {
                    this.activeModule.result.pattern.height = patternSet.height;
                }
                else if (this.activeModule.name === "imageList") {
                    this.activeModule.result.pattern.showImageBorder = (patternSet.showImageBorder === "1" ? true : false);
                    this.activeModule.result.pattern.backgroundShadow = (patternSet.backgroundShadow === "1" ? true : false);
                    this.activeModule.result.pattern.showImageInterval = (patternSet.showImageInterval === "1" ? true : false);
                    //处理绑定逻辑
                    if (this.activeModule.result.base.colNum != patternSet.colNum) {
                        var valList = imageList.addPropContent(patternSet.colNum);
                        this.activeModule.result.property.valueList = valList;
                        var conInfo = imageList.getWidthHeight(patternSet.colNum);
                        this.activeModule.result.base.gridWidth = conInfo.perWidth;
                        this.activeModule.result.base.perHeight = conInfo.perHeight;
                    }
                    this.activeModule.result.base.colNum = parseInt(patternSet.colNum);
                }
                else if (this.activeModule.name === "scanTable") {
                    if (this.activeModule.result.property.showImageAndDesc) {
                        //table
                        this.activeModule.result.base.colNumPerRow = parseInt(patternSet.colNumPerRow);
                        this.activeModule.result.base.totalCount = parseInt(patternSet.totalCount);
                        this.activeModule.result.pattern.borderStyle = patternSet.borderStyle;
                        this.activeModule.result.pattern.borderColor = patternSet.borderColor;
                        this.activeModule.result.pattern.borderWeight = patternSet.borderWeight;
                        this.activeModule.result.pattern.backgroundColor = patternSet.backgroundColor;
                        this.activeModule.result.pattern.showTableBorder = (patternSet.showTableBorder === "1" ? true : false);
                        this.activeModule.result.pattern.showTableCellBorder = (patternSet.showTableCellBorder === "1" ? true : false);
                        this.activeModule.result.pattern.avgColumnWidth = (patternSet.avgColumnWidth === "1" ? true : false);
                        this.activeModule.result.pattern.allowSpanPage = (patternSet.allowSpanPage === "1" ? true : false);
                        this.activeModule.result.pattern.showTableCellMargin = (patternSet.showTableCellMargin === "1" ? true : false);
                        if (this.activeModule.result.tasks && this.activeModule.result.tasks.length > 0) {
                            this.activeModule.result.tasks.forEach(d => {
                                d.result.pattern.cellBorderColor = patternSet.borderColor;
                                d.result.pattern.cellBackgroundColor = patternSet.backgroundColor;
                            });
                        }
                    }
                    else {
                        this.activeModule.result.pattern.showImageBorder = (patternSet.showImageBorder === "1" ? true : false);
                        this.activeModule.result.pattern.backgroundShadow = (patternSet.backgroundShadow === "1" ? true : false);
                        this.activeModule.result.pattern.showImageInterval = (patternSet.showImageInterval === "1" ? true : false);
                        this.activeModule.result.base.colNum = parseInt(patternSet.colNum);
                    }
                }
                else if (this.activeModule.name === "ultrasoundImage") {
                    this.activeModule.result.pattern.height = patternSet.height;
                    if (patternSet.border && patternSet.border === "1") {
                        this.activeModule.result.pattern.border = true;
                    }
                    else {
                        this.activeModule.result.pattern.border = false;
                    }
                    if (patternSet.backgroundShadow && patternSet.backgroundShadow === "1") {
                        this.activeModule.result.pattern.backgroundShadow = true;
                    }
                    else {
                        this.activeModule.result.pattern.backgroundShadow = false;
                    }
                }
                else if (this.activeModule.name === "ultrasoundImageList") {
                    this.activeModule.result.pattern.showImageBorder = (patternSet.showImageBorder === "1" ? true : false);
                    this.activeModule.result.pattern.backgroundShadow = (patternSet.backgroundShadow === "1" ? true : false);
                    this.activeModule.result.pattern.showImageInterval = (patternSet.showImageInterval === "1" ? true : false);
                    //处理绑定逻辑
                    if (this.activeModule.result.pattern.columnNumPerPage != patternSet.columnNumPerPage ||
                        this.activeModule.result.pattern.rowNumPerPage != patternSet.rowNumPerPage) {
                        var list = ultrasoundImageListInfo.addPropContent(patternSet.rowNumPerPage, patternSet.columnNumPerPage,
                            this.activeModule.result.pattern.maxColumnPerPage, this.activeModule.result.pattern.maxRowPerPage,
                            this.activeModule.id, this.activeModule.name, this.activeModule.result.pattern.showImageBorder,
                            this.activeModule.result.pattern.backgroundShadow
                        );
                        this.activeModule.result.tasks = list;
                        if (parseInt(patternSet.rowNumPerPage) != 4)
                        {
                            var avgTempHeight = parseFloat(710.1 / 4);
                            if(this.activeModule.displayContentList && this.activeModule.displayContentList.length > 0)
                            {
                                this.activeModule.displayContentList.forEach(m => {
                                    m.offsetHeight = avgTempHeight * parseFloat(patternSet.rowNumPerPage);
                                });
                            }
                        }
                    }
                    else {
                        if (this.activeModule.result.tasks && this.activeModule.result.tasks.length > 0) {
                            this.activeModule.result.tasks.forEach(c => {
                                if (c && c.result && c.result.pattern) {
                                    c.result.pattern.border = this.activeModule.result.pattern.showImageBorder;
                                    c.result.pattern.backgroundShadow = this.activeModule.result.pattern.backgroundShadow;
                                }
                            });
                        }
                    }
                    this.activeModule.result.pattern.columnNumPerPage = patternSet.columnNumPerPage;
                    this.activeModule.result.pattern.rowNumPerPage = patternSet.rowNumPerPage;
                }
                else if (this.activeModule.name === "grid") {
                    this.activeModule.result.pattern.interval = patternSet.interval;
                }
                else if (this.activeModule.name === "table" || this.activeModule.name === "doctorInfo" || this.activeModule.name === "patientInfo"
                || this.activeModule.name === "reportHeader") {
                    //处理表格
                    this.activeModule.result.pattern.borderStyle = patternSet.borderStyle;
                    this.activeModule.result.pattern.borderColor = patternSet.borderColor;
                    this.activeModule.result.pattern.borderWeight = patternSet.borderWeight;
                    this.activeModule.result.pattern.backgroundColor = patternSet.backgroundColor;
                    this.activeModule.result.pattern.showTableBorder = (patternSet.showTableBorder === "1" ? true : false);
                    this.activeModule.result.pattern.showTableCellBorder = (patternSet.showTableCellBorder === "1" ? true : false);
                    this.activeModule.result.pattern.avgColumnWidth = (patternSet.avgColumnWidth === "1" ? true : false);
                    this.activeModule.result.pattern.allowSpanPage = (patternSet.allowSpanPage === "1" ? true : false);
                    this.activeModule.result.pattern.showTableCellMargin = (patternSet.showTableCellMargin === "1" ? true : false);
                    if (this.activeModule.result.tasks && this.activeModule.result.tasks.length > 0) {
                        this.activeModule.result.tasks.forEach(d => {
                            d.result.pattern.cellBorderColor = patternSet.borderColor;
                            d.result.pattern.cellBackgroundColor = patternSet.backgroundColor;
                        });
                    }
                }
                else if (this.activeModule.name === "cell") {
                    this.activeModule.result.pattern.showCellBorder = (patternSet.showCellBorder === "1" ? true : false);
                    this.activeModule.result.pattern.cellBorderStyle = patternSet.cellBorderStyle;
                    this.activeModule.result.pattern.cellBorderColor = patternSet.cellBorderColor;
                    this.activeModule.result.pattern.cellBorderWeight = patternSet.cellBorderWeight;
                    this.activeModule.result.pattern.cellBackgroundColor = patternSet.cellBackgroundColor;
                }
                if (patternSet.right) {
                    this.activeModule.result.pattern.horizontalAlignment = "Right";
                }
                else if (patternSet.center) {
                    this.activeModule.result.pattern.horizontalAlignment = "Center";
                }
                else if (patternSet.bothends) {
                    this.activeModule.result.pattern.horizontalAlignment = "Bothends";
                }
                else if (patternSet.left) {
                    this.activeModule.result.pattern.horizontalAlignment = "Left";
                }
                this.activeModule.result.pattern.width = patternSet.width;
                if (this.$refs.scDragTool) {
                    this.$refs.scDragTool.loadDynamicObj(this.activeModule);
                }
                if (this.$refs.scDragHeaderTool) {
                    this.$refs.scDragHeaderTool.loadDynamicObj(this.activeModule);
                }
                if (this.$refs.scDragFooterTool) {
                    this.$refs.scDragFooterTool.loadDynamicObj(this.activeModule);
                }
                if (this.$refs && this.$refs.scStyleTool) {
                    this.$refs.scStyleTool.bindData(this.activeModule);
                }
                this.addStep();
            }
        },
        //组件属性回调绑定事件
        propertyChangeEventClick(propertySet) {
            if (propertySet) {
                if (this.activeModule.name === "input" || this.activeModule.name === "textarea" || this.activeModule.name === "datetime" || this.activeModule.name === "label") {
                    if (this.activeModule.name === "label") {
                        if (this.activeModule.result.property.placeholder != propertySet.placeholder) {
                            var newEntity = {
                                keyword: propertySet.placeholder,
                                scan: false,
                                seport: false,
                                languageDatas: []
                            }
                            var entity = this.labelContentList.filter(c => c.keyword === this.activeModule.result.property.placeholder);
                            if (entity.length > 0) {
                                var curIndex = this.labelContentList.indexOf(entity[0]);
                                this.labelContentList.splice((curIndex + 1), 0, newEntity);
                                this.labelContentList.splice(curIndex, 1);
                            }
                            else {
                                this.labelContentList.push(newEntity);
                            }
                        }
                    }
                    if (this.activeModule.name === "label")
                    {
                        var lblWidth = document.getElementById(this.activeModule.id).offsetWidth - 0.9;
                        var l = this.$t(this.activeModule.result.property.placeholder).length;
                        var avgWidth = parseFloat(lblWidth / l);
                        this.activeModule.result.property.placeholder = propertySet.placeholder;
                        var newLblWidth = avgWidth * this.$t(this.activeModule.result.property.placeholder).length;
                        this.activeModule.result.offsetWidth = newLblWidth;
                        var rowCount = parseInt(newLblWidth / this.factPageWidth) + ((newLblWidth % this.factPageWidth) > 0 ? 1 : 0);
                        var rowPerHeight = parseFloat(this.activeModule.result.pattern.fontSize) + 6;
                        if (rowPerHeight < 20)
                        {
                            rowPerHeight = 20;
                        } 
                        this.activeModule.result.offsetHeight = rowPerHeight * rowCount;
                        var lblHeight = document.getElementById(this.activeModule.id).offsetHeight;
                        if (lblHeight > 60 && this.activeModule.result.offsetHeight < lblHeight)
                        {
                            if (parseFloat(this.activeModule.result.pattern.fontSize) <= 20)
                            {
                                rowCount = lblHeight / 36;
                                this.activeModule.result.offsetHeight = rowPerHeight * rowCount;
                            }
                        }
                        var gridControls = ["grid", "diagnosis","replenish"];
                        if (gridControls.some(x => x === this.activeModule.result.parentName)) 
                        {
                            this.$refs.scDragTool.setGridModuleWidthClick(this.activeModule.id, newLblWidth, this.activeModule.result.parentId);
                        }
                        else
                        {
                            var curMainModuleInfo = null;
                            this.activeModuleList.some(y => {
                                if (y && y.result && y.result.tasks && y.result.tasks.length > 0) {
                                    var res = false;
                                    y.result.tasks.forEach(z => {
                                        if (z.id === this.activeModule.result.parentId) 
                                        {
                                            var colWidthList = y.result.base.columnWidth;
                                            var addHeight = this.caculateCellContentFactHeight(z, colWidthList);
                                            z.result.offsetHeight = addHeight;
                                            res = true;
                                            curMainModuleInfo = y;
                                        }
                                    });
                                    if (res)
                                    {
                                        return true;
                                    }
                                }
                            });
                            this.$refs.scDragTool.setTableModuleHeightClick(curMainModuleInfo.id, curMainModuleInfo.result.tasks);
                        }
                    }
                    else
                    {
                        this.activeModule.result.property.placeholder = propertySet.placeholder;
                    }
                    if (this.activeModule.name === "datetime") {
                        this.activeModule.result.property.displayFormat = propertySet.displayFormat;
                        this.activeModule.result.property.enable = (propertySet.enable === "1" ? true : false);
                        this.activeModule.result.property.realTime = (propertySet.realTime === "1" ? true : false);
                    }
                }
                else if (this.activeModule.name === "pageNumber") {
                    this.activeModule.result.property.pageNumberType = propertySet.pageNumberType;
                    this.activeModule.result.property.placeholder = propertySet.placeholder;
                }
                else if (this.activeModule.name === "grid") {
                    this.activeModule.result.property.isHidden = (propertySet.required === "1" ? true : false);
                }
                else if (this.activeModule.name === "scanTable") {
                    this.activeModule.result.property.showImageAndDesc = (propertySet.showImageAndDesc === "1" ? true : false);
                    this.activeModule.result.property.tempStatus = (propertySet.showImageAndDesc === "1" ? true : false);
                }
                else if (this.activeModule.name === "patientInfo") {
                    var cacuInfo = this.activeModule.caculateRowsAndCols(propertySet.CurrentModuleSelectedItems.length, propertySet.CurrentModuleDisplayCols);
                    this.activeModule.result.base.rowCount = cacuInfo.rows;
                    this.activeModule.result.base.moduleBindWidth = cacuInfo.bindWidth;
                    this.activeModule.result.base.columnCountPerRow = propertySet.CurrentModuleDisplayCols;
                    this.activeModule.result.base.columnCount = cacuInfo.showNumPerRow;
                    this.activeModule.result.selectedItems = propertySet.CurrentModuleSelectedItems;
                }
                else if (this.activeModule.name === "doctorInfo")  {
                    this.activeModule.result.property.ReportTime = (propertySet.ReportTime === "1" ? true : false);
                    this.activeModule.result.property.InspectionPhysician = (propertySet.InspectionPhysician === "1" ? true : false);
                    this.activeModule.result.property.ReportPhysician = (propertySet.ReportPhysician === "1" ? true : false);
                    this.activeModule.result.property.ImageFile = (propertySet.ImageFile === "1" ? true : false);
                    var itemList = [
                        { key: "ReportTime", type: "date", title: "reportDesigner.ReportTime", value: this.activeModule.result.property.ReportTime },
                        { key: "InspectionPhysician", type: "input", title: "reportDesigner.InspectionPhysician", value: this.activeModule.result.property.InspectionPhysician },
                        { key: "ReportPhysician", type: "input", title: "reportDesigner.ReportPhysician", value: this.activeModule.result.property.ReportPhysician },
                        { key: "ImageFile", type: "image", title: "reportDesigner.ImageFile", value: this.activeModule.result.property.ImageFile }
                    ];
                    var tempList = itemList.filter(c => c.value === true);
                    var colCount = 0;
                    if (tempList.length === 1) {
                        colCount = 1;
                    }
                    else if (tempList.length === 2) {
                        colCount = 2;
                    }
                    else if (tempList.length === 3) {
                        colCount = 3;
                    }
                    else if (tempList.length === 4) {
                        colCount = 4;
                    }
                    else {
                        colCount = 0;
                        this.activeModule.result.tasks = [];
                    }
                    this.activeModule.result.base.rowCount = 1;
                    this.activeModule.result.base.columnCount = colCount;
                    this.activeModule.result.selectedItems = itemList;
                }
                else if (this.activeModule.name === "reportHeader")  {
                    this.activeModule.result.property.HospitalIcon = (propertySet.HospitalIcon === "1" ? true : false);
                    this.activeModule.result.property.HospitalName = (propertySet.HospitalName === "1" ? true : false);
                    this.activeModule.result.property.ReportTitleName = (propertySet.ReportTitleName === "1" ? true : false);
                    var selectedItem = [
                        { key: "HospitalIcon", value: this.activeModule.result.property.HospitalIcon },
                        { key: "HospitalName", value: this.activeModule.result.property.HospitalName },
                        { key: "ReportTitleName", value: this.activeModule.result.property.ReportTitleName }
                    ];
                    var tmpList = selectedItem.filter(c => c.value === true);
                    var rows = 0, cols = 0;
                    if (tmpList.length === 1) {
                        rows = 1;
                        cols = 1;
                    }
                    else if (tmpList.length === 2) {
                        rows = 1;
                        cols = 2;
                    }
                    else if (tmpList.length === 3) {
                        rows = 2;
                        cols = 2;
                    }
                    else {
                        rows = 0;
                        cols = 0;
                        this.activeModule.result.tasks = [];
                    }
                    this.activeModule.result.base.rowCount = rows;
                    this.activeModule.result.base.columnCount = cols;
                    this.activeModule.result.selectedItems = selectedItem;
                }
                else if (this.activeModule.name === "image") {
                    this.activeModule.result.property.imageFile = propertySet.imageFile;
                    var breakOut = false;
                    if (this.activeModule.result.parentName === "cell")
                    {
                        this.activeModuleList.some(d => {
                            if ((d.name === "reportHeader" || d.name === "table") && d.result && d.result.tasks && d.result.tasks.length > 0) {
                                d.result.tasks.some(e => {
                                    if (e.id === this.activeModule.result.parentId)
                                    {
                                        breakOut = true;
                                        return true;
                                    }
                                });
                                if (breakOut)
                                {
                                    return true;
                                }
                            }
                        });
                    }
                    if (!breakOut)
                    {
                        if (propertySet.imageWidth && propertySet.imageWidth > 0) {
                            if (tool.mmToPx(propertySet.imageWidth) > this.factPageWidth) {
                                this.activeModule.result.pattern.width = 168;
                            }
                            else {
                                this.activeModule.result.pattern.width = propertySet.imageWidth;
                            }
                        }
                        var pertenage = parseFloat(this.activeModule.result.pattern.width / propertySet.imageWidth);
                        if (propertySet.imageHeight && propertySet.imageHeight > 0) {
                            if (pertenage >= 1) {
                                this.activeModule.result.pattern.height = propertySet.imageHeight;
                            }
                            else {
                                this.activeModule.result.pattern.height = parseInt(propertySet.imageHeight * pertenage);
                            }
                        }
                        //重置图像大小
                        if (this.$refs.scPattern) {
                            this.$refs.scPattern.reloadPattern(this.activeModule);
                        }
                        if (this.$refs.scPattern) {
                            this.$refs.scPattern.reloadPattern(this.activeModule);
                        }
                        if (this.$refs.scPattern) {
                            this.$refs.scPattern.reloadPattern(this.activeModule);
                        }
                    }
                }
                else if (this.activeModule.name === "table") {
                    this.activeModule.result.property.isHidden = (propertySet.isHidden === "1" ? true : false);
                    if (propertySet.rowCount > 0 && propertySet.columnCount > 0 &&
                        (propertySet.rowCount != this.activeModule.result.base.rowCount
                        || this.activeModule.result.base.columnCount != propertySet.columnCount)) {
                        this.activeModule.result.base.rowCount = parseInt(propertySet.rowCount);
                        this.activeModule.result.base.columnCount = parseInt(propertySet.columnCount);
                        this.activeModule.result.base.isRedraw = true;
                    }
                }
                else if (this.activeModule.name === "cell") {
                    //处理单元格
                    //处理表格
                    this.activeModule.result.property.cellColumnWidth = propertySet.cellColumnWidth;
                    this.activeModule.result.property.cellColumnWidhtType = propertySet.cellColumnWidhtType;
                    this.activeModule.result.property.cellRowHeight = propertySet.cellRowHeight;
                    this.activeModule.result.property.cellRowHeightType = propertySet.cellRowHeightType;
                    this.activeModule.result.property.mergeBottomCell = propertySet.mergeBottomCell;
                    this.activeModule.result.property.mergeRightCell = propertySet.mergeRightCell;
                    this.activeModule.result.property.insertTopCell = propertySet.insertTopCell;
                    this.activeModule.result.property.insertBottomCell = propertySet.insertBottomCell;
                    this.activeModule.result.property.insertLeftCell = propertySet.insertLeftCell;
                    this.activeModule.result.property.insertRightCell = propertySet.insertRightCell;
                    this.activeModule.result.property.deleteRow = propertySet.deleteRow;
                    this.activeModule.result.property.deleteColumn = propertySet.deleteColumn;
                    this.activeModule.result.property.spliceCell = propertySet.spliceCell;
                }
                else if (this.activeModule.name === "select" || this.activeModule.name === "checkbox" || this.activeModule.name === "radio") {
                    this.activeModule.result.property.staticOptions = [];
                    this.activeModule.result.property.dynamicOptions = [];
                    var typeStr = propertySet[this.activeModule.result.property.dataSourceType.field]
                    this.activeModule.result.property.dataSourceType.value = typeStr;
                    this.activeModule.result.property.dynamicDataSource.methodString = propertySet.dynamicApiObj;
                    propertySet.staticDataSourceItems.map(c => {
                        if (c.type === "inputOption") {
                            this.activeModule.result.property.staticOptions.push(c.value);
                        }
                    })
                    propertySet.dynamicDataSourceItems.map(c => {
                        if (c.type === "inputOption") {
                            this.activeModule.result.property.dynamicOptions.push(c.value);
                        }
                    })
                    if (this.activeModule.name === "select") {
                        this.activeModule.result.property.multiple = (propertySet.multiple === "1" ? true : false);
                        if (typeStr === "0") {
                            this.activeModule.result.property.placeholder = this.activeModule.result.property.staticOptions[0];
                        }
                        else {
                            this.activeModule.result.property.placeholder = this.activeModule.result.property.dynamicOptions[0];
                        }
                    }
                    else if (this.activeModule.name === "checkbox" || this.activeModule.name === "radio") {
                        this.activeModule.result.property.arrangement = (propertySet.arrangement === "1" ? true : false);
                    }
                }
                //结果赋值
                this.activeModule.result.property.bindType = propertySet.bindType;
                this.activeModule.result.property.bindTypeField = propertySet.bindTypeField;
                if (!propertySet.isDefault) 
                {
                    this.activeModule.result.property.isDefault = false;
                }
                else 
                {
                    this.activeModule.result.property.isDefault = propertySet.isDefault;
                }
				//功能标签赋值
				this.activeModule.result.property.featureTag = propertySet.featureTag;
                if (propertySet.bindField && propertySet.bindField.length > 0) {
                    this.dragDisabled = false;
                }
                this.activeModule.result.property.bindField = propertySet.bindField;
                this.activeModule.result.property.required = (propertySet.required === "1" ? true : false);
                this.activeModule.result.property.editable = (propertySet.editable === "1" ? true : false);
                if (this.activeModule.name === "ultrasoundImageList") {
                    if (this.activeModule.result.tasks && this.activeModule.result.tasks.length > 0)
                    {
                        this.activeModule.result.tasks.forEach(mx => {
                            if (mx && mx.result && mx.result.property)
                            {
                                mx.result.property.bindType = this.activeModule.result.property.bindType;
                                mx.result.property.bindTypeField = this.activeModule.result.property.bindTypeField;
                                mx.result.property.bindField = this.activeModule.result.property.bindField;
                            }
                        });
                    }
                }
                //计算项
                if (propertySet.ScanMode && propertySet.ScanMode.length > 0 &&
                    (this.activeModule.result.property.bindType === "CommonMeasure" || this.activeModule.result.property.bindType === "OtherMeasure")) {
                    this.activeModule.result.property.measureItem = {
                        AvailableMethods: propertySet.measureItemList,
                        BaseType: propertySet.MeasureItem,
                        CalculationId: propertySet.MeasureCalculation,
                        MatchId: "",
                        Method: propertySet.MeasureWay,
                        Mode: propertySet.ScanMode,
                        Output: propertySet.OutputItem,
                        OutputV2: propertySet.OutputItem,
                        Unit: propertySet.UnitType,
                    };
                    if (this.activeModule.result.property.bindType === "CommonMeasure")
                    {
                        this.activeModule.result.property.measureItem.UserId = "ReportTemplate." + propertySet.UserDefineName
                    }
                    else
                    {
                        this.activeModule.result.property.measureItem.UserId = propertySet.UserDefineName
                    }
                    if (propertySet.ScanMode === "CustomizeCalculation") {
                        this.activeModule.result.property.measureItem = {
                            AvailableMethods: [],
                            BaseType: propertySet.MeasureItem,
                            CalculationId: "ReportTemplate." + propertySet.OutputItem,
                            MatchId: "",
                            Method: null,
                            Mode: propertySet.ScanMode,
                            Output: null,
                            OutputV2: "ReportTemplate." + propertySet.OutputItem,
                            Unit: propertySet.UnitType,
                            UserId: "ReportTemplate." + propertySet.OutputItem,
                        };
                    }
                }
                if (this.activeModule && this.activeModule.result && this.activeModule.result.tasks && this.activeModule.result.tasks.length <= 0) {
                    if (this.activeModule.name === "doctorInfo" || this.activeModule.name === "reportHeader") {
                        if (this.$refs.scDragTool) {
                            this.$refs.scDragTool.removeDynamicObj(this.activeModule);
                        }
                        if (this.$refs.scDragHeaderTool) {
                            this.$refs.scDragHeaderTool.removeDynamicObj(this.activeModule);
                        }
                        if (this.$refs.scDragFooterTool) {
                            this.$refs.scDragFooterTool.removeDynamicObj(this.activeModule);
                        }
                        // var newIndex = this.activeModuleList.indexOf(this.activeModule);
                        // this.activeModuleList.splice(newIndex, 1);
                        this.dragDisabled = false;
                        this.activeModule = {};
                    }
                    else {
                        if (this.$refs.scDragTool) {
                            this.$refs.scDragTool.loadDynamicObj(this.activeModule);
                        }
                        if (this.$refs.scDragHeaderTool) {
                            this.$refs.scDragHeaderTool.loadDynamicObj(this.activeModule);
                        }
                        if (this.$refs.scDragFooterTool) {
                            this.$refs.scDragFooterTool.loadDynamicObj(this.activeModule);
                        }
                    }
                }
                else {
                    if (this.$refs.scDragTool) {
                        this.$refs.scDragTool.loadDynamicObj(this.activeModule);
                    }
                    if (this.$refs.scDragHeaderTool) {
                        this.$refs.scDragHeaderTool.loadDynamicObj(this.activeModule);
                    }
                    if (this.$refs.scDragFooterTool) {
                        this.$refs.scDragFooterTool.loadDynamicObj(this.activeModule);
                    }
                }
                this.addStep();
            }
        },
        //计算单元格实际高度
        caculateCellContentFactHeight(c, colWidthList) {
            var curOffsetWidth = 0;
            var addHeight = 0;
            if (c.result.base.colStartIndex > 0)
            {
                curOffsetWidth = tool.mmToPx(colWidthList[(c.result.base.colStartIndex - 1)]);
            }
            if (c.result && c.result.tasks && c.result.tasks.length > 0)
            {
                var addWidth = 0;
                var maxOffsetHeight = 0;
                c.result.tasks.some(d => {
                    
                    if (addWidth > 0 && (addWidth + d.result.offsetWidth) >= curOffsetWidth) 
                    {
                        addWidth = 0;
                        addHeight += maxOffsetHeight; 
                        maxOffsetHeight = 0;
                    }
                    //继续处理内容
                    addWidth += d.result.offsetWidth;
                    if (d.result.offsetWidth >= curOffsetWidth && d.name === "label")
                    {
                        var rowCount1 = parseInt(d.result.offsetWidth / curOffsetWidth) + ((d.result.offsetWidth % curOffsetWidth) > 0 ? 1 : 0);
                        var rowPerHeight1 = parseFloat(d.result.pattern.fontSize) + 6;
                        if (rowPerHeight1 < 20)
                        {
                            rowPerHeight1 = 20;
                        } 
                        d.result.offsetHeight = rowPerHeight1 * rowCount1;

                        var lblHeight = document.getElementById(this.activeModule.id).offsetHeight;
                        if (lblHeight > 60 && d.result.offsetHeight < lblHeight)
                        {
                            if (parseFloat(d.result.pattern.fontSize) <= 20)
                            {
                                rowCount1 = lblHeight / 36;
                                d.result.offsetHeight = rowPerHeight1 * rowCount1;
                            }
                        }
                    }
                    if (d.result.offsetHeight > maxOffsetHeight)
                    {
                        maxOffsetHeight = d.result.offsetHeight;
                    }
                });
                if (maxOffsetHeight > 0) 
                {
                    addHeight += maxOffsetHeight; 
                }
            }
            else
            {
                addHeight = 20;
            }
            return addHeight;
        },
        //页面设置回调绑定事件
        pageSettingEventClick(type, pageSetting) {
            if (type === 0) {
                this.activeTemplateSet.defaultPageType = pageSetting.pageType;
                this.activeTemplateSet.defaultPagePadding = {
                    top: pageSetting.marginTop,
                    bottom: pageSetting.marginBottom,
                    left: pageSetting.marginLeft,
                    right: pageSetting.marginRight
                };
                this.activeTemplateSet.defaultPageHeader = {
                    height: pageSetting.headerHeight,
                    top: pageSetting.headerMarginTop
                };
                this.activeTemplateSet.defaultPageFooter = {
                    height: pageSetting.footerHeight,
                    bottom: pageSetting.footerMarginBottom
                };
                this.activeTemplateSet.name = pageSetting.name;
                this.activeTemplateSet.author = pageSetting.author;
                this.activeTemplateSet.isCustom = pageSetting.isCustom;
                this.activeTemplateSet.applicable = pageSetting.applicable;
                this.activeTemplateSet.invertColor = pageSetting.invertColor === "false" ? false : true;
            }
            else if (type === 1) {
                this.isShowPageForm = false;
                this.activeTab = "moduleProperty";
            }
        },
        setActiveEventClick(type) {
            var tempModuel = designerInfo.initAppointModule('grid');
            if (type === "header") {
                this.$refs.scDragTool.clearActiveModuel(tempModuel);
                this.$refs.scDragFooterTool.clearActiveModuel(tempModuel);
            }
            else if (type === "footer") {
                this.$refs.scDragTool.clearActiveModuel(tempModuel);
                this.$refs.scDragHeaderTool.clearActiveModuel(tempModuel);
            }
            else {
                this.$refs.scDragHeaderTool.clearActiveModuel(tempModuel);
                this.$refs.scDragFooterTool.clearActiveModuel(tempModuel);
            }
        },
        //中间面板回调绑定属性事件，包括位置信息的封装
        dragAttributeEventClick(curModule, moduleItemList, type) {
            this.activeModuleList = moduleItemList;
            if (this.activeModuleList && this.activeModuleList.length > 0) {
                if (this.activeTab === "form") {
                    this.activeTab = "moduleProperty";
                }
            }
            else {
                this.activeTab = "form";
            }
            if (curModule && curModule.result) {
                var firstList = this.activeModuleList.filter(c => c.id === curModule.result.parentId);
                if (firstList && firstList.length > 0) {
                    var res = firstList[0].result.tasks.some(c => c.id === curModule.id);
                    if (res) {
                        this.activeModule = curModule;
                    }
                    else {
                        this.activeModule = {};
                    }
                }
                else {
                    this.activeModule = curModule;
                }
            }
            else {
                this.activeModule = {};
            }
            if (this.$refs && this.$refs.scStyleTool) {
                this.$refs.scStyleTool.bindData(this.activeModule);
            }
            if (type === 1) {
                return;
            }
            else if (type === 2) {
                this.dragDisabled = false;
                return;
            }
            //添加步骤
            this.addStep();
            if (this.activeModule.name === "scanTable") {
                this.$refs.scPattern.reloadPattern(this.activeModule);
                this.$refs.scProperty.reloadProperty(this.activeModule);
            }
            this.dragDisabled = false;
        },
        dragSetHeightEventClick(moduleItemList) {
            var allPageFactHeight = 0;
            var contentFactHeight = 0;
            this.activeModuleList = moduleItemList;
            if (this.activeModuleList && this.activeModuleList.length > 0) {
                this.activeModuleList.forEach(m => {
                    if (m.id === this.activeModule.id) {
                        this.activeModule = m;
                    }
                    allPageFactHeight += m.result.offsetHeight;
                    contentFactHeight += m.result.offsetHeight;
                });
            }
            allPageFactHeight += this.headerAndFooterHeight;
            var divScrollHeight = parseFloat(document.getElementById("dragMainContent").style.minHeight.replace("px", ""));
            if (divScrollHeight < allPageFactHeight * 1.5) {
                var diffHeight = allPageFactHeight * 1.5 - divScrollHeight;
                document.getElementById("dragMainContent").style.minHeight = (diffHeight + divScrollHeight) + "px";
                if (this.headerAndFooterHeight > 80) {
                    var divContentScrollHeight = parseFloat(document.getElementById("contentDragToolDiv").style.minHeight.replace("px", ""));
                    if (!divContentScrollHeight) {
                        divContentScrollHeight = parseFloat(document.getElementById("contentDragToolDiv").style.height.replace("px", ""));
                    }
                    var diffContentHeight = 0;
                    if (divContentScrollHeight < contentFactHeight * 1.4) {
                        diffContentHeight = contentFactHeight * 1.57 - divContentScrollHeight;
                    }
                    document.getElementById("contentDragToolDiv").style.minHeight = (diffContentHeight + divContentScrollHeight) + "px";
                }
            }
        },
        //Header面板回调绑定属性事件，包括位置信息的封装
        dragHeaderAttributeEventClick(curModule, moduleItemList, type) {
            this.activeHeaderModuleList = moduleItemList;
            if (!moduleItemList || moduleItemList.length <= 0) {
                this.activeTemplateSet.paperHeaderFooter.usePaperHeader = false;
                return;
            }
            if (this.activeHeaderModuleList && this.activeHeaderModuleList.length > 0) {
                if (this.activeTab === "form") {
                    this.activeTab = "moduleProperty";
                }
            }
            else {
                this.activeTab = "form";
            }
            if (curModule && curModule.result) {
                var firstList = this.activeHeaderModuleList.filter(c => c.id === curModule.result.parentId);
                if (firstList && firstList.length > 0) {
                    var res = firstList[0].result.tasks.some(c => c.id === curModule.id);
                    if (res) {
                        this.activeModule = curModule;
                    }
                    else {
                        this.activeModule = {};
                    }
                }
                else {
                    this.activeModule = curModule;
                }
            }
            else {
                this.activeModule = {};
            }
            if (this.$refs && this.$refs.scStyleTool) {
                this.$refs.scStyleTool.bindData(this.activeModule);
            }
            if (type === 1) {
                return;
            }
            else if (type === 2) {
                this.dragDisabled = false;
                return;
            }
            //添加步骤
            this.addStep();
            if (this.activeModule.name === "scanTable") {
                this.$refs.scPattern.reloadPattern(this.activeModule);
                this.$refs.scProperty.reloadProperty(this.activeModule);
            }
            this.dragDisabled = false;
            if (this.$refs && this.$refs.scDragTool) {
                this.$refs.scDragTool.clearActiveModuel(this.activeModule);
            }
        },
        //Footer面板回调绑定属性事件，包括位置信息的封装
        dragFooterAttributeEventClick(curModule, moduleItemList, type) {
            this.activeFooterModuleList = moduleItemList;
            if (!moduleItemList || moduleItemList.length <= 0) {
                this.activeTemplateSet.paperHeaderFooter.usePaperFooter = false;
                return;
            }
            if (this.activeFooterModuleList && this.activeFooterModuleList.length > 0) {
                if (this.activeTab === "form") {
                    this.activeTab = "moduleProperty";
                }
            }
            else {
                this.activeTab = "form";
            }
            if (curModule && curModule.result) {
                var firstList = this.activeFooterModuleList.filter(c => c.id === curModule.result.parentId);
                if (firstList && firstList.length > 0) {
                    var res = firstList[0].result.tasks.some(c => c.id === curModule.id);
                    if (res) {
                        this.activeModule = curModule;
                    }
                    else {
                        this.activeModule = {};
                    }
                }
                else {
                    this.activeModule = curModule;
                }
            }
            else {
                this.activeModule = {};
            }
            if (this.$refs && this.$refs.scStyleTool) {
                this.$refs.scStyleTool.bindData(this.activeModule);
            }
            if (type === 1) {
                return;
            }
            else if (type === 2) {
                this.dragDisabled = false;
                return;
            }
            //添加步骤
            this.addStep();
            if (this.activeModule.name === "scanTable") {
                this.$refs.scPattern.reloadPattern(this.activeModule);
                this.$refs.scProperty.reloadProperty(this.activeModule);
            }
            this.dragDisabled = false;
        },
        //添加步骤
        addStep() {
            if (this.activeModuleList && this.activeModuleList.length > 0) {
                this.forwardList = [];
                if (this.lastActiveModule && this.lastActiveModule.curActiveModule && this.lastActiveModule.curActiveModule.id && this.lastActiveModule.curActiveModule.id.length > 0) {
                    var temp = {
                        curActiveModule: tool.objCopy(this.lastActiveModule.curActiveModule),
                        curActiveModuleList: tool.objCopy(this.lastActiveModule.curActiveModuleList),
                        parentId: this.lastActiveModule.parentId
                    };
                    this.fallbackList.splice(0, 0, temp);
                }
                var copyActiveModuleInfo = {
                    curActiveModule: this.activeModule,
                    curActiveModuleList: this.activeModuleList,
                    parentId: ""
                }
                //操作的是基础组件
                if (this.basicDragControls.some(d => d === this.activeModule.name)) {
                    //粘贴位置是基础组件,判断基础组件的父级是啥
                    if (this.reportDragControls.some(c => c === this.activeModule.result.parentName)) {
                        //表示是grid，找到当前基础组件在grid中的位置，然后加载其后面
                        copyActiveModuleInfo.parentId = this.activeModule.result.parentId;
                    }
                    else {
                        //表示是表格的cell，找到基础组件在cell中的位置，然后加到其后面，并且要找到cell的table才能操作，及循环两层
                        //单元格组件，加到单元格的最后
                        this.activeModuleList.forEach(m => {
                            if (this.reportTableDragControls.some(p => p === m.name)) {
                                //循环table
                                m.result.tasks.some(o => {
                                    //表示cell
                                    if (o.id === this.activeModule.result.parentId) {
                                        copyActiveModuleInfo.parentId = m.id;
                                        return false;
                                    }
                                });
                            }
                        });
                    }
                }
                else if (this.activeModule.name === "cell") {
                    //单元格，找父级
                    this.activeModuleList.forEach(m => {
                        if (m.id === this.activeModule.result.parentId) {
                            copyActiveModuleInfo.parentId = m.id;
                        }
                    });
                }
                else {
                    //grid或者table
                    copyActiveModuleInfo.parentId = this.activeModule.id;
                }
                this.lastActiveModule = tool.objCopy(copyActiveModuleInfo);
            }
        },
        //克隆拖拽组件,必须，否则会id重复
        cloneDrag({ name }) {
            var newModule = null;
            if (name === "patientInfo") {
                if (this.activeTemplateSet.applicable === "Animal") {
                    newModule = designerInfo.initAppointModule(name, true);
                }
                else {
                    newModule = designerInfo.initAppointModule(name, false);
                }
            }
            else {
                newModule = designerInfo.initAppointModule(name);
            }
            return newModule;
        },
        //左侧组件拖拽移动事件
        onMove(ele) {
            var targetElement = ele.draggedContext.element;
            if (this.activeModuleList.length <= 0) {
                if (this.reportTableDragControls.some(f => f === targetElement.name) || this.reportDragControls.some(f => f == targetElement.name)) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                if (ele.relatedContext === null || ele.relatedContext.list === null || ele.relatedContext.list.length <= 0) {
                    //表示为字容器，只能接收基础组件和报告组件
                    if (this.reportTableDragControls.some(f => f === targetElement.name) || this.reportDragControls.some(f => f == targetElement.name)) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                else {
                    //表示主容器内容为空为拖拽的第一个组件，此时主容器只能接收布局组件
                    var targetElementItem = ele.relatedContext.list[0];
                    if (this.reportTableDragControls.some(f => f === targetElementItem.name) || this.reportDragControls.some(f => f == targetElementItem.name)) {
                        //表明是主容器，只能接收布局组件
                        if (this.reportTableDragControls.some(f => f === targetElement.name) || this.reportDragControls.some(f => f == targetElement.name)) {
                            return true;
                        }
                        else {
                            return false;
                        }
                    }
                    else {
                        //子容器，只能接收基础组件和报告组件
                        if (this.reportTableDragControls.some(f => f === targetElement.name) || this.reportDragControls.some(f => f == targetElement.name)) {
                            return false;
                        }
                        else {
                            return true;
                        }
                    }
                }
            }
        },
        //验证
        validateBindField() {
            var tempActiveModule = null;
            var moduleNameList = ["ultrasoundImageList", "imageList", "ultrasoundImage"];
            var bindImageTagsList = [];//{name: "ultrasoundImageList", bindField: "bindField"}
            var showTagMessage = false;
            var currentHeaderModuelList = this.activeTemplateSet.paperHeaderFooter.usePaperHeader ? this.activeHeaderModuleList : [];
            var currentFooterModuelList = this.activeTemplateSet.paperHeaderFooter.usePaperFooter ? this.activeFooterModuleList : [];
            if (currentHeaderModuelList && currentHeaderModuelList.length > 0)
            {
                currentHeaderModuelList.some(c => {
                    if (c.result && c.result.tasks && c.result.tasks.length > 0) {
                        var firstResult = false;
                        c.result.tasks.some(d => {
                            if (d.name === "cell") {
                                if (d.result && d.result.tasks && d.result.tasks.length > 0) {
                                    var secondResult = false;
                                    d.result.tasks.some(e => {
                                        if (!this.noBindFieldList.some(n => n === e.name)) {
                                            if (e.result && e.result.property && e.result.property) {
                                                if (e.result.property.bindType === "CommonMeasure" || e.result.property.bindType === "OtherMeasure" )
                                                {
                                                    //计算项不验证
                                                }
                                                else if (!e.result.property.bindField || e.result.property.bindField.length <= 0) {
                                                    tempActiveModule = e;
                                                    secondResult = true;
                                                    return true;
                                                }
                                                else if (moduleNameList.some(sx => sx === e.name)) {
                                                    if (bindImageTagsList.length > 0) 
                                                    {
                                                        if (e.result.parentName === "ultrasoundImageList")
                                                        {
                                                            if (bindImageTagsList.some(dx => dx.name !== e.result.parentName && dx.bindField === e.result.property.bindField))
                                                            {
                                                                showTagMessage = true;
                                                                tempActiveModule = e;
                                                                secondResult = true;
                                                                return true;
                                                            }
                                                        } 
                                                        else if (bindImageTagsList.some(dx => dx.name !== e.name && dx.bindField === e.result.property.bindField))
                                                        {
                                                            showTagMessage = true;
                                                            tempActiveModule = e;
                                                            secondResult = true;
                                                            return true;
                                                        }
                                                        else
                                                        {
                                                            if (e.result.parentName === "ultrasoundImageList")
                                                            {
                                                                bindImageTagsList.push({
                                                                    name: 'ultrasoundImageList', 
                                                                    bindField: e.result.property.bindField
                                                                });
                                                            }
                                                            else
                                                            {
                                                                bindImageTagsList.push({
                                                                    name: e.name, 
                                                                    bindField: e.result.property.bindField
                                                                });
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (e.result.parentName === "ultrasoundImageList")
                                                        {
                                                            bindImageTagsList.push({
                                                                name: 'ultrasoundImageList', 
                                                                bindField: e.result.property.bindField
                                                            });
                                                        }
                                                        else
                                                        {
                                                            bindImageTagsList.push({
                                                                name: e.name, 
                                                                bindField: e.result.property.bindField
                                                            });
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    });
                                    if (secondResult) {
                                        firstResult = true;
                                        return true;
                                    }
                                }
                            }
                            else {
                                if (!this.noBindFieldList.some(m => m === d.name)) {
                                    if (d.result && d.result.property && d.result.property) {
                                        if (d.result.property.bindType === "CommonMeasure" || d.result.property.bindType === "OtherMeasure" )
                                        {
                                            //计算项不验证
                                        }
                                        else if (!d.result.property.bindField || d.result.property.bindField.length <= 0) {
                                            tempActiveModule = d;
                                            firstResult = true;
                                            return true;
                                        }
                                        else if (moduleNameList.some(sx => sx === d.name)) {
                                            if (bindImageTagsList.length > 0) 
                                            {
                                                if (d.result.parentName === "ultrasoundImageList")
                                                {
                                                    if (bindImageTagsList.some(dx => dx.name !== d.result.parentName && dx.bindField === d.result.property.bindField))
                                                    {
                                                        showTagMessage = true;
                                                        tempActiveModule = d;
                                                        firstResult = true;
                                                        return true;
                                                    }
                                                } 
                                                else if (bindImageTagsList.some(dx => dx.name !== d.name && dx.bindField === d.result.property.bindField))
                                                {
                                                    showTagMessage = true;
                                                    tempActiveModule = d;
                                                    firstResult = true;
                                                    return true;
                                                }
                                                else
                                                {
                                                    if (d.result.parentName === "ultrasoundImageList")
                                                    {
                                                        bindImageTagsList.push({
                                                            name: 'ultrasoundImageList', 
                                                            bindField: d.result.property.bindField
                                                        });
                                                    }
                                                    else
                                                    {
                                                        bindImageTagsList.push({
                                                            name: d.name, 
                                                            bindField: d.result.property.bindField
                                                        });
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (d.result.parentName === "ultrasoundImageList")
                                                {
                                                    bindImageTagsList.push({
                                                        name: 'ultrasoundImageList', 
                                                        bindField: d.result.property.bindField
                                                    });
                                                }
                                                else
                                                {
                                                    bindImageTagsList.push({
                                                        name: d.name, 
                                                        bindField: d.result.property.bindField
                                                    });
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        });
                        if (firstResult) {
                            return true;
                        }
                    }
                });
                if (tempActiveModule != null) {
                    if (showTagMessage) 
                    {
                        this.$message.warning(this.$t("reportDesigner.singleImageError"));
                    }
                    else {
                        this.$message.warning(this.$t("reportDesigner.validateBindContent"));
                    }
                    this.activeModule = tempActiveModule;
                    if (this.$refs.scDragHeaderTool) {
                        this.$refs.scDragHeaderTool.clearActiveModuel(this.activeModule);
                    }
                    return false;
                }
            }

            if (this.activeModuleList && this.activeModuleList.length > 0)
            {
                this.activeModuleList.some(c2 => {
                    if (c2 && c2.result && c2.result.tasks && c2.result.tasks.length > 0) {
                        var firstResult2 = false;
                        c2.result.tasks.some(d2 => {
                            if (d2.name === "cell") {
                                if (d2.result && d2.result.tasks && d2.result.tasks.length > 0) {
                                    var secondResult2 = false;
                                    d2.result.tasks.some(e2 => {
                                        if (!this.noBindFieldList.some(n2 => n2 === e2.name)) {
                                            if (e2.result && e2.result.property && e2.result.property) {
                                                if (e2.result.property.bindType === "CommonMeasure" || e2.result.property.bindType === "OtherMeasure" )
                                                {
                                                    //计算项不验证
                                                }
                                                else if (!e2.result.property.bindField || e2.result.property.bindField.length <= 0) {
                                                    tempActiveModule = e2;
                                                    secondResult2 = true;
                                                    return true;
                                                }
                                                else if (moduleNameList.some(sx => sx === e2.name)) {
                                                    if (bindImageTagsList.length > 0) 
                                                    {
                                                        if (e2.result.parentName === "ultrasoundImageList")
                                                        {
                                                            if (bindImageTagsList.some(dx => dx.name !== e2.result.parentName && dx.bindField === e2.result.property.bindField))
                                                            {
                                                                showTagMessage = true;
                                                                tempActiveModule = e2;
                                                                secondResult2 = true;
                                                                return true;
                                                            }
                                                        } 
                                                        else if (bindImageTagsList.some(dx => dx.name !== e2.name && dx.bindField === e2.result.property.bindField))
                                                        {
                                                            showTagMessage = true;
                                                            tempActiveModule = e2;
                                                            secondResult2 = true;
                                                            return true;
                                                        }
                                                        else
                                                        {
                                                            if (e2.result.parentName === "ultrasoundImageList")
                                                            {
                                                                bindImageTagsList.push({
                                                                    name: 'ultrasoundImageList', 
                                                                    bindField: e2.result.property.bindField
                                                                });
                                                            }
                                                            else
                                                            {
                                                                bindImageTagsList.push({
                                                                    name: e2.name, 
                                                                    bindField: e2.result.property.bindField
                                                                });
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (e2.result.parentName === "ultrasoundImageList")
                                                        {
                                                            bindImageTagsList.push({
                                                                name: 'ultrasoundImageList', 
                                                                bindField: e2.result.property.bindField
                                                            });
                                                        }
                                                        else
                                                        {
                                                            bindImageTagsList.push({
                                                                name: e2.name, 
                                                                bindField: e2.result.property.bindField
                                                            });
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    });
                                    if (secondResult2) {
                                        firstResult2 = true;
                                        return true;
                                    }
                                }
                            }
                            else {
                                if (!this.noBindFieldList.some(m2 => m2 === d2.name)) {
                                    if (d2.result && d2.result.property && d2.result.property) {
                                        if (d2.result.property.bindType === "CommonMeasure" || d2.result.property.bindType === "OtherMeasure" )
                                        {
                                            //计算项不验证
                                        }
                                        else if (!d2.result.property.bindField || d2.result.property.bindField.length <= 0) {
                                            tempActiveModule = d2;
                                            firstResult2 = true;
                                            return true;
                                        }
                                        else if (moduleNameList.some(sx => sx === d2.name)) {
                                            if (bindImageTagsList.length > 0) 
                                            {
                                                if (d2.result.parentName === "ultrasoundImageList")
                                                {
                                                    if (bindImageTagsList.some(dx => dx.name !== d2.result.parentName && dx.bindField === d2.result.property.bindField))
                                                    {
                                                        showTagMessage = true;
                                                        tempActiveModule = d2;
                                                        firstResult2 = true;
                                                        return true;
                                                    }
                                                } 
                                                else if (bindImageTagsList.some(dx => dx.name !== d2.name && dx.bindField === d2.result.property.bindField))
                                                {
                                                    showTagMessage = true;
                                                    tempActiveModule = d2;
                                                    firstResult2 = true;
                                                    return true;
                                                }
                                                else
                                                {
                                                    if (d2.result.parentName === "ultrasoundImageList")
                                                    {
                                                        bindImageTagsList.push({
                                                            name: 'ultrasoundImageList', 
                                                            bindField: d2.result.property.bindField
                                                        });
                                                    }
                                                    else
                                                    {
                                                        bindImageTagsList.push({
                                                            name: d2.name, 
                                                            bindField: d2.result.property.bindField
                                                        });
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (d2.result.parentName === "ultrasoundImageList")
                                                {
                                                    bindImageTagsList.push({
                                                        name: 'ultrasoundImageList', 
                                                        bindField: d2.result.property.bindField
                                                    });
                                                }
                                                else
                                                {
                                                    bindImageTagsList.push({
                                                        name: d2.name, 
                                                        bindField: d2.result.property.bindField
                                                    });
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        });
                        if (firstResult2) {
                            return true;
                        }
                    }
                });
                if (tempActiveModule != null) {
                    if (showTagMessage) 
                    {
                        this.$message.warning(this.$t("reportDesigner.singleImageError"));
                    }
                    else {
                        this.$message.warning(this.$t("reportDesigner.validateBindContent"));
                    }
                    this.activeModule = tempActiveModule;
                    if (this.$refs.scDragTool) {
                        this.$refs.scDragTool.clearActiveModuel(this.activeModule);
                    }
                    return false;
                }
            }

            if (currentFooterModuelList && currentFooterModuelList.length > 0)
            {
                currentFooterModuelList.some(c1 => {
                    if (c1 && c1.result && c1.result.tasks && c1.result.tasks.length > 0) {
                        var firstResult1 = false;
                        c1.result.tasks.some(d1 => {
                            if (d1.name === "cell") {
                                if (d1.result && d1.result.tasks && d1.result.tasks.length > 0) {
                                    var secondResult1 = false;
                                    d1.result.tasks.some(e1 => {
                                        if (!this.noBindFieldList.some(n1 => n1 === e1.name)) {
                                            if (e1.result && e1.result.property && e1.result.property) {
                                                if (e1.result.property.bindType === "CommonMeasure" || e1.result.property.bindType === "OtherMeasure" )
                                                {
                                                    //计算项不验证
                                                }
                                                else if (!e1.result.property.bindField || e1.result.property.bindField.length <= 0) {
                                                    tempActiveModule = e1;
                                                    secondResult1 = true;
                                                    return true;
                                                }
                                                else if (moduleNameList.some(sx => sx === e1.name)) {
                                                    if (bindImageTagsList.length > 0) 
                                                    {
                                                        if (e1.result.parentName === "ultrasoundImageList")
                                                        {
                                                            if (bindImageTagsList.some(dx => dx.name !== e1.result.parentName && dx.bindField === e1.result.property.bindField))
                                                            {
                                                                showTagMessage = true;
                                                                tempActiveModule = e1;
                                                                secondResult1 = true;
                                                                return true;
                                                            }
                                                        } 
                                                        else if (bindImageTagsList.some(dx => dx.name !== e1.name && dx.bindField === e1.result.property.bindField))
                                                        {
                                                            showTagMessage = true;
                                                            tempActiveModule = e1;
                                                            secondResult1 = true;
                                                            return true;
                                                        }
                                                        else
                                                        {
                                                            if (e1.result.parentName === "ultrasoundImageList")
                                                            {
                                                                bindImageTagsList.push({
                                                                    name: 'ultrasoundImageList', 
                                                                    bindField: e1.result.property.bindField
                                                                });
                                                            }
                                                            else
                                                            {
                                                                bindImageTagsList.push({
                                                                    name: e1.name, 
                                                                    bindField: e1.result.property.bindField
                                                                });
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (e1.result.parentName === "ultrasoundImageList")
                                                        {
                                                            bindImageTagsList.push({
                                                                name: 'ultrasoundImageList', 
                                                                bindField: e1.result.property.bindField
                                                            });
                                                        }
                                                        else
                                                        {
                                                            bindImageTagsList.push({
                                                                name: e1.name, 
                                                                bindField: e1.result.property.bindField
                                                            });
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    });
                                    if (secondResult1) {
                                        firstResult1 = true;
                                        return true;
                                    }
                                }
                            }
                            else {
                                if (!this.noBindFieldList.some(m1 => m1 === d1.name)) {
                                    if (d1.result && d1.result.property && d1.result.property) {
                                        if (d1.result.property.bindType === "CommonMeasure" || d1.result.property.bindType === "OtherMeasure" )
                                        {
                                            //计算项不验证
                                        }
                                        else if (!d1.result.property.bindField || d1.result.property.bindField.length <= 0) {
                                            tempActiveModule = d1;
                                            firstResult1 = true;
                                            return true;
                                        }
                                        else if (moduleNameList.some(sx => sx === d1.name)) {
                                            if (bindImageTagsList.length > 0) 
                                            {
                                                if (d1.result.parentName === "ultrasoundImageList")
                                                {
                                                    if (bindImageTagsList.some(dx => dx.name !== d1.result.parentName && dx.bindField === d1.result.property.bindField))
                                                    {
                                                        showTagMessage = true;
                                                        tempActiveModule = d1;
                                                        firstResult1 = true;
                                                        return true;
                                                    }
                                                } 
                                                else if (bindImageTagsList.some(dx => dx.name !== d1.name && dx.bindField === d1.result.property.bindField))
                                                {
                                                    showTagMessage = true;
                                                    tempActiveModule = d1;
                                                    firstResult1 = true;
                                                    return true;
                                                }
                                                else
                                                {
                                                    if (d1.result.parentName === "ultrasoundImageList")
                                                    {
                                                        bindImageTagsList.push({
                                                            name: 'ultrasoundImageList', 
                                                            bindField: d1.result.property.bindField
                                                        });
                                                    }
                                                    else
                                                    {
                                                        bindImageTagsList.push({
                                                            name: d1.name, 
                                                            bindField: d1.result.property.bindField
                                                        });
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (d1.result.parentName === "ultrasoundImageList")
                                                {
                                                    bindImageTagsList.push({
                                                        name: 'ultrasoundImageList', 
                                                        bindField: d1.result.property.bindField
                                                    });
                                                }
                                                else
                                                {
                                                    bindImageTagsList.push({
                                                        name: d1.name, 
                                                        bindField: d1.result.property.bindField
                                                    });
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        });
                        if (firstResult1) {
                            return true;
                        }
                    }
                });
                if (tempActiveModule != null) {
                    if (showTagMessage) 
                    {
                        this.$message.warning(this.$t("reportDesigner.singleImageError"));
                    }
                    else {
                        this.$message.warning(this.$t("reportDesigner.validateBindContent"));
                    }
                    this.activeModule = tempActiveModule;
                    if (this.$refs.scDragFooterTool) {
                        this.$refs.scDragFooterTool.clearActiveModuel(this.activeModule);
                    }
                    return false;
                }
            }
            return true;
        },
        //保存模板
        saveTemplate() {
            if (!this.validateBindField()) {
                return false;
            }
            this.saveTemplateTagsData();
            if (this.queryInfo.name !== this.activeTemplateSet.name)
            {
                this.$confirm((this.$t('reportDesigner.FileNameInconformity')),this.$t('dialogBox.confirmWarningTitle'), {
                    type: 'warning',
                    confirmButtonText: this.$t('dialogBox.confirmButtonText'),
                    cancelButtonText: this.$t('dialogBox.cancelButtonText'),
                    confirmButtonClass: 'el-button--danger'
                }).then(() => {
                    var curApplicable = (this.queryInfo.type === 0 || this.queryInfo.type === "0") ? "Person" : "Animal";
                    if (curApplicable !== this.activeTemplateSet.applicable)
                    {
                        this.$confirm((this.$t('reportDesigner.UseObjectInconformity')),this.$t('dialogBox.confirmWarningTitle'), {
                            type: 'warning',
                            confirmButtonText: this.$t('dialogBox.confirmButtonText'),
                            cancelButtonText: this.$t('dialogBox.cancelButtonText'),
                            confirmButtonClass: 'el-button--danger'
                        }).then(() => {
                            this.saveTemplateData();
                        }).catch(() => {
                            console.log("Save Designer Tempalte Info Error");
                        })
                    }
                    else {
                        this.saveTemplateData();
                    }
                }).catch(() => {
                    console.log("Save Designer Tempalte Info Error");
                })
            }
            else {
                this.saveTemplateData();
            }
        },
        async saveTemplateData() {
            var currentHeaderModuelList = this.activeTemplateSet.paperHeaderFooter.usePaperHeader ? this.activeHeaderModuleList : [];
            var currentFooterModuelList = this.activeTemplateSet.paperHeaderFooter.usePaperFooter ? this.activeFooterModuleList : [];
            var data = transfer.saveOldJson(this.labelContentList, this.activeTemplateSet,
                currentHeaderModuelList, this.activeModuleList, currentFooterModuelList, this.CustomizeCalculations);
            var reportDatas = null;
            if (typeof data === "object") {
                reportDatas = JSON.stringify(data["reportDatas"], undefined, 4);
                data = JSON.stringify(data["templateJson"], undefined, 4);
            }
            // if (this.queryInfo.category === 0 || this.queryInfo.category === "0") {
                var tempModelInfo = tool.objCopy(this.templateModelInfo);
                tempModelInfo["ReportTemplateJson"] = data;
                tempModelInfo["ReportDatasJson"] = reportDatas;
                var res = await api.template.updateReportTemplateAsync.post(tempModelInfo);
                if (res) {
                    this.$message.warning(this.$t("reportDesigner.saveSuccess"));
                }
                else {
                    this.$message.warning(this.$t("reportDesigner.saveFail"));
                }
            // }
            // else {
            //     //保存到指定地址
            //     if (this.activeModuleList && this.activeModuleList.length > 0) {
            //         var filename = this.activeTemplateSet.name + ".json";
            //         var blob = new Blob([data], { type: "text/json" }),
            //         e = document.createEvent("MouseEvents"),
            //         a = document.createElement("a");
            //         a.download = filename;
            //         a.href = window.URL.createObjectURL(blob);
            //         a.dataset.downloadurl = ["text/json", a.download, a.href].join(":");
            //         e.initMouseEvent(
            //             "click",
            //             true,
            //             false,
            //             window,
            //             0,
            //             0,
            //             0,
            //             0,
            //             0,
            //             false,
            //             false,
            //             false,
            //             false,
            //             0,
            //             null
            //         );
            //         a.dispatchEvent(e);
            //     }
            //     else {
            //         this.$message.warning(this.$t("reportDesigner.CommitTip1"));
            //     }
            // }
            var shell = window["FisShellApi"];
            var templateId = this.templateModelInfo.ReportTemplateCode;
            var name = this.templateModelInfo.ReportTemplateName;
            var useObject = this.templateModelInfo.ReportTemplateUsageType;
            if (shell) {
                shell.saveTemplate(templateId, name, useObject, data, reportDatas);
            }
        },
        //导出保存模板
        loadSaveTemplateData() {
            if (!this.validateBindField()) {
                return false;
            }
            this.saveTemplateTagsData();
            var templateContent = {
                currentPageInfo: this.activeTemplateSet,
                currentModuelList: this.activeModuleList,
                currentHeaderModuelList: this.activeTemplateSet.paperHeaderFooter.usePaperHeader ? this.activeHeaderModuleList : [],
                currentFooterModuelList: this.activeTemplateSet.paperHeaderFooter.usePaperFooter ? this.activeFooterModuleList : []
            };
            tool.data.set("CurrentTemplateContent", templateContent);
            return true;
        },
        //保存，并导出新增的配置信息
        saveTemplateTagsData() {
            var configTags = {};
            var templateTagList = this.$TOOL.data.get("activeTemplateTagList");
            if (templateTagList && templateTagList.length > 0)
            {
                templateTagList.some(c => {
                    configTags[c.Id] = {
                        id: c.Id,
                        name: c.Key,
                        isDefault: c.IsDefault,
                        elementTagType: (c.ParentId === "0" ? "General" : "DiagnosticEntry")
                    };
                });
            }
            this.activeTemplateSet.tags = configTags;
        },
        //打开模板设置
        openPageSetting() {
            this.isShowPageForm = true;
            this.activeTab = "form";
        },
        //加载默认数据
        loadDefaultData() {
            this.$refs.scDragTool.loadDefaultData(this.factPageWidth);
        },
        //导入外部数据
        loadJsonData(jsonData) {
            if (jsonData && jsonData.currentPageInfo) {
                //加载页面配置 page信息
                this.activeTemplateSet.name = jsonData.currentPageInfo.name;
                this.activeTemplateSet.defaultPageType = jsonData.currentPageInfo.defaultPageType;
                this.activeTemplateSet.defaultPagePadding = jsonData.currentPageInfo.defaultPagePadding;
                this.activeTemplateSet.defaultPageHeader = jsonData.currentPageInfo.defaultPageHeader;
                this.activeTemplateSet.defaultPageFooter = jsonData.currentPageInfo.defaultPageFooter;
                this.activeTemplateSet.applicable = jsonData.currentPageInfo.applicable;
                this.activeTemplateSet.defaultPageFont = jsonData.currentPageInfo.defaultPageFont;
                this.activeTemplateSet.version = jsonData.currentPageInfo.version;
                this.activeTemplateSet.invertColor = jsonData.currentPageInfo.invertColor;
                this.activeTemplateSet.paperHeaderFooter = jsonData.currentPageInfo.paperHeaderFooter;
                this.activeTemplateSet.tags = jsonData.currentPageInfo.tags;
                //数据转换 tags
                var tagList = [];
                if (jsonData.currentPageInfo.tags) 
                {
                    for (let tagKey in jsonData.currentPageInfo.tags) {
                        if (tagKey && tagKey.length > 0 && jsonData.currentPageInfo.tags[tagKey])
                        {
                            var tempTag = {
                                Id: jsonData.currentPageInfo.tags[tagKey].id, 
                                Key: jsonData.currentPageInfo.tags[tagKey].name, 
                                Value: jsonData.currentPageInfo.tags[tagKey].name, 
                                ParentId: "1",
                                IsDefault: false
                            };
                            if (jsonData.currentPageInfo.tags[tagKey].elementTagType === "General") 
                            {
                                tempTag.ParentId = "0";
                            }
                            tagList.push(tempTag);
                        }
                    }
                    //添加到浏览器缓存
                    this.$TOOL.data.set("activeTemplateTagList", tagList);
                }
                this.factPageWidth = tool.mmToPx(this.activeTemplateSet.defaultPageType.width) - tool.mmToPx(this.activeTemplateSet.defaultPagePadding.left) - tool.mmToPx(this.activeTemplateSet.defaultPagePadding.right);
                this.$refs.scSetting.loadData(this.activeTemplateSet);
            }
            if (jsonData && jsonData.currentModuelList && jsonData.currentModuelList.length > 0) {
                this.$refs.scDragTool.loadDefaultData(this.factPageWidth, jsonData.currentModuelList);
            }
            if (jsonData && jsonData.labelContentList && jsonData.labelContentList.length > 0) {
                this.labelContentList = jsonData.labelContentList;
            }
            if (jsonData && jsonData.currentHeaderList && jsonData.currentHeaderList.length > 0) {
                this.$refs.scDragHeaderTool.loadDefaultData(jsonData.currentHeaderList);
            }
            if (jsonData && jsonData.currentFooterList && jsonData.currentFooterList.length > 0) {
                this.$refs.scDragFooterTool.loadDefaultData(jsonData.currentFooterList);
            }
            if (jsonData && jsonData.customCalculations && jsonData.customCalculations.length > 0) {
                this.CustomizeCalculations = jsonData.customCalculations;
                //转换成通用数据
                this.customCalculationData = this.AddCustomCalcutationData();
                this.$refs.scProperty.loadCustomMeasureItemData(this.customCalculationData);
            }
        },
        //处理测量项
        getCustomCalcutationData() {
            return { customCalculationData:this.customCalculationData, CustomizeCalculations: this.CustomizeCalculations };
        },
        //添加自定义计算项到总的数据源中
        AddCustomCalcutationData() {
            if (this.CustomizeCalculations && this.CustomizeCalculations.length > 0) {
                //Common
                var modeId = common.guid();
                var model = [{"Id": modeId,"Key":"CustomizeCalculation","Value":"自定义计算项","PId":2,"Type":2}];
                var measureItem = [];
                var measureMethod = [];
                var output = [];
                var type = [];
                var unit = [];
                this.CustomizeCalculations.some(c => {
                    if (c.Formula && c.Formula.length > 0) {
                        var measureItemId = common.guid();
                        var measureMethodId = common.guid();
                        var outputId = common.guid();
                        var typeId = common.guid();
                        var unitId = common.guid();
                        //添加测量项
                        measureItem.push(
                            {"Id":measureItemId,"Key":c.Id,"Value":c.Id,"PId":modeId,"Type":2, "Formula":c.Formula}
                        );
                        //添加测量方法
                        measureMethod.push(
                            {"Id":measureMethodId,"Key":"","Value":"","PId":measureItemId,"Type":2, "Formula":c.Formula}
                        );
                        //输出
                        output.push(
                            {"Id":outputId,"Key":c.Id,"Value":c.Id,"PId":measureMethodId,"Type":2, "Formula":c.Formula}
                        );
                        var unitItems = this.unitOptions.filter(m => m.value === c.Unit);
                        var unitItemLabel = "";
                        if (unitItems && unitItems.length > 0) {
                            unitItemLabel = unitItems[0].name;
                        }
                        //单位
                        unit.push(
                            {"Id":unitId,"Key":c.Unit,"Value":unitItemLabel,"PId":outputId,"Type":2, "Formula":c.Formula}
                        );
                        //自定测量项名称
                        type.push(
                            {"Id":typeId,"Key":c.Id,"Value":c.Id,"PId":unitId,"Type":2, "Formula":c.Formula}
                        );
                    }
                });
            }
            return { measureItem, measureMethod, model, output, type, unit };
        },
        //处理注释内容
        getLabelContentList(contentList) {
            if (contentList && contentList.length > 0) {
                this.labelContentList = contentList;
            }
            else {
                return this.labelContentList;
            }
        },
        //清空
        clearDragRule() {
            this.activeModule = {};
            this.activeModuleList = [];
            this.activeHeaderModuleList = [];
            this.activeFooterModuleList = [];
            this.activeTemplateSet.paperHeaderFooter.usePaperHeader = false;
            this.activeTemplateSet.paperHeaderFooter.usePaperFooter = false;
            this.$refs.scDragTool.clearDrag();
            this.$refs.scDragHeaderTool.clearDrag();
            this.$refs.scDragFooterTool.clearDrag();
        },
    },
};
</script>

<style>
._fc-m-header {
    top: 0px;
    margin-left: 10px;
    text-align: center;
    line-height: 30px;
    display: inline;
}

._fc-m-line {
    height: 1px;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) 8px, transparent 8px, transparent 57%);
    background-size: 12px 100%;
    background-position: 50%;
    width: 100px;
    float: left;
    margin-top: 15px;
}

._fc-m-footer {
    bottom: 0px;
    margin-left: 10px;
    text-align: center;
    line-height: 30px;
    display: inline;
}

._fc-m-header-text,
._fc-m-footer-text {
    float: inline-end;
    width: 300px;
    margin-left: 10px;
}

._fc-m-footer-page,
._fc-m-footer-page-item {
    margin-left: 20px;
    display: inline;
}

._fc-designer {
    height: 100%;
    min-height: 500px;
    overflow: hidden;
    cursor: default;
    position: relative;
}

/* ._fc-designer > .el-main {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 0px;
    }  */

._fc-m ._fc-l-item {
    background: #2E73FF;
    width: 100%;
    height: 10px;
    overflow: hidden;
    transition: all .3s ease;
}

._fc-l,
._fc-m,
._fc-r {
    border-top: 1px solid #ECECEC;
    box-sizing: border-box;
}

._fc-l-group {
    padding: 0 12px;
}

._fc-l-title {
    font-weight: 600;
    font-size: 14px;
    margin: 18px 0px 5px;
}

._fc-l-item {
    display: inline-block;
    color: #000;
    min-width: 70px;
    width: 25%;
    height: 70px;
    line-height: 1;
    text-align: center;
    transition: all .2s ease;
    cursor: pointer;
    background: #FFF;
}

._fc-l-item-G {
    background: #DDE0E3;
    font-weight: 600;
}

._fc-l-item i {
    font-size: 21px;
    display: inline-block;
}

._fc-l-item ._fc-l-name {
    font-size: 12px;
}

._fc-l-item ._fc-l-icon {
    padding: 10px 5px 12px;
}

._fc-l-item:hover {
    background: #2E73FF;
    color: #fff;
}

._fc-m-tools {
    /* height: 40px; */
    height: 60px;
    align-items: center;
    display: flex;
    justify-content: flex-end;
    border: 1px solid #ECECEC;
    border-top: 0 none;
    border-left: 0 none;
    border-right: 0 none;
}

._fc-m-tools button.el-button {
    padding: 5px 14px;
    display: flex;
    align-items: center;
}

._fc-m-tools .fc-icon {
    font-size: 14px;
    margin-right: 2px;
}

._fc-r .el-tabs__nav-wrap::after {
    height: 1px;
    background-color: #ECECEC;
}

._fc-r ._fc-r-tabs {
    display: flex;
    padding: 0;
    border-bottom: 1px solid #ECECEC;
}

._fc-r ._fc-r-tab {
    height: 40px;
    box-sizing: border-box;
    line-height: 40px;
    display: inline-block;
    list-style: none;
    font-size: 14px;
    font-weight: 600;
    color: #303133;
    position: relative;
    flex: 1;
    text-align: center;
    /* background: #F6F8F9; */
}

._fc-r ._fc-r-tab.active {
    color: #409EFF;
    border-bottom: 2px solid #409EFF;
}

.drag-box {
    min-height: 60px;
}

._fc-m-drag {
    overflow: auto;
    padding: 2px;
}

._fc-m-drag,
.draggable-drag {
    background: #fff;
    position: relative;
}

.list-group-item {
    cursor: move;
    background: red;
    /* background: #fff; */
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
    margin: 0 15px 15px 0;
    border: 1px solid #e6e6e6;
}

._fc-l-item1 {
    display: inline-block;
    /* background: #FFF; */
    color: #000;
    line-height: 1;
    text-align: center;
    transition: all .2s ease;
    cursor: pointer;
}

._fc-l-item1 ._fc-l-icon1 {
    padding: 2px 3px 2px;
}

._fc-l-item1:hover {
    background: #DEE0E2;
}

::-webkit-scrollbar {
    height: 6px;
    width: 6px;
    background-color: #F5F5F5;
}

::-webkit-scrollbar-thumb {
    background-color: #949292;
}

::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgb(0 0 0 / 30%);
    background-color: #F5F5F5;
}

/* .icon-input:before {
        content: "\e77f";
    }

    .fc-icon {
        font-family: "fc-icon" !important;
        font-size: 16px;
        font-style: normal;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    .icon-checkbox:before {
        content: "\e780";
    }

    .icon-radio:before {
        content: "\e781";
    }

    @font-face {
        font-family: "fc-icon";
        src: url(@/style/fonts/fc-icons.woff) format('woff');
    } */
</style>

<style scoped>
/* 用于组件样式穿透，局部起作用 */
::v-deep .el-tabs__nav {
    white-space: nowrap;
    position: relative;
    transition: transform var(--el-transition-duration);
    float: right;
    right: 20%;
    z-index: calc(var(--el-index-normal) + 1);
}

::v-deep .el-collapse {
    --el-collapse-border-color: var(--el-border-color-lighter);
    --el-collapse-header-height: 40px;
    --el-collapse-header-bg-color: var(--el-color-white);
    --el-collapse-header-text-color: var(--el-text-color-primary);
    --el-collapse-header-font-size: 13px;
    --el-collapse-content-bg-color: var(--el-color-white);
    --el-collapse-content-font-size: 13px;
    --el-collapse-content-text-color: var(--el-text-color-primary);
    border-top: 1px solid var(--el-collapse-border-color);
    border-bottom: 1px solid var(--el-collapse-border-color);
}

::v-deep .el-collapse-item__header {
    display: flex;
    align-items: center;
    height: var(--el-collapse-header-height);
    line-height: var(--el-collapse-header-height);
    background-color: var(--el-collapse-header-bg-color);
    /* background-color: #F6F8F9; */
    color: var(--el-collapse-header-text-color);
    cursor: pointer;
    border-bottom: 1px solid var(--el-collapse-border-color);
    font-size: var(--el-collapse-header-font-size);
    font-weight: bold;
    transition: border-bottom-color var(--el-transition-duration);
    outline: 0;
}

::v-deep .el-collapse-item__header.is-active {
    /* border-bottom-color: transparent; */
    color: #409EFF;
    border-bottom: 2px solid #409EFF;
}

::v-deep .el-collapse-item__content {
    padding: 25px 0px;
    font-size: var(--el-collapse-content-font-size);
    color: var(--el-collapse-content-text-color);
    line-height: 1.7692307692;
}

::v-deep .el-form-item__content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    flex: 1;
    position: relative;
    font-size: var(--font-size);
    min-width: 0;
}
</style>
