<template>
  <div>
    <BaseDialog
      width="400px"
      :isShow.sync="isShow"
      :title="activeData.tenantId ? '修改' : '新增'"
      @submit="submitForm"
      @close="close"
    >
      <el-form
        :model="formData"
        :rules="rules"
        ref="formData"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="标题：" prop="tenantName">
          <el-input
            clearable
            v-model="formData.tenantName"
            placeholder="输入标题"
          ></el-input>
        </el-form-item>
        <el-form-item label="业务归属：" prop="openingName"
          ><el-input
            clearable
            v-model="formData.openingName"
            placeholder="选择业务归属"
          ></el-input>
        </el-form-item>
        <el-form-item label="账户类型：" prop="openingName"
          ><el-input
            clearable
            v-model="formData.openingName"
            placeholder="选择账户类型"
          ></el-input>
        </el-form-item>
        <el-form-item label="开户名：" prop="openingName"
          ><el-input
            clearable
            v-model="formData.openingName"
            placeholder="输入开户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="开户行：" prop="openingBank"
          ><el-input
            clearable
            v-model="formData.openingBank"
            placeholder="输入开户行"
          ></el-input>
        </el-form-item>
        <el-form-item label="银行账号：" prop="proceedsAccount"
          ><el-input
            clearable
            v-model="formData.proceedsAccount"
            placeholder="输入银行账号"
          ></el-input>
        </el-form-item>
      </el-form>
    </BaseDialog>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    activeData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      formData: {
        tenantName: "",
        openingName: "",
        openingBank: "",
        proceedsAccount: "",
      },
      rules: {
        tenantName: [
          { required: true, message: "请输入机构名称", trigger: "blur" },
        ],
        openingName: [
          { required: true, message: "请输入开户名", trigger: "blur" },
        ],
        openingBank: [
          { required: true, message: "请输入开户行", trigger: "blur" },
        ],
        proceedsAccount: [
          { required: true, message: "请输入账号", trigger: "blur" },
        ],
      },
      days: [],
    };
  },
  methods: {
    init() {
      this.formData = JSON.parse(JSON.stringify(this.activeData));
      if (!this.formData.tenantId) {
        this.formData = {
          tenantName: "",
          openingName: "",
          openingBank: "",
          proceedsAccount: "",
        };
      }
    },
    close() {
      this.$refs["formData"].resetFields();
    },
    submitForm() {
      this.$refs["formData"].validate((valid) => {
        if (valid) {
          this.$api[
            this.activeData.tenantId ? "systemtenantedittop" : "systemtenantadd"
          ](this.formData).then((res) => {
            this.$message.success("成功");
            this.$store.commit("TENANTLIST");
            this.isShow = false;
            this.$emit("search");
          });
        } else {
          return false;
        }
      });
    },
  },
  computed: {
    isShow: {
      get() {
        if (this.dialogVisible) {
          this.init();
        }
        return this.dialogVisible;
      },
      set(val) {
        this.$emit("update:dialogVisible", false);
      },
    },
  },
};
</script>

<style lang="scss" scoped>
.el-input {
  width: 220px;
  margin-right: 10px;
}
.el-select {
  width: 220px;
  margin-right: 10px;
}
</style>
