<template>
  <view>
    <uni-popup
      ref="popup"
      type="bottom"
      :title="title"
      :mask-click="true"
      closeable
      @change="onChange"
    >
      <view class="action-sheet">
        <!-- #ifdef MP-ALIPAY	-->
        <slot />
        <!-- #endif -->
        <!-- #ifndef MP-ALIPAY -->
        <slot>
          <view class="content" />
        </slot>
        <!-- #endif -->
        <slot name="footer">
          <view v-if="actionText" class="footer">
            <button class="action-btn" type="default" @click="onConfirm">
              {{ actionText }}
            </button>
          </view>
        </slot>
      </view>
    </uni-popup>
  </view>
</template>
<script>
import  uniPopup  from "@/components/uni-popup/uni-popup";
export default {
  name: "ActionSheet",
  components: {
    uniPopup
  },
  props: {
    title: {
      type: String,
      default: ""
    },
    showClose: {
      type: Boolean,
      default: true
    },
    closeIconSize: {
      type: Number,
      default: 18
    },
    actionText: {
      type: String,
      default: ""
    }
  },
  methods: {
    /**
     * @exposed-api
     */
    open() {
      this.$refs.popup.open();
    },
    /**
     * @exposed-api
     */
    close() {
      this.$refs.popup.close();
    },
    onChange(e) {
      // 点击遮罩关闭时触发
      if (e.show === false) {
        this.$emit("close");
      }
    },
    onConfirm() {
      this.$emit("confirm");
      this.close();
    },
    onClose() {
      this.close();
      this.$emit("close");
    }
  }
};
</script>
<style lang="scss" scoped>
.action-sheet {
  background-color: $uni-bg-color;
  // border-radius: 12rpx 12rpx 0 0;
  display: flex;
  flex-direction: column;

  .header {
    padding: 36rpx 36rpx 20rpx 36rpx;
    display: flex;
    flex: 1;
    flex-direction: row;
    justify-content: center;
    align-items: center;

    .title {
      flex: 1;
      text-align: center;
      font-size: 32rpx;
      line-height: 44rpx;
      color: #333;
    }
    .close {
      color: #dcdcdc;
    }
  }

  .content {
    padding: 0 30rpx;
  }

  .footer {
    padding: 20rpx 30rpx;

    .action-btn {
      @include primary-bg;
      color: white;
      font-size: $uni-font-size-base;
      font-weight: bold;
      border-radius: $uni-border-radius-xl;
    }
  }
}
</style>
