import tool from '@/utils/tool';
import checkbox from '@/config/designer/checkbox';
import datetime from '@/config/designer/datetime';
import divider from '@/config/designer/divider';
import image from '@/config/designer/image';
import imageList from '@/config/designer/imageList';
import input from '@/config/designer/input';
import label from '@/config/designer/label';
import radio from '@/config/designer/radio';
import select from '@/config/designer/select';
import space from '@/config/designer/space';
import table from '@/config/designer/table';
import tableCell from '@/config/designer/tableCell';
import textarea from '@/config/designer/textarea';
import grid from '@/config/designer/group/grid';
import pageNumber from '@/config/designer/pageNumber';
// import footer from '@/config/designer/group/footer';
// import header from '@/config/designer/group/header';
import ultrasoundImage from '@/config/designer/ultrasoundImage';
import ultrasoundImageList from '@/config/designer/group/ultrasoundImageList';
import scanTable from '@/config/designer/group/scanTable';
import api from "@/api"

//数据转换
const load = {
    labelContentList: [],
    customCalculations: []
}

/* page */
load.page = function (obj) {
    var newJson = null;
    if (obj)
    {
        newJson = {
			id: obj.Id,
			updateTime: obj.UpdateTime,
			isCustom: obj.IsCustom,
			author: obj.Author,
			name: obj.Name,
			defaultPagePadding: {
				top : tool.ptToMM(obj.PagePadding.Top),
				bottom : tool.ptToMM(obj.PagePadding.Bottom),
				left : tool.ptToMM(obj.PagePadding.Left),
				right : tool.ptToMM(obj.PagePadding.Right),
			},
			defaultPageHeader: {
				height: tool.ptToMM(obj.HeaderHeight),
				top: tool.ptToMM(obj.HeaderDistance),
			},
			defaultPageFooter: {
				height: tool.ptToMM(obj.FooterHeight),
				bottom: tool.ptToMM(obj.FooterDistance),
			},
			applicable: obj.Applicable ? obj.Applicable : "Person",
			defaultPageFont: {
				fontSize: obj.BaseFontSize,
				fontName: "宋体"
			},
			//版本
			version: obj.Version,
			invertColor: obj.InvertColor,
            paperHeaderFooter: {
                usePaperHeader: false,
                usePaperFooter: false
            },
            tags:{}
		};
        if (obj.Tags) 
        {
            for (let tagKey in obj.Tags) {
                if (tagKey && tagKey.length > 0 && obj.Tags[tagKey])
                {
                    newJson.tags[tagKey] = {
                        id: obj.Tags[tagKey].Id,
                        name: obj.Tags[tagKey].Name,
                        isDefault: obj.Tags[tagKey].IsDefault,
                        elementTagType: obj.Tags[tagKey].ElementTagType,
                    };
                }
            }
        }
		if (obj.PageSize && obj.PageSize.Height > 841 && obj.PageSize.Width > 595)
		{
			newJson.defaultPageType = {
                key: "A4",
                width: 209.54,
                height: 296.35
            };
		}
		else {
            newJson.defaultPageType = {
                key: "B5",
                width: 181.98,
                height: 256.96
            }
		}
        if (obj.Header && obj.Header.length > 0) {
            newJson.paperHeaderFooter.usePaperHeader = true;
        }
        if (obj.Footer && obj.Footer.length > 0) {
            newJson.paperHeaderFooter.usePaperFooter = true;
        }
    }
	return newJson;
}

/* page */
load.grid = function (obj) {
    var newJson = null;
    if (obj)
    {
        newJson = grid.initData(true);
        newJson.result.pattern = {
            //Left,Right,Center,Bothends
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            //间隔
            interval: obj.Interval ? tool.ptToMM(obj.Interval) : 1,//单位mm
        },
        //属性，每个组件可根据自身特点进行增减
        newJson.result.property = {
            //是否隐藏
            isHidden: obj.IsHidden ? obj.IsHidden : false,
        };
        //位置坐标
        newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.Elements && obj.Elements.length > 0) {
            obj.Elements.forEach(item => {
                var switchTypeStr = load.typeTransfer(item);
                var tempInfo = load.switchType(switchTypeStr, item, newJson.id, newJson.name);
                newJson.result.tasks.push(tempInfo);
            })
        }
        else {
            return null;
        }
    }
    return newJson;
}

/* input */
load.input = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = input.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            verticalAlignment: load.direction(2, obj.VerticalAlignment),
            // horizontalAlignment: "Left",
            // verticalAlignment: "Middle",
            width: tool.ptToMM(obj.LineWidth) ? tool.ptToMM(obj.LineWidth) : 30,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
			//功能标签
			featureTag: obj.FeatureTag,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            //占位文本
            placeholder: obj.Placeholder ? obj.Placeholder : "文本框",
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly,
            //数据源，需要用到则赋值，无需则为空数组
            option: [{value: '', label: ''}],
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        }
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
		newJson.result.property.featureTag = obj.FeatureTag;
    }
	return newJson;
}

/* label */
load.label = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = label.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: "Left",
            verticalAlignment: "Middle",
            width: obj.LineWidth > 0 ? tool.ptToMM(obj.LineWidth) : 0,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            //占位文本
            placeholder: obj.Text,
            //是否可编辑
            editable: false,
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        }
        var newEntity = {
            keyword: obj.Text,
            scan: false,
            seport: false,
            languageDatas: [
                {key: 'Chinese', value: ''}
                ,{key: 'English', value: ''}
                ,{key: 'German', value: ''}
                ,{key: 'Greek', value: ''}
                ,{key: 'Malay', value: ''}
                ,{key: 'Portuguese', value: ''}
                ,{key: 'Romanian', value: ''}
                ,{key: 'Spanish', value: ''}
                ,{key: 'Swedish', value: ''}
                ,{key: 'Norwegian', value: ''}
                ,{key: 'Danish', value: ''}
                ,{key: 'Finnish', value: ''}
                ,{key: 'French', value: ''}
                ,{key: 'Polish', value: ''}
                ,{key: 'Russian', value: ''}
                ,{key: 'Uighur', value: ''}
                ,{key: 'Italian', value: ''}
                ,{key: 'Czech', value: ''}
                ,{key: 'Khmer', value: ''}
                ,{key: 'Hungarian', value: ''}
            ]
        }
        var entity = load.labelContentList.filter(w => w.keyword === obj.Text);
        if (entity.length <= 0) {
            load.labelContentList.push(newEntity);
        }
    }
	return newJson;
}

/* pageNumber */
load.pageNumber = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = pageNumber.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: "Left",
            verticalAlignment: "Middle",
            width: obj.LineWidth > 0 ? tool.ptToMM(obj.LineWidth) : 0,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            //占位文本
            placeholder: "", //占位文本
            //Number,NumberAndTotalNumber,StaticText
            pageNumberType: obj.PageNumberStyle,
            //绑定类型名称
            bindTypeField: "pageNumberType",
            //是否可编辑
            editable: false,
            //所属组
            group: "",
        };
        if (obj.PageNumberStyle && obj.PageNumberStyle.length > 0) {
            if (obj.PageNumberStyle === "NumberAndTotalNumber") {
                newJson.result.property.placeholder = "88/88";
            }
            else if (obj.PageNumberStyle === "Number") {
                newJson.result.property.placeholder = "88";
            }
            else {
                newJson.result.property.placeholder = obj.Text;
            }
        }
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        }
    }
	return newJson;
}

/* datetime */
load.datetime = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = datetime.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            verticalAlignment: load.direction(2, obj.VerticalAlignment),
            width: tool.ptToMM(obj.LineWidth) ? tool.ptToMM(obj.LineWidth) : 30,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        var dateFormatStr = load.dateFormat(obj.DateTimeFormat);
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly,
            //数据源，需要用到则赋值，无需则为空数组
            option: [{value: '', label: ''}],
            //所属组
            group: "",
            //占位文本
            placeholder: tool.dateFormat(Date.now(), dateFormatStr),
            //是否默认当前时间
            realTime: obj.IsRealTime,
            //展示样式
            displayFormat: dateFormatStr,
            //当格式为"yyyy-MM-dd hh:mm" "yyyy年MM月dd日 hh:mm"两种时，为true
            enable: !obj.ShowEnabled,

        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        }
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
	    return newJson;
    }
}

/* divider */
load.divider = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = divider.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            //线条类型
            borderStyle: load.dividerStyle(obj.BorderStyle),
            borderColor: tool.rgbaToHex(obj.Stroke).hex,
            //粗细
            borderWeight: obj.Thickness,
            borderWidth: tool.ptToMM(obj.Width)//长度 单位mm
        };
        newJson.result.property = {
            //是否可编辑
            editable: false,
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        }
    }
	return newJson;
}

/* image */
load.image = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = image.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            width: tool.ptToMM(obj.Width),//单位%
            height: tool.ptToMM(obj.Height)
        };
        newJson.result.property = {
            imageFile: "data:image/png;base64," + obj.Source
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
    }
	return newJson;
}

/* space */
load.space = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = space.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            width: tool.ptToMM(obj.Width),//单位%
        };
        newJson.result.property = {
            bindId: "",
            //绑定类型
            bindType: "",
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: "",
            isDefault: true,
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        }
    }
	return newJson;
}

/* textarea */
load.textarea = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = textarea.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            verticalAlignment: load.direction(2, obj.VerticalAlignment),
            // horizontalAlignment: "Left",
            // verticalAlignment: "Top",
            width: tool.ptToMM(obj.LineWidth) ? tool.ptToMM(obj.LineWidth) : 30,
            height: tool.ptToMM(10),
            //行数
            rows: 5
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
			//功能标签
			featureTag: obj.FeatureTag,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            //占位文本
            placeholder: obj.Placeholder ? obj.Placeholder : "多行文本",
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly,
            //数据源，需要用到则赋值，无需则为空数组
            option: [{value: '', label: ''}],
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
		newJson.result.property.featureTag = obj.FeatureTag;
    }
	return newJson;
}

/* ultrasoundImage */
load.ultrasoundImage = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = ultrasoundImage.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            width: tool.ptToMM(obj.Width) ? tool.ptToMM(obj.Width) : 30,
            height: tool.ptToMM(obj.Height),
            //是否边框
            border: obj.HasBorder,
            //是否背景透明
            backgroundShadow: obj.TransparentBackground,
        };
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            value: "img/DefaultUltrasonicImage2.png",
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
    }
	return newJson
}

/* ultrasoundImageList */
load.ultrasoundImageList = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = ultrasoundImageList.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            //每页列数
            columnNumPerPage: obj.Column,
            //每页行数
            rowNumPerPage: obj.Row,
            maxColumnPerPage: 5,
            maxRowPerPage: 5,
            showImageBorder: obj.HasImageBorder,
            backgroundShadow: obj.TransparentBackground,
            showImageInterval: obj.HasGap,
        };
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        }
        newJson.result.tasks = ultrasoundImageList.addPropContent(obj.Row, obj.Column, 5, 5, newJson.id, newJson.name, false, false, newJson.result.property.bindType, newJson.result.property.bindField);
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
    }
	return newJson
}

/* checkbox */
load.checkbox = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = checkbox.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            verticalAlignment: load.direction(2, obj.VerticalAlignment),
            width: tool.ptToMM(obj.LineWidth) ? tool.ptToMM(obj.LineWidth) : 30,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
			//功能标签
			featureTag: obj.FeatureTag,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            arrangement: obj.Arrangement ? obj.Arrangement : true,
            //占位文本
            placeholder: obj.Placeholder ? obj.Placeholder : obj.Items[0],
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly,
            //数据源，需要用到则赋值，无需则为空数组
            option: [{value: '', label: ''}],
            //多选
            multiple: false,
             //当前数据源类型,这里的名称一定要
            dataSourceType: { field: 'dataSourceType', value: '0'},
            //动态数据源
            dynamicDataSource: {api: api, methodString: "template.findContentConfigAsync"},
            //数据源，需要用到则赋值，无需则为空数组
            staticOptions: obj.Items,
            //动态数据数据源
            dynamicOptions: ['动态选项1','动态选项2', '动态选项3', '动态其他'],
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
		newJson.result.property.featureTag = obj.FeatureTag;
    }
	return newJson;
}

/* checkboxV */
load.checkboxV = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = checkbox.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            verticalAlignment: load.direction(2, obj.VerticalAlignment),
            width: tool.ptToMM(obj.LineWidth) ? tool.ptToMM(obj.LineWidth) : 30,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            arrangement: obj.Arrangement ? obj.Arrangement : false,
            //占位文本
            placeholder: obj.Placeholder ? obj.Placeholder : obj.Items[0],
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly,
            //数据源，需要用到则赋值，无需则为空数组
            option: [{value: '', label: ''}],
            //多选
            multiple: false,
             //当前数据源类型,这里的名称一定要
            dataSourceType: { field: 'dataSourceType', value: '0'},
            //动态数据源
            dynamicDataSource: {api: api, methodString: "template.findContentConfigAsync"},
            //数据源，需要用到则赋值，无需则为空数组
            staticOptions: obj.Items,
            //动态数据数据源
            dynamicOptions: ['动态选项1','动态选项2', '动态选项3', '动态其他'],
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
    }
	return newJson;
}

/* radio */
load.radio = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = radio.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            verticalAlignment: load.direction(2, obj.VerticalAlignment),
            width: tool.ptToMM(obj.LineWidth) ? tool.ptToMM(obj.LineWidth) : 30,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
			//功能标签
			featureTag: obj.FeatureTag,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            arrangement: obj.Arrangement ? obj.Arrangement : true,
            //占位文本
            placeholder: obj.Placeholder ? obj.Placeholder : obj.Items[0],
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly,
            //数据源，需要用到则赋值，无需则为空数组
            option: [{value: '', label: ''}],
            //多选
            multiple: false,
             //当前数据源类型,这里的名称一定要
            dataSourceType: { field: 'dataSourceType', value: '0'},
            //动态数据源
            dynamicDataSource: {api: api, methodString: "template.findContentConfigAsync"},
            //数据源，需要用到则赋值，无需则为空数组
            staticOptions: obj.Items,
            //动态数据数据源
            dynamicOptions: ['动态选项1','动态选项2', '动态选项3', '动态其他'],
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
		newJson.result.property.featureTag = obj.FeatureTag;
    }
	return newJson;
}

/* select */
load.select = function (obj, parentId, parentName) {
	var newJson = null;
    if (obj)
    {
        newJson = select.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.pattern = {
            fontName: obj.FontName,
            fontSize: obj.FontSize,
            fontWeight: 400,
            fontItalic: false,
            fontUnderLine: false,
            fontColor: tool.rgbaToHex(obj.FontColor).hex,
            // horizontalAlignment: "Left",
            // verticalAlignment: "Middle",
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            verticalAlignment: load.direction(2, obj.VerticalAlignment),
            width: tool.ptToMM(obj.LineWidth) ? tool.ptToMM(obj.LineWidth) : 30,
            height: tool.ptToMM(10)
        };
        if (obj.FontStyles && obj.FontStyles.length > 0)
        {
            obj.FontStyles.some(c => {
                if (c === "Bold")
                {
                    newJson.result.pattern.fontWeight = 800; 
                }
            });
        }
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            //占位文本
            placeholder: obj.Placeholder ? obj.Placeholder : obj.Items[0],
            //是否必填
            required: obj.Required ? obj.Required : false,
            //是否可编辑
            editable: !obj.IsReadOnly,
            //数据源，需要用到则赋值，无需则为空数组
            option: [{value: '', label: ''}],
            //多选
            multiple: false,
             //当前数据源类型,这里的名称一定要
            dataSourceType: { field: 'dataSourceType', value: '0'},
            //动态数据源
            dynamicDataSource: {api: api, methodString: "template.findContentConfigAsync"},
            //数据源，需要用到则赋值，无需则为空数组
            staticOptions: obj.Items,
            //动态数据数据源
            dynamicOptions: ['动态选项1','动态选项2', '动态选项3', '动态其他'],
            //所属组
            group: "",
        };
		newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
		newJson.result.property.featureTag = obj.FeatureTag;
    }
	return newJson;
}

/* header */
load.header = function (obj) {
    var newJson = [];
    if (obj.Header && obj.Header.length > 0)
    {
        obj.Header.forEach(c => {
            if (c.ElementType.Name === "RTTable") {
                var headerTb = load.table(c, true);
                newJson.push(headerTb);
            }
            else if (c.ElementType.Name === "Paragraph") {
                var headerGrid = load.grid(c);
                newJson.push(headerGrid);
            }
        });
    }
    return newJson;
}

/* footer */
load.footer = function (obj) {
    var newJson = [];
    if (obj.Footer && obj.Footer.length > 0) {
        obj.Footer.forEach(f => {
            if (f.ElementType.Name === "RTTable") {
                var footerTable = load.table(f, true);
                newJson.push(footerTable);
            }
            else if (f.ElementType.Name === "Paragraph") {
                var footerGrid = load.grid(f);
                newJson.push(footerGrid);
            }
        });
    }
    return newJson;
}

/* table */
load.table = function (obj, isAvgCellWidth) {
	var newJson = null;
    if (obj)
    {
        newJson = table.initData(true);
        newJson.result.base = {
            rowCount: obj.RowDefinitions.length,
            columnCount: obj.ColumnDefinitions.length,
            columnWidth: [],
            rowHeight: []
        };
        obj.ColumnDefinitions.forEach(c => {
            newJson.result.base.columnWidth.push(tool.ptToMM(c.Width));
        });
        obj.RowDefinitions.forEach(c => {
            var temp = {
                height: tool.ptToMM(c.Height),
                type: c.Type,
                minHeight: tool.ptToMM(c.MinHeight),
            };
            newJson.result.base.rowHeight.push(temp);
        });
        var cellList = [];
        if (obj.Cells && obj.Cells.length > 0) {
            for (var m = 0; m < obj.Cells.length; m++) {
                var firstEntity = obj.Cells[m];
                var cellInfo = tableCell.initData(newJson.id, (firstEntity.Row + 1), (firstEntity.Column + 1), newJson.name);
                m++;
                var secondEntity = obj.Cells[m];
                cellInfo.result.base = {
                    rowStartIndex: (firstEntity.Row + 1),
                    colStartIndex: (firstEntity.Column + 1),
                    rowEndIndex: (firstEntity.Row + 1) + firstEntity.RowSpan,
                    colEndIndex: (firstEntity.Column + 1) + firstEntity.ColumnSpan,
                    rowSpan: firstEntity.RowSpan,
                    colSpan: firstEntity.ColumnSpan
                };
                //样式，每个组件可根据自身特点进行增减
                var borderStyle = {};
                if (secondEntity.Borders.Top.BorderStyle === 'None') {
                    borderStyle = secondEntity.Borders.Right;
                }
                else {
                    borderStyle = secondEntity.Borders.Top;
                }
                cellInfo.result.pattern = {
                    //Left,Right,Center,Bothends
                    horizontalAlignment: load.direction(1, secondEntity.HorizontalAlignment),
                    verticalAlignment: load.direction(2, secondEntity.VerticalAlignment),
                    cellBorderStyle: load.dividerStyle(borderStyle.BorderStyle),
                    cellBorderColor: tool.rgbaToHex(borderStyle.Color).hex,
                    cellBorderWeight: borderStyle.Thickness,
                    cellBackgroundColor: secondEntity.Background ? tool.rgbaToHex(secondEntity.Background).hex : "",
                    showCellBorder: borderStyle.BorderStyle === "None" ? false : true,
                };
                //属性，每个组件可根据自身特点进行增减
                cellInfo.result.property = {
                    cellColumnWidth: newJson.result.base.columnWidth[firstEntity.Column],//单位mm
                    cellColumnWidhtType: 1,
                    cellRowHeight: 0,
                    cellRowHeightType: 0,
                    mergeBottomCell: false,
                    mergeRightCell: false,
                    insertTopCell: false,
                    insertBottomCell: false,
                    insertLeftCell: false,
                    insertRightCell: false,
                    deleteRow: false,
                    deleteColumn: false,
                    spliceCell: false
                };
                if (secondEntity.HeightType === "FixedValue") {
                    //固定值
                    cellInfo.result.property.cellRowHeight = newJson.result.base.rowHeight[firstEntity.Row].height;
                    cellInfo.result.property.cellRowHeightType = 1;
                }
                else {
                    cellInfo.result.property.cellRowHeight = newJson.result.base.rowHeight[firstEntity.Row].minHeight;
                    cellInfo.result.property.cellRowHeightType = 0;
                }
                if (secondEntity.Blocks && secondEntity.Blocks.length > 0) {
                    for (var bi = 0; bi < secondEntity.Blocks.length; bi++) 
                    {
                        if (!secondEntity.Blocks[bi])
                        {
                            continue;
                        }
                        if (secondEntity.Blocks[bi].ElementType.Name === "Paragraph") {
                            var elements = secondEntity.Blocks[bi].Elements;
                            if (elements && elements.length > 0) {
                                elements.forEach(item => {
                                    var switchTypeStr = load.typeTransfer(item);
                                    var tempInfo = load.switchType(switchTypeStr, item, cellInfo.id, cellInfo.name);
                                    cellInfo.result.tasks.push(tempInfo);
                                });
                                cellInfo.result.pattern.horizontalAlignment = load.direction(1, secondEntity.Blocks[bi].HorizontalAlignment);
                            }
                        }
                        else if (secondEntity.Blocks[bi].ElementType.Name === "ImageList") {
                            var switchTypeStr2 = load.typeTransfer(secondEntity.Blocks[bi]);
                            var tempInfo2 = load.switchType(switchTypeStr2, secondEntity.Blocks[bi], cellInfo.id, cellInfo.name);
                            cellInfo.result.tasks.push(tempInfo2);
                            cellInfo.result.pattern.horizontalAlignment = load.direction(1, secondEntity.Blocks[bi].HorizontalAlignment);
                        }
                        else if (secondEntity.Blocks[bi].ElementType.Name === "RTTable") {
                            var cells = secondEntity.Blocks[bi].Cells;
                            if (cells && cells.length > 0) {
                                for (var n = 0; n < cells.length; n++) {
                                    n++;
                                    var cellBlocks = cells[n].Blocks;
                                    if (cellBlocks && cellBlocks.length > 0) {
                                        for (var ci = 0; ci < cellBlocks.length; ci++) 
                                        {
                                            if (!cellBlocks[ci]) 
                                            {
                                                continue;
                                            }
                                            if (cellBlocks[ci].ElementType.Name === "Paragraph") {
                                                if (cellBlocks[ci].Elements && cellBlocks[ci].Elements.length > 0) {
                                                    cellBlocks[ci].Elements.forEach(childItem => {
                                                        var switchTypeStr1 = load.typeTransfer(childItem);
                                                        var tempInfo1 = load.switchType(switchTypeStr1, childItem, cellInfo.id, cellInfo.name);
                                                        cellInfo.result.tasks.push(tempInfo1);
                                                    });
                                                }
                                                cellInfo.result.pattern.horizontalAlignment = load.direction(1, cellBlocks[ci].HorizontalAlignment);
                                            }
                                            else if (cellBlocks[ci].ElementType.Name === "ImageList") {
                                                var switchTypeStr3 = load.typeTransfer(cellBlocks[ci]);
                                                var tempInfo3 = load.switchType(switchTypeStr3, cellBlocks[ci], cellInfo.id, cellInfo.name);
                                                cellInfo.result.tasks.push(tempInfo3);
                                                cellInfo.result.pattern.horizontalAlignment = load.direction(1, cellBlocks[ci].HorizontalAlignment);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                cellList.push(cellInfo);
            }
        }
        newJson.result.tasks = cellList;//this.generalCells(tableId, defaultRows, defaultCols, tName);
        //样式，每个组件可根据自身特点进行增减
        newJson.result.pattern = {
            //Left,Right,Center,Bothends
            horizontalAlignment: load.direction(1, obj.HorizontalAlignment),
            borderStyle: obj.BorderStyle ? load.dividerStyle(obj.BorderStyle) : "Solid",
            borderColor: obj.BorderColor ? tool.rgbaToHex(obj.BorderColor).hex : "#747474",
            borderWeight: obj.BorderWeight ? obj.BorderWeight : 1,
            backgroundColor:  obj.BackgroundColor ? tool.rgbaToHex(obj.BackgroundColor).hex : "",
            showTableBorder:  obj.ShowTableBorder ? obj.ShowTableBorder : false,
            avgColumnWidth: obj.IsAverageColumnWidth,
            allowSpanPage: obj.AllowBreakAcrossPages,
            showTableCellBorder: obj.ShowTableCellBorder ? obj.ShowTableCellBorder : true,//?????todo 确认是否会影响cell的显示
            showTableCellMargin: obj.ShowTableCellMargin ? obj.ShowTableCellMargin : false
        };
        if (isAvgCellWidth) {
            //newJson.result.pattern.avgColumnWidth = true;
        }
        //属性，每个组件可根据自身特点进行增减
        newJson.result.property = {
            bindId: "",
            //绑定类型
            bindType: "",
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: "",
            isDefault: true,
            isHidden: obj.AutoHide
        };
        //位置坐标
        newJson.result.margin = {
            sort: 0,
            //0-表示absolute;1-relative
            position: 0,
            //如果采用相对定位，则需要填写上一个组件的组件id
            previousId:"",
            top: 0.0,
            bottom: 0.0,
            left: 0.0,
            right: 0.0,
        };
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
    }
    return newJson;
}

/* scanTable */
load.scanTable = function (obj) {
	var newJson = null;
    if (obj)
    {
        newJson = scanTable.initData(true);
        newJson.result.base = {
            rowCount: 4,
            columnCount: 2,
            rowNum: 1,
            colNum: obj.Column,
            columnWidth:[
                //{columnStartIndex, type:最小值/固定值,width}
            ],
            rowHeight: [
                //{rowStartIndex, type:最小值/固定值,height}
            ],
            gridWidth: tool.ptToMM(obj.ImageWidth),
            gridHeight: tool.ptToMM(obj.ImageHeight),
            colNumPerRow: 2,
            totalCount: 4
        };
        newJson.result.pattern = {
            //Left,Right,Center,Bothends
            horizontalAlignment:"Center",
            borderStyle: "Solid",
            borderColor: "#747474",
            borderWeight: 0,
            backgroundColor: "",
            showTableBorder: true,
            avgColumnWidth: true,
            allowSpanPage: true,
            showTableCellBorder: false,
            showTableCellMargin: false,
            showImageInterval: obj.HasGap,
            showImageBorder: obj.HasImageBorder,
            backgroundShadow: obj.TransparentBackground,
        };
        //属性，每个组件可根据自身特点进行增减
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            showImageAndDesc : false,
            //所属组
            tempStatus: false,
        };
        //位置坐标
        newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        newJson.result.tasks = scanTable.addPropContent(newJson.id, 1, obj.Column, newJson.name);
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
    }
    return newJson;
}

/* imageList */
load.imageList = function (obj, parentId, parentName)  {
	var newJson = null;
    if (obj)
    {
        newJson = imageList.initData(true);
        if (obj.Id && obj.Id.length > 0) 
        {
            newJson.id = obj.Id;
        }
        newJson.result.parentId = parentId;
        newJson.result.parentName = parentName;
        newJson.result.base = {
            rowNum: 1,
            colNum: obj.Column,
            gridWidth: tool.ptToMM(obj.ImageWidth),
            gridHeight: tool.ptToMM(obj.ImageHeight)
        };
        newJson.result.pattern = {
            //Left,Right,Center,Bothends
            horizontalAlignment:"Center",
            showImageInterval: obj.HasGap,
            showImageBorder: obj.HasImageBorder,
            backgroundShadow: obj.TransparentBackground,
        };
        //属性，每个组件可根据自身特点进行增减
        newJson.result.property = {
            bindId: obj.Tag.Id,
            //绑定类型
            bindType: obj.Tag.ElementTagType,
            //绑定类型名称
            bindTypeField: "bindType",
            //绑定内容
            bindField: obj.Tag.Name,
            isDefault: obj.Tag.IsDefault,
            //所属组
            tempStatus: false,
            valueList: []
        };
        //位置坐标
        newJson.result.margin = {
            sort: obj.Index,
            position: 0,
            previousId: "",
            top: tool.ptToMM(obj.Margin.Top),
            bottom: tool.ptToMM(obj.Margin.Bottom),
            left: tool.ptToMM(obj.Margin.Left),
            right: tool.ptToMM(obj.Margin.Right)
        };
        if (obj.Column > 0) {
            for (var k = 0; k < obj.Column; k++) {
                newJson.result.property.valueList.push("img/DefaultUltrasonicImage2.png");
            }
        }
        if (obj.MeasureTag != null) {
            newJson.result.property.measureItem = {
                AvailableMethods: obj.MeasureTag.AvailableMethods,
                BaseType: obj.MeasureTag.BaseType,
                CalculationId: obj.MeasureTag.CalculationId,
                MatchId: obj.MeasureTag.MatchId,
                Method: obj.MeasureTag.Method,
                Mode: obj.MeasureTag.Mode,
                Output: obj.MeasureTag.Output,
                OutputV2: obj.MeasureTag.OutputV2,
                Unit: obj.MeasureTag.Unit,
                UserId: obj.MeasureTag.UserId,
            };
        }
    }
    return newJson;
}

//类型转换
load.typeTransfer = function (data) {
    var result = null;
    if (data.ElementType.Name === "InputText") {
        if (data.TextWrap) {
            //表示文本域
            result = "textarea";
        }
        else {
            result = "input";
        }
    }
    else if (data.ElementType.Name === "StaticText") {
        result = "label";
    }
    else if (data.ElementType.Name === "DateTime") {
        result = "datetime";
    }
    else if (data.ElementType.Name === "Line") {
        result = "divider";
    }
    else if (data.ElementType.Name === "StaticImage") {
        result = "image";
    }
    else if (data.ElementType.Name === "Space") {
        result = "space";
    }
    else if (data.ElementType.Name === "ImageList") {
        result = "imageList";
    }
    else if (data.ElementType.Name === "InputImage") {
        result = "ultrasoundImage";
    }
    else if (data.ElementType.Name === "PageNumber") {
        result = "pageNumber";
    }
    else if (data.ElementType.Name === "MultiSelected") {
        if (data.DisplayStyle === "OnlyShowSelectedItem") {
            result = "select";
        }
        else {
            result = "checkbox";
        }
    }
    else if (data.ElementType.Name === "SingleSelected") {
        if (data.DisplayStyle === "OnlyShowSelectedItem") {
            result = "select";
        }
        else {
            result = "radio";
        }
    }
    else if (data.ElementType.Name === "AtlasElement") {
        result = "ultrasoundImageList";
    }
    else if (data.ElementType.Name === "MultiSelectedVertical") {
        result = "checkboxV";
    }
    return result;
}

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

/* loadNewModuleJson */
load.loadNewModuleJson = function (obj) {
	var newJson = [];
    if (obj.Blocks && obj.Blocks.length > 0)
    {
        obj.Blocks.forEach(module =>
        {
            if (module.ElementType.Name === "AtlasElement")
            {
                var returnImageList = load.ultrasoundImageList(module);
                newJson.push(returnImageList);
            }
            else if (module.ElementType.Name === "ImageList") {
                var newGrid = grid.initData(true);
                var newImageList = load.imageList(module);
                if (newGrid.result && newGrid.result.tasks)
                {
                    newGrid.result.tasks.push(newImageList);
                }
                newJson.push(newGrid);
            }
            else if (module.ElementType.Name === "Paragraph")
            {
                var returnGrid = load.grid(module);
                if (returnGrid) {
                    newJson.push(returnGrid);
                }
            }
            else if (module.ElementType.Name === "RTTable")
            {
                var returnTable = load.table(module);
                newJson.push(returnTable);
            }
        });
    }
	return newJson;
}

/* 读取注释和翻译 */
load.readLanguageTransfer = function (obj) {
    load.labelContentList.forEach(d => {
        if (obj.CustomizeComments && obj.CustomizeComments.length > 0) {
            if (obj.CustomizeComments.some(c => c === d.keyword)) {
                d.scan = true;
            }
            if (obj.CustomizeReportComments.some(c => c === d.keyword)) {
                d.seport = true;
            }
            if (d.languageDatas && d.languageDatas.length > 0) {
                d.languageDatas.forEach(n => {
                    n.value = obj.CustomizeTranslation[n.key][d.keyword]
                });
            }
        }
    });
}

/* 读取自定义计算项 */
load.customCalculationList = function (obj) {
    load.customCalculations = obj.CustomizeCalculations;
}

/* 读取数据 */
load.oldJsonTransferNewJson = function (obj) {
    load.labelContentList = [];
    load.customCalculations = [];
    var pageInfo = load.page(obj);
    var moduelList = load.loadNewModuleJson(obj);
    var headerList = load.header(obj);
    var footerList = load.footer(obj);
    load.readLanguageTransfer(obj);
    load.customCalculationList(obj);
    var templateContent = {
        currentPageInfo: pageInfo,
        currentModuelList: moduelList,
        labelContentList: load.labelContentList,
        currentHeaderList: headerList,
        currentFooterList: footerList,
        customCalculations: load.customCalculations
    };
    return templateContent;
}

/* 方向转换 */
load.direction = function (type, value) {
    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 === "Stretch")
        {
            res = "Left"
        }
        else if (value === "Bothends")
        {
            res = "Bothends"
        }
        else
        {
            res = "Left"
        }
    }
    else if (type === 2)//表示垂直方向
    {
        if (value === "Top")
        {
            res = "Top";
        }
        else if (value === "Center")
        {
            res = "Middle";
        }
        else if (value === "Bottom")
        {
            res = "Bottom";
        }
        else if (value === "Stretch")
        {
            res = "Bottom"
        }
        else
        {
            res = "Top";
        }
    }
    return res;
}

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

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

export default load
