<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="公司名称" prop="companyId">
        <el-select v-model="queryParams.companyId" placeholder="请选择所属公司" filterable clearable size="small">
          <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="员工姓名" prop="companyUserNickName">
        <el-input v-model="queryParams.companyUserNickName" placeholder="请输入员工名称" clearable size="small" @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="订单号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报告编号" prop="reportSn">
        <el-input
          v-model="queryParams.reportSn"
          placeholder="请输入报告编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子类型" prop="inquirySubType">
        <el-select v-model="queryParams.inquirySubType" placeholder="子类型" clearable size="small">
          <el-option v-for="dict in inquirySubTypeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="患者名称" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="patientMobile">
        <el-input
          v-model="queryParams.patientMobile"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="导医" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入导医"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医生名称" prop="doctorName">
        <el-input
          v-model="queryParams.doctorName"
          placeholder="请输医生名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="咨询状态" prop="inquiryStatus">
        <el-select v-model="queryParams.inquiryStatus" placeholder="状态" clearable size="small">
          <el-option
            v-for="dict in inquiryStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="所属小程序" prop="coursePlaySourceConfigId">
        <el-select v-model="queryParams.coursePlaySourceConfigId" placeholder="请选择所属小程序" clearable size="small">
          <el-option
            v-for="dict in appMallOptions"
            :key="dict.id"
            :label="dict.name + '(' + dict.appid + ')'"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="提交时间" prop="createTime">
        <el-date-picker v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
      </el-form-item>
      <el-form-item label="首次分诊时间" prop="updateTime">
        <el-date-picker v-model="updateTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['his:inquiryOrderReport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-tabs type="card" v-model="actName" @tab-click="handleClickX">
      <el-tab-pane label="全部订单" name="10"></el-tab-pane>
      <el-tab-pane v-for="(item,index) in statusOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>
    <el-table height="570" v-loading="loading" border :data="inquiryOrderReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="订单号" align="center" prop="orderId" /> -->
      <el-table-column label="报告编号" align="center" prop="reportSn" width="170px"/>
      <el-table-column label="会员昵称" align="center" prop="nickName" />
      <el-table-column label="患者名称" align="center" prop="patientName" />
      <el-table-column label="会员电话" align="center" prop="phone" width="130px"/>
      <el-table-column label="医生名称" align="center" prop="doctorName" />
      <el-table-column label="公司" align="center" prop="companyName" />
      <el-table-column label="员工" align="center" prop="companyUserName" />
      <el-table-column label="小程序名称" align="center" prop="miniProgramName" width="120px" />
      <el-table-column label="咨询结果" align="center" prop="inquiryResult" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="statusOptions" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="inquiryStatus" >
        <template slot-scope="scope">
          <dict-tag :options="inquiryStatusOptions" :value="scope.row.inquiryStatus" />
        </template>
      </el-table-column>
      <el-table-column label="导医" align="center" prop="userName" />
	  <el-table-column label="分诊人" align="center" prop="fzName" />
      <el-table-column label="订单子类型" align="center" prop="inquirySubType" width="90px">
            <template slot-scope="scope">
              <dict-tag :options="inquirySubTypeOptions" :value="scope.row.inquirySubType"/>
            </template>
      </el-table-column>

      <el-table-column label="提交时间" align="center" prop="createTime" width="180"/>
      <el-table-column label="首次分诊时间" align="center" prop="updateTime" width="180"/>
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status==0&&scope.row.inquiryStatus>1"
            size="mini"
            type="text"
            icon="el-icon-edit-outline"
            @click="handleAudit(scope.row)"
            v-hasPermi="['his:inquiryOrderReport:audit']"
          >分诊</el-button>
          <el-button v-if="scope.row.status==1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['his:inquiryOrderReport:edit']"
          >修改</el-button>
          <el-button
                size="mini"
                type="text"
                @click="handledetails(scope.row)"
           >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
<!-- <el-dialog title="用户提交表单内容" :visible.sync="showOpen" width="50%" append-to-body >
    <el-descriptions title="" :column="3" border >
        <el-descriptions-item :label="form.title" v-for=" form in formJson" >
        <div v-for="x in form.option" > {{x}};</div>
       </el-descriptions-item>
    </el-descriptions> -->

 <!-- <el-row>
    <el-col :span="8" v-for="form in formJson"  >
      <el-card class="box-card" style="margin-bottom: 10px; margin-right: 10px;">
           <div slot="header" class="clearfix">
              <span style="font-weight: bold;"> {{form.title}}</span>
            </div>
            <div style="height: 50px;">
              <div v-for="x in form.option" > {{x}};</div>
            </div>
      </el-card>
    </el-col>
  </el-row> -->
<!--      <div slot="footer" class="dialog-footer">
        <el-button @click="showOpen=false">关  闭</el-button>
      </div>
    </el-dialog> -->

<el-dialog title="搜索咨询结果" :visible.sync="selectOpen" width="50%" append-to-body >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" >

        <el-form-item label="搜索" prop="name">
          <el-input v-model="selectForm.name" placeholder="请输入内容" class="input-with-select"
        onkeypress="if (event.keyCode == 13) return false">
            <el-button icon="el-icon-search" slot="append"  @click="Method(selectForm.name)" size="mini" ></el-button>
          </el-input>
        </el-form-item>
        <el-card class="box-card" v-for="item in illnessList" style="margin-left: 30px;margin-bottom: 20px;" >
             <div slot="header" class="clearfix">
                <span style="font-weight: bold;"> {{item.illnessName}}</span>
                <el-button style="float: right; padding: 3px 0" type="text" @click="selectOK(item)">添加</el-button>
              </div>
          <el-row>
            <el-col :span="22" >
              <div> </div>
              <div> <span style="font-weight: bold;"> 舌脉:</span>  {{item.tongueVein}} </div>
              <div> <span style="font-weight: bold;"> 治法:</span>  {{item.formulaName}}</div>
               <div> <span style="font-weight: bold;"> 用药:</span>  {{item.formulaDescs}}</div>
            </el-col>
          </el-row>
        </el-card>
        <pagination
          v-show="selectTotal>0"
          :total="selectTotal"
          :page.sync="selectForm.pageNum"
          :limit.sync="selectForm.pageSize"
          @pagination="getIllnessList"
        />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="selectOpen=false">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 添加或修改咨询报告对话框 -->
    <el-dialog :title="title " :visible.sync="open" width="70%" append-to-body :close-on-click-modal ="false" >
      <el-descriptions title="" :column="3" border>
        <el-descriptions-item label="患者姓名" ><span v-if="json!=null&&json!=''">{{json.patientName}}</span></el-descriptions-item>
        <el-descriptions-item label="患者年龄" ><span v-if="json!=null&&json!=''">{{json.age}}</span></el-descriptions-item>
        <el-descriptions-item label="患者性别" ><span v-if="json!=null&&json!=''">{{json.sex==1?'男':'女'}}</span></el-descriptions-item>
        <el-descriptions-item label="身份证号" ><span v-if="json!=null&&json!=''">{{json.idCard}}</span></el-descriptions-item>
        <el-descriptions-item label="体重" ><span v-if="json!=null&&json!=''">{{json.weight}}</span></el-descriptions-item>
        <el-descriptions-item label="身高" ><span v-if="json!=null&&json!=''">{{json.height}}</span></el-descriptions-item>
        <el-descriptions-item label="BMI" ><span v-if="json!=null&&json!=''">{{bmi}}</span></el-descriptions-item>
        <el-descriptions-item label="肥胖类型"><span v-if="json!=null&&json!=''">{{fat}}</span></el-descriptions-item>
        <el-descriptions-item label="电话" ><span v-if="json!=null&&json!=''">{{json.mobile}}</span>
          <el-button icon="el-icon-search" size="mini" @click="handlePhone()" style="margin-left: 20px;" circle v-hasPermi="['his:inquiryOrderReport:queryPatientMobile']"></el-button>
        </el-descriptions-item>
        <el-descriptions-item label="学习周期" ><span v-if="json!=null&&json!=''">{{json.study}}</span></el-descriptions-item>
        <el-descriptions-item label="期望咨询方式" ><span v-if="json!=null&&json!=''">{{json.usage}}</span></el-descriptions-item>
        <el-descriptions-item label="正在服药" ><span v-if="json!=null&&json!=''">{{json.drugs}}</span></el-descriptions-item>
        <el-descriptions-item label="用药情况" ><span v-if="json!=null&&json!=''">{{json.medication}}</span></el-descriptions-item>

        <el-descriptions-item label="咨询问题" span="3"><span v-if="json!=null&&json!=''">{{json.title}}</span></el-descriptions-item>
        <el-descriptions-item label="咨询备注"><span v-if="form!=null">{{form.companyUserRemark}}</span></el-descriptions-item>
        <el-descriptions-item label="面部照片" span="3">
                  <el-image v-if="faceImages!=null&&faceImages!=''" v-for="img in faceImages" :key="img.id"
                          style="width: 100px"
                          :src="img"
                          :preview-src-list="[img]">
                  </el-image>
        </el-descriptions-item>
        <el-descriptions-item label="舌苔照片" span="3">
            <el-image v-if="tongueImages!=null&&tongueImages!=''" v-for="img in tongueImages" :key="img.id"
                    style="width: 100px"
                    :src="img"
                    :preview-src-list="[img]">
            </el-image>
           </el-descriptions-item>
        <el-descriptions-item label="检测报告或患病证书" span="3">
              <el-image v-if="imgs!=null&&imgs!=''"  v-for="img in imgs" :key="img.id"
                      style="width: 100px"
                      :src="img"
                      :preview-src-list="[img]">
              </el-image>
        </el-descriptions-item>
      </el-descriptions>

    <div style="margin-top: 50px;"></div>


        <el-row>
          <el-col :span="24">
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
              <el-form-item label="疾病类型" prop="tags">
                <el-select v-model="diseaseType" multiple placeholder="请选择疾病类型" filterable clearable remote reserve-keyword :remote-method="diseaseMethod" size="small">
                  <el-option
                    v-for="dict in diseaseTypeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="咨询结果" prop="inquiryResult">
                    <el-input v-model="form.inquiryResult" placeholder="请输入内容" class="input-with-select">
                      <el-button icon="el-icon-search" slot="append" @click="selectInquiryResult"></el-button>
                    </el-input>
              </el-form-item>
              <el-form-item label="选择体质" prop="bodyValue" >
                    <el-select v-model="bodyValue" placeholder="体质" clearable size="small" @change="changeBofy()">
                        <el-option
                          v-for="dict in body"
                          :key="dict.itemType"
                          :label="dict.itemType"
                          :value="dict.item"
                        />
                    </el-select>
              </el-form-item>



              <el-form-item v-for=" plan in conditioningPlanJson" :label="plan.name=='用药调治'?'健康建议':plan.name" prop="conditioningPlanJson">
                <el-input v-model="plan.value" type="textarea" placeholder="请输入内容" maxlength="1000" show-word-limit  :rows="4"/>
              </el-form-item>
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"  maxlength="1000" show-word-limit :rows="4"/>
              </el-form-item>
              <el-form-item label="医生" prop="doctorId" v-if="title=='咨询报告分诊'">
                <el-select v-model="form.doctorId" filterable placeholder="输入名称搜索" :filter-method="doctorMethod" clearable>
                  <el-option
                    v-for="item in docuser"
                    :key="item.name"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-form>

          </el-col>
         <!-- <el-col :span="5" :offset="1">
            <div  style="background-color: white;" >
              <el-descriptions title="" :column="1" border >
                  <el-descriptions-item :label="form.title" v-for=" form in formJson" >
                  <div v-for="x in form.option" > {{x}};</div>
                 </el-descriptions-item>
              </el-descriptions>
            </div>

          </el-col> -->
      </el-row>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
          <el-button type="info" v-if="title == '咨询报告分诊'" @click="save" >保存</el-button>
        </div>
    </el-dialog>

    <el-drawer
    	:with-header="false"
            size="75%"
             :title="show.title" :visible.sync="show.open">
         <inquiryOrderReportDetails  ref="Details" />
       </el-drawer>
  </div>
</template>

<script>
import { listInquiryOrderReport, getInquiryOrderReport,getBody, delInquiryOrderReport, addInquiryOrderReport, updateInquiryOrderReport, updateInquiryOrderReportAudit, exportInquiryOrderReport,updateAuditReport,getPatientMobile } from "@/api/his/inquiryOrderReport";
import inquiryOrderReportDetails from '../../components/his/inquiryOrderReportDetails.vue';
import { listBySearch } from "@/api/his/inquiryDisease";
import {listdocuser} from "@/api/his/doctor";
import { getIllness } from "@/api/his/illnessLibrary";
import {allList}from "@/api/company/company";
import { getTask } from "@/api/common";
import {list as getAppMallOptions} from '@/api/course/coursePlaySourceConfig';
export default {
  name: "InquiryOrderReport",
  components: { inquiryOrderReportDetails },
  data() {
    return {
      diseaseParams:{
        diseaseId:null,
        diseaseName:null
      },
      diseaseType:[],
      show:{
              open:false,
            },
      imgs:[],
      fat:null,
      json:{patientName:"111"},
      diseaseTypeOptions:[],
      faceImages:[],
      tongueImages:[],
      bmi:null,
      docuser:[],
      conditioningPlanJson:[{"name":"解析","value":""},{"name":"健康建议","value":""},{"name":"饮食调养","value":""},{"name":"运动调理","value":""},{"name":"精神调适","value":""},{"name":"起居调摄","value":""}],
      actName:"0",
      selectForm:{
        name: null,
        pageNum: 1,
        pageSize: 10,
      },
      body:[],
      bodyValue:[],
      showOpen:false,
      selectTotal: 0,
      formJson:null,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      illnessList:[],
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      selectOpen:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 咨询报告表格数据
      inquiryOrderReportList: [],
      inquiryStatusOptions: [],
      // 弹出层标题
      title: "",
      createTime:null,
      updateTime:null,
      // 是否显示弹出层
      open: false,
      // 状态 0待处理 1已处理字典
      statusOptions: [],
      doctorName: {name:"1"},
      inquiryStatusOptions:[],
      inquirySubTypeOptions:[],
      companyList:[],
      appMallOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        userId: null,
        patientId: null,
        doctorId: null,
        reportSn: null,
        createTime: null,
        status: 0,
        sTime:null,
        eTime:null,
        userName: null,
        inquiryStatus:null,
        doctorName:null,
        coursePlaySourceConfigId:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: '状态不能为空', trigger: 'blur' }
        ],
      }
    };
  },
  created() {
    this.getList();
    // this.getDicts("sys_inquiry_order_report_disease_type").then(response => {
    //   this.diseaseTypeOptions = response.data;
    // });
    this.getDicts("sys_inquiry_status").then(response => {
        this.inquiryStatusOptions = response.data;
      });
    this.getDicts("sys_inquiry_status").then(response => {
        this.inquiryStatusOptions = response.data;
      });
    this.getDicts("sys_inquiry_order_report_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_inquiry_sub_type").then(response => {
      this.inquirySubTypeOptions = response.data;
    });
    getBody().then(response => {
          this.body=response;
      });
    
    // 获取小程序选项列表
    this.getAppMallOptions();
    
    this.getAllCompany();
  },
  methods: {
    diseaseMethod(query){
      if (query !== '') {
        this.diseaseParams.diseaseName = query;
        listBySearch(this.diseaseParams).then(response => {
          this.diseaseTypeOptions = response.rows;
        });
      }
    },
    handlePhone(){
        const reportId = this.form.reportId;
        getPatientMobile(reportId).then(response =>{
            this.json.mobile = response.mobile;
        })
      },
    changeBofy(rows){

      if(this.bodyValue!=null&&this.bodyValue!=""){
        this.conditioningPlanJson.find(item => item.name === "饮食调养").value =this.bodyValue.find(item => item.name === "饮食调养").value;
        this.conditioningPlanJson.find(item => item.name === "运动调理").value =this.bodyValue.find(item => item.name === "运动调理").value;
        this.conditioningPlanJson.find(item => item.name === "精神调适").value =this.bodyValue.find(item => item.name === "精神调适").value;
        this.conditioningPlanJson.find(item => item.name === "起居调摄").value =this.bodyValue.find(item => item.name === "起居调摄").value;
      }

    },
    getAllCompany() {
      allList().then(response => {
        this.companyList = response.rows;
      });
    },
    // 获取小程序选项列表
    getAppMallOptions() {
      getAppMallOptions({pageNum:1,pageSize:100,isMall:1}).then(response => {
        this.appMallOptions = response.rows;
      })
    },
    selectOK(rows){

      if(this.form.inquiryResult==null){
        this.form.inquiryResult=rows.illnessName;
        this.conditioningPlanJson.find(item => item.name === "健康建议").value =rows.formulaName+":"+rows.formulaDescs;
        this.conditioningPlanJson.find(item => item.name === "解析").value = "舌脉:"+rows.tongueVein+"\n症状:"+rows.symptom;
      }else{
        this.form.inquiryResult+=","+rows.illnessName;
        this.conditioningPlanJson.find(item => item.name === "健康建议").value +="\n"+ rows.formulaName+":"+rows.formulaDescs;
        this.conditioningPlanJson.find(item => item.name === "解析").value += "\n舌脉:"+rows.tongueVein+"\n症状:"+rows.symptom;
      }
      this.selectOpen=false;
    },
    selectInquiryResult(){
      this.selectOpen=true;
    },
    getIllnessList(){
        getIllness(this.selectForm).then(response => {
          this.illnessList=response.rows;
          this.selectTotal=response.total;
      });
    },
    showForm(){
      this.showOpen=true;
    },
    Method(rows){
      this.selectForm.name=rows.trim();
      if(this.selectForm.name!=null&&this.selectForm.name!=""){
         this.getIllnessList();
      }
    },
    resultChange(rows){
        const filteredList = this.illnessList.find(item => item.illnessName === rows);
        this.conditioningPlanJson.find(item => item.name === "健康建议").value = filteredList.formulaName+":"+filteredList.formulaDescs;
        this.conditioningPlanJson.find(item => item.name === "解析").value = "舌脉:"+filteredList.tongueVein+"\n症状:"+filteredList.symptom;
    },
    /** 查询咨询报告列表 */
    getList() {
      this.loading = true;
      listInquiryOrderReport(this.queryParams).then(response => {
        this.inquiryOrderReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getlistdocuser(){
        listdocuser(this.doctorName).then(response => {
          this.docuser=response.rows;
      });
    },
    doctorMethod(rows){
      this.doctorName.name=rows;
      this.getlistdocuser();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        reportId: null,
        orderId: null,
        userId: null,
        patientId: null,
        patientJson: null,
        doctorId: null,
        reportSn: null,
        patientDescs: null,
        illnessLogs: null,
        drugLogs: null,
        inquiryResult: null,
        formJson: null,
        conditioningPlanJson: null,
        createTime: null,
        remark: null,
        updateTime: null,
        status: 0
      };
      this.diseaseType=[],
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.createTime=null;
      this.updateTime=null;
      this.queryParams.sTime=null;
      this.queryParams.eTime=null;
      this.queryParams.beginTime=null;
      this.queryParams.endTime=null;
      this.queryParams.coursePlaySourceConfigId=null;
      // 注意：不重置status，保持当前tab状态
      // this.queryParams.status 保持不变
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.reportId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加咨询报告";
      this.bodyValue=null;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.bodyValue=null;
      this.json=null;
      this.imgs=null;
      this.tongueImages=null;
      this.faceImages=null;
      this.diseaseTypeOptions=[];
      this.conditioningPlanJson=[{"code":"item1","name":"解析","value":""},{"code":"item2","name":"健康建议","value":""},{"code":"item3","name":"饮食调养","value":""},{"code":"item4","name":"运动调理","value":""},{"code":"item5","name":"精神调适","value":""},{"code":"item6","name":"起居调摄","value":""}];
      const reportId = row.reportId || this.ids
      getInquiryOrderReport(reportId).then(response => {
        this.form = response.data;
        if(response.data.diseaseType!=null){
          this.diseaseType = response.data.diseaseType.split(",")
          this.diseaseType.forEach(disease => {
            this.diseaseParams.diseaseId = disease; // 使用 disease 作为 query 参数
            listBySearch(this.diseaseParams).then(response => {
                this.diseaseTypeOptions.push(...response.rows); // 将 response.rows 展开并推入 diseaseTypeOptions
            });
          });
        }
        if(response.data.conditioningPlanJson!=null){
           this.conditioningPlanJson=JSON.parse(response.data.conditioningPlanJson)
        };
        if(this.form.doctorName!=null){
          this.doctorName.name=this.form.doctorName;
          this.getlistdocuser();
        };
        this.open = true;
        this.title = "修改咨询报告";

        if(response.data.patientJson!=null){

          this.json=JSON.parse(response.data.patientJson);
          if(this.json!=null&&this.json!=""){
            if(this.json.reportImages!=null&&this.json.reportImages!=""){
               this.imgs= (this.json.reportImages).split(",");
            }
           if(this.json.tongueImages!=null&&this.json.tongueImages!=""){
              this.tongueImages=this.json.tongueImages.split(",")
           }
           if(this.json.faceImages!=null&&this.json.faceImages!=""){
              this.faceImages=this.json.faceImages.split(",")
           }

          }

           var weight = this.json.weight;
          var height = this.json.height;
            // 计算BMI值
            this.bmi = Math.round(weight / Math.pow(height / 100, 2));
            // 判断体重状态
            if (this.bmi < 18.5) {
              this.fat="偏瘦";
            } else if (this.bmi < 24) {
              this.fat="正常";
            } else if (this.bmi < 28) {
              this.fat="超重";
            } else {
              this.fat="肥胖";
            }

        };


      });
    },
    handleAudit(row) {
      var ar={ reportId:row.reportId}
      this.json=null;
      updateAuditReport(ar).then(response1 => {
        if(response1==0){
          return this.$message('已经有人在分诊了');
        }else{
          this.imgs=null;
          this.tongueImages=null;
          this.faceImages=null;
          this.open = true;
          this.reset();
          this.formJson=null;
          this.diseaseTypeOptions=[];
          this.conditioningPlanJson=[{"code":"item1","name":"解析","value":""},{"code":"item2","name":"健康建议","value":""},{"code":"item3","name":"饮食调养","value":""},{"code":"item4","name":"运动调理","value":""},{"code":"item5","name":"精神调适","value":""},{"code":"item6","name":"起居调摄","value":""}];
          getInquiryOrderReport(row.reportId).then(response => {
            this.form = response.data;
            if(response.data.conditioningPlanJson!=null){
               this.conditioningPlanJson=JSON.parse(response.data.conditioningPlanJson)
            };
            if(response.data.diseaseType!=null){
              this.diseaseType = response.data.diseaseType.split(",")
              this.diseaseType.forEach(disease => {
                this.diseaseParams.diseaseId = disease; // 使用 disease 作为 query 参数
                listBySearch(this.diseaseParams).then(response => {
                    this.diseaseTypeOptions.push(...response.rows); // 将 response.rows 展开并推入 diseaseTypeOptions
                });
              });
            }
            if(this.form.doctorName!=null){
              this.doctorName.name=this.form.doctorName;
              this.getlistdocuser();
            };

            if(response.data.patientJson!=null){

              this.json=JSON.parse(response.data.patientJson);

                if(this.json!=null&&this.json!=""){
                  if(this.json.reportImages!=null&&this.json.reportImages!=""){
                     this.imgs= (this.json.reportImages).split(",");
                  }
                 if(this.json.tongueImages!=null&&this.json.tongueImages!=""){
                    this.tongueImages=this.json.tongueImages.split(",")
                 }
                 if(this.json.faceImages!=null&&this.json.faceImages!=""){
                    this.faceImages=this.json.faceImages.split(",")
                 }

                }
               var weight = this.json.weight;
              var height = this.json.height;
                // 计算BMI值
                this.bmi = Math.round(weight / Math.pow(height / 100, 2));
                // 判断体重状态
                if (this.bmi < 18.5) {
                  this.fat="偏瘦";
                } else if (this.bmi < 24) {
                  this.fat="正常";
                } else if (this.bmi < 28) {
                  this.fat="超重";
                } else {
                  this.fat="肥胖";
                }

            };

            this.title = "咨询报告分诊";
            this.msgSuccess(response1);
           this.getList()
          });
        }
      });
    },

    change(){
          if(this.createTime!=null){
            this.queryParams.sTime=this.createTime[0];
            this.queryParams.eTime=this.createTime[1];
          }else{
            this.queryParams.sTime=null;
            this.queryParams.eTime=null;
          }
          if(this.updateTime!=null){
            this.queryParams.beginTime=this.updateTime[0];
            this.queryParams.endTime=this.updateTime[1];
          }else{
            this.queryParams.beginTime=null;
            this.queryParams.endTime=null;
          }
        },
    handledetails(row){
            this.show.open=true;
            setTimeout(() => {
                 this.$refs.Details.getDetails(row.reportId);
            }, 1);
        },
    handleClickX(tab, event) {
     if(tab.name=="10"){
       this.queryParams.status=null;
     }else{
       this.queryParams.status=tab.name;
     }
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.diseaseType.length>0){
              this.form.diseaseType=this.diseaseType.toString();
            }
            else{
              this.form.diseaseType=null
            }
          if (this.form.reportId != null) {
            this.form.conditioningPlanJson =JSON.stringify(this.conditioningPlanJson)
            if(this.title=='咨询报告分诊'){
                this.form.status=1;
               updateInquiryOrderReportAudit(this.form).then(response => {
                 this.msgSuccess("分诊成功");
                 this.open = false;
                 this.getList();
               });
            }else{
              updateInquiryOrderReport(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
              addInquiryOrderReport(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
          }
        }
      });
    },
    save(){
      if(this.diseaseType.length>0){
        this.form.diseaseType=this.diseaseType.toString();
      }
      else{
        this.form.diseaseType=null
      }
      this.form.conditioningPlanJson =JSON.stringify(this.conditioningPlanJson)
        updateInquiryOrderReport(this.form).then(response => {
          this.msgSuccess("保存");
          this.open = false;
          this.getList();
        });
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const reportIds = row.reportId || this.ids;
      this.$confirm('是否确认删除咨询报告编号为"' + reportIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInquiryOrderReport(reportIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
		var that=this;
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有咨询报告数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportInquiryOrderReport(queryParams);
        }).then(response => {
          if(response.code==200){
          that.msgSuccess(response.msg);
          that.taskId=response.data;
          that.time=setInterval(function(){
            //查订单
            getTask(that.taskId).then(res => {
              if(res.data.status==1){
                that.exportLoading = false;
                clearTimeout(that.time)
                that.time=null;
                that.download(res.data.fileUrl);
              }
            });
          },10000);
        }
        }).catch(() => {});
    },
    /** tab切换操作 */
    handleClickX(tab, event) {
      if(tab.name=="10"){
        this.queryParams.status=null;
      }else{
        this.queryParams.status=tab.name;
      }
      this.handleQuery();
    },
    /** 查看详情操作 */
    handledetails(row){
      this.show.open=true;
      setTimeout(() => {
        this.$refs.Details.getDetails(row.reportId);
      }, 1);
    },
  }
};
</script>
<style>
  .el-descriptions-item__label.is-bordered-label{
     font-weight: normal;
   }
  .el-descriptions-item__content {
    max-width: 150px;
    min-width: 150px;
  }
  .el-descriptions-item__label {
    min-width: 150px;
  }
</style>

