<template>
    <div>
        <el-card>
            <el-form :inline="true" :model="filterQuery" class="query-form" size="mini">
                <el-row>
                    <el-form-item class="query-form-item">
                        <el-input
                            v-model="filterQuery.companyName"
                            placeholder="企业名称"
                        ></el-input>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <el-input
                            v-model="filterQuery.creditNum"
                            placeholder="社会信用号"
                        ></el-input>
                    </el-form-item>
<!--                    <el-form-item class="query-form-item">-->
<!--                        <el-select v-model="filterQuery.auditStatus" placeholder="审核状态">-->
<!--                            <el-option label="全部" value=""></el-option>-->
<!--                            <el-option label="通过" value='1'></el-option>-->
<!--                            <el-option label="不通过" value='2'></el-option>-->
<!--                            <el-option label="反审" value='3'></el-option>-->
<!--                            <el-option label="申请反审" value='4'></el-option>-->
<!--                            <el-option label="拒绝反审" value='5'></el-option>-->
<!--                        </el-select>-->
<!--                    </el-form-item>-->

                    <el-form-item>
                        <el-button-group>
                            <el-button
                                type="primary"
                                icon="el-icon-refresh"
                                @click="onReset"
                            ></el-button>
                            <el-button type="primary" icon="search" @click="onSubmit"
                            >查询
                            </el-button
                            >
                        </el-button-group>
                    </el-form-item>
                </el-row>
            </el-form>

            <el-table v-loading="loading" :data="list" style="width: 100%" @row-click="getProductAndSalesmanList">
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column
                    label="企业名称"
                    prop="companyName"
                ></el-table-column>
                <el-table-column
                    label="社会信用号"
                    prop="creditNum"
                ></el-table-column>
                <el-table-column label="企业类型" prop="bussinessStatus">
                    <template slot-scope="scope">
                        <span>{{ bussinessFlag[scope.row.bussinessStatus] }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="企业法人"
                    prop="contacts"
                ></el-table-column>
                <el-table-column label="所属地区" prop="area">
                </el-table-column>
                <el-table-column
                    label="详细地址"
                    prop="detailAddr"
                    :show-overflow-tooltip="true"
                >
                </el-table-column>
<!--                <el-table-column label="审核状态" prop="auditStatus" width="120">-->
<!--                    <template slot-scope="scope">-->
<!--                        <span>{{ auditStatusMap[scope.row.auditStatus] }}</span>-->
<!--                    </template>-->
<!--                </el-table-column>-->
                <el-table-column label="操作" fixed="right" width="120">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            @click.native.stop="checkDialog2(scope.row)"
                            :disabled="scope.row.auditStatus !== '6'"
                        >审核
                        </el-button
                        >
<!--                        <el-button-->
<!--                            type="text"-->
<!--                            size="small"-->
<!--                            :disabled="scope.row.auditStatus === '3'"-->
<!--                            @click.native.stop="formSubmit(scope.row, 3)"-->
<!--                        >反审-->
<!--                        </el-button-->
<!--                        >-->
                    </template>
                </el-table-column>
            </el-table>

            <el-pagination
                :page-size="filterQuery.limit"
                @current-change="handleCurrentChange"
                layout="prev, pager, next"
                :total="total"
            ></el-pagination>
        </el-card>

        <el-card class="el-card">
            <el-form :inline="true" :model="productQuery" class="query-form" size="mini">
                <el-row style="width: 100%">
                    <el-form-item class="query-form-item">
                        <el-input
                            v-model="productQuery.cpmctymc"
                            placeholder="产品名称"
                        ></el-input>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <el-input
                            v-model="productQuery.ggxh"
                            placeholder="规格型号"
                        ></el-input>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <el-input
                            v-model="productQuery.ylqxzcrbarmc"
                            placeholder="生产厂家"
                        ></el-input>
                    </el-form-item>
<!--                    <el-form-item class="query-form-item">-->
<!--                        <el-select v-model="productQuery.auditStatus" placeholder="审核状态">-->
<!--                            <el-option label="全部" value=""></el-option>-->
<!--                            <el-option label="通过" value='1'></el-option>-->
<!--                            <el-option label="不通过" value='2'></el-option>-->
<!--                            <el-option label="反审" value='3'></el-option>-->
<!--                            <el-option label="申请反审" value='4'></el-option>-->
<!--                            <el-option label="拒绝反审" value='5'></el-option>-->
<!--                        </el-select>-->
<!--                    </el-form-item>-->

                    <el-form-item>
                        <el-button-group>
                            <el-button
                                type="primary"
                                icon="el-icon-refresh"
                                @click="productOnReset"
                            ></el-button>
                            <el-button type="primary" icon="search" @click="productOnSubmit"
                            >查询
                            </el-button
                            >
                        </el-button-group>
                    </el-form-item>
                </el-row>
            </el-form>

            <el-table v-loading="productLoading"
                      :data="productList"
                      style="width: 100%">
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column label="产品名称" prop="cpmctymc"></el-table-column>
                <el-table-column label="规格型号" prop="ggxh"></el-table-column>
                <el-table-column label="注册/备案凭证号" prop="zczbhhzbapzbh"></el-table-column>
                <el-table-column label="生产厂家" prop="ylqxzcrbarmc"></el-table-column>
                <el-table-column label="审核状态" prop="auditStatus" width="120">
                    <template slot-scope="scope">
                        <span>{{ auditStatusMap[scope.row.auditStatus] }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" width="250">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            @click.native="selectProduct(scope.row)"
                        >审核
                        </el-button
                        >
<!--                        <el-button-->
<!--                            type="text"-->
<!--                            size="small"-->
<!--                            :disabled="scope.row.auditStatus === '3'"-->
<!--                            @click.native.stop="updateProductAuditStatus(scope.row, 3)"-->
<!--                        >反审-->
<!--                        </el-button-->
<!--                        >-->
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                :page-size="productQuery.limit"
                @current-change="salesmanHandleCurrentChange"
                layout="prev, pager, next"
                :total="productTotal"
            >
            </el-pagination>
        </el-card>

        <el-card class="el-card">
            <el-form :inline="true" :model="salesmanQuery" class="query-form" size="mini">
                <el-row style="width: 100%">
                    <el-form-item class="query-form-item">
                        <el-input
                            v-model="salesmanQuery.name"
                            placeholder="业务员姓名"
                        ></el-input>
                    </el-form-item>
<!--                    <el-form-item class="query-form-item">-->
<!--                        <el-select v-model="salesmanQuery.auditStatus" placeholder="审核状态">-->
<!--                            <el-option label="全部" value=""></el-option>-->
<!--                            <el-option label="通过" value='1'></el-option>-->
<!--                            <el-option label="不通过" value='2'></el-option>-->
<!--                            <el-option label="反审" value='3'></el-option>-->
<!--                            <el-option label="申请反审" value='4'></el-option>-->
<!--                            <el-option label="拒绝反审" value='5'></el-option>-->
<!--                        </el-select>-->
<!--                    </el-form-item>-->

                    <el-form-item>
                        <el-button-group>
                            <el-button
                                type="primary"
                                icon="el-icon-refresh"
                                @click="salesmanOnReset"
                            ></el-button>
                            <el-button type="primary" icon="search" @click="salesmanOnSubmit"
                            >查询
                            </el-button
                            >
                        </el-button-group>
                    </el-form-item>
                </el-row>
            </el-form>

            <el-table v-loading="salesmanLoading"
                      :data="salesmanList"
                      style="width: 100%">
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column label="姓名" prop="name"></el-table-column>
                <el-table-column label="电话" prop="tel"></el-table-column>
                <el-table-column label="手机" prop="phone"></el-table-column>
                <el-table-column label="邮箱" prop="email"></el-table-column>
                <el-table-column label="证件类型" prop="certType" width="120">
                    <template slot-scope="scope">
                        <span>{{ certTypeMap[scope.row.certType] }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="证件号" prop="certCode"></el-table-column>
                <el-table-column label="审核状态" prop="auditStatus" width="120">
                    <template slot-scope="scope">
                        <span>{{ auditStatusMap[scope.row.auditStatus] }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" width="250">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            @click.native="addSalesman(scope.row)"
                        >审核
                        </el-button
                        >
<!--                        <el-button-->
<!--                            type="text"-->
<!--                            size="small"-->
<!--                            :disabled="scope.row.auditStatus !== '4'"-->
<!--                            @click.native.stop="updateAuditStatus(scope.row, 3)"-->
<!--                        >反审-->
<!--                        </el-button-->
<!--                        >-->
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                :page-size="salesmanQuery.limit"
                @current-change="salesmanHandleCurrentChange"
                layout="prev, pager, next"
                :total="salesmanTotal"
            >
            </el-pagination>
        </el-card>

        <el-dialog
            title="审核"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :visible.sync="centerDialogVisible"
            width="85%"
            center
        >
            <div style="display: flex; margin-top: -30px">
                <el-button  style="margin: 0 20px 0 auto"type="primary" size="small" @click.native="formSubmit(null, 1)">通过</el-button>
                <el-button  style="margin: 0 20px 0 0"type="primary" size="small" @click.native="formSubmit(null, 2)">不通过</el-button>
                <el-button style="margin: 0 20px 0 0" @click="centerDialogVisible = false">取消</el-button>
            </div>
            <el-card>
                <el-form :model="rowData" ref="rowDataForm" style="margin: 0 20px;">
                    <el-row :gutter="20" class="el-row" type="flex">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="企业名称:" label-width="150px" prop="companyName">
                                <el-input
                                    size="small"
                                    splaceholder=""
                                    v-model="rowData.companyName"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="统一社会信用代码:" label-width="150px" prop="creditNum">
                                <el-input
                                    size="small"
                                    splaceholder=""
                                    v-model="rowData.creditNum"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="企业类别:" label-width="150px" prop="classes">
                                <el-input
                                    size="small"
                                    v-model="bussinessFlag[rowData.bussinessStatus]"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="所属地区:" label-width="150px" prop="area">
                                <el-input
                                    size="small"
                                    v-model="rowData.area"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="联系人:" label-width="150px" prop="contacts">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.contacts"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="详细地址:" label-width="150px" prop="detailAddr">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.detailAddr"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="联系电话:" label-width="150px" prop="mobile">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.mobile"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="邮箱:" label-width="150px" prop="email">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.email"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="证件类型:" label-width="150px" prop="contactsPapersType">
                                <el-select
                                    size="small"
                                    v-model="rowData.contactsPapersType"
                                    placeholder="证件类型"
                                    style="width: 100%;"
                                    :disabled="true"
                                >
                                    <el-option label="身份证" value="1"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="证件号码:" label-width="150px" prop="contactsPapersCode">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.contactsPapersCode"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="登记状态:" label-width="150px" prop="registerStatus">
                                <el-select
                                    size="small"
                                    v-model="rowData.registerStatus"
                                    placeholder="登记状态"
                                    style="width: 100%;"
                                    :disabled="true"
                                >
                                    <el-option label="续存（在营，开业，在册）" value="1"></el-option>
                                    <el-option label="吊销" value="2"></el-option>
                                    <el-option label="注销" value="3"></el-option>
                                    <el-option label="迁出" value="4"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="经营许可证号:" label-width="150px" prop="jyxkzh">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.jyxkzh"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="经营许可证发证机关:" label-width="150px" prop="jyxkzfzjg">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.jyxkzfzjg"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="经营许可证有效期至:" label-width="150px" prop="jyxkzyxq">
                                <el-date-picker
                                    style="width: 100%"
                                    v-model="rowData.jyxkzyxq"
                                    :disabled="true"
                                    type="date"
                                    placeholder="">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="经营备案凭证号:" label-width="150px" prop="jybapzh">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.jybapzh"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="经营备案部门:" label-width="150px" prop="jybabm">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.jybabm"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="发证日期:" label-width="150px" prop="fzrq">
                                <el-date-picker
                                    style="width: 100%"
                                    v-model="rowData.fzrq"
                                    type="date"
                                    placeholder=""
                                    :disabled="true"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="税号:" label-width="150px" prop="suihao">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.suihao"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: -10px">
                        <el-col :span="10" class="el-col">
                            <el-form-item label="开户行:" label-width="150px" prop="kaihuhang">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.kaihuhang"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="el-col">
                            <el-form-item label="开户账号:" label-width="150px" prop="kaihuzhanghao">
                                <el-input
                                    size="small"
                                    placeholder=""
                                    v-model="rowData.kaihuzhanghao"
                                    :disabled="true"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" style="margin-top: -10px">
                        <el-col :span="10">
                            <el-form-item label="营业执照电子档案:" label-width="150px">
                                <el-button
                                    :disabled="rowData.filePath === null || rowData.filePath === ''"
                                    @click.native="openFile(rowData.filePath)"
                                    size="small" type="primary">查看文件
                                </el-button>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10">
                            <el-form-item label="经营许可证电子档案:" label-width="150px">
                                <el-button
                                    :disabled="rowData.filePath2 === null || rowData.filePath2 === ''"
                                    @click.native="openFile(rowData.filePath2)"
                                    size="small" type="primary">查看文件
                                </el-button>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" style="margin-top: -10px">
                        <el-col :span="10">
                            <el-form-item label="经营备案证电子档案:" label-width="150px">
                                <el-button
                                    :disabled="rowData.filePath3 === null || rowData.filePath3 === ''"
                                    @click.native="openFile(rowData.filePath3)"
                                    size="small" type="primary">查看文件
                                </el-button>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10">
                            <el-form-item label="开户行电子档案:" label-width="150px">
                                <el-button
                                    :disabled="rowData.filePath4 === null || rowData.filePath4 === ''"
                                    @click.native="openFile(rowData.filePath4)"
                                    size="small" type="primary">查看文件
                                </el-button>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row :gutter="20" class="el-row" type="flex" style="margin-top: 30px">
                        <el-col :span="20" class="el-col">
                            <el-form-item label="拒绝原因:" label-width="150px" prop="creditNum">
                                <el-input
                                    type="textarea"
                                    size="small"
                                    splaceholder=""
                                    v-model="rowData.noPassCause"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

<!--                    <el-row :gutter="20">-->
<!--                        <el-col :span="3">-->
<!--                            <div class="div-text">-->
<!--                                <span>资质文件:&nbsp;</span>-->
<!--                            </div>-->
<!--                        </el-col>-->
<!--                        <el-col :span="3">-->
<!--                            <el-image-->
<!--                                style="margin-left: 30px; width: 100px; height: 100px"-->
<!--                                :src="fileUrl"-->
<!--                                fit="cover">-->
<!--                            </el-image>-->
<!--                        </el-col>-->
<!--                        <el-col :span="3" v-if="fileUrl.length > 0">-->
<!--                            <div style="margin: 50px 0 0 30px">-->
<!--                                <a :href="fileUrl" target="_blank">查看文件</a>-->
<!--                            </div>-->
<!--                        </el-col>-->
<!--                    </el-row>-->

<!--                    <el-divider></el-divider>-->

<!--                    <el-row :gutter="20">-->
<!--                        <el-col :span="3">-->
<!--                            <div class="div-text">-->
<!--                                <span>分配角色:&nbsp;</span>-->
<!--                            </div>-->
<!--                        </el-col>-->
<!--                        <el-col :span="7">-->
<!--                            <el-form :model="checkQuery">-->
<!--                                <el-form-item label="" style="margin-top: 5px">-->
<!--                                    <el-radio-group v-model="check" @change="handleCheckedChange">-->
<!--                                        <el-radio v-for="item in roles" :key="item.id" :label="item.id">{{-->
<!--                                                item.name-->
<!--                                            }}-->
<!--                                        </el-radio>-->
<!--                                    </el-radio-group>-->
<!--                                </el-form-item>-->
<!--                            </el-form>-->
<!--                        </el-col>-->
<!--                    </el-row>-->
                </el-form>
            </el-card>


<!--            <el-card class="el-card">-->
<!--                <el-table v-loading="certLoading"-->
<!--                          :data="certList"-->
<!--                          style="width: 100%">-->
<!--                    <el-table-column type="index" label="序号" width="50"></el-table-column>-->
<!--                    <el-table-column label="电子档名称" prop="name"></el-table-column>-->
<!--                    <el-table-column label="备注" prop="remark"></el-table-column>-->
<!--                    <el-table-column label="时间" prop="create_time" show-overflow-tooltip>-->
<!--                        <template slot-scope="scope">-->
<!--                            <i class="el-icon-time"></i>-->
<!--                            <span>{{ scope.row.create_time }}</span>-->
<!--                        </template>-->
<!--                    </el-table-column>-->

<!--                    <el-table-column label="操作" fixed="right" width="250">-->
<!--                        <template slot-scope="scope">-->
<!--                            <el-button-->
<!--                                type="text"-->
<!--                                size="small"-->
<!--                                @click.native="toViewCompanyCert(scope.row)"-->
<!--                            >查看文件-->
<!--                            </el-button-->
<!--                            >-->
<!--                        </template>-->
<!--                    </el-table-column>-->
<!--                </el-table>-->
<!--                <el-pagination-->
<!--                    :page-size="certQuery.limit"-->
<!--                    @current-change="certHandleCurrentChange"-->
<!--                    layout="prev, pager, next"-->
<!--                    :total="certTotal"-->
<!--                >-->
<!--                </el-pagination>-->
<!--            </el-card>-->

        </el-dialog>

        <el-dialog
            title="医疗器械信息"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :visible.sync="selectLocalVisible"
            width="85%"
            v-if="selectLocalVisible"
        >
            <selectProduct
                :closeDialog="closeDialog"
                :uuid="uuid"
                :hid="hid"
            ></selectProduct>
        </el-dialog>

        <el-dialog
            title="业务员"
            :visible.sync="addSalesmanVisible"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            width="70%"
            v-if="addSalesmanVisible"
            @close='closeDialog'
        >
            <companyAddSalesman
                :closeDialog="closeDialog"
                :idQuery="idQuery"
            ></companyAddSalesman>
        </el-dialog>
    </div>
</template>

<script>
import {getRegisters, checkPass, deleteRe} from "../../api/auth/register";
import {authAdminRoleList, authCustomerRoles} from "../../api/auth/authAdmin";
import {getSystemPDFTemplates} from "../../api/param/systemPDFTemplate";
import {
    getCustomers,
    updateCustomers,
    deleteCustomers,
} from "../../api/auth/customer";
import customerUser from "./customerUser";
import companyAddSalesman from "../warehouse/companyAddSalesman";
import selectProduct from "../warehouse/selectProduct";
import {BASE_URL} from "../../config/app";
import store from "../../store";
import {filterCompanyCert} from "../../api/warehouse/companyCert";
import {getSubCompany, getSubCompany2, modifyCompany} from "../../api/warehouse/company";
import {filterCompanySalesman, updateCompanySalesman} from "../../api/warehouse/companySalesman";
import {filterCompanyProductRelevance, updateCompanyProductRelevance} from "../../api/warehouse/companyProductRelevance";
import {updateCompanySalesmanUpdateLog} from "../../api/warehouse/companySalesmanUpdateLog";

export default {
    data() {
        return {
            filterQuery: {
                companyName: "",
                checkType: "",
                creditNum: "",
                auditStatus: "6",
                page: 1,
                limit: 20,
            },
            value: "",
            total: 0,
            checkFlag: {
                0: "未审核",
                1: "已通过",
                2: "已拒绝",
            },

            userflag: {
                0: "禁用",
                1: "正常",
                2: "未验证",
            },
            bussinessFlag: {
                1: "医院",
                2: "经营企业"
            },
            list: [],
            isTip: {
                0: "否",
                1: "是",
            },
            formVisible: false,
            contractVisible: false,
            customerVisible: false,
            timer: "",
            formData: {
                customerName: "111",
                userMax: "",
                isInfoLink: "",
                infoLink: "",
                customerId: "",
                userFlag: "",
                roleId: "",
                pdfTemplateId: "",
            },
            contractData: {
                contacts: "",
                mobile: "",
                tel: "",
                email: "",
            },
            currentCustomer: "",
            check: "",
            roles: [],
            pdfTemplates: [],
            centerDialogVisible: false,
            rowData: {},
            rowDataRules: {
                nickName: [
                    {required: true, message: "请输入用户名称", trigger: "blur"},
                ],
            },
            fileUrl: "",
            checkQuery: {
                id: "",
                checkType: "",
                roles: "",
            },
            certQuery: {
                page: 1,
                limit: 20
            },
            certList: [],
            certTotal: 0,
            certLoading: false,
            certFileUrl: "",
            addCertVisible: false,
            certTypeMap: {
                1: '身份证'
            },
            auditStatusMap: {
                4: '申请变更',
                3: '允许变更',
                5: '拒绝变更',
                6: '待审核',
                1: '通过',
                2: '不通过',
            },
            idQuery: {
                id: "",
            },
            salesmanQuery: {
                name: "",
                auditStatus: "6",
                page: 1,
                limit: 20
            },
            salesmanList: [],
            salesmanTotal: 0,
            salesmanLoading: false,
            addSalesmanVisible: false,
            selectLocalVisible: false,
            productQuery: {
                ylqxzcrbarmc: "",
                cpmctymc: "",
                ggxh: "",
                auditStatus: "6",
                page: 1,
                limit: 20
            },
            productList: [],
            productTotal: 0,
            productLoading: false,
            uuid: null,
            hid: true,
        };
    },
    filters: {
        statusFilterType(status) {
            const statusMap = {
                0: "gray",
                1: "success",
                2: "danger",
            };
            return statusMap[status];
        },
        statusFilterName(status) {
            const statusMap = {
                0: "禁用",
                1: "正常",
                2: "未验证",
            };
            return statusMap[status];
        },
    },
    methods: {
        onReset() {
            this.$router.push({
                path: "",
            });
            this.filterQuery = {
                companyName: "",
                creditNum: "",
                auditStatus: "6",
                page: 1,
                limit: 20,
            };
            this.getList();
            this.productList = [];
            this.salesmanList = [];
        },
        formSubmit(row, num) {
            if (num === 2 && this.$isBlank(this.rowData.noPassCause)) {
                return this.$message.warning("请输入拒绝原因");
            }
            let confirmTitle = num === 1 ? "是否允许通过" : "是否拒绝通过";
            this.$confirm(confirmTitle, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                if (this.$isNotBlank(row)) {
                    this.rowData = row;
                }
                this.rowData.auditStatus = num;
                this.rowData.auditor = store.getters.employeeName;
                modifyCompany(this.rowData)
                    .then((response) => {
                        this.loading = false;
                        this.cancelDialog();
                        this.getList();
                        if (response.code === 20000) {
                            this.$message({
                                type: "success",
                                message: "更新成功！",
                            });
                        } else {
                            this.$message.warning("更新失败");
                        }
                    })
                    .catch(() => {
                        this.cancelDialog();
                        this.loading = false;
                    });
            }).catch(() => {
            });
        },
        onSubmit() {
            this.getList();
        },
        openFile(path) {
            window.open(this.fileUrl + path);
        },
        getList() {
            this.loading = true;
            getSubCompany2(this.filterQuery)
                .then((response) => {
                    console.log(response)
                    this.loading = false;
                    this.list = response.data.list || [];
                    this.total = response.data.total || 0;
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                    this.total = 0;
                });
        },
        closeDialog(type) {
            this.addSalesmanVisible = false;
            this.selectLocalVisible = false;
        },
        getProductAndSalesmanList(row) {
            this.getProductRelevanceList(row);
            this.getCompanySalesmanList(row);
        },
        salesmanOnReset() {
            let tC = this.salesmanQuery.customerId;
            this.salesmanQuery = {
                name: "",
                auditStatus: "6",
                page: 1,
                limit: 20
            };
            this.salesmanQuery.customerId = tC;
            this.getCompanySalesmanList();
        },
        salesmanOnSubmit() {
            this.getCompanySalesmanList();
        },
        productOnReset() {
            let tC = this.productQuery.customerId;
            this.productQuery = {
                ylqxzcrbarmc: "",
                cpmctymc: "",
                ggxh: "",
                auditStatus: "6",
                page: 1,
                limit: 20
            };
            this.productQuery.customerId = tC;
            this.getProductRelevanceList();
        },
        productOnSubmit() {
            this.getProductRelevanceList();
        },
        selectProduct(row) {
            if (this.$isNotBlank(row)) {
                this.hid = row.id;
                this.uuid = row.uuid;
                this.selectLocalVisible = true;
            }
        },
        addSalesman(row) {
            if (this.$isNotBlank(row) && this.$isNotBlank(row.id)) {
                this.idQuery.id = row.id;
                this.idQuery.toView = true;
                this.idQuery.formData = row;
                this.addSalesmanVisible = true;
            }
        },
        updateProductAuditStatus(row, num) {
            let tQuery = {
                auditStatus: num,
                id: row.id,
            }
            updateCompanyProductRelevance(tQuery).then(response => {
                this.loading = false;
                if (response.code === 20000) {
                    this.$message.success("成功");
                    this.getProductRelevanceList(this.productQuery);
                } else {
                    this.$message.error(response.message);
                }
            });
        },
        updateAuditStatus(row, num) {
            this.$confirm("是否进行反审?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                let tQuery = {
                    customerId: store.getters.customerId,
                    salesmanId: row.id,
                    status: 2,
                    name: row.name,
                }
                this.loading = true;
                updateCompanySalesmanUpdateLog(tQuery).then(response => {
                    this.loading = false;
                    if (response.code === 20000) {
                        this.$message.success("成功");
                        this.getCompanySalesmanList();
                    } else {
                        this.$message.error(response.message);
                    }
                });
            }).catch(() => {
            });
        },
        salesmanHandleCurrentChange(val) {
            this.salesmanQuery.page = val;
            this.getCompanySalesmanList(this.salesmanQuery);
        },
        productHandleCurrentChange(val) {
            this.productQuery.page = val;
            this.getProductRelevanceList(this.productQuery);
        },
        getCompanySalesmanList(row) {
            if (this.$isNotBlank(row)) {
                this.salesmanQuery.customerId = row.customerId;
            }
            if (this.$isBlank(this.salesmanQuery.customerId)) {
                return;
            }
            this.salesmanLoading = true;
            filterCompanySalesman(this.salesmanQuery)
                .then((response) => {
                    this.salesmanLoading = false;
                    this.salesmanList = response.data.list || [];
                })
                .catch(() => {
                    this.salesmanLoading = false;
                    this.salesmanList = [];
                });
        },
        getProductRelevanceList(row) {
            if (this.$isNotBlank(row)) {
                this.productQuery.customerId = row.customerId;
            }
            if (this.$isBlank(this.productQuery.customerId)) {
                return;
            }
            this.erpDisplay = false;
            this.productLoading = true;
            filterCompanyProductRelevance(this.productQuery)
                .then((response) => {
                    this.productLoading = false;
                    this.productList = response.data.list || [];
                    console.log(this.productList)
                    this.productTotal = response.data.total || 0;
                })
                .catch(() => {
                    this.productLoading = false;
                    this.productList = [];
                    this.productTotal = 0;
                });
        },
        certHandleCurrentChange(val) {
            this.certQuery.page = val;
            this.getCompanyCertList();
        },
        getCompanyCertList() {
            this.certQuery.customerId = this.rowData.customerId;
            if (this.$isBlank(this.certQuery.customerId)) {
                return;
            }
            this.certLoading = true;
            filterCompanyCert(this.certQuery)
                .then((response) => {
                    this.certLoading = false;
                    this.certList = response.data.list || [];
                })
                .catch(() => {
                    this.certLoading = false;
                    this.certList = [];
                });
        },
        toViewCompanyCert(row) {
            window.open(this.certFileUrl + row.filePath);
        },
        hideForm() {
            this.customerVisible = false;
        },
        cancelDialog() {
            this.formVisible = false;
            this.contractVisible = false;
            this.centerDialogVisible = false;
        },

        handleSizeChange(val) {
            this.filterQuery.limit = val;
            this.getList();
        },
        handleCurrentChange(val) {
            this.filterQuery.page = val;
            this.getList();
        },
        handleCheckedChange(val) {
            console.log(val);
            console.log(this.check);
        },
        checkRegister(tquery) {
            this.loading = true;
            checkPass(tquery)
                .then((response) => {
                    if (response.code === 20000) {
                        this.getList();
                        this.$message({
                            type: "success",
                            message: "更新成功！",
                        });
                    } else {
                        this.$message.warning("更新失败");
                        this.loading = false;
                    }
                })
                .catch(() => {
                });
        },
        customerkDialog(row) {
            this.currentCustomer = row.customerId;
            this.timer = new Date().getTime();
            console.log("this.currentCustomer = " + this.currentCustomer);
            this.customerVisible = true;
        },

        closeCustomerDialog() {
            console.log("this.currentCustomer 关闭 = " + this.currentCustomer);

            this.currentCustomer = null;
        },
        checkDialog(row) {
            console.log(row);
            console.log(row.customerName);
            (this.formData = {
                customerName: row.companyName,
                userMax: row.userMax,
                isInfoLink: row.isInfoLink + "",
                infoLink: row.infoLink,
                customerId: row.customerId,
                userFlag: row.userFlag,
                pdfTemplateId: row.pdfTemplateId,
            }),
                (this.check = parseInt(row.roleId));
            console.log(this.check);
            this.formVisible = true;
        },
        checkDialog2(row) {
            (this.formData = {
                customerName: row.companyName,
                userMax: row.userMax,
                isInfoLink: row.isInfoLink + "",
                infoLink: row.infoLink,
                customerId: row.customerId,
                userFlag: row.userFlag,
                pdfTemplateId: row.pdfTemplateId,
            }),
                (this.check = parseInt(row.roleId));
            this.checkQuery = {
                id: row.id + "",
                checkType: 1,
                roles: row.roles,
            };
            this.rowData = row;
            this.fileUrl = "";
            this.fileUrl = BASE_URL + "/udiwms/image/register/file/getImage?type=image1&name=";
            // if (this.$isNotBlank(this.rowData.filePath)) {
            //     this.fileUrl = BASE_URL + "/udiwms/image/register/file/getImage?type=image1&name=" + this.rowData.filePath;
            // }
            this.centerDialogVisible = true;
            // this.getCompanyCertList();
        },

        contractDialog(row) {
            (this.contractData = {
                contacts: row.contacts,
                mobile: row.mobile,
                tel: row.tel,
                email: row.email,
            }),
                (this.contractVisible = true);
        },

        deleteDialog(row) {
            this.$confirm("删除后将清空该客户下所有用户?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    let tQuery = {
                        id: row.customerId,
                    };
                    deleteCustomers(tQuery).then(() => {
                        this.getList();
                    });
                })
                .catch(() => {
                });
        },

        getRoleList() {
            authCustomerRoles()
                .then((response) => {
                    this.roles = response.data.list || [];
                    console.log("888---" + this.checkQuery.roles);
                })
                .catch(() => {
                });
        },

        getPDFTemplateList() {
            getSystemPDFTemplates()
                .then((response) => {
                    this.pdfTemplates = response.data.list;
                })
                .catch(() => {
                });
        },
    },
    components: {
        customerUser,
        companyAddSalesman,
        selectProduct,
    },
    mounted() {
    },
    created() {
        // this.getPDFTemplateList();
        this.getList();
        this.getRoleList();
        this.certFileUrl = BASE_URL + "/udiwms/image/register/file/getImage?type=image2&name=";
    },
};
</script>
