
import common from "@/utils/common"
import api from "@/api"
import i18n from '@/locales'

const label = 'reportDesigner.imageList';
const name = 'imageList';
const category = 0;//0-表示默认基础组件，1-表示报告组件；2-布局组件
export default {
    initData: function(flag, parentId, parentName){
        //组件一级对象
        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(parentId, parentName);
        }
        return obj;
    },
    props: function() {
        return {
            pattern: [
                {
                    type: 'input', field: 'colNum', title: 'reportDesigner.imageList', require: true, value: '2', unit: "reportDesigner.Num", labelWidth:"110px",
                    rules: [{required: true, message: i18n.global.tc("reportDesigner.numberRequireMessage"), trigger: "blur"}],
                    children: [
                        { num: 1, width: 88, height: 53.7 },
                        { num: 2, width: 83, height: 53 },
                        { num: 3, width: 55.6, height: 35.1 },
                        { num: 4, width: 41.5, height: 26.1 },
                    ]
                }, 
                // {
                //     type: 'input', field: 'gridWidth', title: '宽度', require: true, value: '83', unit: "mm"
                // }, 
                // {
                //     type: 'input', field: 'gridHeight', title: '高度', require: true, value: '53', unit: "mm"
                // }, 
                {
                    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: i18n.global.tc("reportDesigner.ContentRequireMessage"), trigger: "blur"}]
                    }, 
                ]
            }
        }
    },
    addPropContent: function (defaultCols) {
        var list = [];
        for (var j = 1; j <= defaultCols; j++) {
            //添加内容
            var temp = "img/DefaultUltrasonicImage2.png";
            list.push(temp);
        }
        return list;
    },    
    getWidthHeight: function (defaultCols) {
        var perWidth = 0;
        var perHeight = 0;
        switch (defaultCols) {
            case 1:
                perWidth = 88;
                perHeight = 53.7;
                break;
            case 2:
                perWidth = 84;
                perHeight = 53.5;
                break;
            case 3:
                perWidth = 55.6;
                perHeight = 35.1;
                break;
            case 4:
                perWidth = 41.5;
                perHeight = 26.1;
                break;
            default:
                break;
        }
        return { perWidth, perHeight };
    },    
    finals: function(parentId, parentName){
        var pId = "";
        var pName = ""; 
        if (parentId && parentId.length > 0) {
            pId = parentId;
        }
        if (parentName && parentName.length > 0) {
            pName = parentName;
        }
        return {
            base: {
                rowNum: 1,
                colNum: 2,
                gridWidth: 83,
                gridHeight: 53,
            },
            offsetWidth: 0,
            offsetHeight: 0,
            //父组件id
            parentId: pId,
            parentName: pName,
            //占位符
            space: "",
            //样式，每个组件可根据自身特点进行增减
            pattern: {
                //Left,Right,Center,Bothends
                horizontalAlignment:"Center",
                showImageInterval: false,
                showImageBorder: false,
                backgroundShadow: true,
            },
            //属性，每个组件可根据自身特点进行增减
            property: {
                bindId: "9fbbaa61-a91d-4399-a3f4-df29117d2d59",
                //绑定类型
                bindType: "General",
                //绑定类型名称
                bindTypeField: "bindType",
                //绑定内容
                bindField: "ReportImages",
                isDefault: false,
                //默认值
                //value: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
                valueList: ["img/DefaultUltrasonicImage2.png", "img/DefaultUltrasonicImage2.png"],
                //是否必填
                required: false,
                //是否可编辑
                editable: 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,
            }
        }
    }
}