<template>
  <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="12">
            <a-form-model-item label="领用单位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="collectingUnitNumber">
              <j-select-depart v-model="model.collectingUnitNumber" :multi="true"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="仪器编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentNumber">
              <a-input v-model="model.instrumentNumber" placeholder="请输入仪器编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="仪器名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentName">
              <a-input v-model="model.instrumentName" placeholder="请输入仪器名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="分类号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryId">
              <a-input v-model="model.categoryId" placeholder="请输入分类号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="model">
              <a-input v-model="model.model" placeholder="请输入型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specifications">
              <a-input v-model="model.specifications" placeholder="请输入规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unitPrice">
              <a-input v-model="model.unitPrice" placeholder="请输入单价"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="厂家" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manufactuer">
              <a-input v-model="model.manufactuer" placeholder="请输入厂家"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="购置日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchasedate">
              <j-date placeholder="请选择购置日期" v-model="model.purchasedate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="领用人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recipient">
              <j-select-user-by-dep v-model="model.recipient" :multi="true" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="入库时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entryDate">
              <j-date placeholder="请选择入库时间" v-model="model.entryDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单据号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="documentNumber">
              <a-input v-model="model.documentNumber" placeholder="请输入单据号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="存放地id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="locationId">
              <a-input v-model="model.locationId" placeholder="请输入存放地id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note">
              <a-input v-model="model.note" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalStatus">
              <j-dict-select-tag type="radio" v-model="model.approvalStatus" dictCode="approval_status" placeholder="请选择审核状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="初审状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="initialAudit">
              <j-dict-select-tag type="radio" v-model="model.initialAudit" dictCode="initial_audit" placeholder="请选择初审状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instrumentId">
              <a-input v-model="model.instrumentId" placeholder="请输入ID"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'RmsInstrumentForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/rms/rmsInstrument/add",
          edit: "/rms/rmsInstrument/edit",
          queryById: "/rms/rmsInstrument/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>