<template>
  <div>
    <el-form
      inline
      :model="form"
      ref="form"
      class="form-wrap dialog-info"
      label-width="100px">

      <el-form-item
        verify
        class="is-required"
        label="新景区名称"
        prop="projectNickName">
        <el-input v-model="form.projectNickName"></el-input>
      </el-form-item>

    </el-form>
    <div class="dialog-btn-wrap">
      <el-button @click="handleClose">关闭</el-button>
      <el-button
        @click="submit"
        type="primary">保存</el-button>
    </div>
  </div>
</template>

<script>
import { updateProject } from '@/api/systemSetting/project'

export default {
  props: {
    projectInfo: {
      type: Object,
      default: () => {}
    }
  },
  computed: {

  },
  data () {
    return {
      visible: false,
      form: {
        projectName: '',
        projectNickName: ''
      }
    }
  },
  methods: {
    handleClose () {
      this.$parent.handleClose()
    },
    reset () {
      this.$refs.form.resetFields()
    },
    submit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.updateProject()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    updateProject () {
      updateProject({projectNickName: this.form.projectNickName}).then(res => {
        this.$message.success('保存成功')
        this.reset()
        this.handleClose()
        this.$emit('updateList')
      })
    }
  },
  watch: {
    visible (val) {
      // 初始化编辑数据
      if (val) {
        this.form = JSON.parse(JSON.stringify(this.projectInfo))
      } else {
        // 重置表单
        this.reset()
      }
    }

  }
}
</script>

<style scoped>
.btn-wrap{
  padding-right: 20px;
}
</style>
