<template>
  <j-modal :title="title" :width="width" :visible="visible" switchFullscreen @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="工具" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolId">
                <!--              <a-input v-model="model.toolId" placeholder="请输入工具"  ></a-input>-->
                <a-tag>{{ model.toolId_dictText }} - {{ model.code }}</a-tag>
              </a-form-model-item>
              <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="count">
                <a-input-number v-model="model.count" :max="model.num" :min="0" placeholder="请输入数量"></a-input-number>
              </a-form-model-item>
              <a-form-model-item label="出库类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outType">
                <!--              <a-input v-model="model.toolId" placeholder="请输入工具"  ></a-input>-->
                <j-dict-select-tag type="list" v-model="model.outType" dictCode="borrow_status" placeholder="请选择出库类型" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'ToolOutstockModal',
  data() {
    return {
      title: '',
      width: 800,
      formDisabled: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      visible: false,
      disableSubmit: false,
      model: {
      },
      confirmLoading: false,
      url: {
        add: "/toolBorrowingRecord/add",
        edit: "/toolBorrowingRecord/edit",
        queryById: "/toolBorrowingRecord/queryById"
      },
      validatorRules: {}
    }
  },
  methods: {
    edit(record) {
      this.visible = true
      this.model = record;
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleOk() {
      this.submitForm();
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      that.confirmLoading = true;
      let httpurl = '';
      let method = '';
      httpurl += this.url.add;
      method = 'post';
      const _data = {
        toolId: this.model.id,
        status: this.model.outType,
        count: this.model.count,
        workOrder: ''
      }
      httpAction(httpurl, _data, method).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
          this.submitCallback()
        } else {
          that.$message.warning(res.message);
        }
      }).finally(() => {
        that.confirmLoading = false;
      })
  },
  submitCallback() {
    this.$emit('ok');
    this.visible = false;
  },
  handleCancel() {
    this.close()
  }
}
  }
</script>