<template>
  <a-modal
    :title="modalTitle"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <a-form :form="form">
      <a-form-item v-show='false'>
        <a-input v-decorator="['id']" type='hidden' />
        <a-input v-decorator="['userId']" type='hidden' />
        <a-input v-decorator="['no']" type='hidden' />
        <a-input v-decorator="['repairStartTime']" type='hidden' />
      </a-form-item>
      <row-list :col="1">
        <row-item>
          <a-form-item
            label="驳回原因"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-textarea
              :rows="4"
              v-decorator="['remark']"/>
          </a-form-item>
        </row-item>
      </row-list>
    </a-form>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
    </template>
  </a-modal>
</template>

<script>
import { refusedByDTO } from '@/api/repair/application-form'
import pick from 'lodash.pick'
export default {
  name: 'DispatchBaseForm',
  data () {
    return {
      confirmLoading: false,
      modalTitle: null,
      form: this.$form.createForm(this),
      visible: false
      // 下拉框map
    }
  },
  props: {
  },
  created () {
    // 下拉框map
  },
  methods: {
    base (record) {
      this.visible = true
      // 如果是空标识添加
      const { form: { setFieldsValue } } = this
      this.$nextTick(() => {
        setFieldsValue(Object.assign(pick(record, [
          'id',
          'no',
          'userId',
          'repairStartTime'
        ])))
      })
      this.modalTitle = '驳回'
    },
    save () {
      const { form: { validateFieldsAndScroll } } = this
      this.confirmLoading = true
      validateFieldsAndScroll((errors, values) => {
        if (errors) {
          this.confirmLoading = false
          return
        }
        refusedByDTO(values)
          .then(() => {
            this.handleCancel(values)
          }).catch(() => {
            this.confirmLoading = false
          })
      })
    },
    handleCancel (values) {
      this.visible = false
      this.confirmLoading = false
      this.form.resetFields()
      if (this.BaseTool.Object.isNotBlank(values)) {
        this.$emit('ok')
      }
    }
  }
}
</script>
