<template>
  <div class="app-container">
    <el-form ref="postForm" :rules="formRules" :model="formData" label-width="150px">
      
      <el-form-item label="编号：" prop="number">
        <el-col :span="6">
          <el-input v-model="formData.number" placeholder="请输入登录编号"/>
        </el-col>
      </el-form-item>
      <el-form-item label="日期：" prop="date">
        <el-col :span="6">
          <el-input v-model="formData.date" placeholder="请输入登录日期"/>
        </el-col>
      </el-form-item>
      <el-form-item label="户名：" prop="name">
        <el-col :span="6">
          <el-input v-model="formData.name" placeholder="请输入户名"/>
        </el-col>
      </el-form-item>
      <el-form-item label="摘要：" prop="abstract">
        <el-col :span="6">
          <el-input v-model="formData.abstract" placeholder="请输入登录摘要"/>
        </el-col>
      </el-form-item>
      <el-form-item label="金额：" prop="amount">
        <el-col :span="6">
          <el-input v-model="formData.amount" placeholder="请输入登录金额"/>
        </el-col>
      </el-form-item>
      <el-form-item align="center">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { checkRqInput, checkPwdLength, checkTel } from '@/utils/validate'
// import { detailYardman, updateYardman, createYardman,  } from '@/api/user/index'

export default {
  name: 'ArticleDetail',
  // 配合路由配置的props属性实现在组件中通过props获取参数
  props: {
    id: {
      type: String,
      default() {
        return this.$route.params.id;
      }
    }
  },
  data() {
    return {
      formData: {freeze_flag:false},
      // 校验规则
      formRules: {
        number: [ checkRqInput ],
        date: [ checkRqInput ],
        name: [ checkRqInput ],
        abstract: [ checkRqInput],
        amount: [ checkRqInput ],
      },
    }
  },
  created() {
    this.fetchDetail()
  },
  methods: {
    // 获取企业详情
    fetchDetail() {
      const id = this.$props.id
      if (id) {
        this.$http(detailYardman(id), (res) => {
          if (res.code == 0) {
            this.formData = res.data
          }
        })
      }
      this.formData.yardman_id = id
    },
    // 提交表单
    submitForm() {
      this.$refs['postForm'].validate((valid) => {
        // if (valid) {
        //   // 修改
        //   if (this.formData.yardman_id) {
        //     this.$http(updateYardman(this.formData), res => {
        //       this.$message({
        //         message: '成功',
        //         type: 'success'
        //       })
        //       this.$router.go(-1)
        //     })
        //   } else {
        //     // 新增
        //     this.$http(createYardman(this.formData), res => {
        //       this.$message({
        //         message: '成功',
        //         type: 'success'
        //       })
        //       this.$router.go(-1)
        //     })
        //   }
        // } else {
        //   return false
        // }
      })
    },
    // 取消
    onCancel() {
      this.$message({
        message: '已取消!',
        type: 'warning'
      })
      this.$router.go(-1)
    },
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
