<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="所属医院" prop="hospitalId">
        <el-button
          type
          class="stationbtn"
          @click="clickinnerVisible(true)"
        >{{ queryParams.hospitalName }}</el-button>
      </el-form-item>
      <el-form-item label="所属科室" prop="departmentId">
        <el-button type class="stationbtn" @click="clicklist(true)">{{ queryParams.departmentName }}</el-button>
      </el-form-item>
      <el-form-item label="人员名称" prop="personName">
        <el-input
          v-model="queryParams.personName"
          placeholder="请输入科室人员名称"
          clearable
          maxlength="7"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="personPhone">
        <el-input
          v-model="queryParams.personPhone"
          placeholder="请输入联系电话"
          clearable
          oninput="value=value.replace(/[^\d]/g,'')"
          @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 == "RESIDENT_PHYSICIAN" ? "住院医师" : "" }}
          {{ 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="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="1200px"
      :before-close="cancel"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="140px" :inline="true">
        <el-form-item label="所属医院" prop="hospitalId">
          <el-button
            type
            v-if="form.hospitalName == '请选择所属医院'"
            @click="clickinnerVisible(false)"
            style="
              width: 210px;
              text-align: left;
              height: 36px;

              color: #c0c4cc;
              overflow: hidden;
            "
          >{{ form.hospitalName }}</el-button>
          <el-button
            @click="clickinnerVisible(false)"
            type
            v-else
            style="
              width: 210px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
          >{{ form.hospitalName }}</el-button>
        </el-form-item>
        <el-form-item label="所属科室" prop="departmentId">
          <el-button
            type
            v-if="form.departmentName == '请选择所属科室'"
            @click="clicklist(false)"
            style="
              width: 210px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
          >{{ form.departmentName }}</el-button>
          <el-button
            @click="clicklist(false)"
            type
            v-else
            style="
              width: 210px;
              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" maxlength="7" placeholder="请输入人员名称" />
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input
            maxlength="11"
            v-model="form.personPhone"
            oninput="value=value.replace(/[^\d]/g,'')"
            placeholder="请输入联系电话"
          />
        </el-form-item>

        <el-form-item label="人员地址" prop="personAddress">
          <el-input
            v-model="form.personAddress"
            style="width: 210px"
            maxlength="300"
            placeholder="请输入人员地址"
          />
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input maxlength="18" v-model="form.cardNo" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="人员职称" prop="academicTitle">
          <el-select v-model="form.academicTitle" placeholder="请选择" style="width: 210px">
            <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
            maxlength="8"
            :change="checkPrice()"
            v-model="form.consultingFee"
            placeholder="请输入咨询费用"
          />
        </el-form-item>
        <el-form-item label="显示顺序" prop="personSort">
          <el-input
            oninput="value=value.replace(/[^\d]/g,'')"
            maxlength="5"
            v-model.number="form.personSort"
            placeholder="值越小,排名越靠前"
          />
        </el-form-item>
        <el-form-item label="人员头像" prop="personPictureUrl">
          <stationAcatar @imgUrl="imgUrl2" :img="form.personPictureUrl" :type="'personPictureUrl'" />
        </el-form-item>
        <el-form-item label="个人简介" prop="personIntroduce">
          <el-input
            type="textarea"
            :rows="5"
            maxlength="200"
            style="width: 540px"
            placeholder="请输入个人简介"
            v-model="form.personIntroduce"
          ></el-input>
        </el-form-item>
        <div
          v-for="(item, index) in form.hospitalPersonCertificateList"
          :key="index"
          style="margin-top: 20px; border-bottom: 1px solid #f3f3f3"
        >
          <el-form-item label="证书名称">
            <el-input maxlength="50" v-model="item.certificateName" placeholder="请输入证书名称" />
          </el-form-item>

          <el-form-item label="证书图片">
            <stationAcatar
              @imgUrl="imgUrl"
              @item="imgclassifyItem"
              :img="item.certificateUrl"
              :item="item"
              :type="'certificateUrl'"
            />
          </el-form-item>
          <el-form-item label="证书显示顺序">
            <el-input
              oninput="value=value.replace(/[^\d]/g,'')"
              maxlength="5"
              v-model.number="item.certificateSort"
              placeholder="请输入证书显示顺序"
            />
          </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="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="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="departmentclick" 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="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>
  </div>
</template>

<script>
import {
  list,
  listHospitalPerson,
  getHospitalPerson,
  delHospitalPerson,
  addHospitalPerson,
  listHospitalDepartment,
  updateHospitalPerson
} from "@/api/system/hospitalPerson";
import editor from "@/components/Editor";
import stationAcatar from "../stationAvatar/index.vue";
import { updatePicture } from "@/api/system/station";
export default {
  components: { editor, stationAcatar },
  name: "HospitalPerson",
  data() {
    // 验证手机号的规则
    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,
      idd: 0,
      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: "ATTENDING_DOCTOR",
          label: "主治医师"
        },
        {
          value: "RESIDENT_PHYSICIAN",
          label: "住院医师"
        },
        {
          value: "PHYSICIAN",
          label: "医师"
        },
        {
          value: "HEALER",
          label: "医士"
        }
      ],
      value: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      imgone: "",
      // 健康咨询-科室人员信息表格数据
      hospitalPersonList: [],
      // 弹出层标题
      title: "",
      deletNewImgs: [],
      NewImgs: [],
      objitempicture: [],
      objitem: [],
      // 是否显示弹出层
      open: false,
      addopen: false,
      homenumber: false,
      deletupdata: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hospitalId: null,
        departmentId: null,
        personCode: null,
        personName: null,
        departmentName: null,
        hospitalName: null,
        personPhone: null,
        personAddress: null,
        cardNo: null,
        academicTitle: null,
        consultingFee: null,
        personIntroduce: null,
        personSort: null,
        personPictureUrl: null,
        certificateSort: null,
        certificateName: null,
        certificateUrl: null
      },
      // 表单参数
      form: {
        // hospitalPersonCertificateList:[],
      },
      hospitalDepartmentList: [],
      hospitalqueryParams: {
        pageNum: 1,
        pageSize: 10,
        hospitalCode: ""
      },
      departmentqueryParams: {
        pageNum: 1,
        pageSize: 10,
        hospitalId: "",
        departmentCode: "",
        departmentName: ""
      },
      infolist: [],
      deletUploadImages: [],
      // 表单校验
      rules: {
        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"
          }
        ],
        consultingFee: [
          {
            required: true,
            message: "请选择咨询费用",
            trigger: "blur"
          }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.info();
  },
  methods: {
    /**只能输入数字且有小数点最多保留两位*/
    checkPrice() {
      let checkPlan = "" + this.form.consultingFee;
      checkPlan = checkPlan
        .replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
        .replace(/\.{2,}/g, ".") // 只保留第一个. 清除多余的
        .replace(/^\./g, "") // 保证第一个为数字而不是.
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      if (checkPlan.indexOf(".") < 0 && checkPlan !== "") {
        // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        checkPlan = parseFloat(checkPlan) + "";
      } else if (checkPlan.indexOf(".") >= 0) {
        checkPlan = checkPlan.replace(/^()*(\d+)\.(\d\d).*$/, "$1$2.$3"); // 只能输入两个小数
      }
      this.form.consultingFee = checkPlan;
    },
    //接收图片所属的item
    imgclassifyItem(item) {
      let imgUrlData = JSON.parse(item);
      // 存贮新上传的图片数组
      this.deletNewImgs.push(imgUrlData.certificateUrl);
      this.objitem.push(imgUrlData.certificateUrl);
      let items = JSON.parse(item);
      if (items.idd && !items.id) {
        this.form.hospitalPersonCertificateList.forEach(e => {
          if (e.idd == items.idd) {
            e.certificateUrl = items.certificateUrl;
          }
        });
      } else if (!items.idd && items.id) {
        this.form.certificateUrl = items.certificateUrl;
      }
    },
    imgUrl(imgUrl) {
      this.form.certificateUrl = imgUrl;
      this.deletupdata.push(imgUrl);
    },
    imgUrl2(imgUrl) {
      this.form.personPictureUrl = imgUrl;
      this.deletUploadImages.push(imgUrl);
    },

    nurseclick(row) {
      if (this.homenumber) {
        this.queryParams.hospitalName = row.hospitalName;
        this.queryParams.hospitalId = row.id;
      } else {
        this.hospitalId = row.id;
        // this.form.hospitalId = row.id;
        this.form.hospitalName = row.hospitalName;
      }
      this.form.hospitalId = row.id;
      this.innerVisible = false;
      this.addresetQuery();
    },
    // 科室
    departmentclick(row) {
      this.departmentId = row.id;
      if (this.homenumber) {
        this.queryParams.departmentName = row.departmentName;
        this.queryParams.departmentId = row.id;
        this.form.departmentId = row.id;
      } else {
        this.form.departmentId = row.id;
        this.form.departmentName = row.departmentName;
      }
      this.innerVisibledepartment = false;
    },

    //医院关闭
    innerVisiblecancel() {
      this.innerVisible = false;
    },
    //科室关闭
    innerVisiblecanceldepart() {
      this.innerVisibledepartment = false;
    },

    //删除deldisease
    deldisease(index) {
      this.form.hospitalPersonCertificateList.splice(index, 1);
    },
    adddisease() {
      this.idd++;
      var obj = {
        certificateName: null,
        certificateSort: null,
        certificateUrl: null,
        idd: this.idd
      };
      if (this.form.hospitalPersonCertificateList.length == 5) {
        this.$message.error("最多只能5条");
      } else {
        this.form.hospitalPersonCertificateList.push(obj);
      }
    },
    /** 查询健康咨询-科室人员信息列表 */
    getList() {
      this.loading = true;
      // this.queryParams.hospitalId = this.form.hospitalId;
      listHospitalPerson(this.queryParams).then(response => {
        this.hospitalPersonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 新增医院按钮
    clickinnerVisible(item) {
      this.queryParams.departmentName = "";
      this.form.departmentName = "请选择所属科室";
      this.info();
      this.innerVisible = true;
      this.homenumber = item;
      if (this.homenumber) {
        this.hospitalId = this.queryParams.hospitalId;
      } else {
        this.hospitalId = this.form.hospitalId;
      }
    },
    //新增科室按钮
    clicklist(item) {
      this.homenumber = item;
      // this.departmentId=item.id
      if (this.homenumber) {
        this.hospitalId = this.queryParams.hospitalId;
      } else {
        this.hospitalId = this.form.hospitalId;
      }
      if (this.hospitalId) {
        this.departmentList();
        this.innerVisibledepartment = true;
      } else {
        this.$message.error("请先选择所属医院");
      }
    },
    // 搜索
    departmentList() {
      this.departmentqueryParams.hospitalId = this.hospitalId;
      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;
        this.total2 = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      var obj = { pictureUrlList: [] };
      if (this.form.hospitalPersonCertificateList) {
        this.form.hospitalPersonCertificateList.forEach(e => {
          obj.pictureUrlList.push(e.certificateUrl);
        });
      }
      if (this.deletUploadImages.length > 0) {
        updatePicture({
          pictureUrlList: this.deletUploadImages
        }).then(res => {});
      }
      if (this.deletupdata.length > 0) {
        updatePicture({ pictureUrlList: this.deletupdata }).then(res => {});
      }
      this.form.hospitalId = null;
      this.departmentId = null;
      this.imgsurl = { pictureUrlList: [] };
      this.addopen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        personCode: null,
        personName: null,
        personPhone: null,
        personAddress: null,
        cardNo: null,
        academicTitle: null,
        consultingFee: null,
        personIntroduce: null,
        personSort: null,
        personPictureUrl: null,
        createBy: null,
        createTime: null,
        departmentId: null,
        hospitalId: null,
        updateBy: null,
        updateTime: null,
        hospitalName: "请选择所属医院",
        departmentName: "请选择所属科室",
        hospitalPersonCertificateList: [
          {
            certificateName: null,
            certificateSort: null,
            certificateUrl: null,
            idd: 0
          }
        ]
      };
      this.deletUploadImages = [];
      this.deletupdata = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.departmentId = "";
      this.hospitalId = "";
      this.departmentqueryParams = {
        pageNum: 1,
        pageSize: 10
      };
      this.queryParams = {
        pageNum: 1,
        pageSize: 10
      };
      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.form = {
        hospitalPersonCertificateList: [
          {
            certificateSort: "",
            certificateName: "",
            certificateUrl: "",
            idd: this.idd
          }
        ]
      };
      this.departmentId = "";
      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.departmentId = response.data.departmentId;
        this.hospitalId = response.data.hospitalId;
        this.imgone = this.form.certificateUrl;
        this.addopen = true;
        this.title = "修改科室人员信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (this.form.hospitalPersonCertificateList.length > 0) {
        this.form.hospitalPersonCertificateList.forEach(e => {
          if (!e.certificateName && !e.certificateUrl && !e.certificateSort) {
            this.form.hospitalPersonCertificateList = this.form.hospitalPersonCertificateList.filter(
              el => el.idd != e.idd
            );
          }
        });
        if (this.form.hospitalPersonCertificateList.length == 0) {
          var obj = {
            certificateSort: null,
            certificateName: null,
            certificateUrl: null
          };
          this.form.hospitalPersonCertificateList.push(obj);
        }
      }
      if (this.form.consultingFee) {
        this.form.consultingFee = Number(this.form.consultingFee);
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHospitalPerson(this.form).then(response => {
              if (response.code == 200) {
              this.$modal.msgSuccess("修改成功");
              this.addopen = false;
              this.getList();
              }
            });
          } else {
            addHospitalPerson(this.form).then(response => {
              if (response.code == 200) {
              this.$modal.msgSuccess("新增成功");
              this.addopen = false;
              this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除此人员信息？")
        .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>
<style lang="scss" scoped>
.stationbtn {
  width: 208px;
  text-align: left;
  height: 32px;
  overflow: hidden;
  font-size: 14px;
}
</style>