<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form" style="padding-bottom: 30px;padding-top: 30px">

        <a-form-item label="验收结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-radio-group @change="handleChange" :value="isCheck">
            <a-radio :value="2">合格</a-radio>
            <a-radio :value="1">不合格</a-radio>
          </a-radio-group>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import Vue from 'vue'


  export default {
    name: 'HwOrderSelectModal',
    components: {

    },
    data() {
      return {
        headers: {},
        fileList: [],
        form: this.$form.createForm(this),
        title: '操作',
        width: 600,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        options: [{
          value: '',
          label: '',
          isLeaf: false
        }],
        isCheck: 0,
        confirmLoading: false,
        validatorRules: {
          workContract: {},
        },
        url: {
          edit: '/ordermanager/hwOrder/edit'
        }

      }
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.form.resetFields()
        this.model = Object.assign({}, record)
        this.visible = true
        this.isCheck = record.isCheck;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'isCheck'))
        })
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      handleOk() {
        const that = this
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true
            let httpurl = ''
            let method = ''
            httpurl += this.url.edit
            method = 'put'
            let formData = Object.assign(this.model, values)
            formData.isCheck = this.isCheck;
            console.log('表单提交数据', formData)
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success('验收完成')
                that.$emit('ok')
              } else {
                that.$message.warning('验收失败')
              }
            }).finally(() => {
              that.confirmLoading = false
              that.close()
            })
          }

        })
      },
      handleCancel() {
        this.close()
      },
      popupCallback(row) {
        this.form.setFieldsValue(pick(row, 'isCheck'))
      },
      handleChange(e){
        this.isCheck = e.target.value
      }

    }
  }
</script>