import common from "@/utils/common"

const label = 'reportDesigner.Image';
const name = 'image';
const category = 0;//0-表示默认基础组件，1-表示报告组件；2-布局组件
export default {
    initData: function(flag, img){
        //组件一级对象
        var obj = {
            icon: 'icon-upload',
            label,
            id: common.guid(),
            name,
            category: category,
            disabledMove: false,
            //二级对象,用来封装属性和样式
            data: {},
            result: {}
        };
        if (flag)
        {
            obj.data = this.props();
            obj.result = this.finals(img);
        }
        return obj;
    },
    props: function() {
        return {
            // 规则：type：表示标签类型
            //     field:表示绑定值
            //     title:表示显示label
            //     require:表示是否需要验证必填项
            //     value:表示设置的默认值
            //     rules:表示验证规则，同elementplus验证规则一致
            //     dataSource:动态绑定数据源
            //     labelWidth:label宽度
            //       
            // //特殊样式
            // specialStyle: [ 
            //     {icon: "", title: "左对齐", type: "left", sort: 10, value: false, group: "horizontalAlignment"},
            //     {icon: "", title: "居中", type: "center", sort: 11, value: false, group: "horizontalAlignment"},
            //     {icon: "", title: "右对齐", type: "right", sort: 12, value: false, group: "horizontalAlignment"},
            //     {icon: "", title: "两端对齐", type: "bothends", sort: 13, value: false, group: "horizontalAlignment"}
            // ],
            //样式 
            pattern: [
                {
                    type: 'input', field: 'width', title: 'reportDesigner.TextLengthPerLine', require: true, value: '168', unit: "mm",
                    rules: [{required: true, message: "Please input module width", trigger: "blur"}]
                }, 
                {
                    type: 'input', field: 'height', title: 'reportDesigner.Height', require: true, value: '120', unit: "mm",
                    rules: [{required: true, message: "Please input module width", trigger: "blur"}]
                }
            ],
            //属性
            property: {
                formatSet:[                
                    {type: 'elUpload', field: 'imageFile', title: 'reportDesigner.ChangeImage', require: false, value: '', unit: "", rules:[], labelWidth:"0px"}, 
                ]
            }
        }
    },
    finals: function(img){
        var defaultImg = "";
        if (img && img.length > 0) {
            defaultImg = img
        }
        else {
            defaultImg = "data:image/png;base64,[encoded data, 700456 characters]"
        }
        return {
            //父组件id
            parentId: "",
            parentName: "",
            offsetWidth: 0,
            offsetHeight: 0,
            //占位符
            space: "",
            //样式，每个组件可根据自身特点进行增减
            pattern: {
                width: 168,//单位%
                height: 120
            },
            //属性，每个组件可根据自身特点进行增减
            property: { 
                bindId: "",
                //绑定类型
                bindType: "",
                //绑定类型名称
                bindTypeField: "bindType",
                isDefault: false,
                //绑定内容
                bindField: "",
                //默认值
                //value: "img/DefaultImage.png",现在显示base64图片
                imageFile: defaultImg,
                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,
            }
        }
    }
}