<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form size="small" :model="inputForm" ref="inputForm" @keyup.enter.native="doSubmit()"
             label-width="80px" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method==='view'" @submit.native.prevent>
      <el-row :gutter="15">

        <el-col :span="12">
          <el-form-item label="收款日期" prop="gatheringTime"
                        :rules="[
                  {required: true, message:'收款日期不能为空', trigger:'blur'}
                 ]">
            <el-date-picker
              style="width: 100%;"
              v-model="inputForm.gatheringTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
      <el-button size="small" v-if="method != 'view'" type="primary" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import ReimbursementSys from '@/api/reimbursementSys/wuHanReimbursementSysService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          name: '',
          parent: {
            id: ''
          },
          gatheringTime: '' // 业务编码
        }
      }
    },
    reimbursementSys: null,
    created () {
      this.reimbursementSys = new ReimbursementSys()
    },
    methods: {
      init (method, obj) {
        this.method = method
        if (method === 'edit') {
          this.title = '修改收款日期'
        }
        this.visible = true
        this.$nextTick(() => {
          this.$refs['inputForm'].resetFields()
          this.inputForm.id = obj.id
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.reimbursementSys.saveGatheringTime(this.inputForm).then(({data}) => {
              this.loading = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.visible = false
              this.$emit('refreshDataList')
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>
