<template>
  <el-dialog
    :visible.sync="visible"
    :title="title"
    :modal-append-to-body="false"
    :width="`${percentWidth}%`"
    @close="handleCancel"
  >
    <el-tabs
      v-model="activeName"
      @tab-click="tabClick"
    >
      <el-tab-pane
        label="基本信息"
        name="first"
      ><PublicFormWithTitle
        ref="publicFormWithTitle"
        :form-arr="formArrFirst"
        :form-data="formData"
        @outOperation="outOperation"
      /></el-tab-pane>
      <el-tab-pane
        label="扩展信息"
        name="second"
      ><PublicForm
        ref="publicForm"
        :form-arr="formArrSecond"
        :form-data="formData"
        @outOperation="outOperation"
      /></el-tab-pane>
    </el-tabs>
    <span
      slot="footer"
      class="dialog-footer"
    >
      <el-button
        type="primary"
        @click="dialogOK"
      >保 存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import PublicFormWithTitle from './formWithTitle.vue';
import PublicForm from '@/components/form/index.vue';
export default {
  components: {
    PublicFormWithTitle,
    PublicForm,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: '',
    },
    formArrFirst: {
      type: Array,
      required: true,
    },
    formArrSecond: {
      type: Array,
      required: true,
    },
    percentWidth: {
      type: Number,
      default: 30,
    },
    formData: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      activeName: 'first',
    };
  },
  methods: {
    handleCancel() {
      console.log('我是formArr', this.formArrFirst, this.FormArrSecond, this.activeName);
      this.$emit('handleCancel');
    },
    outOperation(val, index, prop, num) {
      console.log('我是outOperation', val, index, prop, num);
    },
    dialogOK() {
      // 判断表单验证是否通过
    //   if (this.$refs.publicFormWithTitle.submitForm()) {
    //     console.log('success');
    //     console.log(this.formData);
    //     if (this.title === '新增') {
    //       this.$emit('dialogOK', this.formData, 1);
    //     } else if (this.title === '编辑') {
    //       this.$emit('dialogOK', this.formData, 2);
    //     }
    //   } else {
    //     console.log('error');
    //   }
    },
    tabClick(tab, event) {
      console.log(tab, event);
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .titiebox .titieboxlabel {
  white-space: nowrap;
}
</style>
