<template>
  <div>
    <el-dialog title="外部地址" :append-to-body="true" :visible.sync="isShow" class="input-external-link-dlg" @open="beforeDialogOpen">
      <el-form :model="link" :rules="linkRules" ref="form" label-width="25%">
        <el-form-item label="地址：" prop="URL">
          <el-input v-model="link.URL" :style="{width:'75%'}" ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="isShow= false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import util from '@src/common/util.js'
export default {
  props: {show: Boolean},
  data() {
    return {
      link: {URL: ''}, // 链接地址
      linkRules: {
        URL: [{ required: true, message: '不能为空', trigger: 'blur,change' }]
      }
    }
  },
  computed: {
    isShow: {
      get() {
        return this.show
      },
      set(val) {
        this.$emit('update:show', val)
      }
    }
  },
  methods: {
    beforeDialogOpen() {
      this.link.URL = 'http://'
    },
    // 得到外部地址
    async confirm() {
      try {
        await util.validateForm(this.$refs['form'])
      } catch (e) {
        this.submitLoading = false
        util.showErrorMessageBox(e)
        return
      }
      this.$emit('update:show', false)
      this.$emit('callback', this.link.URL)
    }
  }
}
</script>
<style>
.input-external-link-dlg .el-dialog{
  width:400px;
}
@media (max-width:480px){
  .input-external-link-dlg .el-dialog{
    width:96%;
  }
}
</style>
