<template>
  <div class="tuitui-toast" catchtouchmove="disMove">
    <div class='toast-mask' v-if='showMask' @click='maskClick'></div>
    <div class='toast-content'>
      <div class='toast-icon' v-if='icon'>
        <img :src='iconImg[icon]' alt="icon">
      </div>
      <div class='title' v-if='title'>{{title}}</div>
      <div class='sub-title' v-if='subTitle'>{{subTitle}}</div>
      <div class='message' v-if='message'>{{message}}</div>
      <div class='btns' v-if='btns.length'>
        <div v-for='item in btns' :key='item.name' @click='item.fn' :class='item.fontColor + " bg-" + item.bgColor'>
          {{item.name}}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/*
toastConfig = {
  icon: 'success', [success, failed]
  title: '标题',
  subTitle: '副标题',
  message: '内容',
  maskClick: 背景点击事件,
  btns: [ // 按钮配置事件
    {
      name: '取消', // 文案
      fontColor: 'black', // 字体颜色 【blue, white, black】
      bgColor: 'white', // 背景颜色[blue, white]
      fn: this.toggleToast // 点击事件
    }
  ]
}
*/
const iconImg = {
  success: '/static/images/success.png',
  error: '/static/images/error.svg'
}
export default {
  props: {
    title: ['String'],
    subTitle: ['String'],
    icon: ['String'],
    message: ['String'],
    maskClick: ['Function'],
    showMask: {
      type: Boolean,
      default () {
        return true
      }
    },
    btns: {
      type: Array,
      default () {
        return [
          {
            name: '取消',
            fontColor: 'black',
            bgColor: 'white',
            fn: () => {
              console.log('click cancel')
            }
          },
          {
            name: '确定',
            fontColor: 'blue',
            bgColor: 'white',
            fn: () => {
              console.log('click confirm')
            }
          }
        ]
      }
    }
  },
  data: () => {
    return {
      iconImg
    }
  },
  methods: {
    close: () => {
      console.log('close')
    }
  }
}
</script>

<style scoped>
.tuitui-toast {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.toast-mask {
  background: #000000;
  opacity: 0.5;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  min-height: 100vh;
}

.toast-content {
  width: 670px;
  border-radius: 10px;
  margin: 0 auto;
  text-align: center;
  z-index: 105;
  background: #fff;
  position:relative;
  margin-top: 50%;
  transform: translateY(-30%);
  padding-top: 64px;
}

.tuitui-toast .btns {
  display: flex;
  border-top: solid 2px #E5E5E5;
  margin-top: 64px;
}
.tuitui-toast .btns > div {
  flex: 1;
  font-size: 32px;
  font-weight: 600;
  text-align: center;
  height: 88px;
  line-height: 88px;
  border-right: solid 2px #EBEBEB;
}
.tuitui-toast .btns > div:first-child {
  border-bottom-left-radius: 10px;
}
.tuitui-toast .btns > div:last-child {
  border-bottom-left-radius: 10px;
  border-right: none;
}
.title {
  font-size: 36px;
  font-weight: 600;
  text-align: center;
  height: 100px;
  line-height: 100px;
  color: #222;
  padding: 0 40px;
}
.sub-title {
  font-size: 30px;
  font-weight: 600;
  text-align: center;
  line-height: 40px;
  padding: 0 40px;
}
.message {
  font-size: 28px;
  line-height: 40px;
  margin-top: 20px;
  padding: 0 40px;
  color: #999;
}
.toast-icon {
  display: flex;
  justify-content: center;
}
.toast-icon img{
  width: 72px;
  height: 72px;
}
.bg-blue {
  background-color: #2477FA;
}
.bg-white {
  background-color: #fff;
}
.blue {
  color: #2477FA;
}
.white {
  color: #fff;
}
.black {
  color: #222;
}

</style>

