<template>
  <el-dialog
    title="编辑"
    :visible.sync="dialogVisible"
    width="30%"
    :close-on-click-modal='false'
    :before-close='handleClose'
  >
    <el-form ref="form" :rules="rules" :model="form" label-width="120px">
      <el-form-item label="按钮名称:" prop="title">
        <el-input v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="跳转链接:" prop="src">
        <el-input v-model="form.src" placeholder="请输入以http://或https://开头的完整路径"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: "",
  props: {
    btnTitle: {
      type: String,
      default:"立即体验"
    },
    btnSrc: {
      type: String,
    },
  },
  data() {
    return {
      dialogVisible: false,
      form: {
        title: "立即体验",
        src: "",
      },
      rules: {
        title: [
          { required: true, message: "请输入按钮名称", trigger: "blur" },
          { min: 1, max: 9, message: "长度在 1 到 9 个字符", trigger: "blur" },
        ],
        src: [{ required: true, message: "请输入跳转链接", trigger: "blur" }],
      },
    };
  },
  methods: {
    handleClose() {
        this.$refs.form.resetFields();
        this.dialogVisible=false
    },
    handleConfirm() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.$emit('handleSuccess',this.form)
            this.handleClose()
          }
        });
    },
  },
  watch:{
      dialogVisible(newVal){
          if(newVal){
              this.form.title = this.btnTitle
              this.form.src = this.btnSrc
          }
      }
  }
};
</script>

<style lang='scss' scoped>
</style>