<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
    <el-form ref="form" label-width="80px" :model="form" :rules="regEdit">
      <el-form-item label="区域描述" prop="regionDesc">
        <el-input v-model.trim="form.regionDesc" />
      </el-form-item>
      <el-form-item label="负责人" prop="userName">
        <el-input v-model.trim="form.userName" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.remark" type="textarea" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import regionApi from '@/api/base/region/region'

  export default {
    name: 'Edit',
    data() {
      return {
        form: {
          regEdit: [],
        },
        regEdit: {
          regionDesc: [{ required: true, trigger: 'blur', message: '请填写区域' }],
          userName: [{ required: true, trigger: 'blur', message: '请填写区域负责人' }],
        },
        title: '',
        dialogFormVisible: false,
        //省份
        district: [],
        //区域
        options: [],
        provinceCode: '',
        // 区域
        regionId: '',
        vaule: '',
      }
    },
    created() {},
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '编辑'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            if (this.form.id) {
              console.log(this.form)
              const { msg } = await regionApi.doCreate(this.form)
              this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            } else {
              console.log('from--->', this.form)
              const { msg } = await regionApi.doCreate(this.form)
              this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            }
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
