/**
 * 表现形式常量定义
 * @author cls
 * @date 2021-05-16
 * import { $ViewStyle } from "@birt/funclib/ViewStyle";
 */

export const $ViewStyle = {
  // 单选枚举,按钮
  RADIOGROUP: (fieldConf, childConf, controlName) => {
    let viewStyle = childConf.viewStyle;
    let HcRadioGroup = {
      controlName: "HcRadioGroup",
      size: "small"
    }
    return Object.assign(HcRadioGroup, viewStyle || {});
  },
  // 系统枚举查找
  LKSYSENUMS: (fieldConf, childConf, controlName) => {
    let lookupConf = fieldConf.lookup;
    let hcSelect = {
      controlName: "HcSelect",
      loadOnce: true,
      option: {
        labelField: "foptionname",
        valueField: "foptionvalue",
      },
      style: "width: 100%;"
    };
    if (childConf._isFilterEditor) {
      hcSelect.clearable = true;
      hcSelect.filterable = true;
    }
    if (lookupConf.showValue) {
      hcSelect.children = [
        {
          controlName: "HcSpan",
          slot: "option",
          title: function () {
            return this.scope.foptionname;
          },
          style: "float:left;",
        },
        {
          controlName: "HcSpan",
          slot: "option",
          title: function () {
            return this.scope.foptionvalue;
          },
          style: "float:right;",
        },
      ]
    }
    return Object.assign(hcSelect, lookupConf || {});
  },
  // 数据查找,下拉查找
  LKDATADROPDOWN: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcSelect",
      clearable: true,
      filterable: true,
      option: fieldConf.lookup.option,
      lookup: fieldConf.lookup
    }
  },
  // 数据查找,弹出查找
  LKDATADIALOG: (fieldConf, childConf, controlName) => {
    return Object.assign({
      controlName: "HcLookup",
    }, fieldConf.lookup)
  },
  // 字符串文本编辑器
  INPUT: (fieldConf, childConf, controlName) => {
    let hcInput = {
      controlName: "HcInput",
      clearable: true
    };
    if (childConf.suffix) {
      hcInput.clearable = false;
      hcInput.suffix = childConf.suffix;
      hcInput.children = [
        { controlName: "HcSpan", slot: "suffix", title: childConf.suffix }
      ]
    }
    return hcInput;
  },
  // 整数编辑器
  INPUTINT: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcInputNumber",
      controlsPosition: "right",
      style: "width:100%;"
    }
  },
  // 数值型编辑器带单位
  INPUTNUMBER: (fieldConf, childConf, controlName) => {
    let hcInput = $ViewStyle.INPUT(fieldConf, childConf, controlName);
    hcInput.oninput = "value=value.replace(/[^0-9.]/g,'')";
    return hcInput;
  },
  // 整型布尔型，复选框
  CHECKBOXINT: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcCheckbox",
      trueLabel: 1,
      falseLabel: 0
    }
  },
  // true,false 布尔型，复选框
  CHECKBOXBOOLEAN: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcCheckbox"
    }
  },
  // 多行文本
  TEXTAREA: (fieldConf, childConf, controlName) => {
    return Object.assign({
      controlName: "HcInput",
      type: "textarea",
      rows: 3
    }, childConf.viewStyle || {})
  },
  // 对话框多行文本
  TEXTDIALOG: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcTextDialog",
    }
  },
  // 日期时间选择器
  DATEPICKER: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcDatePicker",
      style: "width:100%;"
    }
  },
  // 日期范围选择器
  DATERANGE: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcDateRange",
    }
  },
  // 上传图片、头像
  UPLOADAVATAR: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcUpload",
      accept: "",
      showFileList: false,
      withCredentials: true,
      autoUpload: true,
      avatar: true,//为true时是图片上传组件
      previewUrl: "/file/review?relativePath=",
      postUrl: "/file/upload",
      action: "",
      beforeUpload: function (file) {
        console.log(file)
      },
      onPreview: function (file) {
        console.log(file);
      },
      onRemove: function (file, fileList) {
        console.log(file, fileList);
      },
      beforeRemove: function (file, fileList) {
        return this.$confirm(`确定移除 ${file.name}？`);
      },
      onExeceed: function (files, fileList) {

      }
    }
  },
  // 级联
  CASCADER: (fieldConf, childConf, controlName) => {
    return {
      controlName: "HcCascader",
      style: fieldConf.style,
      options: fieldConf.options,
      value: [],
      events: {
        change: function (val) {
          console.log(val + "," + this.value);
        },
      },
      style: "width: 100%;"
    }
  },
  // 必填标签
  REQUIRED: (childConf) => {
    childConf.children = [
      {
        controlName: "HcSpan",
        title: childConf.value
      },
      {
        controlName: "HcSpan",
        title: "*",
        style: "color:red;"
      }
    ]
    return childConf;
  }

};