<template>
  <div>
    <el-form :model="editData" :rules="formRules" ref="dataForm" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="20">
          <el-form-item label="UDI码:" prop="code">
            <el-input
              v-model="editData.code"
              clearable
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="11">
          <el-form-item prop="productDate" label="生产日期">
            <el-input v-model="editData.produceDate" auto-complete="off"
                      oninput="if(value.length>6)value=value.slice(0,6)"
                      type="number"
                      :disabled="editType!=1"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item prop="expireDate" label="失效日期">
            <el-input v-model="editData.expireDate" auto-complete="off"
                      oninput="if(value.length>6)value=value.slice(0,6)"
                      type="number"
                      :disabled="editType!=1"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="11">
          <el-form-item prop="batchNo" label="批次号">
            <el-input v-model="editData.batchNo" auto-complete="off" :disabled="editType!=1"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item prop="serialNo" label="序列号">
            <el-input v-model="editData.serialNo" auto-complete="off" :disabled="editType!=1"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="11">
          <el-form-item prop="count" label="扫码数量">
            <el-input v-model="editData.count" auto-complete="off"
                      type="number"
                      min="1"
                      :disabled="editData.serialNo!=null && editData.serialNo!='' "></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="11">
          <el-form-item>
            <el-checkbox v-model="isUseDyCheck" disabled>是否以使用单元数量出入库</el-checkbox>
          </el-form-item>
        </el-col>
      </el-row>
      <div style="text-align: right;margin-top: 20px">
        <el-button @click="cancelDialog">取 消</el-button>
        <el-button type="primary" @click="saveCode()">确 定</el-button>
      </div>
    </el-form>
  </div>

</template>

<script>

import {
  findByCode,
  saveCode, tabCode
} from "@/api/inout/code";

export default {
  name: "editCode",
  props: {
    editType: {
      type: Object,
      required: true,
    },
    closeCodeDialog: {
      type: Function,
      required: true,
    },
    repeatAddCode: {
      type: Function,
      required: false,
    },
    codeDetail: {
      type: Object,
      required: true,
    },
    editData: null
  },

  data() {
    return {
      xlhEnable: false,
      isUseDyCheck: false
    };
  },

  methods: {
    saveCode() {
      if (this.editType == 1) {
        this.repeatAddCode(this.editData);

        tabCode(this.editData)
          .then((response) => {
            console.log(response)
            if (response.code === 20000) {
              this.$message.success("提交成功");
            } else {
              this.$message.error(response.message);
            }
            this.loading = false;
          });

      } else {
        saveCode(this.editData)
          .then((response) => {
            console.log(response)
            if (response.code === 20000) {
              this.$message.success("提交成功");
              this.codeDetail = this.editData;
              this.closeCodeDialog();
            } else {
              this.$message.error(response.message);
            }
            this.loading = false;
          });
      }

    }
    ,
    cancelDialog() {
      this.closeCodeDialog();
    }
    ,
    findByCode() {
      let query = {udiCode: this.editData.code};
      findByCode(query)
        .then((response) => {
          if (response.code === 20000) {
            if (response.data.scbssfbhxlh == "否") {
              this.xlhEnable = true;
            }
            if (response.data.zxxsbzbhsydysl > 1) {
              this.isUseDyCheck = true;
            }
          } else {
          }
          this.loading = false;
        });
    }

  }
  ,
  created() {

    this.editData = JSON.parse(JSON.stringify(this.codeDetail));
    this.findByCode();
  }
}
</script>

<style scoped>

</style>
