<template>
  <div>
    <el-form-item label="点击绑定事件">
      <el-select v-model="optionModel.clickBindEvent" clearable>
        <el-option value="1" label="打开选择弹框"></el-option>
        <el-option value="2" label="列表添加数据"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="点击前置事件" label-width="150px">
      <a href="javascript:void(0);" class="a-link link-oneLind"
         @click="editEventHandler('onBeforeClickButton', evnentParams)">
        <span>{{ optionModel.onBeforeClickButton }}</span>
        <i class="el-icon-edit"></i>
      </a>
    </el-form-item>
    <searchDialogEventEditor :designer="designer" :selectedWidget="selectedWidget" :optionModel.sync="optionModel"
                             v-if="optionModel.clickBindEvent=='1'"></searchDialogEventEditor>
    <addTableDataEventEditor :designer="designer" :selectedWidget="selectedWidget" :optionModel.sync="optionModel"
                             v-if="optionModel.clickBindEvent=='2'"></addTableDataEventEditor>
  </div>
</template>
<script>
import searchDialogEventEditor from "./search-dialog-event-editor.vue";
import addTableDataEventEditor from "./addTableData-event-editor.vue";
import {defaultSearchDialogConfig} from "../../../../../../components/xform/form-designer/widget-panel/widgetsConfig";

import i18n from "../../../../../../components/xform/utils/i18n";
import eventMixin
  from "../../../../../../components/xform/form-designer/setting-panel/property-editor/event-handler/eventMixin";

let clickBindEventConfig = {
  searchDialogConfig: {
    ...defaultSearchDialogConfig
  },
  addTableDataConfig: {
    tableRef: null,
    tableData: {}
  }
}

export default {
  name: "clickBindEvent-editor",
  mixins: [i18n, eventMixin],
  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },
  components: {
    searchDialogEventEditor,
    addTableDataEventEditor
  },
  provide() {
    return {
      defaultClickBindEventConfig: clickBindEventConfig
    }
  },
  data() {
    return {
      evnentParams: ["dataId", "formCode", "done"]
    }
  },
  created() {
    if (!this.optionModel.addTableDataConfig) {
      this.$set(this.optionModel, 'addTableDataConfig', this.$baseLodash.cloneDeep(clickBindEventConfig.addTableDataConfig));
    }
    if (!this.optionModel.searchDialogConfig) {
      this.$set(this.optionModel, 'searchDialogConfig', this.$baseLodash.cloneDeep(clickBindEventConfig.searchDialogConfig));
    }
    if (this.optionModel.searchDialogConfig.multipleChoices === void 0) {
      if (this.selectedWidget.type == 'vabsearch') {
        this.$set(this.optionModel.searchDialogConfig, 'multipleChoices', false);
      } else {
        this.$set(this.optionModel.searchDialogConfig, 'multipleChoices', true);
      }
    }
  },
  methods: {
    changeEventType(val) {
      // this.optionModel.clickBindEventConfig = clickBindEventConfig;
      // this.$set(this.optionModel, "clickBindEventConfig", clickBindEventConfig);
    }
  }
}
</script>
<style scoped>

</style>
