import tool from '@/utils/tool';
import common from "@/utils/common";
import i18n from '@/locales'
import previewContent from '@/config/designer/preview';
//import divider from '@/config/designer/divider';

//数据转换
const transfer = {
    reportTableDragControls: ["table", "scanTable"],
    reportElementList: []
 }

/* page */
transfer.page = function (languagesTableData, obj, data) {
    var oldJson = null;
    if (obj)
    {
        //tool.dateFormat(Date.now()),
        var headerHeight = tool.mmToPt(obj.defaultPageHeader.height);
        var footerHeight = tool.mmToPt(obj.defaultPageFooter.height)
        oldJson = {
            Id: obj.id,
            UpdateTime: tool.dateFormat(Date.now()),
            IsCustom: obj.isCustom,
            Author: obj.author,
            Name: obj.name,
            PagePadding: {
                Left: tool.mmToPt(obj.defaultPagePadding.left),
                Top: tool.mmToPt(obj.defaultPagePadding.top),
                Right: tool.mmToPt(obj.defaultPagePadding.right),
                Bottom: tool.mmToPt(obj.defaultPagePadding.bottom),
            },
            PageSize: {},
            HeaderHeight: null,
            HeaderDistance: tool.mmToPt(obj.defaultPageHeader.top),
            FooterHeight: null,
            FooterDistance: tool.mmToPt(obj.defaultPageFooter.bottom),
            Header: [],
            Footer: [],
            BaseFontSize: parseFloat(obj.defaultPageFooter.fontSize),
            InvertColor: obj.invertColor,
            Version: obj.version,
            Applicable: obj.applicable,
            Tags: {},
            CustomizeTranslation: {
                Chinese: {
                    //"ttttt": "测量","test": "测试"
                },
                English: {
                    //"添加": "Add","ttttt": "de"
                },
                German: {},
                Greek: {},
                Malay: {},
                Portuguese: {},
                Romanian: {},
                Spanish: {},
                Swedish: {},
                Norwegian: {},
                Danish: {},
                Finnish: {},
                French: {},
                Polish: {},
                Russian: {},
                Uighur: {},
                Italian: {},
                Czech: {},
                Khmer: {},
                Hungarian: {}
            },
            CustomizeComments: [
                //"添加","ttttt"
            ],//勾选了扫查注释
            CustomizeReportComments: [
                //"ttttt","test"
            ],//报告注释
            CustomizeCalculations: [],
            Blocks: []
        };
        if (obj.tags) 
        {
            for (let tagKey in obj.tags) {
                if (tagKey && tagKey.length > 0 && obj.tags[tagKey])
                {
                    oldJson.Tags[tagKey] = {
                        Id: obj.tags[tagKey].id,
                        Name: obj.tags[tagKey].name,
                        IsDefault: obj.tags[tagKey].isDefault,
                        ElementTagType: obj.tags[tagKey].elementTagType,
                    };
                }
            }
        }
        if (headerHeight > 0)
        {
            oldJson.HeaderHeight = headerHeight;
        }
        if (footerHeight > 0)
        {
            oldJson.FooterHeight = footerHeight;
        }
        //注释语言
        if (languagesTableData && languagesTableData.length > 0) {
            languagesTableData.forEach(m => {
                if (m.scan) {
                    oldJson.CustomizeComments.push(m.keyword);
                }
                if (m.seport) {
                    oldJson.CustomizeReportComments.push(m.keyword);
                }
                if (m.languageDatas && m.languageDatas.length > 0) {
                    m.languageDatas.forEach(n => {
                        if (n.value && n.value.length > 0) {
                            oldJson.CustomizeTranslation[n.key][m.keyword] = n.value;
                        }
                    });
                }
            });
        }
        if (data && data.length > 0) {
            oldJson.CustomizeCalculations = data;
        }
        if (obj.defaultPageType.key === "A4") {
            oldJson.PageSize = {
                Height: 841.88976377952747,
                Width: 595.275590551181,
            };
        }
        else {
            oldJson.PageSize = {
                Height: 730.0,
                Width: 517.0,
            };
        }
    }
	return oldJson;
}

/* grid */
transfer.grid = function (data) {
    var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            LineSpace: 0.0,
            Elements: [],
            Id: data.id,
            Index: obj.margin.sort,
            Tag: null,
            Interval: tool.mmToPt(obj.pattern.interval),
            MeasureTag: null,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment),
            VerticalAlignment: "Stretch",
            Margin: {
                Left: 0.0,
                Top: 0.0,
                Right: 0.0,
                Bottom: 0.0,
            },
            ElementType: {
                Name: "Paragraph"
            },
        };
    }
	return oldJson;
}

/* table */
transfer.table = function (data) {
    var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            BorderStyle: transfer.dividerStyle(obj.pattern.borderStyle),
            BorderColor: tool.hexToRgb(obj.pattern.borderColor),
            borderWeight: obj.pattern.borderWeight,
            BackgroundColor: tool.hexToRgb(obj.pattern.backgroundColor, true),
            ShowTableBorder: obj.pattern.showTableBorder,
            AutoHide: obj.property.isHidden,
            IsAverageColumnWidth: obj.pattern.avgColumnWidth,
            AllowBreakAcrossPages: obj.pattern.allowSpanPage,
            ShowTableCellBorder: obj.pattern.ShowTableCellBorder,
            ShowTableCellMargin: obj.pattern.ShowTableCellMargin,
            ColumnDefinitions: [],
            RowDefinitions: [],
            Cells: [],
            Id: data.id,
            Index: 0,
            Tag: null,
            MeasureTag: null,
            HorizontalAlignment: "Left",
            VerticalAlignment: "Stretch",
            Margin: {
                Left: 0.0,
                Top: 0.0,
                Right: 0.0,
                Bottom: 0.0,
            },
            ElementType: {
                Name: "RTTable"
            }
        };
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (obj.base && obj.base.columnWidth && obj.base.columnWidth.length > 0) {
            obj.base.columnWidth.forEach(d => {
                oldJson.ColumnDefinitions.push(
                    { Width : (tool.mmToPt(d) - 1) }
                )
            });
        }
        if (obj.base && obj.base.rowHeight && obj.base.rowHeight.length > 0) {
            obj.base.rowHeight.forEach(e => {
                oldJson.RowDefinitions.push(
                    { Height: tool.mmToPt(e.height <= 0 ? 6.34 : e.height), Type: e.type, MinHeight: tool.mmToPt(e.minHeight <= 0 ? 6.34 : e.minHeight) },
                )
            });
        }
        if (obj.tasks  && obj.tasks.length > 0) {
            obj.tasks.forEach(m => {
                var cellHeader = {
                    Row: (m.result.base.rowStartIndex - 1),
                    Column: (m.result.base.colStartIndex - 1),
                    RowSpan: m.result.base.rowSpan,
                    ColumnSpan: m.result.base.colSpan
                };
                oldJson.Cells.push(cellHeader);
                var cellContent = {
                    Blocks: [],
                    Background: tool.hexToRgb(m.result.pattern.cellBackgroundColor, true),
                    WidthType: parseInt(m.result.property.cellColumnWidhtType) === 1 ? "FixedValue" : "MinValue",
                    HeightType: parseInt(m.result.property.cellRowHeightType) === 1 ? "FixedValue" : "MinValue",
                    Borders: {},
                    Id: m.id,
                    Index: 0,
                    Tag: null,
                    MeasureTag: null,
					FeatureTag: m.result.property.contentSetItems,
                    HorizontalAlignment: transfer.direction(1, m.result.pattern.horizontalAlignment),
                    VerticalAlignment: transfer.direction(2, m.result.pattern.verticalAlignment),//"Stretch",
                    Margin: {
                        Left: 0.0,
                        Top: 0.0,
                        Right: 0.0,
                        Bottom: 0.0,
                    },
                    ElementType: {
                        Name: "RTCell"
                    },
                };
                if (obj.pattern.showTableCellBorder && m.result.pattern.showCellBorder) {
                    var defaultStyleInfo = {
                        BorderStyle: transfer.dividerStyle(m.result.pattern.cellBorderStyle),
                        Color: tool.hexToRgb(m.result.pattern.cellBorderColor),
                        Thickness: parseFloat(m.result.pattern.cellBorderWeight)//粗细
                    };
                    //表示要显示表格边框，且显示单元格
                    cellContent.Borders = {
                        Left: defaultStyleInfo,
                        Top: defaultStyleInfo,
                        Right: defaultStyleInfo,
                        Bottom: defaultStyleInfo
                    };
                }
                else {
                    var styleInfo = {
                        BorderStyle: "None",
                        Color: {
                            A: 255,
                            R: 0,
                            G: 0,
                            B: 0
                        },
                        Thickness: 1//粗细
                    };
                    cellContent.Borders = {
                        Left: styleInfo,
                        Top: styleInfo,
                        Right: styleInfo,
                        Bottom: styleInfo
                    };
                }
                var blockItem = {
                    LineSpace: 0.0,
                    Elements: [],
                    Id: common.guid(),
                    Index: 0,
                    Tag: null,
                    MeasureTag: null,
                    HorizontalAlignment: transfer.direction(1, m.result.pattern.horizontalAlignment),
                    VerticalAlignment: "Stretch",
                    Margin: {
                        Left: 0.0,
                        Top: 0.0,
                        Right: 0.0,
                        Bottom: 0.0,
                    },
                    ElementType: {
                        Name: "Paragraph"
                    },
                };
                if (m.result && m.result.tasks && m.result.tasks.length > 0) {
                    //用来填充基础组件
                    m.result.tasks.forEach((n, index) => {
                        var moduleDetail = transfer.switchType(n, index);
                        if (moduleDetail.ElementType.Name === "ImageList")
                        {
                            cellContent.Blocks.push(tool.objCopy(blockItem));
                            cellContent.Blocks.push(moduleDetail);
                            blockItem = {
                                LineSpace: 0.0,
                                Elements: [],
                                Id: common.guid(),
                                Index: 0,
                                Tag: null,
                                MeasureTag: null,
                                HorizontalAlignment: transfer.direction(1, m.result.pattern.horizontalAlignment),
                                VerticalAlignment: "Stretch",
                                Margin: {
                                    Left: 0.0,
                                    Top: 0.0,
                                    Right: 0.0,
                                    Bottom: 0.0,
                                },
                                ElementType: {
                                    Name: "Paragraph"
                                },
                            };
                        }
                        else 
                        {
                            blockItem.Elements.push(moduleDetail);
                        }
                    });
                    // if (blockItem.Elements && blockItem.Elements.length > 0) 
                    // {
                    //     cellContent.Blocks.push(blockItem);
                    // }
                }
                cellContent.Blocks.push(blockItem);
                oldJson.Cells.push(cellContent);
            });
        }
    }
	return oldJson;
}

/* input */
transfer.input = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            IsReadOnly: !obj.property.editable,
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: 5,//输入文本长度
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: false,
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: i18n.global.tc(obj.property.placeholder),
                Required: obj.property.required ? obj.property.required : false,
            },
            MeasureTag: null,
			FeatureTag: obj.property.featureTag,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "InputText"
            }
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

/* checkbox */
transfer.checkbox = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            IsReadOnly: !obj.property.editable,
            Items: [],
            DisplayStyle: "ShowAllItems",
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: 5,//输入文本长度
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: false,
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: obj.property.placeholder,
                Required: obj.property.required ? obj.property.required : false,
                Arrangement: obj.property.arrangement ? obj.property.arrangement : false,
            },
            MeasureTag: null,
			FeatureTag: obj.property.featureTag,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "MultiSelected"
            }
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
        if (obj.property.dataSourceType.value === '0' || obj.property.dataSourceType.value === 0) {
            if (obj.property.staticOptions && obj.property.staticOptions.length > 0)
            {
                obj.property.staticOptions.some(c => {
                    oldJson.Items.push(i18n.global.tc(c));
                });
            }
        }
        else {
            if (obj.property.dynamicOptions && obj.property.dynamicOptions.length > 0)
            {
                obj.property.dynamicOptions.some(c => {
                    oldJson.Items.push(i18n.global.tc(c));
                });
            }
        }
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

/* datetime */
transfer.datetime = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            IsReadOnly: !obj.property.editable,
            DateTimeFormat: transfer.dateFormat(obj.property.displayFormat),
            IsRealTime: obj.property.realTime ? obj.property.realTime : false,
            ShowEnabled: obj.property.enable ? !obj.property.enable : false,
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: 5,//输入文本长度
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: false,
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: obj.property.placeholder,
                Required: obj.property.required ? obj.property.required : false,
            },
            MeasureTag: null,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "DateTime"
            }
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

/* divider */
transfer.divider = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            Width: tool.mmToPt(obj.pattern.borderWidth),//宽度
            BorderStyle: transfer.dividerStyle(obj.pattern.borderStyle),//线条样式
            Stroke: tool.hexToRgb(obj.pattern.borderColor),//颜色
            Thickness: obj.pattern.borderWeight,//粗细
            Id: data.id,
            Index: index,
            Tag: null,
            MeasureTag: null,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "Line"
            }
        };
    }
	return oldJson;
}

/* image */
transfer.image = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        var imageFileBase64 = "";
        if (obj.property.imageFile && obj.property.imageFile.length > 0)
        {
            var imgIndex = obj.property.imageFile.indexOf(";base64,") + 8;
            imageFileBase64 = obj.property.imageFile.substring(imgIndex);
        }
        oldJson = {
            Source: imageFileBase64,
            Stretch: "Uniform",
            Width: tool.mmToPt(obj.pattern.width),//输入文本长度
            Height: tool.mmToPt(obj.pattern.height),
            Id: data.id,
            Index: index,
            Tag: null,
            MeasureTag: null,
            HorizontalAlignment: "Stretch",//？？？这里要转换
            VerticalAlignment: "Stretch",//？？？这里要转换
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "StaticImage"
            }
        };
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
    }
	return oldJson;
}

/* imageList */
transfer.imageList = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            Elements: [],
            ImageWidth: tool.mmToPt(obj.base.gridWidth),
            ImageHeight: tool.mmToPt(obj.base.gridHeight),
            Column: obj.base.colNum,
            HasImageBorder: obj.pattern.showImageBorder,
            IsReadOnly: false,
            TransparentBackground: obj.pattern.backgroundShadow,
            HasGap: obj.pattern.showImageInterval,
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: obj.property.placeholder,
                Required: obj.property.required ? obj.property.required : false,
            },
            MeasureTag: null,
            HorizontalAlignment: "Center",//？？？这里要转换
            VerticalAlignment: "Stretch",//？？？这里要转换
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "ImageList"
            }
        };
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name] + ";" + previewContent["zh-CN"][(oldJson.Tag.Name + '3')]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name] + ";" + previewContent["zh-CN"][(oldJson.Tag.Name + '3')]
            });
        }
    }
	return oldJson;
}

/* label */
transfer.label = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            Text: i18n.global.tc(obj.property.placeholder),
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: obj.property.placeholder.length,//输入文本长度
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: false,
            Id: data.id,
            Index: index,
            Tag: null,
            MeasureTag: null,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "StaticText"
            }
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
    }
	return oldJson;
}

/* radio */
transfer.radio = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            IsReadOnly: !obj.property.editable,
            Items: [],
            DisplayStyle: "ShowAllItems",
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: 5,//输入文本长度
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: false,
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: obj.property.placeholder,
                Required: obj.property.required ? obj.property.required : false,
                Arrangement: obj.property.arrangement ? obj.property.arrangement : false,
            },
            MeasureTag: null,
			FeatureTag: obj.property.featureTag,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "SingleSelected"
            }
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
        if (obj.property.dataSourceType.value === '0' || obj.property.dataSourceType.value === 0) {
            if (obj.property.staticOptions && obj.property.staticOptions.length > 0)
            {
                obj.property.staticOptions.some(c => {
                    oldJson.Items.push(i18n.global.tc(c));
                });
            }
        }
        else {
            if (obj.property.dynamicOptions && obj.property.dynamicOptions.length > 0)
            {
                obj.property.dynamicOptions.some(c => {
                    oldJson.Items.push(i18n.global.tc(c));
                });
            }
        }
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

/* select */
transfer.select = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            IsReadOnly: !obj.property.editable,
            Items: [],
            DisplayStyle: "OnlyShowSelectedItem",
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: 5,//输入文本长度
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: false,
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: obj.property.placeholder,
                Required: obj.property.required ? obj.property.required : false,
            },
            MeasureTag: null,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {}
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
        // if (obj.property.dataSourceType.value === '0' || obj.property.dataSourceType.value === 0) {
        //     oldJson.Items = obj.property.staticOptions;
        // }
        // else {
        //     oldJson.Items = obj.property.dynamicOptions;
        // }
        if (obj.property.dataSourceType.value === '0' || obj.property.dataSourceType.value === 0) {
            if (obj.property.staticOptions && obj.property.staticOptions.length > 0)
            {
                obj.property.staticOptions.some(c => {
                    oldJson.Items.push(i18n.global.tc(c));
                });
            }
        }
        else {
            if (obj.property.dynamicOptions && obj.property.dynamicOptions.length > 0)
            {
                obj.property.dynamicOptions.some(c => {
                    oldJson.Items.push(i18n.global.tc(c));
                });
            }
        }
        if (!obj.property.multiple) {
            oldJson.ElementType = {
                Name: "SingleSelected"
            }
        }
        else {
            oldJson.ElementType = {
                Name: "MultiSelected"
            }
        }
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

/* space */
transfer.space = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            SpaceUnitCount: 0,
            SpaceWidth: tool.mmToPt(obj.pattern.width),
            Width: tool.mmToPt(obj.pattern.width),
            Id: data.id,
            Index: index,
            Tag: null,
            MeasureTag: null,
            HorizontalAlignment: "Stretch",
            VerticalAlignment: "Stretch",
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "Space"
            }
        };
    }
	return oldJson;
}

/* textarea */
transfer.textarea = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            IsReadOnly: !obj.property.editable,
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: 46,//输入文本长度
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: true,
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: i18n.global.tc(obj.property.placeholder),
                Required: obj.property.required ? obj.property.required : false,
            },
            MeasureTag: null,
			FeatureTag: obj.property.featureTag,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "InputText"
            }
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

/* ultrasoundImage */
transfer.ultrasoundImage = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            Comment: null,
            IsReadOnly: !obj.property.editable,
            Column: 1,
            HasBorder: obj.pattern.border,
            HasImageBorder: obj.pattern.border,
            TransparentBackground: obj.pattern.backgroundShadow,
            HasGap: false,
            Stretch: "Uniform",
            Width: tool.mmToPt(obj.pattern.width),
            Height: tool.mmToPt(obj.pattern.height),
            Id: data.id,
            Index: index,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: obj.property.placeholder,
                Required: obj.property.required ? obj.property.required : false,
            },
            MeasureTag: null,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: "Center",
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "InputImage"
            }
        };
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

/* pageNumber */
transfer.pageNumber = function (data, index) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            // Text: "",
            // PageNumberStyle:"",
            FontName: obj.pattern.fontName ? obj.pattern.fontName : "宋体",
            FontSize: parseFloat(obj.pattern.fontSize ? obj.pattern.fontSize : "10.5"),
            FontStyles: [],
            FontColor: tool.hexToRgb(obj.pattern.fontColor),
            Background: {
                A: 255,
                R: 255,
                G: 255,
                B: 255
            },
            LineLength: obj.property.placeholder.length,//输入文本长度   5
            LineWidth: tool.mmToPt(obj.pattern.width),
            TextWrap: false,
            Id: data.id,
            Index: index,
            Tag: null,
            MeasureTag: null,
            HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment, true),//？？？这里要转换
            VerticalAlignment: transfer.direction(2, obj.pattern.verticalAlignment),
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: ""
            }
        };
        if (parseInt(obj.pattern.fontWeight ? obj.pattern.fontWeight : 400) > 400)
        {
            oldJson.FontStyles = ["Bold"];
        }
        if (obj.property.pageNumberType === "Number" || obj.property.pageNumberType === "NumberAndTotalNumber") {
            oldJson["PageNumberStyle"] = obj.property.pageNumberType;
            oldJson.ElementType.Name = "PageNumber";
            oldJson.LineLength = 5;
        }
        else {
            oldJson["Text"] = obj.property.placeholder;
            oldJson.ElementType.Name = "StaticText";
            oldJson.LineLength = obj.property.placeholder.length;
        }
    }
	return oldJson;
}

/* header */
transfer.header = function (data) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = transfer.grid(data);
        if (obj.tasks && obj.tasks.length > 0) {
            obj.tasks.forEach((childModule, index) => {
                var moduleDetail = transfer.switchType(childModule, index);
                if (moduleDetail) {
                    oldJson.Elements.push(moduleDetail);
                }
            });
        }
    }
	return oldJson;
}

/* footer */
transfer.footer = function (data) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = transfer.grid(data);
        if (obj.tasks && obj.tasks.length > 0) {
            obj.tasks.forEach((childModule, index) => {
                var moduleDetail = transfer.switchType(childModule, index);
                if (moduleDetail) {
                    oldJson.Elements.push(moduleDetail);
                }
            });
        }
    }
	return oldJson;
}

/* ultrasoundImageList */
transfer.ultrasoundImageList = function (data) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        oldJson = {
            Elements: [],
            Column: parseInt(obj.pattern.columnNumPerPage),
            Row: parseInt(obj.pattern.rowNumPerPage),
            HasImageBorder: obj.pattern.showImageBorder,
            IsReadOnly: false,
            TransparentBackground: obj.pattern.backgroundShadow,
            HasGap: obj.pattern.showImageInterval,
            Id: data.id,
            Index: obj.margin.sort,
            Tag: {
                Id: transfer.getBindFieldId(obj.property.bindField),
                Name: obj.property.bindField,
                IsDefault: obj.property.isDefault,
                ElementTagType: obj.property.bindType,
                Placeholder: obj.property.placeholder,
                Required: obj.property.required ? obj.property.required : false,
            },
            MeasureTag: null,
            HorizontalAlignment: "Center",//？？？这里要转换
            VerticalAlignment: "Top",//？？？这里要转换
            Margin: {//这里可能要做计算，针对相对定位
                Left: tool.mmToPt(obj.margin.left),
                Top: tool.mmToPt(obj.margin.top),
                Right: tool.mmToPt(obj.margin.right),
                Bottom: tool.mmToPt(obj.margin.bottom)
            },
            ElementType: {
                Name: "AtlasElement"
            }
        };
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            var zhValueList = "";
            var enValueList = "";
            for (var m = 0; m < oldJson.Row; m++)
            {
                for (var n = 0; n < oldJson.Column; n++)
                {
                    if (m === 0 && n === 0)
                    {
                        zhValueList += previewContent["zh-CN"][(oldJson.Tag.Name + '2')];
                        enValueList += previewContent["en-US"][(oldJson.Tag.Name + '2')];
                    }
                    else if (m === (oldJson.Row - 1))
                    {
                        if (n === (oldJson.Column - 1))
                        {
                            zhValueList += ";" + previewContent["zh-CN"][(oldJson.Tag.Name + '3')];
                            enValueList += ";" + previewContent["en-US"][(oldJson.Tag.Name + '3')];
                        }
                        else
                        {
                            zhValueList += ";" + previewContent["zh-CN"][(oldJson.Tag.Name)];
                            enValueList += ";" + previewContent["en-US"][(oldJson.Tag.Name)];
                        }
                    }
                    else {
                        zhValueList += ";" + previewContent["zh-CN"][(oldJson.Tag.Name + '2')];
                        enValueList += ";" + previewContent["en-US"][(oldJson.Tag.Name + '2')];
                    }
                }
            }
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": zhValueList
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": enValueList
            });
        }
    }
	return oldJson;
}

/* scanTable */
transfer.scanTable = function (data) {
	var oldJson = null;
    var obj = data.result;
    if (obj)
    {
        if (!data.result.property.showImageAndDesc) {
            oldJson = {
                Elements: [],
                ImageWidth: tool.mmToPt(obj.base.gridWidth),
                ImageHeight: tool.mmToPt(obj.base.gridHeight),
                Column: obj.base.colNum,
                HasImageBorder: obj.pattern.showImageBorder,
                IsReadOnly: false,
                TransparentBackground: obj.pattern.backgroundShadow,
                HasGap: obj.pattern.showImageInterval,
                Id: data.id,
                Index: obj.margin.sort,
                Tag: {
                    Id: transfer.getBindFieldId(obj.property.bindField),
                    Name: obj.property.bindField,
                    IsDefault: obj.property.isDefault,
                    ElementTagType: obj.property.bindType,
                    Placeholder: obj.property.placeholder,
                    Required: obj.property.required ? obj.property.required : false,
                },
                MeasureTag: null,
                HorizontalAlignment: "Left",//？？？这里要转换
                VerticalAlignment: "Stretch",//？？？这里要转换
                Margin: {//这里可能要做计算，针对相对定位
                    Left: tool.mmToPt(obj.margin.left),
                    Top: tool.mmToPt(obj.margin.top),
                    Right: tool.mmToPt(obj.margin.right),
                    Bottom: tool.mmToPt(obj.margin.bottom)
                },
                ElementType: {
                    Name: "ImageList"
                }
            };
        }
        else {
            oldJson = {
                AutoHide: obj.property.isHidden,
                IsAverageColumnWidth: obj.pattern.avgColumnWidth,
                AllowBreakAcrossPages: obj.pattern.allowSpanPage,
                ShowTableCellBorder: obj.pattern.ShowTableCellBorder,
                ShowTableCellMargin: obj.pattern.ShowTableCellMargin,
                ColumnDefinitions: [],
                RowDefinitions: [],
                Cells: [],
                Id: data.id,
                Index: 0,
                Tag: null,
                MeasureTag: null,
                HorizontalAlignment: "Left",
                VerticalAlignment: "Stretch",
                Margin: {
                    Left: 0.0,
                    Top: 0.0,
                    Right: 0.0,
                    Bottom: 0.0,
                },
                ElementType: {
                    Name: "RTTable"
                }
            };
            if (obj.base && obj.base.columnWidth && obj.base.columnWidth.length > 0) {
                obj.base.columnWidth.forEach(d => {
                    oldJson.ColumnDefinitions.push(
                        { Width : (tool.mmToPt(d) - 1) }
                    )
                });
            }
            if (obj.base && obj.base.rowHeight && obj.base.rowHeight.length > 0) {
                obj.base.rowHeight.forEach(e => {
                    oldJson.RowDefinitions.push(
                        { Height: tool.mmToPt(e.height <= 0 ? 6.34 : e.height), Type: e.type, MinHeight: tool.mmToPt(e.minHeight <= 0 ? 6.34 : e.minHeight) },
                    )
                });
            }
            if (obj.tasks  && obj.tasks.length > 0) {
                obj.tasks.forEach(m => {
                    var cellHeader = {
                        Row: (m.result.base.rowStartIndex - 1),
                        Column: (m.result.base.colStartIndex - 1),
                        RowSpan: m.result.base.rowSpan,
                        ColumnSpan: m.result.base.colSpan
                    };
                    oldJson.Cells.push(cellHeader);
                    var cellContent = {
                        Blocks: [],
                        Background: {
                            A: 255,
                            R: 255,
                            G: 255,
                            B: 255
                        },
                        WidthType: parseInt(m.result.property.cellColumnWidhtType) === 1 ? "FixedValue" : "MinValue",
                        HeightType: parseInt(m.result.property.cellRowHeightType) === 1 ? "FixedValue" : "MinValue",
                        Borders: {},
                        Id: m.id,
                        Index: 0,
                        Tag: null,
                        MeasureTag: null,
                        // HorizontalAlignment: "Stretch",
                        // VerticalAlignment: "Stretch",
                        HorizontalAlignment: transfer.direction(1, m.result.pattern.horizontalAlignment),
                        VerticalAlignment: transfer.direction(2, m.result.pattern.verticalAlignment),//"Stretch",
                        Margin: {
                            Left: 0.0,
                            Top: 0.0,
                            Right: 0.0,
                            Bottom: 0.0,
                        },
                        ElementType: {
                            Name: "RTCell"
                        },
                    };
                    if (obj.pattern.showTableCellBorder && m.result.pattern.showCellBorder) {
                        var defaultStyleInfo = {
                            BorderStyle: transfer.dividerStyle(m.result.pattern.cellBorderStyle),
                            Color: tool.hexToRgb(m.result.pattern.cellBorderColor),
                            Thickness: parseFloat(m.result.pattern.cellBorderWeight)//粗细
                        };
                        //表示要显示表格边框，且显示单元格
                        cellContent.Borders = {
                            Left: defaultStyleInfo,
                            Top: defaultStyleInfo,
                            Right: defaultStyleInfo,
                            Bottom: defaultStyleInfo
                        };
                    }
                    else {
                        var styleInfo = {
                            BorderStyle: "None",
                            Color: {
                                A: 255,
                                R: 0,
                                G: 0,
                                B: 0
                            },
                            Thickness: 1//粗细
                        };
                        cellContent.Borders = {
                            Left: styleInfo,
                            Top: styleInfo,
                            Right: styleInfo,
                            Bottom: styleInfo
                        };
                    }
                    var blockItem = {
                        LineSpace: 0.0,
                        Elements: [],
                        Id: common.guid(),
                        Index: 0,
                        Tag: null,
                        MeasureTag: null,
                        HorizontalAlignment: "Stretch",
                        VerticalAlignment: "Stretch",
                        Margin: {
                            Left: 0.0,
                            Top: 0.0,
                            Right: 0.0,
                            Bottom: 0.0,
                        },
                        ElementType: {
                            Name: "Paragraph"
                        },
                    };
                    if (m.result && m.result.tasks && m.result.tasks.length > 0) {
                        //用来填充基础组件
                        m.result.tasks.forEach((n, index) => {
                            if (n.name === "label") {
                                blockItem.HorizontalAlignment = "Center";
                                blockItem.VerticalAlignment = "Center";
                            }
                            var moduleDetail = transfer.switchType(n, index);
                            blockItem.Elements.push(moduleDetail);
                        });
                    }
                    cellContent.Blocks.push(blockItem);
                    oldJson.Cells.push(cellContent);
                });
            }
        }
        if (obj.property && obj.property.measureItem && obj.property.measureItem.Mode && obj.property.measureItem.Mode.length > 0)
        {
            oldJson["MeasureTag"] = {
                AvailableMethods: obj.property.measureItem.AvailableMethods,
                BaseType: obj.property.measureItem.BaseType,
                CalculationId: obj.property.measureItem.CalculationId,
                MatchId: obj.property.measureItem.MatchId,
                Method: obj.property.measureItem.Method,
                Mode: obj.property.measureItem.Mode,
                Output: obj.property.measureItem.Output,
                OutputV2: obj.property.measureItem.OutputV2,
                Unit: obj.property.measureItem.Unit,
                UserId: obj.property.measureItem.UserId
            };
        }
        if (oldJson.Tag) 
        {
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "zh-CN",
                "Value": previewContent["zh-CN"][oldJson.Tag.Name]
            });
            transfer.reportElementList.push({
                "Key": oldJson.Id,
                "TagId": oldJson.Tag.Id,
                "Name": oldJson.Tag.Name,
                "AILanguage": "en-US",
                "Value": previewContent["en-US"][oldJson.Tag.Name]
            });
        }
    }
	return oldJson;
}

transfer.diagnosis = function (data) {
    var oldJsonList = [];
    var obj = data.result;
    if (obj)
    {
        if (obj.tasks && obj.tasks.length > 0) 
        {
            obj.tasks.some((d, index) => {
                var oldJson = {
                    LineSpace: 0.0,
                    Elements: [],
                    Id: data.id,
                    Index: obj.margin.sort,
                    Tag: null,
                    Interval: tool.mmToPt(obj.pattern.interval),
                    MeasureTag: null,
                    HorizontalAlignment: transfer.direction(1, obj.pattern.horizontalAlignment),
                    VerticalAlignment: "Stretch",
                    Margin: {
                        Left: 0.0,
                        Top: 0.0,
                        Right: 0.0,
                        Bottom: 0.0,
                    },
                    ElementType: {
                        Name: "Paragraph"
                    },
                };
                var moduleDetail = transfer.switchType(d, index);
                if (moduleDetail) {
                    oldJson.Elements.push(moduleDetail);
                }
                oldJsonList.push(oldJson);
            });
        }
    }
	return oldJsonList;
}

/* saveOldJson */
transfer.saveOldJson = function (languagesTableData, templateSet, headerList, moduleList, footerList, customizeCalculations) {
	var oldJson = transfer.page(languagesTableData, templateSet, customizeCalculations);
    if (oldJson)
    {
        if (moduleList && moduleList.length > 0) {
            moduleList.forEach(module =>
            {
                if (module.name === "table" || module.name === "reportHeader") {
                    //table 布局组件
                    var tableInfo = transfer.table(module);
                    oldJson.Blocks.push(tableInfo);
                }
                if (module.name === "diagnosis") {
                    //拆成多个grid
                    var diagnosisInfo = transfer.diagnosis(module);
                    if (diagnosisInfo && diagnosisInfo.length > 0)
                    {
                        diagnosisInfo.some(x => {
                            oldJson.Blocks.push(x);
                        });
                    }
                }
                else if (module.name === "doctorInfo" || module.name === "patientInfo")
                {
                    //table 布局组件
                    var tableReportInfo = transfer.table(module);
                    oldJson.Blocks.push(tableReportInfo);
                }
                else if (module.name === "scanTable") {
                    //扫查信息
                    oldJson.Blocks.push(transfer.scanTable(module));
                }
                else if (module.name === "ultrasoundImageList") {
                    //超声图册
                    oldJson.Blocks.push(transfer.switchType(module));
                }
                else {
                    //grid 布局组件
                    var gridInfo = transfer.grid(module);
                    if (module.result.tasks && module.result.tasks.length > 0) {
                        module.result.tasks.forEach((childModule, index) => {
                            var moduleDetail = transfer.switchType(childModule, index);
                            if (moduleDetail) {
                                if (moduleDetail.ElementType.Name === "ImageList")
                                {
                                    oldJson.Blocks.push(tool.objCopy(gridInfo));
                                    oldJson.Blocks.push(moduleDetail);
                                    gridInfo = transfer.grid(module);
                                }
                                else 
                                {
                                    gridInfo.Elements.push(moduleDetail);
                                }
                            }
                        });
                    }
                    if (gridInfo.Elements && gridInfo.Elements.length > 0) 
                    {
                        oldJson.Blocks.push(gridInfo);
                    }
                }
            });
        }
        if (headerList && headerList.length > 0) {
            headerList.forEach(module =>
            {
                if (module.name === "grid") {
                    var gridInfo = transfer.grid(module);
                    if (module.result.tasks && module.result.tasks.length > 0) {
                        module.result.tasks.forEach((childModule, index) => {
                            var moduleDetail = transfer.switchType(childModule, index);
                            if (moduleDetail) {
                                if (moduleDetail.ElementType.Name === "ImageList")
                                {
                                    oldJson.Header.push(tool.objCopy(gridInfo));
                                    oldJson.Header.push(moduleDetail);
                                    gridInfo = transfer.grid(module);
                                }
                                else 
                                {
                                    gridInfo.Elements.push(moduleDetail);
                                }
                            }
                        });
                    }
                    if (gridInfo.Elements && gridInfo.Elements.length > 0) 
                    {
                        oldJson.Header.push(gridInfo);
                    }
                }
                else if (module.name === "header") {
                    var footerInfo = transfer.header(module);
                    oldJson.Header.push(footerInfo);
                }
                else if (module.name === "table") {
                    //table 布局组件
                    var tableInfo = transfer.table(module);
                    oldJson.Header.push(tableInfo);
                }
            });
        }
        if (footerList && footerList.length > 0) {
            footerList.forEach(module =>
            {
                if (module.name === "grid") {
                    var gridInfo = transfer.grid(module);
                    if (module.result.tasks && module.result.tasks.length > 0) {
                        module.result.tasks.forEach((childModule, index) => {
                            var moduleDetail = transfer.switchType(childModule, index);
                            if (moduleDetail) {
                                if (moduleDetail.ElementType.Name === "ImageList")
                                {
                                    oldJson.Footer.push(tool.objCopy(gridInfo));
                                    oldJson.Footer.push(moduleDetail);
                                    gridInfo = transfer.grid(module);
                                }
                                else 
                                {
                                    gridInfo.Elements.push(moduleDetail);
                                }
                            }
                        });
                    }
                    if (gridInfo.Elements && gridInfo.Elements.length > 0) 
                    {
                        oldJson.Footer.push(gridInfo);
                    }
                }
                else if (module.name === "footer") {
                    var footerInfo = transfer.footer(module);
                    oldJson.Footer.push(footerInfo);
                }
                else if (module.name === "table") {
                    //table 布局组件
                    var tableInfo = transfer.table(module);
                    oldJson.Footer.push(tableInfo);
                }
            });
        }
    }
    return { "templateJson": oldJson, "reportDatas": transfer.reportElementList };
}

//遍历调用对应的组件
transfer.switchType = function (data, index) {
    var result = null;
    switch (data.name) {
        case "input":
            result = transfer.input(data, index)
            break;
        case "checkbox":
            result = transfer.checkbox(data, index)
            break;
        case "datetime":
            result = transfer.datetime(data, index)
            break;
        case "divider":
            result = transfer.divider(data, index)
            break;
        case "image":
            result = transfer.image(data, index)
            break;
        case "imageList":
            result = transfer.imageList(data, index)
            break;
        case "label":
            result = transfer.label(data, index)
            break;
        case "radio":
            result = transfer.radio(data, index)
            break;
        case "select":
            result = transfer.select(data, index)
            break;
        case "space":
            result = transfer.space(data, index)
            break;
        case "textarea":
            result = transfer.textarea(data, index)
            break;
        case "ultrasoundImage":
            result = transfer.ultrasoundImage(data, index)
            break;
        case "ultrasoundImageList":
            result = transfer.ultrasoundImageList(data)
            break;
        case "pageNumber":
            result = transfer.pageNumber(data)
            break;
        default:
            break;
    }
    return result;
}

/* 方向转换 */
transfer.direction = function (type, value, isReturnDefault) {
    var res = "";
	if (type === 1)//表示水平方向
    {
        if (value === "Left")
        {
            res = "Left"
        }
        else if (value === "Right")
        {
            res = "Right"
        }
        else if (value === "Center")
        {
            res = "Center"
        }
        else if (value === "Bothends")
        {
            res = "Bothends"
        }
        else
        {
            res = "Left"
        }
    }
    else if (type === 2)//表示垂直方向
    {
        if (value === "Top")
        {
            res = "Top";
        }
        else if (value === "Middle")
        {
            res = "Center";
        }
        else if (value === "Bottom")
        {
            res = "Bottom";
        }
        else
        {
            res = "Stretch";
        }
    }
    if (isReturnDefault) 
    {
        res = "Stretch";
    }
    return res;
}

/* 位置，坐标转换 */
transfer.location = function () {
    var res = "";
    return res;
}

/* 时间转换 */
transfer.dateFormat = function (type) {
    var res = "";
    switch (type) {
        case "yyyy-MM-dd hh:mm":
            res = "yyyy-MM-dd HH:mm";
            break;
        case "yyyy年MM月dd日 hh:mm":
            res = "yyyy年M月d日 HH:mm";
            break;
        case "yyyy-MM-dd":
            res = "yyyy-MM-dd";
            break;
        case "yyyy/MM/dd":
            res = "yyyy/MM/dd";
            break;
        case "yyyy.MM.dd":
            res = "yyyy.MM.dd";
            break;
        case "yyyy年MM月dd日":
            res = "yyyy年M月d日";
            break;
        default:
            res = "d";
            break;
    }
    return res;
}

/* 获取绑定项的Id */
transfer.getBindFieldId = function (key) {
    var allList = [];
    var returnId = null;
    var contentConfigStorage = tool.data.get("ContentConfigStorage")
    if (contentConfigStorage && contentConfigStorage.length > 0) {
        allList = contentConfigStorage;
    }
    if (allList && allList.length > 0) {
        var levelOneList = allList.filter(c => c.Key === key);
        if (levelOneList && levelOneList.length > 0) {
            returnId = levelOneList[0].Id;
        }
        else {
            allList.some(d => {
                if (d.Children && d.Children.length > 0) {
                    var res = false;
                    d.Children.some(e => {
                        if (e.Key === key) {
                            returnId = e.Id;
                            res = true;
                            return true;
                        }
                    });
                    if (res) {
                        return true;
                    }
                }
            });
        }
    }
    else {
        returnId = "";
    }
    if (returnId === null || !returnId || returnId.length <= 0) 
    {
        var templateTagList = tool.data.get("activeTemplateTagList");
        if (templateTagList && templateTagList.length > 0)
        {
            templateTagList.some(c => {
                if (c.Key === key)
                {
                    returnId = c.Id;
                    return true;
                }
            });
        }
    }
    return returnId;
}

/* 线条转换 */
transfer.dividerStyle = function (type) {
    var res = "";
    switch (type) {
        case "Solid":
            res = "Solid";
            break;
        case "Dotted":
            res = "Dot";
            break;
        case "Dashed":
            res = "Dash";
            break;
        default:
            res = "Solid";
            break;
    }
    return res;
}

export default transfer
