<template>
    <div class="inStockAdd">
        <a-card style="height: 100vh">
        <div>
          <span style="font-size: 16px;font-weight: bold">添加供应商</span>
        </div>
        <div style="width:75%;margin: 0 auto;margin-top: 20px">
            <a-form-model ref="formRef" :model="formData" :rules="formRules"
                          :labelCol="{span: 6}"
                          :wrapperCol="{span: 16}"
            >
                <a-row :gutter="16">
                    <a-col :span="24">
                        <a-form-model-item label="供应商名称"
                                           prop="supplierName"
                                           :labelCol="{span: 3}"
                                           :wrapperCol="{span: 20}">
                            <a-input v-model="formData.supplierName"
                                     placeholder="请输入供应商名称"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-model-item label="联系人" prop="contactsName">
                            <a-input v-model="formData.contactsName"
                                     placeholder="请输入联系人"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-model-item label="联系人电话" prop="contactsPhone">
                            <a-input v-model="formData.contactsPhone"
                                     placeholder="请输入联系人电话"></a-input>
                        </a-form-model-item>

                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="联系地址"
                                           prop="address"
                                           :labelCol="{span: 3}"
                                           :wrapperCol="{span: 20}">
                            <a-input v-model="formData.address"
                                     placeholder="请输入联系地址"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="详细地址"
                                           prop="batchId"
                                           :labelCol="{span: 3}"
                                           :wrapperCol="{span: 20}">
                            <a-input v-model="formData.stockNum"
                                     placeholder="请输入详细地址"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="备注"
                                           prop="remarks"
                                           :labelCol="{span: 3}"
                                           :wrapperCol="{span: 20}">
                            <a-textarea
                                    :rows="6"
                                    v-model="formData.remarks"
                                    placeholder="请输入备注"></a-textarea>
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
        </div>
        <div style="text-align: center">
            <a-button class="search_btn btn_space" @click="goBack">取消</a-button>
            <a-button type="primary" class="search_btn btn_space" :loading="subLoad" style="margin-left: 10px" @click="submitForm">保存</a-button>
        </div>
        </a-card>
    </div>
</template>
<script>
    import moment from 'moment'
    import {closedDetail} from "../../../utils/common";
    export default {
        components: {},
        data() {
            return {
                subLoad: false,
                // form表单
                formData: {
                    breedId: undefined,
                    batchNumber: undefined,
                    medicalId: undefined,
                    factoryId: undefined,
                    supplyName: undefined,
                    classify: undefined,
                    unitPrice: undefined,
                    batchId: undefined,
                    produceDate: undefined,
                    expireDate: undefined,
                    stockNum: undefined,

                    supplierName: undefined,
                    contactsName: undefined,
                    contactsPhone: undefined,

                },
                formRules: {
                    supplierName: [
                        {required: true, message: '请输入供应商名称'}
                    ],
                    contactsName:[
                        {required: true, message: '请输入联系人'}
                    ],
                    contactsPhone: [
                        {required: true, message: '请输入联系人电话'}
                    ],
                    medicalId: [
                        {required: true, message: '请选择品种名称'}
                    ],
                    factoryId: [
                        {required: true, message: '请选择生产厂家', trigger: 'change'}
                    ],
                    batchId: [
                        {required: true, message: '请输入生产批次', trigger: 'change'}
                    ],
                    stockNum: [
                        {required: true, message: '请输入药具数量', trigger: 'change'}
                    ],
                    produceDate: [
                        {required: true, message: '请选择日期', trigger: 'change'}
                    ],
                    expireDate: [
                        {required: true, message: '请选择日期', trigger: 'change'}
                    ],
                    unitPrice: [
                        {required: true, message: '请输入单价'}
                    ],
                },
                routerParams: {}
            }
        },
        created() {
           this.routerParams = this.$route.query
            if (this.routerParams.flag == 'update') {
               this.getSupplyDetail(this.routerParams)
            }
        },
        methods: {
            getSupplyDetail(record) {
                let par = {
                    id: record.id
                }
                this.$api.supplyManage.fetchSupplyDetail(par).then(({data}) => {

                })
            },
            // 弹窗确定按钮
            submitForm() {
                let vm = this
                this.$refs.formRef.validate(valid => {
                    if (valid) {
                        vm.subLoad = true
                        let par = {
                            ...vm.formData
                        }
                        vm.$api.stockManage.addHistoryStock(par).then(res => {
                            this.subLoad = false;
                            if (res.code === 'SUCCESS') {
                                vm.$message.success('保存成功！')
                                vm.goBack()
                            }
                        }).catch(() => {
                            this.subLoad = false
                        })
                    }
                });
            },
            goBack() {
                closedDetail('/supplyManage/add','/Home/supplyManage')
            }
        },
    }
</script>
<style lang="less" scoped>

</style>
