<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <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>
             <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="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>
        <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:pharmacist: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:pharmacist: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:pharmacist:export']"
        >导出</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="600" 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="150px"/>

      <el-table-column label="余额" align="center" prop="balance" />
      <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" />
      <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="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="remark"  show-overflow-tooltip/>
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <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:pharmacist: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:pharmacist: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:pharmacist:audit']"
            >审核</el-button>
            <el-button
              size="mini"
              type="text"
              v-hasPermi="['his:pharmacist:resetpwd']"
              @click="editPass(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="900px" append-to-body >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">

      <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-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="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-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
                                  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="300px">
                                  <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="200px" >
                                    <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
                                  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="300px">
                                  <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="auditType">
                      <el-select v-model="form.auditType" multiple placeholder="药师类型" style="width: 300px;">
                        <el-option
                          v-for="item in auditTypeOptions"
                          :key="item.dictValue"
                          :label="item.dictLabel"
                          :value="parseInt(item.dictValue)"
                        ></el-option>
                      </el-select>
                </el-form-item>
             </el-col>
        </el-row>
       <el-row>
             <el-col :span="12">
               <el-form-item label="登录账号" prop="account" v-if="form.doctorId==null||form.doctorId==''">
                 <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="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="show.open">
        <pharmacistDetails  ref="pharmacistDetails" />
           </el-drawer>


  </div>
</template>

<script>
import {getUserList, listDoctor, getDoctor, 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 pharmacistDetails from '../../components/his/pharmacistDetails.vue';
export default {
  name: "pharmacist",
  components: { pharmacistDetails },
  data() {
    return {
      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",
      baseUrl: process.env.VUE_APP_BASE_API,
      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",
      bauploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
      orOptions: [],
      isauditOptions: [],
      positionOptions: [],
      statusOptions: [],
      sexOptions: [],
      StoreOrderType:[],
      //科室列表
      depList:[],
      userName: {name:"1"},
      userList:[],
      // auditTypeOptions:[{
      //     dictValue: '1',
      //     dictLabel: '西药'
      //   }, {
      //     dictValue: '2',
      //     dictLabel: '中药'
      //   }],
      auditTypeOptions:[],
      //医院列表
      hospitalList:[],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      show:{
              title:"医生详情",
              open:false,
            },
      citys:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医生管理表格数据
      doctorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      open3: false,
      editForm:{
         doctorId:null,
         isAudit:1,
         remark:null,
       },
      form2:{
        doctorId:null,
        price1:1,
        price2:1,
        status:false
      },
      // 查询参数
      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: 2,
        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
      },
      // 表单参数
      form: {},
      // 表单校验
      form: {},
      // 表单校验
      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" }
        ],

        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" }
        ],
        auditType: [
          { required: true, message: "类别不能为空", trigger: "blur" }
        ],
      },
      editRadio: [{
              "dictLabel": "通过",
              "dictValue": 1
            }, {
              "dictLabel": "驳回",
              "dictValue": -1
      }],


    };
  },
  created() {
    this.getCitys();
    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.getDicts("sys_store_order_type").then(response => {
      this.StoreOrderType = response.data;
    });
    this.getDicts("sys_product_type").then(response => {
      this.auditTypeOptions = response.data;
    });


    this.getdeplist();
    this.getHospitaldeplist();
  },
  methods: {

    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.pharmacistDetails.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;
              console.log(this.form)
               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;
        });
      },
    /** 查询医生管理列表 */
    getList() {
      this.loading = true;
       this.queryParams.doctorType=2;
      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: 2,
        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: 1,
        auditTime: null,
        auditType:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    getUserList(){
      getUserList(this.userName).then(response => {
        this.userList=response.rows;
      });
    },


    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.form.isAudit=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 = "添加药师";
    },

   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() {});
   },
    /** 修改按钮操作 */
    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.auditType!=null){
           this.form.auditType= ((this.form.auditType).split(",")).map(Number)
           console.log(this.form.auditType)
        }
       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.isAudit!=null){
         this.form.isAudit = String(this.form.isAudit)
       }
      this.form.cityIds=((this.form.cityIds).split(",")).map(Number)
      });
    },

   docetrUpdate(row){
     this.title = "审核";
     this.open3=true;
     this.editForm.doctorId=row.doctorId;
     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();
       });
          }
        });

      },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
                  this.form.cityIds=(this.form.cityIds).toString()
                  this.form.auditType=(this.form.auditType).toString()
          if (this.form.doctorId != null) {
            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(() => {});
    },
   editDoctorPrice(row){
       this.open2 = true;
       this.title = "修改问诊价格";
       this.form2.doctorId=row.doctorId;
       this.form2.status=row.workStatus==0?false:true;
       var data=JSON.parse(row.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()
    },
    /** 导出按钮操作 */
    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(() => {});
    }
  }
};
</script>
<style>
  .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;
    }
  #sign .avatar{
    min-width: 120px;
    min-height: 80px;
    display: block;
  }
</style>
