<template>
    <div class="main_box">
        <navbar :title="title" v-if="isShow == '1'"></navbar>
        <div class="wrapper" v-if="isShow == '1'">
            <van-form ref="form">
                <div class="title">法人信息</div>
                <van-field v-model="baseform.lpName" maxlength="18" label="法人姓名" name="lpName"
                    placeholder="请输入"></van-field>
                <van-field v-model="baseform.custIdc" label="身份证号" name="custIdc" placeholder="请输入" class="required-field"
                    @blur="initInfoByCustIdc(baseform.custIdc)"
                    :rules="[{ required: true, message: '身份证号不能为空' }, { required: true, validator: validateCustIdc }]"></van-field>
                <van-field label="性别" name="custGender">
                    <template #input>
                        <van-radio-group v-model="baseform.custGender" direction="horizontal">
                            <van-radio name="男">男</van-radio>
                            <van-radio name="女">女</van-radio>
                        </van-radio-group>
                    </template>
                </van-field>
                <van-field v-model="baseform.birthday" is-link readonly label="出生日期" name="birthday" placeholder="请选择"
                    @click="showDatePicker = true"></van-field>
                <van-popup v-model:show="showDatePicker" position="bottom">
                    <van-datetime-picker v-model="currentDate" :min-date="minDate" :max-date="maxDate" type="date"
                        title="选择日期" @confirm="onConfirmDate" @cancel="showDatePicker = false"></van-datetime-picker>
                </van-popup>
                <van-field v-model="baseform.custAge" maxlength="3" label="年龄" name="custAge" placeholder="请输入"></van-field>
                <van-field v-model="baseform.custPhone" label="法人手机号" name="custPhone" placeholder="请输入"
                    class="required-field"
                    :rules="[{ required: true, message: '法人手机号不能为空' }, { required: true, validator: validatePhone, }]"
                    maxlength="11"></van-field>
                <div class="title">企业信息</div>
                <van-field v-model="baseform.custName" maxlength="18" label="企业名称" name="custName"
                    placeholder="请输入" class="required-field" :rules="[{ required: true, message: '企业名称不能为空' }]"></van-field>
                <van-field v-model="baseform.socialCreditCode" maxlength="18" label="统信码" name="socialCreditCode" class="required-field"
                    :rules="[{ required: true, message: '统信码不能为空' }]"
                    placeholder="请输入" @blur="socialCreditCodeBlurFn(baseform.socialCreditCode)"></van-field>
                <van-field v-model="statusText" label="经营状态" is-link readonly placeholder="请选择"
                    @click="showPicker = true"></van-field>
                <van-popup v-model="showPicker" position="bottom" :style="{ height: '40%' }">
                    <van-picker show-toolbar :columns="statusList" @cancle="showPicker = false" :value-key="'label'"
                        @confirm="onConfirm" @cancel="cancelStatus"></van-picker>
                </van-popup>
                <van-field v-model="baseform.businessScope" label="经营范围" maxlength="18" name="businessScope"
                    placeholder="请输入"></van-field>
                <div class="dzxzq">
                    <van-field v-model="baseform.custLocation" label="经营地址" is-link readonly placeholder="请选择"
                        @click="handleShowjydz"></van-field>
                    <van-popup v-model="showCustLocationPicker" position="bottom" :style="{ height: '40%' }">
                        <div class="btn_box">
                            <div @click="handleJydzCancle">取消</div>
                            <div @click="handleJydzConfim">确定</div>
                        </div>
                        <div class="picker_box">
                            <van-picker show-toolbar :columns="cityList" :value-key="'text'"
                                @change="handleChangeCity"></van-picker>
                            <van-picker show-toolbar :columns="countyList" :value-key="'text'"
                                @change="handleChangeCounty"></van-picker>
                            <van-picker show-toolbar :columns="jdList" :value-key="'text'"
                                @change="handleChangeJd"></van-picker>
                            <van-picker show-toolbar :columns="cunList" :value-key="'text'"
                                @change="handleChangeCun"></van-picker>
                        </div>
                    </van-popup>
                </div>
                <van-field v-model="custLocationNum" label="门牌号" name="custLocationNum" placeholder="请输入门牌号"></van-field>
                <div class="dzxzq">
                    <van-field v-model="baseform.registerLocation" label="注册地址" is-link readonly placeholder="请选择"
                        @click="handleShowzcdz"></van-field>
                    <van-popup v-model="showzcPicker" position="bottom" :style="{ height: '40%' }">
                        <div class="btn_box">
                            <div @click="handlezcCancle">取消</div>
                            <div @click="handlezcConfim">确定</div>
                        </div>
                        <div class="picker_box">
                            <van-picker show-toolbar :columns="cityList" :value-key="'text'"
                                @change="handleChangeCity"></van-picker>
                            <van-picker show-toolbar :columns="countyList" :value-key="'text'"
                                @change="handleChangeCounty"></van-picker>
                            <van-picker show-toolbar :columns="jdList" :value-key="'text'"
                                @change="handleChangeJd"></van-picker>
                            <van-picker show-toolbar :columns="cunList" :value-key="'text'"
                                @change="handleChangeCun"></van-picker>
                        </div>
                    </van-popup>
                </div>
                <van-field v-model="registerLocationNum" label="门牌号" name="registerLocationNum"
                    placeholder="请输入门牌号"></van-field>
                <van-field v-model="baseform.custCapital" label="注册资本(万元)" maxlength="18" name="custCapital"
                    placeholder="请输入"></van-field>
                <van-field v-model="industryText" label="行业名称" is-link readonly placeholder="请选择"
                    @click="showPickerBelonBusi = true"></van-field>
                <van-popup v-model="showPickerBelonBusi" position="bottom" :style="{ height: '40%' }">
                    <van-picker show-toolbar :columns="belonBusiList" cancel-button-text="" confirm-button-text=""
                        @cancel="cancleBelonBusi" @confirm="changeBelonBusi" />
                </van-popup>
                <van-field v-model="baseform.tel" label="企业电话" name="tel" placeholder="请输入" maxlength="11"></van-field>
                <div class="title">关联人信息</div>
                <div class="glrBox" v-for="(item, index) in list" :key="index">
                    <div class="glrBox_left">
                        <div class="left_img_box">
                            <img src="../../images/home/xkdjrw.png" alt="" style="width: 30px;height: 30px;">
                        </div>
                        <div class="left_main_box">
                            <div class="left_main_box_top">{{ item.relatePerson }}</div>
                            <div class="left_main_box_card">身份号:{{ item.relateCustIdc }}</div>
                        </div>
                    </div>
                    <div class="glr_right">
                        <div class="glr_right_edit" @click="handleEdit(item, index)">编辑</div>
                        <div class="glr_right_delete" @click="handleDelete(index)">删除</div>
                    </div>
                </div>
                <div class="addBtn" @click="handleAdd">
                    <van-icon name="add"></van-icon>
                    <span>添加关联人</span>
                </div>

                <div class="title">其他信息</div>
                <van-field v-model="belongBranchText" label="客户经理归属机构" is-link readonly placeholder="请选择"
                    :rules="[{ required: true, message: '归属机构不能为空' }]" @click="showBelongBranch = true"
                    class="required-field"></van-field>
                <div class="gsjg">
                    <van-popup v-model="showBelongBranch" position="bottom" :style="{ height: '40%' }">
                        <van-picker show-toolbar :columns="belongBranchList" cancel-button-text="" confirm-button-text=""
                            @cancel="cancleBelongBranch" @confirm="changeBelongBranch" />
                    </van-popup>
                </div>

                <van-field v-model="belongUserText" label="客户经理" is-link readonly placeholder="请选择"
                    @click="customSelectFn"></van-field>
                <van-popup v-model="showUserPicker" position="bottom" :style="{ height: '40%' }">
                    <div class="search-input">
                        <van-search type="text" :left-icon="null" v-model="searchValue" placeholder="请输入搜索条件"
                            @clear="onCancel()" style="width:100%"/>
                        <div class="search_btn">
                            <van-icon name="search" @click="onSearch"></van-icon>
                        </div>
                    </div>
                    <van-picker show-toolbar :columns="userShowList" @cancle="showUserPicker = false" @confirm="onConfirmUser"
                        @cancel="cancelUser"></van-picker>
                </van-popup>
            </van-form>
            <div class="formBtn">
                <van-button plain color="#2372eb" @click="handleCancle" class="qx">取消</van-button>
                <van-button type="primary" @click="handleSave">保存</van-button>
            </div>
        </div>

        <div class="wrapper_two" v-if="isShow == '2'">
            <div class="navb" v-if="isShow == '2'">
                <div class="navLeft">
                    <van-icon name="arrow-left"></van-icon>
                    <span @click="handleAddCancle">返回</span>
                </div>
                <div class="navRight">添加关联人</div>
            </div>
            <van-form ref="addForm">
                <van-field v-model="addForm.relatePerson" maxlength="18" label="关联人" name="relatePerson"
                    placeholder="请输入"></van-field>
                <van-field v-model="addForm.relateCustIdc" maxlength="18" label="身份证号" name="relateCustIdc"
                    class="required-field" placeholder="请输入"
                    :rules="[{ required: true, message: '身份证号不能为空' }, { required: true, validator: addFormValidateCustIdc }]"></van-field>
            </van-form>
            <div class="addFormBtn">
                <van-button plain color="#2372eb" @click="handleAddCancle" class="qx">取消</van-button>
                <van-button type="primary" @click="handleAddSave">保存</van-button>
            </div>
        </div>
    </div>
</template>
<script>
import navbar from '../../components/navbar/navbar.vue';
import {
    Button, Form, Field, RadioGroup, Radio, Popup, DatetimePicker, Picker, Area, Cascader, Icon, TreeSelect, Search
} from 'vant';
import { getRegStatus, getIndustryTree } from "@/service/api/custome";
import { addRecord, recordCustInfo } from "@/service/api/filing";
import { getIndicator, getDeptTree,getDeptTreeAll, getDeptUser,getDeptUserAll } from "@/service/api/dzTree";
import _ from "lodash";
export default {
    data() {
        return {
            title: '企业客户',
            isShow: '1',
            addOrEdit: '',
            editInddex: null,
            statusText: '',
            showPicker: false,
            statusList: [],
            showCustLocationPicker: false,
            showzcPicker: false,
            cityList: [],
            cityObj: {},
            countyList: [],
            countyObj: {},
            jdList: [],
            jdObj: {},
            cunList: [],
            cunObj: {},
            showPickerBelonBusi: false,
            belonBusiList: [],
            baseform: {
                lpName: '',
                custIdc: '',
                custGender: '',
                birthday: '',
                custAge: '',
                custPhone: '',
                custName: '',
                socialCreditCode: '',
                status: '',
                businessScope: '',
                custLocation: '',
                registerLocation: '',
                custCapital: '',
                industry: '',
                tel: '',
                belongBranchId: '',

            },
            custLocationNum: '',
            registerLocationNum: '',
            industryText: '',
            showDatePicker: false,
            currentDate: new Date(),
            minDate: new Date(1900, 0, 1),
            maxDate: new Date(),
            list: [

            ],
            belongBranchText: '',
            belongBranchId: '',
            showBelongBranch: false,
            belongBranchList: [

            ],
            activeId: '',
            activeIndex: '',
            branchPrams: {},
            belongUserText: '',
            belongUserId: '',
            showUserPicker: false,
            userList: [],
            userShowList: [],
            addForm: {
                relatePerson: '',
                relateCustIdc: '',
            },
            searchValue:"",
            industryList:[],
        }
    },
    components: {
        navbar: navbar,
        VanButton: Button,
        VanForm: Form,
        VanField: Field,
        VanRadioGroup: RadioGroup,
        VanRadio: Radio,
        VanPopup: Popup,
        VanDatetimePicker: DatetimePicker,
        VanPicker: Picker,
        VanArea: Area,
        VanCascadePicker: Cascader,
        VanIcon: Icon,
        VanTreeSelect: TreeSelect,
        VanSearch: Search,
    },
    created() {
        this.initRegStatus()
        this.initIndustryTree()
        this.initGetDeptTree()
    },
    methods: {
        validateCustIdc(value) {

            const regex = /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
            if (!regex.test(value)) {
                // callback(new Error('请输入正确的身份证号码'))
                this.$toast('请输入正确的身份证号码')
                this.baseform.custIdc = ''
                return
            } else {
                return
            }
        },
        addFormValidateCustIdc(value) {

            const regex = /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
            if (!regex.test(value)) {
                // callback(new Error('请输入正确的身份证号码'))
                this.$toast('请输入正确的身份证号码')
                this.addForm.relateCustIdc = ''
                return
            } else {
                return
            }
        },
        validatePhone(value) {

            const regExp = /^1(3|4|5|6|7|8|9)[0-9]{9}$/
            if (!regExp.test(value)) {
                this.$toast('请输入正确的手机号码')
                this.baseform.custPhone = ''
                return
            } else {
                return
            }
        },
        onConfirmDate(value) {
            this.baseform.birthday = this.formatDate(value);
            const currentYear = new Date().getFullYear()
            const birthdayYear = Number(this.formatDate(value).slice(0, 4))
            this.baseform.custAge = currentYear - birthdayYear
            this.showDatePicker = false
        },
        formatDate(date) {
            if (date.getMonth() + 1 < 10) {
                return `${date.getYear() + 1900}-0${date.getMonth() + 1}-${date.getDate()}`;
            } else {
                return `${date.getYear() + 1900}-${date.getMonth() + 1}-${date.getDate()}`;
            }

        },
        onConfirm(value) {
            this.statusText = this.initStatus(value.value)
            this.baseform.status = value.value
            this.showPicker = false
        },
        cancelStatus() {
            this.showPicker = false
        },
        initRegStatus() {
            getRegStatus().then(res => {
                if (res.code == 200) {
                    this.statusList = res.data.map(item => {
                        return {
                            label: item.dictLabel,
                            value: item.dictValue
                        }
                    })

                }
            })
        },
        initStatus(data) {
            let arr = this.statusList.filter(item => item.value === data)
            if (arr && arr.length > 0) {
                return arr[0].label
            }
        },
        handleShowjydz() {
            this.showCustLocationPicker = true
            this.initGetIndicator()
        },
        initGetIndicator(data) {
            const query = {
                level: data ? data.level : '1',
                code: data ? data.value : 33
            }

            getIndicator(query).then(res => {
                if (res.code == 200) {
                    if (query.level == '1') {
                        this.cityList = res.data.map(item => {
                            return {
                                text: item.label,
                                value: item.value,
                                level: item.level
                            }
                        })
                        this.cityList.unshift({
                            text: '请选择',
                            value: '',
                            level: '1'
                        })
                    } else if (query.level == '2') {
                        this.countyList = res.data.map(item => {
                            return {
                                text: item.label,
                                value: item.value,
                                level: item.level
                            }
                        })
                        this.countyList.unshift({
                            text: '请选择',
                            value: '',
                            level: '2'
                        })
                    } else if (query.level == '3') {
                        this.jdList = res.data.map(item => {
                            return {
                                text: item.label,
                                value: item.value,
                                level: item.level
                            }
                        })
                        this.jdList.unshift({
                            text: '请选择',
                            value: '',
                            level: '3'
                        })
                    } else if (query.level == '4') {
                        this.cunList = res.data.map(item => {
                            return {
                                text: item.label,
                                value: item.value,
                                level: item.level
                            }
                        })
                        this.cunList.unshift({
                            text: '请选择',
                            value: '',
                            level: '4'
                        })
                    }

                }
            })
        },
        handleChangeCity(picker, value) {
            this.cityObj = value
            this.countyList = []
            const data = {
                level: value.level,
                value: value.value
            }
            this.initGetIndicator(data)

        },
        handleChangeCounty(picker, value) {
            this.countyObj = value
            this.jdList = []
            const data = {
                level: value.level,
                value: value.value
            }
            this.initGetIndicator(data)

        },
        handleChangeJd(picker, value) {
            this.jdObj = value
            this.cunList = []
            const data = {
                level: value.level,
                value: value.value
            }
            this.initGetIndicator(data)

        },
        handleChangeCun(picker, value) {
            this.cunObj = value
        },
        handleJydzCancle() {
            this.cityList = []
            this.countyList = []
            this.jdList = []
            this.cunList = []
            this.showCustLocationPicker = false
        },
        handleJydzConfim() {
            this.baseform.custLocation = `${this.cityObj.text}-${this.countyObj.text}-${this.jdObj.text}-${this.cunObj.text}`
            this.showCustLocationPicker = false
        },
        handleShowzcdz() {
            this.initGetIndicator()
            this.showzcPicker = true
        },
        handlezcCancle() {
            this.cityList = []
            this.countyList = []
            this.jdList = []
            this.cunList = []
            this.showzcPicker = false
        },
        handlezcConfim() {
            this.baseform.registerLocation = `${this.cityObj.text}-${this.countyObj.text}-${this.jdObj.text}-${this.cunObj.text}`
            this.showzcPicker = false
        },
        initIndustryTree() {
            getIndustryTree().then(res => {
                this.industryOptions = res.data.map(item => {
                    return {
                        value: item.code,
                        label: item.name,
                        children: item.industryTrees
                    }
                })
                this.industryOptions.forEach(item => {
                    item.children.forEach(el => {
                        el.value = el.code
                        el.label = el.name
                    })
                })
                this.belonBusiList = res.data.map(item => {
                    return {
                        text: item.name,
                        id: item.code,
                        children: item.industryTrees
                    }
                })
                this.belonBusiList.forEach(item => {
                    item.children.forEach(el => {
                        el.text = el.name
                        el.id = el.code
                    })
                })
                this.belonBusiList.forEach(item => {
                    item.children.unshift({
                        text: '请选择',
                        id: ''
                    })
                })
                this.industryList=this.getIndustryTreeFn(this.belonBusiList);
            })
        },
        getIndustryTreeFn(nodes){
            return _.flatMap(nodes, (node) => [
                node, // 直接添加当前节点（保留所有属性）
                ...(node.children && node.children.length 
                ? this.getIndustryTreeFn(node.children) // 递归处理子节点
                : [])
            ]);
        },
        cancleBelonBusi() {
            this.showPickerBelonBusi = false
        },
        changeBelonBusi(value) {

            let strOne = value[0]
            let strTwo = value[1]
            if (strTwo == '请选择') {
                let obj = this.belonBusiList.find(item => item.text == strOne)
                this.baseform.industry = obj.id
                this.industryText = obj.text
            } else {
                let obj = {}
                for (let i = 0; i < this.belonBusiList.length; i++) {
                    for (let j = 0; j < this.belonBusiList[i].children.length; j++) {
                        if (strTwo == this.belonBusiList[i].children[j].text) {
                            obj = this.belonBusiList[i].children[j]
                        }
                    }
                }
                this.baseform.industry = obj.id
                this.industryText = obj.text
            }
            this.showPickerBelonBusi = false
        },
        initGetDeptTree() {
            getDeptTreeAll().then(res => {
                if (res.code == 200) {
                    this.belongBranchList = res.data.map(item => {
                        return {
                            text: item.label,
                            id: item.id,
                            children: item.children
                        }
                    })
                    this.belongBranchList[0].children.forEach(item => {
                        item.text = item.label
                    })
                    this.belongBranchList[0].children.forEach(item => {
                        if (item.children) {
                            item.children.forEach(el => {
                                el.text = el.label
                            })
                        }
                    })
                    this.belongBranchList.forEach(item => {
                        item.children.unshift({
                            id: '',
                            text: '请选择',
                            children: []
                        })
                    })
                    this.belongBranchList[0].children.forEach(item => {
                        if (item.children) {
                            item.children.unshift({
                                id: '',
                                text: '请选择'
                            })
                        }
                    })
                    console.log(this.belongBranchList, 'this.belongBranchList')
                }
            })
        },
        cancleBelongBranch() {
            this.showBelongBranch = false
        },
        changeBelongBranch(value) {
            let one = value[0]
            let two = value[1]
            let three = value[2]
            if (two == '请选择' && three == '请选择') {
                this.belongBranchText = one
                this.belongBranchId = this.belongBranchList[0].id
            } else if (two != '请选择' && three == '请选择') {
                this.belongBranchText = two
                let idArr = this.belongBranchList[0].children.find(item => item.text == two)
                this.belongBranchId = idArr.id
            } else if (two != '请选择' && three != '请选择') {
                this.belongBranchText = three
                let obj = this.findBelongBranchId(this.belongBranchList, three)
                this.belongBranchId = obj.id
            }
            this.showBelongBranch = false
            this.initGetDeptUser()
        },
        findBelongBranchId(tree, text) {
            for (const node of tree) {
                if (node.text === text) {
                    return node
                }
                if (node.children && node.children.length) {
                    const found = this.findBelongBranchId(node.children, text)
                    if (found) return found
                }
            }
            return null
        },
        initGetDeptUser() {
            const query = {
                deptid: this.belongBranchId
            }
            getDeptUserAll(query).then(res => {
                if (res.code == 200) {
                    this.userList = res.data.map(item => {
                        return {
                            id: item.userName,
                            text: `${item.nickName}-${item.userName}`,
                        }
                    })
                    this.userShowList=this.userList||[]
                }

                console.log(this.userList, 'this.userList')
            })
        },
        onConfirmUser(value) {
            if(!value){
                return
            }
            this.belongUserText = value.text
            this.belongUserId = value.id
            this.showUserPicker = false
        },
        cancelUser() { this.showUserPicker = false },
        handleAdd() {
            this.isShow = '2'
            this.addOrEdit = 'add'
            this.title = '添加关联人'
        },
        handleAddCancle() {
            this.isShow = '1'
            this.addOrEdit = ''
            this.title = '企业客户'
            this.addForm = {
                relatePerson: '',
                relateCustIdc: '',
            }
        },
        handleAddSave() {
            this.$refs.addForm.validate().then(() => {
                this.isShow = '1'
                this.title = '企业客户'
                if (this.addOrEdit == 'add') {
                    this.list.push(
                        {
                            relatePerson: this.addForm.relatePerson,
                            relateCustIdc: this.addForm.relateCustIdc,
                        }
                    )
                    this.addForm = {
                        relatePerson: '',
                        relateCustIdc: '',
                    }
                    this.addOrEdit = ''
                } else if (this.addOrEdit == 'edit') {
                    this.list.splice(this.editInddex, 1, {
                        relatePerson: this.addForm.relatePerson,
                        relateCustIdc: this.addForm.relateCustIdc,
                    })
                }
            }).catch(() => {
                this.$toast('请输入必填项')
            })
        },
        handleEdit(item, index) {
            this.isShow = '2'
            this.editInddex = index
            this.addOrEdit = 'edit'
            this.title = '添加关联人'
            this.addForm.relatePerson = item.relatePerson
            this.addForm.relateCustIdc = item.relateCustIdc
        },
        handleDelete(index) {
            this.list.splice(index, 1)
        },
        handleCancle() {
            this.$router.go(-1);
        },
        initInfoByCustIdc(data) {

            //性别
            let sexCode = data.charAt(16)
            let gender = parseInt(sexCode, 10) % 2 === 0 ? '女' : '男'
            //年龄
            let today = new Date()
            let birthDate = new Date(data.substring(6, 10))
            let age = today.getFullYear() - birthDate.getFullYear()
            //出生日期
            let year = data.substring(6, 10)
            let mounth = data.substring(10, 12)
            let day = data.substring(12, 14)
            let csDate = `${year}-${mounth}-${day}`
            this.baseform.custGender = gender
            this.baseform.birthday = csDate
            this.baseform.custAge = age

        },
        socialCreditCodeBlurFn(){
            let params={
               custType: '2',
               custId: this.baseform.socialCreditCode
            }
            recordCustInfo(params).then(res => {
                if(res.code == 200){
                    if(res?.data?.custInfoRecord?.custName){
                        this.baseform.custName=res?.data?.custInfoRecord?.custName
                    }
                    if(res?.data?.custInfoRecord?.lpName){
                        this.baseform.lpName=res?.data?.custInfoRecord?.lpName
                    }
                    if(res?.data?.custInfoRecord?.custPhone){
                        this.baseform.custPhone=res?.data?.custInfoRecord?.custPhone
                    }
                    if(res?.data?.custInfoRecord?.custCapital){
                        this.baseform.custCapital=res?.data?.custInfoRecord?.custCapital
                    }
                    if(res?.data?.custInfoRecord?.custLocation){
                        this.baseform.custLocation=res?.data?.custInfoRecord?.custLocation
                    }
                    // if(res?.data?.custInfoRecord?.belongBranchId){
                    //     this.belongBranchId=res?.data?.custInfoRecord?.belongBranchId
                    // }
                    // if(res?.data?.custInfoRecord?.belongBranchName){
                    //     this.belongBranchName=res?.data?.custInfoRecord?.belongBranchName
                    // }
                    // if(res?.data?.custInfoRecord?.belongUserId){
                    //     this.belongUserId=res?.data?.custInfoRecord?.belongUserId
                    // }
                    // if(res?.data?.custInfoRecord?.belongUserName){
                    //     this.belongUserName=res?.data?.custInfoRecord?.belongUserName
                    // }
                    if(res?.data?.custInfoRecord?.tel){
                        this.baseform.tel=res?.data?.custInfoRecord?.tel
                    }
                    if(res?.data?.custInfoRecord?.registerLocation){
                        this.baseform.registerLocation=res?.data?.custInfoRecord?.registerLocation
                    }
                    if(res?.data?.custInfoRecord?.businessScope){
                        this.baseform.businessScope=res?.data?.custInfoRecord?.businessScope
                    }
                    if(res?.data?.custInfoRecord?.industry){
                        this.baseform.industry=res?.data?.custInfoRecord?.industry
                        this.industryText=_.find(this.industryList, { code: res?.data?.custInfoRecord?.industry })?.text;
                    }
                    if(res?.data?.custInfoRecord?.custIdc){
                        this.baseform.custIdc=res?.data?.custInfoRecord?.custIdc
                    }
                    if(res?.data?.custInfoRecord?.custGender){
                        this.baseform.custGender=res?.data?.custInfoRecord?.custGender
                    }
                    if(res?.data?.custInfoRecord?.custAge){
                        this.baseform.custAge=res?.data?.custInfoRecord?.custAge
                    }
                    if(res?.data?.custInfoRecord?.birthday){
                        this.baseform.birthday=res?.data?.custInfoRecord?.birthday
                    }
                    if(res?.data?.recordRelates){
                        this.list=res?.data?.recordRelates||[]
                    }
                }
            })
        },
        handleSave() {
            this.$refs.form.validate().then(() => {
                const infoParams = {
                    custType: '2',
                    custIdc: this.baseform.custIdc,
                    lpName: this.baseform.lpName,
                    custGender: this.baseform.custGender,
                    birthday: this.baseform.birthday,
                    custAge: this.baseform.custAge,
                    custPhone: this.baseform.custPhone,
                    registerLocation: `${this.baseform.registerLocation} ${this.registerLocationNum}`,
                    custLocation: `${this.baseform.custLocation} ${this.custLocationNum}`,
                    socialCreditCode: this.baseform.socialCreditCode,
                    custName: this.baseform.custName,
                    businessScope: this.baseform.businessScope,
                    status: this.baseform.status,
                    custCapital: this.baseform.custCapital,
                    industry: this.baseform.industry,
                    tel: this.baseform.tel,
                    belongBranchId: this.belongBranchId,
                    belongBranchName: this.belongBranchText,
                    belongUserId: this.belongUserId,
                    belongUserName: this.belongUserText,
                }
                console.log(infoParams)
                const params = {
                    custInfoRecord: infoParams,
                    familyMembersRecords: [],
                    recordRelates: this.list

                }
                console.log(params)
                addRecord(params).then(res => {
                    sessionStorage.setItem("activeTab", 0);
                    this.$router.push('/filingHome');
                })
            }).catch(() => {
                this.$toast('请输入必填项')
            })



        },
        customSelectFn(){
            this.showUserPicker = true;
            this.searchValue="";
            this.userShowList=this.userList;
        },
        onCancel(){
            this.userShowList=this.userList;
        },
        onSearch(){
            this.userShowList=this.userList.filter(item => item.text.includes(this.searchValue));
        },
    }
}


</script>
<style lang="less" scoped>
.wrapper {
    padding-top: 46px;
    min-height: 100vh;
    font-size: 16px;
    padding-bottom: 60px;
}

.wrapper_two {
    min-height: 100vh;
    font-size: 16px;
    padding-bottom: 60px;
}

.title {
    color: rgb(89, 89, 89);
    font-size: 12px;
    line-height: 35px;
    padding-left: 15px;
}

.dzxzq {
    /deep/ .van-picker__toolbar {
        display: none;
    }
}

.btn_box {
    display: flex;
    padding: 20px;
    justify-content: space-between;
}

.picker_box {
    display: flex;

    /deep/ .van-picker {
        width: 40%;
    }
}

.glrBox {
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    margin-top: 3px;
    padding: 15px;
}

.glrBox_left {
    display: flex;
    align-items: center;

}

.left_img_box {
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    background-color: rgb(246, 249, 255);
}

.left_main_box {
    margin-left: 20px;
}

.left_main_box_top {
    font-size: 16px;
    font-weight: 600;
    line-height: 30px;
}

.left_main_box_card {
    font-size: 12px;
    line-height: 25px;
    color: rgb(140, 140, 140);
}

.glr_right {
    display: flex;
}

.glr_right_edit {
    background-color: rgb(233, 241, 253);
    color: rgb(35, 114, 235);
    height: 33px;
    line-height: 33px;
    width: 60px;
    text-align: center;
    border-radius: 5px;
}

.glr_right_delete {
    background-color: rgb(253, 243, 234);
    color: rgb(238, 140, 21);
    height: 33px;
    line-height: 33px;
    width: 60px;
    text-align: center;
    border-radius: 5px;
    margin-left: 5px;
}

.addBtn {
    margin-top: 5px;
    line-height: 50px;
    background-color: rgb(233, 241, 253);
    color: rgb(35, 114, 235);
    text-align: center;
    border: 1px solid rgb(35, 114, 235);
}

.addFormBtn {
    margin-top: 50px;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;

    /deep/ .van-button {
        width: 48%;
    }
}

.formBtn {
    display: flex;
    justify-content: space-between;

    /deep/ .van-button {
        width: 48%;
    }
}

.navb {
    background-color: #fff;
    display: flex;
    line-height: 46px;
    padding-left: 16px;
}

.navLeft {
    color: #1989fa;
    width: 40%;
}

.gsjg {
    /deep/ .van-ellipsis {
        white-space: normal;
    }
}

.required-field {
    /deep/ .van-field__label::after {
        content: " *";
        color: red;
    }
}
.search-input {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-right: 15px;
}
.search_btn {
    background-color: rgb(24, 144, 255);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    color: #fff;
    font-size: 20px;
}
</style>