<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" size="small">
      <el-form-item label="医生姓名" prop="doctorName">
        <el-input
          v-model="queryParams.doctorName"
          placeholder="请输入医生姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="所属医院" prop="hospitalId" >
      <el-select v-model="queryParams.hospitalId" placeholder="请选择所属医院" filterable size="small">
            <el-option v-for="(option, index) in hospitalList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>
       </el-select>
      </el-form-item>
      <el-form-item label="科室" prop="deptId">
       <el-select v-model="queryParams.deptId" placeholder="请选择所属科室" size="small">
         <el-option
             v-for="dict in depList"
             :key="dict.dictValue"
             :label="dict.dictLabel"
             :value="dict.dictValue"
           />
         </el-select>
      </el-form-item>
      <el-form-item label="职称" prop="position">
       <el-select v-model="queryParams.position" placeholder="职称" clearable size="small">
            <el-option
              v-for="dict in positionOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
         <el-select v-model="queryParams.status" placeholder="状态" clearable size="small">
              <el-option
                v-for="dict in statusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
      </el-form-item>


      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="性别" clearable size="small">
             <el-option
               v-for="dict in sexOptions"
               :key="dict.dictValue"
               :label="dict.dictLabel"
               :value="dict.dictValue"
             />
           </el-select>
      </el-form-item>


      <el-form-item label="接诊状态" prop="workStatus">
      <el-select v-model="queryParams.workStatus" placeholder="接诊状态" clearable size="small">
           <el-option
             v-for="dict in statusOptions"
             :key="dict.dictValue"
             :label="dict.dictLabel"
             :value="dict.dictValue"
           />
         </el-select>
      </el-form-item>

       <el-form-item label="创建时间" prop="createTime">
                 <el-date-picker v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
              </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="['his:doctor: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="['his:doctor: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="['his:doctor:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['his:doctor:export']"
        >导出</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleUpdateFollow"
          v-hasPermi="['his:doctor:code']"
        >随访转移</el-button>
      </el-col> -->
     <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="wxCode"
          v-hasPermi="['his:doctor:code']"
        >邀请医生二维码</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
      <el-tabs type="card" v-model="queryParams.isAudit" @tab-click="handleClickX">
      <el-tab-pane v-for="(item,index) in isauditOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>
    <el-table height="550" v-loading="loading" border :data="doctorList" @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="医生姓名" align="center" prop="doctorName" />
      <el-table-column label="擅长领域" align="center" prop="speciality"  show-overflow-tooltip />
      <!-- <el-table-column label="所属用户" align="center" width="150px">
       <template slot-scope="scope">
         <div v-if="scope.row.nickName!=null"> {{scope.row.nickName}}-{{scope.row.phone}}</div>
       </template>
      </el-table-column> -->
      <el-table-column label="所属医院" align="center" prop="hospitalName" width="200px"/>
      <el-table-column label="科室" align="center" prop="deptName" />
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="职称" align="center" prop="position" width="100px">
        <template slot-scope="scope">
          <dict-tag :options="positionOptions" :value="scope.row.position"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <dict-tag :options="statusOptions" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="评分" align="center" prop="pingStar" />
      <el-table-column label="咨询量" align="center" prop="orderNumber" />
      <el-table-column label="响应速度" align="center" prop="speed" />
      <el-table-column label="手机号" align="center" prop="mobile" width="120px"/>
      <el-table-column label="性别" align="center" prop="sex" >
        <template slot-scope="scope">
          <dict-tag :options="sexOptions" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="出生年月" align="center" prop="bitthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bitthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="登录账号" align="center" prop="account" width="170px"/>
      <el-table-column label="是否推荐" align="center" prop="isTui">
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.isTui"/>
        </template>
      </el-table-column>
      <el-table-column label="是否专家" align="center" prop="isExpert" >
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.isExpert"/>
        </template>
      </el-table-column>
      <el-table-column label="接诊状态" align="center" prop="workStatus" >
        <template slot-scope="scope">
          <dict-tag :options="statusOptions" :value="scope.row.workStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="isAudit" >
        <template slot-scope="scope">
          <dict-tag :options="isauditOptions" :value="scope.row.isAudit"/>
        </template>
      </el-table-column>
      <el-table-column label="是否可抢单" align="center" prop="isAccept" >
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.isAccept"/>
        </template>
        </el-table-column>
        <el-table-column label="是否自营" align="center" prop="isSelf" >
          <template slot-scope="scope">
            <dict-tag :options="orOptions" :value="scope.row.isSelf"/>
          </template>
      </el-table-column>
         <el-table-column label="备注" align="center" prop="remark"  show-overflow-tooltip/>
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180"/>
       <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="170px" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['his:doctor:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handledetai(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['his:doctor:remove']"
          >删除</el-button>
          <el-button v-if="scope.row.isAudit==0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="docetrUpdate(scope.row)"
            v-hasPermi="['his:doctor:audit']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['his:doctor:resetpwd']"
            @click="editPass(scope.row)"
          >重置密码</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
             v-hasPermi="['his:doctor:inquiry']"
            @click="editDoctorPrice(scope.row)"
          >问诊配置</el-button>
          <el-button
            size="mini"
            type="text"
             v-hasPermi="['his:doctor:inquiry']"
            @click="doctorInquiry(scope.row)"
          >常用处方</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="open" width="950px" append-to-body >
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">

        <el-row>
              <el-col :span="12">
                <el-form-item label="医生姓名" prop="doctorName">
                  <el-input v-model="form.doctorName" placeholder="请输入医生姓名" />
                </el-form-item></el-col>
              <el-col :span="12">
                  <el-form-item label="所属医院" prop="hospitalId">
                    <el-select v-model="form.hospitalId" placeholder="请选择所属医院" clearable size="small" filterable>
                         <el-option
                           v-for="dict in hospitalList"
                           :key="dict.dictValue"
                           :label="dict.dictLabel"
                           :value="dict.dictValue"
                         />
                       </el-select>
                  </el-form-item>
              </el-col>
        </el-row>
        <el-row>
              <el-col :span="12">
                <el-form-item label="科室" prop="deptId">
                <el-select v-model="form.deptId"  placeholder="请选择所属科室">
                      <el-option
                          v-for="dict in depList"
                          :key="dict.dictValue"
                          :label="dict.dictLabel"
                          :value="dict.dictValue"
                        />
                      </el-select>

                 </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="职称" prop="position">
                       <el-select v-model="form.position" placeholder="职称" clearable size="small">
                            <el-option
                              v-for="dict in positionOptions"
                              :key="dict.dictValue"
                              :label="dict.dictLabel"
                              :value="dict.dictValue"
                            />
                          </el-select>
                  </el-form-item>
              </el-col>
        </el-row>

        <el-row>
              <el-col :span="12">
                <el-form-item label="所属用户" prop="userId">
                  <el-select v-model="form.userId" filterable placeholder="请选择"  :filter-method="remoteMethod">
                    <el-option
                      v-for="item in userList"
                      :key="item.name"
                      :label="item.name"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="性别" prop="sex">
                <el-radio-group v-model="form.sex">
                         <el-radio :label="item.dictValue" v-for="item in sexOptions" >{{item.dictLabel}}</el-radio>
                </el-radio-group>
              </el-form-item>
              </el-col>
        </el-row>
        <el-row>
              <el-col :span="12">
                <el-form-item label="出生年月" prop="bitthday">
                  <el-date-picker clearable size="small"
                    v-model="form.bitthday"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择出生年月">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="所属省市区" prop="cityIds">
               <el-cascader
                         ref="citySelect"
                         v-model="form.cityIds"
                         :options="citys"
                         @change="handleCityChange">
                         </el-cascader>
               </el-form-item>
                </el-col>
        </el-row>
        <el-row>
              <el-col :span="12">
                <el-form-item label="标签" prop="tags">
                  <el-input v-model="form.tags" placeholder="请输入标签" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="手机号" prop="mobile">
                    <el-input v-model="form.mobile" placeholder="请输入手机号" />
                  </el-form-item>
              </el-col>
        </el-row>
        <el-form-item label="排序" prop="sort" >
          <el-input-number v-model="form.sort"   label="排序"></el-input-number>
        </el-form-item>

        <el-form-item label="简介" prop="introduction">
          <el-input type="textarea" :rows="4" v-model="form.introduction" placeholder="请输入简介" maxlength="200"/>
        </el-form-item>
        <el-form-item label="擅长领域" prop="speciality">
          <el-input  type="textarea" :rows="4" v-model="form.speciality" placeholder="请输入擅长领域" maxlength="400" />
        </el-form-item>
        <el-form-item label="备注" prop="remark" >
          <el-input type="textarea" :rows="4" v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="是否处方医生" prop="isPrescribeDoctor" >
          <el-radio-group v-model="form.isPrescribeDoctor">
                   <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
          </el-radio-group>

        </el-form-item>
        <el-form-item label="处方医生" prop="prescribeDoctorId" v-if="form.isPrescribeDoctor==0">
          <el-select v-model="form.prescribeDoctorId" filterable placeholder="输入名称搜索" :filter-method="doctorMethod">
            <el-option
              v-for="item in docuser"
              :key="item.name"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-row>
              <el-col :span="12">
                  <el-form-item label="资格证编号" prop="certificateCode" >
                    <el-input v-model="form.certificateCode" placeholder="请输入资格证编号" maxlength="200"/>
                  </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="执业证编号" prop="practiseCode" >
                    <el-input v-model="form.practiseCode" placeholder="请输入资格证编号" maxlength="200"/>
                  </el-form-item>
              </el-col>
        </el-row>
           <el-form-item label="资格证" prop="certificateImages">
             <ImageUpload v-model="form.certificateImages" type="image" :num="10" :width="150" :height="150" />
           </el-form-item>
           <el-form-item label="执业证" prop="practiseImages">
             <ImageUpload v-model="form.practiseImages" type="image" :num="10" :width="150" :height="150" />
           </el-form-item>
            <el-row>
                  <el-col :span="12">
                    <el-form-item label="身份证号" prop="idCard">
                      <el-input v-model="form.idCard" placeholder="请输入身份证号" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="咨询量" prop="orderNumber">
                        <el-input-number v-model="form.orderNumber"  :min="0"  label="咨询量"></el-input-number>
                      </el-form-item>
                  </el-col>
            </el-row>
            <el-row>
                  <el-col :span="12">
                      <el-form-item label="身份证正面" prop="idCardFrontUrl">
                         <el-upload id="sf"
                            v-model="form.idCardFrontUrl"
                            class="avatar-uploader"
                            :action="fruploadUrl"
                            :show-file-list="false"
                            :on-success="frhandleAvatarSuccess"
                            :before-upload="beforeAvatarUpload">
                            <img v-if="form.idCardFrontUrl" :src="form.idCardFrontUrl" class="avatar" width="150px">
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                        <el-form-item label="工作照" prop="avatar">
                           <el-upload
                              v-model="form.avatar"
                              class="avatar-uploader"
                              :action="avataruploadUrl"
                              :show-file-list="false"
                              :on-success="avatarhandleAvatarSuccess"
                              :before-upload="beforeAvatarUpload">
                              <img v-if="form.avatar" :src="form.avatar" class="avatar" width="150px" >
                              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                          </el-upload>
                        </el-form-item>
                  </el-col>
            </el-row>
            <el-row>
                  <el-col :span="12">
                      <el-form-item label="身份证反面" prop="idCardBackUrl">
                        <el-upload id="sf"
                         v-model="form.idCardBackUrl"
                         class="avatar-uploader"
                         :action="bauploadUrl"
                         :show-file-list="false"
                         :on-success="bahandleAvatarSuccess"
                         :before-upload="beforeAvatarUpload">
                         <img v-if="form.idCardBackUrl" :src="form.idCardBackUrl" class="avatar" width="150px">
                         <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="医生签名" prop="signUrl">
                        <el-upload id="sign"
                         v-model="form.signUrl"
                         class="avatar-uploader"
                         :action="bauploadUrl"
                         :show-file-list="false"
                         :on-success="signhandleAvatarSuccess"
                         :before-upload="beforeAvatarUpload">
                         <img v-if="form.signUrl" :src="form.signUrl" class="avatar" width="150px">
                         <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                      </el-form-item>
                  </el-col>
            </el-row>

        <el-row>
              <el-col :span="12">
                <el-form-item label="状态"  prop="status">
                     <el-radio-group v-model="form.status">
                              <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
                     </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="接诊状态" prop="workStatus">
                  <el-radio-group v-model="form.workStatus">
                           <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
                  </el-radio-group>
                  </el-form-item>
              </el-col>
         </el-row>
         <el-row>
               <el-col :span="12">
                 <el-form-item label="是否推荐" prop="isTui">
                      <el-radio-group v-model="form.isTui">
                               <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
                      </el-radio-group>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
                  <el-form-item label="是否专家" prop="isExpert">
                       <el-radio-group v-model="form.isExpert">
                                <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
                       </el-radio-group>
                  </el-form-item>
               </el-col>
          </el-row>
          <el-row>
               <el-col :span="12">
                 <el-form-item label="是否可抢单" prop="isAccept">
                      <el-radio-group v-model="form.isAccept">
                               <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
                      </el-radio-group>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
                <el-form-item label="是否自营" prop="isSelf">
                     <el-radio-group v-model="form.isSelf">
                              <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
                     </el-radio-group>
                </el-form-item>
               </el-col>
          </el-row>
          <el-row>
               <el-col :span="12">
                 <el-form-item label="是否展示" prop="isShow">
                      <el-radio-group v-model="form.isShow">
                               <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
                      </el-radio-group>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
                <el-form-item label="协定方医生" prop="isAgreementPrescribeDoctor">
                     <el-radio-group v-model="form.isAgreementPrescribeDoctor">
                        <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
                     </el-radio-group>
                </el-form-item>
               </el-col>
          </el-row>
          <el-row>
               <el-col :span="12">
                 <el-form-item label="是否随访" prop="isFollow">
                      <el-radio-group v-model="form.isFollow">
                          <el-radio :label="parseInt(item.dictValue)" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
                      </el-radio-group>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
				<el-form-item label="所属店铺" prop="storeIds">
				  <el-select v-model="form.storeIds" placeholder="状态" clearable size="small"  remote multiple filterable>
				          <el-option
				            v-for="dict in storeOPtions"
				            :key="dict.dictValue"
				            :label="dict.dictLabel"
				            :value="dict.dictValue"
				          />
				        </el-select>
				</el-form-item>
               </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="套餐包" prop="packageIds">
                 <el-select v-model="form.packageIds" multiple placeholder="请选择套餐包" style="width: 300px;">
                   <el-option
                     v-for="item in packageList"
                     :key="item.dictValue"
                     :label="item.dictLabel"
                     :value="item.dictValue"
                   ></el-option>
                 </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="平均响应速度" prop="speed" >
                <el-input-number v-model="form.speed"  :min="0" label="平均响应速度"></el-input-number>
              </el-form-item>
            </el-col>
           </el-row>
        <el-row>
               <el-col :span="12">
                 <el-form-item label="咨询量" prop="orderNumber">
                   <el-input-number v-model="form.orderNumber"  :min="0" label="咨询量"></el-input-number>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
                 <el-form-item label="评分" prop="pingStar" >
                   <el-rate v-model="form.pingStar"></el-rate>
                 </el-form-item>
               </el-col>
         </el-row>
         <el-row>
               <el-col :span="12">
                 <el-form-item label="绑定ai" prop="aiRoleId">
                  <el-select v-model="form.gptRoleId" placeholder="请选择">
                  <el-option
                    v-for="item in aiOption"
                    :key="item.roleId"
                    :label="item.roleName"
                    :value="item.roleId">
                  </el-option>
                </el-select>
              </el-form-item>
               </el-col>

         </el-row>

         <el-row>
               <el-col :span="12">
                 <el-form-item label="登录账号" prop="account" >
                   <el-input v-model="form.account" placeholder="请输入账号名称" />
                 </el-form-item>
               </el-col>
               <el-col :span="12">
                 <el-form-item label="登录密码" prop="password" v-if="form.doctorId==null||form.doctorId==''">
                   <el-input v-model="form.password" placeholder="输入登录密码" />
                 </el-form-item>
               </el-col>
          </el-row>
      </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="title" :visible.sync="open2" width="600px" append-to-body >
      <el-form ref="form2" :model="form2"  label-width="100px">
        <el-form-item label="接诊开关" >
          <el-switch  v-model="form2.status" ></el-switch>
        </el-form-item>
        <el-form-item label="图文价格" >
           <el-input-number v-model="form2.price1" :precision="2" :step="0.1" :min="0"></el-input-number>
        </el-form-item>
        <el-form-item label="视频问诊价格" >
           <el-input-number v-model="form2.price2" :precision="2" :step="0.1" :min="0"></el-input-number>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="priceSubmitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="随访继承" :visible.sync="updateFollowOpen" width="800px" append-to-body @close="cancel">
         <el-form ref="form" :model="editFollowForm" :rules="rules" label-width="100px">
           <el-form-item label="需转移医生" prop="followDoctorIds"  >
              <el-select v-model="editFollowForm.fromId" placeholder="请选择随访医生" style="width: 300px;" filterable>
                <el-option
                  v-for="item in followDoctorList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
           </el-form-item>
           <el-form-item label="目标医生" prop="followDoctorIds" filterable >
              <el-select v-model="editFollowForm.toId"  placeholder="请选择随访医生" style="width: 300px;" filterable>
                <el-option
                  v-for="item in followDoctorList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
           </el-form-item>
         </el-form>
         <div slot="footer" class="dialog-footer" >
           <el-button type="primary" @click="editFollowSubmitForm">提交</el-button>
           <el-button @click="editFollowCancel">取消</el-button>
         </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="open3" width="800px" append-to-body @close="cancel">
         <el-form ref="form" :model="editForm" :rules="rules" label-width="100px">
           <el-form-item label="审核" prop="isAudit">
            <el-radio-group v-model="editForm.isAudit">
                <el-radio :label="item.dictValue" v-for="item in editRadio" >{{item.dictLabel}}</el-radio>
            </el-radio-group>
           </el-form-item>
           <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="editForm.remark" placeholder="备注" />
           </el-form-item>
         </el-form>
         <div slot="footer" class="dialog-footer" >
           <el-button type="primary" @click="editSubmitForm">提交</el-button>
           <el-button @click="cancel">取消</el-button>
         </div>
    </el-dialog>
       <el-drawer
            :with-header="false"
            size="75%"
            :title="show.title" :visible.sync="inquiryOpen">
        <doctorinquiryDetails  ref="doctorinquiryDetails" />
       </el-drawer>
    <el-drawer
      :with-header="false"
      size="75%"
      :visible.sync="show.open">
      <doctorDetails  ref="doctorDetails" />
    </el-drawer>
  </div>
</template>
<script>
import {editFollow,getAllFollowDoctorList,getUserList, listDoctor, getWxaCodeUnLimit,getDoctor, listdocuser,delDoctor, addDoctor, updateDoctor, exportDoctor ,updateAuditDoctor,getDoctorPrice,editDoctorPrice,editPassWord,editPrice} from "@/api/his/doctor";
import{listDepartment} from "@/api/his/disease";
import{listAllHospital} from "@/api/his/hospital";
import {getCitys} from "@/api/store/city";
import {getAllAiRoleList} from "@/api/chat/chatRole"
import { allPackage, } from "@/api/his/package";
import doctorinquiryDetails from '../../components/his/doctorinquiryDetails.vue';
import doctorDetails from '../../components/his/doctorDetails.vue';
import { Form } from "element-ui";
import ImageUpload from '@/components/ImageUpload'
import { listStore } from "@/api/his/storeProduct";
export default {
  name: "Doctor",
  components: { doctorDetails,doctorinquiryDetails,ImageUpload },
  data() {
    return {
      doctorName: {name:"1"},
      docuser:[],
      updateFollowOpen:false,
      editFollowForm:{
        fromId:null,
        toId:null,
      },
      followDoctorList:[],
      //身份证
      fruploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      bauploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      //头像
      avataruploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      certificateBack:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      practise:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      practiseBack:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      baseUrl: process.env.VUE_APP_BASE_API,
      orOptions: [],
	  storeOPtions: [],
      isauditOptions: [],
      positionOptions: [],
      statusOptions: [],
      sexOptions: [],
      editRadio: [{
              "dictLabel": "通过",
              "dictValue": 1
            }, {
              "dictLabel": "驳回",
              "dictValue": -1
      }],
      //科室列表
      depList:[],
      userName: {name:"1"},
      userList:[],
      //医院列表
      hospitalList:[],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      show:{
              title:"医生详情",
              open:false,
            },
      inquiryOpen:false,
      citys:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医生管理表格数据
      doctorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      open3: false,
      form2:{
        doctorId:null,
        price1:1,
        price2:1,
        status:false
      },
      packageList:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        doctorName: null,
        introduction: null,
        speciality: null,
        certificateCode: null,
        certificateImages: null,
        avatar: null,
        userId: null,
        hospitalId: null,
        deptId: null,
        balance: null,
        position: null,
        tags: null,
        status: null,
        pingStar: null,
        orderNumber: null,
        speed: null,
        mobile: null,
        doctorType: 1,
        sex: null,
        bitthday: null,
        idCard: null,
        idCardFrontUrl: null,
        idCardBackUrl: null,
        cityIds: null,
        province: null,
        city: null,
        district: null,
        isTui: null,
        isExpert: null,
        workStatus: null,
        isAudit: "0",
        auditTime: null,
        sTime:null,
        eTime:null,
      },
        createTime:null,
      // 表单参数
      form: {},
      aiOption:{},
      editForm:{
        doctorId:null,
        isAudit:1,
        remark:null,
      },
      // 表单校验
      rules: {
        doctorName: [
          { required: true, message: "医生姓名不能为空", trigger: "blur" }
        ],
        introduction: [
          { required: true, message: "简介不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        isTui: [
          { required: true, message: "是否推荐不能为空", trigger: "blur" }
        ],
        isExpert: [
          { required: true, message: "是否专家不能为空", trigger: "blur" }
        ],
        workStatus: [
          { required: true, message: "接诊状态不能为空", trigger: "blur" }
        ],
        isAudit: [
          { required: true, message: "是否审核不能为空", trigger: "blur" }
        ],
        hospitalId: [
          { required: true, message: "所属医院不能为空", trigger: "blur" }
        ],
        cityIds: [
          { required: true, message: "省市区不能为空", trigger: "blur" }
        ],
        account: [
          { required: true, message: "登录账号不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        isAudit: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        isAccept: [
          { required: true, message: "是否可抢单不能为空", trigger: "blur" }
        ],
        isSelf: [
          { required: true, message: "是否自营不能为空", trigger: "blur" }
        ],
        isPrescribeDoctor: [
          { required: true, message: "是否处方医生不能为空", trigger: "blur" }
        ],
        prescribeDoctorId: [
          { required: true, message: "处方医生id不能为空", trigger: "blur" }
        ],
        isShow: [
          { required: true, message: "是否展示不能为空", trigger: "blur" }
        ],
        isAgreementPrescribeDoctor: [
          { required: true, message: "是否协定处方医生不能为空", trigger: "blur" }
        ],

      }
    };
  },
  created() {
    this.getCitys();
    this.getPackageList();
    this.getList();
    this.getUserList();
    this.getDicts("sys_company_isaudit").then(response => {
      this.isauditOptions = response.data;
    });
    this.getDicts("sys_company_or").then(response => {
      this.orOptions = response.data;
    });
    this.getDicts("sys_doc_position").then(response => {
      this.positionOptions = response.data;
    });
    this.getDicts("sys_company_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getdeplist();
    listStore().then(response => {
      this.storeOPtions = response.rows;
    });
    this.getHospitaldeplist();
    getAllFollowDoctorList().then(response => {

           this.followDoctorList=response.rows;
       });
      this.getAllAiRoleList();
  },
  methods: {
     getlistdocuser(){
         listdocuser(this.doctorName).then(response => {
           this.docuser=response.rows;
       });
     },
     handleUpdateFollow(){
       this.editFollowForm={
        fromId:null,
        toId:null,
      },
       this.updateFollowOpen=true;
     },
     editFollowSubmitForm(){
        editFollow(this.editFollowForm).then(response => {
           if(response.code==200){
            this.msgSuccess("转移成功");
            this.updateFollowOpen=false;
           }
           else{
             this.msgError(res.msg);
           }
       });
     },
     editFollowCancel(){
       this.updateFollowOpen=false;
     },

     doctorMethod(rows){
       this.doctorName.name=rows;
       this.getlistdocuser();
     },
     saveImg(base64) {
          var byteCharacters = atob(
            base64.replace(/^data:image\/(png|jpeg|jpg);base64,/, "")
          );
          var byteNumbers = new Array(byteCharacters.length);
          for (var i = 0; i < byteCharacters.length; i++) {
            byteNumbers[i] = byteCharacters.charCodeAt(i);
          }
          var byteArray = new Uint8Array(byteNumbers);
          var blob = new Blob([byteArray], {
            type: undefined,
          });
          var aLink = document.createElement("a");
          aLink.download = "医生注册二维码.jpg"; //这里写保存时的图片名称
          aLink.href = URL.createObjectURL(blob);
          aLink.click();
    },
    wxCode(){
      getWxaCodeUnLimit().then(response => {
        this.saveImg(response.data)
      });
    },
    change(){
          if(this.createTime!=null){
            this.queryParams.sTime=this.createTime[0];
            this.queryParams.eTime=this.createTime[1];
          }else{
            this.queryParams.sTime=null;
            this.queryParams.eTime=null;
          }

        },
    doctorInquiry(row){
        this.inquiryOpen=true;
        setTimeout(() => {
             this.$refs.doctorinquiryDetails.getDetails(row.doctorId);
        }, 1);
    },
    remoteMethod(rows){
      this.userName.name=rows;
      getUserList(this.userName).then(response => {
        this.userList=response.rows;
      });
    },
    handleCityChange(value) {
      var nodes=this.$refs.citySelect.getCheckedNodes();
      this.form.cityIds=value.toString();
      this.form.province=nodes[0].pathLabels[0];
      this.form.city=nodes[0].pathLabels[1];
      this.form.district=nodes[0].pathLabels[2];
    },

    handledetai(row){
        this.show.open=true;
        setTimeout(() => {
             this.$refs.doctorDetails.getDetails(row.doctorId);
        }, 1);

    },
    getCitys(){
        getCitys().then(res => {
          this.loading = false;
          this.citys=res.data;
        })
    },
    avatarhandleAvatarSuccess(res, file) {
            if(res.code==200){
            this.form.avatar=res.url;
            this.$forceUpdate();
            }
            else{
              this.msgError(res.msg);
            }
     },
    frhandleAvatarSuccess(res, file) {
            if(res.code==200){
              this.form.idCardFrontUrl=res.url;
              this.$forceUpdate();
            }
            else{
              this.msgError(res.msg);
            }
    },
    bahandleAvatarSuccess(res, file) {
                if(res.code==200){
                  this.form.idCardBackUrl=res.url;
                  this.$forceUpdate();
                }
                else{
                  this.msgError(res.msg);
                }
     },
     signhandleAvatarSuccess(res, file) {
                if(res.code==200){
                  this.form.signUrl=res.url;
                  this.$forceUpdate();
                }
                else{
                  this.msgError(res.msg);
                }
     },

    handleAvatarSuccess(res, file) {
            if(res.code==200){
              this.form.certificateImages=res.url;
              this.$forceUpdate();
            }
            else{
              this.msgError(res.msg);
            }
    },
    handleCertificateBackSuccess(res, file) {
            if(res.code==200){
              this.form.certificateImagesBack=res.url;
                 this.$forceUpdate();
            }
            else{
              this.msgError(res.msg);
            }
    },
    handlePractiseSuccess(res, file) {
            if(res.code==200){
              this.form.practiseImages=res.url;
               this.$forceUpdate();
            }
            else{
              this.msgError(res.msg);
            }
    },
    handlePractiseBackSuccess(res, file) {
            if(res.code==200){
              this.form.practiseImagesBack=res.url;
              this.$forceUpdate();
            }
            else{
              this.msgError(res.msg);
            }
    },
    beforeAvatarUpload(file) {
          const isLt1M = file.size / 1024 / 1024 < 1;
          if (!isLt1M) {
            this.$message.error('上传图片大小不能超过 1MB!');
          }
          return   isLt1M;
    },
    /** 查询科室列表 */
     getdeplist() {
       listDepartment().then(response => {
         this.depList = response.rows;
       });
     },
     /** 查询医院列表 */
      getHospitaldeplist() {
        listAllHospital().then(response => {
          this.hospitalList = response.rows;
        });
      },
       editPass(row) {
         this.$confirm('是否确认重复密码为123456?', "警告", {
             confirmButtonText: "确定",
             cancelButtonText: "取消",
             type: "warning"
           }).then(function() {

             var data={
              doctorId:row.doctorId,
              password:123456
             }
             return editPassWord(data);
           }).then(() => {
             this.msgSuccess("重置成功");
           }).catch(function() {});
       },
    /** 查询医生管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.doctorType=1;
      listDoctor(this.queryParams).then(response => {
        this.doctorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open2 = false;
      this.open3 = false;
      this.reset();
      this.reset2();
      this.editForm={
        doctorId:null,
        isAudit:1,
        remark:null,
      };
    },
     reset2() {
       this.form2={
         doctorId:null,
         price1:1,
         price2:1,
         status:false
       }
     },
    // 表单重置
    reset() {
      this.form = {
        doctorId: null,
        doctorName: null,
        introduction: null,
        speciality: null,
        certificateCode: null,
        certificateImages: null,
        avatar: null,
        userId: null,
        hospitalId: null,
        deptId: null,
        balance: null,
        position: null,
        tags: null,
        createTime: null,
        updateTime: null,
        status: null,
        remark: null,
        pingStar: null,
        orderNumber: null,
        speed: null,
        mobile: null,
        doctorType: 1,
        sex: null,
        bitthday: null,
        idCard: null,
        idCardFrontUrl: null,
        idCardBackUrl: null,
        cityIds: null,
        province: null,
        city: null,
        district: null,
        isTui: null,
        isExpert: null,
        workStatus: null,
        isAudit: null,
        isAccept: null,
        packageIds:null,
        auditTime: null,
        isSelf:null,
        sort:null,
        isShow:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    getUserList(){
      getUserList(this.userName).then(response => {
        this.userList=response.rows;
      });
    },
    getPackageList(){
      allPackage().then(response => {
        this.packageList=response.rows;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.createTime=null;
      this.queryParams.sTime=null;
      this.queryParams.eTime=null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.doctorId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加医生";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const doctorId = row.doctorId || this.ids
      getDoctor(doctorId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改医生";
        if(this.form.workStatus!=null){
              this.form.workStatus = String(this.form.workStatus)
        }
        if(this.form.isExpert!=null){
           this.form.isExpert = String(this.form.isExpert)
        }
        if(this.form.isTui!=null){
            this.form.isTui = String(this.form.isTui)
        }
        if(this.form.sex!=null){
           this.form.sex = String(this.form.sex)
        }
        if(this.form.status!=null){
          this.form.status = String(this.form.status)
        }
        if(this.form.packageIds!=null){
           this.form.packageIds= ((this.form.packageIds).split(",")).map(Number)
        }
        if(this.form.storeIds!=null){
          this.form.storeIds= ((this.form.storeIds).split(",")).map(Number)
        }
        if(this.form.isSelf!=null){
          this.form.isSelf = String(this.form.isSelf)
        }
        if(this.form.isAudit!=null){
          this.form.isAudit = String(this.form.isAudit)
        }
        if(this.form.isShow!=null){
          this.form.isShow = String(this.form.isShow)
        }
        if(this.form.isAgreementPrescribeDoctor!=null){
          this.form.isAgreementPrescribeDoctor = String(this.form.isAgreementPrescribeDoctor)
        }
        if(this.form.isPrescribeDoctor!=null){
          this.form.isPrescribeDoctor = String(this.form.isPrescribeDoctor)
        }
        if(this.form.cityIds){
          this.form.cityIds=((this.form.cityIds).split(",")).map(Number)
        }

        if(this.form.prescribeDoctorName!=null){
              this.doctorName.name=this.form.prescribeDoctorName;
              this.getlistdocuser();
        }
        if(this.form.userId!=null && this.form.phone!=null){
              this.remoteMethod(this.form.phone)
        }
      });
    },
    editDoctorPrice(row){
        this.open2 = true;
        this.title = "修改问诊价格";
        getDoctor(row.doctorId).then(response => {
          this.form = response.data;
            this.form2.doctorId=row.doctorId;
            this.form2.status=this.form.workStatus==0?false:true;
            var data=JSON.parse(this.form.priceJson)
            for(let i in data){
              if(data[i].type==1){
                 this.form2.price1=data[i].price;
              }else{
                this.form2.price2=data[i].price;
              }
            }
        });
    },
    priceSubmitForm(){
      var arr = [
        { price: this.form2.price1, type: 1 },
        { price: this.form2.price2, type: 2 }
      ];
      var jsonString = JSON.stringify(arr);
      var form={
          doctorId: this.form2.doctorId,
          workStatus:this.form2.status?1:0,
          priceJson:jsonString
      }
      editPrice(form).then(response => {
       this.msgSuccess("修改成功");
       this.open2 = false;
       this.getList();
      });
    },
    handleClickX(){
        this.getList()
    },
    /** 提交按钮 */
    submitForm() {
      if(this.form.isPrescribeDoctor!=null){
          this.form.isPrescribeDoctor = String(this.form.isPrescribeDoctor)
        }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.form.packageIds!=null){
            this.form.packageIds=(this.form.packageIds).toString()
          }
          if(this.form.storeIds!=null){
            this.form.storeIds=(this.form.storeIds).toString()
          }
          this.form.cityIds=(this.form.cityIds).toString()
          if (this.form.doctorId != null) {
            this.form.doctorType=1;
            updateDoctor(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDoctor(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const doctorIds = row.doctorId || this.ids;
      this.$confirm('是否确认删除医生编号为"' + doctorIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDoctor(doctorIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
  docetrUpdate(row){
    this.title = "审核";
    this.open3=true;
    this.editForm.doctorId=row.doctorId
    },
    editSubmitForm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateAuditDoctor(this.editForm).then(response => {
          this.msgSuccess("修改成功");
          this.open3 = false;
          this.getList();
          });
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有药师数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportDoctor(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    getAllAiRoleList(){
      getAllAiRoleList().then(response => {
         this.aiOption = response.data;
      })
    }

  }
};
</script>
<style>
  .el-upload .el-upload-list__item-thumbnail img {
    width: 150px;
    height: 150px;
  }
  .pStar{
    padding-top: 10px;
  }
  .avatar-uploader .el-upload {
     border: 1px dashed #d9d9d9;
     border-radius: 6px;
     cursor: pointer;
     position: relative;
     overflow: hidden;
   }
   .avatar-uploader .el-upload:hover {
     border-color: #409EFF;
   }
   .avatar-uploader-icon {
     font-size: 28px;
     color: #8c939d;
     width: 150px;
     height: 150px;
     line-height: 150px;
     text-align: center;
   }
    #sf .avatar{
      min-width: 240px;
      min-height: 150px;
      display: block;
    }
    #sign .avatar{
      min-width: 120px;
      min-height: 80px;
      display: block;
    }
    .avatar {
         min-width: 150px;
         min-height: 150px;
         display: block;
     }
</style>
