popup.vue 1.75 KB
<template>
  <van-popup
    :model-show="props.showPopup"
    round
    @close="close"
    :close-on-click-overlay="true"
    :position="props.position"
  >
    <div class="content-box">
      <div class="btn-class">
        <button class="cancel-btn" @click="cancel">取消</button>
        <button
          class="save-btn"
          :class="isDisabled ? 'disabled' : ''"
          @click="save"
          v-preventReClick
        >
          {{ isDisabled ? "关闭" : "确定" }}
        </button>
      </div>
      <slot></slot>
    </div>
  </van-popup>
</template>

<script>
import { defineComponent } from "vue";
export default defineComponent({
  name: "PopupCom",
  props: {
    showPopup: {
      type: Boolean,
      default: false,
    },
    position: {
      type: String,
    },
    isDisabled: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, { emit }) {
    const cancel = () => {
      emit("btnCancel");
    };
    const close = () => {
      emit("btnCancel");
    };
    const save = () => {
      if (props.isDisabled) {
        emit("btnCancel");
      } else {
        emit("btnSave");
      }
    };
    return {
      cancel,
      save,
      props,
      close,
    };
  },
});
</script>
<style lang="scss">
.content-box {
  display: flex;
  align-items: center;
  background: #fff;
  flex-flow: column;
  border-radius: 0 0 16px 16px;
  overflow: hidden;
  padding-bottom: 40px;
  .btn-class {
    padding: 15px;
    box-sizing: border-box;
    border-bottom: 1px solid #f0f2f5;
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    .cancel-btn {
      color: #6c737a;
    }
    .save-btn {
      color: var(--base-color);
    }
    .save-btn.disabled {
      color: #6c737a;
    }
  }
}
</style>