<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="用户Id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户Id"></el-input>
    </el-form-item>
    <el-form-item label="年份" prop="year">
      <el-input v-model="dataForm.year" placeholder="年份"></el-input>
    </el-form-item>
    <el-form-item label="入职时间" prop="startTime">
      <el-input v-model="dataForm.startTime" placeholder="入职时间"></el-input>
    </el-form-item>
    <el-form-item label="离职时间" prop="endTime">
      <el-input v-model="dataForm.endTime" placeholder="离职时间"></el-input>
    </el-form-item>
    <el-form-item label="借款明细" prop="borrowingDetails">
      <el-input v-model="dataForm.borrowingDetails" placeholder="借款明细"></el-input>
    </el-form-item>
    <el-form-item label="工资标准计算方式" prop="gzjsfs">
      <el-input v-model="dataForm.gzjsfs" placeholder="工资标准计算方式"></el-input>
    </el-form-item>
    <el-form-item label="工资结清及时间节点" prop="gzjqjsjjd">
      <el-input v-model="dataForm.gzjqjsjjd" placeholder="工资结清及时间节点"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="创建人" prop="createName">
      <el-input v-model="dataForm.createName" placeholder="创建人"></el-input>
    </el-form-item>
    <el-form-item label="删除时间" prop="deleteTime">
      <el-input v-model="dataForm.deleteTime" 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>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          year: '',
          startTime: '',
          endTime: '',
          borrowingDetails: '',
          gzjsfs: '',
          gzjqjsjjd: '',
          remark: '',
          createTime: '',
          updateTime: '',
          createName: '',
          deleteTime: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户Id不能为空', trigger: 'blur' }
          ],
          year: [
            { required: true, message: '年份不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '入职时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '离职时间不能为空', trigger: 'blur' }
          ],
          borrowingDetails: [
            { required: true, message: '借款明细不能为空', trigger: 'blur' }
          ],
          gzjsfs: [
            { required: true, message: '工资标准计算方式不能为空', trigger: 'blur' }
          ],
          gzjqjsjjd: [
            { required: true, message: '工资结清及时间节点不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          createName: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          deleteTime: [
            { 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) {
            this.$http({
              url: this.$http.adornUrl(`/business/businessworkersalary/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.businessWorkerSalary.userId
                this.dataForm.year = data.businessWorkerSalary.year
                this.dataForm.startTime = data.businessWorkerSalary.startTime
                this.dataForm.endTime = data.businessWorkerSalary.endTime
                this.dataForm.borrowingDetails = data.businessWorkerSalary.borrowingDetails
                this.dataForm.gzjsfs = data.businessWorkerSalary.gzjsfs
                this.dataForm.gzjqjsjjd = data.businessWorkerSalary.gzjqjsjjd
                this.dataForm.remark = data.businessWorkerSalary.remark
                this.dataForm.createTime = data.businessWorkerSalary.createTime
                this.dataForm.updateTime = data.businessWorkerSalary.updateTime
                this.dataForm.createName = data.businessWorkerSalary.createName
                this.dataForm.deleteTime = data.businessWorkerSalary.deleteTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/business/businessworkersalary/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'userId': this.dataForm.userId,
                'year': this.dataForm.year,
                'startTime': this.dataForm.startTime,
                'endTime': this.dataForm.endTime,
                'borrowingDetails': this.dataForm.borrowingDetails,
                'gzjsfs': this.dataForm.gzjsfs,
                'gzjqjsjjd': this.dataForm.gzjqjsjjd,
                'remark': this.dataForm.remark,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'createName': this.dataForm.createName,
                'deleteTime': this.dataForm.deleteTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
