import {
  deepClone,
  translateOptionItems,
  getDSByName,
  overwriteObj,
  runDataSourceRequest,
  getReportGlobalMap,
  getAccessUrl,
  generateId,
  trim
} from "../../../../../components/xform/utils/util";
import FormValidators, {getRegExp} from "../../../../../components/xform/utils/validators";
import scriptHttpMixin from "../../../../../components/xform/mixins/scriptHttp";
import defaultHandleMixin from "../../../../../components/xform/mixins/defaultHandle";

import {
  fieldIsUsedInFormula, calculateFormula, recalculateFormulaOnSubFormRowDelete,
} from '@base/components/xform/utils/formula-util'
import * as formulajs from '@formulajs/formulajs'
import settingConfig from "@/settings.js";

let modules = {};
const isDev = process.env.NODE_ENV === "development";
const baseRefUtil = {
  deepClone,
  translateOptionItems,
  getDSByName,
  overwriteObj,
  runDataSourceRequest,
  FormValidators,
  getReportGlobalMap,
  getAccessUrl,
};
modules = {
  mixins: [scriptHttpMixin, defaultHandleMixin],
  props: {
    columnConfig: {
      type: Object,
      default: null,
    },
    tableParam: {
      type: Object,
      default: null,
    },
    formItemProp: {
      type: String,
      default: null,
    }
  },
  provide() {
    return {
      tableParam: this.tableParam,
      formItemProp: this.formItemProp,
    };
  },
  inject: [
    "refList",
    "widgetKeyNameMap",
    "getFormConfig",
    "globalOptionData",
    "globalModel",
    "getOptionData",
    "getGlobalDsv",
    "getReadMode",
    "getSubFormFieldFlag",
    "getSubFormName",
    "getReportTemplate",
    "getObjectFieldFlag",
    "getObjectName",
  ],
  data: function () {
    return {
      fieldReadonlyFlag: !1,
      requestAccess: null,
      extraAccessData: {},
      timerMap: {},

      disabled: false,
      hidden: false,
      readonly: false
    };
  },
  beforeDestroy() {
    this.clearAllInterval();
  },
  created() {
    // this.initFieldAttrs();
    this.initConfig();
    this.initValueWatchEvent();
    if (this.field.options.searchDialogConfig) {
      if (this.field.options.searchDialogConfig.multipleChoices === void 0) {
        if (this.hasVabsearchFlag()) {
          this.$set(
            this.field.options.searchDialogConfig,
            "multipleChoices",
            false
          );
        } else {
          this.$set(
            this.field.options.searchDialogConfig,
            "multipleChoices",
            true
          );
        }
      }
    }
  },
  mounted() {
  },
  /*watch: {
    currentValue(val) {
      this.initFieldModel(true);
    },
  },*/
  computed: {
    /* currentValue() {
      let currentData =
        this.tableParam && this.tableParam.row
          ? this.tableParam.row
          : this.formModel;
      let currentValue = currentData[this.fieldKeyName];
      return currentValue;
    }, */
    formConfig: function () {
      return this.getFormConfig();
    },
    subFormName: function () {
      return this.getSubFormName ? this.getSubFormName() : "";
    },
    subFormItemFlag: function () {
      return !!this.getSubFormFieldFlag && this.getSubFormFieldFlag();
    },
    formModel: {
      cache: !1,
      get: function () {
        return this.globalModel.formModel;
      },
    },
    isReadMode: function () {
      return !!this.getReadMode() || this.fieldReadonlyFlag;
    },
    optionLabel() {
      return this.getOptionLabel();
    },
    tableRow() {
      let tableParam = this.tableParam;
      return tableParam && tableParam.row ? tableParam.row : null;
    },
    fieldKeyName() {
      let o = this.field.options.name;
      return (
        (this.field.options.keyNameEnabled && this.field.options.keyName) || o
      );
    },
  },
  methods: {
    getCurrentValue() {
      let currentData =
        this.tableParam && this.tableParam.row
          ? this.tableParam.row
          : this.formModel;
      let currentValue = currentData[this.fieldKeyName];
      return currentValue;
    },
    setFormScriptEnabled(value){
      this.field.options.formScriptEnabled = value || false
    },
    getOptionLabel(){
      if (this.fieldModel === null) {
        return null
      } else {
        let resultList = []
        let labelField = this.getOptionItemLabelKey();
        let valueField = this.getOptionItemValueKey();
        this.field.options.optionItems.forEach(oItem => {
          if ((oItem[valueField] === this.fieldModel) || (this.findInArray(this.fieldModel, oItem[valueField])) !== -1) {
            resultList.push(this.$t1(oItem[labelField]))
            // resultContent = resultContent === '--' ? oItem.label : resultContent + ' ' + oItem.label
          }
        })
        return resultList.join(",")
      }
    },
    initValueWatchEvent() {
      if (!this.designer) {
        this.$watch(() => {
          let currentData = this.tableParam && this.tableParam.row
            ? this.tableParam.row
            : this.formModel;
          let currentValue = currentData[this.fieldKeyName];
          return currentValue;
        }, (newValue, oldValue) => {
          if (oldValue !== undefined) {
            this.initFieldModel(true);
          }
        })
      }
    },
    initFieldAttrs() {
      this.setDisabled(this.field.options.disabled)
      this.setHidden(this.field.options.hidden)
      this.setReadonly(this.field.options.readonly)
    },
    initConfig() {
      /*if (this.designState) {
        let config = this.designer.getFieldWidgetByType(this.field.type);
        if(config){
          let defaultOptions = config.options;
          let options = this.field.options;
          Object.keys(defaultOptions).forEach(function (k) {
            if (!options.hasOwnProperty(k)) {
              let val = defaultOptions[k]
              if (Array.isArray(val)) {
                options[k] = []
              } else {
                options[k] = null
              }
            }
          })
        }

      }*/

      /*this.field.options = Object.assign(
        {},
        config.options,
        this.field.options
      );*/
    },
    findInArray: function (e, t) {
      if (!Array.isArray(e)) return -1;
      let i = -1;
      return (
        e.forEach(function (e, n) {
          e === t && (i = n);
        }),
          i
      );
    },
    getPropName: function () {
      if (this.formItemProp) {
        return this.formItemProp;
      } else {
        return this.subFormItemFlag && !this.designState
          ? this.subFormName +
          "." +
          this.subFormRowIndex +
          "." +
          this.fieldKeyName
          : this.getObjectFieldFlag() && !this.designState
            ? this.getObjectName() + "." + this.fieldKeyName
            : this.fieldKeyName;
      }
    },
    initFieldModel: function (flag) {
      let e = this;
      if (this.field.formItemFlag) {
        let currentData =
          this.tableParam && this.tableParam.row
            ? this.tableParam.row
            : this.formModel;
        /*if (this.subFormItemFlag && !this.designState) {
          let t = currentData[this.subFormName];
          return void 0 !== t && void 0 !== t[this.subFormRowIndex] && void 0 !== t[this.subFormRowIndex][
            this.fieldKeyName
            ] || void 0 === this.field.options.defaultValue ? void 0 === t[this.subFormRowIndex][this
            .fieldKeyName
            ] ? (this.fieldModel = null,
            t[this.subFormRowIndex][this.fieldKeyName] = null) : this.fieldModel = t[this
            .subFormRowIndex][this.fieldKeyName] : (this.fieldModel = this.field.options
            .defaultValue,
            t[this.subFormRowIndex][this.fieldKeyName] = this.field.options.defaultValue),
            setTimeout((function () {
              e.handleOnChangeForSubForm(e.fieldModel, e.oldFieldValue, t, e.subFormRowId)
            }), 800),
            this.oldFieldValue = baseRefUtil.deepClone(this.fieldModel),
            void this.initFileList();
        }*/

        let defaultValue = this.field.options.defaultValue;
        let dataId = this.getFormRef()?.dataId ?? null;
        let nullValue = null;
        let widgetType = this.field.type;
        if (widgetType === "number") {
          nullValue = undefined;
        } else if (widgetType === 'checkbox' || (widgetType === 'select' && this.field.options.multiple)) {
          nullValue = [];
        } else if (widgetType === "time-range" || widgetType === "date-range" || (widgetType === 'date' && this.field.options.type === "dates")) {
          nullValue = [];
        }
        if (void 0 === currentData[this.fieldKeyName]) {
          this.$set(currentData, this.fieldKeyName, nullValue);
        }
        if (flag) {
          this.fieldModel = currentData[this.fieldKeyName];
        } else if (currentData[this.fieldKeyName] !== null) {
          this.fieldModel = currentData[this.fieldKeyName];
        } else {
          if (!dataId) {
            //新增
            if (!this.designState && this.hasVabsearchFlag() && !this.field.options.multipleChoices) {
              let searchDialogConfig = this.field.options.searchDialogConfig || {};
              if (this.field.options.userDefaultVabSearch) {
                let userInfo = this.getFormRef().getUserInfo();
                let valueSourceField = "id";
                let labelSourceField = "nick_name";
                if (this.field.options.clickBindEvent === "1") {
                  if (searchDialogConfig.valueSourceField) valueSourceField = searchDialogConfig.valueSourceField
                  if (searchDialogConfig.labelSourceField) labelSourceField = searchDialogConfig.labelSourceField
                }
                this.initValue(userInfo[valueSourceField] ?? null);
                this.setShowValue(userInfo[labelSourceField] ?? null);
              } else if (this.field.options.saleOrgDefaultVabSearch) {
                let saleOrgDTO = this.getFormRef().getDefaultSaleOrgDTO();
                if (saleOrgDTO) {
                  let valueSourceField = "id";
                  let labelSourceField = "name";
                  if (this.field.options.clickBindEvent === "1") {
                    if (searchDialogConfig.valueSourceField) valueSourceField = searchDialogConfig.valueSourceField
                    if (searchDialogConfig.labelSourceField) labelSourceField = searchDialogConfig.labelSourceField
                  }
                  this.initValue(saleOrgDTO[valueSourceField] ?? null);
                  this.setShowValue(saleOrgDTO[labelSourceField] ?? null);
                }
              }
            }
            if (!this.tableParam) {
              //主表
              if (this.isNotNullVal(defaultValue)) {
                this.initValue(defaultValue);
              }
            } else {
              //明细
              if (!this.tableParam.row.id && this.isNotNullVal(defaultValue)) {
                this.initValue(defaultValue);
              }
            }
          } else {
            //编辑
            if (!this.tableParam) {
              //主表
            } else {
              //明细
              if (!this.tableParam.row.id && this.isNotNullVal(defaultValue)) {
                this.initValue(defaultValue);
              }
            }
          }
        }

        /*if (this.fieldKeyName === "f_mobile" && !this.fieldModel) {
        }*/
        /*void 0 === currentData[this.fieldKeyName] && void 0 !== this.field.options.defaultValue
          ? this.fieldModel = this.field.options.defaultValue :
          void 0 === currentData[this.fieldKeyName] ? currentData[this.fieldKeyName] = null : this.fieldModel = currentData[this.fieldKeyName];*/
        this.oldFieldValue = baseRefUtil.deepClone(this.fieldModel);
        /*if (this.fieldKeyName === "f_contract" && !this.fieldModel) {
        }*/
        this.initFileList();
      }
    },
    isNotNullVal(val) {
      return val !== null && val !== undefined && val !== "";
    },
    initFileList: function () {
      ("picture-upload" !== this.field.type &&
        "file-upload" !== this.field.type) ||
      !0 === this.designState ||
      (this.fieldModel &&
        (Array.isArray(this.fieldModel)
          ? (this.fileList = baseRefUtil.deepClone(this.fieldModel))
          : this.fileList.splice(
            0,
            0,
            baseRefUtil.deepClone(this.fieldModel)
          )));
    },
    handleCreatedEnterEvent() {
      this.handleCustomEvent(this.field.options.onCreatedEnter);
    },
    initEventHandler() {
      this.designState ||
      (this.$on("setFormData", (o) => {
        /*if (!this.subFormItemFlag)
        if (
          !!this.getObjectFieldFlag()
          && !this.designState
        ) {
          const e = this.getObjectModel();
          this.setValue(
            e === void 0
              ? null
              : e[this.fieldKeyName]
          );
        } else this.setValue(o[this.fieldKeyName]);*/
        this.subFormItemFlag || this.setValue(o[this.fieldKeyName]);
      }),
        this.$on("field-value-changed", (o) => {
          if (this.subFormItemFlag) {
            let e = this.formModel[this.subFormName];
            this.handleOnChangeForSubForm(o[0], o[1], e, this.subFormRowId);
          } else this.handleOnChange(o[0], o[1]);
        }),
        /* this.$on("field-value-changed", function (e) {
          if (this.subFormItemFlag) {
            let t = this.formModel[this.subFormName];
            this.handleOnChangeForSubForm(e[0], e[1], t, this.subFormRowId);
          } else this.handleOnChange(e[0], e[1]);
        }), */
        this.$on("sync-field-value", (o) => {
          const e = o[0],
            n = o[1];
          if (
            this.field.options.name === e ||
            (!n && this.field.options.keyName !== e) ||
            (!this.field.options.keyName && this.field.options.name !== n) ||
            (!!this.field.options.keyName &&
              !!n &&
              this.field.options.keyName !== n) ||
            o[5] !== this.getObjectName()
          )
            return;
          const s = o[2],
            c = o[3],
            u = o[4];
          !this.subFormName && !s
            ? this.setValue(u, !0)
            : this.subFormName === s &&
            this.subFormRowId === c &&
            this.setValue(u, !0);
        }),

        /* 执行计算公式运算 */
        this.$on('calculate-formula', (newValue, sourceWidget) => {
          if (!!this.field.options.formulaEnabled && !!this.field.options.formula) {
            let changedFieldRef = sourceWidget
            const changedFieldName = sourceWidget.field.options.name
            //检查计算公式是否包含当前修改字段
            if (fieldIsUsedInFormula(changedFieldName, this.field.options.formula, this.getFormRef(), this)) {

              /* 计算公式的计算改成延时执行，否则当子表单开启默认创建新行后，子表单字段的计算公式中使用到主表单字段则会出现计算错误！！ */
              //calculateFormula(this.getFormRef(), this.getGlobalDsv(), formulajs, this, changedFieldRef)

              setTimeout(() => {
                calculateFormula(this.getFormRef(), this.getGlobalDsv(), formulajs, this, changedFieldRef)
              }, 200)
            }
          }
        }),

        /* 删除子表单行后重新执行计算公式运算 */
        this.$on('calculate-formula-sfRowDeleted', (newValue, deletedFieldName) => {
          if (!!this.field.options.formulaEnabled && !!this.field.options.formula) {
            //检查计算公式是否包含当前修改字段
            if (fieldIsUsedInFormula(deletedFieldName, this.field.options.formula, this.getFormRef())) {
              recalculateFormulaOnSubFormRowDelete(this.getFormRef(), this.getGlobalDsv(), formulajs, this)
            }
          }
        }),

        this.$on("loadOptionItemsFromDataSet", (o) => {
          this.loadOptionItemsFromDataSet(o), (this.dataSetLoadedFlag = !0);
        }),
        this.$on("reloadOptionItems", (o) => {
          (o.length === 0 || o.indexOf(this.field.options.name) > -1) &&
          this.initOptionItems(!0);
        }));
    },
    getEventParam() {
      let formRef = this.getFormRef();
      let dataId = formRef?.dataId;
      let formCode = formRef?.reportTemplate?.formCode;
      return {
        eventParamNames: ["dataId", "formCode"],
        eventParamValues: [dataId, formCode],
      };
    },
    handleCustomEvent(funtionStr, eventParamNames = [], eventParamValues = []) {
      if (!this.designState && funtionStr) {
        let eventParam = this.getEventParam();
        let e = new Function(
          ...eventParam.eventParamNames,
          ...eventParamNames,
          funtionStr
        );
        let that = this;
        try{
          return e.call(
            this,
            ...eventParam.eventParamValues,
            ...eventParamValues
          );
        }catch(error){
          if(settingConfig.fontErrorTipEnabled){
            that.$errorMsg({
              rmid: that.$t1("前端脚本异常"),
              content: error.message,
              type: 'error',
              _errorMsg: error.stack
            })
          }
          throw error;
        }
      }
    },
    handleOnCreated: function () {
      this.handleCustomEvent(this.field.options.onCreated);
    },
    handleOnMounted: function () {
      this.handleCustomEvent(this.field.options.onMounted);
      this.autoExcScript();
    },
    registerToRefList: function (e) {
      /* null !== this.refList && this.field.options.name && (this.tableParam && !this.designState ? (e
      && delete this.refList[e + "@row" + this.tableParam.rowIndex],
        this.refList[this.field.options.name + "@row" + this.tableParam.rowIndex] = this) : (e
      && delete this.refList[e],
        this.refList[this.field.options.name] = this)); */
      if (null !== this.refList && this.field.options.name) {
        if (this.tableParam && !this.designState) {
          let row = this.tableParam.row;
          if (!row._X_ROW_KEY) {
            row._X_ROW_KEY = "row_" + generateId()
          }
          let keyVal = row._X_ROW_KEY;
          e && delete this.refList[e + "_" + keyVal];
          this.refList[this.field.options.name + "_" + keyVal] = this;

          /*      if (!!e) {
                  delete this.refList[e + '_' + this.subFormRowId]
                }
                this.refList[this.field.options.name + '@' + this.subFormRowId] = this
      */
        } else {
          e && delete this.refList[e];
          this.refList[this.field.options.name] = this;
          if (this.widgetKeyNameMap) {
            if (!this.widgetKeyNameMap[this.fieldKeyName]) {
              this.widgetKeyNameMap[this.fieldKeyName] = [this.field.options.name]
            } else {
              this.widgetKeyNameMap[this.fieldKeyName].push(this.field.options.name);
            }
          }
        }
      }
    },
    getTableRef() {
      let tableRef = this.getWidgetRef(this.parentWidget.options.name)
      return tableRef;
    },
    getWidgetRefByTableRow(index, name) {
      let tableRef = this.getTableRef();
      return tableRef.getWidgetRefByTableRow(index, name)
    },
    getWidgetRefByTableParam(param) {
      let tableParam = param || this.tableParam;
      let tableRef = this.getTableRef();
      return tableRef.getWidgetRefByTableParam(tableParam);
    },
    unregisterFromRefList: function () {
      if (null !== this.refList && this.field.options.name) {
        let e = this.field.options.name;
        this.tableParam && !this.designState
          ? delete this.refList[e + "@row" + this.tableParam.rowIndex]
          : delete this.refList[e];
      }
    },
    initOptionItemsHandle() {
      if(this.tableParam){
        if(this.field._syncInited){
          this.handleCustomEvent(
            this.field.options.formScriptSuccess
          );
        }
        return
      }
      this.initGloatOptionItems(true);
    },
    initGloatOptionItems(initFlag) {
      let t = this;
      if (this.designState) {
        return;
      }

      if (
        this.field.type === "radio" ||
        this.field.type === "checkbox" ||
        this.field.type === "select" ||
        this.field.type === "cascader" ||
        this.field.type === "status"
      ) {
        /* this.field.options.optionItems.forEach(item=>{
          if (!item.hasOwnProperty('disabled')) {
            this.$set(item,"disabled",false)
          }
        }) */

        let reportTemplate = this.getFormRef().reportTemplate;
        let formCode = reportTemplate.formCode;
        let formScriptEnabled = this.field.options.formScriptEnabled || false;
        let scriptCode = this.field.options.formScriptCode || "getList";
        let tableParam = this.tableParam;
        if (formScriptEnabled) {
          if (initFlag && tableParam) {
            let optionItems = this.getOptionItemsFlag()
            if (optionItems !== undefined) {
              return
            }
            this.setOptionItemsFlag(null)
          }
          let accessParam = this.handleCustomEvent(
            this.field.options.formScriptParam
          );
          return this.formHttp({
            scriptCode: scriptCode,
            data: {
              formCode: formCode,
              formVersion: reportTemplate.formVersion,
              taBm: this.fieldKeyName,
              data: {
                ...accessParam,
              },
            },
            callback: (res) => {
              let rows = res.objx?.records || res.objx || [];
              this.loadGloatOptions(rows, initFlag);
              this.handleCustomEvent(
                this.field.options.formScriptSuccess,
                ["res"],
                [res]
              );
            },
          });
        } else if (this.field.options.commonAttributeEnabled) {
          let commonAttributeCode = this.field.options.commonAttributeCode;
          if (!commonAttributeCode) return;
          if (initFlag && tableParam) {
            let optionItems = this.getOptionItemsFlag();
            if (optionItems !== undefined) {
              return
            }
            this.setOptionItemsFlag(null)
          }
          let accessParam = this.handleCustomEvent(
            this.field.options.formScriptParam
          );
          this.$getBaseDicts({
            code: commonAttributeCode,
            data:{
              ...accessParam
            },
            success: ({dicts, dictMap}) => {
              this.loadGloatOptions(dicts, initFlag);
              this.handleCustomEvent(
                this.field.options.formScriptSuccess,
                ["res"],
                [dicts]
              );
            },
          });
        }

        return;
      }
    },
    loadGloatOptions: function (e, initFlag) {
      let optionItems = baseRefUtil.translateOptionItems(
        e,
        this.field.type,
        this.getOptionItemLabelKey(),
        this.getOptionItemValueKey()
      );
      // this.field.options.optionItems = optionItems
      this.setOptionItems(optionItems)
      let tableParam = this.tableParam;
      if (tableParam) {
        if (initFlag) {
          this.setOptionItemsFlag(true)
        }
        this.loadTableOtions(optionItems)
      }
    },
    setOptionItems(rows){
      let formScriptEnabledTypes = ['select', 'checkbox', 'radio',"cascader"]
      let widgetType = this.field.type;
      if(formScriptEnabledTypes.includes(widgetType)){
        this.field.options.optionItems = rows || [];
      }else if(widgetType=="status"){
        this.field.options.statusParam = rows || [];
      }
    },
    loadTableOtions(e) {
      let tableParam = this.tableParam;
      if (tableParam) {
        let optionItems = baseRefUtil.translateOptionItems(
          e,
          this.field.type,
          this.getOptionItemLabelKey(),
          this.getOptionItemValueKey()
        );
        let widgetName = this.field.options.name;
        let tableWidgetName = tableParam.column.params.tableWidgetName
        let tableTarget = this.getWidgetRef(tableWidgetName);
        tableTarget.loopHandleWidgetByName(widgetName, (row, widget, target) => {
          widget.options.optionItems = optionItems
        })
        if (tableParam.column.params.widget) {
          if (tableParam.column.params.widget.options.name === widgetName) {
            tableParam.column.params.widget.options.optionItems = optionItems
          }

        }
        if (tableParam.column.params.editWidget) {
          if (tableParam.column.params.editWidget.options.name === widgetName) {
            tableParam.column.params.editWidget.options.optionItems = optionItems
          }
        }
        if (tableParam.column.params.widgetList?.length) {
          this.loopHandleWidget(tableParam.column.params.widgetList, (item1) => {
            if (item1.options.name === widgetName) {
              item1.options.optionItems = optionItems
            }
          });
        }

        delete tableParam.column.params[widgetName]
      }
    },
    async initOptionItems(gloatFlag) {
      let t = this;
      if (this.designState) {
        return;
      }

      if (
        this.field.type === "radio" ||
        this.field.type === "checkbox" ||
        this.field.type === "select" ||
        this.field.type === "cascader"
      ) {
        let reportTemplate = this.getFormRef().reportTemplate;
        let formCode = reportTemplate.formCode;
        let formScriptEnabled = this.field.options.formScriptEnabled || false;
        let scriptCode = this.field.options.formScriptCode || "getList";
        let tableParam = this.tableParam;
        if (formScriptEnabled) {
          let accessParam = this.handleCustomEvent(
            this.field.options.formScriptParam
          );
          return this.formHttp({
            scriptCode: scriptCode,
            data: {
              formCode: formCode,
              formVersion: reportTemplate.formVersion,
              taBm: this.fieldKeyName,
              data: {
                ...accessParam,
              },
            },
            callback: (res) => {
              let rows = res.objx || [];
              this.loadOptions(rows);
              this.handleCustomEvent(
                this.field.options.formScriptSuccess,
                ["res"],
                [res]
              );
            },
          });
        } else if (this.field.options.commonAttributeEnabled) {
          let commonAttributeCode = this.field.options.commonAttributeCode;
          if (!commonAttributeCode) return;
          this.$getBaseDicts({
            code: commonAttributeCode,
            success: ({dicts, dictMap}) => {
              this.loadOptions(dicts);
              this.handleCustomEvent(
                this.field.options.formScriptSuccess,
                ["res"],
                [dicts]
              );
            },
          });
        }

        return;
      }
    },
    refreshDefaultValue: function () {
      !0 === this.designState &&
      void 0 !== this.field.options.defaultValue &&
      (this.fieldModel = this.field.options.defaultValue);
    },

    clearFieldRules() {
      if (!this.field.formItemFlag) {
        return
      }

      this.rules && this.rules.splice(0, this.rules.length)  //清空已有
    },

    getValidateDefaultMsg(labelCode, vldName) {
      let label = this.$t1(labelCode);
      let map = {
        number: "[{label}]包含非数字字符",
        letter: "[{label}]包含非字母字符",
        letterAndNumber: "[{label}]只能输入字母或数字",
        mobilePhone: "[{label}]手机号码格式有误",
        letterStartNumberIncluded: "[{label}]必须以字母开头，可包含数字",
        noChinese: "[{label}]不可输入中文字符",
        chinese: "[{label}]只能输入中文字符",
        email: "[{label}]邮箱格式有误",
        url: "[{label}]URL格式有误",
        required: "[{label}]不能为空"
      }
      let result = null
      let value = map[vldName]
      if (!value) {
        value = "[{label}]invalid value"
      }
      result = this.$t1(value, {label});
      return result
    },
    getValidationHintMsg() {
      let vldName = this.field.options.validation
      if (this.field.options.validationHint) {
        return this.$t1(this.field.options.validationHint)
      } else {
        return this.getValidateDefaultMsg(this.field.options.label, vldName)
      }
    },
    getRequiredHintMsg() {
      if (this.field.options.requiredHint) {
        return this.$t1(this.field.options.requiredHint)
      } else {
        return this.getValidateDefaultMsg(this.field.options.label, "required")
      }
    },
    buildFieldRules() {
      if (!this.field.formItemFlag || this.field.options.hidden) {
        return
      }

      this.rules.splice(0, this.rules.length)  //清空已有
      if (!!this.field.options.required) {
        this.rules.push({
          required: true,
          //trigger: ['blur', 'change'],
          trigger: ['blur'],  /* 去掉change事件触发校验，change事件触发时formModel数据尚未更新，导致radio/checkbox必填校验出错！！ */
          message: this.getRequiredHintMsg()
        })
      }

      if (!!this.field.options.validation) {
        let vldName = this.field.options.validation
        if (!!FormValidators[vldName]) {
          this.rules.push({
            validator: FormValidators[vldName],
            trigger: ['blur', 'change'],
            label: this.field.options.label,
            // errorMsg: this.field.options.validationHint
            errorMsg: this.getValidationHintMsg()
          })
        } else {
          this.rules.push({
            validator: FormValidators['regExp'],
            trigger: ['blur', 'change'],
            regExp: vldName,
            label: this.field.options.label,
            // errorMsg: this.field.options.validationHint
            errorMsg: this.getValidationHintMsg()
          })
        }
      }

      if (!!this.field.options.onValidate) {
        let customFn = (rule, value, callback) => {
          let tmpFunc = new Function('rule', 'value', 'callback', this.field.options.onValidate)
          return tmpFunc.call(this, rule, value, callback)
        }
        this.rules.push({
          validator: customFn,
          trigger: ['blur', 'change'],
          label: this.field.options.label
        })
      }
    },

    /**
     * 禁用字段值变动触发表单校验
     */
    disableChangeValidate() {
      if (!this.rules) {
        return
      }

      this.rules.forEach(rule => {
        if (!!rule.trigger) {
          rule.trigger.splice(0, rule.trigger.length)
        }
      })
    },

    /**
     * 启用字段值变动触发表单校验
     */
    enableChangeValidate() {
      if (!this.rules) {
        return
      }

      this.rules.forEach(rule => {
        if (!!rule.trigger) {
          rule.trigger.push('blur')
          rule.trigger.push('change')
        }
      })
    },

    disableOptionOfList(optionList, optionValue) {
      if (!!optionList && (optionList.length > 0)) {
        let valueKey = this.getOptionItemValueKey();
        optionList.forEach(opt => {
          if (opt[valueKey] === optionValue) {
            opt.disabled = true
          }

          if (opt.children && Array.isArray(opt.children)) {
            this.disableOptionOfList(opt.children, optionValue)
          }
        })
        this.$forceUpdate()
      }
    },

    enableOptionOfList(optionList, optionValue) {
      if (!!optionList && (optionList.length > 0)) {
        let valueKey = this.getOptionItemValueKey();
        optionList.forEach(opt => {
          if (opt[valueKey] === optionValue) {
            opt.disabled = false
          }

          if (opt.children && Array.isArray(opt.children)) {
            this.enableOptionOfList(opt.children, optionValue)
          }
        })
        this.$forceUpdate()
      }
    },


    emitFieldDataChange(newValue, oldValue) {
      if (this.designState) return
      this.$emit('field-value-changed', [newValue, oldValue])

      /* 同步更新keyName属性一致的字段组件值！！ */
      if (this.field.options.keyNameEnabled) {
        this.getFormRef().broadcast('FieldWidget', 'sync-field-value',
          [this.field.options.name, this.field.options.keyName, this.subFormName, this.subFormRowId,
            newValue, this.getObjectName()])
      } else {
        this.getFormRef().broadcast('FieldWidget', 'sync-field-value',
          [this.field.options.name, this.field.options.name, this.subFormName, this.subFormRowId,
            newValue, this.getObjectName()])
      }

      if (this.field.type === 'number') {
        this.getFormRef().broadcast('FieldWidget', 'calculate-formula', [newValue, this])  //触发计算公式计算
      }

      /* 必须用dispatch向指定父组件派发消息！！ */
      this.dispatch('VFormRender', 'fieldChange',
        [this.field.options.name, newValue, oldValue, this.subFormName, this.subFormRowIndex])
    },
    syncUpdateFormModel: function (e) {
      if (!this.designState)
        if (this.tableRow) {
          this.tableRow[this.fieldKeyName] = e;
        } else if (this.subFormItemFlag) {
          let t = this.formModel[this.subFormName] || [{}],
            i = t[this.subFormRowIndex];
          i[this.fieldKeyName] = e;
        } else this.formModel[this.fieldKeyName] = e;
    },
    handleChangeEvent: function (e) {
      let widgetType = this.field.type;
      if(widgetType === "select"){
        if(e===""){
           e = this.field.options.multiple? [] : null;
           this.fieldModel = e;
        }
      }else if(widgetType === "number"){
        if(e===undefined){
           e = null;
           this.fieldModel = e;
        }
      }

      this.syncUpdateFormModel(e),
        this.emitFieldDataChange(e, this.oldFieldValue),
        (this.oldFieldValue = baseRefUtil.deepClone(e)),
        this.dispatch("VFormRender", "fieldValidation", [this.getPropName()]);
    },
    handleFocusCustomEvent: function (e) {
      if (
        ((this.oldFieldValue = baseRefUtil.deepClone(this.fieldModel)),
          this.field.options.onFocus)
      ) {
        let t = new Function("event", this.field.options.onFocus);
        t.call(this, e);
      }
    },
    handleBlurCustomEvent: function (e) {
      if (this.field.options.onBlur) {
        let t = new Function("event", this.field.options.onBlur);
        t.call(this, e);
      }
    },
    handleInputCustomEvent: function (e) {
      if (
        (this.syncUpdateFormModel(e),
          this.dispatch("VFormRender", "fieldValidation", [this.getPropName()]),
          this.field.options.onInput)
      ) {
        let t = new Function("value", this.field.options.onInput);
        t.call(this, e);
      }
    },
    emitAppendButtonClick: function () {
      if (!this.designState) {
        if (this.field.options.onAppendButtonClick) {
          let tableParam = this.tableParam;
          let eventParamNames = [];
          let eventParamValues = [];
          if (tableParam) {
            eventParamNames = ["rowData", "rowIndex"];
            eventParamValues = [tableParam.row, tableParam.rowIndex];
          }

          this.handleCustomEvent(
            this.field.options.onAppendButtonClick,
            eventParamNames,
            eventParamValues
          );

          // this.handleCustomEvent(this.field.options.onAppendButtonClick)
        } else {
          this.dispatch("VFormRender", "appendButtonClick", [this]);
        }
        this.handleCustomClickEvent();
      }
    },
    handleCustomClickEvent: function (flag) {
      let tableParam = this.tableParam;
      let clickBindEvent = !flag ? this.field.options.clickBindEvent : this.field.options.widgetTextLinkConfig?.options?.clickBindEvent;

      const done = () => {
        if (clickBindEvent === "1") {
          //打开选择弹框
          this.openSearchDialog(tableParam, flag);
        } else if (clickBindEvent === "2") {
          //列表插入数据
          this.handleAddTableDataEvent(flag);
        }
      }
      if (clickBindEvent && this.field.options.onBeforeClickButton) {
        if (this.handleCustomEvent(this.field.options.onBeforeClickButton, ["done"], [done]) !== false) {
          done();
        }
      } else {
        done();
      }
    },
    handleAddTableDataEvent(flag) {
      let optionModel = !flag ? this.field.options : (this.field.options.widgetTextLinkConfig?.options || {});

      let addTableDataConfig = optionModel.addTableDataConfig || {};
      if (!addTableDataConfig.tableRef) return;
      let tableData = addTableDataConfig.tableData || {};
      this.getWidgetRef(addTableDataConfig.tableRef).addTableData([tableData]);
    },
    handleOnChange: function (e, t) {
      if (this.field.options.onChange) {
        let i = new Function("value", "oldValue", this.field.options.onChange);
        i.call(this, e, t);
      }
    },
    handleOnChangeForSubForm: function (e, t, i, n) {
      if (this.field.options.onChange) {
        let o = new Function(
          "value",
          "oldValue",
          "subFormData",
          "rowId",
          this.field.options.onChange
        );
        o.call(this, e, t, i, n);
      }
    },
    handleButtonWidgetClick: function (event, flag) {
      if (!this.designState) {
        let onClick = !flag ? this.field.options.onClick : this.field.options.widgetTextLinkConfig?.options?.onClick
        if (onClick) {
          let tableParam = this.tableParam;
          let eventParamNames = ["event"];
          let eventParamValues = [event];
          if (tableParam) {
            eventParamNames = ["row", "rowIndex", "event"];
            eventParamValues = [tableParam.row, tableParam.rowIndex, event];
          }
          this.handleCustomEvent(
            onClick,
            eventParamNames,
            eventParamValues
          );
        } else {
          if (!flag) this.dispatch("VFormRender", "buttonClick", [this]);
        }
        this.handleCustomClickEvent(flag);
      }
    },
    getSearchDialogSourceField(targetField) {
      let searchDialogConfig = this.field.options.searchDialogConfig || {};
      let tableData = searchDialogConfig.tableData || [];
    },
    openSearchDialog(tableParam, flag) {
      let optionModel = !flag ? this.field.options : (this.field.options.widgetTextLinkConfig?.options || {});
      let searchDialogConfig = optionModel.searchDialogConfig || {};
      let formCode = searchDialogConfig.formCode;
      let tableData = searchDialogConfig.tableData || [];
      let formModel = this.formModel;

      let rows = [];
      if (this.hasVabsearchFlag()) {
        if (this.field.options.multipleChoices) {
          let fieldKeyName = this.fieldKeyName;
          let valueField = trim(this.field.options.valueField || fieldKeyName);
          let vabSearchName = trim(this.field.options.vabSearchName || fieldKeyName);
          let valueSourceField = trim(searchDialogConfig.valueSourceField)
          let labelSourceField = trim(searchDialogConfig.labelSourceField)

          rows = (this.fieldModel || []).map((row) => {
            return {
              [valueSourceField]: row[valueField],
              [labelSourceField]: row[vabSearchName],
            };
          });
        }
      }

      // dialogQueryParam.
      let queryParam = null;
      if (searchDialogConfig.dialogQueryParam) {
        queryParam = this.handleCustomEvent(searchDialogConfig.dialogQueryParam)
      }
      let dialogCustomParam = {};
      if (searchDialogConfig.dialogCustomParam) {
        dialogCustomParam = this.handleCustomEvent(searchDialogConfig.dialogCustomParam) || {}
      }
      let dialogParam = Object.assign({
        formCode: formCode,
        rows,
        queryParam,
        multiple: searchDialogConfig.multipleChoices || false,
        confirm: (rows) => {
          this.handleConfirmSearchDialog(rows, false, flag);
        },
      },dialogCustomParam)
      this.getFormRef().openSearchDialog(dialogParam);
    },
    handleClearSearchDialog() {
      let clickBindEvent = this.field.options.clickBindEvent;
      if (clickBindEvent === "1") {
        this.handleConfirmSearchDialog(null, true);
      }
    },
    getMultipleChoices() {
      let multipleChoices = this.field.options.multipleChoices;
      return multipleChoices;
    },
    hasVabsearchFlag() {
      return this.field.type === "vabsearch" || this.field.type === "singerSearch" || this.field.type === "multiSearch"
    },
    handleConfirmSearchDialog(rows, isClear, flag) {
      if (!isClear && !rows.length) return;
      let optionModel = !flag ? this.field.options : (this.field.options.widgetTextLinkConfig?.options || {});

      let tableParam = this.tableParam;
      let searchDialogConfig = optionModel.searchDialogConfig || {};
      let formCode = searchDialogConfig.formCode;
      let tableData = searchDialogConfig.tableData || [];
      let formModel = this.formModel;
      let row = rows && rows.length ? rows[0] : null;
      let multipleChoices =
        optionModel.searchDialogConfig.multipleChoices || false;

      let valueSourceField = trim(searchDialogConfig.valueSourceField)
      let labelSourceField = trim(searchDialogConfig.labelSourceField)
      if (this.hasVabsearchFlag()) {
        let fieldKeyName = this.fieldKeyName;
        let valueField = trim(this.field.options.valueField || fieldKeyName);
        let vabSearchName = trim(this.field.options.vabSearchName || fieldKeyName);
        if (tableParam) {
          let rowData = tableParam.row;
          if (this.getMultipleChoices()) {
            if (isClear) {
              rowData[fieldKeyName] = [];
            } else {
              rowData[fieldKeyName] = rows.map((item) => {
                let newData = {};
                newData[valueField] =
                  item[valueSourceField] ?? null;
                newData[vabSearchName] =
                  item[labelSourceField] ?? null;
                tableData.forEach((item1) => {
                  let targetFormField = trim(item1.targetFormField || item1.targetField)
                  let sourceField = trim(item1.sourceField)
                  newData[targetFormField] = item[sourceField];
                });
                return newData;
              });
            }
          } else {
            rowData[fieldKeyName] = !isClear
              ? row[valueSourceField]
              : null;
            if (labelSourceField)
              rowData[vabSearchName] = !isClear
                ? row[labelSourceField]
                : null;
            tableData.forEach((item) => {
              let targetFormField = trim(item.targetFormField || item.targetField);
              let sourceField = trim(item.sourceField)
              if (!isClear) {
                rowData[targetFormField] = row[sourceField];
              } else {
                rowData[targetFormField] = null;
              }
            });
          }
        } else {
          if (this.getMultipleChoices()) {
            let rowData = [];
            if (isClear) {
              rowData = [];
            } else {
              rowData = rows.map((item) => {
                let newData = {};
                newData[valueField] =
                  item[valueSourceField] ?? null;
                newData[vabSearchName] =
                  item[labelSourceField] ?? null;
                tableData.forEach((item1) => {
                  let targetFormField = trim(item1.targetFormField || item1.targetField)
                  let sourceField = trim(item1.sourceField)
                  newData[targetFormField] = item[sourceField];
                });
                return newData;
              });
            }
            this.setValue(rowData);
          } else {
            /* this.fieldModel = !isClear
              ? row[valueSourceField]
              : null; */
            let value = !isClear
                ? row[valueSourceField]
                : null
            this.setValue(value)
            if (labelSourceField) {
              this.setShowValue(
                !isClear ? row[labelSourceField] : null
              );
            }
            tableData.forEach((item) => {
              // formModel[item.targetField] = row[item.sourceField]
              let value = !isClear ? row[item.sourceField] ?? null : null;
              let targetField = trim(item.targetField)
              let targetFormField = trim(item.targetFormField)
              if (targetField) {
                this.getWidgetRef(targetField).setValue(value);
              } else if (targetFormField) {
                formModel[targetFormField] = value;
              }
            });
          }
        }
      } else {
        if (searchDialogConfig.tableEnabled) {
          if (!searchDialogConfig.tableRef || !tableData.length) return;
          let addRows = rows.map((rowData) => {
            let itemData = {};
            tableData.forEach((item) => {
              let targetFormField = trim(item.targetFormField || item.targetField);
              let sourceField = trim(item.sourceField)
              itemData[targetFormField] = rowData[sourceField];
            });
            return itemData;
          });
          let tableUniqueKey = trim(searchDialogConfig.tableUniqueKey);
          this.getWidgetRef(searchDialogConfig.tableRef).addTableData(
            addRows,
            tableUniqueKey
          );
        } else if (!multipleChoices) {
          tableData.forEach((item) => {
            let value = row[item.sourceField] ?? null;
            // formModel[item.targetField] = value
            // this.getWidgetRef(item.targetField).setValue(value);
            let targetField = trim(item.targetField)
            let targetFormField = trim(item.targetFormField)
            if (targetField) {
              this.getWidgetRef(targetField).setValue(value);
            } else if (targetFormField) {
              formModel[targetFormField] = value;
            }


          });
          // this.$forceUpdate();
        }
      }

      if (!isClear) {
        this.$nextTick(() => {
          this.handleCustomEvent(
            searchDialogConfig.confirmCallback,
            ["rows"],
            [rows]
          );
        });
      }
    },
    remoteQuery: function (e) {
      if (this.field.options.onRemoteQuery) {
        let t = new Function("keyword", this.field.options.onRemoteQuery);
        t.call(this, e);
      }
    },
    getFormRef: function () {
      return this.refList ? this.refList["v_form_ref"] : null;
    },
    getWidgetRef: function (e, t) {
      let i = this.refList[e];
      return (
        !i &&
        t &&
        this.$message.error(this.i18nt("render.hint.refNotFound") + e),
          i
      );
    },
    getFieldEditor: function () {
      return this.$refs["fieldEditor"];
    },
    initValue: function (e) {
        let value = e ?? null;
        let currentData =
          this.tableParam && this.tableParam.row
            ? this.tableParam.row
            : this.formModel;
        if (void 0 === currentData[this.fieldKeyName]) {
          this.$set(currentData, this.fieldKeyName, null);
        }
        this.fieldModel = value;
        this.initFileList();
        this.syncUpdateFormModel(value);
    },
    setValue: function (e) {
      if (this.field.formItemFlag) {
        let value = e ?? null;

        let currentData =
          this.tableParam && this.tableParam.row
            ? this.tableParam.row
            : this.formModel;
        if (void 0 === currentData[this.fieldKeyName]) {
          this.$set(currentData, this.fieldKeyName, null);
        }

        let t = baseRefUtil.deepClone(this.fieldModel);
        (this.fieldModel = value),
          this.initFileList(),
          this.syncUpdateFormModel(value),
          this.emitFieldDataChange(value, t);
      }
    },
    getValue: function () {
      return this.fieldModel;
    },
    resetField: function () {
      if (!this.subFormItemFlag) {
        let e = this.field.options.defaultValue;
        this.setValue(e),
        ("picture-upload" !== this.field.type &&
          "file-upload" !== this.field.type) ||
        (this.$refs["fieldEditor"].clearFiles(),
          this.fileList.splice(0, this.fileList.length));
      }
    },
    setWidgetOption: function (e, t) {
      this.field.options.hasOwnProperty(e) && (this.field.options[e] = t);
    },
    setReadonly: function (e) {
      this.field.options.readonly = e;
      this.readonly = e;
    },
    setDisabled: function (e) {
      this.field.options.disabled = e;
      this.disabled = e;
    },
    setAppendButtonVisible: function (e) {
      this.field.options.appendButton = e;
    },
    setAppendButtonDisabled: function (e) {
      this.field.options.appendButtonDisabled = e;
    },
    setHidden: function (e) {
      this.field.options.hidden = e;
      this.hidden = e;
      e ? this.clearFieldRules() : this.buildFieldRules();
    },
    setRequired: function (e) {
      (this.field.options.required = e), this.buildFieldRules();
    },
    setLabel: function (e) {
      this.field.options.label = e;
    },
    focus: function () {
      this.getFieldEditor() &&
      this.getFieldEditor().focus &&
      this.getFieldEditor().focus();
    },
    clearSelectedOptions: function () {
      ("checkbox" !== this.field.type &&
        "radio" !== this.field.type &&
        "select" !== this.field.type) ||
      ("checkbox" === this.field.type ||
      ("select" === this.field.type && this.field.options.multiple)
        ? (this.fieldModel = [])
        : (this.fieldModel = ""));
    },
    getOptionItemValueKey(){
      return this.field.options.valueKey || "value"
    },
    getOptionItemLabelKey(){
      return this.field.options.labelKey || "label"
    },
    loadRowGloatOptions: function (e) {
      let optionItems = baseRefUtil.translateOptionItems(
        e,
        this.field.type,
        this.getOptionItemLabelKey(),
        this.getOptionItemValueKey()()
      );
      // this.field.options.optionItems = optionItems
      this.setOptionItems(optionItems)
    },
    loadOptions: function (e, rowOptionFlag) {
      let optionItems = baseRefUtil.translateOptionItems(
        e,
        this.field.type,
        this.getOptionItemLabelKey(),
        this.getOptionItemValueKey()
      );
      // this.field.options.optionItems = optionItems
      this.setOptionItems(optionItems)
    },
    getOptionKey() {
      let key = "optionItems-" + this.field.options.name
      return key;
    },
    getOptionItemsFlag: function () {
      let key = this.getOptionKey()
      return this.getGlobalParam(key);
    },
    setOptionItemsFlag: function (flag) {
      let key = this.getOptionKey()
      return this.setGlobalParam(key, flag);
    },
    reloadOptions: function (e) {
      let optionItems = baseRefUtil.translateOptionItems(
        e,
        this.field.type,
        this.getOptionItemLabelKey(),
        this.getOptionItemValueKey()
      );
      // this.field.options.optionItems = optionItems;
      this.setOptionItems(optionItems)
    },
    getOptions: function () {
      return this.getOptionItems();
    },
    disableOption: function (e) {
      this.disableOptionOfList(this.getOptionItems(), e);
    },
    enableOption: function (e) {
      this.enableOptionOfList(this.getOptionItems(), e);
    },
    getOptionItems: function () {
      let optionItems = this.field.options.optionItems;
      return optionItems;
    },
    setUploadHeader: function (e, t) {
      this.$set(this.uploadHeaders, e, t);
    },
    setUploadData: function (e, t) {
      this.$set(this.uploadData, e, t);
    },
    setToolbar: function (e) {
      this.customToolbar = e;
    },
    isSubFormItem: function () {
      return this.subFormItemFlag;
    },
    isSubFormField: function () {
      return this.subFormItemFlag;
    },
    setReadMode: function () {
      let e =
        !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0];
      this.fieldReadonlyFlag = e;
    },
    addCssClass: function (e) {
      this.field.options.customClass
        ? this.field.options.customClass.push(e)
        : (this.field.options.customClass = [e]);
    },
    removeCssClass: function (e) {
      if (this.field.options.customClass) {
        let t = -1;
        this.field.options.customClass.map(function (i, n) {
          i === e && (t = n);
        }),
        t > -1 && this.field.options.customClass.splice(t, 1);
      }
    },
    async initAccess() {
      if (this.field.options.accessCode) {
        return this.$http({
          url: SUPPORT_PREFIX + `/report_requestaccess/getByCode`,
          method: `post`,
          data: {
            stringOne: this.field.options.accessCode,
          },
          isLoading: true,
          // modalStrictly: true,
          success: (res) => {
            let requestAccess = res.objx || {};

            let dsModel = {};
            if (requestAccess.accessViewContent) {
              dsModel = JSON.parse(requestAccess.accessViewContent);
            }
            if (!dsModel.headers) dsModel.headers = [];
            if (!dsModel.params) dsModel.params = [];
            if (!dsModel.data) dsModel.data = [];
            if (dsModel.dataHandlerCode === null || dsModel.dataHandlerCode === undefined) dsModel.dataHandlerCode = "";
            if (dsModel.configHandlerCode === null || dsModel.configHandlerCode === undefined)
              dsModel.configHandlerCode = "";
            if (dsModel.errorHandlerCode === null || dsModel.errorHandlerCode === undefined) dsModel.errorHandlerCode = "";

            requestAccess.dsModel = dsModel;
            this.requestAccess = requestAccess;
          },
        });
      } else {
        return null;
      }
    },
    addExtraAccessData(data) {
      if (data) {
        Object.keys(data).forEach((field) => {
          this.extraAccessData[field] = data[field];
        });
      }
    },
    clearExtraAccessData() {
      this.extraAccessData = {};
    },
    doAccess(accessCode, conditions, callback) {
      let path = baseRefUtil.getAccessUrl();
      let globalReqData = baseRefUtil.getReportGlobalMap(); //全局请求参数
      return this.$http({
        url: path,
        method: `post`,
        loadingTarget: document.body,
        data: {
          accessCode: accessCode,
          conditions: {
            ...conditions,
            ...globalReqData,
          },
        },
        isLoading: true,
        success: (res) => {
          callback && callback(res);
        },
      });
    },
    autoExcScript() {
      if (!this.designState && this.field.options.accessAutoExc) {
        this.scriptHttp({
          options: this.field.options,
        });
      }
    },
    addInterval(handler, timeout) {
      let timer = setInterval(handler, timeout);
      this.timerMap[timer] = timer;
      return timer;
    },
    clearAllInterval() {
      let timerMap = this.timerMap;
      for (let key in timerMap) {
        let timer = timerMap[key];
        clearInterval(timer);
      }
      this.timerMap = {};
    },
    getI18nLabel(label, path, param) {
      return !this.designState && label ? this.$t2(label, path, param) : label;
    },
    getParentTarget() {
      let name = this.parentWidget?.options?.name ?? null;
      return name ? this.getWidgetRef(name) : null;
    },
    setWidgetTextFlag(val) {
      this.widgetTextFlag = val;
    },
    showWidget() {
      this.widgetTextFlag = 0;
    },
    showText() {
      this.widgetTextFlag = 1;
    },
    showEncryptText() {
      this.widgetTextFlag = 2;
    },
    showAText() {
      this.widgetTextFlag = 3;
    },
    getAuthCode(){
      let formRef = this.getFormRef();
      if(formRef){
        return formRef.reportTemplate.formCode + ":" + this.field.options.name;
      }

    }
  },
};

export default modules;
