<template>
  <Dialog
    ref="dialog"
    width="542px"
    height="450px"
  >
    <img v-audio class="close btn" src="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/Rectangle%201175%20copy.png" alt="" @click="visible = false">
    <div class="bg"/>
    <div class="content">
      <div class="title">设置</div>
      <div class="message">
        <div class="box">
          <AudioSize :value="volumeMachine" title="机器音效" @on-change="(value) => handler().changeAudioMachine(value)" />
          <AudioSize :value="volumeBg" title="背景音乐" @on-change="(value) => handler().changeAudioBg(value)" />
          <AudioSize :value="volumeButton" title="按键音效" @on-change="(value) => handler().changeAudioButton(value)" />
        </div>
      </div>
      <div class="dialog-footer">
        <div v-audio class="btn" type="primary" @click="cancel"/>
      </div>
    </div>
  </Dialog>
</template>

<script>
import Dialog from '@/components/dialog/index'
import AudioSize from './audio-size'
import { mapState, mapMutations, } from 'vuex'
export default {
  components: {
    Dialog,
    AudioSize,
  },
  props: {
  },
  data() {
    return {
      visible: false,
    }
  },
  computed: {
    ...mapState([
      'zoom',
    ]),
    ...mapState('audio', [
      'volumeMachine',
      'volumeBg',
      'volumeButton',
    ]),
  },
  watch: {
    visible(value) {
      if (value) {
        this.$refs.dialog.show()
      } else {
        this.$refs.dialog.close()
      }
    },
  },
  created() {
  },
  methods: {
    ...mapMutations('audio', [
      'SetVolumeMachine',
      'SetVolumeBg',
      'SetVolumeButton',
    ]),
    cancel() {
      this.visible = false
    },
    show() {
      this.visible = true
    },
    handler() {
      return {
        // 设置机器声音
        changeAudioMachine: (value) => {
          this.SetVolumeMachine(value)
        },
        // 设置背景音
        changeAudioBg: (value) => {
          this.SetVolumeBg(value)
        },
        // 设置按键音
        changeAudioButton: (value) => {
          this.SetVolumeButton(value)
        },
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.close {
  position: absolute;
  right: 4px;
  top: 0;
  width: 40px;
  z-index: 10;
}
.bg {
  background-image: url(https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/pop_up_bg.png);
  background-size: 100% 100%;
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 1;
  top: 0;
  left: 0;
}
.content {
  position: relative;
  z-index: 2;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 20px 30px;
  box-sizing: border-box;
  .title {
    text-align: center;
    font-size: 28px;
    font-weight: bold;
    color: white;
    margin-top: 20px;
  }
  .message {
    text-align: center;
    color: white;
    margin-top: 10px;
    font-size: 18px;
    flex: 1;
    .box {
      width: 300px;
      margin: auto;
    }
  }
  .dialog-footer {
    padding-bottom: 20px;
    display: flex;
    justify-content: center;
    .btn {
      background-image: url(https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/chinese/logout_sel_zh.png);
      background-size: 100% 100%;
      width: 400px;
      height: 40px;
      opacity: 0.80;
      text-align: center;
      line-height: 40px;
      color: #5e4926;
      font-size: 18px;
      font-weight: bold;
      margin: 0 36px;
      &:hover {
        opacity: 1;
      };
      &:active {
        opacity: 0.80;
      }
    }
  }
  .footer-tip {
    height: 30px;
    line-height: 30px;
    text-align: right;
    padding: 4px 16px;
    font-size: 12px;
    color: #bc9a6c;
  }
}
/deep/ .game-dialog {
  position: relative;
  background: transparent;
  height: 320px;
  padding: 0;
  .el-dialog__header {
    padding: 0;
  }
  .el-dialog__body {
    max-height: inherit;
    padding: 0;
    overflow: hidden;
    height: 100%;
    box-sizing: border-box;
  }
}
</style>
