<template>
    <div class="add-edit-dialog-container">
        <el-dialog :title="title" :visible.sync="isVisible" width="500px" :before-close="close">
            <el-form
                :model="addEditDialogForm"
                ref="addEditDialogForm"
                :rules="addEditDialogRules"
                label-width="90px"
            >
                <el-form-item label="税率" prop="taxRate">
                    <el-select v-model="addEditDialogForm.taxRate" placeholder="请选择">
                        <el-option
                            v-for="item in options"
                            :key="item.id"
                            :label="item.taxName"
                            :value="item.taxRate"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="close()">取 消</el-button>
                <el-button
                    type="primary"
                    @click="submitForm('addEditDialogForm')"
                    :disabled="submitBtndisabled"
                >确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { queryTaxRateList } from '@/apps/mobile/api/payment/auditInvoice/index';
export default {
    data() {
        return {
            isVisible: false,
            title: '税率设置',
            addEditDialogForm: {
                taxRate: null,
            },
            submitBtndisabled: false,
            addEditDialogRules: {
                taxRate: [
                    {
                        required: true,
                        message: '请选择税率',
                        trigger: 'change',
                    },
                ],
            },
            type: null,
            options: [],
        };
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    console.log(this.addEditDialogForm.taxRate);
                    // let formData = {
                    //     ...this.addEditDialogForm,
                    //     field: 'reward',
                    //     tableName: 'reward_setting',
                    // };
                    // let message = '新增成功';
                    // if (this.type === 'add') {
                    //     console.log(formData);
                    //     addDictionary(formData)
                    //         .then(res => {
                    //             this.completeOperation(message);
                    //         })
                    //         .catch(() => {
                    //             this.submitBtndisabled = false;
                    //         });
                    // }
                } else {
                    return false;
                }
            });
        },
        open(id) {
            console.log(id);
            this.getTaxRateList();
            this.isVisible = true;
        },
        close() {
            this.$refs['addEditDialogForm'].resetFields();
            this.isVisible = false;
        },
        getTaxRateList() {
            let obj = {
                examineFlag: 1,
                // id: 0,
                // pageNum: 0,
                // pageSize: 100,
                // sort: {
                //     order: 'string',
                //     orderBy: 'string',
                // },
            };
            queryTaxRateList(obj)
                .then(res => {
                    console.log(res);
                    this.options = res.data.records;
                })
                .catch();
        },
        completeOperation(message) {
            this.$message({
                type: 'success',
                message,
            });
            this.close();
            this.submitBtndisabled = false;
            this.$emit('queryListData');
        },
    },
};
</script>
<style lang="stylus" scoped>
.add-edit-dialog-container {
    ::v-deep .el-input__inner {
        width: 200px;
    }
}
</style>
