<template>
    <div class="site-setting-wrap pagePadding min-flex-right">
        <p class="pageTitle bold mb24">基础信息</p>
        <div class="siteMessage flex-common" id="siteMessage1">
            <p class="littleTitle mb32">基础信息</p>
            <el-form :model="form" :rules="siteFormrules" ref="siteForm">
                <div class="flex-wrap">
                    <div class="flex-left">
                        <GuipFormItem column="column" class="mb24" label="出诊医院省市" :required="true">
                            <div class="flex-between" slot="formDom">
                                <div class="short-width">
                                    <GuipSelect width="100%" v-model="form.province" :options="options_province"
                                        :disabled="(depart_id && doctor_id) ? true : false" placeholder="选择省份"
                                        @change="provinceChange">
                                    </GuipSelect>
                                </div>
                                <div class="short-width">
                                    <GuipSelect width="100%" v-model="form.city" :options="options_city"
                                        :disabled="(depart_id && doctor_id) ? true : false" placeholder="选择城市">
                                    </GuipSelect>
                                </div>
                            </div>
                        </GuipFormItem>
                        <GuipFormItem column="column" class="mb24" label="出诊医院名称" :required="true"
                            style="margin-bottom: 0px;">
                            <GuipInput slot="formDom" ref="GuipInput" column="column" v-model="form.h_realname"
                                :disabled="true" v-if="depart_id && doctor_id" prop="h_realname"></GuipInput>
                        </GuipFormItem>

                        <div class="mb24" style="margin-top:-24px;" v-if="!depart_id && doctor_id">
                            <el-autocomplete v-model="hospitalSearchState" style="width: 100%"
                                :fetch-suggestions="queryHospital" placeholder="请输入医院名称或地址" ref="hospitalAutocomplete"
                                :popper-class="((hospitalSearchFlag || hospitalRestaurants.length > 0) ? '' : ' el-autocomplete-noloading')"
                                @select="hospitalHandleSelect">
                                <template #append>
                                    <el-button icon="el-icon-search" @click="handleSearch"
                                        style="padding: 12px;"></el-button>
                                </template>
                            </el-autocomplete>
                        </div>

                        <GuipFormItem column="column" class="mb24" label="医院简称">
                            <span slot="formRight" class="desc">方便患者记忆，非必填</span>
                            <GuipInput slot="formDom" ref="GuipInput" column="column" v-model="form.h_shortname"
                                prop="h_shortname" placeholder="请输入" />
                        </GuipFormItem>
                        <GuipFormItem column="column" class="mb24" label="所在科室">
                            <GuipInput slot="formDom" ref="GuipInput" column="column" v-model="form.depart_name"
                                prop="depart_name" :placeholder="(depart_id && doctor_id) ? '无' : '请输入'"
                                :disabled="(depart_id && doctor_id) ? true : false" />
                        </GuipFormItem>
                    </div>
                    <div class="flex-line"></div>
                    <div class="flex-right">
                        <GuipFormItem column="column" class="mb24" v-if="departIsFixed != -1">
                            <div slot="formLeft" class="form-top-icon">医保定点</div>
                            <div class="flex" slot="formDom" style="padding: 9px 0px;">
                                <GuipSwitch :value="departIsFixed" @change="onSwitchChange" activeText="医保定点"
                                    inactiveText="非医保定点" :active-value="true" :inactive-value="false">
                                </GuipSwitch>
                            </div>
                        </GuipFormItem>
                        <GuipFormItem column="column" class="mb24" label="使用功能">
                            <el-checkbox-group slot="formDom" v-model="departType" @change="validateSelection"
                                class="checkboxGroup">
                                <div class="flex">
                                    <el-checkbox :label="0">患者预约</el-checkbox>
                                    <el-checkbox :label="1">仅项目计数</el-checkbox>
                                </div>
                                <el-checkbox :label="2">仅医生名片</el-checkbox>
                            </el-checkbox-group>
                        </GuipFormItem>
                        <GuipFormItem column="column" class="" label="就诊提醒">
                            <div slot="formRight" class="desc">就诊前的注意事项，非必填</div>
                            <GuipTextarea slot="formDom" v-model="form.notice" prop="notice" width="100%" height="84px"
                                autosize placeholder="输入" />
                        </GuipFormItem>
                    </div>
                </div>
            </el-form>
            <GroupFormBtns @cancel="cancelClick" @confirm="submitForm('siteForm')" />
        </div>

        <div class="siteMessage flex-common mt12" id="siteMessage2">
            <p class="littleTitle mb32">出诊时间</p>
            <el-form :model="form" :rules="siteFormrules1" ref="siteForm1">
                <div class="flex-wrap">
                    <div class="flex-left">
                        <GuipFormItem column="column" class="mb24" label="工作时间（ 上午 ）" :required="true">
                            <el-time-picker slot="formDom" style="width:100%" is-range v-model="form.morning_worktime"
                                range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围"
                                @change="ChangeTime('time1')" format="HH:mm" value-format="HH:mm">
                            </el-time-picker>
                        </GuipFormItem>
                        <GuipFormItem column="column" class="mb24" label="工作时间（ 下午 ）" :required="true">
                            <el-time-picker slot="formDom" style="width:100%" is-range v-model="form.afternoon_worktime"
                                range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围"
                                @change="ChangeTime('time1')" format="HH:mm" value-format="HH:mm">
                            </el-time-picker>
                        </GuipFormItem>
                    </div>
                    <div class="flex-line"></div>
                    <div class="flex-right" v-if="form.worktimes">
                        <GuipFormItem column="column" label="每周出诊安排" :required="true">

                            <div class="flex weekPlan" slot="formDom">
                                <GuipSelect v-for="day in weekDays" :key="day.id" v-model="form.worktimes[day.id].plan"
                                    :options="options_weekPlan" :label="day.name" placeholder="休息"></GuipSelect>
                            </div>

                        </GuipFormItem>
                    </div>
                </div>
            </el-form>
            <GroupFormBtns @cancel="cancelClick" @confirm="submitForm('siteForm1')" />
        </div>
        <div class="siteMessage flex-common mt12" id="siteMessage3">
            <p class="littleTitle mb32">放号设置</p>
            <el-form :model="form" :rules="numSettingFormRule" ref="numSettingForm">
                <div class="flex-wrap">
                    <div class="flex-left">
                        <GuipFormItem column="column" class="mb24" label="号源单位时段" :required="true">
                            <span class="desc" slot="formRight">如30分钟，放号时9:00-9:30；9:30-10:00来划分</span>
                            <GuipInput slot="formDom" ref="GuipInput" column="column" v-model="form.time_unit"
                                prop="time_unit" placeholder="请输入" unit="分钟/时段" />
                        </GuipFormItem>
                        <GuipFormItem column="column" class="mb24" label="放号量" :required="true">
                            <span class="desc" slot="formRight">放号量可少于实际数量，以便为现场约号患者预留</span>
                            <GuipInput slot="formDom" ref="GuipInput" column="column" v-model="form.time_unit_num"
                                prop="time_unit_num" placeholder="请输入" unit="个号/时段" />
                        </GuipFormItem>
                    </div>
                    <div class="flex-line"></div>
                    <div class="flex-right">
                        <GuipFormItem column="column" class="mb24" label="开放预约" :required="true">
                            <span class="desc" slot="formRight">患者可提前多久约号</span>
                            <GuipInput slot="formDom" ref="GuipInput" column="column" v-model="form.visit_day"
                                prop="visit_day" placeholder="请输入" unit="天">
                                <span slot="prependshow">提前</span>
                            </GuipInput>
                        </GuipFormItem>
                        <GuipFormItem column="column" class="mb24" label="超时未就诊提醒">
                            <span class="desc" slot="formRight">不输入即无期限</span>
                            <GuipInput slot="formDom" ref="GuipInput" column="column" v-model="form.treat_expire"
                                prop="treat_expire" placeholder="请输入" unit="天" />
                        </GuipFormItem>
                    </div>
                </div>
            </el-form>
            <GroupFormBtns @cancel="cancelClick" @confirm="submitForm('numSettingForm')" />
        </div>
        <div class="siteMessage flex-common mt12" id="siteMessage6">
            <el-form>
                <div class="mb32 flex gap12">
                    <span class="littleTitle">线上收款</span>
                    <GuipSwitch :value="onLinePay" ref="hasOnlinePayRef" :active-value="1" :inactive-value="0" :disabled="!wxpayList.length" @change="onLineChange"></GuipSwitch>
                    <span v-if="!onLinePay" class="tipInfo">未绑定微信收款方式，无法开启线上收款</span>
                    <span v-if="!onLinePay == 1"> {{ onLinePay == 1 ? '开启' : '' }}</span>
                </div>
                <div class="flex-wrap">
                    <div class="flex-left">
                        <!-- 微信 -->
                        <GuipFormItem column="column" class="mb24" :require="true">
                            <div slot="formLeft" class="form-top-icon">
                                <img src="@/assets/weixin.svg" style="width: 26px;height: 26px;"
                                    alt=""><span>微信收款</span>
                                <img class="requireImg" src="@/assets/require.svg" alt="">
                            </div>
                            <CustomDropdown slot="formDom" width="100%" :options="wxpayList" ref="wxPayRef"
                                :options_null="!wxpayList.length" displayKey="name" valueKey="payid"
                                @change="changeSelectWeixin">
                                <template #trigger>
                                    <span v-if="selectWxpay && (selectWxpay.company_short_name || selectWxpay.appid)">{{
                                        selectWxpay.company_short_name }} {{ selectWxpay.appid }}</span>
                                    <span v-else-if="wxpayList.length === 0">暂无收款账号，稍后配置</span>
                                    <span v-else>未绑定微信收款</span>
                                </template>

                                <template #normal>
                                    <div class="flex flex-between noraml-jump">
                                        <div class="left">
                                            <b>绑定新微信收款</b>
                                            <p class="one">需要使用您公司的微信支付</p>
                                            <p>需在微信商户平台-产品中心开通Native支付</p>
                                        </div>
                                        <div class="right">
                                            <GuipButton type="primary" size="medium" @click="goToAddPay(payTypeWeixin)">
                                                前往添加</GuipButton>
                                        </div>
                                    </div>
                                </template>
                                <template #item="{ item }">
                                    <div class="flex-between">
                                        <div class="left">
                                            <p class="one">{{ item.company_short_name }}</p>
                                            <p>{{ item.appid }}</p>
                                        </div>
                                        <div class="right">
                                            <img v-if="item.is_bind"
                                                src="@/assets/drop-selected.svg" alt="">
                                        </div>
                                    </div>
                                </template>
                            </CustomDropdown>
                        </GuipFormItem>
                    </div>
                    <div class="flex-line"></div>
                    <div class="flex-right">
                        <!-- 支付宝 -->
                        <GuipFormItem column="column">
                            <div slot="formLeft" class="form-top-icon">
                                <img src="@/assets/zhifubao.svg" style="width: 26px;height: 26px;"
                                    alt=""><span>支付宝收款</span>
                            </div>
                            <div slot="formRight" class="desc">
                                绑定后，患者支付宝扫码付款可享自动退费
                            </div>
                            <CustomDropdown slot="formDom" width="100%" :options="alipayList"
                                :options_null="!alipayList.length" @change="changeSelectAlipay">
                                <template #trigger>
                                    <span v-if="selectAlipay && (selectAlipay.company_short_name || selectAlipay.appid)">{{
                                        selectAlipay.company_short_name }} {{ selectAlipay.appid }}</span>
                                    <span v-else-if="alipayList.length === 0">非必须绑定项</span>
                                    <span v-else>未绑定支付宝收款</span>
                                </template>
                                <template #normal>
                                    <div class="flex flex-between noraml-jump">
                                        <div class="left">
                                            <b>绑定新支付宝收款</b>
                                            <p class="one">需要使用您公司的支付宝支付</p>
                                            <p>需在支付宝商户平台-产品中心开通Native支付</p>
                                        </div>
                                        <div class="right">
                                            <GuipButton type="primary" size="medium" @click="goToAddPay(payTypeAlipay)">
                                                前往添加</GuipButton>
                                        </div>
                                    </div>
                                </template>

                                <template #item="{ item }">
                                    <div class="flex-between">
                                        <div class="left">
                                            <p class="one">{{ item.company_short_name }}</p>
                                            <p>{{ item.appid }}</p>
                                        </div>
                                        <div class="right">
                                            <img v-if="item.is_bind"
                                                src="@/assets/drop-selected.svg" alt="">
                                        </div>
                                    </div>
                                </template>
                            </CustomDropdown>
                        </GuipFormItem>
                    </div>
                </div>
            </el-form>
        </div>
        <div class="siteMessage flex-common mt12" id="siteMessage7">
            <el-form>
                <div class="mb32 flex gap12">
                    <span class="littleTitle">收挂号费</span>
                    <GuipSwitch :value="hasVisitFee" ref="hasVisitFeeRef" :active-value="1" :inactive-value="0" @change="onVisitFeeChange"></GuipSwitch>
                    <span class="desc">患者在小程序预约时，{{hasVisitFee == 1?'':'不'}}需缴纳挂号费</span>
                </div>
                <div class="bidwrap-item">
                    <div class="biditemMast mb12 flex-between">
                        <div class="bidwrap-item-top flex">
                            <div class="top-right column">
                                <p>设置挂号费金额</p>
                                <p class="desc" v-if="registerMoney">{{registerMoney}}元/人</p>
                            </div>
                        </div>
                        <div class="flex" v-if="registerMoney">
                            <span :class="'yesSet'">已设置</span>
                            <GuipButton type="system" :btnstyle="{ width: '126px', height: '38px' }"
                                @click="showDialog('register')">修改</GuipButton>
                        </div>
                        <div class="flex" v-else>
                            <span :class="'notSet'">未设置</span>
                            <GuipButton type="system"
                                :btnstyle="{ width: '126px', height: '38px' }"
                                @click="showDialog('register')">立即设置</GuipButton>
                        </div>
                    </div>
                    <div class="biditemMast mb12 flex-between">
                        <div class="bidwrap-item-top flex">
                            <div class="top-right column">
                                <p>免挂号费规则</p>
                                <p class="desc" v-if="againVisitFreeDays && hasAgainVisitFreeDays">患者{{againVisitFreeDays}}天内再次就诊、患者有剩余治疗项目，免收挂号费</p>
                            </div>
                        </div>
                        <div class="flex" v-if="hasFreeRegisterRule">
                            <span :class="'yesSet'">已设置</span>
                            <GuipButton type="system" :btnstyle="{ width: '126px', height: '38px' }"
                                @click="showDialog('registerRule')">修改</GuipButton>
                        </div>
                        <div class="flex" v-else>
                            <span :class="'notSet'">未设置</span>
                            <GuipButton type="system"
                                :btnstyle="{ width: '126px', height: '38px' }"
                                @click="showDialog('registerRule')">立即设置</GuipButton>
                        </div>
                    </div>
                </div>
            </el-form>
        </div>

        <!-- <p class="pageTitle bold">项目管理</p> -->
        <div class="siteMessage flex-common mt12" id="siteMessage4">
            <el-form>
                <div class=" mb32 flex-between">
                    <span class="littleTitle">项目列表</span>
                    <div class="flex-between" style="gap:10px">
                        <GuipButton size="table" type="ignore" @click="addNewGroup">新增分组</GuipButton>
                        <GuipButton size="table" type="primary" @click="addNewProject">新增项目</GuipButton>
                    </div>
                </div>
                <div class="selectAllTable-wrap flex-between  mt32">
                    <div class="left flex">
                        <div class="checkboxAll">
                            <el-checkbox @change="handleSelectAllChange" v-model="selectAll"
                                :indeterminate="isIndeterminate">全选</el-checkbox>
                        </div>
                        <span class="totalCount">共{{ projectList.length }}条，已选8{{ selectedCount }}条</span>
                        <GuipButton type="ignore" :btnstyle="{ width: '99px', height: '32px', margin: '0 26px' }"
                            @click="batchOperate(0, 'project')">批量禁用</GuipButton>
                        <GuipButton type="ignore" :btnstyle="{ width: '99px', height: '32px' }"
                            @click="batchOperate(1, 'project')">
                            批量启用</GuipButton>
                    </div>

                </div>
                <div class="flex-between mb32 mt32">
                    <div class="tabProject scroll-container" v-if="Object.values(projectTagData).length > 0">
                        <div class="overTab scroll-list">
                            <div :class="['tab-item point', projectSearchId == 'all' ? 'active' : '']"
                                @click="selectTag('all')">
                                全部分类</div>
                            <div :class="['tab-item point', projectSearchId == item.id ? 'active' : '']"
                                @click="selectTag(item)" v-for="item in projectTagData" :key="item.name">{{ item.name }}
                            </div>
                        </div>
                    </div>
                    <div class="right flex">
                        <span style="margin-right: 16px;">搜索项目</span>
                        <GuipInput ref="GuipInput" class="special-input" column="column" width="280px"
                            v-model="projectSearchName" prop="company_name" placeholder="请输入" @blur="getFilterProject">
                            <img src="@/assets/input_search_ic.svg" slot="suffix" />
                        </GuipInput>
                    </div>
                </div>
                <GuipTable :tableData="projectList" :key="tableKey" style="width: 100%" ref="multipleTable"
                    @selection-change="handleSelectionChange" :loading="loading">
                    <el-table-column type="selection" label="选择" width="80"></el-table-column>
                    <el-table-column prop="name" label="项目名称" min-width="185"></el-table-column>
                    <el-table-column prop="price" label="项目价格" min-width="155">
                        <template slot-scope="scope">
                            <GuipInput width="90%" v-model="scope.row.price" @change="changePrice(scope.row)" />
                        </template>
                    </el-table-column>
                    <el-table-column prop="price" label="治疗时长（分钟）" min-width="155">
                        <template slot-scope="scope">
                            <GuipInput width="90%" v-model="scope.row.treat_time"
                                @change="changeTreatTime(scope.row)" />
                        </template>
                    </el-table-column>
                    <el-table-column prop="classify_id" label="分组" min-width="155">
                        <template slot-scope="scope">
                            <GuipSelect width="90%" v-model="scope.row.classify_id" @change="changeClassify(scope.row)"
                                prop="classify_id" :options="projectTagData" valueKey="id" labelKey="name" />
                        </template>
                    </el-table-column>
                    <el-table-column prop="create_time" label="添加时间" min-width="225"></el-table-column>

                    <el-table-column prop="need_countdown" label="倒计时弹窗开关" min-width="125">
                        <template slot-scope="scope">
                            <GuipSwitch :value="scope.row.need_countdown" active-value="1" inactive-value="0"
                                @change="onSwitchChange3(scope.row)">
                            </GuipSwitch>
                        </template>
                    </el-table-column>

                    <el-table-column prop="status" label="状态" min-width="125">
                        <template slot-scope="scope">
                            <GuipSwitch :value="scope.row.status" active-value="1" inactive-value="0"
                                @change="onSwitchChange1(scope.row)">
                            </GuipSwitch>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column label="操作" fixed="right" min-width="100px">
                        <template slot-scope="scope">
                            <div class="flex">
                                <el-button type="text" @click="handleClick(scope.row)">编辑</el-button>
                            </div>
                        </template>
                    </el-table-column> -->
                </GuipTable>
                <!-- <el-pagination background @size-change='handleSizeChange' @current-change='handleCurrentChange'
                    :current-page="currentPage" :page-size=pageSize layout="prev, pager, next,jumper"
                    :total="projectList.length">
                </el-pagination> -->
            </el-form>
        </div>
        <div class="siteMessage flex-common mt12" id="siteMessage5">
            <el-form>
                <div class=" mb32 flex-between">
                    <span class="littleTitle">疗程套餐</span>
                    <div class="flex-between" style="gap:10px">
                        <GuipButton size="table" type="primary" @click="addNewSetMenu">新增套餐</GuipButton>
                    </div>
                </div>
                <div class="selectAllTable-wrap flex-between  mt32 mb32">
                    <div class="left flex">
                        <div class="checkboxAll">
                            <el-checkbox @change="handleSelectAllChange1" v-model="selectAll1"
                                :indeterminate="isIndeterminate1">全选</el-checkbox>
                        </div>
                        <span class="totalCount">共{{ courseList.length }}条，已选{{ selectedCount }}条</span>
                        <GuipButton type="ignore" :btnstyle="{ width: '99px', height: '32px', margin: '0 26px' }"
                            @click="batchOperate(0, 'group')">批量禁用</GuipButton>
                        <GuipButton type="ignore" :btnstyle="{ width: '99px', height: '32px' }"
                            @click="batchOperate(1, 'group')">
                            批量启用</GuipButton>
                    </div>

                </div>
                <GuipTable :tableData="courseList" style="width: 100%" ref="multipleTable1"
                    @selection-change="handleSelectionChange1" :loading="loading1" :key="tableKey1">
                    <el-table-column type="selection" label="选择" width="80"></el-table-column>
                    <el-table-column prop="name" label="套餐名称" min-width="225"></el-table-column>
                    <el-table-column prop="price" label="套餐价格" min-width="125"></el-table-column>
                    <el-table-column prop="group" label="套餐内容" min-width="125">
                        <template slot-scope="scope">
                            {{ scope.row.project_classify_num }}项,共{{ scope.row.project_num_count }}次
                        </template>
                    </el-table-column>
                    <el-table-column prop="create_time" label="添加时间" min-width="225"></el-table-column>
                    <el-table-column prop="status" label="状态" min-width="125">
                        <template slot-scope="scope">
                            <GuipSwitch :value="scope.row.status" active-value="1" inactive-value="0"
                                @change="onSwitchChange2(scope.row)">
                            </GuipSwitch>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" fixed="right" min-width="100px">
                        <template slot-scope="scope">
                            <div class="flex">
                                <el-button type="text" @click="handleClick1(scope.row)">编辑</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </GuipTable>
                <!-- <el-pagination background @size-change='handleSizeChange' @current-change='handleCurrentChange'
                    :current-page="currentPage" :page-size=pageSize layout="prev, pager, next,jumper"
                    :total="courseList.length">
                </el-pagination> -->
            </el-form>
        </div>

        <GuipDialog :dialogVisible="registrationVisible" title="设置挂号费金额" :show-close-button="false" width="599px"
            :show-cancel-button="true" @confirm="handleRegisterConfirm('registerMoney')" @cancel="handleregisterCancel" ref="visitFee">
            <el-form>
                <GuipInput v-model="registerMoney" ref="registerMoney" class="registerMoney" placeholder="请输入" unit="元/人"></GuipInput>
            </el-form>
        </GuipDialog>
        <!-- freeRegVisible -->
        <GuipDialog :dialogVisible="freeRegVisible" title="免挂号费规则" :show-close-button="false" width="599px"
            :show-cancel-button="true" @confirm="handleRegisterConfirm('freeRegVisible')" @cancel="handleregisterCancel" >
            <p class="freeDesc">若勾选多个规则，满足其一即免挂号费</p>
            <el-form class="freeWrap">
                <div class="flex gap8 mb24 mt24">
                    <el-checkbox v-model="hasAgainVisitFreeDays" :true-label="1" :false-label="0"></el-checkbox>
                    患者
                    <GuipInput v-model="againVisitFreeDays" type="number" width="92px" placeholder="请输入"></GuipInput>天内再次就诊，免挂号费
                </div>
                <p class="flex gap8">
                    <el-checkbox v-model="hasRemainVisitFree" :true-label="1" :false-label="0"></el-checkbox>
                    患者有剩余治疗项目，免挂号费
                </p>
            </el-form>
        </GuipDialog>

        <GuipDialog :dialogVisible="dialogVisible" :title="dialogTitle" :show-close-button="true" width="762"
            :show-cancel-button="true" @confirm="handleConfirm" @cancel="handleCancel" @close="handleClose"
            @dialogVisibleChange="dialogVisibleChange">
            <BatchProject ref="channelProject" v-if="dialogType == '1'" :projectTagData="projectTagData" />
        </GuipDialog>
        <GuipDialog :dialogVisible="dialogVisible1" :title="'新增项目分组'" :show-close-button="true" width="599px"
            type="center" :show-cancel-button="true" @confirm="handleConfirm" @cancel="handleCancel"
            @close="handleClose" confirmText="确定新增" @dialogVisibleChange="dialogVisibleChange">
            <el-form :model="form1" @submit.native.prevent ref="projectNameForm">
                <GuipFormItem column="column" class="" label="分组名称">
                    <GuipInput slot="formDom" ref="GuipInput" v-model="form1.projectName" :rules="nameRules"
                        prop="projectName" placeholder="请填写新增分组名称" />
                </GuipFormItem>
            </el-form>
        </GuipDialog>

        <SetAliPay payType="3" :visible="isShowAddAliPay" @update:visible="handleEvent" @update:data="handleUpdateEvent"
        :isExistSelfSupplys="isExistSelfSupplys" :doctor_id="doctor_id" :depart_id="depart_id" :checkAliPay="checkAliPay"></SetAliPay>
    </div>
</template>
<script>
import GuipFormItem from '@/components/GuipFormItem.vue';
import BatchProject from '@/components/BatchProject.vue';
import store from '@/store';
import GuipButton from '@/components/GuipButton.vue';
import GuipInput from '@/components/GuipInput.vue';
import GuipTextarea from '@/components/GuipTextarea.vue';
import GroupFormBtns from '@/components/GroupFormBtns.vue';
import GuipSelect from '@/components/GuipSelect.vue';
import GuipSwitch from '@/components/GuipSwitch.vue';
import GuipTable from '@/components/GuipTable.vue';
import GuipDialog from '@/components/GuipDialog.vue';
//import GuipSelectFilter from '@/components/GuipSelectFilter.vue';
import CustomDropdown from '@/components/CustomDropdown.vue';
import SetAliPay from '@/components/SetAliPay.vue';

import { mapState } from 'vuex';
import { Object } from 'core-js';
const PAY_TYPE_WEIXIN = 2;    // 微信
const PAY_TYPE_ALIPAY = 3;    // 支付宝
export default {
    // 站点设置
    name: '',
    props: [''],
    components: {
        CustomDropdown,
        GuipFormItem,
        BatchProject,
        GuipButton,
        GuipDialog,
        GuipInput,
        GuipTable,
        GuipSwitch,
        GuipSelect,
        GuipTextarea,
        GroupFormBtns,
        SetAliPay
    },
    data() {
        return {
            depart_id: false,
            doctor_id: false,
            dialogType: '1',
            tableKey: Date.now(),
            tableKey1: Date.now(),
            hospitalName: '',
            dialogVisible: false,
            dialogVisible1: false,
            form1: {
                projectName: ''
            },
            nameRules: [{ required: true, message: '分组名称不得为空', trigger: 'blur' }],
            dialogTitle: '批量录入项目',
            currentPage: 1,
            pageSize: 1000,
            currentPage1: 1,
            pageSize1: 1000,
            loading: false,
            loading1: false,
            selectedRows: [],//已选中数据
            selectedRows1: [],//已选中数据
            isIndeterminate: false,
            isIndeterminate1: false,
            projectSearchId: 'all',
            projectSearchName: '',
            hospitalRestaurants: [],
            hospitalSearchState: '',
            hospitalSearchFlag: false,
            hospitalSearchTimeout: false,
            departIsFixed: -1,
            projectList: [],
            projectTagData: [],
            courseList: [],
            selectAll: false,
            selectAll1: false,
            departType: [],
            numSettingForm: {
                times: '',
                hours: '',
                nums: '',
                days: ''
            },
            numSettingFormRule: {
                times: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                hours: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                nums: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                days: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
            },
            options_province: [],
            options_city: [],
            weekPlan: {
                '周一': '',
                '周二': '',
                '周三': '',
                '周四': '',
                '周五': '',
                '周六': '',
                '周日': '',
            },
            weekDays: [
                { id: 1, name: '周一' },
                { id: 2, name: '周二' },
                { id: 3, name: '周三' },
                { id: 4, name: '周四' },
                { id: 5, name: '周五' },
                { id: 6, name: '周六' },
                { id: 7, name: '周日' }
            ],
            time1: '',
            time2: '',
            fileList: [
                { name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' }
            ],
            yibao: '',
            options_weekPlan: [{
                value: '1',
                label: '上午班'
            }, {
                value: '2',
                label: '下午班'
            }, {
                value: '3',
                label: '全天'
            }, {
                value: '0',
                label: '休息'
            },],
            siteForm: {
                company_name: '',
                company_address: '',
                company_phone: '',
                site_alias: '',
            },
            oldForm: {
                description: '',
                detailDesc: '',
                tags: ''
            },
            form: {
                province: '',
                city: '',
                depart_name: '',
                address: "",
                afternoon_worktime: "",
                depart_id: "0",
                h_name: "",
                h_pos: "",
                hid: "0",
                is_fixed: '0',
                morning_worktime: "",
                h_shortname: '',
                notice: "",
                time_unit: "0",
                time_unit_num: "0",
                treat_expire: "0",
                visit_day: "0",
                search_province: "",
                search_city: "",
            },
            siteFormrules: {
            },
            siteForm1: {
                domain_set: '',
                domain_source: '平台免费域名',
            },
            siteFormrules1: {
                domain_source: [
                    { required: true, message: '请输入站点简称', trigger: 'blur' }
                ]
            },
            wxpayList:[],
            alipayList:[],
            payTypeWeixin: PAY_TYPE_WEIXIN,
            payTypeAlipay: PAY_TYPE_ALIPAY,
            selectWxpay:null,
            selectAlipay: null,
            onLinePay:null,
            payinfo: [],
            registerMoney:'',//挂号费金额
            registerDays:5,
            freeRegVisible:false,
            registrationVisible:false,
            hasVisitFee:null,
            hasFreeRegisterRule:false,
            hasAgainVisitFreeDays:0,
            againVisitFreeDays:0,
            hasRemainVisitFree:0,
            isShowAddAliPay:false,
            isExistSelfSupplys: false,
            checkAliPay:null
        }
    },
    created() {
        store.commit('SET_CUSTOMIZE', true);
        store.commit('SET_SLIDER_MENU', 'hosMenuData');
    },
    async mounted() {
        const { depart_id, doctor_id } = this.$route.query; // 获取 doctorId 参数
        if (doctor_id) this.doctor_id = doctor_id;
        if (doctor_id && depart_id) {
            // 请求医生信息
            this.depart_id = depart_id;
            this.doctor_id = doctor_id;
            await this.fetchDoctorData()
            console.log(this.doctor_id)
            await this.getAreaData()
            this.fetchPackData()
            this.fetchProjectData()
            this.geHosAdress()
            this.getBindpayList()
        } else {
            await this.getAreaData()
        }
    },
    watch: {
        '$route.query': {
            immediate: true,
            deep: true,
            handler(newVal) {
                this.doctor_id = newVal.doctor_id;
                this.depart_id = newVal.depart_id;
                this.getAreaData();
                this.fetchDoctorData();
                this.fetchPackData();
                this.fetchProjectData();
                this.geHosAdress();
            }
        }
    },
    computed: {
        selectedCount() {
            return this.selectedRows.length;
        },
        ...mapState(['hosMenuData']) // 从Vuex映射showSidebar状态到组件的计算属性中
    },
    methods: {
        handleEvent(data) {
            this.isShowAddAliPay = data;
        },
        handleUpdateEvent(data){
            this.bindAlipayId = data.payid;
            this.selectAlipay = data;
        },
        goToAddPay(pay_type){
            if(pay_type == this.payTypeWeixin) {
                this.$router.push(`/setPaymentForm?doctor_id=${this.doctor_id}&depart_id=${this.depart_id}`);
                return
            }

            this.isShowAddAliPay = true;
        },
        showDialog(type) {
            if (type == 'register') {
                this.registrationVisible = true;
            } else if (type == 'registerRule') {
                this.freeRegVisible = true;
            }
        },
        async getBindpayList() {
            await this.$http('POST', '/api/admin/get_pay_list', {
                doctor_id: this.doctor_id,
                depart_id: this.depart_id
            }).then(response => {
                if (
                    response.data &&
                    response.data[this.payTypeWeixin]
                    &&response.data[this.payTypeWeixin].length > 0
                ) {
                    this.wxpayList =response.data[this.payTypeWeixin]
                    this.selectWxpay = this.wxpayList.filter(item => item.is_bind)[0];
                    console.log(this.selectWxpay,'this.selectWxpay');
                }else{
                    this.selectWxpay = null;
                }
                if (
                    response.data &&
                    response.data[this.payTypeAlipay]
                    &&response.data[this.payTypeAlipay].length > 0
                ) {
                    this.alipayList = response.data[this.payTypeAlipay]
                    this.selectAlipay = this.alipayList.filter(item => item.is_bind)[0];
                }else{
                    this.selectAlipay = null;
                }
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        async onLineChange(e) {
            this.onLinePay = e;
            await this.$http('POST', '/api/admin/set_pay_switch', {
                doctor_id: this.doctor_id,
                depart_id: this.depart_id,
                pay_switch:this.onLinePay
            }).then(response => {
                console.log(response,'===');
                    const { code } = response
                    const msg = this.onLinePay === 1 ? '已开启' : '已关闭'
                    const type = code === 0 ? 'success' : 'error';
                    this.$positionMessage({
                        type: type,
                        message: msg+'线上收款',
                        target: this.$refs['hasOnlinePayRef'],
                        position: 'top'
                    })
            }).catch(error => {
                this.onLinePay = 0;
                console.error(error, 'error')
            })
        },
        async onVisitFeeChange(e) {
            this.hasVisitFee = e
            await this.$http('POST', '/api/admin/set_has_visit_fee', {
                has_visit_fee: this.hasVisitFee,
                doctor_id: this.doctor_id,
                depart_id: this.depart_id
            }).then(response => {
                const { code } = response
                const msg = this.hasVisitFee === 1 ? '已开启' : '已关闭'
                const type = code === 0 ? 'success' : 'error';
                this.$positionMessage({
                    type: type,
                    message: msg+'收挂号费',
                    target: this.$refs['hasVisitFeeRef'],
                    position: 'top'
                })
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        changeSelectWeixin(item) {
            console.log(item, 'item')
            // if(this.bindWxpayId === item.payid){
            //     this.bindWxpayId = 0
            //     this.selectWxpay = null
            //     return true
            // }
            // this.bindWxpayId = item.payid;
            this.selectWxpay = item;
            this.bindPayMethod(item.id)
        },
        changeSelectAlipay(item) {
            // if(this.bindAlipayId === item.payid){
            //     this.bindAlipayId = 0
            //     this.selectAlipay = null
            //     return true
            // }
            // this.bindAlipayId = item.payid;
            this.selectAlipay = item;
            this.bindPayMethod(item.id)
        },

        async bindPayMethod(id){
            await this.$http('POST', '/api/admin/bind_pay_method', {
                pay_id: id,
                doctor_id: this.doctor_id,
                depart_id: this.depart_id
            }).then(response => {
                const { code } = response;
                if(code == 0){
                    this.$Message.success(response.msg || '绑定成功');

                }else{
                    this.$Message.error(response.msg || '绑定失败');
                }
                this.getBindpayList()

            }).catch(error => {
                console.error(error, 'error')
            })
        },

        handleregisterCancel(){
            console.log('取消');
            this.freeRegVisible = false;
            this.registrationVisible = false;
        },
        handleRegisterConfirm(type){
            var params = {}
            params.doctor_id = this.doctor_id
            params.depart_id = this.depart_id
            if(type == 'freeRegVisible'){
                params.has_again_visit_free_days = parseInt(this.hasAgainVisitFreeDays) ? 1 : 0
                params.again_visit_free_days = parseInt(this.againVisitFreeDays)
                if(params.again_visit_free_days < 0){
                    this.$positionMessage({
                        type: 'error',
                        message: '请输入正确的天数',
                        target: '#siteMessage7',
                    })
                    return;
                }
                params.has_remain_visit_free = parseInt(this.hasRemainVisitFree) ? 1 : 0

                this.$http('POST', '/api/admin/set_visit_free_rules', {
                   ...params
                }).then(response => {
                    this.$nextTick(() => {
                        if(response.code == 0) {
                            this.$Message.success('设置成功');
                            this.fetchDoctorData()
                        }else{
                            this.$Message.error(response.msg);
                        }
                       this.freeRegVisible = false;
                    })
                }).catch(error => {
                    console.error(error, 'error')
                })
            }else{
                params.price = parseInt(this.registerMoney)
                if(!params.price || params.price <= 0) {
                    this.$positionMessage({
                        type: 'error',
                        message: '请输入正确的金额',
                        target: '.registerMoney',
                        position: 'top',
                    })
                    return;
                }
                this.$http('POST', '/api/admin/set_visit_price', {
                   ...params
                }).then(response => {
                    this.$nextTick(() => {
                       if(response.code !== 0) {
                            this.$Message.error(response.msg);
                        }else{
                            this.$Message.success('设置成功');
                       }
                       this.registrationVisible = false;
                    })
                }).catch(error => {
                    console.error(error, 'error')
                })
            }
        },

        handleSearch() {
            if (this.hospitalSearchFlag) return
            this.hospitalSearchFlag = true
            if (!this.hospitalSearchState.trim()) {
                this.$message.error('医院名称或地址不能为空');
                this.hospitalSearchFlag = false
                return
            }
            this.getInternetHospital(this.hospitalSearchState)
        },
        hospitalHandleSelect(item) {
            this.form.h_realname = item.value
            this.form.search_province = item.province
            this.form.search_city = item.city
            this.form.address = item.address
            this.form.h_pos = item.location.lat + ',' + item.location.lng
            console.log(item)
        },
        getInternetHospital(queryString) {
            if (!this.hospitalSearchFlag) return;
            this.hospitalSearchTimeout = setTimeout(function () {
                this.hospitalSearchFlag = false
            }.bind(this), 5000);

            this.$http('POST', '/api/admin/search_hoispital', {
                keyword: queryString,
                province: this.form.province,
                city: this.form.city,
            }).then(response => {
                this.hospitalSearchFlag = false
                clearTimeout(this.hospitalSearchTimeout)
                if (response.code !== 0) {
                    this.hospitalRestaurants = []
                    this.$refs.hospitalAutocomplete.getData(this.hospitalSearchState)
                    this.$message.error(response.msg);
                    return
                }

                this.hospitalRestaurants = Object.values(response.data)
                this.$refs.hospitalAutocomplete.activated = true
                this.$refs.hospitalAutocomplete.getData(this.hospitalSearchState)

                if (this.hospitalRestaurants.length <= 0) this.$message.error('未查询相关信息');
            }).catch(error => {
                this.hospitalSearchFlag = false
                clearTimeout(this.hospitalSearchTimeout)
                this.hospitalRestaurants = []
                console.error(error, 'error')
            })
        },
        queryHospital(queryString, cb) {
            console.log(queryString)
            cb(this.hospitalRestaurants);
        },
        random() {
            var randomNumber = Math.random();
            return randomNumber
        },
        provinceChange(e) {
            this.options_city = []
            this.form.city = ''
            this.getAreaData(e)
        },
        async getAreaData(province = '') {
            if (province != '') this.options_city = []
            this.$http('POST', '/api/admin/get_areas_data', {
                province: province,
            }).then(response => {
                if (province == '') {
                    this.options_province = response.data
                } else {
                    this.options_city = response.data
                }
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        async fetchDoctorData() {
            this.$http('POST', '/api/admin/get_depart_info', {
                depart_id: this.depart_id,
                doctor_id: this.doctor_id
            }).then(response => {
                this.form = {
                    ...this.form, ...response.data,
                    'morning_worktime': response.data.morning_worktime ? response.data.morning_worktime.split('-') : '',
                    'afternoon_worktime': response.data.afternoon_worktime ? response.data.afternoon_worktime.split('-') : ''
                }
                this.departType = (response.data.type || response.data.type === 0 || response.data.type === "0") ? [Number(response.data.type)] : []
                this.departIsFixed = response.data.is_fixed == "1" ? true : false
                this.onLinePay = response.data.pay_switch
                this.hasVisitFee = response.data.has_visit_fee
                this.registerMoney = response.data.visit_price

                this.hasAgainVisitFreeDays = response.data.has_again_visit_free_days
                this.againVisitFreeDays = response.data.again_visit_free_days
                this.hasRemainVisitFree = response.data.has_remain_visit_free
                if((this.hasAgainVisitFreeDays && this.againVisitFreeDays) || this.hasRemainVisitFree) this.hasFreeRegisterRule = true

                this.getAreaData(this.form.province)
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        // 疗程套餐
        fetchPackData() {
            this.$http('POST', '/api/admin/get_project_packagelist', {
                depart_id: this.depart_id,
                doctor_id: this.doctor_id
            }).then(response => {
                if (response.code == 0) {
                    this.loading1 = false
                    this.$nextTick(() => {
                        this.courseList = response.data.list ? response.data.list : [];
                        this.tableKey1 = Date.now(); // 强制重新渲染表格
                    })
                }

            }).catch(error => {
                console.error(error, 'error')
            })
        },
        // 项目列表
        fetchProjectData() {
            var param = {
                depart_id: this.depart_id,
                doctor_id: this.doctor_id,
                name: this.projectSearchName,
                classify_id: this.projectSearchId
            }

            this.$http('POST', '/api/admin/get_project_list', param).then(response => {
                if (response.code == 0) {
                    this.loading = false
                    this.$nextTick(() => {
                        if (response.data.classify) {
                            this.projectTagData = response.data.classify;//项目分类
                            if (response.data.list && response.data.list.length > 0) {
                                this.projectList = Object.values(response.data.list);//项目列表
                            } else {
                                this.projectList = []
                            }
                            this.tableKey = Date.now(); // 强制重新渲染表格
                        }
                        // this.$set('projectList',Object.values(response.data.list))
                        // this.$set('projectTagData',response.data.classify)
                    })
                }
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        geHosAdress() {
            this.$http('POST', '/api/admin/search_hoispital', {
                keyword: this.doctor_id,
            }).then(response => {
                console.log(response.data, '===data');

            }).catch(error => {
                console.error(error, 'error')
            })
        },
        validateSelection(val) {
            this.departType = []
            if (val.length > 0) this.departType[0] = val[val.length - 1]
        },
        selectTag(item) {
            if (item == 'all') {
                this.projectSearchId = 'all';
            } else {
                this.projectSearchId = item.id;
            }
            // 筛选逻辑
            this.fetchProjectData()
        },
        getFilterProject() {
            this.fetchProjectData()
        },
        // 修改项目价格
        changePrice(row) {
            this.editorProjectInfo({ price: row.price, project_id: row.id })
        },
        // 修改项目价格
        changeTreatTime(row) {
            this.editorProjectInfo({ treat_time: row.treat_time, project_id: row.id })
        },
        // 修改分类
        changeClassify(row) {
            this.editorProjectInfo({ classify_id: row.classify_id, project_id: row.id })
        },
        editorProjectInfo(props) {
            this.$http('POST', '/api/admin/edit_project', {
                ...props,
                depart_id: this.depart_id,
                doctor_id: this.doctor_id,
            }).then(response => {
                if (response.code == 0) {
                    this.$Message.success('修改成功')
                    this.fetchProjectData()
                }
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        addNewSetMenu() {
            this.$router.push(`/addNewTreatment?doctor_id=${this.doctor_id}&depart_id=${this.depart_id}`)
        },
        addNewGroup() {
            this.dialogVisible1 = true
        },
        addNewProject() {
            this.dialogVisible = true
        },
        handleClose() {
            this.$Message.info('弹框已关闭');
            this.dialogVisible = false;
        },
        handleSizeChange(val) {
            this.pageSize = val
            this.getData()
        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.getData()
        },

        // 确认按钮事件
        handleConfirm() {
            if (this.dialogVisible1) {
                this.$refs['projectNameForm'].validate((valid) => {
                    if (valid) {
                        this.$http('POST', '/api/admin/add_project_group', {
                            name: this.form1.projectName.trim(),
                            depart_id: this.depart_id,
                            doctor_id: this.doctor_id,
                        }).then(response => {
                            if (response.code == 0) {
                                this.$Message.success('修改成功')
                                this.dialogVisible1 = false;
                                this.form1.projectName = ''
                                this.fetchProjectData()
                            }
                        }).catch(error => {
                            this.$Message.error(error || '错误！')
                        })
                    } else {
                        this.$Message.info('项目分组名称不可为空')
                        return false;
                    }
                });
            } else if (this.dialogVisible) {//新增项目
                let data = JSON.parse(JSON.stringify(this.$refs.channelProject.form));
                let str = data.project_contents;
                data.project_contents = str.trim();
                if ((data.groupType == '1' && !data.classify_id) || (data.groupType == '2' && !data.classify_name)) {
                    this.$Message.info('分组不能为空')
                    return;
                }

                if (!data.project_contents) {
                    this.$Message.info('录入项目内容不能为空！')
                    return;
                }

                this.$http('POST', '/api/admin/mitil_add_project', {
                    depart_id: this.depart_id,
                    doctor_id: this.doctor_id,
                    ...data
                }).then(response => {
                    if (response.code == 0) {
                        this.$Message.success('新增项目成功')
                        this.$refs.channelProject.formReset()
                        this.dialogVisible = false;
                        this.fetchProjectData();
                    }
                }).catch(error => {
                    this.$Message.error(error || '错误！')
                })
            }
        },
        // 取消按钮事件
        handleCancel() {
            if (this.dialogVisible) this.$refs.channelProject.formReset()
            this.dialogVisible = false;
            this.dialogVisible1 = false;
        },
        dialogVisibleChange(data) {
            console.log(data, 'data098908090');
        },
        onSwitchChange1(row) {
            row.status = row.status == 0 ? 1 : 0;
            this.$set(this.projectList, row)
            this.editorProjectInfo({ status: row.status, project_id: row.id })
        },
        onSwitchChange2(row) {
            var tmpstatus = row.status == 1 ? 0 : 1
            this.$set(this.courseList, row)
            this.selectedRows1 = [row]
            this.batchOperate(tmpstatus, 'group')
        },
        onSwitchChange3(row) {
            row.need_countdown = row.need_countdown == 0 ? 1 : 0;
            this.$set(this.projectList, row)
            this.editorProjectInfo({ need_countdown: row.need_countdown, project_id: row.id })
        },
        handleClick1(row) {
            console.log(row);
            this.$router.push(`/addNewTreatment?package_id=${row.id}&doctor_id=${this.doctor_id}&depart_id=${this.depart_id}`)
            // 跳转编辑页面
        },
        handleClick(row) {
            console.log(row);
            // 跳转编辑页面
        },
        // 处理全选按钮变化
        handleSelectAllChange(val) {
            console.log(this.$refs.multipleTable, 'multipleTable-');
            if (val) {
                // 只选中未选中的行
                const unselectedRows = this.projectList.filter(
                    row => !this.selectedRows.includes(row)
                );
                unselectedRows.forEach(row => {
                    this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, true);
                });
            } else {
                // 只取消已选中的行
                this.selectedRows.forEach(row => {
                    this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, false);
                });
            }
        },

        // 处理选择变化
        handleSelectionChange(rows) {
            this.selectedRows = rows;
            // 更新全选按钮状态
            const allSelected = rows.length === this.projectList.length;
            const noneSelected = rows.length === 0;

            this.selectAll = allSelected;
            this.isIndeterminate = !noneSelected && !allSelected;
        },
        handleSelectAllChange1(val) {
            console.log(this.$refs.multipleTable, 'multipleTable-');
            if (val) {
                // 只选中未选中的行
                const unselectedRows = this.courseList.filter(
                    row => !this.selectedRows1.includes(row)
                );
                unselectedRows.forEach(row => {
                    this.$refs.multipleTable1.$refs.guiptable.toggleRowSelection(row, true);
                });
            } else {
                // 只取消已选中的行
                this.selectedRows.forEach(row => {
                    this.$refs.multipleTable1.$refs.guiptable.toggleRowSelection(row, false);
                });
            }
        },

        // 处理选择变化
        handleSelectionChange1(rows) {
            console.log(rows, '1=====');
            this.selectedRows1 = rows;
            // 更新全选按钮状态
            const allSelected = rows.length === this.courseList.length;
            const noneSelected = rows.length === 0;

            this.selectAll1 = allSelected;
            this.isIndeterminate1 = !noneSelected && !allSelected;
        },
        // 批量操作
        batchOperate(type, name) {
            // 默认疗程 启用、禁用
            let url = '/api/admin/project_package_mutil_option';
            let props = {
                status: type,
                depart_id: this.depart_id,
                doctor_id: this.doctor_id
            }
            let str = []
            // 禁用
            if (name == 'project') {
                // 修改项目列表
                url = '/api/admin/project_mutil_option';
                // selectedRows
                console.log(this.selectedRows, '----09999888');
                this.selectedRows.forEach(item => {
                    if (item.status != type) {
                        str.push(item.id)
                    }
                })
                if (str.length == 0) {
                    this.$message.error('请重新选择！')
                    return
                }
                props.project_ids = str.join(',')
            } else {
                // 修改疗程套餐
                // selectedRows1
                this.selectedRows1.forEach(item => {
                    if (item.status != type) {
                        str.push(item.id)
                    }
                })
                if (str.length == 0) {
                    this.$message.error('请重新选择！')
                    return
                }
                props.package_ids = str.join(',')
            }
            // console.log(url,props);
            this.changePackData(url, props, name)
        },
        //
        changePackData(url, params, name) {
            this.$http('POST', url, {
                ...params
            }).then(response => {
                if (response.code == 0) {
                    this.$Message.success('操作成功')
                    if (name == 'project') {
                        this.loading = true;
                        this.selectedRows = []
                        this.fetchProjectData()
                    } else {
                        this.loading1 = true;
                        this.selectedRows1 = [];
                        this.fetchPackData()
                    }
                }
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        ChangeTime(type) {
            console.log(this.form.morning_worktime, type, '===');
        },
        onSwitchChange(data) {
            this.form.is_fixed = data ? 1 : 0
            this.departIsFixed = data
            console.log(data, '---');
        },
        updateHosInfo(props, url) {
            if (this.doctor_id) props.doctor_id = this.doctor_id;

            if (this.doctor_id && this.depart_id) {
                props.doctor_id = this.doctor_id;
                props.depart_id = this.depart_id;
                props.hid = this.form.hid;
            }

            this.$http('POST', url, {
                ...props
            }).then(response => {
                if (response.code == 0) {
                    this.$Message.success('更新成功')
                    if (this.doctor_id && !this.depart_id) {
                        var that = this
                        setTimeout(() => {
                            that.$router.push({
                                name: '医院信息',
                                query: { doctor_id: this.doctor_id, depart_id: response.data.depart_id }
                            })
                        }, 1000)
                    }
                    return;
                }
                this.$Message.error(response.msg)
            }).catch(error => {
                console.error(error, 'error')
            })
        },
        submitForm(form) {
            this.$refs[form].validate((valid) => {
                console.log(this[form], '======formxinxi8', '==============' + form);
                var rqurl = '';
                if (valid) {
                    let props = {}
                    switch (form) {
                        case 'siteForm1':
                            var worktimesArray = Object.entries(this.form.worktimes).map(([key, value]) => ({
                                type: parseInt(key),
                                plan: value.plan
                            }));

                            props = {
                                morning_worktime: this.form.morning_worktime ? this.form.morning_worktime.join('-') : '',
                                afternoon_worktime: this.form.afternoon_worktime ? this.form.afternoon_worktime.join('-') : '',
                                week_visit_plan: JSON.stringify(worktimesArray),
                            }

                            rqurl = "/api/admin/set_depart_worktime";
                            break;
                        case 'siteForm':
                            if (this.doctor_id && !this.depart_id) {
                                if (!this.form.search_province.trim() || !this.form.search_city.trim() || !this.form.address.trim() || !this.form.h_pos.trim()) {
                                    this.$Message.info('请选择搜索结果下拉中的出诊医院')
                                    return;
                                }
                            }

                            if (this.departType.length <= 0) {
                                this.$Message.info('请选择使用功能')
                                return;
                            }

                            props = {
                                is_fixed: this.form.is_fixed,
                                type: this.departType[0],
                                notice: this.form.notice,
                                h_shortname: this.form.h_shortname
                            }

                            if (this.doctor_id && !this.depart_id) {
                                if (this.departType.length <= 0) {
                                    this.$Message.info('请选择使用功能')
                                    return;
                                }

                                props = this.form
                                props.type = this.departType[0]
                            }
                            rqurl = "/api/admin/set_hospital_depart";
                            break;
                        case 'numSettingForm':
                            props = {
                                time_unit: this.form.time_unit,
                                time_unit_num: this.form.time_unit_num,
                                visit_day: this.form.visit_day,
                                treat_expire: this.form.treat_expire,
                            }
                            rqurl = "/api/admin/set_visit_num";
                            break;
                    }
                    this.updateHosInfo(props, rqurl)
                } else {
                    return false;
                }
            });
        },
        cancelClick() {
            console.log('quxiao');
        },
        confirmClick(type) {
            console.log(type, '确认');
        }

    }
}
</script>
<style lang="scss" scoped>
.freeWrap{
    letter-spacing: 0.08em;
    color: #626573;
}
.freeDesc{
    color: #8A9099;
}
.el-form-item {
    margin-bottom: 0;
}
.requireImg{
    width: 8px;
    height: 8px;
}
.notSet,
.yesSet {
    margin-right: 12px;
    color: #FF4D4F;
}

.yesSet {
    color: #00C261;
}
.desc{
    font-size: 12px;
    font-weight: normal;
    line-height: 13px;
    letter-spacing: 0.08em;
    color: #6B7280;
}
.bidwrap-item{
    padding: 24px 14px;
    box-sizing: border-box;
    background: #FAFAFA;
    .biditemMast {
        background: #fff;
        padding: 24px 16px;
        border-radius: 8px;
        background: #FFFFFF;
        align-items: flex-start;
        .bidwrap-item-top {
            .top-right {
                p {
                    margin-top: 10px;
                    color: #1E2226;
                }
                .desc{
                    color: #6B7280;
                }
                a {
                    text-decoration: none;
                    color: #006AFF;

                    img {
                        margin-right: 10px;
                    }
                }
            }
        }

        .bidwrap-item-bot {
            padding-left: 54px;
            justify-content: flex-end;
        }
    }
}
.el-autocomplete-noloading {
    display: none !important;
}

.weekPlan {
    display: grid;
    grid-gap: 12px 44px;
    grid-template-columns: repeat(2, 1fr);
}

#siteMessage4 ::v-deep .el-form-item {
    margin-bottom: 0 !important;
}
.tipInfo{
    font-family: Microsoft YaHei UI;
    font-size: 12px;
    font-weight: normal;
    line-height: 13px;
    letter-spacing: 0.08em;
    color: #FF4D4F;
}

.pageTitle {
    // padding: 12px 0;
}

.scroll-container {
    width: calc(100% - 380px);
    overflow-x: auto;
    /* 关键：启用横向滚动 */
}

.special-input {
    margin-bottom: 0 !important;
}

.scroll-list {
    display: flex;
    /* Flex 布局 */
    flex-wrap: nowrap;
    /* 禁止换行 */
    gap: 10px;
    /* 子项间距 */
}

.scroll-item {
    flex: 0 0 auto;
    /* 不伸缩、不收缩 */
    width: 200px;
    /* 固定子项宽度 */
    height: 100px;
    background: #eee;
}

.totalCount {
    font-size: 12px;
    font-weight: normal;
    line-height: 13px;
    letter-spacing: 0.08em;
    color: #8A9099;
    margin-left: 12px;
}

.tabProject {
    width: calc(100% - 380px);
    overflow-x: auto;

    .overTab {
        display: flex;
        gap: 12px;
        flex-wrap: nowrap;
        /* 禁止换行 */
    }

    .tab-item {
        height: 28px;
        // min-width: 74px;
        display: inline-flex;
        /* 关键修改：从 flex 改为 inline-flex */
        justify-content: center;
        align-items: center;
        box-sizing: border-box;
        padding: 4px 12px;
        gap: 4px;
        z-index: 2;
        border-radius: 14px;
        background: #FFFFFF;
        border: 1px solid #DFE2E6;
        font-family: Microsoft YaHei UI;
        font-size: 14px;
        text-align: justify;
        letter-spacing: 0.08em;
        color: #8A9099;
        white-space: nowrap;
        /* 防止文字换行 */
    }

    .active {
        color: #006AFF;
        border-color: transparent;
        background: #F2F3F5;
    }
}

.siteMessage {
    border-radius: 4px;
    transition: all .5s;
    border: 1px solid transparent;
}

.checkboxGroup {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: 24px;
    height: 72px;
    padding: 10px 0;
}

.addStore {
    margin-top: 12px;
}

.qqCode-wrap {
    margin-bottom: 14px;

    .labelImg {
        opacity: .7;
        margin-left: 8px;
    }

    .avatar-uploader {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        margin: 12px 0 8px;
    }

    .avatar-desc {
        text-align: left;
    }
}


.site-setting-wrap {
    width: 100%;
}

#siteMessage2 {
    margin: 12px 0;
}

.domain-wrap {
    .domain-item {
        margin-bottom: 10px;
    }


    .domain-item p:last-child {
        padding-left: 23px;
        color: #8A9099;
    }

    p {
        text-align: left;
        line-height: 18px;
        margin-bottom: 8px;
    }

    .domain-box {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }
}
</style>