
import common from "@/utils/common"
import api from "@/api"
import ultrasoundImageInfo from '@/config/designer/ultrasoundImage';
import pageInfo from '@/config/designer/page';
import tool from '@/utils/tool';

const label = 'reportDesigner.ultrasoundImageList';
const name = 'ultrasoundImageList';
const category = 2;//0-表示默认基础组件，1-表示报告组件；2-布局组件
export default {
    initData: function (flag) {
        var guid = common.guid();
        //组件一级对象
        var obj = {
            icon: 'icon-space',
            label,
            id: guid,
            name,
            category: category,
            disabledMove: false,
            displayContentList: [
            {
                rowIndex: 1,
                offsetWidth: 0,
                offsetHeight: 710,//4行
                moduleIdList: []
            }],
            //二级对象,用来封装属性和样式
            data: {},
            result: {}
        };
        if (flag) {
            obj.data = this.props();
            obj.result = this.finals(guid, name);
        }
        return obj;
    },
    addPropContent: function (rowNum, colNum, maxColNum, maxRowNum, guid, name, border, backgroundShadow, bindType, bindField) {
        var list = [];
        if (colNum > maxColNum) {
            colNum = maxColNum
        }
        if (rowNum > maxRowNum) {
            rowNum = maxRowNum
        }
        var width = tool.mmToPx(pageInfo.defaultPageType.width) - tool.mmToPx(pageInfo.defaultPagePadding.left) - tool.mmToPx(pageInfo.defaultPagePadding.right) - 25;
        //var height = pageInfo.defaultPageType.height - tool.mmToPx(pageInfo.defaultPagePadding.top) - tool.mmToPx(pageInfo.defaultPagePadding.bottom);
        var perWidth = parseFloat(tool.pxToMM(parseInt(width / colNum)- 5));
        //var perHeight = parseFloat(tool.pxToMM(parseInt(height / rowNum) - 5));
        var perHeight = 45.38;
        for (var i = 0; i < rowNum; i++ ) {
            for (var j = 0; j < colNum; j++ ) { 
                //添加内容
                var temp = ultrasoundImageInfo.initData(true, guid, name);
                temp.result.pattern.horizontalAlignment = "Center";
                temp.result.pattern.width = perWidth;
                temp.result.pattern.height = perHeight;
                temp.result.property.bindType = bindType;
                temp.result.property.bindField = bindField;
                temp.result.pattern.border = border;
                temp.result.pattern.backgroundShadow = backgroundShadow;
                list.push(temp);
            }
        }
        return list;
    },
    props: function () {
        return {
            //样式
            pattern: [
                {
                    type: 'input', field: 'columnNumPerPage', title: 'reportDesigner.ColumnNumbersPerPage', require: true, value: '2', unit: "reportDesigner.Columns", labelWidth:"110px",
                    rules: [{required: true, message: "Please input module width", trigger: "blur"}]
                }, 
                {
                    type: 'input', field: 'rowNumPerPage', title: 'reportDesigner.RowNumbersPerPage', require: true, value: '4', unit: "reportDesigner.Rows", labelWidth:"110px",
                    rules: [{required: true, message: "Please input module width", trigger: "blur"}]
                }, 
                {
                    type: 'switch', field: 'showImageBorder', title: 'reportDesigner.HasBorder', require: false, value: '1', unit: "", rules:[], labelWidth:"270px"
                }, 
                {
                    type: 'switch', field: 'backgroundShadow', title: 'reportDesigner.TransparentBackground', require: false, value: '1', unit: "", rules:[], labelWidth:"270px"
                }, 
                {
                    type: 'switch', field: 'showImageInterval', title: 'reportDesigner.HasGap', require: false, value: '1', unit: "", rules:[], labelWidth:"270px"
                }, 
            ],
            //属性
            property: {
                contentSet: [
                    {
                        type: 'select', field: 'bindType', title: 'reportDesigner.bindType', require: false, value: '', unit: "", rules:[], 
                        dataSource: api.template.findContentConfigAsync, 
                        tiedDataSource: api.template.findContentConfigAsync,
                        tiedBack: "bindField", changeStatus: true
                    }, 
                    {
                        type: 'elSelect', field: 'bindField', title: 'reportDesigner.bindField', require: true, value: '', unit: "",
                        rules: [{required: true, message: "Please select bind content", trigger: "blur"}]
                    }, 
                ],
            }
        }
    },
    finals: function (guid, name) {
        var colNum = 2;
        var rowNum = 4;
        var maxColNum = 5;
        var maxRowNum = 5;
        return {
            //父组件id
            parentId: "",
            parentName: "",
            tasks: this.addPropContent(rowNum, colNum, maxColNum, maxRowNum, guid, name, false, false, 'General', 'ReportImages'),
            //占位符
            space: "",
            offsetWidth: 0,
            offsetHeight: 695,
            //样式，每个组件可根据自身特点进行增减
            pattern: {
                //每页列数
                columnNumPerPage: colNum,
                //每页行数
                rowNumPerPage: rowNum,
                maxColumnPerPage: maxColNum,
                maxRowPerPage: maxRowNum,
                showImageBorder: false,
                backgroundShadow: false,
                showImageInterval: false,
            },
            //属性，每个组件可根据自身特点进行增减
            property: {
                bindId: "9fbbaa61-a91d-4399-a3f4-df29117d2d59",
                //绑定类型
                bindType: "General",
                //绑定类型名称
                bindTypeField: "bindType",
                //绑定内容
                bindField: "ReportImages",
                isDefault: false,
                measureItem: {
                    AvailableMethods: [],
                    BaseType: "",
                    CalculationId: "",
                    MatchId: "",
                    Method: "",
                    Mode: "",
                    Output: "",
                    OutputV2: "",
                    Unit: "",
                    UserId: ""
                }
            },
            //位置坐标
            margin: {
                sort: 0,
                //0-表示absolute;1-relative
                position: 0,
                //如果采用相对定位，则需要填写上一个组件的组件id
                previousId: "",
                top: 0.0,
                bottom: 0.0,
                left: 0.0,
                right: 0.0,
            }
        }
    }
}