<template>
  <el-dialog
    :visible.sync="visible"
    :width="width"
    :show-close="false"
    :close-on-click-modal="false"
    :append-to-body="appendToBody"
    @closed="close"
  >
    <div slot="title" class="hearders">
      <div class="leftTitle">{{ title }}</div>
      <div class="rightBoxs">
        <img
          src="@/assets/images/Close@2x.png"
          alt=""
          @click="visible = false"
        />
      </div>
    </div>
    <slot></slot>
    <div slot="footer" class="dialog-footer" v-if="isShowFooter">
      <el-button :loading="disabledBtn" @click="visible = false">{{
        cancelName
      }}</el-button>
      <el-button :loading="disabledBtn" type="primary" @click="confirmBtn">{{
        confirmName
      }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "BaseDialog",
  props: {
    title: {
      type: String,
      default: "",
    },
    isShow: {
      type: Boolean,
      default: false,
    },
    width: {
      type: String,
      default: "600px",
    },
    cancelName: {
      type: String,
      default: "取 消",
    },
    confirmName: {
      type: String,
      default: "确 定",
    },
    isShowFooter: {
      type: Boolean,
      default: true,
    },
    appendToBody: {
      type: Boolean,
      default: false,
    },
    disabledBtn: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  methods: {
    confirmBtn() {
      this.$emit("submit", "123");
    },
    close() {
      this.$emit("close");
    },
  },
  computed: {
    visible: {
      get() {
        return this.isShow;
      },
      set(val) {
        this.$emit("update:isShow", false);
      },
    },
  },

  watch: {
    visible(val) {
      // 在此做显示与隐藏的交互
      if (val === false) {
        // 重置操作
      } else {
        // 展示时操作
      }
    },
  },
};
</script>

<style scoped lang="scss">
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
/deep/.el-button {
  border-radius: 8px;
}
</style>
