<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="130px"
    >
      <el-form-item label="人员名称" prop="personName">
        <el-input
          v-model="queryParams.personName"
          placeholder="请输入科室人员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员联系电话" prop="personPhone">
        <el-input
          v-model="queryParams.personPhone"
          placeholder="请输入人员联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="身份证号" prop="cardNo">
        <el-input
          v-model="queryParams.cardNo"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:hospitalPerson:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:hospitalPerson:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:hospitalPerson:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:hospitalPerson:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="hospitalPersonList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键id" align="center" prop="id" /> -->
      <el-table-column label="所属医院" align="center" prop="hospitalName" />
      <el-table-column label="所属部门" align="center" prop="departmentName" />
      <el-table-column label="人员编码" align="center" prop="personCode" />
      <el-table-column label="人员名称" align="center" prop="personName" />
      <el-table-column label="人员联系电话" align="center" prop="personPhone" />
      <el-table-column label="人员地址" align="center" prop="personAddress" />
      <el-table-column label="身份证号" align="center" prop="cardNo" />
      <el-table-column label="人员职称" align="center" prop="academicTitle">
        <template slot-scope="scope">
          {{ scope.row.academicTitle == "CHIEF_PHYSICIAN" ? "主任医师" : "" }}
          {{
            scope.row.academicTitle == "DEPUTY_CHIEF_PHYSICIAN"
              ? "副主任医师"
              : ""
          }}
          {{ scope.row.academicTitle == "ATTENDING_DOCTOR" ? "主治医师" : "" }}
          {{ scope.row.academicTitle == "PHYSICIAN" ? "医师" : "" }}
          {{ scope.row.academicTitle == "HEALER" ? "医士" : "" }}
        </template>
      </el-table-column>
      <el-table-column label="咨询费用" align="center" prop="consultingFee" />
      <!-- <el-table-column label="个人简介" align="center" prop="personIntroduce" /> -->
      <el-table-column label="显示顺序" align="center" prop="personSort" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:hospitalPerson:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:hospitalPerson:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加健康咨询-科室人员信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="addopen"
      width="1100px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="140px"
        :inline="true"
      >
        <div
          v-for="(item, index) in form.hospitalPersonInfoList"
          :key="index"
          style="margin-top: 20px; border-bottom: 1px solid #f3f3f3"
        >
          <el-form-item
            label="所属医院"
            :rules="rules.hospitalPersonInfoList.hospitalId"
            :prop="`hospitalPersonInfoList.${index}.hospitalId`"
          >
            <el-button
              type=""
              v-if="item.hospitalName == '请选择所属医院'"
              @click="clickinnerVisible(item, index)"
              style="
                width: 210px;
                text-align: left;
                height: 36px;
                color: #c0c4cc;
                overflow: hidden;
              "
              >{{ item.hospitalName }}</el-button
            >
            <el-button
              @click="clickinnerVisible(item, index)"
              type=""
              v-else
              style="
                width: 210px;
                text-align: left;
                height: 36px;
                padding-left: -10px;
                overflow: hidden;
              "
              >{{ item.hospitalName }}</el-button
            >
          </el-form-item>
          <el-form-item
            label="所属科室"
            :rules="rules.hospitalPersonInfoList.departmentId"
            :prop="`hospitalPersonInfoList.${index}.departmentId`"
          >
            <el-button
              type=""
              v-if="item.departmentName == '请选择所属科室'"
              @click="clicklist(item, index)"
              style="
                width: 210px;
                text-align: left;
                height: 36px;
                color: #c0c4cc;
                overflow: hidden;
              "
              >{{ item.departmentName }}</el-button
            >
            <el-button
              @click="clicklist(item, index)"
              type=""
              v-else
              style="
                width: 210px;
                text-align: left;
                height: 36px;
                padding-left: -10px;
                overflow: hidden;
              "
              >{{ item.departmentName }}</el-button
            >
          </el-form-item>
          <el-form-item
            label="人员名称"
            :rules="rules.hospitalPersonInfoList.personName"
            :prop="`hospitalPersonInfoList.${index}.personName`"
          >
            <el-input v-model="item.personName" placeholder="请输入人员名称" />
          </el-form-item>
          <el-form-item
            label="人员联系电话"
            :rules="rules.hospitalPersonInfoList.personPhone"
            :prop="`hospitalPersonInfoList.${index}.personPhone`"
          >
            <el-input
              v-model="item.personPhone"
              placeholder="请输入人员联系电话"
            />
          </el-form-item>
          <el-form-item
            label="人员地址"
            :rules="rules.hospitalPersonInfoList.personAddress"
            :prop="`hospitalPersonInfoList.${index}.personAddress`"
          >
            <el-input
              v-model="item.personAddress"
              placeholder="请输入人员地址"
            />
          </el-form-item>
          <el-form-item
            label="身份证号"
            :rules="rules.hospitalPersonInfoList.cardNo"
            :prop="`hospitalPersonInfoList.${index}.cardNo`"
          >
            <el-input v-model="item.cardNo" placeholder="请输入身份证号" />
          </el-form-item>
          <el-form-item
            label="人员职称"
            :rules="rules.hospitalPersonInfoList.academicTitle"
            :prop="`hospitalPersonInfoList.${index}.academicTitle`"
          >
            <el-select
              v-model="item.academicTitle"
              placeholder="请选择"
              style="width: 200px"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="咨询费用"
            :rules="rules.hospitalPersonInfoList.consultingFee"
            :prop="`hospitalPersonInfoList.${index}.consultingFee`"
          >
            <el-input
              v-model="item.consultingFee"
              placeholder="请输入咨询费用"
            />
          </el-form-item>
          <el-form-item
            label="显示顺序"
            :rules="rules.hospitalPersonInfoList.personSort"
            :prop="`hospitalPersonInfoList.${index}.personSort`"
          >
            <el-input v-model="item.personSort" placeholder="请输入显示顺序" />
          </el-form-item>
          <el-form-item
            label="个人简介"
            :rules="rules.hospitalPersonInfoList.personIntroduce"
            :prop="`hospitalPersonInfoList.${index}.personIntroduce`"
          >
            <editor
              @imgs="imgs"
              :min-height="100"
              v-model="item.personIntroduce"
            ></editor>
          </el-form-item>

          <el-button
            type="primary"
            circle
            plain
            icon="el-icon-circle-plus-outline"
            @click="adddisease"
            v-if="index == 0"
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            plain
            @click="deldisease(index)"
            v-if="index != 0"
          ></el-button>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--新增 选择医院 -->
    <el-dialog
      title="选择医院"
      :visible.sync="innerVisible"
      width="1000px"
      append-to-body
      :before-close="innerVisiblecancel"
    >
      <el-form
        ref="queryForm"
        :model="hospitalqueryParams"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item label="医院编码" prop="hospitalCode" label-width="120">
          <el-input
            v-model="hospitalqueryParams.hospitalCode"
            placeholder="请输入科室编码"
            clearable
          />
        </el-form-item>
        <el-form-item label="医院名称" prop="hospitalName" label-width="120">
          <el-input
            v-model="hospitalqueryParams.hospitalName"
            placeholder="请输入医院名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="info"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="addresetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="infolist"
        @cell-dblclick="nurseclick"
        v-loading="loading"
      >
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              v-if="form.hospitalId == scope.row.id"
              circle
              @click="nurseclick(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="nurseclick(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="hospitalCode"
          label="医院编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="hospitalName"
          label="医院名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>

        <el-table-column
          property="hospitalAddress"
          label="医院地址"
          align="center"
        >
        </el-table-column>
        <!-- <el-table-column
          property="hospitalIntroduce"
          label="医院介绍"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column> -->
        <el-table-column
          property="phone"
          label="联系电话"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total2 > 0"
        :total="total2"
        :page.sync="hospitalqueryParams.pageNum"
        :limit.sync="hospitalqueryParams.pageSize"
        @pagination="info"
      />
    </el-dialog>

    <!-- 选择科室 -->
    <el-dialog
      title="选择科室"
      :visible.sync="innerVisibledepartment"
      width="1000px"
      append-to-body
      :before-close="innerVisiblecanceldepart"
    >
      <el-form
        ref="queryForm"
        :model="departmentqueryParams"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item label="科室编码" prop="departmentCode" label-width="120">
          <el-input
            v-model="departmentqueryParams.departmentCode"
            placeholder="请输入科室编码"
            clearable
          />
        </el-form-item>
        <el-form-item label="科室名称" prop="departmentName" label-width="120">
          <el-input
            v-model="departmentqueryParams.departmentName"
            placeholder="请输入医院名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="departmentList"
            >搜索</el-button
          >
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="departresetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="hospitalDepartmentList"
        @cell-dblclick="nurseclick"
        v-loading="loading"
      >
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              v-if="form.departmentId == scope.row.id"
              circle
              @click="departmentclick(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="departmentclick(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="departmentCode"
          label="科室编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="departmentName"
          label="科室名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>

        <el-table-column
          property="departmentPhone"
          label="科室联系电话"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="departmentAddress"
          label="科室地址"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total3 > 0"
        :total="total3"
        :page.sync="departmentqueryParams.pageNum"
        :limit.sync="departmentqueryParams.pageSize"
        @pagination="departmentList"
      />
    </el-dialog>
    <!-- 修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px" :inline="true">
        <el-form-item label="所属医院" prop="hospitalName">
          <el-button
            type=""
            v-if="form.hospitalName == '请选择所属医院'"
            @click="clickinnerVisiblexg()"
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ foem.hospitalName }}</el-button
          >
          <el-button
            @click="clickinnerVisiblexg()"
            type=""
            v-else
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ form.hospitalName }}</el-button
          >

        </el-form-item>
        <el-form-item label="所属科室" prop="departmentName">
       
          <el-button
            type=""
            v-if="form.departmentName == '请选择所属科室'"
            @click="clickdepartmentlist()"
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ form.departmentName }}</el-button
          >
          <el-button
            @click="clickdepartmentlist()"
            type=""
            v-else
            style="
              width: 250px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ form.departmentName }}</el-button
          >
        </el-form-item>
        <el-form-item label="人员名称" prop="personName">
          <el-input
            v-model="form.personName"
            placeholder="请输入人员名称"
            style="width: 250px"
            maxlength="15"
          />
        </el-form-item>
        <el-form-item label="人员联系电话" prop="personPhone">
          <el-input
            v-model="form.personPhone"
            placeholder="请输入身份证号"
            maxlength="11"
            style="width: 250px"
          />
        </el-form-item>
        <el-form-item label="科室地址" prop="personAddress">
          <el-input
            v-model="form.personAddress"
            placeholder="请输入科室地址"
            style="width: 250px"
          />
        </el-form-item>
       
      
        <el-form-item label="身份证" prop="cardNo">
          <el-input
            v-model="form.cardNo"
            placeholder="请输入身份证号"
            maxlength="18"
            style="width: 250px"
          />
        </el-form-item>
     
        <el-form-item label="人员职称" prop="academicTitle">
          <el-select
            v-model="form.academicTitle"
            placeholder="请选择人员职称"
            style="width: 250px"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="咨询费用" prop="consultingFee">
          <el-input
            v-model="form.consultingFee"
            placeholder="请输入咨询费用"
            style="width: 250px"
          />
        </el-form-item>
        <el-form-item label="显示顺序" prop="personSort">
          <el-input
            v-model="form.personSort"
            placeholder="请输入显示顺序"
            style="width: 250px"
          />
        </el-form-item>
        <el-form-item label="个人简介" prop="personIntroduce">
          <editor
            @imgs="imgs"
            :min-height="100"
            v-model="form.personIntroduce"
          ></editor>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--修改 选择医院 -->
    <el-dialog
      title="选择医院"
      :visible.sync="innerVisiblexg"
      width="1000px"
      append-to-body
      :before-close="innerVisiblecancelxg"
    >
      <el-form
        ref="queryForm"
        :model="hospitalqueryParams"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item label="医院编码" prop="hospitalCode" label-width="120">
          <el-input
            v-model="hospitalqueryParams.hospitalCode"
            placeholder="请输入科室编码"
            clearable
          />
        </el-form-item>
        <el-form-item label="医院名称" prop="hospitalName" label-width="120">
          <el-input
            v-model="hospitalqueryParams.hospitalName"
            placeholder="请输入医院名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="info"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="addresetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="infolist"
        @cell-dblclick="nurseclick"
        v-loading="loading"
      >
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              v-if="form.hospitalId == scope.row.id"
              circle
              @click="nurseclickxg(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="nurseclickxg(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="hospitalCode"
          label="医院编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="hospitalName"
          label="医院名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>

        <el-table-column
          property="hospitalAddress"
          label="医院地址"
          align="center"
        >
        </el-table-column>
        <!-- <el-table-column
          property="hospitalIntroduce"
          label="医院介绍"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column> -->
        <el-table-column
          property="phone"
          label="联系电话"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total2 > 0"
        :total="total2"
        :page.sync="hospitalqueryParams.pageNum"
        :limit.sync="hospitalqueryParams.pageSize"
        @pagination="info"
      />
    </el-dialog>
    <!-- 修改科室 -->
    <el-dialog
      title="选择科室"
      :visible.sync="innerVisibledepartmentxg"
      width="1000px"
      append-to-body
      :before-close="innerVisiblecanceldepartxg"
    >
      <el-form
        ref="queryForm"
        :model="departmentqueryParams"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <el-form-item label="科室编码" prop="departmentCode" label-width="120">
          <el-input
            v-model="departmentqueryParams.departmentCode"
            placeholder="请输入科室编码"
            clearable
          />
        </el-form-item>
        <el-form-item label="科室名称" prop="departmentName" label-width="120">
          <el-input
            v-model="departmentqueryParams.departmentName"
            placeholder="请输入医院名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="departmentList"
            >搜索</el-button
          >
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="departresetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="hospitalDepartmentList"
        @cell-dblclick="nurseclick"
        v-loading="loading"
      >
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              v-if="form.departmentId == scope.row.id"
              circle
              @click="departmentclickxg(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="departmentclickxg(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="departmentCode"
          label="科室编码"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="departmentName"
          label="科室名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>

        <el-table-column
          property="departmentPhone"
          label="科室联系电话"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="departmentAddress"
          label="科室地址"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total3 > 0"
        :total="total3"
        :page.sync="departmentqueryParams.pageNum"
        :limit.sync="departmentqueryParams.pageSize"
        @pagination="departmentList"
      />
    </el-dialog>
  </div>
</template>

<script>
import {
  list,
  listHospitalPerson,
  getHospitalPerson,
  delHospitalPerson,
  addHospitalPerson,
  listHospitalDepartment,
  updateHospitalPerson,
} from "@/api/system/hospitalPerson";
import editor from "@/components/Editor";
export default {
  components: { editor },
  name: "HospitalPerson",
  data() {
    //验证身份证
    var isCardId = (rule, value, callback) => {
      if (!value) {
        return new Error("请输入身份证号)");
      } else {
        const reg =
          /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(([0-2][1-9])|10|20|30|31)\d{3}(\d|X|x)$/;
        const card = reg.test(value);
        if (!card) {
          callback(new Error("身份证号格式有误！"));
        } else {
          callback();
        }
      }
    };
    // 验证手机号的规则
    // var checkMobile = (rule, value, cb) => {
    //   // 验证手机号的正则表达式
    //   const regMobile =
    //     // /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57]|19[0-9])[0-9]{8}$/;
    //     // /^((0\\d{2,3}(-)?\\d{7,8})|((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[2567]{1})(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\\d{8})$/;
    //     /^((0\d{2,3}(-)?\d{7,8})|(13[0-9]|14[0-9]|15[0-9]|16[2567]|17[0-9]|18[0-9]|19[0-9])+\d{8})$/;

    //   if (regMobile.test(value)) {
    //     return cb();
    //   }
    //   cb(new Error("请输入正确的联系电话"));
    // };
    return {
      // 遮罩层
      loading: true,
      nnerVisibleindex: "",
      departmentListindex: "",
      total2: 0,
      total3: 0,
      innerVisible: false,
      innerVisibledepartment: false,
      innerVisibledepartmentxg: false,
      innerVisiblexg: false,
      imgsurl: { pictureUrlList: [] },
      options: [
        {
          value: "CHIEF_PHYSICIAN",
          label: "主任医师",
        },
        {
          value: "DEPUTY_CHIEF_PHYSICIAN",
          label: "副主任医师",
        },
        {
          value: "PHYSICIAN",
          label: "医师",
        },
        {
          value: "HEALER",
          label: "医士",
        },

        {
          value: "ATTENDING_DOCTOR",
          label: "主治医师",
        },
      ],
      value: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 健康咨询-科室人员信息表格数据
      hospitalPersonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      addopen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hospitalId: null,
        departmentId: null,
        personCode: null,
        personName: null,
        personPhone: null,
        personAddress: null,
        cardNo: null,
        academicTitle: null,
        consultingFee: null,
        personIntroduce: null,
        personSort: null,
      },
      // 表单参数
      form: {},
      hospitalDepartmentList: [],
      hospitalqueryParams: {
        pageNum: 1,
        pageSize: 10,
        hospitalCode: "",
        hospitalName: "",
      },
      departmentqueryParams: {
        pageNum: 1,
        pageSize: 10,
        departmentCode: "",
        departmentName: "",
      },
      infolist: [],
      // 表单校验
      rules: {
        hospitalPersonInfoList: {
          hospitalId: [
            {
              required: true,
              message: "请选择所属医院",
              trigger: "blur",
            },
          ],
          departmentId: [
            {
              required: true,
              message: "请选择所属科室",
              trigger: "blur",
            },
          ],
          personName: [
            {
              required: true,
              message: "请选择科室人员名称",
              trigger: "blur",
            },
          ],
          personAddress: [
            {
              required: true,
              message: "请选择科室人员地址",
              trigger: "blur",
            },
          ],
          academicTitle: [
            {
              required: true,
              message: "请选择人员职称",
              trigger: "blur",
            },
          ],
          personIntroduce: [
            {
              required: true,

              trigger: "blur",
              message: "请选择个人简介",
            },
          ],
          personSort: [
            {
              required: true,
              message: "请选择排序",
              trigger: "blur",
            },
          ],
          personPhone: [
            {
              required: true,
              // validator: checkMobile,
              message: "请输入联系电话",
              trigger: "blur",
            },
          ],
          cardNo: [
            {
              required: true,
              message: "",
              validator: isCardId,
              trigger: "blur",
            },
          ],

          consultingFee: [
            {
              required: true,
              message: "请选择咨询费用",
              trigger: "blur",
            },
          ],
        },
        hospitalId: [
          {
            required: true,
            message: "请选择所属医院",
            trigger: "blur",
          },
        ],
        departmentId: [
          {
            required: true,
            message: "请选择所属科室",
            trigger: "blur",
          },
        ],
        personName: [
          {
            required: true,
            message: "请选择科室人员名称",
            trigger: "blur",
          },
        ],
        personAddress: [
          {
            required: true,
            message: "请选择科室人员地址",
            trigger: "blur",
          },
        ],
        academicTitle: [
          {
            required: true,
            message: "请选择人员职称",
            trigger: "blur",
          },
        ],
        personIntroduce: [
          {
            required: true,

            trigger: "blur",
            message: "请选择个人简介",
          },
        ],
        personSort: [
          {
            required: true,
            message: "请选择排序",
            trigger: "blur",
          },
        ],
        personPhone: [
          {
            required: true,
            // validator: checkMobile,
            message: "11",
            trigger: "blur",
          },
        ],
        cardNo: [
          {
            required: true,
            message: "",
            validator: isCardId,
            trigger: "blur",
          },
        ],

        consultingFee: [
          {
            required: true,
            message: "请选择咨询费用",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.info();
  },
  methods: {
    imgs(item) {
      console.log(item);
      this.imgsurl.pictureUrlList.push(item);
    },

    nurseclick(row) {
      console.log(row);
      this.form.hospitalPersonInfoList[this.nnerVisibleindex].hospitalName =
        row.hospitalName;
      this.form.hospitalPersonInfoList[this.nnerVisibleindex].hospitalId =
        row.id;
      this.innerVisible = false;
    },
    nurseclickxg(row) {
      console.log(row);
      this.form.hospitalName = row.hospitalName;
      this.form.hospitalId = row.id;
      this.innerVisiblexg = false;
    },
    // 科室
    departmentclick(row) {
      console.log(row);
      this.form.hospitalPersonInfoList[
        this.departmentListindex
      ].departmentName = row.departmentName;
      this.form.hospitalPersonInfoList[this.departmentListindex].departmentId =
        row.id;
      // }
      this.innerVisibledepartment = false;
    },
    departmentclickxg(row) {
      console.log(row);
      this.form.departmentName = row.departmentName;
      this.form.departmentId = row.id;
      // }
      this.innerVisibledepartmentxg = false;
    },
//医院关闭
    innerVisiblecancel() {
      this.innerVisible = false;
    },
  
    innerVisiblecancelxg() {
      this.innerVisiblexg = false;
    },
    //科室关闭
    innerVisiblecanceldepart() {
      this.innerVisibledepartment = false;
    },
    innerVisiblecanceldepartxg() {
      this.innerVisibledepartmentxg = false;
    },
    //删除deldisease
    deldisease(index) {
      this.form.hospitalPersonInfoList.splice(index, 1);
    },
    adddisease() {
      var obj = {
        hospitalId: "",
        departmentCode: "",
        departmentId: "",
        departmentName: "请选择所属科室",
        departmentPerson: "",
        departmentPhone: "",
        hospitalName: "请选择所属医院",
      };
      if (this.form.hospitalPersonInfoList.length == 5) {
        this.$message.error("最多只能5条");
      } else {
        this.form.hospitalPersonInfoList.push(obj);
      }
    },
    /** 查询健康咨询-科室人员信息列表 */
    getList() {
      this.loading = true;
      listHospitalPerson(this.queryParams).then((response) => {
        this.hospitalPersonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 新增医院按钮
    clickinnerVisible(item, index) {
      // this.addresetQuery();
      this.form.hospitalId = item.hospitalId;
      this.nnerVisibleindex = index;
      console.log(this.nnerVisibleindex);
      this.innerVisible = true;
      // this.homenumber = item;
    },
    // 修改医院按钮
    clickinnerVisiblexg(item) {
      this.addresetQuery();
      // this.form.hospitalId = item.hospitalId;
      // this.nnerVisibleindex = index;
      // console.log(this.nnerVisibleindex);
      this.innerVisiblexg = true;
      // this.homenumber = item;
    },
    //新增科室按钮
    clicklist(item, index) {
      this.departmentList();
      this.form.departmentId = item.departmentId;
      this.departmentListindex = index;
      console.log(this.departmentListindex);
      this.innerVisibledepartment = true;
    },
    // 修改科室按钮
    clickdepartmentlist(){
      this.departmentList();
      // this.form.departmentId = item.departmentId;
      this.innerVisibledepartmentxg = true;
    },
    departmentList() {
      // this.loading = true;
      listHospitalDepartment(this.departmentqueryParams).then((response) => {
        this.hospitalDepartmentList = response.rows;
        this.total3 = response.total;
        this.loading = false;
      });
    },
    //修改医院按钮
    addresetQuery() {
      this.hospitalqueryParams = {
        pageNum: 1,
        pageSize: 10,
        hospitalCode: "",
        hospitalName: "",
      };
      this.info();
    },
    departresetQuery() {
      this.departmentqueryParams = {
        pageNum: 1,
        pageSize: 10,
        departmentCode: "",
        departmentName: "",
      };
      this.departmentList();
    },
    info() {
      list(this.hospitalqueryParams).then((response) => {
        this.infolist = response.rows;
        console.log(this.infolist);
        this.total2 = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.addopen = false;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        hospitalPersonInfoList: [
          {
            id: null,
            hospitalId: null,
            departmentId: null,
            personCode: null,
            personName: null,
            personPhone: null,
            personAddress: null,
            cardNo: null,
            academicTitle: null,
            consultingFee: null,
            personIntroduce: null,
            personSort: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            hospitalName: "请选择所属医院",
            departmentName: "请选择所属科室",
          },
        ],
      };

      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.addopen = true;
      this.title = "添加健康咨询-科室人员信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getHospitalPerson(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改健康咨询-科室人员信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      // if (this.form.id == null) {
      //           this.form.departmentName = this.form.hospitalPersonInfoList[0].departmentName
      //           this.form.personName = this.form.hospitalPersonInfoList[0].personName
      //           this.form.personPhone = this.form.hospitalPersonInfoList[0].personPhone
      //           this.form.personAddress = this.form.hospitalPersonInfoList[0].personAddress
      //           this.form.cardNo = this.form.hospitalPersonInfoList[0].cardNo
      //           this.form.academicTitle = this.form.hospitalPersonInfoList[0].academicTitle
      //           this.form.consultingFee = this.form.hospitalPersonInfoList[0].consultingFee
      //       }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateHospitalPerson(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHospitalPerson(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.addopen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm(
          '是否确认删除健康咨询-科室人员信息编号为"' + ids + '"的数据项？'
        )
        .then(function () {
          return delHospitalPerson(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/hospitalPerson/export",
        {
          ...this.queryParams,
        },
        `hospitalPerson_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
