<template>
    <div>
        <el-form :model="editData" :rules="formRules" ref="dataForm">
            <el-row :gutter="20">
                <el-col :span="3">
                    <div class="ao-text">
                        <span>条码：</span>
                    </div>
                </el-col>
                <el-col :span="16">
                    <el-form-item 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="3">
                    <div class="ao-text">
                        <span>生产日期：</span>
                    </div>
                </el-col>
                <el-col :span="7">
                    <el-form-item prop="productDate">
                        <el-input v-model="editData.produceDate" auto-complete="off"
                                  oninput="if(value.length>6)value=value.slice(0,6)"
                                  type="number"
                                  :disabled="false"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="3">
                    <div class="ao-text">
                        <span>失效日期：</span>
                    </div>
                </el-col>
                <el-col :span="7">
                    <el-form-item prop="expireDate">
                        <el-input v-model="editData.expireDate" auto-complete="off"
                                  oninput="if(value.length>6)value=value.slice(0,6)"
                                  type="number"
                                  :disabled="false"></el-input>

                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="3">
                    <div class="ao-text">
                        <span>批次号：</span>
                    </div>
                </el-col>
                <el-col :span="7">
                    <el-form-item prop="batchNo">
                        <el-input v-model="editData.batchNo" auto-complete="off" :disabled="false"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="3">
                    <div class="ao-text">
                        <span>序列号：</span>
                    </div>
                </el-col>
                <el-col :span="7">
                    <el-form-item prop="serialNo">
                        <el-input v-model="editData.serialNo" auto-complete="off" :disabled="xlhEnable"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row :gutter="20">
                <el-col :span="3">
                    <div class="ao-text">
                        <span>数量：</span>
                    </div>
                </el-col>
                <el-col :span="7">
                    <el-form-item prop="count">
                        <el-input v-model="editData.count" auto-complete="off"
                                  type="number"
                                  :disabled="editData.serialNo!=null && editData.serialNo!='' "></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="17">
                </el-col>
                <el-col :span="7">
                    <el-button @click="cancelDialog">取 消</el-button>
                    <el-button type="primary" @click="saveCode()">确 定</el-button>
                </el-col>
            </el-row>

        </el-form>
    </div>

</template>

<script>

import {
    findByCode,
    saveCode
} from "../../api/warehouse/code";

export default {
    name: "editCode",
    props: {
        editTye: {
            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,
        };
    },

    methods: {
        saveCode() {
            if (this.editTye == 1) {
                this.repeatAddCode();
            } 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;
                        }
                    } else {
                    }
                    this.loading = false;
                });
        }

    }
    ,
    created() {

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

<style scoped>

</style>
