<template lang="html">
  <div class="databaseDeleteVue pop-up">
    <div class="title">
      删除数据库
      <i class="close" @click="close()"></i>
    </div>
    <div class="main">
      <p>是否确认删除以下{{ checkedDatabase.length }}个数据库？</p>
      <ul>
        <li class="lengthLimit" v-for="n,i in checkedDatabase">{{ n.dbName }}</li>
      </ul>
    </div>
    <div class="btns">
      <button type="button" class="btn3" @click="submit()">确认</button>
      <button type="button" class="btn3" @click="close()">返回</button>
    </div>
  </div>
</template>

<script>
import { bus, requestDeleteServer } from '@/vuex/request.js'

export default {
  data () {
    return {
    }
  },
  props: ['checkedDatabase'],
  mounted () {
    // 弹框弹出动画
    window.$(() => {
      bus.$emit('pop-up-show', '.databaseDeleteVue.pop-up')
    })
  },
  methods: {
    // 关闭弹窗&动画
    close () {
      window.$(() => {
        bus.$emit('pop-up-close', '.databaseDeleteVue.pop-up')
        setTimeout(() => {
          window.$('#generationTime').DatePickerClear()
          this.$emit('close')
        }, 500)
      })
    },
    submit () {
      let data = {
        serverid: this.checkedDatabase.map((n, i) => {
          return n.id
        })
      }
      requestDeleteServer({}, data, (response) => {
        if (response.data) {
          if (response.data.state) {
            bus.$emit('alert', response.data.message)
            this.$emit('update')
            this.$emit('clear-checkbox')
            this.$emit('close')
          } else {
            bus.$emit('alert', response.data.message)
          }
        } else {
          bus.$emit('alert', response + '.')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.databaseDeleteVue{
  width: 500px;
  .main{
    p{
      font-size: 16px;
      margin-bottom: 20px;
    }
    ul{
      padding-left: 20px;
      margin-bottom: 50px;
      max-height: 150px;
      overflow-y: auto;
      li{
        display: list-item;
        list-style-type: circle;
        line-height: 1.5;
        overflow: visible;
        max-width: 400px;
      }
    }
  }
}
</style>
