<template>
    <el-dialog title="审核" :visible.sync="dialogVisible" width="50%" :before-close="close">
        <el-form :model="ruleForm" ref="ruleForm" :rules="formRules" label-width="100px">
            <el-form-item label="专家服务费" prop="serviceFee">
                <el-input v-model="ruleForm.serviceFee" maxLength="20"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="submit" :disabled="submitBtndisabled">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
import { expertApproval } from '@/apps/mobile/api/expert/index';
import { validPrice } from '@/apps/mobile/utils/validate';
export default {
    data() {
        // 验证费用
        var checkServiceFee = (rule, value, callback) => {
            if (value && !validPrice(value)) {
                callback(new Error('格式不正确'));
            } else {
                callback();
            }
        };
        return {
            dialogVisible: false,
            ruleForm: {},
            formRules: {
                serviceFee: [
                    {
                        required: true,
                        message: '请输入专家服务费',
                        trigger: 'blur',
                    },
                    {
                        required: true,
                        trigger: 'blur',
                        validator: checkServiceFee,
                        message: '请输入正确的服务费，保留两位小数',
                    },
                ],
            },
            submitBtndisabled: false,
            formData: {},
        };
    },
    methods: {
        open(data) {
            console.log(data);
            this.dialogVisible = true;
            this.submitBtndisabled = false;
            this.formData = { ...data };
        },
        close() {
            this.dialogVisible = false;
            this.submitBtndisabled = true;
            this.$refs['ruleForm'].resetFields();
            this.ruleForm = {};
        },
        submit() {
            this.$refs['ruleForm'].validate(valid => {
            if (valid) {
                let obj = {
                    id: this.formData.id,
                    checkFlag: 1,
                    serviceFee: this.ruleForm.serviceFee,
                };
                console.log(obj);
                expertApproval(obj)
                .then(res => {
                    if (res.statusCode === '1') {
                        this.$message.success(res.message);
                    } else {
                        this.$message.warning(res.message);
                    }
                    this.$emit('queryListData');
                    this.close();
                })
                .catch(() => {
                    this.submitBtndisabled = false;
                });
            } else {
                    return false;
                }
            });
        },
    }
};
</script>

