<template>
    <div class="content-main tradingDetailPage">
        <h3>交易用户审核</h3>
        <el-form ref="formData" :model="formData" :rules="ruleData" label-width="140px">
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="企业名称:" prop="qymc">
                        <el-input v-model="formData.qymc" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="统一社会信用代码:" prop="tyshxydm">
                        <el-input v-model="formData.tyshxydm" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="纳税等级:" prop="nsdjmc">
                        <el-input v-model="formData.nsdjmc" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="法 人:" prop="fddbr">
                        <el-input v-model="formData.fddbr" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="开户银行账号:" prop="yhzh">
                        <el-input v-model="formData.yhzh" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="地 区:" prop="areaName">
                        <el-input v-model="formData.areaName" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="详细地址:" prop="qytxdz">
                        <el-input v-model="formData.qytxdz" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="邮政编码:" prop="qyyb">
                        <el-input v-model="formData.qyyb" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="联 系 人:" prop="qylxr">
                        <el-input v-model="formData.qylxr" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="联系方式:" prop="lxfs">
                        <el-input v-model="formData.lxfs" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="单位代码:" prop="dwdm">
                        <el-input v-model="formData.dwdm" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="审核结果:" prop="shjg">
                        <el-radio v-model="formData.shjg" label='2' :disabled="isShow">通过</el-radio>
                        <el-radio v-model="formData.shjg" label='3' :disabled="isShow">不通过</el-radio>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12" :offset="6">
                    <el-form-item label="审核意见:" prop="shyj">
                        <el-input v-model="formData.shyj" type='textarea' placeholder="请输入" clearable :autosize='{minRows: 4, maxRows: 4}' resize="none" :disabled="isShow"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-row style="text-align:center;margin-top:20px;padding-bottom: 20px;">
            <el-button
                @click="goSave"
                type="primary"
                size="small"
                class="iconfont iconbaocun"
                v-if="!isShow"
                :loading='btnLoading'
            >保存</el-button>
            <el-button
                @click="goBack"
                type="primary"
                size="small"
                class="iconfont iconfanhui"
            >返回</el-button>
        </el-row>
    </div>
</template>
<script>
    import { validateTenBai } from '@/directives'
    import { findDetail, checkSave } from "@/api/transaction/customerManager"
    export default {
        data() {
            return {
                formData: {
                    shjg: '',
                    shyj: ''
                },
                isShow: false,
                btnLoading: false,
                ruleData: {
                    shjg: [
                        {required: true, message: '请选择审核结果',trigger: ["blur",'change']}
                    ],
                    shyj: [
                        {validator: validateTenBai,trigger: "blur"}
                    ]
                }
            }
        },
        created() {
            if(this.$route.query.state == 'see') {
                this.isShow = true
            }
            this.getInitInfo()
        },
        methods: {
            getInitInfo() {
                findDetail(this.$route.query.id).then(res => {
                    if(res.infoCode == 200) {
                        this.formData = res.data
                        if(this.$route.query.state == 'see') {
                            this.formData.shjg = this.formData.qyzt.toString()
                        }
                    }else {
                        this.$message({
                            type: 'error',
                            message: res.msg,
                            duration: 2000
                        })
                    }
                })
            },
            goSave() {//保存
                this.$refs.formData.validate(valid => {
                    if(valid) {
                        this.formData.qyzt = parseInt(this.formData.shjg)
                        this.btnLoading = true
                        checkSave(this.formData).then(res => {
                            if(res.infoCode == 200) {
                                this.$message({
                                    type: 'success',
                                    message: '保存成功',
                                    duration: 2000
                                })
                                this.goBack()
                            }else {
                                this.$message({
                                    type: 'error',
                                    message: res.msg,
                                    duration: 2000
                                })
                                this.btnLoading = false
                            }
                        })
                    }else {
                        return false
                    }
                })
            },
            goBack() {
                this.$router.back(-1)
            }
        }
    }
</script>
<style scoped lang='scss'>
    .tradingDetailPage {
        h3 {
            font-size: 18px;
            font-weight: bold;
            text-align: center;
            padding-bottom: 20px;
        }
    }
</style>