<template>
  <view class="cv-dialog-bottom__wrap" :class="isLastShow ? 'show' : ''">
    <view class="cv-dialog-bottom__mask" @click.stop="maskClick"></view>
    <view class="cv-dialog-bottom__box">
      <view class="cv-dialog-bottom__bar">
        <view class="cv-dialog-bottom__bar-left" v-if="showLeft" @tap="cancel">取消</view>
        <view class="cv-dialog-bottom__bar-title">
          <slot name="title">{{ title }}</slot>
        </view>
        <view class="cv-dialog-bottom__bar-right" v-if="showRight" @tap="confirm">确定</view>
      </view>
      <view class="cv-dialog-bottom__body" :style="bodyClass">
        <slot name="default" />
      </view>
    </view>
  </view>
</template>
<script>
import mpMixin from '../../libs/mixin/mpMixin.js';
import mixin from '../../libs/mixin/mixin.js';
export default {
  mixins: [mpMixin, mixin],
  name: 'cvDialogBottom',
  emits: ['cancel', 'confirm'],
  props: {
    show: {
      type: Boolean,
      default: false
    },
    bodyClass: {
      type: [String],
      default: ''
    },
    isMaskClick: {
      type: Boolean,
      default: true
    },
    showLeft: {
      type: Boolean,
      default: true
    },
    showRight: {
      type: Boolean,
      default: true
    },
    title: {
      type: [String],
      default: ''
    }
  },
  watch: {},
  computed: {
    isLastShow() {
      return this.localShow || this.show;
    }
  },
  data() {
    return {
      localShow: false
    };
  },
  created() {},
  methods: {
    open() {
      this.localShow = true;
    },
    close() {
      this.localShow = false;
    },
    confirm() {
      this.close();
      this.$emit('confirm');
    },
    cancel() {
      this.close();
      this.$emit('cancel');
    },

    maskClick() {
      if (this.isMaskClick) {
        this.close();
      }
    }
  }
};
</script>
<style>
.cv-dialog-bottom__wrap {
  background: rgba(0, 0, 0, 0.6);
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 999;
  opacity: 0;
  width: 100%;
  outline: 0;
  backface-visibility: hidden;
  -webkit-perspective: 1104px;
  perspective: 1104px;
  pointer-events: none;
  text-align: center;
  transform: scale(1.185);
  transition: all 0.3s ease-in-out 0s;
  margin-bottom: -552px;
  display: flex;
  flex-direction: column;
}
.cv-dialog-bottom__mask {
  flex: 1;
  min-height: 60px;
}
.cv-dialog-bottom__wrap.show {
  opacity: 1;
  overflow-x: hidden;
  overflow-y: auto;
  pointer-events: auto;
  transition-duration: 0.3s;
  transform: scale(1);
  margin-bottom: 0;
}
.cv-dialog-bottom__box {
  display: inline-block;
  vertical-align: middle;
  margin-left: auto;
  margin-right: auto;
  width: 375px;
  max-width: 100%;
  width: 100%;
  background-color: #f8f8f8;
  border-radius: 0;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  overflow: hidden;
}
.cv-dialog-bottom__bar {
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  min-height: 45px;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  background-color: #ffffff;
  color: #666666;
  padding: 0 10px;
  font-size: 15px;
}
.cv-dialog-bottom__bar-title {
  flex: 1;
  display: flex;
  justify-content: center;
  font-size: 15px;
  font-weight: 400;
}
.cv-dialog-bottom__bar-left {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 55px;
  color: #0081ff;
}
.cv-dialog-bottom__bar-right {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 55px;
  color: #39b54a;
}
.cv-dialog-bottom__body {
  padding: 10px;
  overflow: auto;
  background-color: #fff;
}
</style>
