package com.mortals.xhx.common.formdesign.component;

import cn.hutool.core.util.IdUtil;
import com.mortals.xhx.common.code.ComponentEnum;
import com.mortals.xhx.common.formdesign.DesignComponent;
import com.mortals.xhx.common.formdesign.ListItem;
import com.mortals.xhx.common.pdu.gen.Component;
import com.mortals.xhx.common.pdu.gen.Config;
import com.mortals.xhx.common.pdu.gen.FieldsItem;
import com.mortals.xhx.common.pdu.gen.Slot;
import com.mortals.xhx.common.pdu.gen.component.ComponentCons;

import java.util.ArrayList;

/**
 * 图片组件
 *
 * @author: zxfei
 * @date: 2021/10/26 10:35
 * @description:
 **/
public class DesignImageComponent extends DesignComponent {

    public DesignImageComponent(String type) {
        super(type);
    }

    @Override
    public ListItem buildDefaultComponent(ComponentCons cons) {
        ListItem columnsItem = new ListItem();
        columnsItem.setId(cons.getVal());
        columnsItem.set_id(cons.getVal());
        columnsItem.setCompType("upload");
        columnsItem.setCompName(cons.getLabel());
        columnsItem.setCompIcon("button");
        columnsItem.setEle("el-upload");
        columnsItem.setViewType("component");
        columnsItem.setConfig(true);
        columnsItem.setShowLabel(true);
        columnsItem.setLabel(cons.getLabel());
        columnsItem.setLabelWidth(120);
        columnsItem.setType("primary");
        columnsItem.setText("按钮");
        columnsItem.setPlain(true);
        columnsItem.setRound(false);
        columnsItem.setCircle(false);
        columnsItem.setLoading(false);
        columnsItem.setLayout("colItem");
        return columnsItem;



      /*  //图片选择
        FieldsItem fieldsItem = new FieldsItem();
        Config config = new Config();
        config.setLabel("日期选择");
        config.setTag("el-upload");
        config.setTagIcon("upload");
        config.setButtonText("点击上传");
        config.setFileSize(2);
        config.setSizeUnit("MB");
        config.setLabelWidth("");
        config.setShowLabel(true);
        config.setChangeTag(true);
        config.setTag("el-upload");
        config.setRequired(false);
        config.setLayout("colFormItem");
        config.setDocument("https://element.eleme.cn/#/zh-CN/component/upload");
        config.setRegList(new ArrayList<>());
        config.setSpan(12);
        fieldsItem.setConfig(config);

        Slot slot = new Slot();
        slot.setListType(true);

        fieldsItem.setSlot(slot);
        fieldsItem.setAction("/m/file/commonupload?prePath=preview");
        fieldsItem.setAccept("image/*");
        fieldsItem.setName("file");
        fieldsItem.setAutoUpload(true);
        fieldsItem.setListType("picture-card");
        fieldsItem.setMultiple(false);
        fieldsItem.setClearable(true);

        fieldsItem.setReadonly(false);
        fieldsItem.setDisabled(false);
        fieldsItem.setVModel("imageupload");

        return fieldsItem;*/
    }

    @Override
    public String getType() {
        return ComponentEnum.IMAGE.getValue();
    }
}
