<template>
  <div class="app-container">
    <a-form :model="queryForm" ref="queryFormRef" layout="inline">

      <a-form-item field="inquiry_no" label="订单编号">
        <a-input :style="{ width: '182px' }" v-model="queryForm.inquiry_no" placeholder="请输入订单编号" @press-enter="handleQuery" />
      </a-form-item>
      <a-form-item field="doctor_name" label="医生姓名">
        <a-input :style="{ width: '182px' }" v-model="queryForm.doctor_name" placeholder="请输入医生姓名" @press-enter="handleQuery" />
      </a-form-item>
      <a-form-item field="patient_name" label="就诊人姓名">
        <a-input :style="{ width: '182px' }" v-model="queryForm.patient_name" placeholder="请输入就诊人姓名" @press-enter="handleQuery" />
      </a-form-item>
      <!-- <a-form-item field="department_custom_name" label="科室名称">
        <a-input v-model="queryForm.department_custom_name" placeholder="请输入科室名称" @press-enter="handleQuery" />
      </a-form-item> -->
     <a-form-item field="mobile" label="电话号码">
      <a-input
          :style="{ width: '182px' }"
          v-model="queryForm.mobile"
          placeholder="请输入医生或者患者电话号码"
          @press-enter="handleQuery"
        />
      </a-form-item>
      <a-form-item field="inquiry_status" label="订单状态">
        <a-select  v-model="queryForm.inquiry_status" placeholder="请选择订单状态" :style="{ width: '182px' }">
              <!-- 1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消） -->
          <a-option value="1">待支付</a-option>
          <a-option value="2">待分配</a-option>
          <a-option value="3">待接诊</a-option>
          <a-option value="4">已接诊</a-option>
          <a-option value="5">已完成</a-option>
          <a-option value="6">已结束</a-option>
          <a-option value="7">已取消</a-option>
        </a-select>
      </a-form-item>
      <a-form-item field="inquiry_type" label="服务类型">
        <a-select  v-model="queryForm.inquiry_type" placeholder="请选择服务类型" :style="{ width: '182px' }">
          <!-- 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 -->
          <a-option :value="1">专家问诊</a-option>
          <a-option :value="2">快速问诊</a-option>
          <a-option :value="3">公益问诊</a-option>
          <a-option :value="4">问诊购药</a-option>
          <a-option :value="5">糖组检测</a-option>
        </a-select>
      </a-form-item>
      <a-row>
        <a-form-item field="pay_range_time" label="支付时间范围">
        <a-range-picker style="width: 330px;" v-model="queryForm.pay_range_time" />
      </a-form-item>
      <a-form-item field="complete_range_time" label="完成时间范围">
        <a-range-picker style="width: 330px;" v-model="queryForm.complete_range_time" />
      </a-form-item>
      <a-form-item field="end_range_time" label="结束时间范围">
        <a-range-picker style="width: 330px;" v-model="queryForm.end_range_time" />
      </a-form-item>
      <a-form-item field="cancel_range_time" label="取消时间范围">
        <a-range-picker
          style="width: 330px"
          v-model="queryForm.cancel_range_time"
        />
      </a-form-item>
      <a-form-item field="reception_range_time" label="接诊时间范围">
        <a-range-picker
          style="width: 330px"
          v-model="queryForm.reception_range_time"
        />
      </a-form-item>
      <a-form-item field="create_range_time" label="创建时间范围">
        <a-range-picker
          style="width: 330px"
          v-model="queryForm.create_range_time"
        />
      </a-form-item>
      <a-form-item>
        <a-space>
          <a-button type="primary" @click="handleQuery"><icon-search /> 搜索</a-button>
          <a-button @click="handleResetQuery"><icon-loop /> 重置</a-button>
        </a-space>
      </a-form-item>
      </a-row>
    </a-form>

    <a-divider />
 <!-- action -->
 <div class="action">
      <a-space>
        <a-button v-has="'admin:sysOrderList:selectExport'" type="primary" @click="handlExport(2)"><icon-export /> 选择数据导出 </a-button>
        <a-button v-has="'admin:sysOrderList:searchExport'" type="primary"  @click="handlExport(1)"><icon-export /> 当前搜索全部导出</a-button> 
        <a-button v-has="'admin:sysOrderList:allExport'" type="primary"  @click="handlExport(3)"><icon-export /> 全部导出</a-button> 
      </a-space>
    </div> 

    <!-- table -->
    <a-table
      :columns="columns"
      :scroll="{ x: 1600 }"
      :data="tableData"
      :pagination="{ 'show-total': true, 'show-jumper': true, 'show-page-size': true, total: pager.total, current: currentPage }"
      :row-selection="{ type: 'checkbox', showCheckedAll: true }"
      row-key="order_inquiry_id"
      @selection-change="(selection) => {deleteData = selection;}" 
      @page-change="handlePageChange"
      @page-size-change="handlepage_sizeChange"
    >
      <template #post_id="{record,rowIndex}">
          <div>{{(rowIndex+1)+(pager.page-1)*pager.page_size}}</div>
      </template>
      <template #inquiry_pay_channel="{record}">
          <div v-if="record.inquiry_pay_channel==1">小程序支付</div>
          <div v-else-if="record.inquiry_pay_channel==2">微信扫码</div>
          <div v-else-if="record.inquiry_pay_channel==3">模拟支付</div>
      </template>
      <!-- 1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消） -->
      <template #inquiry_status="{record}">
          <div v-if="record.inquiry_status==1">待支付</div>
          <div v-else-if="record.inquiry_status==2">待分配</div>
          <div v-else-if="record.inquiry_status==3">待接诊</div>
          <div v-else-if="record.inquiry_status==4">已接诊</div>
          <div v-else-if="record.inquiry_status==5">已完成</div>
          <div v-else-if="record.inquiry_status==6">已结束</div>
          <div v-else-if="record.inquiry_status==7">已取消</div>
      </template>
      <template #amount_total="{ record }">
        {{(record.amount_total) }}元
      </template>
      <template #payment_amount_total="{ record }">
        {{(record.payment_amount_total) }}元
      </template>
      <template #patient_name="{ record }">
        <div class="ta-patient" :title="record.patient_name">{{record.patient_name}}({{record.patient_sex==1?'男，':'女，'}}{{record.patient_age}}岁)</div>
      </template>
      
      <template #inquiry_type="{ record }">
        {{ formatInquiryType(record.inquiry_type) }}
      </template>
      <template #pay_time="{ record }">
        {{ parseTime(record.pay_time) }}
      </template>

      <template #action="{ record }">
        <a-space>
          <a-button v-has="'admin:sysOrderList:detail'" type="text"
            @click="handleDetail(record)"><icon-book />详情</a-button>
          <!-- <a-button v-has="'admin:sysPost:remove'" type="text" @click="() => { deleteVisible = true; deleteData = [record.post_id];  }"><icon-delete /> 删除</a-button> -->
        </a-space>
      </template>
    </a-table>




      <!-- Modal -->
      <a-modal v-model:visible="modalVisible" fullscreen :title="modalTitle" title-align="start" :footer="false"
      @close="() => {$refs.modalFormRef.resetFields(); modalForm.doctor_id = null;}">
      <div class="titlebox">
        <div class="bar"></div>
        <div class="name">订单信息</div>
      </div>
      <a-form :model="modalForm" :disabled="true" :rules="rules" ref="modalFormRef" :auto-label-width="true">
        <a-row :gutter="24" style="margin-top: 35px;">
          <a-col :span="12">
            <a-form-item field="inquiry_no" label="订单编号：">
            <span>{{ modalForm.inquiry_no }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item field="inquiry_status" label="订单状态：" >
              <span>{{ formatInquiryStatus(modalForm.inquiry_status) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24" >
          <a-col :span="12">
            <a-form-item field="user.created_at" label="下单时间：">
              <span >{{modalForm.created_at}}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item field="pay_time" label="支付时间：">
              <span v-if="parseTime(modalForm.pay_time)">{{parseTime(modalForm.pay_time)}}</span>
              <span v-else>-</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item field="amount_total" label="订单金额：">
               <span>{{modalForm.amount_total}}元</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item field="coupon_amount_total" label="优惠卷：">
              <span  v-if="modalForm.coupon_amount_total>0">{{modalForm.coupon_amount_total}}元</span>
              <span  v-else>无</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item field="payment_amount_total" label="实付金额：">
              <span>{{modalForm.payment_amount_total}}元</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item field="inquiry_type" label="问诊类型：">
              <span>{{formatInquiryType(modalForm.inquiry_type)}}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24" v-if="modalForm.cancel_reason">
          <a-col :span="24">
            <a-form-item field="department_custom_name" label="备   注 ：">
             <span>{{ formatOrderCancelReason(modalForm.cancel_reason)}}</span>
        </a-form-item>
          </a-col>
        </a-row>
        <a-divider />
        <div class="titlebox" v-if="modalForm.order_inquiry_refund">
          <div class="bar"></div>
          <div class="name">退款信息</div>
        </div>
        <a-row :gutter="24" style="margin-top: 35px;" v-if="modalForm.order_inquiry_refund">
          <a-col :span="12">
            <a-form-item field="inquiry_refund_no" label="退款编号：">
              <span>{{modalForm.order_inquiry_refund.inquiry_refund_no}}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item field="escrow_trade_no" label=" 第三方订单编号：">
             <span>{{modalForm.escrow_trade_no}}</span>

           </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24"  v-if="modalForm.order_inquiry_refund">
          <a-col :span="12">
            <a-form-item field="inquiry_refund_no" label="退款金额：">
              <span>{{modalForm.order_inquiry_refund.refund_total}}元</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item field="escrow_trade_no" label="退款状态：">
             <span>{{formatRefundStatus(modalForm.order_inquiry_refund.inquiry_refund_status)}}</span>

           </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24"  v-if="modalForm.order_inquiry_refund">
          <a-col :span="24">
            <a-form-item field="inquiry_refund_no" label="退款时间：">
              <span v-if="parseTime(modalForm.order_inquiry_refund.success_time)">{{modalForm.order_inquiry_refund.success_time}}</span>
              <span v-else>-</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24"  v-if="modalForm.order_inquiry_refund">
          <a-col :span="24">
            <a-form-item field="inquiry_refund_no" label="退款原因：">
              <span>{{modalForm.order_inquiry_refund.refund_reason}}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-divider  v-if="modalForm.order_inquiry_refund"/>
        <div class="titlebox">
          <div class="bar"></div>
          <div class="name">医生信息</div>
          <a-space  style="margin-right: 8px;flex:1;display: flex;justify-content: flex-end;" v-if="modalForm.user_doctor">
              <a-button type="primary" @click="openDcotor">查看医生完整信息</a-button>
          </a-space>
        </div>
        <a-row :gutter="24" style="margin-top: 35px;" >
          <a-col :span="24">
            <a-form-item field="license_cert" :hide-label="true" >
               <div class="doctorInfo" v-if="modalForm.user_doctor">
                <a-space size="large">
                  <a-image width="80" height="80" class="headImg" :src="modalForm.user_doctor.avatar" v-if="modalForm.user_doctor.avatar">
                  </a-image>
                  <a-image width="80" height="80" class="headImg" src="https://img.applets.igandanyiyuan.com/basic/file/doctor_avatar.png" v-else>
                  </a-image>
                 </a-space>
                <div class="infobox">
                   <div class="name">{{modalForm.user_doctor.user_name}}&nbsp;&nbsp;{{formatDoctorTitle(modalForm.user_doctor.doctor_title)}}</div>
                   <div class="hospital">{{modalForm.user_doctor.hospital.hospital_name}}&nbsp;&nbsp;{{modalForm.user_doctor.department_custom_name}}</div>
                </div>
               </div>
               <div class="doctorInfo" v-else>暂未分配到医生</div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-divider  v-if="modalForm.user_doctor"/>
        <div class="titlebox" >
          <div class="bar"></div>
          <div class="name">就诊人信息</div>
          <a-space  style="margin-right: 8px;flex:1;display: flex;justify-content: flex-end;">
              <a-button type="primary" status="warning"  @click="openPatient">查看就诊人完整信息</a-button>
          </a-space>
        </div>
        <a-row :gutter="24"  style="margin-top: 35px" v-if="modalForm.order_inquiry_case">
        <a-col :span="24">
          <a-form-item  label="就诊人姓名：">
            <span>{{modalForm.patient_name}}&nbsp;&nbsp;（{{modalForm.patient_sex==1?'男':'女'}}&nbsp;&nbsp;{{modalForm.patient_age}}岁）</span>
          </a-form-item>
        </a-col>
      </a-row>
       <a-row :gutter="24" v-if="modalForm.order_inquiry_case">
        <a-col :span="24">
              <a-form-item field="inquiry_no" label="确诊疾病：">
                <span> <span>{{modalForm.order_inquiry_case.disease_class_name}}&nbsp;&nbsp;{{modalForm.user_doctor.department_custom_name}}</span></span>
              </a-form-item>
        </a-col> 
      </a-row>
      <a-row :gutter="24" v-if="modalForm.order_inquiry_case && modalForm.order_inquiry_case.disease_desc">
        <a-col :span="24">
              <a-form-item field="inquiry_no" label="病情描述：">
                {{modalForm.order_inquiry_case.disease_desc}}
              </a-form-item>
            </a-col> 
      </a-row> 
      <a-divider />
      <div class="titlebox"  v-if="modalForm.order_evaluation">
        <div class="bar"></div>
        <div class="name">评价信息</div>
      </div>
      <a-row :gutter="24" v-if="modalForm.order_evaluation" style="margin-top: 35px;">
        <a-col :span="24">
              <a-form-item field="inquiry_no" label="回复质量：">
                <span><a-rate v-model="comment.reply_quality" readonly /></span>
              </a-form-item>
        </a-col> 
      </a-row>
      <a-row :gutter="24" v-if="modalForm.order_evaluation">
        <a-col :span="24">
              <a-form-item field="inquiry_no" label="服务态度：">
                <span><a-rate v-model="comment.service_attitude" readonly /></span>
              </a-form-item>
        </a-col> 
      </a-row>
      <a-row :gutter="24" v-if="modalForm.order_evaluation">
        <a-col :span="24">
              <a-form-item field="inquiry_no" label="回复速度：">
                <span><a-rate v-model="comment.reply_progress" readonly /></span>
              </a-form-item>
        </a-col> 
      </a-row>
      <a-row :gutter="24" v-if="modalForm.order_evaluation">
        <a-col :span="24">
              <a-form-item field="inquiry_no" label="评价内容：">
                <span>
                  {{ comment.content }}
                </span>
              </a-form-item>
        </a-col> 
      </a-row>
      <!-- <a-row :gutter="24" style="margin-top: 35px;" v-if="modalForm.order_evaluation">
        <a-col :span="24">
          <a-form-item field="" label="" no-style>
            <div class="infobox commentbox">
                  <div class="row">
                    <div class="nameDesc">回复质量：</div>
                    <div class="desc"><a-rate :default-value="modalForm.order_evaluation.reply_quality" readonly /></div>
                  </div>
                  <div class="row">
                    <div class="nameDesc">服务态度：</div>
                    <div class="desc"><a-rate :default-value="modalForm.order_evaluation.service_attitude" readonly /></div>
                  </div>
                  <div class="row">
                    <div class="nameDesc">回复速度：</div>
                    <div class="desc"><a-rate :default-value="modalForm.order_evaluation.reply_progress" readonly /></div>
                  </div>
                  <div class="row">
                    <div class="nameDesc">评价内容：</div>
                    <div class="desc">{{ modalForm.order_evaluation.content }}</div>
                  </div>
                </div>
          </a-form-item>
        </a-col>
      </a-row> -->
      <a-divider v-if="modalForm.order_evaluation"/>
      </a-form>
     
      <div class="titlebox" >
        <div class="bar"></div>
        <div class="name">操作</div>
      </div>
      <a-row :gutter="24" style="margin-top: 35px;" >
        <a-col :span="24">
          <a-form-item field="" label="" no-style>
            <a-space  style="margin-right: 8px;" v-if="modalForm.inquiry_status==4 || modalForm.inquiry_status==5 || modalForm.inquiry_status==6">
              <a-button type="primary" @click="openInquiryRecord"  v-has="'admin:sysOrderList:record'">问诊记录</a-button>
            </a-space>
            <a-space  style="margin-right: 8px;" v-if="modalForm.inquiry_status==4 || modalForm.inquiry_status==5">
              <a-button type="primary" status="danger"   v-has="'admin:sysOrderList:cancel'" @click="()=>{okVisible=true;cur_inruiry_id=modalForm.order_inquiry_id;}">取消问诊</a-button>
            </a-space>
          </a-form-item>
        </a-col>
      </a-row>
    </a-modal>

      <!-- 医生详情弹框 -->
      <doctorModal :doctorVisible="doctorVisible" :doctor_id="doctor_id" @doctorVisibleChange="() => {doctorVisible = false;doctor_id='';}"></doctorModal>

      <!-- 患者详情弹窗 -->
      <patientModal :patientVisible="patientVisible" :data="patientData" @patientVisibleChange="() => {patientVisible = false;}"></patientModal>

      <confirmModal :okVisible="okVisible"  :api="cancelInquiry" :title="'确定取消此订单吗？'" :dealType="'order_inquiry_id'" :id="cur_inruiry_id" @closeChange="handelCloseChange"></confirmModal>

      <!-- 聊天记录 -->
      <!-- Modal -->
      <!-- <a-modal v-model:visible="chatVisible" fullscreen title="聊天记录" title-align="start" :footer="false"
      @close="() => {}">
      <a-form :model="modalForm" :disabled="true" :rules="rules" ref="modalFormRef" :auto-label-width="true">
        <a-row :gutter="24" >
          <a-col :span="24">
            <a-form-item field="license_cert" :hide-label="true">
      <chatRecord :id="modalForm.order_inquiry_id" :user_doctor="modalForm.user_doctor"></chatRecord>
    </a-form-item>
          </a-col>
         
        </a-row>
      </a-form>
      </a-modal> -->
      <!-- 问诊记录详情 -->
      <inquiryDetailModal :modalVisible="recordVisible" :modalForm="modalForm" @inquiryVisibleChange="()=>{recordVisible=false}"></inquiryDetailModal>
  </div>


</template>

<script setup>
import { reactive, ref, getCurrentInstance, onMounted, nextTick, watch } from 'vue';
import {exportInquiry, getOrderList,getOrderDetail,cancelInquiry,inquiryCase} from '@/api/order/list';
import { parseTime } from '@/utils/parseTime';
import {formatDoctorTitle,formatOrderCancelReason} from "@/utils/format"
import { downloadFile } from '@/utils/downloadFile';
// Akiraka 20230210 删除数据
const deleteData = ref([])
// Akiraka 20230210 删除对话框
const deleteVisible = ref(false)

const doctorVisible=ref(false);
const okVisible=ref(false);
const cur_inruiry_id=ref('');
const doctor_id=ref('');
const patientVisible=ref(false);
const patientData=reactive({
});
const comment=reactive({

});
const recordVisible=ref(false);
// Akiraka 20230210 监听删除事件
watch(() => deleteVisible.value ,(value) => {

  if ( value == false ) {
    getOrderInfo(pager);
  }
})
const { proxy } = getCurrentInstance();

const currentPage = ref(1);
// Pager
const pager = {
  total: 0,
  page: 1,
  page_size: 10,
};
// form
const queryForm = reactive({
  range_time:null
});
const modalForm = reactive({
  sort: 0,
  status: 1,
  order_inquiry_refund:{},
  order_evaluation:null

});
watch(()=>queryForm.end_range_time,(value)=>{
  if(value){
    let[startTime,endTime]=value
    queryForm.finish_time=startTime+"&"+endTime;
  }else{
    queryForm.finish_time=''
  };
  console.log(queryForm.finish_time)
})
watch(()=>queryForm.pay_range_time,(value)=>{
  if(value){
    let[startTime,endTime]=value
    queryForm.pay_time=startTime+"&"+endTime;
  }else{
    queryForm.pay_time=''
  };
})
watch(()=>queryForm.complete_range_time,(value)=>{
  if(value){
    let[startTime,endTime]=value
    queryForm.complete_time=startTime+"&"+endTime;
  }else{
    queryForm.complete_time=''
  };
})
watch(()=>queryForm.cancel_range_time,(value)=>{
  if(value){
    let[startTime,endTime]=value
    queryForm.cancel_time=startTime+"&"+endTime;
  }else{
    queryForm.cancel_time=''
  };
})
watch(()=>queryForm.reception_range_time,(value)=>{
  if(value){
    let[startTime,endTime]=value
    queryForm.reception_time=startTime+"&"+endTime;
  }else{
    queryForm.reception_time=''
  };
})
watch(()=>queryForm.create_range_time,(value)=>{
  if(value){
    let[startTime,endTime]=value
    queryForm.created_at=startTime+"&"+endTime;
  }else{
    queryForm.created_at=''
  };
})
// Rules
const rules = {
  post_name: [{ required: true, message: '请输入岗位名称' }]
};

// Modal
const modalVisible = ref(false);
const modalTitle = ref('默认标题');

// Batch Del List
let batchList = [];

// Table Columns
const columns = [
  { title: '排序', dataIndex: 'post_id',slotName: 'post_id',width: 90 },
  { title: '订单编号', dataIndex: 'inquiry_no',width:200 },
  { title: '医生姓名', dataIndex: 'doctor_name',width:100  },
  { title: '就诊人', dataIndex: 'patient_name',slotName:'patient_name',width:200},
  { title: '联系电话', dataIndex: 'patient_mobile',width: 130  },
  { title: '订单金额', dataIndex: 'amount_total',slotName:'amount_total',width:100 },
  { title: '实付金额', dataIndex: 'payment_amount_total',slotName:'payment_amount_total',width:100 },
  { title: '服务类型', dataIndex: 'inquiry_type',slotName:'inquiry_type',width:100 },
  { title: '支付方式', dataIndex: 'inquiry_pay_channel',slotName:  'inquiry_pay_channel'},
  { title: '订单状态', dataIndex: 'inquiry_status', slotName:'inquiry_status' },
  { title: '支付时间', dataIndex: 'pay_time', slotName: 'pay_time',width:200 },
  { title: '操作', slotName: 'action',fixed: "right", width: 100  },
];

// Table Data
const tableData = ref([]);

// 新增
const handleAdd = () => {
  modalVisible.value = true;
  modalTitle.value = '新增岗位';
};

// 修改
const handleUpdate = async (record) => {
  modalVisible.value = true;
  modalTitle.value = '修改岗位';

  await nextTick();
  Object.assign(modalForm, record);
};

// Modal ok
// 异步关闭Modal需要调用 done()
// const handleSubmit = (done) => {
//   proxy.$refs.modalFormRef.validate(async (valid) => {
//     if (!valid) {
//       let res;
//       if (!modalForm.post_id) {
//         const { code, message } = await addPost(modalForm);
//         if (code == 200 ) {
//           proxy.$notification.success('新增成功');
//         } else {
//           proxy.$notification.error(message);
//         }
//       } else {
//         console.log("post_id:"+modalForm.post_id)

//         const { code, message } = await updatePost(modalForm, modalForm.post_id);
//         if (code == 200 ) {
//           proxy.$notification.success('更新成功');
//         } else {
//           proxy.$notification.error(message);
//         }
//       }
//       done();
//       getOrderInfo(pager);
//     } else {
//       proxy.$message.error('表单校验失败');
//       done(false);
//     }
//   });
// };


/**
 * 分页改变
 * @param {Number} [page]
 */
 const handlePageChange = (page) => {
  pager.page = page;

  // 修改当前页码
  currentPage.value = page;
  getOrderInfo({ ...pager, ...queryForm });
};

// 每页数据量
const handlepage_sizeChange = (page_size) => {
  pager.page_size = page_size;
  getOrderInfo({ ...pager, ...queryForm });
};

// 获取岗位信息
const getOrderInfo = async (params = {}) => {
  const { data, code, message } = await getOrderList(params);
  if ( code == 200 ) {
    tableData.value = data.data;
    Object.assign(pager, { total: data.total, page: data.page, page_size: data.page_size });
  } else {
    proxy.$notification.error(message);
  }
};

// 查询岗位信息
const handleQuery = async () => {
  pager.page=1;
  const params = {
    page: pager.page,
    page_size: pager.page_size,
    ...queryForm,
  };
  getOrderInfo(params);
};

//获取订单详情
 const handleDetail = async (record) => {
    modalVisible.value = true;
    modalTitle.value = '问诊订单详情';
    Object.assign(patientData,{});
    const { code, data, message } = await getOrderDetail(record.order_inquiry_id);

    if (code == 200) {
      Object.assign(modalForm, data);
      let result=data.order_evaluation;
      if(data.order_inquiry_case && data.order_inquiry_case.inquiry_case_id){
      
        const caseInfo= await inquiryCase(data.order_inquiry_case.inquiry_case_id);
        Object.assign(patientData,caseInfo.data);

      }
      if(result){
        Object.assign(comment,{
          reply_progress:result.reply_progress/20,
          reply_quality:result.reply_quality/20,
          service_attitude:result.service_attitude/20,
          content:result.content
        })
      }
    }
  };
  const formatInquiryStatus=(val)=>{
    //问诊订单状态（1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消）
    let data={1:'待支付', 2:'待分配', 3:'待接诊', 4:'已接诊', 5:'已完成', 6:'已结束', 7:'已取消'}
     if(val){
      return data[val]
     }else{
      return ''
     }
  }
  const formatRefundStatus=(val)=>{
    //问诊订单退款状态（0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常）
    let data={0:'无退款', 1:'申请退款', 2:'退款中',3:'退款成功', 4:'拒绝退款', 5:'退款关闭', 6:'退款异常'}
     if(val || val==0){
      return data[val]
     }else{
      return ''
     }
  }
  const formatInquiryType=(val)=>{
    //订单类型（1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测）
    let data={1:'专家问诊', 2:'快速问诊', 3:'公益问诊', 4:'问诊购药', 5:'糖组检测'}
     if(val){
      return data[val]
     }else{
      return ''
     }
  }



const openDcotor=()=>{
  doctor_id.value=modalForm.doctor_id;
  doctorVisible.value=true;
}
const openPatient=()=>{
  //patientData=modalForm.order_inquiry_case;
  
  // console.log(patientData);
  patientVisible.value=true;
}
const openInquiryRecord=()=>{
 recordVisible.value=true;
}
//关闭确认框
const handelCloseChange=(data)=>{
  cur_inruiry_id.value="";
  okVisible.value=false;
  console.log(data)
  if(data){
    modalVisible.value=false;
     getOrderInfo({ ...pager, ...queryForm });
  }
}
// 重置搜索
const handleResetQuery = () => {
  proxy.$refs.queryFormRef.resetFields();
  currentPage.value=1;
  handleQuery();
  //getOrderInfo(queryForm);
  
}
const handlExport=async(type)=>{
  proxy.$loading.show();
  let fromData=null;
  if(type==1){
    fromData={
      type,
      ...queryForm
    }
  }else if(type==2){
      if(deleteData.value.length==0){
        proxy.$message.warning('请勾选数据');
        proxy.$loading.hide();
        return false;
      };
    let id='';
    deleteData.value.forEach((item)=>{
      if(id){
        id+=","+item
      }else{
        id=item;
      }
    })
    fromData={
      type,
     id
    }
  }else if(type==3){
    fromData={
      type
    }
  }
  const {code,data}=await exportInquiry(fromData);
 if(code==200){
  downloadFile(data,'问诊订单');
 }
  proxy.$loading.hide();
}
  
onMounted(() => {
  getOrderInfo(pager);
});
</script>

<style lang="scss">
.action {
  margin-bottom: 12px;
}
.doctorInfo{
  display: flex;
  align-items: center;

}
 .row{
  line-height:32px;
  display: flex;
}
 .row .nameDesc{
  text-align: right;
  width:120px;
  color:#000;
}
.row .desc{
  color:#666;
}
.ta-patient{
  width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.infobox{
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.headImg {
    margin-right: 20px;
    border-radius: 50%;
    width: 80px;
    height: 80px;
  }
  .arco-form-item-content{
  word-break: break-all;
}
</style>
