<template>
  <div class="diagnosis-list-content">
    <div
      id="screenSet"
      class="component-content screenSet"
    >
      <div class="title">
        编辑
      </div>
      <el-form
        ref="form"
        v-loading="loading"
        :model="formData"
        label-width="130px"
        :rules="editorType == 2 ? null : rules"
      >
        <h1>预约单信息</h1>
        <el-form-item label="预约类型">
          <el-select
            v-model="formData.diagnoseType"
            placeholder="请选择预约类型"
            disabled
            class="set-width"
          >
            <el-option
              v-for="item of tyleList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label="预约来源"
          disabled
        >
          <el-select
            v-model="formData.appointSource"
            placeholder="请选择预约来源"
            disabled
            class="set-width"
          >
            <el-option
              v-for="item of sourceList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="formData.createdTime"
            disabled
            class="set-width"
            type="datetime"
            placeholder="创建时间"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="匹配时间">
          <el-date-picker
            v-model="formData.operateTime"
            disabled
            class="set-width"
            type="datetime"
            placeholder="匹配时间"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="完成时间">
          <el-date-picker
            v-model="formData.doneTime"
            disabled
            class="set-width"
            type="datetime"
            placeholder="匹配时间"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item
          label="问诊价格"
          prop="price"
        >
          <el-input
            v-model="formData.price"
            placeholder="请输入问诊价格"
            disabled
            class="set-width"
          />
          (单位元)
        </el-form-item>
        <el-form-item label="支付方式">
          <el-select
            v-model="formData.payType"
            placeholder="请选择支付方式"
            disabled
            class="set-width"
          >
            <el-option
              v-for="item of payList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="招募人">
          <el-input
            v-model="formData.crrsName"
            placeholder="请输入招募人"
            disabled
            class="set-width"
          />
        </el-form-item>

        <br>
        <h1>预约信息</h1>
        <el-form-item label="当前状态">
          <el-select
            v-model="formData.status"
            placeholder="请选择状态"
            disabled
            class="set-width"
          >
            <el-option
              v-for="item of statusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="运营人员">
          <el-input
            v-model="formData.operateUserName"
            placeholder="请输入患者姓名"
            disabled
            class="set-width"
          />
        </el-form-item>

        <!-- 新增 -->
        <el-form-item label="分诊人员">
          <el-input
            v-model="formData.triageOperatorName"
            placeholder=""
            disabled
            class="set-width"
          />
        </el-form-item>
        <el-form-item label="接诊人员">
          <el-input
            v-model="formData.receptionOperatorName"
            placeholder=""
            disabled
            class="set-width"
          />
        </el-form-item>
        <el-form-item
          label="助诊意向时间"
          prop="appointBeginTime"
        >
          <el-date-picker
            v-model="formData.assistantBeginTime"
            :disabled="true"
            type="datetime"
            placeholder="开始时间"
            style="width: 200px"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
          <span>-</span>
          <el-date-picker
            v-model="formData.assistantEndTime"
            :disabled="true"
            type="datetime"
            placeholder="结束时间"
            style="width: 200px"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="备注（助诊）">
          <span>{{ formData.assistantRemark }}</span>
        </el-form-item>
        <el-form-item label="分诊科室">
          <!-- 由于不可编辑，只展示，故前端option获取接口省略，由前端写死 -->
          <el-select
            v-model="formData.triageDepartmentId"
            placeholder="请选择状态"
            disabled
            class="set-width"
          >
            <el-option
              v-for="item of [
                {
                  value: formData.triageDepartmentId,
                  label: formData.triageDepartment,
                },
              ]"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注（分诊）">
          <span>{{ formData.triageRemark }}</span>
        </el-form-item>
        <el-form-item
          label="接诊意向时间"
          prop="appointBeginTime"
        >
          <el-date-picker
            v-model="formData.receptionBeginTime"
            :disabled="true"
            type="datetime"
            placeholder="开始时间"
            style="width: 200px"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
          <span>-</span>
          <el-date-picker
            v-model="formData.receptionEndTime"
            :disabled="true"
            type="datetime"
            placeholder="结束时间"
            style="width: 200px"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <!-- 新增 -->

        <el-form-item
          label="预约时间"
          prop="appointBeginTime"
        >
          <el-date-picker
            v-model="formData.appointBeginTime"
            :disabled="true"
            type="datetime"
            placeholder="开始时间"
            style="width: 200px"
            :picker-options="endDateOpt"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="continueBeginChange"
          />
          <span>-</span>
          <el-date-picker
            v-model="formData.appointEndTime"
            :disabled="true"
            type="datetime"
            placeholder="结束时间"
            style="width: 200px"
            format="yyyy-MM-dd HH:mm:ss"
            :picker-options="endDateOpt1"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="continueEndChange"
          />
        </el-form-item>

        <br>
        <h1>患者信息</h1>
        <el-form-item
          label="患者姓名"
          prop="patientName"
        >
          <el-input
            v-model="formData.patientName"
            placeholder="请输入患者姓名"
            class="set-width"
            :disabled="noable || editorType == 2"
            minlength="2"
            maxlength="20"
          />
        </el-form-item>
        <el-form-item
          label="证件类型"
          prop="idCardType"
        >
          <el-select
            v-model="formData.idCardType"
            placeholder="请选择证件类型"
            class="set-width"
            :disabled="noable || editorType == 2"
            @change="blurFn"
          >
            <el-option
              v-for="item of carList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label="证件号"
          prop="idCard"
        >
          <el-input
            v-model="formData.idCard"
            placeholder="请输入证件号"
            class="set-width"
            :disabled="noable || editorType == 2"
            maxlength="18"
            @blur="blurFn"
          />
        </el-form-item>
        <el-form-item
          label="出生日期"
          prop="birthdayStr"
        >
          <el-date-picker
            v-model="formData.birthdayStr"
            class="set-width"
            :disabled="noable || birthDisable || editorType == 2"
            type="date"
            placeholder="出生日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item
          label="性别"
          prop="sex"
        >
          <el-select
            v-model="formData.sex"
            placeholder="请选择性别"
            class="set-width"
            :disabled="noable || editorType == 2"
          >
            <el-option
              v-for="item of sexList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label="婚否"
          prop="maritalStatus"
        >
          <el-radio-group
            v-model="formData.maritalStatus"
            :disabled="formData.status == 4 || editorType == 2"
          >
            <el-radio :label="1">
              未婚
            </el-radio>
            <el-radio :label="2">
              已婚
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="患者电话"
          prop="patientMobilePhone"
        >
          <el-input
            v-model="formData.patientMobilePhone"
            placeholder="请输入手机号"
            class="set-width"
            :disabled="noable || editorType == 2"
            maxlength="11"
          />
        </el-form-item>

        <br>
        <h1>助诊信息</h1>
        <el-form-item
          label="助诊医生"
          prop="userName"
        >
          <el-input
            v-model="formData.userName"
            placeholder="请选择助诊医生"
            class="set-width"
            disabled
          />
          <!-- <el-select v-model="formData.userName" placeholder="请选择助诊医生" disabled class="set-width">
                        <el-option v-for="item of sexList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select> -->
        </el-form-item>
        <el-form-item label="助诊医生职称">
          <el-input
            v-model="formData.userTitle"
            placeholder="请选择职称"
            class="set-width"
            disabled
          />
          <!-- <el-select v-model="formData.userTitle" placeholder="请选择职称" disabled class="set-width">
                        <el-option v-for="item of sexList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select> -->
        </el-form-item>
        <el-form-item label="助诊医生所在机构">
          <el-input
            v-model="formData.userHospital"
            placeholder="请选择机构"
            class="set-width"
            disabled
          />
          <!-- <el-select v-model="formData.userHospital" placeholder="请选择机构" disabled class="set-width">
                        <el-option v-for="item of sexList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select> -->
        </el-form-item>
        <el-form-item label="助诊医生所在科室">
          <el-input
            v-model="formData.userDepartment"
            placeholder="请选择科室"
            class="set-width"
            disabled
          />
          <!-- <el-select v-model="formData.userDepartment" placeholder="请选择科室" disabled class="set-width">
                        <el-option v-for="item of sexList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select> -->
        </el-form-item>
        <el-form-item label="助诊电话">
          <el-input
            v-model="formData.userMobile"
            placeholder="请输入助诊医生手机号"
            disabled
            class="set-width"
          />
        </el-form-item>
        <el-form-item label="与患者关系">
          <el-select
            v-model="formData.patientRelation"
            placeholder="请选择与患者关系"
            class="set-width"
            :disabled="editorType == 2"
          >
            <el-option
              v-for="item of relationList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="招募人" v-if="formData.crrsName" prop="crrsName">
                    {{ formData.crrsName }}
                </el-form-item> -->

        <br>
        <h1>接诊信息</h1>
        <el-form-item
          label="接诊医生"
          prop="doctorName"
        >
          <!--                    <el-input v-model="formData.doctorName" placeholder="请选择接诊医生" class="set-width" disabled></el-input>-->
          <el-select
            v-model="formData.doctorName"
            filterable
            placeholder="请选择接诊医生"
            class="set-width"
            disabled
            @change="doctorChanged($event)"
          >
            <el-option
              v-for="item of doctorList"
              :key="item.doctorId"
              :label="item.doctorName"
              :value="item.doctorId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="接诊医生职称">
          <el-input
            v-model="formData.doctorTitle"
            placeholder="请选择职称"
            class="set-width"
            disabled
          />
          <!-- <el-select v-model="formData.doctorTitle" placeholder="请选择职称" disabled class="set-width">
                        <el-option v-for="item of sexList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select> -->
        </el-form-item>
        <el-form-item label="接诊医生所在机构">
          <el-input
            v-model="formData.doctorHospital"
            placeholder="请选择机构"
            class="set-width"
            disabled
          />
          <!-- <el-select v-model="formData.doctorHospital" placeholder="请选择机构" disabled class="set-width">
                        <el-option v-for="item of sexList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select> -->
        </el-form-item>
        <el-form-item label="接诊医生所在科室">
          <el-input
            v-model="formData.doctorDepartment"
            placeholder="请选择机构"
            class="set-width"
            disabled
          />
          <!-- <el-select v-model="formData.doctorDepartment" placeholder="请选择科室" disabled class="set-width">
                        <el-option v-for="item of sexList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select> -->
        </el-form-item>
        <el-form-item label="接诊医生电话">
          <el-input
            v-model="formData.doctorMobile"
            placeholder="请输入接诊医生手机号"
            disabled
            class="set-width"
          />
        </el-form-item>
        <el-form-item label="接诊医生来源">
          <el-select
            v-model="formData.doctorSource"
            placeholder="请选择医生来源"
            class="set-width"
            disabled
          >
            <el-option
              v-for="item of doctorSourceList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="医生服务费" prop="serviceFee">
                    <el-input v-model="formData.serviceFee" placeholder="请输入医生服务费" class="set-width" :disabled="editorType== 2"></el-input> (单位元)
                </el-form-item> -->
        <!-- 新增 -->
        <el-form-item
          label="站外医生姓名"
          prop="outsideDoctor"
        >
          <el-input
            v-model="formData.outsideDoctor"
            placeholder="请输入站外医生姓名"
            class="set-width"
            :disabled="true"
          />
        </el-form-item>
        <!-- -->

        <br>
        <h1>结算信息</h1>
        <el-form-item
          label="接诊服务费"
          prop="receptionServiceFeeStr"
        >
          {{
            formData.receptionServiceFeeStr
              ? `￥ ${formData.receptionServiceFeeStr}`
              : ""
          }}
        </el-form-item>
        <el-form-item
          label="接诊付款方式"
          prop="receptionPayType"
        >
          {{ getReceptionPayType }}
        </el-form-item>
        <el-form-item
          label="接诊付款时间"
          prop="receptionSettleTime"
        >
          {{ formData.receptionSettleTime }}
        </el-form-item>
        <el-form-item
          label="助诊服务费"
          prop="assistantServiceFeeStr"
        >
          {{
            formData.assistantServiceFeeStr
              ? `￥ ${formData.assistantServiceFeeStr}`
              : ""
          }}
        </el-form-item>
        <el-form-item
          label="助诊付款方式"
          prop="assistantPayType"
        >
          {{ getAssistantPayType }}
        </el-form-item>
        <el-form-item
          label="助诊付款时间"
          prop="assistantSettleTime"
        >
          {{ formData.assistantSettleTime }}
        </el-form-item>

        <br>
        <h1>问诊信息</h1>
        <el-form-item
          label="初/复诊"
          prop="diagnoseStage"
        >
          <el-radio-group
            v-model="formData.diagnoseStage"
            :disabled="formData.status == 4 || editorType == 2"
          >
            <el-radio :label="1">
              初诊（就此病没有去过医院）
            </el-radio>
            <el-radio :label="2">
              复诊（就此病去过医院）
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="是否确诊"
          prop="determineFlag"
        >
          <el-radio-group
            v-model="formData.determineFlag"
            :disabled="formData.status == 4 || editorType == 2"
          >
            <el-radio :label="1">
              是
            </el-radio>
            <el-radio :label="2">
              否
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="确诊疾病">
          <el-input
            v-model="formData.diagnoseDisease"
            placeholder="请输入确诊疾病名称"
            :disabled="formData.status == 4 || editorType == 2"
            class="set-width"
          />
        </el-form-item>
        <el-form-item
          label="病情描述"
          prop="illnessDetail"
        >
          <el-input
            v-model="formData.illnessDetail"
            type="textarea"
            placeholder="请输入病情描述"
            maxlength="1000"
            :disabled="editorType == 2"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="病情照片">
          <p class="img-title">
            请上传患处照片、所用药品、与病情相关的线上诊疗记录截图、检查检测报告，请保证图片清晰完整，以便医生确认病情
          </p>
          <upload-img
            ref="imgComponent"
            :is-disable="editorType == 2"
            :img-list="formData.illnessImageUrls"
          />
        </el-form-item>
        <el-form-item
          label="诊断建议"
          prop="diagnoseAdvice"
        >
          <p class="old-diagnoseAdvice">
            {{ oldDiagnoseAdvice }}
          </p>
          <el-input
            v-model="formData.diagnoseAdvice"
            type="textarea"
            placeholder="请输入更新建议（更新后原建议将被删除）"
            :disabled="editorType == 2"
            maxlength="1000"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="系统录音/录像">
          <el-form-item
            v-for="item in formData.vodList"
            :key="item.url"
          >
            <el-link
              :href="item.url"
              target="_blank"
            >
              {{
                diagnoseLogId +
                  "_" +
                  item.name +
                  "_" +
                  formData.doctorName +
                  "_" +
                  formData.doctorDepartment +
                  ".mp4"
              }}
            </el-link>
          </el-form-item>
        </el-form-item>
        <el-form-item label="音频">
          <upload-music
            ref="musicComponent"
            :is-disable="editorType == 2"
            :music-list="formData.illnessAudioUrls"
          />
        </el-form-item>

        <br>
        <!-- 新增 -->
        <h1>备注信息</h1>
        <el-form-item
          label="患者是否在场"
          prop="patInFlag"
        >
          <el-radio-group
            v-model="formData.patInFlag"
            :disabled="editorType == 2"
          >
            <el-radio :label="1">
              是
            </el-radio>
            <el-radio :label="2">
              否
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-show="formData.patInFlag == 1"
          label="是否有价值"
          prop="valueFlag"
        >
          <el-radio-group
            v-model="formData.valueFlag"
            :disabled="editorType == 2"
          >
            <el-radio :label="1">
              是
            </el-radio>
            <el-radio :label="2">
              否
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-show="formData.valueFlag == 2 && formData.patInFlag == 1"
          label=""
          prop="worthlessReason"
        >
          <el-input
            v-model="formData.worthlessReason"
            type="textarea"
            placeholder="请输入低价值说明"
            maxlength="1000"
            :disabled="editorType == 2"
            show-word-limit
          />
        </el-form-item>
        <el-form-item
          label="其他备注"
          prop="otherRemark"
        >
          <el-input
            v-model="formData.otherRemark"
            type="textarea"
            placeholder="请输入其他备注信息"
            maxlength="1000"
            :disabled="editorType == 2"
            show-word-limit
          />
        </el-form-item>
        <!-- -->

        <br>
        <h1>跟进信息</h1>
        <el-form-item label="是否跟进">
          <el-radio-group
            v-model="formData.followFlag"
            :disabled="editorType == 2"
          >
            <el-radio :label="1">
              是
            </el-radio>
            <el-radio :label="2">
              否
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="药品跟进状态">
          <el-select
            v-model="formData.drugFollowStatus"
            placeholder="请跟进状态"
            class="set-width"
            :disabled="editorType == 2"
          >
            <el-option
              v-for="item of followList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="药品跟进">
          <el-input
            v-model="formData.drugFollow"
            type="textarea"
            placeholder="请输入可跟进的事项"
            maxlength="1000"
            :disabled="editorType == 2"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="检查跟进状态">
          <el-select
            v-model="formData.checkFollowStatus"
            placeholder="请跟进状态"
            class="set-width"
            :disabled="editorType == 2"
          >
            <el-option
              v-for="item of followList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="检查跟进">
          <el-input
            v-model="formData.checkFollow"
            type="textarea"
            placeholder="请输入可跟进的事项"
            maxlength="1000"
            :disabled="editorType == 2"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="其他跟进状态">
          <el-select
            v-model="formData.otherFollowStatus"
            placeholder="请跟进状态"
            class="set-width"
            :disabled="editorType == 2"
          >
            <el-option
              v-for="item of followList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="其他跟进">
          <el-input
            v-model="formData.otherFollow"
            type="textarea"
            placeholder="请输入可跟进的事项"
            maxlength="1000"
            :disabled="editorType == 2"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="formData.remark"
            type="textarea"
            placeholder="请输入备注信息，如沟通协商记录等"
            maxlength="1000"
            :disabled="editorType == 2"
            show-word-limit
          />
        </el-form-item>

        <br>
        <!-- -->
        <h1>操作日志</h1>
        <el-table
          :data="logData"
          class="log-info"
        >
          <el-table-column
            prop="operateTime"
            width="180"
            label="变更时间"
          />
          <el-table-column
            prop="operateUserName"
            label="变更人"
            width="120"
          />

          <el-table-column
            prop="to"
            label="变更后内容"
          />
          <el-table-column
            prop="from"
            label="变更前内容"
          />
        </el-table>
        <!-- 与产品确认，不需要分页功能<br/>
                <el-row :gutter="0" type="flex" justify="end" align="center">
                    <el-pagination
                        class="log-info-pagin"
                        @size-change="handlelogSizeChange"
                        @current-change="handlelogCurrentChange"
                        :current-page="logCurrentPage"
                        :page-sizes="[5, 10, 20, 50]"
                        :page-size="5"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="logTotalCount">
                    </el-pagination>
                </el-row>-->
        <!-- -->
      </el-form>

      <br>
      <el-row
        :gutter="60"
        type="flex"
        justify="center"
        align="center"
      >
        <el-button @click="cancle">
          {{ editorType == 1 ? "取消" : "返回" }}
        </el-button>
        <el-button
          v-if="editorType == 1"
          type="primary"
          :disabled="btnDisable"
          @click="save"
        >
          保存
        </el-button>
      </el-row>
    </div>
  </div>
</template>
<script>
  import uploadImg from '@/components/editor/upload-img';
  import uploadMusic from '@/components/editor/upload-music';
  import {
    TYPE_LIST,
    PAY_LIST,
    SOURCE_LIST,
    STATUS_LIST,
    CAR_LIST,
    SEX_LIST,
    RELATION_LIST,
    D_S_LIST,
    FOLLW_LIST,
  } from '@/utils/constants';
  import { getBirth } from '@/utils/index';
  import { getAdminDiagnose, getDoctorList, getDiagnoseLog, diagnoseUpdate } from '@/api/diagnosis';

  const PAY_TYPE = {
    1: '自动付款',
    2: '手动付款',
  };
  export default {
    components: {
      uploadImg,
      uploadMusic,
    },
    data() {
      return {
        asd: 123,
        diagnoseLogId: '',
        birthDisable: false,
        noable: false,
        editorType: 1, //   //1为编辑状态，2为查看
        loading: true,
        btnDisable: false,
        oldDiagnoseAdvice: '', // 旧的诊断建议
        formData: {
          // 预约单信息
          diagnoseType: '',
          appointSource: '',
          createdTime: '',
          operateTime: '',
          doneTime: '',
          payType: '',
          crrsName: '',
          // 预约信息
          status: 1,
          operateUserName: '',
          appointBeginTime: '',
          appointEndTime: '',
          triageOperatorName: '', // 分诊人员姓名
          receptionOperatorName: '', // 接诊人员姓名
          assistantBeginTime: '', // 助诊意向开始时间
          assistantEndTime: '', // 助诊意向结束时间
          assistantRemark: '', // 助诊备注
          triageDepartmentId: '', // 分诊科室id,
          triageDepartment: '', // 分诊科室名
          triageRemark: '', // 分诊备注
          receptionBeginTime: '', // 接诊意向开始时间
          receptionEndTime: '', // 接诊意向结束时间
          // 患者信息
          patientName: '',
          idCardType: 1,
          idCard: '',
          birthdayStr: '',
          birthday: '',
          sex: 1,
          patientMobilePhone: '',
          // 助诊信息
          userName: '',
          userTitle: '',
          userHospital: '',
          userDepartment: '',
          userMobile: '',
          patientRelation: '',
          // crrsName: '', // 招募人
          // 医生信息
          doctorName: '',
          doctorTitle: '',
          doctorHospital: '',
          doctorDepartment: '',
          doctorMobile: '',
          doctorSource: '',
          serviceFee: '',
          outsideDoctor: '', // 站外医生姓名
          // 问诊信息
          diagnoseStage: '',
          determineFlag: '',
          diagnoseDisease: '',
          illnessDetail: '',
          illnessImageUrls: [],
          diagnoseAdvice: '',
          illnessAudioUrls: [],
          followFlag: 1,
          drugFollow: '',
          drugFollowStatus: '',
          checkFollow: '',
          checkFollowStatus: '',
          otherFollowStatus: '',
          otherFollow: '',
          remark: '',
          maritalStatus: 2,
          createType: 1, // //创建方式1.系统创建 2.手动创建
          // 备注信息
          patInFlag: '', // 患者是否在场 1是 2否
          valueFlag: '', // 是否有价值 1是 2否
          worthlessReason: '', // 无价值原因
          otherRemark: '', // 其他备注
          // 结算信息
          receptionServiceFee: 0, // 接诊医生服务费单位分
          receptionServiceFeeStr: '', // 接诊医生服务费展示字段
          receptionPayType: '', // 接诊医生付款方式1自动打款2手动打款
          receptionSettleTime: '', // 接诊医生结算时间
          assistantServiceFee: 0, // 助诊医生服务费单位分
          assistantServiceFeeStr: '', // 助诊医生服务费展示字段
          assistantPayType: '', // 助诊医生付款方式1自动打款2手动打款
          assistantSettleTime: '', // 助诊医生结算时间
          // 录像信息
          vodList: {
            name: '',
            url: '',
          },
        },
        tyleList: TYPE_LIST,
        payList: PAY_LIST,
        sourceList: SOURCE_LIST,
        statusList: STATUS_LIST,
        carList: CAR_LIST,
        sexList: SEX_LIST,
        relationList: RELATION_LIST,
        doctorSourceList: D_S_LIST,
        followList: FOLLW_LIST,
        doctorList: [],
        rules: {
          appointBeginTime: [
            { required: true, message: '请输入预约时间', trigger: 'change' },
          ],
          patientName: [
            {
              required: true,
              message: '请输入患姓名',
              trigger: ['blur', 'change'],
            },
            {
              min: 2,
              max: 20,
              message: '长度在 2 到 20 个字符',
              trigger: ['blur', 'change'],
            },
          ],
          idCardType: [
            { required: true, message: '请选择证件类型', trigger: 'change' },
          ],
          idCard: [
            { min: 18, message: '长度18个字符', trigger: 'blur' },
            { pattern: /[0-9A-Za-z]{6,24}$/, message: '只能是数字或字母' },
          ],
          birth: [{ required: true, message: '请选择生日', trigger: 'change' }],
          sex: [{ required: true, message: '请选择性别', trigger: 'change' }],
          maritalStatus: [
            { required: true, message: '请选择婚否', trigger: 'change' },
          ],
          patientMobilePhone: [
            {
              required: true,
              message: '请输入患者电话',
              trigger: ['blur', 'change'],
            },
          ],
          doctorName: [
            { required: true, message: '请选择接诊医生', trigger: 'change' },
          ],
          serviceFee: [
            { required: false, message: '请输入医生服务费', trigger: 'change' },
            {
              pattern:
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
              message: '请输入正确额格式,可保留两位小数',
            },
          ],
          diagnoseStage: [
            { required: true, message: '请选择初/复诊', trigger: 'change' },
          ],
          determineFlag: [
            { required: true, message: '是否确诊', trigger: 'change' },
          ],
          illnessDetail: [
            { required: true, message: '请输入病情描述', trigger: 'change' },
          ],
          diagnoseAdvice: [
            { required: true, message: '请输入诊断建议', trigger: 'change' },
          ],
          worthlessReason: [
            {
              required: true,
              min: 2,
              max: 1000,
              message: '必填项，支持2-1000个字符',
              trigger: 'change',
            },
          ],
          otherRemark: [
            {
              required: true,
              min: 2,
              max: 1000,
              message: '必填项，支持2-1000个字符',
              trigger: 'change',
            },
          ],
          patInFlag: [
            {
              required: true,
              message: '必填项',
            },
          ],
          valueFlag: [
            {
              required: true,
              message: '必填项',
            },
          ],
        },
        endDateOpt: {
          disabledData: (time) => {
            if (
              this.formData.appointEndTime != '' &&
              this.formData.appointEndTime != null
            ) {
              return (
                time.getTime() > new Date(this.formData.appointEndTime).getTime()
              );
            }
          },
        },
        endDateOpt1: {
          disabledDate: (time) => {
            return (
              time.getTime() < new Date(this.formData.appointBeginTime).getTime()
            );
          },
        },
        // 操作日志数据
        /* 元素结构
             {
                operateTime: '2016-05-02',
                operateUserName: '赵丽颖',
                to: '问诊状态由已完成变成已结算',
                from: '助诊医生时间不匹配'
            }
            */
        logData: [],
      // 分页功能与产品沟通不做
      // logCurrentPage: 1,
      // logTotalCount: 0
      };
    },
    computed: {
      getReceptionPayType() {
        return PAY_TYPE[this.formData.receptionPayType];
      },
      getAssistantPayType() {
        return PAY_TYPE[this.formData.assistantPayType];
      },
    },
    created() {
      this.editorType = this.$route.query.editorType;
      this.diagnoseLogId = this.$route.query.id;
      this.search();
    },
    mounted() {},
    methods: {
      search() {
        this.loading = true;
        getAdminDiagnose({
          id: this.diagnoseLogId,
        })
          .then((res) => {
            this.loading = false;
            if (res.code == '000000') {
              this.formData = res.data;
              this.formData.price = this.priceFilter(this.formData.price);
              this.formData.serviceFee = this.priceFilter(
                this.formData.serviceFee
              );
              if (!this.formData.illnessImageUrls) {
                this.formData.illnessImageUrls = [];
              } else {
                this.formData.illnessImageUrls = this.setObjectArr(
                  this.formData.illnessImageUrls
                );
              }
              if (!this.formData.illnessAudioUrls) {
                this.formData.illnessAudioUrls = [];
              } else {
                this.formData.illnessAudioUrls = this.setObjectArr(
                  this.formData.illnessAudioUrls
                );
              }
              if (this.formData.diagnoseAdvice) {
                this.oldDiagnoseAdvice = this.formData.diagnoseAdvice;
                this.formData.diagnoseAdvice = '';
              }
              if (!this.formData.sex) {
                this.formData.sex = 1;
              }
              if (!this.formData.maritalStatus) {
                this.formData.maritalStatus = 1;
              }
            } else {
              this.$message.info('请稍后重试');
            }
            this.getDoctorList();
            this.queryOperationLogs();
          })
          .catch(() => {
            this.$message.info('请稍后重试');
          });
      },
      getDoctorList() {
        this.loading = true;
        getDoctorList({
          diagnoseType:this.formData.diagnoseType
        })
          .then((res) => {
            this.loading = false;
            if (res.code == '000000') {
              this.doctorList = res.data;
            } else {
              this.$message.info('请稍后重试');
            }
          })
          .catch(() => {
            this.loading = false;
            this.$message.info('请稍后重试');
          });
      },
      queryOperationLogs() {
        getDiagnoseLog({
          id:this.diagnoseLogId
        })
          .then((res) => {
            if (res.code == '000000') {
              this.logData = res.data;
            }
          // 非交互性功能接口不提示
          })
          .catch(() => {
            this.loading = false;
          });
      },
      // 预约开始时间选择时
      continueBeginChange(val) {
        if (this.formData.appointEndTime) {
          if (
            new Date(val).getTime() >
            new Date(this.formData.appointEndTime).getTime()
          ) {
            this.$message.info('开始时间要小于结束时间');
            this.formData.appointBeginTime = '';
            return;
          }
        }
      },
      // 预约结束时间选择时
      continueEndChange(val) {
        if (this.formData.appointBeginTime) {
          if (
            new Date(val).getTime() <=
            new Date(this.formData.appointBeginTime).getTime()
          ) {
            this.$message.info('结束时间要大于开始时间');
            this.formData.appointEndTime = '';
            return;
          }
        }
      },
      blurFn() {
        if (
          this.formData.idCardType == 1 &&
          this.formData.idCard &&
          this.formData.idCard.length == 18
        ) {
          this.formData.birthdayStr = getBirth(this.formData.idCard);
          this.birthDisable = true;
        } else {
          this.formData.birthdayStr = '';
          this.birthDisable = false;
        }
      },
      cancle() {
        this.$router.back();
      },
      priceFilter(value) {
        if (!value) return 0;
        if (value) {
          return value / 100;
        }
      },
      setPrice(value) {
        if (!value) return 0;
        if (value) {
          return value * 100;
        }
      },
      doctorChanged(value) {
        const selected = this.doctorList.find((item) => item.doctorId === value);
        if (selected) {
          this.formData.doctorId = value;
          this.formData.doctorName = selected.doctorName;
          this.formData.doctorTitle = selected.doctorTitle;
          this.formData.doctorHospital = selected.doctorHospital;
          this.formData.doctorDepartment = selected.doctorDepartment;
          this.formData.doctorMobile = selected.doctorMobile;
          this.formData.serviceFee = this.priceFilter(selected.serviceFee);
        }
      },
      save() {
        this.$refs.form.validate((valid) => {
          this.formData.birthday = new Date(this.formData.birthdayStr);
          // this.formData.birthday = this.formData.birthdayStr;
          const params = JSON.parse(JSON.stringify(this.formData));
          params.illnessImageUrls = this.$refs.imgComponent
            ? [...this.$refs.imgComponent.setNewArr()]
            : [];
          params.illnessAudioUrls = this.$refs.musicComponent
            ? [...this.$refs.musicComponent.setNewArr()]
            : [];
          params.price = this.setPrice(params.price);
          params.serviceFee = this.setPrice(params.serviceFee);
          if (!params.diagnoseAdvice) {
            params.diagnoseAdvice = this.oldDiagnoseAdvice;
          }
          this.loading = true;
          this.btnDisable = true;
          diagnoseUpdate(params)
            .then((res) => {
              this.loading = false;
              this.btnDisable = false;
              if (res.code == '000000') {
                this.$message.success('保存成功');
                this.$router.back();
              } else {
                this.$message({
                  message: res.message,
                  type: 'error',
                });
              }
            })
            .catch(() => {
              this.btnDisable = false;
              this.loading = false;
            });

        });
      },
      // 格式话音频/视频数组
      setObjectArr(array) {
        const newArr = [];
        array.forEach((element) => {
          newArr.push({ from: 'all', url: element });
        });
        return newArr;
      },

    },
  };
</script>
<style lang="scss" scoped>
.diagnosis-list-content {
  .component-content {
    padding: 10px;
    background: #fff;
    overflow: hidden !important;
    .title {
      margin-bottom: 30px;
    }
    .img-title {
      margin-top: 20px;
      font-size: 14px;
      color: #6d8bc7;
      line-height: 40px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
    }
    .old-diagnoseAdvice {
      margin-top: 20px;
      font-size: 14px;
      color: #9197a3;
      line-height: 40px;
    }
    .set-width {
      width: 300px;
    }
    .log-info {
      margin: 15px auto;
      width: calc(100% - 30px);
    }
    .log-info-pagin {
      margin: 0 15px;
    }
  }
  .btn-wrap {
    padding: 40px 0 60px;
    margin: 0 auto;
  }
}
</style>
