<template>
    <el-card class="el-card">
        <el-form :inline="true" :model="newProductData" size="mini">
            <div>
                <el-row :gutter="20" class="el-row" type="flex">
                    <el-col :span="18" class="el-col">
                        <div class="text item">
                            <div class="itemTag">
                                <span>第三方系统:&nbsp;</span>
                            </div>
                            <el-select
                                style="width: 60%"
                                disabled
                                v-model="newProductData.thirdSysFk" placeholder="请选择第三方系统"
                            >
                                <el-option
                                    v-for="item in thirdSys"
                                    :key="item.value"
                                    :label="item.thirdName"
                                    :value="item.thirdId">
                                    <span style="float: left">{{ item.thirdName }}</span>
                                    <span style="float: right; color: #8492a6; font-size: 13px">{{
                                            item.thirdId
                                        }}</span>
                                </el-option>
                            </el-select>
                        </div>
                    </el-col>
                </el-row>
                <el-row :gutter="20" class="el-row" type="flex">
                    <el-col :span="18" class="el-col">
                        <div class="text item">
                            <div class="itemTag">
                                <span>产品编码:&nbsp;</span>
                            </div>
                            <el-input
                                style="width: 60%"
                                size="small"
                                placeholder="请输入内容"
                                v-model.trim="newProductData.code"
                            ></el-input>
                        </div>
                    </el-col>
                </el-row>

                <div style='text-align: center; margin-top: 20px;margin-bottom: 20px'>
                    <el-button type="primary" @click="saveNewProduct">提交</el-button>
                    <el-button type="primary" @click="closeAddDialog(false)">取消</el-button>
                </div>


                <div>
                    <span style="color: red;margin-top: 30px;font-size: 12px">注意:&nbsp;请确保所填产品编码已在第三方系统录入 </span>
                </div>
            </div>
        </el-form>
    </el-card>
</template>

<script>
import {addProduct} from "@/api/thrsys/thrProductsAdd";


import {getBasicThirdSys} from "@/api/basic/basicThirdSys";

export default {
    name: "ThrProductEdit",
    props: {
        closeAddDialog: {
            type: Function,
            required: true,
        },
        thirdSysFk: {
            type: Object,
            required: true,
        },
        relId: {
            type: Object,
            required: true,
        }
    },
    data() {
        return {
            newProductData: {
                name: '',
                code: null,
                registerNo: null,
                manufactory: null,
                spec: null,
                measname: null,
                ylqxzcrbarmc: null,
                ylqxzcrbarywmc: null,
                cplb: null,
                flbm: null,
                sptm: null,
                ybbm: null,
                tyshxydm: null,
                qxlb: null,
                cplx: null,
                cpms: null,
                thirdSysFk: null,
                cpdls: null,
                relId: null,
            },
            thirdSys: [],
            combineQuery: {
                relId: null,
                thirdSys: null,
                thirdId: null,
            },

        }

    },
    methods: {
        saveNewProduct() {
            this.addProductVisible = false;
            this.newProductData.relId = this.relId;
            this.newProductData.thirdSysFk = this.thirdSysFk;
            addProduct(this.newProductData).then((res) => {
                if (res.code == 20000) {
                    this.$message.success("产品编码已提交，将在审核后自动关联，请稍后刷新查看！");
                    this.closeAddDialog(true);

                } else {
                    this.$message.error(res.message);
                }
            }).catch((error) => {
                this.$message.error(error.message);
            })


        },
        getBasicThirdSys() {
            let query = {
                enabled: true,
            };
            getBasicThirdSys(query)
                .then((response) => {
                    this.thirdSys = response.data.list || [];
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                });
        },
    },
    created() {
        this.newProductData.thirdSysFk = this.thirdSysFk;
        this.getBasicThirdSys();
    },
}
</script>

<style scoped>
.el-row {
    margin-top: 10px;
}
</style>
