<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="患者ID" prop="patientId">
        <el-input v-model="queryParams.patientId" placeholder="请输入患者ID" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="患者姓名" prop="patientName">
        <el-input v-model="queryParams.patientName" placeholder="请输入患者姓名" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="患者身份证号" prop="idNumber">
        <el-input v-model="queryParams.idNumber" placeholder="请输入患者身份证号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="患者电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入患者电话" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="住院号" prop="hosNumber">
        <el-input v-model="queryParams.hosNumber" placeholder="请输入住院号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="入院日期" prop="inhosDate">
        <el-date-picker v-model="queryParams.inhosDate" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="出院日期" prop="outhosDate">
        <el-date-picker v-model="queryParams.outhosDate" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <!-- <el-form-item label="办理类型（本人办理/他人代办）" prop="handleType">
        <el-select v-model="queryParams.handleType" placeholder="请选择办理类型（本人办理/他人代办）" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="领取方式" prop="deliveryType">
        <el-select v-model="queryParams.deliveryType" placeholder="请选择领取方式（邮寄/自取）" clearable size="small">
          <el-option v-for="dict in typeDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)" />
        </el-select>
        
      </el-form-item>
      <!-- <el-form-item label="代办人姓名" prop="reName">
        <el-input v-model="queryParams.reName" placeholder="请输入代办人姓名" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="代办人身份证号" prop="reId">
        <el-input v-model="queryParams.reId" placeholder="请输入代办人身份证号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="代办人电话" prop="rePhone">
        <el-input v-model="queryParams.rePhone" placeholder="请输入代办人电话" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="患者身份证正面地址" prop="cardFronturl">
        <el-input v-model="queryParams.cardFronturl" placeholder="请输入患者身份证正面地址" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="患者身份证反面地址" prop="cardBackurl">
        <el-input v-model="queryParams.cardBackurl" placeholder="请输入患者身份证反面地址" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="代办委托书地址" prop="attorneyUrl">
        <el-input v-model="queryParams.attorneyUrl" placeholder="请输入代办委托书地址" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="代办人身份证正面地址" prop="recordFronturl">
        <el-input v-model="queryParams.recordFronturl" placeholder="请输入代办人身份证正面地址" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="代办人身份证反面地址" prop="recordBackurl">
        <el-input v-model="queryParams.recordBackurl" placeholder="请输入代办人身份证反面地址" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="查询费默认10元" prop="selectAmount">
        <el-input v-model="queryParams.selectAmount" placeholder="请输入查询费默认10元" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="查询页数" prop="pages">
        <el-input v-model="queryParams.pages" placeholder="请输入查询页数" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="订单号  EX" prop="orderno">
        <el-input v-model="queryParams.orderno" placeholder="请输入订单号  EX" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="his订单号" prop="reptno">
        <el-input v-model="queryParams.reptno" placeholder="请输入his订单号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="需要支付金额" prop="amount">
        <el-input v-model="queryParams.amount" placeholder="请输入需要支付金额" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="领取状态（0尚未领取/1已自取/2已邮寄）" prop="send">
        <el-input v-model="queryParams.send" placeholder="请输入领取状态（0尚未领取/1已自取/2已邮寄）" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="取件码" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入取件码" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <el-form-item label="申请状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择申请状态" clearable size="small">
          <el-option v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['system:nxexpress:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['system:nxexpress:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="status !== 'constraint'"  size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['system:nxexpress:update']">审核</el-button> -->
          <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['system:nxexpress:delete']">删除</el-button> -->
        <!-- </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- 审核按钮（待审核状态） -->
          <el-button
            v-if="scope.row.status === 3"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:nxexpress:update']"
          >审核</el-button>
          <!-- 打回按钮（待审核状态） -->
          <el-button
            v-if="scope.row.status === 3"
            size="mini"
            type="text"
            icon="el-icon-circle-close"
            @click="handleReject(scope.row)"
            v-hasPermi="['system:nxexpress:update']"
          >打回</el-button>
          <!-- 基于领取方式的操作按钮（已支付状态） -->
          <el-button
            v-if="scope.row.status === 2 && scope.row.send === 0"
            size="mini"
            type="primary"
            plain
            @click="handleSend(scope.row)"
          >自取或邮寄</el-button>
        </template>
      </el-table-column>      
      <el-table-column label="ID" align="center" prop="id" width="50"/>
      <el-table-column label="打印份数" align="center" prop="copies" width="80"/>
      <el-table-column label="住院号" align="center" prop="hosNumber" width="100"/>
      <el-table-column label="患者ID" align="center" prop="patientId"  width="100"/>
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="患者身份证号" align="center" prop="idNumber"  width="180" />
      <el-table-column label="患者电话" align="center" prop="phone"  width="120"/>
      <el-table-column label="查询费" align="center" prop="selectAmount" />
      <el-table-column label="查询页数" align="center" prop="pages" />
      <el-table-column label="订单号  EX" align="center" prop="orderno" />
      <el-table-column label="his订单号" align="center" prop="reptno" />
      <el-table-column label="支付金额" align="center" prop="amount" />
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.EXPRESS_STATUS" :value="scope.row.status"/>
        </template>
      </el-table-column>/>
      <el-table-column label="领取状态" align="center" prop="send" >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.EXPRESS_SEND" :value="scope.row.send"/>
        </template>
      </el-table-column>
      <el-table-column label="取件码" align="center" prop="code" />
      <el-table-column label="入院日期" align="center" prop="inhosDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inhosDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出院日期" align="center" prop="outhosDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outhosDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="办理类型" align="center" prop="handleType" >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.EXPRESS_APPLY" :value="scope.row.handleType"/>
        </template>
      </el-table-column>
      <el-table-column label="领取方式" align="center" prop="deliveryType" >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.EXPRESS_TYPE" :value="scope.row.deliveryType"/>
        </template>
      </el-table-column>
      <el-table-column label="代办人姓名" align="center" prop="reName" />
      <el-table-column label="代办人身份证号" align="center" prop="reId" />
      <el-table-column label="代办人电话" align="center" prop="rePhone" />
      <el-table-column label="患者身份证正面地址" align="center" prop="cardFronturl" width="250">
        <template slot-scope="scope">
          <img v-if="scope.row.cardFronturl" :src="scope.row.cardFronturl" class="id-card-preview" @click="showImagePreview(scope.row.cardFronturl)">
        </template>
      </el-table-column>
      <el-table-column label="患者身份证反面地址" align="center" prop="cardBackurl" width="250">
        <template slot-scope="scope">
          <img v-if="scope.row.cardBackurl" :src="scope.row.cardBackurl" class="id-card-preview" @click="showImagePreview(scope.row.cardBackurl)">
        </template>
      </el-table-column>
      <el-table-column label="代办委托书地址" align="center" prop="attorneyUrl" width="250">
        <template slot-scope="scope">
          <img v-if="scope.row.attorneyUrl" :src="scope.row.attorneyUrl" class="id-card-preview" @click="showImagePreview(scope.row.attorneyUrl)">
        </template>
      </el-table-column>
      <el-table-column label="代办人身份证正面地址" align="center" prop="recordFronturl" width="250">
        <template slot-scope="scope">
          <img v-if="scope.row.recordFronturl" :src="scope.row.recordFronturl" class="id-card-preview" @click="showImagePreview(scope.row.recordFronturl)">
        </template>
      </el-table-column>
      <el-table-column label="代办人身份证反面地址" align="center" prop="recordBackurl" width="250">
        <template slot-scope="scope">
          <img v-if="scope.row.recordBackurl" :src="scope.row.recordBackurl" class="id-card-preview" @click="showImagePreview(scope.row.recordBackurl)">
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="查询页数" prop="pages">
          <el-input v-model="form.pages" type="number" placeholder="请输入查询页数" @input="calcAmount"/>
        </el-form-item>
        <el-form-item label="查询费默认10元"  prop="selectAmount">
          <el-input v-model="form.selectAmount" placeholder="请输入查询费默认10元" disabled  />
        </el-form-item>
        <el-form-item label="支付金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入支付金额" disabled />
        </el-form-item>
        <el-form-item label="申请状态" readonly prop="status">
          <el-radio-group v-model="form.status" disabled>
            <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.EXPRESS_STATUS)"
                      :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
          </el-radio-group>          
        </el-form-item>
        <el-form-item label="领取状态" prop="send">
          <el-radio-group v-model="form.send" disabled>
            <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.EXPRESS_SEND)"
                      :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
          </el-radio-group>          
        </el-form-item>
        <el-form-item label="取件码" prop="code">
          <el-input v-model="form.code" placeholder="请输入取件码" />
        </el-form-item>
        <el-form-item label="订单号  EX" prop="orderno">
          <el-input v-model="form.orderno" placeholder="请输入订单号  EX" />
        </el-form-item>
        <el-form-item label="办理类型" prop="handleType">
          <el-radio-group v-model="form.handleType" disabled>
            <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.EXPRESS_APPLY)"
                      :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
          </el-radio-group>          

        </el-form-item>
        <el-form-item label="领取方式" prop="deliveryType">
          <el-radio-group v-model="form.deliveryType" disabled>
            <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.EXPRESS_TYPE)"
                      :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
          </el-radio-group>          
        </el-form-item>

        <el-form-item label="患者ID" prop="patientId">
          <el-input v-model="form.patientId" placeholder="请输入患者ID" />
        </el-form-item>
        <el-form-item label="患者姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入患者姓名" />
        </el-form-item>
        <el-form-item label="打印份数" prop="copies">
          <el-input v-model="form.copies" type="number" placeholder="请输入打印份数" />
        </el-form-item>
        <el-form-item label="住院号" prop="hosNumber">
          <el-input v-model="form.hosNumber" placeholder="请输入住院号" />
        </el-form-item>
        <el-form-item label="患者身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入患者身份证号" />
        </el-form-item>
        <el-form-item label="患者电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入患者电话" />
        </el-form-item>
        <el-form-item label="入院日期" prop="inhosDate">
          <el-date-picker clearable v-model="form.inhosDate" type="date" value-format="timestamp" placeholder="选择入院日期" />
        </el-form-item>
        <el-form-item label="出院日期" prop="outhosDate">
          <el-date-picker clearable v-model="form.outhosDate" type="date" value-format="timestamp" placeholder="选择出院日期" />
        </el-form-item>
        <el-form-item label="代办人姓名" prop="reName">
          <el-input v-model="form.reName" placeholder="请输入代办人姓名" />
        </el-form-item>
        <el-form-item label="代办人身份证号" prop="reId">
          <el-input v-model="form.reId" placeholder="请输入代办人身份证号" />
        </el-form-item>
        <el-form-item label="代办人电话" prop="rePhone">
          <el-input v-model="form.rePhone" placeholder="请输入代办人电话" />
        </el-form-item>
        <el-form-item label="患者身份证正面" prop="cardFronturl">
          <img v-if="form.cardFronturl" :src="form.cardFronturl" class="id-card-preview" @click="showImagePreview(form.cardFronturl)">
        </el-form-item>
        <el-form-item label="患者身份证反面" prop="cardBackurl">
          <img v-if="form.cardBackurl" :src="form.cardBackurl" class="id-card-preview" @click="showImagePreview(form.cardBackurl)">
        </el-form-item>
        <el-form-item label="代办委托书" prop="attorneyUrl">
          <img v-if="form.attorneyUrl" :src="form.attorneyUrl" class="id-card-preview" @click="showImagePreview(form.attorneyUrl)">
        </el-form-item>
        <el-form-item label="代办人身份证正面" prop="recordFronturl">
          <img v-if="form.recordFronturl" :src="form.recordFronturl" class="id-card-preview" @click="showImagePreview(form.recordFronturl)">
        </el-form-item>
        <el-form-item label="代办人身份证反面" prop="recordBackurl">
          <img v-if="form.recordBackurl" :src="form.recordBackurl" class="id-card-preview" @click="showImagePreview(form.recordBackurl)">
        </el-form-item>
        <el-form-item label="his订单号" prop="reptno">
          <el-input v-model="form.reptno" placeholder="请输入his订单号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    
    <!-- 图片预览对话框 -->
    <el-dialog
      title="图片预览"
      :visible.sync="imagePreviewVisible"
      width="90%"
      append-to-body
    >
      <div class="image-preview-container">
        <img :src="previewImageUrl" class="preview-image">
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { createnxexpress, updatenxexpress, deletenxexpress, getnxexpress, getnxexpressPage, exportnxexpressExcel,updateSend, rejectnxexpress } from "@/api/system/nxexpress";
import {DICT_TYPE, getDictDatas} from "@/utils/dict";

export default {
  name: "nxexpress",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 病案申请列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        patientId: null,
        patientName: null,
        idNumber: null,
        phone: null,
        hosNumber: null,
        copies: 1,
        inhosDate: [],
        outhosDate: [],
        handleType: null,
        deliveryType: null,
        reName: null,
        reId: null,
        rePhone: null,
        cardFronturl: null,
        cardBackurl: null,
        attorneyUrl: null,
        recordFronturl: null,
        recordBackurl: null,
        selectAmount: null,
        pages: null,
        orderno: null,
        reptno: null,
        amount: null,
        status: 3,
        send: null,
        code: null,
        createTime: [],
      },
      // 表单参数
      form: {},
      // 图片预览相关
      imagePreviewVisible: false,
      previewImageUrl: '',
      // 表单校验
      rules: {
        userId: [{ required: true, message: "申请人用户ID不能为空", trigger: "blur" }],
        patientName: [{ required: true, message: "患者姓名不能为空", trigger: "blur" }],
        copies: [{ required: true, message: "打印份数不能为空", trigger: "blur" }],
        idNumber: [{ required: true, message: "患者身份证号不能为空", trigger: "blur" }],
        phone: [{ required: true, message: "患者电话不能为空", trigger: "blur" }],
        hosNumber: [{ required: true, message: "住院号不能为空", trigger: "blur" }],
        inhosDate: [{ required: true, message: "入院日期不能为空", trigger: "blur" }],
        outhosDate: [{ required: true, message: "出院日期不能为空", trigger: "blur" }],
        handleType: [{ required: true, message: "办理类型（本人办理/他人代办）不能为空", trigger: "change" }],
        deliveryType: [{ required: true, message: "领取方式（邮寄/自取）不能为空", trigger: "change" }],
        cardFronturl: [{ required: true, message: "患者身份证正面地址不能为空", trigger: "blur" }],
        cardBackurl: [{ required: true, message: "患者身份证反面地址不能为空", trigger: "blur" }],
        selectAmount: [{ required: true, message: "查询费默认10元不能为空", trigger: "blur" }],
        status: [{ required: true, message: "状态（0已退费/1待支付/2已支付/3待审核）不能为空", trigger: "blur" }],
        send: [{ required: true, message: "领取状态（0尚未领取/1已自取/2已邮寄）不能为空", trigger: "blur" }],
      },
      statusDictDatas: getDictDatas(DICT_TYPE.EXPRESS_STATUS),
      sendDictDatas: getDictDatas(DICT_TYPE.EXPRESS_SEND),
      typeDictDatas: getDictDatas(DICT_TYPE.EXPRESS_TYPE),
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 显示图片预览
    showImagePreview(url) {
      this.previewImageUrl = url;
      this.imagePreviewVisible = true;
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getnxexpressPage(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 开始自动刷新 */
    startAutoRefresh() {
      // 每100秒直接调用一次getList()方法
      this.autoRefreshTimer = setInterval(() => {
        this.getList();
      }, 60000);
    },
    /** 停止自动刷新 */
    stopAutoRefresh() {
      if (this.autoRefreshTimer) {
        clearInterval(this.autoRefreshTimer);
        this.autoRefreshTimer = null;
      }
    },
  // 页数变化时自动计算支付金额
  calcAmount() {
    // 保证 pages 是数字
    const pages = Number(this.form.pages) || 0;
    this.form.amount = (10 + 0.5 * pages).toFixed(2);
  },    
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,
        patientName: undefined,
        idNumber: undefined,
        phone: undefined,
        hosNumber: undefined,
        copies: undefined,
        inhosDate: undefined,
        outhosDate: undefined,
        handleType: undefined,
        deliveryType: undefined,
        reName: undefined,
        reId: undefined,
        rePhone: undefined,
        cardFronturl: undefined,
        cardBackurl: undefined,
        attorneyUrl: undefined,
        recordFronturl: undefined,
        recordBackurl: undefined,
        selectAmount: undefined,
        pages: undefined,
        orderno: undefined,
        reptno: undefined,
        amount: undefined,
        status: undefined,
        send: undefined,
        code: undefined,
      };
      this.resetForm("form");
      
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      // 手动重置查询参数，确保清空状态正确保存
      this.queryParams.deliveryType = null;
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加病案申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getnxexpress(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改病案申请";
      });
    },
    /** 打回按钮操作 */
    handleReject(row) {
      this.$modal.confirm('是否确认打回该申请?').then(() => {
        // 使用专门的打回接口，只需要传递id
        const rejectData = {
          id: row.id,
          status: 4,
        };
        
        console.log('打回操作提交的数据:', rejectData);
        return rejectnxexpress(rejectData);
      }).then(() => {
        this.$modal.msgSuccess("打回成功");
        this.getList();
      }).catch(error => {
        console.error('打回操作失败:', error);
        // 解析错误信息
        if (error.response && error.response.data) {
          console.error('后端返回的错误:', error.response.data);
          this.$modal.msgError(error.response.data.msg || "打回失败，请稍后重试");
        } else {
          this.$modal.msgError("打回失败，请稍后重试");
        }
      });
    },
    /**邮寄/自取按钮操作 */
    handleSend(row) {
      this.reset();
      const id = row.id;

      getnxexpress(id).then(response => {
        this.form = response.data;
        console.log(this.form, "form");
         if(this.form.deliveryType == "1"){
            this.form.send = 1;
         }
         if(this.form.deliveryType == "2"){
            this.form.send = 2;
         }
         console.log(this.form, "form1");

        // 修改的提交
        if (this.form.id != null) {
          updateSend(this.form).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        }

      });

    // updateSend(id).then(res =>{
  
    //   if(res.code === 200){
    //     this.$modal.msgSuccess("操作成功");
    //     this.getList();
    //   }
    // })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updatenxexpress(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createnxexpress(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除病案申请编号为"' + id + '"的数据项?').then(function() {
          return deletenxexpress(id);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有病案申请数据项?').then(() => {
          this.exportLoading = true;
          return exportnxexpressExcel(params);
        }).then(response => {
          this.$download.excel(response, '病案申请.xls');
          this.exportLoading = false;
        }).catch(() => {});
    },
  }
};
</script>

<style scoped>
.id-card-preview {
  max-width: 240px;
  max-height: 150px;
  cursor: pointer;
  transition: all 0.3s;
}
.id-card-preview:hover {
  transform: scale(1.05);
}

.image-preview-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.preview-image {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
}
</style>
