<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="accountname">
      <el-input v-model="dataForm.accountname" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="accountno">
      <el-input v-model="dataForm.accountno" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="optype">
      <el-input v-model="dataForm.optype" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="amount">
      <el-input v-model="dataForm.amount" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="bankserialno">
      <el-input v-model="dataForm.bankserialno" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="explore1">
      <el-input v-model="dataForm.explore1" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="explore2">
      <el-input v-model="dataForm.explore2" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="explore3">
      <el-input v-model="dataForm.explore3" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/wmsettleaccountreceive'

    export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          accountname: '',
          accountno: '',
          optype: '',
          amount: '',
          bankserialno: '',
          explore1: '',
          explore2: '',
          explore3: ''
        },
        dataRule: {
          accountname: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          accountno: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          optype: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          amount: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          bankserialno: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          explore1: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          explore2: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          explore3: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getObj(this.dataForm.id).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
                putObj(this.dataForm).then(data => {
                    this.$message.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$message.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                })
            }
          }
        })
      }
    }
  }
</script>
