<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="笔记标题" prop="noteTitle" class="is-required">
          <el-input v-model="temp.noteTitle" placeholder="笔记标题" />
        </el-form-item>

        <el-form-item label="笔记内容" prop="noteContent" class="is-required">
          <el-input type="textarea" v-model="temp.noteContent" placeholder="笔记内容" />
        </el-form-item>

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

        <el-form-item label="创建时间" prop="createTime" class="is-required">
          <el-date-picker
            v-model="temp.createTime"
            type="datetime"
            placeholder="创建时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="修改时间" prop="updateTime" class="is-required">
          <el-date-picker
            v-model="temp.updateTime"
            type="datetime"
            placeholder="修改时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </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="upCount" class="is-required">
          <el-input v-model="temp.upCount" readonly placeholder="点赞数" />
        </el-form-item>

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

        <el-form-item label="冻结状态" prop="authorStatus" class="is-required">
          <el-radio-group v-model="temp.noteStatus">
            <el-radio :label="0">正常</el-radio>
            <el-radio :label="1">冻结</el-radio>
          </el-radio-group>
        </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 { editNote } from "@/api/business/note/note";
import {setRequiredFields} from "@/utils";
const requiredFields = []

export default {
  name: "editForm",
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        noteId:'',
        noteTitle:'',
        noteContent:'',
        noteCategory:'',
        noteCategoryName:'',
        noteType:'',
        authorId:'',
        authorAvatar:'',
        authorName:'',
        firstPicture:'',
        version:'',
        deleted:'',
        createTime:'',
        updateTime:'',
        ipAddress:'',
        ipRealAddress:'',
        upCount:'',
        starCount:'',
      },
    }
  },
  methods: {
    open(row) {
      this.temp = this.$options.data().temp
      this.temp = row
      this.dialogVisible = true
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          editNote(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>
