<template>
    <div class="main_box">
        <navbar title="我的客户"></navbar>
        <div class="wrapper">
            <div class="wrapper_main">
                <van-tabs @change="tabChange()" v-model="activeTab" class="content" type="line" color="#4682ff" title-active-color="#4682ff" line-width="80">
                    <van-tab title="企业" :disabled="isPrivate || personalOnly">
                        <div class="search-input">
                            <van-search type="text" :left-icon="null" v-model="searchValue" placeholder="搜索客户号、客户名称"
                                @clear="handleSearch()" @keyup.enter.native="handleSearch()" />
                            <div class="search_btn">
                                <van-icon name="search" @click="handleSearch"></van-icon>
                            </div>
                        </div>
                        <div class="special-search-box">
                            <van-dropdown-menu active-color="#4682ff">
                                <van-dropdown-item
                                    title="更多筛选"
                                    ref="moreRef"
                                    :title-class="moreSearch ? 'title-dist' : ''"
                                    v-if="activeTab == 0"
                                    >
                                    <div class="ssb-box">
                                        <van-sidebar v-model="activeKey">
                                            <van-sidebar-item
                                                title="总行行政网格"
                                                :class="queryForm.firstGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="支行行政网格"
                                                :class="queryForm.secondGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="自绘地图网格"
                                                :class="queryForm.mapGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="自建名单网格"
                                                :class="queryForm.mdGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                        </van-sidebar>
                                        <div class="ssb-box-rg">
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 0"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in firstGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.firstGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'firstGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 1"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in secondGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.secondGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'secondGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 2"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in mapGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.mapGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'mapGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 3"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in mdGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.mdGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'mdGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                        </div>
                                    </div>
                                    <div class="footer">
                                        <van-button class="btn" @click="resetForm">重置</van-button>
                                        <van-button type="primary" class="btn" @click="submitForm">确认</van-button>
                                    </div>
                                </van-dropdown-item>
                            </van-dropdown-menu>
                        </div>
                        <van-pull-refresh v-model="firmRefreshing" @refresh="onRefresh">
                            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :immediate-check="false"
                                @load="onLoad">
                                <div class="item" v-for="(item, index) in list" :key="index">
                                    <div class="item_top">
                                        <div class="item_top_left">
                                            <div class="icon_box">
                                                <img src="../../images/part_one/icon_company.png" alt="">
                                            </div>
                                            <div class="item_name">{{ item.custName }}</div>
                                        </div>
                                        <div class="item_viewDetail" @click="handleViewFirmDetail(item)">查看详情</div>
                                    </div>
                                    <div class="item_main">
                                        <div class="main_item"><span class="mian_title">统信码：</span>{{ item.socialCreditCode
                                        }}</div>
                                        <div class="main_item"><span class="mian_title">企业地址：</span>{{ item.custLocation }}
                                        </div>
                                        <div class="main_item"><span class="mian_title">法人代表：</span>{{ item.lpName }}</div>
                                        <div class="main_item"><span class="mian_title">联系方式：</span>{{ item.custPhone }}
                                        </div>
                                        <div class="main_item"><span class="mian_title">经营状态：</span>{{
                                            initStatus(item.status) }}</div>
                                    </div>
                                </div>
                            </van-list>
                        </van-pull-refresh>

                    </van-tab>
                    <van-tab title="个人" :disabled="isPublic">
                        <div class="search-input">
                            <van-search type="text" :left-icon="null" v-model="searchValue" placeholder="搜索客户号、客户名称"
                                @clear="handleSearch()" @keyup.enter.native="handleSearch()" />
                            <div class="search_btn">
                                <van-icon name="search" @click="handleSearch"></van-icon>
                            </div>
                        </div>
                        <div class="special-search-box">
                            <van-dropdown-menu active-color="#4682ff">
                                <van-dropdown-item
                                    title="更多筛选"
                                    ref="moreRef"
                                    :title-class="moreSearch ? 'title-dist' : ''"
                                    v-if="activeTab == 1"
                                    >
                                    <div class="ssb-box">
                                        <van-sidebar v-model="activeKey">
                                            <van-sidebar-item
                                                title="总行行政网格"
                                                :class="queryForm.firstGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="支行行政网格"
                                                :class="queryForm.secondGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="自绘地图网格"
                                                :class="queryForm.mapGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="自建名单网格"
                                                :class="queryForm.mdGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="客户层级"
                                                v-if="showLevel"
                                                :class="queryForm.mdGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                        </van-sidebar>
                                        <div class="ssb-box-rg">
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 0"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in firstGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.firstGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'firstGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 1"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in secondGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.secondGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'secondGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 2"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in mapGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.mapGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'mapGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 3"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in mdGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.mdGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'mdGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-if="(userInfo.deptId+'').substring(0,3) == '875' && activeKey == 4"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in custLevelList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.custLevel.includes(item) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'custLevel')"
                                                    :style="item? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item }}
                                                </van-col>
                                            </van-row>
                                        </div>
                                    </div>
                                    <div class="footer">
                                        <van-button class="btn" @click="resetForm">重置</van-button>
                                        <van-button type="primary" class="btn" @click="submitForm">确认</van-button>
                                    </div>
                                </van-dropdown-item>
                            </van-dropdown-menu>
                        </div>
                        <van-pull-refresh v-model="firmRefreshing" @refresh="onRefresh">
                            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :immediate-check="false"
                                @load="onLoad">
                                <div class="item" v-for="(item, index) in list" :key="index">
                                    <div class="item_top">
                                        <div class="item_top_left">
                                            <div :class="item.custGender == '男' ? 'userMan_box' : 'userWoMan_box'">
                                                <van-icon name="manager item_user"></van-icon>
                                            </div>
                                            <div class="item_name">{{ item.custName }}</div>
                                        </div>
                                        <div class="item_viewDetail" @click="handleViewPersonDetail(item)">查看详情</div>
                                    </div>
                                    <div class="item_main">
                                        <div class="main_item"><span class="mian_title">身份证号：</span>{{ item.custIdc }}</div>
                                        <div class="main_item"><span class="mian_title">性别：</span>{{ item.custGender }}
                                        </div>
                                        <div class="main_item"><span class="mian_title">联系方式：</span>{{ item.custPhone }}
                                        </div>
                                        <div class="main_item"><span class="mian_title">客户内码：</span>{{ item.custIsn }}</div>
                                        <div class="main_item" v-if="showLevel"><span class="mian_title">客户层级：</span>{{ item.custLevel }}</div>
                                        <!-- <div class="main_item"><span class="mian_title">征信授权：</span>{{ item.status }}</div> -->
                                    </div>
                                </div>
                            </van-list>
                        </van-pull-refresh>

                    </van-tab>
                    <van-tab title="商户" :disabled="isPublic || personalOnly">
                        <div class="search-input">
                            <van-search type="text" :left-icon="null" v-model="searchValue" placeholder="搜索客户号、客户名称"
                                @clear="handleSearch()" @keyup.enter.native="handleSearch()" />
                            <div class="search_btn">
                                <van-icon name="search" @click="handleSearch"></van-icon>
                            </div>
                        </div>
                        <div class="special-search-box">
                            <van-dropdown-menu active-color="#4682ff">
                                <van-dropdown-item
                                    title="更多筛选"
                                    ref="moreRef"
                                    :title-class="moreSearch ? 'title-dist' : ''"
                                    v-if="activeTab == 2"
                                    >
                                    <div class="ssb-box">
                                        <van-sidebar v-model="activeKey">
                                            <van-sidebar-item
                                                title="总行行政网格"
                                                :class="queryForm.firstGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="支行行政网格"
                                                :class="queryForm.secondGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="自绘地图网格"
                                                :class="queryForm.mapGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                            <van-sidebar-item
                                                title="自建名单网格"
                                                :class="queryForm.mdGird.length ? 'activeBar' : ''"
                                            ></van-sidebar-item>
                                        </van-sidebar>
                                        <div class="ssb-box-rg">
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 0"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in firstGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.firstGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'firstGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 1"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in secondGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.secondGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'secondGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 2"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in mapGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.mapGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'mapGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                            <van-row
                                                type="flex"
                                                justify="space-around"
                                                v-show="activeKey == 3"
                                            >
                                                <van-col
                                                    span="11"
                                                    v-for="(item, index) in mdGirdList"
                                                    :key="index"
                                                    class="ssb-box-rg-item"
                                                    :class="queryForm.mdGird.includes(item.gridId) ? 'ssb-box-rg-item-active' : ''"
                                                    @click="handleClickItem(item, 'mdGird')"
                                                    :style="item.gridId? { visibility: 'visible' }: { visibility: 'hidden' }"
                                                >
                                                    {{ item.gridName }}
                                                </van-col>
                                            </van-row>
                                        </div>
                                    </div>
                                    <div class="footer">
                                        <van-button class="btn" @click="resetForm">重置</van-button>
                                        <van-button type="primary" class="btn" @click="submitForm">确认</van-button>
                                    </div>
                                </van-dropdown-item>
                            </van-dropdown-menu>
                        </div>
                        <van-pull-refresh v-model="firmRefreshing" @refresh="onRefresh">
                            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :immediate-check="false"
                                @load="onLoad">
                                <div class="item" v-for="(item, index) in list" :key="index">
                                    <div class="item_top">
                                        <div class="item_top_left">
                                            <div class="userMan_box">
                                                <img src="../../images/home/sh.png" alt=""
                                                    style="width: 25px;height: 25px;">
                                            </div>
                                            <div class="item_name">{{ item.custName }}</div>
                                        </div>
                                        <div class="item_viewDetail" @click="handleViewCommercialDetail(item)">查看详情</div>
                                    </div>
                                    <div class="item_main">
                                        <div class="main_item"><span class="mian_title">身份证号：</span>{{ item.custIdc }}</div>
                                        <div class="main_item"><span class="mian_title">性别：</span>{{ item.custGender }}
                                        </div>
                                        <div class="main_item"><span class="mian_title">联系方式：</span>{{ item.custPhone }}
                                        </div>
                                        <div class="main_item"><span class="mian_title">统信码：</span>{{ item.socialCreditCode
                                        }}</div>
                                        <div class="main_item"><span class="mian_title">经营状态：</span>{{
                                            initStatus(item.status) }}</div>
                                        <div class="main_item"><span class="mian_title">商铺地址：</span>{{ item.custLocation }}
                                        </div>
                                    </div>
                                </div>
                            </van-list>
                        </van-pull-refresh>


                    </van-tab>
                </van-tabs>
            </div>
        </div>
    </div>
</template>
<script>
import navbar from '../../components/navbar/navbar.vue';
import { custBaseInfoList, getRegStatus, gridCmpmCustBaseInfoList, gridCmpmCustListTag } from "@/service/api/custome";
import { gridSelectRegion,gridSelectDraw,gridSelectVirtual } from "@/service/api/myGrid.js";
import {
    Tab,
    Tabs,
    Icon,
    Button,
    Search,
    List,
    PullRefresh,
    DropdownMenu,
    DropdownItem,
    Sidebar,
    SidebarItem,
    Row,
    Col,
} from 'vant';
import { mapGetters } from 'vuex'
export default {
    data() {
        return {
            activeTab: 0,
            searchValue: '',
            num: '2',
            list: [

            ],
            personList: [

            ],
            commerList: [

            ],
            pageNum: 1,
            pageSize: 5,
            custPattern: '2',
            firmRefreshing: false,
            loading: false,
            finished: false,
            currentPage: 1,
            statusList: [],
            isHeadAdmin:false,
            isPublic:false,
            isPrivate:false,
            isHeadOps:false,
            isBranchAdmin:false,
            isOutletAdmin:false,
            isCommonManager:false,
            moreSearch:false,
            activeKey: 0,
            queryForm:{
                firstGird:[],
                secondGird:[],
                mapGird:[],
                mdGird:[],
                custLevel: []
            },
            firstGirdList:[],
            secondGirdList:[],
            mapGirdList:[],
            mdGirdList:[],
            custLevelList: [],
            personalOnly: false,
            userInfo: JSON.parse(sessionStorage.getItem('userInfo'))
        }
    },
    computed: {
        ...mapGetters(["userInfo"]),
        showLevel() {
            const arr = ['931', '875'] // 莲都、海宁
            const { deptId = '' } = this.userInfo
            const str = String(deptId).substring(0,3)
            return arr.includes(str) ? true : false
        }
    },
    components: {
        navbar: navbar,
        VanTab: Tab,
        VanTabs: Tabs,
        VanIcon: Icon,
        VanButton: Button,
        VanSearch: Search,
        VanList: List,
        VanPullRefresh: PullRefresh,
        VanDropdownMenu: DropdownMenu,
        VanDropdownItem: DropdownItem,
        VanSidebar: Sidebar,
        VanSidebarItem: SidebarItem,
        VanRow: Row,
        VanCol: Col,
    },
    created() {
        let userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
        if (userInfo.roles.includes('headAdmin')) {
            this.isHeadAdmin = true
        } else if (userInfo.roles.includes('headPublic')) {
            this.isPublic = true
        } else if (userInfo.roles.includes('headPrivate')) {
            this.isPrivate = true
            this.custPattern = '0'
        } else if (userInfo.roles.includes('headOps')) {
            this.isHeadOps = true
        } else if (userInfo.roles.includes('branchAdmin')) {
            this.isBranchAdmin = true
        } else if (userInfo.roles.includes('outletAdmin')) {
            this.isOutletAdmin = true
        } else if (userInfo.roles.includes('commonManager')) {
            this.isCommonManager = true
        }
        let activeTab = sessionStorage.getItem('activeTab')
        console.log(565656, (userInfo.deptId+'').substring(0,3), userInfo)
        if ((userInfo.deptId+'').substring(0,3) == '875') {
          console.log(1111111111111)
          activeTab = 1
          this.activeTab = 1
          this.personalOnly = true
        } else {
          if (activeTab) {
            this.activeTab = Number(activeTab);
          }
        }
        if (activeTab == 0) {
            this.custPattern = '2'
        } else if (activeTab == 1) {
            this.custPattern = '0'
        } else if (activeTab == 2) {
            this.custPattern = '1'
        }
        this.initList();
        this.gridSelectRegionFn('1');
        this.gridSelectRegionFn('2');
        this.gridSelectDrawFn();
        this.gridSelectVirtualFn();
        this.gridCmpmCustListTagFn()
    },
    methods: {
        async gridSelectRegionFn(type){
            const params = {
                gridLevel: type,
            };
            if (this.activeTab == '0') {
                params.opsDept = '1'
            } else {
                params.opsDept = '0'
            }
            const res = await gridSelectRegion(params)
            if (res.code == 200) {
                if(type == '1'){
                    this.firstGirdList=res.data||[]
                    if(this.firstGirdList.length % 2 == 1){
                         this.firstGirdList.push({})
                    }
                }else{
                    this.secondGirdList=res.data||[]
                    if(this.secondGirdList.length % 2 == 1){
                         this.secondGirdList.push({})
                    }
                }
            }
        },
        async gridSelectDrawFn(){
            const params = {};
            if (this.activeTab == '0') {
                params.opsDept = '1'
            } else {
                params.opsDept = '0'
            }
            const res = await gridSelectDraw(params)
            if (res.code == 200) {
                this.mapGirdList=res.data||[]
                if(this.mapGirdList.length % 2 == 1){
                    this.mapGirdList.push({})
                }
            }
        },
        async gridSelectVirtualFn(){
            const params = {};
            if (this.activeTab == '0') {
                params.opsDept = '1'
            } else {
                params.opsDept = '0'
            }
            const res = await gridSelectVirtual(params)
            if (res.code == 200) {
                this.mdGirdList=res.data||[]
                if(this.mdGirdList.length % 2 == 1){
                    this.mdGirdList.push({})
                }
            }
        },
        async gridCmpmCustListTagFn() {
            const res = await gridCmpmCustListTag('retail')
            if (res.code == 200) {
                this.custLevelList=res.data||[]
                // if(this.custLevelList.length % 2 == 1){
                //     this.custLevelList.push({})
                // }
            }
            console.log(111111111, this.custLevelList)
        },
        handleClickItem(row,type){
            if(type == 'firstGird'){
                const index = this.queryForm.firstGird.findIndex((value) => value == row.gridId);
                if (index > -1) {
                    this.queryForm.firstGird.splice(index, 1);
                } else {
                    this.queryForm.firstGird.push(row.gridId);
                }
            }else if(type == 'secondGird'){
                const index = this.queryForm.secondGird.findIndex((value) => value == row.gridId);
                if (index > -1) {
                    this.queryForm.secondGird.splice(index, 1);
                } else {
                    this.queryForm.secondGird.push(row.gridId);
                }
            }else if(type == 'mapGird'){
                const index = this.queryForm.mapGird.findIndex((value) => value == row.gridId);
                if (index > -1) {
                    this.queryForm.mapGird.splice(index, 1);
                } else {
                    this.queryForm.mapGird.push(row.gridId);
                }
            }else if(type == 'mdGird'){
                const index = this.queryForm.mdGird.findIndex((value) => value == row.gridId);
                if (index > -1) {
                    this.queryForm.mdGird.splice(index, 1);
                } else {
                    this.queryForm.mdGird.push(row.gridId);
                }
            }else if(type == 'custLevel'){
                const index = this.queryForm.custLevel.findIndex((value) => value == row);
                if (index > -1) {
                    this.queryForm.custLevel.splice(index, 1);
                } else {
                    this.queryForm.custLevel.push(row);
                }
            }
        },
        resetForm(){
            this.queryForm={
                firstGird:[],
                secondGird:[],
                mapGird:[],
                mdGird:[],
            }
            this.submitForm();
        },
        submitForm(){
            this.handleSearch();
            this.$refs.moreRef.toggle();
        },
        async initList() {

            if (this.currentPage === 1) {
                this.list = [];
            }
            const params = {
                num: this.pageNum,
                size: this.pageSize,
                custPattern: this.custPattern,
                isSelectGrid: false,
                searchStr: this.searchValue,
                regionTopGridIds:this.queryForm.firstGird,
                regionSecGridIds:this.queryForm.secondGird,
                drawGridIds:this.queryForm.mapGird,
                virtualGridIds:this.queryForm.mdGird,
                custLevelList:this.queryForm.custLevel
            };
            if(this.queryForm.firstGird.length == 0 && this.queryForm.secondGird.length == 0 && this.queryForm.mapGird.length == 0 && this.queryForm.mdGird.length == 0){
                params.isSelectGrid=false;
                this.moreSearch=false;
            }else{
                params.isSelectGrid=true;
                this.moreSearch=true;
            }
            // if (this.personalOnly) {
            //   const res = await gridCmpmCustBaseInfoList(params)
            // } else {
            //   const res = await custBaseInfoList(params)
            // }
            const res = this.personalOnly ? await gridCmpmCustBaseInfoList(params) : await custBaseInfoList(params)
            console.log(res, 'ressss')
            if (res.code == 200) {
                sessionStorage.removeItem('activeTab')
                this.initRegStatus()
                if (this.firmRefreshing) {
                    this.firmRefreshing = false;
                }
                this.loading = false;
                if (res.data) {
                    this.list = params.num == "1" ? res.data : [...this.list, ...res.data];
                    if (res.data.length < params.size) {
                        this.finished = true;
                    }
                    this.currentPage++;
                } else {
                    this.list = []
                    this.finished = true;
                }
            }
        },
        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
            }
        },
        tabChange() {
            if (this.activeTab == 0) {
                this.custPattern = '2'
            } else if (this.activeTab == 1) {
                this.custPattern = '0'
            } else if (this.activeTab == 2) {
                this.custPattern = '1'
            }
            this.searchValue = ''
            this.currentPage = 1;
            this.pageNum = 1;
            this.activeKey=0;
            this.queryForm={
                firstGird:[],
                secondGird:[],
                mapGird:[],
                mdGird:[],
            }
            this.initList();
            this.gridSelectRegionFn('1');
            this.gridSelectRegionFn('2');
            this.gridSelectDrawFn();
            this.gridSelectVirtualFn();
        },
        //下拉刷新
        onRefresh() {
            this.list = [];
            this.finished = false; //解除上拉加载之后数据不能再次上拉
            this.currentPage = 1;
            this.pageNum = this.currentPage;
            this.initList();
        },
        //上拉加载
        onLoad() {
            this.pageNum = this.currentPage + "";
            this.initList();
        },
        handleSearch() {
            this.currentPage = 1;
            this.pageNum = 1;
            this.initList();
        },
        handleViewFirmDetail(item) {
            sessionStorage.setItem('custId', item.custId);
            sessionStorage.setItem("activeTab", this.activeTab);
            this.$router.push('/customerFirmDetails');
        },
        handleViewPersonDetail(item) {
            sessionStorage.setItem('custId', item.custId);
            sessionStorage.setItem("activeTab", this.activeTab);
            this.$router.push('/customePersonDetail');
        },
        handleViewCommercialDetail(item) {
            sessionStorage.setItem('custId', item.custId);
            sessionStorage.setItem("activeTab", this.activeTab);
            sessionStorage.setItem("socialCreditCode", item.socialCreditCode);
            this.$router.push('/customeCommercialDetail');
        },
    }
}
</script>
<style lang="less" scoped>
.wrapper {
    padding-top: 46px;
    min-height: 100vh;
    font-size: 16px;
    padding-bottom: 60px;
}

.search-input {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 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;
}

/deep/ .van-search {
    width: 100%;
    padding: 5px 8px;
}

.tot_box {
    padding: 10px 15px 5px 15px;

}

.red_num {
    color: red;
    display: inline-block;
    padding: 0 10px;
}

.item {
    margin: 10px 0;
    background-color: #fff;
    padding: 15px 20px;
}

.item_top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.item_top_left {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 70%;
}

.item_name {
    font-size: 18px;
    font-weight: 600;
    margin-left: 10px;
    display: flex;
    flex-wrap: wrap;
    word-break: break-all;
}

.item_viewDetail {
    background-color: rgba(233, 241, 253);
    color: rgb(35, 114, 235);
    padding: 10px 15px;
    border-radius: 5px;
    width: 30%;
}

.icon_box {
    background-color: rgb(35, 114, 235);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px 5px;
}

.item_main {
    margin-top: 10px;
}

.main_item {
    font-size: 16px;
    line-height: 25px;
    word-break: break-all;
}

.mian_title {
    color: rgb(140, 140, 140);
}

.item_user {
    font-size: 25px;
    color: #fff;
}

.userMan_box {
    background-color: rgb(35, 114, 235);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px 5px;
}

.userWoMan_box {
    background-color: rgb(252, 123, 80);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px 5px;
}

.special-search-box{
    ::v-deep .title-dist {
        color: #4682ff !important;
        &::after {
        border-color: transparent transparent #4682ff #4682ff !important;
        }
    }
    ::v-deep .van-sidebar-item--select::before {
        display: none !important;
    }
    ::v-deep .van-sidebar{
        width: 110px
    }
    .ssb-box{
        display: flex;
        flex-direction: row;
        position: relative;
        height: 384px;
        &-rg{
            position: absolute;
            width: calc(100% - 110px);
            top: 10px;
            left: 110px;
            height: 384px;
            overflow: scroll;
            &-item {
                height: 36px;
                background: rgba(244, 245, 251, 1);
                color: rgba(0, 0, 0, 0.85);
                font-size: 12px;
                border-radius: 4px;
                text-align: center;
                margin-bottom: 10px;
                display: flex;
                align-items: center;
                justify-content: center;
                padding: 5px;
            }
            &-item-active {
                background: rgba(231, 237, 252, 1) !important;
                color: rgba(70, 130, 255, 1) !important;
            }
        }
    }
    .footer {
      position: fixed;
      // bottom: 108px;
      width: 100%;
      display: flex;
      justify-content: space-between;
      background: #fff;
      padding: 10px 10px;
      border-radius: 0 0 5px 5px;
      .btn {
        border-radius: 5px;
        width: 80px;
        &:first-child {
          margin-right: 15px;
          width: 120px;
        }
        &:last-child {
          width: 240px;
        }
      }
    }
}

</style>