<template>
    <div>
        <navbar title="基本信息"></navbar>
        <div class="wrapper">
            <div class="title">基本信息</div>
            <van-form ref="form" :model="baseForm">
                <van-field v-model="baseForm.companyName" label="企业名称" placeholder="请输入"></van-field>
                <van-field v-model="baseForm.creditCode" label="统一信用码" placeholder="请输入"></van-field>
                <van-field v-model="baseForm.operName" label="法定代表人" placeholder="请输入"></van-field>
                <div class="jine">
                    <van-field v-model="baseForm.registCapi" label="注册资金" placeholder="请输入" type="number"></van-field>
                    <span class="danwei" v-if="baseForm.registCapi">万元人民币</span>
                </div>
                <div class="jine">
                    <van-field v-model="baseForm.recCap" label="实缴资金" placeholder="请输入" type="number"></van-field>   
                    <span class="danwei" v-if="baseForm.recCap">万元人民币</span>
                </div>
                <van-field v-model="baseForm.phoneNumber" label="联系电话" placeholder="请输入" type="number"></van-field>
                <van-field v-model="baseForm.registAddress" label="注册地址" placeholder="请输入" type="textarea"
                    :row="3"></van-field>
                <van-field v-model="baseForm.address" label="经营地址" placeholder="请输入" type="textarea" :row="3"></van-field>
                <van-field v-model="baseForm.industry" label="行业" placeholder="请输入"></van-field>
                <van-field v-model="baseForm.overdueFlg" label="有无征信逾期" placeholder="请输入无或是"></van-field>
                <van-field v-model="baseForm.litigFlg" label="有无涉诉执行" placeholder="请输入无或是"></van-field>
                <van-field v-model="baseForm.blackGreyFlg" label="行内黑灰名单" placeholder="请输入无或是"></van-field>
                <van-field v-model="baseForm.rnabhxFlg" label="行内核销贷款" placeholder="请输入无或是"></van-field>
                <div class="jine">
                    <van-field v-model="baseForm.financingAmt" label="银行融资金额" placeholder="请输入" type="number"></van-field>
                    <span class="danwei" v-if="baseForm.financingAmt">万元人民币</span>
                </div>
                <div class="jine">
                    <van-field v-model="baseForm.guaranteeAmt" label="对外担保金额" placeholder="请输入" type="number"></van-field>
                    <span class="danwei" v-if="baseForm.guaranteeAmt">万元人民币</span>
                </div>
           
                <van-field v-model="baseForm.otherBadFlg" label="有无其他不良" placeholder="请输入无或是"></van-field>
            </van-form>
            <div class="header">
                <div class="title">股权结构</div>
                <div class="header_btn">
                    <van-button plain color="#2372eb" size="mini" @click="handleStockholder">添加股东</van-button>
                </div>
            </div>
            <div class="main_item" v-for="(item, index) in stockList" :key="index" @click="goDetail(item)">
                <div class="main_item_left">{{ item.stockName }}({{ item.stockPercent }})</div>
                <div class="main_item_right"><van-icon name="arrow" class="header_icon" /></div>
            </div>
            <div class="title">我行业务情况</div>
            <van-form ref="form" :model="conditionform">
                <div class="jine">
                    <van-field v-model="conditionform.loanAmt" label="贷款金额" placeholder="请输入" type="number"></van-field>
                    <span class="danwei" v-if="conditionform.loanAmt">万元人民币</span>
                </div>
                <div class="jine">
                    <van-field v-model="conditionform.depositAmt" label="存款金额" placeholder="请输入" type="number"></van-field>
                    <span class="danwei" v-if="conditionform.depositAmt">万元人民币</span>
                </div>
                <div class="jine">
                    <van-field v-model="conditionform.internatAmt" label="国际结算金额" placeholder="请输入" type="number"></van-field>
                    <span class="danwei" v-if="conditionform.internatAmt">万元人民币</span>
                </div>
                <van-field v-model="conditionform.middleBusiness" label="中间业务" placeholder="请输入" type="textarea"
                    :row="3"></van-field>

            </van-form>
        </div>
        <div class="footer">
            <van-button type="primary" class="btn" @click="handleCommit">保存</van-button>
        </div>
    </div>
</template>
<script>
import navbar from '../../../components/navbar/navbar.vue';
import { queryReportCompanyInfo, queryPartnerInfos, updateReportCompanyInfo } from "@/service/api/report";
import {
    Icon,
    Field,
    Form,
    Button,
    Toast
} from 'vant';
export default {
    components: {
        navbar: navbar,
        VanIcon: Icon,
        VanForm: Form,
        VanField: Field,
        VanButton: Button,

    },
    data() {
        return {
            baseForm: {
                companyName: '',
                creditCode: '',
                operName: '',
                registCapi: '',
                recCap: '',
                phoneNumber: '',
                address: '',
                industry: '',
                overdueFlg: '',
                litigFlg: '',
                blackGreyFlg: '',
                rnabhxFlg: '',
                financingAmt: '',
                guaranteeAmt: '',
                otherBadFlg: ''
            },
            options: [
                { text: '无', value: '0' },
                { text: '是', value: '1' }
            ],
            stockList: [],
            conditionform: {
                loanAmt: '',
                depositAmt: '',
                internatAmt: '',
                middleBusiness: ''
            }
        }
    },
    created() {
        this.initQueryReportCompanyInfo()
        this.initQueryPartnerInfos()
    },
    methods: {
        async initQueryReportCompanyInfo() {
            const params = {
                companyId: sessionStorage.getItem('companyId')
            }
            let result = await queryReportCompanyInfo(params);
            if (result) {
                this.baseForm = result
                this.conditionform = result
                result.overdueFlg == '0' ? this.baseForm.overdueFlg = '无' : this.baseForm.overdueFlg = '是'
                result.litigFlg == '0' ? this.baseForm.litigFlg = '无' : this.baseForm.litigFlg = '是'
                result.blackGreyFlg == '0' ? this.baseForm.blackGreyFlg = '无' : this.baseForm.blackGreyFlg = '是'
                result.rnabhxFlg == '0' ? this.baseForm.rnabhxFlg = '无' : this.baseForm.rnabhxFlg = '是'
                result.otherBadFlg == '0' ? this.baseForm.otherBadFlg = '无' : this.baseForm.otherBadFlg = '是'
            }
        },
        async initQueryPartnerInfos() {
            const params = {
                companyId: sessionStorage.getItem('companyId'),
                pageNum: 1,
                pageSize: 10000
            }
            let result = await queryPartnerInfos(params);
            console.log(result, 'resultresult')
            this.stockList = result.records
        },
        async handleCommit() {
            console.log(this.baseForm, 'baseformbaseform')
            debugger
            this.baseForm.overdueFlg == '无' ? this.baseForm.overdueFlg = 0 : this.baseForm.overdueFlg = 1
            this.baseForm.litigFlg == '无' ? this.baseForm.litigFlg = 0 : this.baseForm.litigFlg = 1
            this.baseForm.blackGreyFlg == '无' ? this.baseForm.blackGreyFlg = 0 : this.baseForm.blackGreyFlg = 1
            this.baseForm.rnabhxFlg == '无' ? this.baseForm.rnabhxFlg = 0 : this.baseForm.rnabhxFlg = 1
            this.baseForm.otherBadFlg == '无' ? this.baseForm.otherBadFlg = 0 : this.baseForm.otherBadFlg = 1


            let result = updateReportCompanyInfo(this.baseForm)
            if (result) {
                Toast.success('更新成功');
                this.$router.go(-1)
            }
        },
        handleStockholder() {
            sessionStorage.setItem('addAndEdit', 'add');
            this.$router.push({ path: '/StockDetail' })
        },
        goDetail(item) {
            sessionStorage.setItem('addAndEdit', 'edit');
            let str = JSON.stringify(item)
            sessionStorage.setItem('shareholder', str);
            this.$router.push({ path: '/StockDetail' })
        },
    }
}
</script>
<style lang="less" scoped>
.wrapper {
    padding-top: 46px;
    min-height: 100vh;
    font-size: 16px;
    padding-bottom: 60px;
}

.title {
    line-height: 45px;
    padding: 5px 15px;
    color: rgb(89, 89, 89);
}

.header {
    display: flex;
    justify-content: space-between;
    padding-right: 15px;
    align-items: center;
}

.header_btn {
    text-align: center;
}

.main_item {
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    color: rgb(89, 89, 89);
    line-height: 45px;
    margin-top: 1px;

}

.main_item_left {
    font-size: 14px;
}

.footer {
    text-align: center;
    position: fixed;
    bottom: 0;
    width: 100%;
}

.btn {
    width: 100%;
}
.jine{
    display: flex;
    align-items: center;
    background-color: #fff;
    /deep/ .van-cell{
        width: 50%;
    }
}
.danwei{
    font-size: 14px;
}
</style>