<template>
    <el-dialog title="生产激活码" :visible.sync="dialogVisible" width="500px" @close="reset">
        <el-form :model="form" :rules="rules" label-width="100px" label-position="left">
            <el-form-item label="激活时长" prop="periodYear">
                <el-input-number v-model="form.periodYear" controls-position="right" :min="1" :step="1"
                    step-strictly></el-input-number>
            </el-form-item>
            <el-form-item label="生产数量" prop="number">
                <el-input-number v-model="form.number" controls-position="right" :min="1" :step="1"
                    step-strictly></el-input-number>
            </el-form-item>
            <!-- <el-form-item label="所属代理" prop="agent">
                <el-input v-model="form.agent" placeholder="请输入完整的代理账号查找"></el-input>
            </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="close">取消</el-button>
            <el-button type="primary" v-loading="loading" @click="tbMerchantRegisterPost">生产激活码</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { tbMerchantRegisterPost } from '@/api/shop.js'
export default {
    data() {
        return {
            dialogVisible: false,
            loading: false,
            form: {
                periodYear: 1,
                number: 1,
                agent: ''
            },
            rules: {
                periodYear: [{
                    required: true,
                    message: ' ',
                    trigger: 'blur'
                }],
                number: [{
                    required: true,
                    message: ' ',
                    trigger: 'blur'
                }]
            }
        }
    },
    methods: {
        async tbMerchantRegisterPost() {
            try {
                this.loading = true
                const res = await tbMerchantRegisterPost(this.form)
                this.$emit('success', res)
                this.close()
                this.$notify({
                    title: '成功',
                    message: `添加成功`,
                    type: 'success'
                });
                this.loading = false
            } catch (error) {
                this.loading = false
                console.log(error)
            }
        },
        show() {
            this.dialogVisible = true
        },
        close() {
            this.dialogVisible = false
        },
        reset() {
            this.form.periodYear = 1
            this.form.number = 1
            this.form.agent = ''
        }
    }
}
</script>