<template>
  <div>
    <div>
      <div style="display: flex;justify-content:space-between;">
        <div class="contenttitle">
          体检 /<span class="contenttitleBold">检查医生诊台</span>
        </div>
        <div style="position: absolute;margin-right:120px; top:50px;right:10px;z-index: 2;">
          <el-image style="width: 100px; height: 105px;" :src="peoplePhoto">
            <div slot="placeholder" class="image-slot">
              加载中<span class="dot">...</span>
            </div>
          </el-image>
        </div>
      </div>
      <div style="display: flex;">
        <div :style="`width:${window.pageWidth - 120}px;`">
          <div style="display: flex;justify-content:space-between;z-index:-1;">
            <div>              
              <PatientRegisterBase />
            </div>
            <div style="width: 100px;"></div>
          </div>
          <div style="display: flex;">
            <el-tabs v-model="activeName" tab-position="bottom" style="width: 200px;">
              <el-tab-pane label="组合项目" name="asbitem">                
                <RegisterCheckList />                
              </el-tab-pane>
              <el-tab-pane v-if="LocalConfig.doctorCheck.isQueue == 'Y'" label="叫号" name="call">                
                <QueueCheckList />                
              </el-tab-pane>
            </el-tabs>

            <div :style="'width:' + (window.pageWidth - 200 - 110 - 15) + 'px;'">
              <div :style="'margin-left: 2px;width:' + (window.pageWidth - 200 - 110 - 15 - 2) + 'px;'">                
                <CheckItemList :isCheckPicture="isCheckPicture" :doctor_check_check_charge="doctor_check_check_charge"
                  :registerCheckId="dataTransOpts.tableS.register_check.id" />                  
              </div>
              <div v-if="isCheckPicture" class="demo-image__preview"
                :style="'margin-top: 2px;margin-left: 2px;height:110px;width:' + (window.pageWidth - 200 - 110 - 45 - 2) + 'px;'">                
                <CheckPicture :doctorBtnDisabled="doctorBtnDisabled" />                
              </div>
              <div :style="'margin-top: 2px;margin-left: 2px;width:' + (window.pageWidth - 200 - 110 - 15 - 2) + 'px;'">
                
                <CheckSumSug :registerCheckId="dataTransOpts.tableS.register_check.id" :isCheckPicture="isCheckPicture"
                  :optGrant="optGrant" :addSummary="addSummary" :btnMakeDiagnosis="btnMakeDiagnosis" :save="save"
                  :audit="audit" :unAudit="unAudit" :btnLineUp="btnLineUp" :doctorBtnDisabled="doctorBtnDisabled" />
                
              </div>
              <div :style="'margin-top: 2px;width:' + (window.pageWidth - 200 - 110 - 15 - 2) + 'px;'">                
                <RegisterCheckEdit :registerCheckId="dataTransOpts.tableS.register_check.id" />          
              </div>
            </div>
          </div>
        </div>
        <div style="width:110px;">
          <ButtonList :optGrant="optGrant" :addSummary="addSummary" :btnMakeDiagnosis="btnMakeDiagnosis" :save="save"
            :audit="audit" :unAudit="unAudit" :doctorBtnDisabled="doctorBtnDisabled" />
        </div>
      </div>
    </div>
    <!--组件弹窗-->
    <div>
      <!-- 危急值 -->
      <el-dialog title="危急值" :visible.sync="dialogWin.FollowCriticalCheck" width="800px"
        :show-close="false" :close-on-click-modal="false" :append-to-body="true">        
        <FollowCriticalCheck />
      </el-dialog>      
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { arrayExistObj, tcdate, deepCopy } from "../../utlis/proFunc";
import { photoParse } from "../../utlis/proApi";

import PatientRegisterBase from "../../components/doctorCheck/PatientRegisterBase.vue";
import ButtonList from "../../components/doctorCheck/ButtonList.vue";
import CheckPicture from "../../components/doctorCheck/CheckPicture.vue";
import RegisterCheckList from "../../components/doctorCheck/RegisterCheckList.vue";
import QueueCheckList from "../../components/doctorCheck/QueueCheckList.vue";
import CheckItemList from "../../components/doctorCheck/CheckItemList.vue";
import CheckSumSug from "../../components/doctorCheck/CheckSumSug.vue";
import RegisterCheckEdit from "../../components/doctorCheck/RegisterCheckEdit.vue";
import FollowCriticalCheck from "../../components/follow/FollowCriticalCheck.vue";
import moment from 'moment';
import Follow from "@/components/follow/follow.vue";

export default {
  components: {
    RegisterCheckList,
    QueueCheckList,
    PatientRegisterBase,
    ButtonList,
    CheckPicture,
    CheckItemList,
    CheckSumSug,
    RegisterCheckEdit,
    FollowCriticalCheck,
  },
  data() {
    return {
      peoplePhoto: '', //人员照片
      activeName: 'asbitem',
      isCheckPicture: true,  //是否显示结果图片

      LocalConfig: {
        doctorCheck: { // 医生诊台
          isCheckPicture: false, // 是否显示检查图片
          isQueue: 'N',  //启用分诊排队
          queueRoom: '',  //默认分诊房间
        }
      },
      LocalConfigInit: {},
      doctor_check_check_charge: 'Y',  // 默认判断收费
    };
  },

  created() {
    // console.log("this.$route.query", this.$route.query)

    if (this.$route.query.patient_register) {
      this.dataTransOpts.tableS.patient_register = this.$route.query.patient_register
    } else {
      this.dataTransOpts.tableS.patient_register = { id: '', patientRegisterNo: '' }
      this.dataTransOpts.tableS.register_check = { id: '' }
      this.peoplePhoto = ''
    }

    this.LocalConfigInit = deepCopy(this.LocalConfig)
    let LocalConfig = window.localStorage.getItem("LocalConfig") || null
    try {
      this.LocalConfig = Object.assign({}, deepCopy(this.LocalConfigInit), JSON.parse(LocalConfig) || {})

    } catch (error) {
      console.log('window.localStorage.getItem("LocalConfig")', error)
    }

    if (this.$peisAPI) {
      // this.$message.info("此功能，需要在壳客户端才可运行！");
      // console.log('this.$peisAPI',this.$peisAPI)
      this.$peisAPI.getIsCheckPicture().then(res => {
        console.log("this.$peisAPI.getIsCheckPicture()", res)
        if (res) this.isCheckPicture = res.toUpperCase() == 'Y' ? true : false
      })
    } else {

      try {
        this.isCheckPicture = this.LocalConfig.doctorCheck.isCheckPicture
      } catch (error) {
        console.log('window.localStorage.getItem("LocalConfig")', error)
      }

    }

    console.log('this.LocalConfig', this.LocalConfig)
  },

  //挂载完成
  mounted() {
    this.dictInit();

    // window.addEventListener("contextmenu", (e) => {
    //   if (this.$peisAPI) {
    //     e.preventDefault();
    //     this.$peisAPI.contextMenuForPeis()
    //   }
    // })
  },

  // deactivated() {
  //   window.removeEventListener('contextmenu', (e) => {
  //     console.log('window.removeEventListener')
  //   });
  // },

  computed: {
    ...mapState(["window", "dataTransOpts", "dict", "dialogWin","patientRegister", "customerOrg", "doctorCheck", "sumDoctorCheck"]),
  },

  methods: {

    //数据初始化
    async dictInit() {
      let sysParmId = "doctor_check_check_charge"
      let sysParam = await postapi('/api/app/SysParmValue/GetSysParmValueBySysParmId', { sysParmId })
      this.doctor_check_check_charge = sysParam.data.toUpperCase()

      //性别（仅档案用）
      getapi("/api/app/sex").then((res) => {
        if (res.code == 1) {
          this.dict.sex = res.data;
        }
      });

      //性别（查询）
      getapi("/api/app/for-sex").then((res) => {
        if (res.code == 1) {
          this.dict.forSex = res.data;
        }
      });

      //体检中心
      getapi("/api/app/organization-units/organization-unit-by-is-peis").then(
        (res) => {
          if (res.code == 1) {
            this.dict.organization = res.data;
          }
        }
      );

      //体检单位
      // getapi("/api/app/customer-org/in-filter").then((res) => {
      //   if (res.code == 1) {
      //     this.dict.customerOrg = res.data;
      //   }
      // });

      //体检类别
      getapi("/api/app/medical-type/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.medicalType = res.data;
        }
      });

      //人员类别
      getapi("/api/app/personnel-type/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.personnelType = res.data;
        }
      });

      //婚姻状况
      getapi("/api/app/MaritalStatus/GetMaritalStatusList").then((res) => {
        if (res.code == 1) {
          this.dict.maritalStatus = res.data;
        }
      });

      //性激素期
      getapi("/api/app/sex-hormone-term/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.sexHormoneTerm = res.data;
        }
      });

      //民族
      getapi("/api/app/nation/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.nation = res.data;
        }
      });

      //籍惯 ，出生地
      getapi("/api/app/birth-place/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.birthPlace = res.data;
        }
      });

      //套餐
      postapi("/api/app/medicalpackage/GetBasicList", {}).then((res) => {
        if (res.code == 1) {
          this.dict.medicalPackage = res.data;
        }
      });

      //分组，所有分组，不限单位，不限次数
      // getapi("/api/app/customer-org-group").then((res) => {
      //   if (res.code == 1) {
      //     this.dict.customerOrgGroupAll = res.data.items;
      //   }
      // });

      //支付方式
      getapi("/api/app/pay-mode").then((res) => {
        if (res.code == 1) {
          this.dict.payMode = res.data;
        }
      });

      //体检类别 树结构
      getapi("/api/app/item-type/by-code-all").then((res) => {
        if (res.code == 1) {
          this.dict.itemTypeTree = res.data;
          tcdate(this.dict.itemTypeTree);
        }
      });

      //所有组合项目
      postapi("/api/app/asbitem/GetBasicList", { isFilterActive: 'Y' }).then((res) => {
        if (res.code == 1) {
          this.dict.asbItemAll = res.data;
        }
      });

      //获取体检单位列表树信息   
      // getapi("/api/app/customerorg/getbycodeall").then((res) => {
      //   //customerOrgTree = res.data;
      //   console.log("res.data", res.data);
      //   this.patientRegister.customerOrgTreeAll = res.data;
      //   tcdate(this.patientRegister.customerOrgTreeAll)
      // });

      postapi('/api/app/CustomerOrg/GetCustomerOrgByParentId', { parentId: null })
        .then(res => {
          if (res.code > -1) {
            res.data.forEach(e => {
              e.isLeaf = e.isChild == 'Y' ? false : true
            });
            this.patientRegister.customerOrgTreeAll = res.data;
            tcdate(this.patientRegister.customerOrgTreeAll)
          }
        })


      console.log("dict", this.dict);
    },

    //操作判断
    optGrant(optType) {
      let ret = ''
      if (!this.doctorCheck.RegisterCheckEdit.id) return '请选择组合项目'
      if (this.doctorCheck.RegisterCheckEdit.isLock == 'Y') return '组合项目已锁定，不可执行此操作'
      // if (this.doctorCheck.RegisterCheckEdit.completeFlag == '2') return '组合项目已弃检，不可执行此操作'
      if (optType == 'save') {
        // if (!this.doctorCheck.RegisterCheckEdit.checkDoctorId) return "请选择检查医生"
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '2') return "该项目项目已弃检，不可再执行此操作"
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '1') return "该项目项目已保存，不可再执行此操作，如需操作请点【修改结果】"
        if (this.doctorCheck.RegisterCheckEdit.isAudit == 'Y') return '组合项目已审核，请先取消审核，方可执行此操作！'
      }
      if (optType == 'edit') {
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '0') return "该检查项目尚未保存，无需执行此操作"
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '2') return "该项目项目已弃检，不可再执行此操作"
        if (this.doctorCheck.RegisterCheckEdit.isAudit == 'Y') return '组合项目已审核，请先取消审核，方可执行此操作！'
      }
      if (optType == 'del') {
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '0') return "该检查项目尚未保存，无需执行此操作"
        if (this.doctorCheck.RegisterCheckEdit.isAudit == 'Y') return '组合项目已审核，请先取消审核，方可执行此操作！'
      }
      if (optType == 'audit') {
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '0') return "该检查项目尚未保存，无需执行此操作"
        if (this.doctorCheck.RegisterCheckEdit.isAudit == 'Y') return "该检查项目已审核，无需再执行此操作"
      }
      if (optType == 'unAudit') {
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '0') return "该检查项目尚未保存，无需执行此操作"
        if (this.doctorCheck.RegisterCheckEdit.isAudit == 'N') return "该检查项目尚未审核，无需执行此操作"
      }
      if (optType == 'delItem' || optType == 'refuseItem' || optType == 'makeDiagnosis') {
        if (this.doctorCheck.RegisterCheckEdit.completeFlag == '1') return "该项目项目已保存，不可再执行此操作，如需操作请点【修改结果】"
        if (this.doctorCheck.RegisterCheckEdit.isAudit == 'Y') return "该检查项目已审核，请先取消审核"
      }
      return ret
    },

    // 按钮可用
    doctorBtnDisabled(btnFlagName) {
      let patientRegister = this.dataTransOpts.tableS.patient_register
      let RegisterCheckEdit = this.doctorCheck.RegisterCheckEdit
      let ret = true

      //' 请选择体检人员'
      if (!patientRegister.id) return ret

      switch (btnFlagName) {
        case 'btnCheckHistory':
        case 'btnReport':
          return false
        case 'toSumDoctorCheck':
          let operatorType = window.sessionStorage.getItem("operatorType")
          if (operatorType == '2' || operatorType == '3') ret = false
          return ret
        case 'btnOcc':
          console.log('patientRegister', patientRegister)
          if (patientRegister.isPatientOccupationalDisease && patientRegister.isPatientOccupationalDisease == 'Y') ret = false
          return ret
      }

      // '人员已锁定，不可执行此操作'
      if (patientRegister.isLock && patientRegister.isLock == 'Y') return ret
      if (patientRegister.completeFlag && patientRegister.completeFlag == '3') return ret

      if (btnFlagName == 'editPr' || btnFlagName == 'delPr') return false


      // 未选检查项目
      if (!RegisterCheckEdit.id) return ret
      switch (btnFlagName) {
        case 'btnEdit': // 修改结果
        case 'btnDel':  // 删除结果
          if (RegisterCheckEdit.completeFlag && (RegisterCheckEdit.completeFlag == '1' || RegisterCheckEdit.completeFlag == '2')) ret = false
          break;
        case 'refuse': // 放弃检查项目
        case 'refuseItem': // 放弃明细检查项目
        case 'delItem':   // 删除检查项目
        case 'btnMakeDiagnosis':   // 生成小结
        case 'save':   // 保存结果
        case 'addSummary':   // 新增小结
        case 'delSum':   // 删除小结
        case 'addSuggestion':   // 新增建议
        case 'delSug':   // 删除建议
        case 'btnGetPic':   // 采图（图片采集）
        case 'btnExpPic':   // 导图（图片上传）
        case 'btnSavePic':   // 图片保存
        case 'btnDelImage':   // 图片删除 
          // console.log('btnFlagName RegisterCheckEdit', btnFlagName, RegisterCheckEdit.completeFlag)          
          if (this.doctor_check_check_charge == 'Y') {
            if (RegisterCheckEdit.completeFlag && RegisterCheckEdit.completeFlag == '0' && RegisterCheckEdit.isCharge == 'Y') ret = false
          } else {
            if (RegisterCheckEdit.completeFlag && RegisterCheckEdit.completeFlag == '0') ret = false
          }
          break;
        case 'btnCritical':
          if (RegisterCheckEdit.isAudit && RegisterCheckEdit.isAudit != 'Y') ret = false
          break;
        case 'audit':
          if (RegisterCheckEdit.completeFlag && RegisterCheckEdit.completeFlag != '0' && RegisterCheckEdit.isAudit && RegisterCheckEdit.isAudit != 'Y') ret = false
          break;
        case 'unAudit':
          if (RegisterCheckEdit.completeFlag && RegisterCheckEdit.completeFlag != '0' && RegisterCheckEdit.isAudit && RegisterCheckEdit.isAudit != 'N') ret = false
          break;
        default:
          ret = false
          break;
      }
      // console.log('sumBtnDisabled btnFlagName, patientRegister,ret', btnFlagName, patientRegister, ret)
      return ret
    },

    // 生成小结
    btnMakeDiagnosis() {
      let ret = this.optGrant('makeDiagnosis')
      if (ret) {
        this.$message.warning(ret)
        return
      }

      if (this.doctorCheck.checkItemList.length == 0) {
        this.$message.warning("系统错误，组合项目没有明细")
        return
      }

      console.log('生成小结');

      if (this.doctorCheck.checkSummaryList.length > 0) {
        this.$confirm("已经有小结，是否重新生成小结?", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        }).then(() => {
          this.makeDiagnosisFun();
        }).catch((err) => {
          if (err == "cancel") {
            this.$message.info("已取消");
          }
        });
      } else {
        this.makeDiagnosisFun();
      }

    },

    // 生成小结的函数
    makeDiagnosisFun() {

      // /api/app/diagnosisfunction/getdiagnosisresult
      // {
      //     "registerCheckId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      //     "items": [
      //         {
      //         "itemId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      //         "result": "string"
      //         }
      //     ]
      // }


      let body = {
        registerCheckId: '',
        items: []
      }

      this.doctorCheck.checkItemList.forEach((e, index) => {
        if (index == 0) body.registerCheckId = e.registerCheckId
        body.items.push({
          itemId: e.itemId,
          result: e.result
        })
      })

      // 旧接口： console.log(`/api/app/diagnosisfunction/getdiagnosisresult`, body)
      this.doctorCheck.checkSummaryList = []
      this.doctorCheck.checkSuggestionList = []
      postapi(`/api/app/DiagnosisFunction/GetDoctorCheckDiagnosisResultAsync`, body)
        .then((res) => {
          if (res.code > -1) {
            // if (res.code == 0) {
            //   // 个别项目有异常，但不影响其他项目生成小结
            //   this.$message.warning({ showClose: true, message: res.message })
            // }
            // 小结
            res.data.diagnosisResultDetails.forEach(e => {
              this.doctorCheck.checkSummaryList.push({
                id: Math.random(),
                registerCheckId: body.registerCheckId,
                summary: e.diagnosisResult,
                summaryFlag: 'Y'
              })
            })

            // 建议
            res.data.diagnosisSuggestionDetails.forEach(e => {
              this.doctorCheck.checkSuggestionList.push({
                id: Math.random(),
                registerCheckId: body.registerCheckId,
                suggestion: e.diagnosisSuggestion
              })
            })
            console.log("操作成功！")
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `生成小结失败，原因：${err}` });
        });
    },

    // 手动新增小结与建议
    addSummary() {
      let ret = this.optGrant('makeDiagnosis')
      if (ret) {
        this.$message.warning(ret)
        return
      }

      this.doctorCheck.checkSummaryList.push({
        id: Math.random(),
        registerCheckId: this.doctorCheck.RegisterCheckEdit.id,
        summary: '',
        summaryFlag: 'N',
      })

    },

    //保存数据
    save() {
      let ret = this.optGrant('save')
      if (ret) {
        this.$message.warning(ret)
        return
      }

      // //更新明细
      // this.updateCheckItemList();

      // //更新检查项目与医生
      // this.updateDoctorCheck();

      // //更新小结        
      // this.saveCheckSummary();

      // //更新建议      
      // this.saveCheckSuggestion(true);

      // 合并成一个事务
      // {
      //   "registerCheckId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      //   "checkDoctorId": "string",
      //   "checkDate": "2024-04-17T14:13:24.889Z",
      //   "registerCheckItems": [
      //     {
      //       "itemId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      //       "result": "string",
      //       "criticalValue": "string",
      //       "checkDoctorName": "string",
      //       "checkDate": "string"
      //     }
      //   ],
      //   "summarys": [
      //     {
      //       "summary": "string",
      //       "summaryFlag": "string"
      //     }
      //   ],
      //   "suggestions": [
      //     {
      //       "suggestion": "string"
      //     }
      //   ]
      // }
      let checkDate = this.doctorCheck.RegisterCheckEdit.checkDate || new Date();
      checkDate = moment(new Date(checkDate)).format('yyyy-MM-DD HH:mm:ss'); //yyyy-MM-DD HH:mm:ss
      let checkDoctorId = this.doctorCheck.RegisterCheckEdit.checkDoctorId || null;
      let registerCheckId = this.doctorCheck.RegisterCheckEdit.id
      // 明细
      let registerCheckItems = []
      this.doctorCheck.checkItemList.forEach(e => {
        registerCheckItems.push({
          itemId: e.itemId,
          result: e.result,
          checkDoctorName: checkDoctorId,
          checkDate,
        })
      });
      // 小结
      let summarys = []
      this.doctorCheck.checkSummaryList.forEach(item => {
        summarys.push({
          summary: item.summary,
          summaryFlag: item.summaryFlag,
        })
      });
      // 建议
      let suggestions = []
      this.doctorCheck.checkSuggestionList.forEach(item => {
        suggestions.push({
          suggestion: item.suggestion
        })
      });

      let body = {
        registerCheckId,
        checkDoctorId,
        checkDate,
        registerCheckItems,
        summarys,
        suggestions
      }


      if (summarys.length == 0) {
        this.$message.warning({ showClose: true, message: '请生成小结！' })
        return
      }

      postapi('/api/app/registercheck/UpdateCheckResult', body)
        .then(res => {
          if (res.code > -1) {
            this.doctorCheck.RegisterCheckEdit.completeFlag = '1';
            //更新组合项目列表记录状态
            let lfind = arrayExistObj(this.doctorCheck.RegisterCheckList, 'id', body.registerCheckId)
            if (lfind > -1) this.doctorCheck.RegisterCheckList[lfind].completeFlag = '1'

            console.log('操作成功')
          } else {
            this.$message.error({ showClose: true, message: res.message })
          }
        })
    },


    //更新检查医生
    updateDoctorCheck(successTip) {
      let checkDate = this.doctorCheck.RegisterCheckEdit.checkDate || new Date();
      checkDate = moment(new Date(checkDate)).format('yyyy-MM-DD HH:mm:ss'); //yyyy-MM-DD HH:mm:ss
      let checkDoctorId = this.doctorCheck.RegisterCheckEdit.checkDoctorId || window.sessionStorage.getItem("user");

      let body = {
        registerCheckId: this.doctorCheck.RegisterCheckEdit.id,
        checkDoctorId,
        checkDate
      }
      console.log(`/api/app/registercheck/updatecheckdoctor`, body)
      postapi(`/api/app/registercheck/updatecheckdoctor`, body)
        .then((res) => {
          console.log("updateDoctorCheck", res.data);
          if (res.code != -1) {
            console.log("更新检查医生 成功", res.data);
            this.doctorCheck.RegisterCheckEdit.completeFlag = '1';
            //更新组合项目列表记录状态
            let lfind = arrayExistObj(this.doctorCheck.RegisterCheckList, 'id', body.registerCheckId)
            if (lfind > -1) this.doctorCheck.RegisterCheckList[lfind].completeFlag = '1'
            if (successTip) console.log("操作成功！")
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `更新检查医生失败，原因：${err}` });
        });
    },

    //更新检查项目明细
    updateCheckItemList(successTip) {
      let checkDate = this.doctorCheck.RegisterCheckEdit.checkDate || new Date();
      checkDate = moment(new Date(checkDate)).format('yyyy-MM-DD'); //yyyy-MM-DD HH:mm:ss
      let checkDoctorId = this.doctorCheck.RegisterCheckEdit.checkDoctorId || window.sessionStorage.getItem("user");
      let body = []
      for (let i = 0; i < this.doctorCheck.checkItemList.length; i++) {
        body.push({
          registerCheckId: this.doctorCheck.checkItemList[i].registerCheckId,
          itemId: this.doctorCheck.checkItemList[i].itemId,
          result: this.doctorCheck.checkItemList[i].result,
          checkDoctorName: checkDoctorId,
          checkDate,
        })
      }
      console.log(`/api/app/registercheckitem/updateregistercheckitemmany`, body)
      postapi(`/api/app/registercheckitem/updateregistercheckitemmany`, body)
        .then((res) => {
          console.log("updateCheckItemList", res.data);
          if (res.code != -1) {
            console.log("更新检查项目明细成功", res.data);
            if (successTip) console.log("操作成功！")
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `更新检查项目明细失败，原因：${err}` });
        });
    },

    //更新小结        
    saveCheckSummary(successTip) {
      let details = []
      this.doctorCheck.checkSummaryList.forEach(item => {
        details.push({
          registerCheckId: item.registerCheckId,
          summary: item.summary,
          summaryFlag: item.summaryFlag,
        })
      });
      let body = {
        registerCheckId: this.doctorCheck.RegisterCheckEdit.id,
        details
      }

      console.log(`/api/app/registerchecksummary/createregisterchecksummarymany`, body)
      postapi(`/api/app/registerchecksummary/createregisterchecksummarymany`, body)
        .then((res) => {
          console.log("saveCheckSummary", res.data);
          if (res.code != -1) {
            console.log("更新小结 成功", res.data);
            if (successTip) console.log("操作成功！")
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `更新小结失败，原因：${err}` });
        });

    },

    //更新建议      
    saveCheckSuggestion(successTip) {
      let details = []
      this.doctorCheck.checkSuggestionList.forEach(item => {
        details.push({
          registerCheckId: item.registerCheckId,
          suggestion: item.suggestion
        })
      });

      let body = {
        registerCheckId: this.doctorCheck.RegisterCheckEdit.id,
        details
      }

      console.log(`/api/app/registerchecksuggestion/createregisterchecksuggestionmany`, body)
      postapi(`/api/app/registerchecksuggestion/createregisterchecksuggestionmany`, body)
        .then((res) => {
          console.log("saveCheckSuggestion", res.data);
          if (res.code != -1) {
            //this.doctorCheck.RegisterCheckEdit.completeFlag = '1';
            if (successTip) console.log("操作成功！")
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `更新建议失败，原因：${err}` });
        });

    },

    //审核
    audit() {
      let ret = this.optGrant('audit')
      if (ret) {
        this.$message.warning(ret)
        return
      }
      let body = {
        registerCheckId: this.doctorCheck.RegisterCheckEdit.id,
        //auditorUserId: "3fa85f64-5717-4562-b3fc-2c963f66afa6", 
        //auditTime: "string" 不传时，取当前时间
      }

      console.log(`/api/app/registercheck/updateauditordoctor`, body)
      postapi(`/api/app/registercheck/updateauditordoctor`, body)
        .then((res) => {
          console.log("audit", res.data);
          if (res.code != -1) {
            this.doctorCheck.RegisterCheckEdit.isAudit = 'Y';
            this.$message({ type: "success", message: `组合项目审核成功` });
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `组合项目审核失败，原因：${err}` });
        });
    },

    //取消审核
    unAudit() {
      let ret = this.optGrant('unAudit')
      if (ret) {
        this.$message.warning(ret)
        return
      }

      console.log(`/api/app/registercheck/updateisaudit?RegisterCheckId=${this.doctorCheck.RegisterCheckEdit.id}&IsAudit=N`)
      postapi(`/api/app/registercheck/updateisaudit?RegisterCheckId=${this.doctorCheck.RegisterCheckEdit.id}&IsAudit=N`)
        .then((res) => {
          console.log("unAudit", res.data);
          if (res.code != -1) {
            this.doctorCheck.RegisterCheckEdit.isAudit = 'N';
            this.$message({ type: "success", message: `组合项目取消审核成功` });
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `组合项目取消审核失败，原因：${err}` });
        });
    },

    // 排队
    btnLineUp() {
      console.log('排队')
    },

  },

  //监听事件()
  watch: {
    // //1级单位值改变，分组改变
    // "patientRegister.query.CustomerOrgParentId"(newVal, oldVal) {
    //   console.log(
    //     "watch patientRegister.query.CustomerOrgParentId newVal：",
    //     newVal,
    //     " oldVal：",
    //     oldVal
    //   );
    //   if (newVal != oldVal && newVal !== this.dict.personOrgId) {
    //     this.getCustomerOrgGroup(newVal);
    //   }
    // },
    "patientRegister.photo": {
      immediate: true,
      // deep:true,
      handler(newVal, oldVal) {
        //console.log('patientRegister.patientRegisterRd.id newVal：',newVal,' oldVal：',oldVal)
        if (newVal != oldVal) {
          this.peoplePhoto = photoParse(newVal)
        }
      }
    },

  },
};
</script>
<style scoped>
@import '../../assets/css/global_card.css';
@import '../../assets/css/global_input.css';
@import '../../assets/css/global_table.css';
@import '../../assets/css/global.css';
</style>