<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      top="8vh"
      width="40%"
      :visible.sync="dialogVisible"
      center
      @close="handleCancel"
    >
      <div class="el-dialog-div">
      <el-form
        :rules="rules"
        ref="dataForm"
        :model="temp"
        label-position="right"
        label-width="120px"
        style="height: 90%;"
      >

                  <el-form-item label="作者id" prop="authorId"  class="is-required">
            <el-input v-model="temp.authorId" placeholder="作者id" />
          </el-form-item>

          <el-form-item label="作者号" prop="authorNo"  class="is-required">
            <el-input v-model="temp.authorNo" placeholder="作者号" />
          </el-form-item>

          <el-form-item label="作者姓名" prop="authorName"  class="is-required">
            <el-input v-model="temp.authorName" placeholder="作者姓名" />
          </el-form-item>

          <el-form-item label="头像id" prop="avatarId"  class="is-required">
            <el-input v-model="temp.avatarId" placeholder="头像id" />
          </el-form-item>

          <el-form-item label="头像地址" prop="avatarUrl"  class="is-required">
            <el-input v-model="temp.avatarUrl" placeholder="头像地址" />
          </el-form-item>

          <el-form-item label="简介" prop="description"  class="is-required">
            <el-input v-model="temp.description" placeholder="简介" />
          </el-form-item>

          <el-form-item label="性别" prop="sex"  class="is-required">
            <el-input v-model="temp.sex" placeholder="性别" />
          </el-form-item>

          <el-form-item label="生日" prop="birth"  class="is-required">
            <el-input v-model="temp.birth" placeholder="生日" />
          </el-form-item>

          <el-form-item label="职业" prop="job"  class="is-required">
            <el-input v-model="temp.job" placeholder="职业" />
          </el-form-item>

          <el-form-item label="地区" prop="area"  class="is-required">
            <el-input v-model="temp.area" placeholder="地区" />
          </el-form-item>

          <el-form-item label="学校" prop="school"  class="is-required">
            <el-input v-model="temp.school" placeholder="学校" />
          </el-form-item>

          <el-form-item label="背景图" prop="backGroundId"  class="is-required">
            <el-input v-model="temp.backGroundId" placeholder="背景图" />
          </el-form-item>

          <el-form-item label="背景图地址" prop="backGroundUrl"  class="is-required">
            <el-input v-model="temp.backGroundUrl" placeholder="背景图地址" />
          </el-form-item>

          <el-form-item label="关注数" prop="follow"  class="is-required">
            <el-input v-model="temp.follow" placeholder="关注数" />
          </el-form-item>

          <el-form-item label="粉丝数" prop="fans"  class="is-required">
            <el-input v-model="temp.fans" placeholder="粉丝数" />
          </el-form-item>

          <el-form-item label="点赞数" prop="upCount"  class="is-required">
            <el-input v-model="temp.upCount" placeholder="点赞数" />
          </el-form-item>

          <el-form-item label="收藏数" prop="starCount"  class="is-required">
            <el-input v-model="temp.starCount" placeholder="收藏数" />
          </el-form-item>

          <el-form-item label="0正常" prop="authorStatus"  class="is-required">
            <el-input v-model="temp.authorStatus" placeholder="0正常" />
          </el-form-item>

          <el-form-item label="乐观锁字段" prop="version"  class="is-required">
            <el-input v-model="temp.version" placeholder="乐观锁字段" />
          </el-form-item>

          <el-form-item label="0正常 1删除" prop="deleted"  class="is-required">
            <el-input v-model="temp.deleted" placeholder="0正常 1删除" />
          </el-form-item>

          <el-form-item label="创建时间" prop="createTime"  class="is-required">
            <el-input v-model="temp.createTime" placeholder="创建时间" />
          </el-form-item>

          <el-form-item label="修改时间" prop="updateTime"  class="is-required">
            <el-input v-model="temp.updateTime" placeholder="修改时间" />
          </el-form-item>

          <el-form-item label="ip地址" prop="ipAddress"  class="is-required">
            <el-input v-model="temp.ipAddress" placeholder="ip地址" />
          </el-form-item>

          <el-form-item label="真实ip地址" prop="ipRealAddress"  class="is-required">
            <el-input v-model="temp.ipRealAddress" placeholder="真实ip地址" />
          </el-form-item>

          <el-form-item label="真实姓名" prop="realName"  class="is-required">
            <el-input v-model="temp.realName" placeholder="真实姓名" />
          </el-form-item>

          <el-form-item label="身份证号" prop="idCard"  class="is-required">
            <el-input v-model="temp.idCard" placeholder="身份证号" />
          </el-form-item>

          <el-form-item label="手机号" prop="phoneNumber"  class="is-required">
            <el-input v-model="temp.phoneNumber" placeholder="手机号" />
          </el-form-item>


      </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addAuthor} from "@/api/business/author/author";
import {setRequiredFields} from "@/utils";
const requiredFields = []
export default {
  name: "addForm",
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        authorId:'',
        authorNo:'',
        authorName:'',
        avatarId:'',
        avatarUrl:'',
        description:'',
        sex:'',
        birth:'',
        job:'',
        area:'',
        school:'',
        backGroundId:'',
        backGroundUrl:'',
        follow:'',
        fans:'',
        upCount:'',
        starCount:'',
        authorStatus:'',
        version:'',
        deleted:'',
        createTime:'',
        updateTime:'',
        ipAddress:'',
        ipRealAddress:'',
        realName:'',
        idCard:'',
        phoneNumber:'',
      },
    }
  },
  methods: {
    open() {
      this.dialogVisible = true
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          addAuthor(this.temp).then(response =>{
            this.handleCancel()
            this.$emit('ok', response.data)
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    handleCancel() {
      //初始化
      this.temp = this.$options.data().temp
      this.dialogVisible = false
      this.$refs['dataForm'].resetFields();
    }
  },
}
</script>

<style scoped>

</style>
