<template>
  <a-modal
    :title="modalTitle"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    class="ant-modal2"
    @cancel="handleCancel"
  >
    <a-form :form="form">
      <a-form-item v-show="false" >
        <a-input v-decorator="['id']" type="hidden"/>
        <a-input v-decorator="['category']" type="hidden"/>
      </a-form-item>
      <row-list>
        <row-item >
          <a-form-item
            label="生产审核人"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-select
              v-decorator="['produceVerifyUserId', {rules: [{required: true, message: '生产审核人不能为空'}]}]"
              placeholder="请选择">
              <a-select-option
                v-for="item in userMap"
                :key="item.userId"
                :label="item.realName"
                :value="item.userId">{{ item.realName }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </row-item>
      </row-list>
      <a-form-item
        label="申请原因"
        :labelCol="BaseTool.Constant.labelCol2"
        :wrapperCol="BaseTool.Constant.wrapperCol2"
      >
        <a-textarea v-decorator="['remark']"/>
      </a-form-item>
    </a-form>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
    </template>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { applyBigRepair, getProducerUser } from '@/api/repair/application-form'

export default {
  name: 'ReportUpForm',
  data () {
    return {
      model: null,
      confirmLoading: false,
      modalTitle: null,
      userMap: [],
      form: this.$form.createForm(this),
      visible: false,
      chooseType: null,
      roleType: null,
      roleUserMap: []
      // 下拉框ma
    }
  },
  components: {

  },
  props: {
  },
  created () {
    // 下拉框map
    getProducerUser().then(res => {
      this.userMap = res.data
    })
  },
  methods: {
    base (record) {
      this.visible = true
      this.model = record
      const { form: { setFieldsValue } } = this
      this.$nextTick(() => {
        setFieldsValue(Object.assign(pick(record, [
          'id',
          'category'
        ])))
      })
    },
    save () {
      const { form: { validateFieldsAndScroll } } = this
      this.confirmLoading = true
      validateFieldsAndScroll((errors, values) => {
        if (errors) {
          this.confirmLoading = false
          return
        }
        // 日期处理
        applyBigRepair(values).then(() => {
          this.$message.info('操作成功')
          this.handleCancel()
        }).catch(() => {
          this.confirmLoading = false
        })
      })
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.form.resetFields()
      this.$emit('ok')
    }
  }
}
</script>
