<template>
    <div v-loading="loading">
        <div class="white-box">
            <el-form ref="form"  label-width="250px" class="form-page">

                <el-form-item label="Kitting products name"><!-- 套餐名称 -->
                    <el-input v-model="form.packageName"></el-input>
                </el-form-item>
                <el-form-item label="Kitting products code"><!-- 套餐编号 -->
                    <el-input v-model="form.packageNo"></el-input>
                </el-form-item>
                <el-form-item label="标准价格">
                    <el-input v-model="form.amountStandard"></el-input>
                </el-form-item>
                <el-form-item label="Kitting products amount"><!-- 套餐金额 -->
                    <el-input v-model="form.amount"></el-input>
                </el-form-item>
                <el-form-item label="Kitting products BV"><!-- 套餐bV -->
                    <el-input v-model="form.amountPv"></el-input>
                </el-form-item>
                <el-form-item label="Entry level ID"><!-- 报单级别ID -->
                    <el-select v-model="form.levelId" placeholder="Select entry level"><!-- 请选择报单级别 -->
                        <el-option v-for="(item,index) in allDecLevel" :key="index" :label="item.LEVEL_NAME"
                                   :value="item.ID"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="Kit products"><!-- 套餐内容 -->
                    <el-input v-model="form.packageContent"></el-input>
                </el-form-item>
                <el-form-item label="套餐库存">
                    <el-input oninput="value=value.replace(/[^\d]/g,'')" v-model="form.storenums"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="addSubmit" :loading="submitButtonStat">Add<!-- 添加 --></el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    import store from '@/utils/vuexStore'
    import network from '@/utils/network'
    import tool from '@/utils/tool'
    import baseInfo from '../../utils/baseInfo'
    export default {
        name: "package-add",

        data(){
            return{
                loading: false,
                form:{
                    packageName:'',
                    packageNo:'',
                    id:'',
                    amount:'',
                    amountPv:'',
                    levelId:'',
                    packageContent:'',
                    amountStandard: '',
                    storenums:''
                },
                submitButtonStat: false,
                allDecLevel: baseInfo.decLevels(),
                exchangeRate: baseInfo.exchangeRate(),
            }
        },
        methods: {
            addSubmit() {
                this.submitButtonStat = true
                let path = 'shop/package-add';
                let postData = {
                    id: this.form.id,
                    packageName: this.form.packageName,
                    packageNo: this.form.packageNo,
                    amount: this.form.amount,
                    amountPv: this.form.amountPv,
                    levelId: this.form.levelId,
                    packageContent: this.form.packageContent,
                    amountStandard: this.form.amountStandard,
                    storenums:this.form.storenums,

                }

                return network.postData(path, postData).then(response => {
                    console.log(response);
                    this.$message({
                        message: response,
                        type: 'success'
                    })
                    this.submitButtonStat = false
                    this.$router.go(-1)
                }).catch(() => {
                    this.submitButtonStat = false
                })
            },
            handleEdit() {
                this.dialogEditFormVisible = false
                this.$message({
                    message: 'Modifying data',
                    type: 'info'
                })
                let path = 'finance/deal-type-edit'
                network.postData(path, this.form).then(response => {
                    this.$message({
                        message: response,
                        type: 'success'
                    })
                    this.getData(this.currentPage, this.pageSize)
                }).catch(response => {
                })
            },
        },
        watch:{
            // 监听商品标准价格,自动计算销售价格
            'form.amountStandard': {
                deep: true,
                handler(modern, origin) {
                    this.form.amount = modern * this.exchangeRate
                }
            },
        },
    }
</script>

<style scoped>

</style>
