<template>
    <div>
        <el-form :model="codeDetail" :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="codeDetail.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="codeDetail.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="codeDetail.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="codeDetail.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="price">
                        <el-input v-model="codeDetail.serialNo" auto-complete="off"></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,
        },
    },
    methods: {
        saveCode() {
            if (this.editTye == 1) {
                this.repeatAddCode();
            } else {
                saveCode(this.codeDetail)
                    .then((response) => {
                        console.log(response)
                        if (response.code === 20000) {
                            this.$message.success("提交成功");
                            this.closeCodeDialog();
                        } else {
                            this.$message.error(response.message);
                        }
                        this.loading = false;
                    });
            }

        },
        cancelDialog() {
            this.closeCodeDialog();
        },
        findByCode() {
            let query = {udiCode: this.codeDetail.code};
            findByCode(query)
                .then((response) => {
                    if (response.code === 20000) {

                    } else {
                    }
                    this.loading = false;
                });
        }

    },
    created() {

    },
}
</script>

<style scoped>

</style>
