无人机管理后台前端(已迁走)
rain
2025-04-12 4c0ce06dbc18a576f84aa69d67a7dfbe030d0b60
工单事件
2 files modified
1117 ■■■■ changed files
src/api/tickets/ticket.js 33 ●●●● patch | view | raw | blame | history
src/views/tickets/ticket.vue 1084 ●●●● patch | view | raw | blame | history
src/api/tickets/ticket.js
@@ -12,10 +12,9 @@
export const createTicket = (data, file) => {
  const formData = new FormData();
  
  // 添加文件到 eventDto 中作为一个字段
  // 创建 eventDto 对象,不显式设置 file 字段
  const eventDto = {
    ...data,
    file: null // 后端会处理这个字段
    ...data  // 直接使用传入的 data,不添加 file: null
  };
  // 添加所有字段到 FormData
@@ -23,7 +22,7 @@
    formData.append(key, value);
  });
  
  // 单独添加文件
  // 只有当 file 存在时才添加文件
  if (file) {
    formData.append("file", file);
  }
@@ -46,3 +45,29 @@
    params: { id }, // 使用工单 ID 查询
  });
};
// 修改接口:处理待审核状态,动态构建 FormData 提交
export const flowEvent = (data, file) => {
  const formData = new FormData();
  // 动态添加非空字段到 FormData
  Object.entries(data).forEach(([key, value]) => {
    if (value !== undefined && value !== null) {
      formData.append(key, value);
    }
  });
  // 如果 file 存在,则添加到 FormData
  if (file) {
    formData.append('file', file);
  }
  return request({
    url: '/drone-device-core/jobEvent/flowEvent',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data', // 设置为表单数据格式
    },
  });
};
src/views/tickets/ticket.vue
@@ -5,41 +5,91 @@
                <div class="tab-content">
                    <!-- 查询条件筛选栏 -->
                    <div class="filter-bar">
                        <el-input v-model="filters.keyword" placeholder="请输入关键字" class="filter-item" clearable
                            @keyup.enter="handleSearch" />
                        <el-select v-model="filters.department" placeholder="请选择所属单位" class="filter-item" clearable>
                            <el-option v-for="item in departments" :key="item.value" :label="item.label"
                                :value="item.value" />
            <el-input
              v-model="filters.keyword"
              placeholder="请输入关键字"
              class="filter-item"
              size="small"
              clearable
              @keyup.enter="handleSearch"
            />
            <el-select
              v-model="filters.department"
              placeholder="请选择所属单位"
              class="filter-item"
              size="small"
              clearable
            >
              <el-option v-for="item in departments" :key="item.value" :label="item.label" :value="item.value" />
                        </el-select>
                        <el-select v-model="filters.type" placeholder="请选择工单类型" class="filter-item" clearable>
                            <el-option v-for="item in types" :key="item.value" :label="item.label"
                                :value="item.value" />
            <el-select
              v-model="filters.type"
              placeholder="请选择工单类型"
              class="filter-item"
              size="small"
              clearable
            >
              <el-option v-for="item in types" :key="item.value" :label="item.label" :value="item.value" />
                        </el-select>
                        <el-date-picker v-model="filters.dateRange" type="daterange" range-separator="至"
                            start-placeholder="开始日期" end-placeholder="结束日期" class="date-picker"
                            value-format="yyyy-MM-dd" />
                        <el-select v-model="filters.status" placeholder="请选择状态" class="filter-item" clearable>
                            <el-option v-for="item in statuses" :key="item.value" :label="item.label"
                                :value="item.value" />
            <el-date-picker
              v-model="filters.dateRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              class="date-picker"
              size="small"
              value-format="yyyy-MM-dd"
            />
            <el-select
              v-model="filters.status"
              placeholder="请选择状态"
              class="filter-item"
              size="small"
              clearable
            >
              <el-option v-for="item in statuses" :key="item.value" :label="item.label" :value="item.value" />
                        </el-select>
                        <el-button type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
                        <el-button icon="el-icon-refresh" @click="handleReset">重置</el-button>
            <el-select
              v-model="filters.algorithm"
              placeholder="请选择关联算法"
              class="filter-item"
              size="small"
              clearable
            >
              <el-option
                v-for="item in algorithms"
                :key="item.dict_key"
                :label="item.dict_value"
                :value="item.dict_key"
              />
            </el-select>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleSearch">查询</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="handleReset">重置</el-button>
                    </div>
                    <!-- 表格部分 -->
                    <avue-crud :data="tableData" :option="option" :page="{
                        total: page.total,
                        currentPage: page.currentPage,
                        pageSize: page.pageSize,
                        pageSizes: [10000, 20000, 30000]
                    }" @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
                        @on-load="onLoad" :table-loading="loading">
          <avue-crud
            v-model="tableData"
            :option="option"
            :data="tableData"
            v-model:page="page"
            @size-change="sizeChange"
            @current-change="handleCurrentChange"
            :table-loading="loading"
          >
                        <template #menu-left>
                            <!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新建工单</el-button> -->
              <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新建工单</el-button>
                            <el-button type="success" plain icon="el-icon-download" @click="exportData">导出</el-button>
                        </template>
                        <template #menu="{ row }">
              <template v-if="row.status === 0">
                <el-button type="text" icon="el-icon-edit" @click="handleEdit(row)">编辑</el-button>
                <el-button type="text" icon="el-icon-delete" class="danger-button" @click="handleDelete(row)">删除</el-button>
              </template>
              <template v-else>
                            <el-button type="text" icon="el-icon-view" @click="handleViewDetail(row)">详情</el-button>
              </template>
                        </template>
                        <template #status="{ row }">
                            <el-tag :type="getStatusTagType(row.status)">{{ mapStatus(row.status) }}</el-tag>
@@ -67,8 +117,7 @@
                        <el-col :span="12">
                            <el-form-item label="工单类型" prop="type">
                                <el-select v-model="form.type" placeholder="请选择工单类型" class="full-width">
                                    <el-option v-for="item in types" :key="item.value" :label="item.label"
                                        :value="item.value" />
                  <el-option v-for="item in types" :key="item.value" :label="item.label" :value="item.value" />
                                </el-select>
                            </el-form-item>
                        </el-col>
@@ -76,19 +125,16 @@
                    <el-row :gutter="12">
                        <el-col :span="12">
                            <el-form-item label="所属部门" prop="department">
                                <el-select v-model="form.department" placeholder="请选择所属部门"
                                    @change="handleDepartmentChange" class="full-width">
                                    <el-option v-for="dept in departments" :key="dept.value" :label="dept.label"
                                        :value="dept.value" />
                <el-select v-model="form.department" placeholder="请选择所属部门" @change="handleDepartmentChange"
                  class="full-width">
                  <el-option v-for="dept in departments" :key="dept.value" :label="dept.label" :value="dept.value" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="处理人员" prop="handler">
                                <el-select v-model="form.handler" placeholder="请选择处理人员" :disabled="!form.department"
                                    class="full-width">
                                    <el-option v-for="user in availableHandlers" :key="user.id" :label="user.name"
                                        :value="user.id" />
                <el-select v-model="form.handler" placeholder="请选择处理人员" :disabled="!form.department" class="full-width">
                  <el-option v-for="user in availableHandlers" :key="user.id" :label="user.name" :value="user.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
@@ -97,8 +143,7 @@
                        <el-col :span="12">
                            <el-form-item label="关联算法" prop="algorithm">
                                <el-select v-model="form.algorithm" placeholder="请选择关联算法" class="full-width">
                                    <el-option v-for="item in algorithms" :key="item.value" :label="item.label"
                                        :value="item.value" />
                  <el-option v-for="item in algorithms" :key="item.value" :label="item.label" :value="item.value" />
                                </el-select>
                            </el-form-item>
                        </el-col>
@@ -113,8 +158,12 @@
                            <el-form-item label="地图选址" prop="location">
                                <div class="map-select">
                                    <!-- 替换地图为按钮 -->
                                    <avue-input-map v-model="form.location" :params="mapParams"
                                        @change="handleLocationChange" type="button">
                  <avue-input-map
                    v-model="form.location"
                    :params="mapParams"
                    @change="handleLocationChange"
                    type="button"
                  >
                                        <el-button type="primary" plain>
                                            <i class="el-icon-map-location"></i> 选择位置
                                        </el-button>
@@ -135,13 +184,21 @@
                <div class="form-section">
                    <div class="section-title">工单内容</div>
                    <el-form-item label="工单描述" prop="content">
                        <el-input type="textarea" v-model="form.content" rows="3" placeholder="请输入工单内容描述"
                            resize="none"></el-input>
            <el-input type="textarea" v-model="form.content" rows="3" placeholder="请输入工单内容描述" resize="none"></el-input>
                    </el-form-item>
                    <el-form-item label="附件图片" class="upload-item">
                        <el-upload ref="upload" :action="'#'" :auto-upload="false" list-type="picture-card"
                            :on-change="handleFileChange" :on-remove="handleUploadRemove" :before-upload="beforeUpload"
                            :file-list="form.photos" :limit="1" accept="image/*">
            <el-upload
              ref="upload"
              :action="'#'"
              :auto-upload="false"
              list-type="picture-card"
              :on-change="handleFileChange"
              :on-remove="handleUploadRemove"
              :before-upload="beforeUpload"
              :file-list="form.photos"
              :limit="1"
              accept="image/*"
            >
                            <i class="el-icon-plus"></i>
                        </el-upload>
                        <div class="el-upload__tip">支持jpg/png格式图片,最多1张,单张不超过5MB</div>
@@ -151,6 +208,7 @@
            <template #footer>
                <div class="dialog-footer">
                    <el-button size="small" @click="dialogVisible = false">取 消</el-button>
          <el-button size="small" type="info" @click="saveDraft">存草稿</el-button>
                    <el-button size="small" type="primary" @click="submitForm">提 交</el-button>
                </div>
            </template>
@@ -162,12 +220,18 @@
                <!-- 工单状态流程 -->
                <div class="status-flow">
                    <el-steps :active="currentDetail.status" align-center finish-status="success">
                        <el-step title="发起任务" :description="currentDetail.creator || '未知创建人'" />
            <el-step
              title="发起任务"
              :description="currentDetail.creator || '未知创建人'"
            />
                        <el-step title="待审核" />
                        <el-step title="待处理" />
                        <el-step title="处理中" />
                        <el-step title="已完成" />
                        <el-step title="已完结" :description="currentDetail.handler || '未分配'" />
            <el-step
              title="已完结"
              :description="currentDetail.handler || '未分配'"
            />
                    </el-steps>
                </div>
@@ -176,8 +240,15 @@
                    <el-table-column prop="label1" label="基本信息" width="150" />
                    <el-table-column>
                        <template #default="{ row }">
              <!-- 修复工单名称可编辑 -->
                            <template v-if="currentDetail.status === 2 && row.label1 === '工单名称'">
                                <el-input v-model="currentDetail.orderName" placeholder="请输入工单名称" />
              </template>
              <!-- 修复任务接收单位为下拉框 -->
              <template v-else-if="currentDetail.status === 2 && row.label1 === '任务接收单位'">
                <el-select v-model="currentDetail.department" placeholder="请选择任务接收单位" @change="handleDepartmentChange">
                  <el-option v-for="item in departments" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
                            </template>
                            <template v-else>{{ row.value1 }}</template>
                        </template>
@@ -185,13 +256,20 @@
                    <el-table-column prop="label2" label="基本信息" width="150" />
                    <el-table-column>
                        <template #default="{ row }">
              <!-- 修复工单内容可编辑 -->
                            <template v-if="currentDetail.status === 2 && row.label2 === '工单内容'">
                                <el-input v-model="currentDetail.remark" placeholder="请输入工单内容" />
                <el-input type="textarea" v-model="currentDetail.remarkContent" placeholder="请输入工单内容" />
                            </template>
              <!-- 修复工单类型为下拉框 -->
                            <template v-else-if="currentDetail.status === 2 && row.label2 === '工单类型'">
                                <el-select v-model="currentDetail.type" placeholder="请选择工单类型">
                                    <el-option v-for="item in types" :key="item.value" :label="item.label"
                                        :value="item.value" />
                  <el-option v-for="item in types" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </template>
              <!-- 修复任务处理人为下拉框 -->
              <template v-else-if="currentDetail.status === 2 && row.label2 === '任务处理人'">
                <el-select v-model="currentDetail.handler" placeholder="请选择任务处理人" @change="handleHandlerChange">
                  <el-option v-for="user in departmentUsers[currentDetail.department] || []" :key="user.id" :label="user.name" :value="user.id" />
                                </el-select>
                            </template>
                            <template v-else>{{ row.value2 }}</template>
@@ -202,32 +280,57 @@
                <!-- 事件处理详情 -->
                <div v-if="[3, 4, 5].includes(currentDetail.status)" class="form-section">
                    <div class="section-title">事件处理详情</div>
                    <el-input type="textarea" v-model="currentDetail.processingDetail"
                        :disabled="currentDetail.status !== 3" placeholder="请输入事件处理详情" rows="4"
                        style="width: 100%; margin-bottom: 10px;" />
          <!-- 处理中状态显示输入框 -->
          <template v-if="currentDetail.status === 3">
            <el-input
              type="textarea"
              v-model="currentDetail.processingDetail"
              placeholder="请输入事件处理详情"
              :rows="4"
              style="width: 100%; margin-bottom: 10px;"
            />
          </template>
          <!-- 已完成和已完结状态显示只读文本 -->
          <template v-else>
            <div class="readonly-processing-detail">
              {{ currentDetail.processingDetail }}
            </div>
          </template>
                </div>
                <!-- 上传图片 -->
                <div v-if="[3, 4].includes(currentDetail.status)" class="form-section">
                    <div class="section-title">上传图片</div>
                    <el-upload ref="upload" :action="'#'" :auto-upload="false" list-type="picture-card"
                        :on-change="handleFileChange" :on-remove="handleUploadRemove" :before-upload="beforeUpload"
                        :file-list="[]" accept="image/*">
          <el-upload
            ref="upload"
            :action="'#'"
            :auto-upload="false"
            list-type="picture-card"
            :on-change="handleFileChange"
            :on-remove="handleUploadRemove"
            :before-upload="beforeUpload"
            :file-list="[]"
            accept="image/*"
          >
                        <i class="el-icon-plus"></i>
                    </el-upload>
                    <div class="el-upload__tip">支持 jpg/png 格式图片,最多 5 张,单张不超过 5MB</div>
                </div>
                <!-- 图片和地图 -->
        <!-- 图片和地图部分 -->
                <div class="media-section">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <div class="media-box">
                                <div class="media-title">事件图片/事件视频</div>
                                <div class="media-content">
                                    <el-image v-if="currentDetail.mediaUrl" :src="currentDetail.mediaUrl"
                                        :preview-src-list="[currentDetail.mediaUrl]" fit="cover"
                                        style="width: 100%; height: 300px;">
                  <el-image
                    v-if="currentDetail.mediaUrl"
                    :src="currentDetail.mediaUrl"
                    :preview-src-list="[currentDetail.mediaUrl]"
                    fit="cover"
                    style="width: 100%; height: 300px;"
                  >
                                        <template #placeholder>
                                            <div class="image-placeholder">
                                                <i class="el-icon-picture-outline"></i>
@@ -247,13 +350,41 @@
                        </el-col>
                        <el-col :span="12">
                            <div class="media-box">
                <!-- 根据状态显示不同的标题和内容 -->
                <template v-if="currentDetail.status === 5">
                  <div class="media-title">工单处理图片</div>
                  <div class="media-content">
                    <el-image
                      v-if="currentDetail.updatePhotoUrl"
                      :src="currentDetail.updatePhotoUrl"
                      :preview-src-list="[currentDetail.updatePhotoUrl]"
                      fit="cover"
                      style="width: 100%; height: 300px;"
                    >
                      <template #placeholder>
                        <div class="image-placeholder">
                          <i class="el-icon-picture-outline"></i>
                          <span>加载中...</span>
                        </div>
                      </template>
                      <template #error>
                        <div class="image-error">
                          <i class="el-icon-picture-outline"></i>
                          <span>加载失败</span>
                        </div>
                      </template>
                    </el-image>
                    <div v-else class="no-media">暂无处理图片</div>
                  </div>
                </template>
                <template v-else>
                                <div class="media-title">地图标记事件点</div>
                                <div class="media-content">
                                    <div id="map-container" style="width: 100%; height: 300px; background: #f5f5f5;">
                                        <!-- 地图容器 -->
                                        <map-container v-if='detailVisible' :rowDetails="currentDetail"></map-container>
                                    </div>
                                </div>
                </template>
                            </div>
                        </el-col>
                    </el-row>
@@ -268,7 +399,7 @@
                        <el-button @click="detailVisible = false">取消</el-button>
                    </template>
                    <template v-else-if="currentDetail.status === 2">
                        <!-- 待处理 -->
                        <el-button type="primary" @click="approveAndDispatch">通过并派发</el-button>
                        <el-button type="danger" @click="rejectTicket">不通过</el-button>
                        <el-button @click="detailVisible = false">取消</el-button>
@@ -290,13 +421,36 @@
                </div>
            </div>
        </el-dialog>
    <!-- 派发工单对话框 -->
    <el-dialog v-model="dispatchDialogVisible" title="派发工单" width="40%" :close-on-click-modal="false">
      <el-form :model="dispatchForm" :rules="dispatchRules" ref="dispatchForm" label-width="100px">
        <el-form-item label="选择部门" prop="department">
          <el-select v-model="dispatchForm.department" placeholder="请选择部门" @change="handleDispatchDepartmentChange">
            <el-option v-for="dept in departments" :key="dept.value" :label="dept.label" :value="dept.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="选择处理人" prop="handler">
          <el-select v-model="dispatchForm.handler" placeholder="请选择处理人" :disabled="!dispatchForm.department">
            <el-option v-for="user in availableDispatchHandlers" :key="user.id" :label="user.name" :value="user.id" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dispatchDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitDispatch">确认派发</el-button>
      </template>
    </el-dialog>
    </basic-container>
</template>
<script>
import { getList, createTicket, getTicketInfo } from '@/api/tickets/ticket'
import { export_json_to_excel } from '@/utils/exportExcel'
import { getList, createTicket, getTicketInfo, flowEvent } from '@/api/tickets/ticket';
import { export_json_to_excel } from '@/utils/exportExcel';
import geoJson from '@/assets/geoJson.json'
import { mapGetters } from 'vuex'
import { getAdcodeObj } from '@/utils/disposeData'
export default {
    name: "TicketPage",
    data () {
@@ -317,6 +471,7 @@
                type: "",
                dateRange: [],
                status: "",
        algorithm: "", // 新增算法筛选字段
            },
            departments: [],
            types: [],
@@ -339,10 +494,10 @@
                stripe: true,
                menuWidth: 150,
                searchMenuSpan: 6,
                addBtnText: "新建工单",
                viewBtn: false,
                editBtn: false,
                delBtn: false,
        addBtn:false,
                menu: true,
                page: true,
                column: [
@@ -355,7 +510,7 @@
                    { label: "工单类型", prop: "type", width: 108 },
                    {
                        label: "工单内容",
                        prop: "address",
            prop: "remarkContent",
                        slot: true,
                        width: 250,
                        overHidden: true
@@ -368,8 +523,8 @@
            page: {
                total: 0,
                currentPage: 1,
                pageSize: 10000,
                pageSizes: [10000, 20000, 30000]
        pageSize: 10,
        pageSizes: [10, 20, 30 ]
            },
            dialogVisible: false,
            detailVisible: false,
@@ -384,6 +539,7 @@
                address: '',
                content: '',
                photos: [],
        remarkContent: '', // 新增字段,用于存储后端返回的 content
            },
            rules: {
                name: [{ required: true, message: '请输入工单名称', trigger: 'blur' }],
@@ -399,20 +555,34 @@
            isFetching: false,
            mapParams: {
                zoom: 15,
                center: [115.861365, 28.621311],  // 默认中心点
        center: null, // 初始设为 null,等待动态设置
            },
        }
      dispatchDepartment: '', // 新增:派发部门
      dispatchHandler: '', // 新增:派发处理人
      dispatchDialogVisible: false, // 新增:派发对话框可见性
      dispatchForm: {
        department: '',
        handler: '',
      }, // 新增:派发表单数据
      dispatchRules: {
        department: [{ required: true, message: '请选择部门', trigger: 'change' }],
        handler: [{ required: true, message: '请选择处理人', trigger: 'change' }],
      }, // 新增:派发表单验证规则
    };
    },
    created () {
        this.loadAMapScripts()
        this.fetchDropdownData()
    this.loadAMapScripts();
    this.fetchDropdownData();
    },
    mounted () {
        this.fetchTableData()
    this.fetchTableData();
    },
    computed: {
        availableHandlers () {
            return this.form.department ? (this.departmentUsers[this.form.department] || []) : []
      return this.form.department ? (this.departmentUsers[this.form.department] || []) : [];
    },
    availableDispatchHandlers() {
      return this.dispatchForm.department ? (this.departmentUsers[this.dispatchForm.department] || []) : [];
        },
        detailTableData () {
            return [
@@ -466,11 +636,11 @@
                },
                {
                    label: "工单内容",
                    value: this.currentDetail.remark,
          value: this.currentDetail.remarkContent,
                    editable: this.currentDetail.status === 2,
                    type: "textarea",
                },
            ]
      ];
        },
        detailFields () {
            return [
@@ -483,119 +653,145 @@
                { label: "关联算法", value: this.currentDetail.content, editable: false },
                { label: "任务接收单位", value: this.currentDetail.department, editable: false },
                { label: "发起任务时间", value: this.currentDetail.startTime, editable: false },
                { label: "工单内容", value: this.currentDetail.remark, editable: this.currentDetail.status === 2, type: "textarea" },
            ]
        { label: "工单内容", value: this.currentDetail.remarkContent, editable: this.currentDetail.status === 2, type: "textarea" },
      ];
        },
        formattedDetailFields () {
            const fields = [
                { label: "工单名称", value: this.currentDetail.orderName },
                { label: "工单类型", value: this.currentDetail.type },
                { label: "关键数据", value: this.currentDetail.handler || '未分配' }, // 显示处理人
        { label: "任务处理人", value: this.currentDetail.handler || '未分配' }, // 显示处理人
                { label: "任务发起人", value: this.currentDetail.creator },
                { label: "当前状态", value: this.mapStatus(this.currentDetail.status) },
                { label: "事件地址", value: this.currentDetail.address }, // 包含经纬度信息
                { label: "关联算法", value: this.currentDetail.content },
                { label: "任务接收单位", value: this.currentDetail.department },
                { label: "发起任务时间", value: this.currentDetail.startTime },
                { label: "工单内容", value: this.currentDetail.remark },
            ]
        { label: "工单内容", value: this.currentDetail.remarkContent },
      ];
            // 将字段分成两列
            const formattedFields = []
      const formattedFields = [];
            for (let i = 0; i < fields.length; i += 2) {
                formattedFields.push({
                    label1: fields[i]?.label || "",
                    value1: fields[i]?.value || "暂无数据",
                    label2: fields[i + 1]?.label || "",
                    value2: fields[i + 1]?.value || "暂无数据",
                })
        });
            }
            return formattedFields
      return formattedFields;
        },
    ...mapGetters(['userInfo']),
    },
    methods: {
        async loadAMapScripts () {
            try {
                this.mapLoaded = true
        const areaCode = this.userInfo.detail.areaCode;
        const subAreaCode = areaCode ? areaCode.substring(0, 6) : '';
        const adcodeObj = getAdcodeObj(geoJson, 'adcode', subAreaCode);
        console.log('区域代码:', subAreaCode);
        // 直接从返回对象中获取正确的路径
        const center = adcodeObj?.payload?.objects?.collection?.geometries?.[0]?.properties?.center;
        console.log('获取到的中心点:', center);
        if (Array.isArray(center) && center.length === 2) {
          this.mapParams.center = center;
          console.log('成功设置地图中心点:', center);
        } else {
          // 如果找不到中心点,尝试使用 bbox 的中心点
          const bbox = adcodeObj?.payload?.bbox;
          if (Array.isArray(bbox) && bbox.length === 4) {
            const centerX = (bbox[0] + bbox[2]) / 2;
            const centerY = (bbox[1] + bbox[3]) / 2;
            this.mapParams.center = [centerX, centerY];
            console.log('使用 bbox 计算的中心点:', this.mapParams.center);
          } else {
            console.warn('无法获取有效的中心点坐标,使用默认值');
            this.mapParams.center = [115.861365, 28.621311];
          }
        }
        this.mapLoaded = true;
            } catch (error) {
                console.error('Failed to load AMap scripts:', error)
                this.$message.error('地图加载失败,请检查网络或API Key配置')
        console.error('地图脚本加载失败:', error);
        this.$message.error('地图加载失败,请检查网络或API Key配置');
            }
        },
        async fetchDropdownData () {
            try {
                const response = await getTicketInfo()
                const { dept_data, event_type, ai_type } = response.data.data
        const response = await getTicketInfo();
        const { dept_data, event_type, ai_type } = response.data.data;
                this.departments = dept_data.map(item => ({
                    label: item.dept_name,
                    value: item.id,
                }))
        }));
                this.departmentUsers = dept_data.reduce((acc, dept) => {
                    acc[dept.id] = dept.user_data || []
                    return acc
                }, {})
          acc[dept.id] = dept.user_data || [];
          return acc;
        }, {});
                this.types = Object.entries(event_type).map(([key, value]) => ({
                    label: value,
                    value: key,
                }))
        }));
        // 修改算法数据的映射
                this.algorithms = ai_type.map(item => ({
                    label: item.dict_value,
                    value: item.dict_key,
                }))
          dict_key: item.dict_key,
          dict_value: item.dict_value
        }));
            } catch (error) {
                console.error('获取下拉框数据失败:', error)
                this.$message.error('加载下拉框数据失败')
        console.error('获取下拉框数据失败:', error);
        this.$message.error('加载下拉框数据失败');
            }
        },
        async fetchTableData () {
            if (this.isFetching) return
            this.isFetching = true
            this.loading = true
      if (this.isFetching) return;
      this.isFetching = true;
      this.loading = true;
            try {
                const currentTab = this.tabs.find(tab => tab.name === this.activeTab)
        const currentTab = this.tabs.find(tab => tab.name === this.activeTab);
                const params = {
                    word_order_type: this.filters.type || undefined,
                    status: currentTab?.name === 'myTickets' ? undefined :
                        this.filters.status !== "" ? Number(this.filters.status) :
                            currentTab?.value,
                    keyword: this.filters.keyword || undefined,
          event_name: this.filters.keyword || undefined,
                    dept_id: this.filters.department || undefined,
                    start_date: this.filters.dateRange?.[0] ? this.formatDate(this.filters.dateRange[0]) : undefined,
                    end_date: this.filters.dateRange?.[1] ? this.formatDate(this.filters.dateRange[1]).replace("00:00:00", "23:59:59") : undefined,
                    current: parseInt(this.page.currentPage),  // 确保是数字
                    size: parseInt(this.page.pageSize)        // 确保是数字
                }
                const param = ref({
                    zoom: 10,
                    // zoomEnable: false,
                    // dragEnable: false,
                })
          current: Number(this.page.currentPage),  // 使用当前页码
          size: Number(this.page.pageSize),       // 使用每页条数
          ai_type: this.filters.algorithm || undefined, // 添加算法参数
        };
                const form = ref([113.10235504165291, 41.03624227495205, "内蒙古自治区乌兰察布市集宁区新体路街道顺达源广告传媒"])
                const response = await getList(params)
        const response = await getList(params);
                if (!response?.data?.data?.records) {
                    throw new Error('接口返回数据格式不正确')
          throw new Error('接口返回数据格式不正确');
                }
                const { total, records } = response.data.data
                let filteredRecords = records
        const { total, records } = response.data.data;
        let filteredRecords = records;
                // 如果是"我发起的"tab,过滤数据
                if (currentTab?.name === 'myTickets') {
                    filteredRecords = records.filter(item =>
                        String(item.create_user_id) === String(item.user_id)
                    )
          );
                }
                this.tableData = filteredRecords.map(item => {
                    const longitude = Number(item.longitude) || 0
                    const latitude = Number(item.latitude) || 0
          const longitude = Number(item.longitude) || 0;
          const latitude = Number(item.latitude) || 0;
                    return {
                        id: item.id,
                        orderNumber: item.event_num, // 修改这里:优先使用 event_num
@@ -603,6 +799,7 @@
                        department: this.departments.find(d => d.value === item.dept_id)?.label || item.dept_name,
                        startTime: item.create_time,
                        content: item.ai_types,
            remarkContent: item.content, // 将后端返回的 content 映射为 remarkContent
                        type: this.types.find(t => t.value === item.event_dict_key)?.label,
                        keyData: (!isNaN(longitude) && !isNaN(latitude))
                            ? `${longitude.toFixed(6)}, ${latitude.toFixed(6)}`
@@ -615,34 +812,37 @@
                        photo_url: item.photo_url || '',  // 保存原始 photo_url
                        video_url: item.video_url || '',  // 保存原始 video_url
                        location: (!isNaN(longitude) && !isNaN(latitude)) ? [longitude, latitude] : null,
                    }
                })
            processing_details: item.processing_details || '', // 添加处理详情字段
            update_photo_url: item.update_photo_url || '', // 添加处理图片字段
          };
        });
                // 更新总数显示
                if (currentTab?.name === 'myTickets') {
                    this.page.total = filteredRecords.length
          this.page.total = filteredRecords.length;
                } else {
                    this.page.total = total || 0
          this.page.total = total || 0;
                }
                if (this.activeTab === 'all') {
                    // 计算"我发起的"工单数量
                    const myTicketsCount = records.filter(item =>
                        String(item.create_user_id) === String(item.user_id)
                    ).length
          ).length;
                    // 更新全局计数,包括"我发起的"数量
                    this.updateGlobalCounts(records, total, myTicketsCount)
          this.updateGlobalCounts(records, total, myTicketsCount);
                }
                this.updateTabCounts()
        this.updateTabCounts();
            } catch (error) {
                console.error("获取数据失败:", error)
                this.$message.error(error.message || "获取数据失败")
                this.tableData = []
                this.page.total = 0
        console.error("获取数据失败:", error);
        this.$message.error(error.message || "获取数据失败");
        this.tableData = [];
        this.page.total = 0;
            } finally {
                this.loading = false
                this.isFetching = false
        this.loading = false;
        this.isFetching = false;
            }
        },
@@ -650,15 +850,14 @@
            this.$refs.form.validate(async (valid) => {
                if (valid) {
                    if (!this.form.location || this.form.location.length < 2) {
                        this.$message.warning('请在地图上选择位置')
                        return
            this.$message.warning('请在地图上选择位置');
            return;
                    }
                    try {
                        // 修改提交数据结构
                        const submitData = {
                            eventName: this.form.name,
                            remark: this.form.content,
              content: this.form.content,  // 传递工单内容
                            workType: "1",
                            longitude: String(this.form.location[0]),
                            latitude: String(this.form.location[1]),
@@ -666,92 +865,151 @@
                            eventDictKey: this.form.type,
                            aiType: this.form.algorithm,
                            updateUser: this.form.handler,
                            createDept: this.form.department,  // 添加所属部门ID
              createDept: this.form.department,
                            isDraft: 0
            };
            // 如果是编辑状态,添加 id
            if (this.form.id) {
              submitData.id = this.form.id;
                        }
                        // 获取文件对象
                        let file = null
            let file = null;
                        if (this.form.photos && this.form.photos.length > 0) {
                            file = this.form.photos[0].raw
              file = this.form.photos[0].raw;
                        }
                        const response = await createTicket(submitData, file)
            const response = await createTicket(submitData, file);
                        if (response.data.code === 0) {
                            this.$message.success('工单创建成功')
                            this.dialogVisible = false
                            this.fetchTableData()
              this.$message.success('工单创建成功');
              this.dialogVisible = false;
              this.fetchTableData();
                        } else {
                            throw new Error(response.data.msg || '创建失败')
              throw new Error(response.data.msg || '创建失败');
                        }
                    } catch (error) {
                        console.error('提交失败:', error)
                        this.$message.error(error.message || '工单创建失败,请稍后重试')
            console.error('提交失败:', error);
            this.$message.error(error.message || '工单创建失败,请稍后重试');
                    }
                }
            })
      });
    },
    async saveDraft() {
      try {
        const submitData = {
          id: this.form.id,
          eventName: this.form.name || undefined,
          content: this.form.content || undefined,  // 传递工单内容
          workType: "1",
          longitude: this.form.location?.[0] ? String(this.form.location[0]) : undefined,
          latitude: this.form.location?.[1] ? String(this.form.location[1]) : undefined,
          address: this.form.address || undefined,
          eventDictKey: this.form.type || undefined,
          aiType: this.form.algorithm || undefined,
          updateUser: this.form.handler || undefined,
          createDept: this.form.department || undefined,
          isDraft: 1
        };
        // 确保即使为空字符串也会传入 content
        if (this.form.content !== undefined) {
          submitData.content = this.form.content;
        }
        // 如果是编辑状态,添加 id
        if (this.form.id) {
          submitData.id = this.form.id;
        }
        // 过滤掉所有 undefined 的字段
        Object.keys(submitData).forEach(key =>
          submitData[key] === undefined && delete submitData[key]
        );
        // 获取文件对象
        let file = null;
        if (this.form.photos && this.form.photos.length > 0) {
          file = this.form.photos[0].raw;
        }
        const response = await createTicket(submitData, file); // 使用 createTicket 而不是 flowEvent
        if (response.data.code === 0) {
          this.$message.success('草稿保存成功');
          this.dialogVisible = false;
          this.fetchTableData();
        } else {
          throw new Error(response.data.msg || '保存失败');
        }
      } catch (error) {
        console.error('保存草稿失败:', error);
        this.$message.error(error.message || '保存草稿失败,请稍后重试');
      }
        },
        async handleLocationChange (val) {
            console.log('地图选址返回值:', val)
      console.log('地图选址返回值:', val);
            // 处理 Proxy 对象的值
            let locationValue = val.value
      let locationValue = val.value;
            if (locationValue && locationValue.length >= 3) {
                // 确保我们获取到实际的数组值
                this.form.location = [locationValue[0], locationValue[1]]
                this.form.address = locationValue[2] || ''
        this.form.location = [locationValue[0], locationValue[1]];
        this.form.address = locationValue[2] || '';
                console.log('解析后的位置信息:', {
                    经度: this.form.location[0],
                    纬度: this.form.location[1],
                    地址: this.form.address
                })
        });
            } else {
                console.warn('无效的位置数据')
                this.form.location = []
                this.form.address = ''
        console.warn('无效的位置数据');
        this.form.location = [];
        this.form.address = '';
            }
        },
        formatDate (date) {
            if (!date) return undefined
            const d = new Date(date)
            return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} 00:00:00`
      if (!date) return undefined;
      const d = new Date(date);
      return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} 00:00:00`;
        },
        mapStatus (status) {
            const statusTextMap = {
        0: "草稿",  // 添加草稿状态
                1: "待审核",
                2: "待处理",
                3: "处理中",
                4: "已完成",
                5: "已完结"
            }
            return statusTextMap[status] || "未知状态"
      };
      return statusTextMap[status] || "未知状态";
        },
        getStatusTagType (status) {
            const statusMap = {
        0: "info",    // 为草稿状态添加样式
                1: "warning",
                2: "info",
                3: "primary",
                4: "success",
                5: "danger",
            }
            return statusMap[status] || "info"
      };
      return statusMap[status] || "info";
        },
        handleTabChange (tab) {
            this.activeTab = tab.props?.name || tab.name
            this.filters.status = ""
            this.page.currentPage = 1
            this.fetchTableData()
      this.activeTab = tab.props?.name || tab.name;
      this.filters.status = "";
      this.page.currentPage = 1;
      this.fetchTableData();
        },
        handleSearch () {
            this.page.currentPage = 1
            this.fetchTableData()
      this.page.currentPage = 1;
      this.fetchTableData();
        },
        handleReset () {
@@ -761,27 +1019,27 @@
                type: "",
                dateRange: [],
                status: "",
            }
            this.page.currentPage = 1
            this.fetchTableData()
        algorithm: "", // 重置时清空算法筛选
      };
      this.page.currentPage = 1;
      this.fetchTableData();
        },
        currentChange (currentPage) {
            console.log('currentChange triggered, new page:', currentPage)
            // 先更新页码,再请求数据
            this.page.currentPage = currentPage
            this.$nextTick(() => {
                this.fetchTableData()
            })
    async handleCurrentChange(val) {
      console.log('当前页变更:', val);
      // 先更新页码
      this.page.currentPage = val;
      // 等待 DOM 更新后再请求数据
      await this.$nextTick();
      await this.fetchTableData();
        },
        sizeChange (pageSize) {
            console.log('sizeChange triggered, new size:', pageSize)
            this.page.pageSize = pageSize
            this.page.currentPage = 1
            this.$nextTick(() => {
                this.fetchTableData()
            })
    async sizeChange(val) {
      console.log('每页条数变更:', val);
      this.page.pageSize = val;
      this.page.currentPage = 1; // 重置到第一页
      await this.$nextTick();
      await this.fetchTableData();
        },
        updateGlobalCounts (records, total, myTicketsCount) {
@@ -793,36 +1051,36 @@
                completed: 0,
                closed: 0,
                myTickets: myTicketsCount || 0  // 添加"我发起的"计数
            }
      };
            records.forEach(item => {
                const tab = this.tabs.find(t => t.value === Number(item.status))
        const tab = this.tabs.find(t => t.value === Number(item.status));
                if (tab) {
                    counts[tab.name] = (counts[tab.name] || 0) + 1
          counts[tab.name] = (counts[tab.name] || 0) + 1;
                }
            })
      });
            this.globalCounts = counts
      this.globalCounts = counts;
        },
        updateTabCounts () {
            if (this.activeTab === 'all') {
                this.tabs.forEach(tab => {
                    tab.count = this.globalCounts[tab.name] || 0
                })
          tab.count = this.globalCounts[tab.name] || 0;
        });
            } else {
                this.tabs.forEach(tab => {
                    if (tab.name === this.activeTab) {
                        tab.count = this.tableData.length
            tab.count = this.tableData.length;
                    } else {
                        tab.count = this.globalCounts[tab.name] || 0
            tab.count = this.globalCounts[tab.name] || 0;
                    }
                })
        });
            }
        },
        handleAdd () {
            this.dialogVisible = true
      this.dialogVisible = true;
        },
        resetForm () {
@@ -836,71 +1094,105 @@
                address: '',
                content: '',
                photos: [],
            }
        remarkContent: '', // 新增字段,用于存储后端返回的 content
      };
            if (this.$refs.form) {
                this.$refs.form.resetFields()
        this.$refs.form.resetFields();
            }
        },
        formatLocation (location) {
            if (!Array.isArray(location)) {
                return '未知位置'
        return '未知位置';
            }
            return `${location[0].toFixed(6)}, ${location[1].toFixed(6)}`
      return `${location[0].toFixed(6)}, ${location[1].toFixed(6)}`;
        },
        handleViewDetail (row) {
            // 添加调试日志
            console.log('原始行数据:', row)
            const mediaUrl = row.photo_url || row.video_url
            console.log('媒体信息:', {
                photo_url: row.photo_url,
                video_url: row.video_url,
                mediaUrl: mediaUrl,
                rowData: JSON.stringify(row)  // 添加完整行数据打印
            })
            const longitude = row.location?.[0] || '未知经度'
            const latitude = row.location?.[1] || '未知纬度'
            const addressWithCoordinates = `${row.address || '暂无地址信息'} (${longitude}, ${latitude})`
            this.currentDetail = {
                ...row,
                mediaUrl: mediaUrl || '',
                photos: mediaUrl ? [{ url: mediaUrl }] : [],
                address: addressWithCoordinates,
                handler: row.handler || '未分配', // 设置处理人
      console.log('查看详情数据:', row);
      // 重要:重置上传组件的文件列表
      this.$nextTick(() => {
        if (this.$refs.upload) {
          // 如果是多个上传组件,需要处理数组情况
          if (Array.isArray(this.$refs.upload)) {
            this.$refs.upload.forEach(upload => {
              upload.clearFiles();
            });
          } else {
            this.$refs.upload.clearFiles();
            }
            this.detailVisible = true
        }
      });
      const detailData = {
        ...row,
        processingDetail: row.processing_details || '',
        mediaUrl: row.photo_url || row.video_url || '',
        updatePhotoUrl: row.update_photo_url || '',
        photos: [], // 重置photos数组
      };
      if ([4, 5].includes(row.status) && !detailData.processingDetail) {
        this.fetchProcessingDetails(row.id);
      }
      this.currentDetail = detailData;
      console.log('当前详情数据:', this.currentDetail);
      this.detailVisible = true;
    },
    // 新增:获取处理详情的方法
    async fetchProcessingDetails(id) {
      try {
        const response = await getTicketInfo(id); // 假设有这个API
        if (response?.data?.data?.processing_details) {
          this.currentDetail.processingDetail = response.data.data.processing_details;
        }
      } catch (error) {
        console.error('获取处理详情失败:', error);
      }
        },
        openMap () {
            this.$message.info("地图选址功能暂未实现")
      const areaCode = this.userInfo.detail.areaCode;
      const subAreaCode = areaCode ? areaCode.substring(0, 6) : '';
      const adcodeObj = getAdcodeObj(geoJson, 'adcode', subAreaCode);
      console.log('区域代码:', subAreaCode);
      console.log('getAdcodeObj返回值:', {
        完整对象: adcodeObj,
        级别: adcodeObj?.level,
        名称: adcodeObj?.name,
        代码: adcodeObj?.adcode,
        中心点: adcodeObj?.center,
        边界: adcodeObj?.polyline,
      });
      this.$message.info("地图选址功能暂未实现");
        },
        handlePreview (file) {
            this.$message.info(`预览图片:${file.name}`)
      this.$message.info(`预览图片:${file.name}`);
        },
        handleRemove (file) {
            this.$message.info(`移除图片:${file.name}`)
      this.$message.info(`移除图片:${file.name}`);
        },
        refreshChange () {
            if (this.isFetching) return
            this.fetchTableData()
      if (this.isFetching) return;
      this.fetchTableData();
        },
        onLoad () {
            if (this.isFetching) return
            this.fetchTableData()
      if (this.isFetching) return;
      this.fetchTableData();
        },
        async exportData () {
            try {
                this.loading = true
                const currentTab = this.tabs.find(tab => tab.name === this.activeTab)
        this.loading = true;
        const currentTab = this.tabs.find(tab => tab.name === this.activeTab);
                // 使用与查询列表相同的参数构造逻辑
                const params = {
@@ -913,27 +1205,27 @@
                    start_date: this.filters.dateRange?.[0] ? this.formatDate(this.filters.dateRange[0]) : undefined,
                    end_date: this.filters.dateRange?.[1] ? this.formatDate(this.filters.dateRange[1]) : undefined,
                    current: 1,
                    size: 10000
                }
          size: 10
        };
                const response = await getList(params)
        const response = await getList(params);
                if (!response?.data?.data?.records) {
                    throw new Error('接口返回数据格式不正确')
          throw new Error('接口返回数据格式不正确');
                }
                const { records } = response.data.data
        const { records } = response.data.data;
                // 使用与查询列表相同的过滤逻辑
                let filteredRecords = records
        let filteredRecords = records;
                if (currentTab?.name === 'myTickets') {
                    filteredRecords = records.filter(item =>
                        String(item.create_user_id) === String(item.user_id)
                    )
          );
                }
                const exportData = filteredRecords.map(item => {
                    const longitude = Number(item.longitude) || 0
                    const latitude = Number(item.latitude) || 0
          const longitude = Number(item.longitude) || 0;
          const latitude = Number(item.latitude) || 0;
                    return {
                        工单编号: item.event_num || '',
                        工单名称: item.event_name || '',
@@ -946,12 +1238,12 @@
                        创建人: item.create_user || '',
                        处理人: item.update_user || '',
                        工单状态: this.mapStatus(Number(item.status || 0))
                    }
                })
          };
        });
                if (exportData.length === 0) {
                    this.$message.warning('没有数据可供导出')
                    return
          this.$message.warning('没有数据可供导出');
          return;
                }
                const headers = [
@@ -966,75 +1258,295 @@
                    '创建人',
                    '处理人',
                    '工单状态'
                ]
        ];
                export_json_to_excel(headers, exportData, '工单数据')
                this.$message.success('数据导出成功')
        export_json_to_excel(headers, exportData, '工单数据');
        this.$message.success('数据导出成功');
            } catch (error) {
                console.error('导出失败:', error)
                this.$message.error(error.message || '导出失败,请稍后重试')
        console.error('导出失败:', error);
        this.$message.error(error.message || '导出失败,请稍后重试');
            } finally {
                this.loading = false
        this.loading = false;
            }
        },
        handleDepartmentChange (deptId) {
            this.form.handler = ''
      this.form.handler = '';
    },
    handleDispatchDepartmentChange(deptId) {
      this.dispatchForm.handler = ''; // 清空处理人选择
        },
        // 文件改变时的钩子
        handleFileChange (file, fileList) {
            this.form.photos = fileList
            this.currentDetail.photos = fileList
      this.form.photos = fileList;
      this.currentDetail.photos = fileList;
        },
        // 文件移除时的钩子
        handleUploadRemove (file, fileList) {
            this.form.photos = fileList
            this.currentDetail.photos = fileList
      this.form.photos = fileList;
      this.currentDetail.photos = fileList;
        },
        // 上传前的验证
        beforeUpload (file) {
            const isImage = file.type.includes('image')
            const isLt5M = file.size / 1024 / 1024 < 5
      const isImage = file.type.includes('image');
      const isLt5M = file.size / 1024 / 1024 < 5;
            if (!isImage) {
                this.$message.error('只能上传图片文件!')
                return false
        this.$message.error('只能上传图片文件!');
        return false;
            }
            if (!isLt5M) {
                this.$message.error('图片大小不能超过5MB!')
                return false
        this.$message.error('图片大小不能超过5MB!');
        return false;
            }
            return true
      return true;
        },
        approveTicket () {
            this.$message.success("工单已通过并派发")
    async approveTicket() {
      try {
        const data = {
          id: this.currentDetail.id,
          status: this.currentDetail.status,
          isPass: 0, // 0 表示通过
          eventName: this.currentDetail.orderName, // 工单名称
          eventType: this.currentDetail.type, // 工单类型
          processingDetails: this.currentDetail.remarkContent, // 使用 remarkContent 替代原来的 remark
          departmentId: this.dispatchForm.department, // 派发部门 ID
          handlerId: this.dispatchForm.handler, // 处理人 ID
        };
        const file = this.currentDetail.file || null; // 如果没有文件,则为 null
        const response = await flowEvent(data, file);
        if (response.data.code === 0) {
          this.$message.success('工单已通过');
          this.detailVisible = false;
          this.fetchTableData();
        } else {
          throw new Error(response.data.msg || '操作失败');
        }
      } catch (error) {
        console.error('通过操作失败:', error);
        this.$message.error(error.message || '操作失败,请稍后重试');
      }
        },
        rejectTicket () {
            this.$message.error("工单未通过")
    async rejectTicket() {
      try {
        const data = {
          id: this.currentDetail.id,
          status: this.currentDetail.status,
          isPass: 1, // 1 表示不通过
        };
        const response = await flowEvent(data);
        if (response.data.code === 0) {
          this.$message.success('工单未通过');
          this.detailVisible = false;
          this.fetchTableData();
        } else {
          throw new Error(response.data.msg || '操作失败');
        }
      } catch (error) {
        console.error('不通过操作失败:', error);
        this.$message.error(error.message || '操作失败,请稍后重试');
      }
        },
        submitProcessing () {
            this.$message.success("处理详情已提交")
    async submitProcessing() {
      if (this.currentDetail.status !== 3) {
        this.$message.warning('只有处理中状态的工单可以提交处理详情');
        return;
      }
      try {
        const data = {
          id: this.currentDetail.id, // 当前工单 ID
          status: this.currentDetail.status, // 当前工单状态
          processing_details: this.currentDetail.processingDetail, // 事件处理详情
        };
        // 如果有图片,添加 file 参数
        const file = this.currentDetail.photos?.[0]?.raw || null;
        const response = await flowEvent(data, file);
        if (response.data.code === 0) {
          this.$message.success('处理详情提交成功');
          this.detailVisible = false;
          this.fetchTableData();
        } else {
          throw new Error(response.data.msg || '提交失败');
        }
      } catch (error) {
        console.error('处理详情提交失败:', error);
        this.$message.error(error.message || '提交失败,请稍后重试');
      }
        },
        markAsCompleted () {
            this.$message.success("工单已标记为完成")
      this.$message.success("工单已标记为完成");
        },
        completeTicket () {
            this.$message.success("工单已完成")
    async completeTicket() {
      try {
        if (!this.currentDetail.processingDetail) {
          this.$message.warning('请先填写事件处理详情');
          return;
        }
        const data = {
          id: this.currentDetail.id,
          status: this.currentDetail.status,
          processingDetails: this.currentDetail.processingDetail
        };
        // 如果有上传的图片,添加到请求中
        const file = this.currentDetail.photos?.[0]?.raw || null;
        const response = await flowEvent(data, file);
        if (response.data.code === 0) {
          this.$message.success('工单已完成');
          this.detailVisible = false;
          this.fetchTableData(); // 刷新列表数据
        } else {
          throw new Error(response.data.msg || '操作失败');
        }
      } catch (error) {
        console.error('完成工单失败:', error);
        this.$message.error(error.message || '操作失败,请稍后重试');
      }
    },
    async approveAndDispatch() {
      this.dispatchDialogVisible = true; // 打开派发对话框
    },
    async submitDispatch() {
      this.$refs.dispatchForm.validate(async (valid) => {
        if (valid) {
          try {
            const data = {
              id: this.currentDetail.id,
              status: this.currentDetail.status,
              isPass: 0, // 0 表示通过
              eventName: this.currentDetail.orderName, // 工单名称
              eventType: this.currentDetail.type, // 工单类型
              processingDetails: this.currentDetail.remarkContent, // 使用 remarkContent 替代原来的 remark
              createDept: this.dispatchForm.department, // 派发部门 ID
              updateUser: this.dispatchForm.handler, // 处理人 ID
            };
            const file = this.currentDetail.file || null; // 如果没有文件,则为 null
            const response = await flowEvent(data, file);
            if (response.data.code === 0) {
              this.$message.success('工单已成功派发');
              this.dispatchDialogVisible = false;
              this.detailVisible = false;
              this.fetchTableData();
            } else {
              throw new Error(response.data.msg || '派发失败');
            }
          } catch (error) {
            console.error('派发失败:', error);
            this.$message.error(error.message || '派发失败,请稍后重试');
          }
        }
      });
    },
    async finalizeTicket() {
      try {
        // 检查是否上传了图片
        if (!this.currentDetail.photos || !this.currentDetail.photos.length) {
          this.$message.warning('请上传处理图片');
          return;
        }
        const data = {
          id: this.currentDetail.id,
          status: this.currentDetail.status
        };
        const file = this.currentDetail.photos[0].raw;
        const response = await flowEvent(data, file);
        if (response.data.code === 0) {
          this.$message.success('工单已完结');
          this.detailVisible = false;
          this.fetchTableData();
        } else {
          throw new Error(response.data.msg || '操作失败');
        }
      } catch (error) {
        console.error('完结工单失败:', error);
        this.$message.error(error.message || '操作失败,请稍后重试');
      }
    },
    // 添加编辑方法
    handleEdit(row) {
      // 从原始数据中获取 id 和 dept_id
      const originalDeptId = row.department?.value || row.dept_id;
      this.form = {
        id: row.id, // 保存原始 id
        name: row.orderName,
        type: row.event_dict_key, // 使用原始 key 值
        department: originalDeptId,
        handler: row.handler,
        algorithm: row.content,
        location: row.location,
        address: row.address,
        content: row.remarkContent,
        photos: [],
        remarkContent: row.remarkContent,
      };
      // 如果有图片,添加到表单中
      if (row.photo_url) {
        this.form.photos = [{
          name: 'existing-photo',
          url: row.photo_url
        }];
      }
      this.dialogVisible = true;
    },
    // 添加删除方法
    handleDelete(row) {
      this.$confirm('确认删除该工单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        try {
          const response = await flowEvent({
            id: row.id,
            status: 0,
            isDelete: 1
          });
          if (response.data.code === 0) {
            this.$message.success('删除成功');
            this.fetchTableData();
          } else {
            throw new Error(response.data.msg || '删除失败');
          }
        } catch (error) {
          console.error('删除失败:', error);
          this.$message.error(error.message || '删除失败,请稍后重试');
        }
      }).catch(() => {});
        },
    },
    watch: {
        tableData: {
            handler () {
                this.updateTabCounts()
        this.updateTabCounts();
            },
            deep: true
        },
    }
}
};
</script>
<style lang="scss" scoped>
@@ -1047,15 +1559,18 @@
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
  gap: 8px; // 使用 gap 统一设置间距
    .filter-item {
        margin-right: 10px;
        margin-bottom: 10px;
        width: 200px;
    width: 160px; // 减小宽度
    }
    .date-picker {
        width: 150px;
    width: 240px; // 日期选择器宽度适当调整
  }
  .el-button {
    margin-left: 0; // 覆盖 element-ui 默认的按钮间距
    }
}
@@ -1324,4 +1839,21 @@
    color: #303133;
    word-break: break-word;
}
.readonly-processing-detail {
  background-color: #f5f7fa;
  padding: 12px;
  border-radius: 4px;
  min-height: 40px;
  color: #606266;
  line-height: 1.5;
}
// 添加删除按钮样式
.danger-button {
  color: #F56C6C;
}
.danger-button:hover {
  color: #f78989;
}
</style>