modal.vue 2.22 KB
<template>
  <div class="modal-box" v-show="value" v-transfer-dom :data-transfer="transfer">
    <div class="modal-mask"></div>
    <div class="modal-wrap" @touchmove.prevent.stop="onTouchmove">
      <div class="modal modal-content">
        <div class="modal-body">
          <slot>
            <div class="text">{{title}}</div>
          </slot>
        </div>
        <div class="modal-footer">
          <slot name="footer">
            <Button class="btn" type="button" @click="onCancel">取消</Button>
            <Button class="btn" type="button" @click="onSure">调整售价</Button>
          </slot>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Button from 'components/button.vue';

export default {
  name: 'Modal',
  props: {
    transfer: [Boolean],
    title: String,
    value: Boolean
  },
  methods: {
    onTouchmove() {},
    onCancel() {
      this.$emit('on-cancel');
      this.$emit('input', false);
    },
    onSure() {
      this.$emit('on-sure');
    }
  },
  components: {Button}
};
</script>

<style lang="scss">
.modal-box {
  font-size: 24px;
}

.modal-mask {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.4);
  height: 100%;
  z-index: 1000;

  &-hidden {
    display: none;
  }
}

.modal {
  width: auto;
  margin: 0 auto;
  position: relative;
  outline: none;

  &-hidden {
    display: none !important;
  }

  &-wrap {
    position: fixed;
    overflow: auto;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    -webkit-overflow-scrolling: touch;
    outline: 0;
  }

  &-content {
    position: relative;
    background-color: #fff;
    top: 314px;
    border: 0;
    width: 600px;
    background-clip: padding-box;

    & .text {
      text-align: center;
      padding-top: 30px;
      padding-bottom: 30px;
    }
  }

  &-body {
    padding: 38px;
  }

  &-footer {
    width: 100%;
    border-top: 1px solid #eee;
    display: flex;

    button {
      width: 50%;
      overflow: hidden;
      height: 100px;
      background: none;

      &:first-child {
        color: #999;
      }
    }

    button + button {
      margin-left: 8px;
      margin-bottom: 0;
      border-left: 1px solid #eee;
    }
  }
}
</style>