import common from "@/utils/common"
import api from "@/api"
import tableCell from '../tableCell';
import labelInfo from '@/config/designer/label';
import inputInfo from '@/config/designer/input';
import dateInfo from '@/config/designer/datetime';
import imageInfo from '@/config/designer/image';

const label = 'reportDesigner.doctorInfo';
const name = 'doctorInfo';
const category = 2;//0-表示默认基础组件，1-表示报告组件；2-布局组件
var obj;
export default {
    initData: function (flag) {
        var commonId = common.guid();
        //组件一级对象
        obj = {
            icon: 'icon-space',
            label,
            id: commonId,
            name,
            category: category,
            disabledMove: false,
            displayContentList: [],
            //二级对象,用来封装属性和样式
            data: {},
            result: {}
        };
        if (flag) {
            obj.data = this.props();
            obj.caculateCellInfo = function(defaultRows, defaultCols) {
                var columnWidthList = [];
                var rowHeightList = [];
                rowHeightList = [{height: 7.59, type: "MinValue", minHeight: 6.34 }];
                if (defaultCols > 3) {
                    columnWidthList = [46.77, 46.77, 46.77, 28.16];
                }
                else if (defaultCols > 2) {
                    columnWidthList = [56.16, 56.16, 56.16];
                }
                else if (defaultCols > 1) {
                    columnWidthList = [84.24, 84.24];
                }
                else {
                    columnWidthList = [168.48];
                }
                return { columnWidthList, rowHeightList };
            };
            obj.generalCells = function(tableId, defaultRows, defaultCols, tName, showControls) {
                var list = [];
                showControls.forEach(item => {                    
                    if (item.value) {
                        let cellTemp = tableCell.initData(tableId, 1, (list.length + 1), tName, 1, 1);
                        cellTemp.groupField = item.key;
                        obj.AddControls(item.type, cellTemp, item.key, item.title, defaultCols);
                        list.push(cellTemp);
                    }                   
                });
                return list;
            };
            obj.AddControls = function(type, cell, bindField, placeholder, defaultCols) {
                var controlWidth = 32;
                if (defaultCols > 3) {
                    controlWidth = 20;
                }
                switch (type) {
                    case "image":
                        var imgBase64 = "data:image/png;base64, ";
                        var imgPhysician = imageInfo.initData(true, imgBase64);
                        imgPhysician.result.parentId = cell.id;
                        imgPhysician.result.parentName = cell.name;
                        imgPhysician.result.pattern.width = 23;
                        imgPhysician.result.pattern.height = 8
                        imgPhysician.result.property.group = bindField;
                        imgPhysician.result.property.bindField = bindField;
                        cell.result.tasks.push(imgPhysician);
                        break;
                    case "input":
                        var hospitalNameTitle = labelInfo.initData(true);
                        hospitalNameTitle.result.parentId = cell.id;
                        hospitalNameTitle.result.parentName = cell.name;
                        hospitalNameTitle.result.pattern.horizontalAlignment = "Left";
                        hospitalNameTitle.result.pattern.verticalAlignment = "Middle";
                        hospitalNameTitle.result.pattern.width = 0;
                        hospitalNameTitle.result.property.placeholder = placeholder;
                        cell.result.tasks.push(hospitalNameTitle);

                        var inputInspectionPhysician = inputInfo.initData(true);
                        inputInspectionPhysician.result.parentId = cell.id;
                        inputInspectionPhysician.result.parentName = cell.name;
                        inputInspectionPhysician.result.pattern.horizontalAlignment = "Left";
                        inputInspectionPhysician.result.pattern.width = controlWidth;
                        inputInspectionPhysician.result.property.group = bindField;
                        inputInspectionPhysician.result.property.bindType = "General";
                        inputInspectionPhysician.result.property.bindField = bindField;
                        cell.result.tasks.push(inputInspectionPhysician);
                        break;
                    case "date":
                        var reportName = labelInfo.initData(true);
                        reportName.result.parentId = cell.id;
                        reportName.result.parentName = cell.name;
                        reportName.result.pattern.width = 0;
                        reportName.result.pattern.horizontalAlignment = "Left";
                        reportName.result.pattern.verticalAlignment = "Middle";
                        reportName.result.property.placeholder = placeholder;
                        cell.result.tasks.push(reportName);

                        var inputReportTime = dateInfo.initData(true);
                        inputReportTime.result.parentId = cell.id;
                        inputReportTime.result.parentName = cell.name;
                        inputReportTime.result.pattern.horizontalAlignment = "Left";
                        inputReportTime.result.pattern.width = controlWidth;
                        inputReportTime.result.property.group = bindField;
                        inputReportTime.result.property.bindType = "General";
                        inputReportTime.result.property.bindField = bindField;
                        cell.result.tasks.push(inputReportTime);
                        break;
                }
            }
            obj.result = this.finals(obj);
        }
        return obj;
    },
    props: function () {
        return {
            //样式
            pattern: [
                {
                    type: 'borderStyleSelect', field: 'borderStyle', title: 'reportDesigner.LineType', require: false, value: 'solid', unit: "",
                    options: [
                        { key: 'Solid', value: 'reportDesigner.solid' },
                        { key: 'Dotted', value: 'reportDesigner.dotted' },
                        { key: 'Dashed', value: 'reportDesigner.dashed' }
                    ]
                },
                {
                    type: 'colorPicker', field: 'borderColor', title: 'reportDesigner.borderColor', require: false, value: '#888', unit: ""
                },
                {
                    type: 'borderWeightSelect', field: 'borderWeight', title: 'reportDesigner.Thickness', require: false, value: 0, unit: "",
                    options: [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 3, 4.5, 6]
                },
                {
                    type: 'colorPicker', field: 'backgroundColor', title: 'reportDesigner.Fill', require: false, value: '#FFF', unit: ""
                },
                {
                    type: 'switch', field: 'showTableBorder', title: 'reportDesigner.showTableBorder', require: false, value: '0', unit: "", rules: [], labelWidth: "270px"
                },
                {
                    type: 'switch', field: 'showTableCellBorder', title: 'reportDesigner.showTableCellBorder', require: false, value: '0', unit: "", rules: [], labelWidth: "270px"
                },
                {
                    type: 'switch', field: 'avgColumnWidth', title: 'reportDesigner.AverageColumnWidth', require: false, value: '1', unit: "", rules: [], labelWidth: "270px"
                },
                {
                    type: 'switch', field: 'allowSpanPage', title: 'reportDesigner.allowSpanPage', require: false, value: '1', unit: "", rules: [], labelWidth: "270px"
                },
                {
                    type: 'switch', field: 'showTableCellMargin', title: 'reportDesigner.showTableCellMargin', require: false, value: '0', 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: false, value: '', unit: ""
                    }
                ],
                formatSet: [
                    {type: 'switch', field: 'ReportTime', title: 'reportDesigner.ReportTime', require: false, value: '1', unit: "", rules:[], labelWidth:"270px"}, 
                    {type: 'switch', field: 'InspectionPhysician', title: 'reportDesigner.InspectionPhysician', require: false, value: '1', unit: "", rules:[], labelWidth:"270px"},
                    {type: 'switch', field: 'ReportPhysician', title: 'reportDesigner.ReportPhysician', require: false, value: '1', unit: "", rules:[], labelWidth:"270px"},
                    {type: 'switch', field: 'ImageFile', title: 'reportDesigner.ReportPhysicianESignature', require: false, value: '1', unit: "", rules:[], labelWidth:"270px"},
                    { type: 'switch', field: 'isHidden', title: 'reportDesigner.hidden', require: false, value: '0', unit: "", rules: [], labelWidth: "270px" },
                ]
            },
        }
    },
    //结果
    finals: function (curObj) {
        var defaultRows = 1;
        var defaultCols = 3;
        var caculateInfo = curObj.caculateCellInfo(defaultRows, defaultCols); 
        var selectedItem = [
            { key: "ReportTime", type: "date", title: "reportDesigner.ReportTime", value: true },
            { key: "InspectionPhysician", type: "input", title: "reportDesigner.InspectionPhysician", value: true },
            { key: "ReportPhysician", type: "input", title: "reportDesigner.ReportPhysician", value: true },
            { key: "ImageFile", type: "image", title: "reportDesigner.ReportPhysicianESignature", value: false }
        ];
        return {
            base: {
                rowCount: defaultRows,//表格行数
                columnCount: defaultCols,//表格列数
                columnWidth: caculateInfo.columnWidthList,//表格每列的宽度列表
                rowHeight: caculateInfo.rowHeightList//表格每行的高度列表
            },
            //父组件id
            parentId: "",
            parentName: "",
            offsetWidth: 0,
            offsetHeight: 25,
            selectedItems: selectedItem,
            tasks: curObj.generalCells(curObj.id, defaultRows, defaultCols, curObj.name, selectedItem),//如果每行列的数量有变化，请重置表格
            //占位符
            space: "",
            //样式，每个组件可根据自身特点进行增减
            pattern: {
                //Left,Right,Center,Bothends
                horizontalAlignment: "",
                borderStyle: "Solid",
                borderColor: "#747474",
                borderWeight: 1,
                backgroundColor: "",
                showTableBorder: false,
                avgColumnWidth: true,
                allowSpanPage: true,
                showTableCellBorder: false,
                showTableCellMargin: false
            },
            //属性，每个组件可根据自身特点进行增减
            property: {
                bindId: "",
                //绑定类型
                bindType: "",
                //绑定类型名称
                bindTypeField: "bindType",
                //绑定内容
                bindField: "",
                isDefault: false,
                isHidden: false,
                ReportTime: true,
                InspectionPhysician: true,
                ReportPhysician: true,
                ImageFile: 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,
            }
        }
    }
}