<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="24">
            <a-form-model-item label="样品条码列表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="barCodes">
              <a-select type="list_multi"
                        mode="multiple"
                        v-model="model.barCodes"
                        value-in-value
                        show-search
                        :options="rukuSampleBarcodeOptions"
                        placeholder="请选择样品条码列表" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="过期样品处理方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlingMethod">
              <a-input v-model="model.handlingMethod" placeholder="请输入处理方式"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">-->
<!--              <j-dict-select-tag type="list" v-model="model.auditStatus" dictCode="audit_status" placeholder="请选择审核状态" :disabled="editdisabled"/>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="拒绝原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rejectReason">-->
<!--              <a-input v-model="model.rejectReason" placeholder="请输入拒绝原因"  :disabled="editdisabled"></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'
  import { rukuSampleBarcodeList } from '@/api/api'

  export default {
    name: 'ItdmSampleExpireForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      //禁止编辑
      editdisabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        rukuSampleBarcodeOptions : [],
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/inventory/itdmSampleExpire/add",
          edit: "/inventory/itdmSampleExpire/edit",
          queryById: "/inventory/itdmSampleExpire/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      this.getSampleBarcodeList();//初始化已入库样品条码下拉列表
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      // 获得已入库样品条码下拉列表，此方法要在created里，初始化时调用
      getSampleBarcodeList(){
        rukuSampleBarcodeList().then((res) =>{
          this.rukuSampleBarcodeOptions = res.result.map( res => {
            return{
              value: res.barCode,
              label: res.barCode,
              // label: res.sampleName
            }
          })
        })
      },
      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>