无人机管理后台前端(已迁走)
张含笑
2025-11-19 ba069239a9a7046f0681238b0e75c37931e22325
feat:分离
1 files modified
3 files added
1861 ■■■■■ changed files
src/views/tickets/ticket.vue 899 ●●●●● patch | view | raw | blame | history
src/views/tickets/ticketComponent/CreateTicketDialog.vue 616 ●●●●● patch | view | raw | blame | history
src/views/tickets/ticketComponent/DispatchDialog.vue 229 ●●●●● patch | view | raw | blame | history
src/views/tickets/ticketComponent/RecheckDialog.vue 117 ●●●●● patch | view | raw | blame | history
src/views/tickets/ticket.vue
@@ -270,207 +270,18 @@
    </el-tabs>
    <!-- 新建工单对话框 -->
    <el-dialog
      v-model="dialogVisible"
      v-if="dialogVisible"
      title="新建工单"
      width="70%"
      :close-on-click-modal="false"
      @close="resetForm"
    >
      <el-form
        :model="form"
        :rules="rules"
        ref="form"
        label-width="90px"
        class="create-ticket-form"
      >
        <div class="form-section">
          <el-row :gutter="16">
            <el-col :span="12">
              <el-form-item label="工单名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入工单名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工单类型" prop="type">
                <el-select
                  @change="handleTypeChange"
                  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-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="16">
            <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>
              </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>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="16">
            <el-col :span="12">
              <el-form-item label="关联算法" prop="algorithm">
                <el-select
                  v-model="form.algorithm"
                  multiple
                  placeholder="请选择关联算法"
                  class="full-width"
                  :disabled="!form.type"
                >
                  <el-option
                    v-for="item in algorithms2"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="事件位置" prop="location">
                <div class="location-wrapper">
                  <avue-input-map
                    v-model="form.location"
                    :clearable="false"
                    :params="mapParams"
                    @change="handleLocationChange"
                    type="button"
                  >
                    <el-button type="primary" plain class="map-button">
                      <i class="el-icon-map-location"></i> 地图选点
                    </el-button>
                  </avue-input-map>
                  <!-- <div v-if="form.location?.length >= 3">
    {{ form.location[2] || '获取地址中...' }}
  </div> -->
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="16">
            <el-col :span="12">
              <el-form-item label="工单内容" prop="content">
                <el-input
                  type="textarea"
                  v-model="form.content"
                  :rows="4"
                  placeholder="请输入工单内容描述"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="事件图片" prop="photos" required class="upload-wrapper">
                <el-upload
                  v-if="createoredit === 1"
                  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/*"
                  class="create-upload"
                >
                  <template v-if="form.photos.length < 1">
                    <!-- <i class="el-icon-plus">+</i> -->
                    <div class="el-icon-plus">
                      <span>+</span>
                    </div>
                  </template>
                </el-upload>
                <el-upload
                  v-else
                  ref="upload"
                  :action="'#'"
                  :auto-upload="false"
                  list-type="picture-card"
                  :on-change="handleFileChange"
                  :on-remove="handleUploadRemove"
                  :before-upload="beforeUpload"
                  :file-list="popupShowImage(form.photos)"
                  :limit="1"
                  accept="image/*"
                  class="create-upload"
                >
                  <template v-if="form.photos.length < 1">
                    <div class="el-icon-plus">
                      <span>+</span>
                    </div>
                  </template>
                </el-upload>
                <div class="upload-tip">需上传含有地址信息的照片(jpg、jpeg、png),且不超过5M</div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <template #footer>
        <div class="dialog-footer-new">
          <el-button
            type="danger"
            :loading="submitLoading"
            @click="submitForm"
            icon="el-icon-position"
            >发布
          </el-button>
          <el-button
            type="infoprimary"
            plain
            :loading="draftLoading"
            @click="saveDraft"
            icon="el-icon-document-add"
            >存草稿
          </el-button>
          <el-button @click="handleCancel" icon="el-icon-circle-close">取 消</el-button>
        </div>
      </template>
    </el-dialog>
   <create-ticket-dialog
  v-model="dialogVisible"
  :departments="departments"
  :department-users="departmentUsers"
  :types="types"
  :all-algorithms="allAlgorithms"
  :edit-data="editFormData"
  :map-center="inputMapShowDefaultCenter"
  @create-success="handleCreateSuccess"
  @draft-success="handleDraftSuccess"
  @create-error="handleCreateError"
/>
    <!-- 工单详情对话框 -->
    <el-dialog
@@ -814,6 +625,7 @@
                icon="el-icon-check"
                >受理
              </el-button>
              <el-button
                v-if="hasProcessingBtnPermission()"
                type="danger"
@@ -855,52 +667,16 @@
    </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
            filterable
            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" icon="el-icon-circle-close"
          >取消
        </el-button>
        <el-button type="primary" :loading="dispatchLoading" @click="submitDispatch"
          >确认派发
        </el-button>
      </template>
    </el-dialog>
      <dispatch-dialog
        v-model="dispatchDialogVisible"
        :current-detail="currentDetail"
        :departments="departments"
        :department-users="departmentUsers"
        :algorithms="algorithms"
        :types="types"
        @dispatch-success="handleDispatchSuccess"
        @dispatch-error="handleDispatchError"
      />
    <!-- 添加在其他 dialog 组件之后 -->
    <el-dialog
@@ -984,20 +760,11 @@
    </el-dialog>
    <!-- 复核弹出层 -->
    <el-dialog
      v-model="reCheckDialog"
      title="工单复核"
      width="30%"
      append-to-body
      class="ztzf-dialog-mange"
      @close="reCheckDialog = false"
    >
      <div class="dialog-footer">
        <el-button type="primary" @click="reCheckConfirm(1)">人工复核</el-button>
        <el-button type="primary" @click="reCheckConfirm(2)">无人机复核</el-button>
      </div>
    </el-dialog>
    <recheck-dialog
  v-model="reCheckDialog"
  :recheck-data="reCheckData"
  @recheck-success="handleRecheckSuccess"
/>
  </basic-container>
</template>
@@ -1028,7 +795,9 @@
import getBaseConfig from '@/buildConfig/config';
import CreateQRcode from '@/components/CreateQRcode/CreateQRcode.vue';
import { CircleClose } from '@element-plus/icons-vue';
import RecheckDialog from '@/views/tickets/ticketComponent/RecheckDialog.vue';
import DispatchDialog from '@/views/tickets/ticketComponent/DispatchDialog.vue';
import CreateTicketDialog from '@/views/tickets/ticketComponent/CreateTicketDialog.vue';
const { envName } = getBaseConfig();
function regExp(label, name) {
@@ -1037,13 +806,13 @@
}
export default {
  components: { elTooltipCopy, CreateQRcode },
  components: { elTooltipCopy, CreateQRcode,RecheckDialog,DispatchDialog,CreateTicketDialog, },
  name: 'TicketPage',
  data() {
    return {
      currentIndex: null, // 当前显示的数据索引
      submitLoading: false, // 新增loading状态
      draftLoading: false,
      approveLoading: false,
      rejectLoading: false,
      dispatchLoading: false,
@@ -1151,54 +920,11 @@
        total: 0,
      },
      dialogVisible: false,
       editFormData: null, // 专门用于存储编辑数据的对象
        createoredit: '', // 可以删除这个字段,因为组件内部会判断
      detailVisible: false,
      currentDetail: {},
      form: {
        name: '',
        type: '',
        department: '',
        handler: '',
        algorithm: [], // 关联算法改为数组
        location: [], // 将存储为[经度, 纬度, 地址]格式
        address: '',
        photos: [],
        content: '', // 新增字段,用于存储后端返回的 content
      },
      rules: {
        name: [{ required: true, message: '请输入工单名称', trigger: 'blur' }],
        type: [{ required: true, message: '请选择工单类型', trigger: 'change' }],
        department: [{ required: true, message: '请选择所属部门', trigger: 'change' }],
        handler: [{ required: true, message: '请选择处理人员', trigger: 'change' }],
        content: [{ required: true, message: '请输入工单内容', trigger: 'blur' }],
        algorithm: [{ required: true, message: '请选择关联算法', trigger: 'change' }],
        location: [
          {
            required: true,
            validator: (rule, value, callback) => {
              if (!value || value.length < 2) {
                callback(new Error('请选择位置信息'));
              } else if (!value[0] || !value[1]) {
                callback(new Error('请选择位置信息'));
              } else {
                callback();
              }
            },
            trigger: 'change',
          },
        ],
        photos: [
          {
            validator: (rule, value, callback) => {
              if (!this.form.photos || this.form.photos.length === 0) {
                callback(new Error('请上传工单图片'));
              } else {
                callback();
              }
            },
            trigger: 'change',
          },
        ],
      },
      departmentUsers: {},
      loading: false,
      globalCounts: {},
@@ -1211,14 +937,7 @@
      dispatchDepartment: '', // 新增:派发部门
      dispatchHandler: '', // 新增:派发处理人
      dispatchDialogVisible: false, // 新增:派发对话框可见性
      dispatchForm: {
        department: '',
        handler: '',
      }, // 新增:派发表单数据
      dispatchRules: {
        department: [{ required: true, message: '请选择部门', trigger: 'change' }],
        handler: [{ required: true, message: '请选择处理人', trigger: 'change' }],
      }, // 新增:派发表单验证规则
      stepInfos: [], // 新增:存储步骤信息
      fixedStatuses: ['2', '0', '3', '4'], // 固定的五个状态
      userNameToIdMap: {}, // 新增用户名到ID的映射
@@ -1235,6 +954,7 @@
      // 复核弹窗
      reCheckDialog: false,
      reCheckData: {}, // 专门用于存储复核数据的对象
      treePropsSF: {
        label: 'dictValue',
        value: 'id',
@@ -1759,34 +1479,7 @@
        this.$message.error('加载下拉框数据失败');
      }
    },
    // 工单类型变化时触发
    handleTypeChange(typeValue) {
      this.form.algorithm = [];
      if (!typeValue) {
        // 未选择类型时清空算法列表
        this.algorithms2 = [];
        return;
      }
      const matchedCategory = this.allAlgorithms.find(category => category.dict_key === typeValue);
      if (
        !matchedCategory ||
        !matchedCategory.algorithms ||
        matchedCategory.algorithms.length === 0
      ) {
        // 无匹配的算法时清空
        this.algorithms2 = [];
        this.$message.info('该工单类型暂无关联算法');
        return;
      }
      this.algorithms2 = matchedCategory.algorithms.map(algo => ({
        label: algo.dict_value,
        value: algo.dict_key,
        dict_key: algo.dict_key,
        dict_value: algo.dict_value,
      }));
    },
    async fetchTableData() {
      if (this.isFetching) return;
@@ -1892,174 +1585,6 @@
      }
    },
    async submitForm() {
      if (this.submitLoading) return; // 防止重复提交
      this.submitLoading = true;
      try {
        // 提交时需要完整验证
        await this.$refs.form.validate();
        // 验证位置信息
        if (!this.form.location || this.form.location.length < 2) {
          this.$message.warning('请在地图上选择位置');
          return;
        }
        // 修改图片验证逻辑
        if (!this.form.photos || this.form.photos.length === 0) {
          this.$message.warning('请上传工单图片');
          return;
        }
        let [lng, lat] = this.disposeLocation(true, this.form);
        const submitData = {
          eventName: this.form.name,
          content: this.form.content,
          workType: '1',
          longitude: lng,
          latitude: lat,
          address: this.form.address,
          workOrderTypeDictKey: this.form.type,
          aiType: Array.isArray(this.form.algorithm) ? this.form.algorithm : [this.form.algorithm], // 传数组
          updateUser: this.form.handler,
          createDept: this.form.department,
          isDraft: 0,
        };
        if (this.form.id) {
          submitData.id = this.form.id;
        }
        // 修改获取文件的逻辑
        let file = null;
        const photoInfo = this.form.photos[0];
        if (photoInfo.raw) {
          // 如果有新上传的文件,使用新文件
          file = photoInfo.raw;
        } else if (photoInfo.existingUrl) {
          // 如果是已存在的图片,将URL添加到提交数据中
          submitData.photoUrl = photoInfo.existingUrl;
        } else {
          this.$message.warning('图片文件无效,请重新上传');
          return;
        }
        const response = await createTicket(submitData, file);
        if (response.data.code === 0) {
          this.$message.success('工单创建成功');
          this.dialogVisible = false;
          this.fetchTableData();
        } else {
          throw new Error(response.data.msg || '创建失败');
        }
      } catch (error) {
        if (error.message.includes('验证未通过')) {
          this.$message.warning('请填写完整的工单信息');
        } else {
          this.$message.error(error.message || '工单创建失败,请稍后重试');
        }
      } finally {
        this.submitLoading = false;
      }
    },
    async saveDraft() {
      if (this.draftLoading) return; // 防止重复提交
      this.draftLoading = true;
      try {
        let handlerValue = this.form.handler;
        if (!handlerValue || handlerValue === '未分配') {
          handlerValue = undefined;
        }
        // 验证位置信息
        if (
          !this.form.location ||
          this.form.location.length < 2 ||
          !this.form.location[0] ||
          !this.form.location[1]
        ) {
          this.$message.warning('请在地图上选择位置');
          return;
        }
        let [lng, lat] = this.disposeLocation(true, this.form);
        const submitData = {
          id: this.form.id,
          eventName: this.form.name || undefined,
          content: this.form.content || undefined,
          workType: '1',
          longitude: lng,
          latitude: lat,
          address: this.form.address || undefined,
          workOrderTypeDictKey: this.form.type || undefined,
          aiType:
            this.form.algorithm && this.form.algorithm.length > 0 ? this.form.algorithm : undefined, // 传数组
          updateUser: handlerValue,
          createDept: this.form.department || undefined,
          isDraft: 1,
        };
        // 草稿时也至少需要工单名称
        if (!submitData.eventName) {
          this.$message.warning('请输入工单名称');
          return;
        }
        // 过滤掉所有 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);
        if (response.data.code === 0) {
          this.$message.success('草稿保存成功');
          this.dialogVisible = false;
          (this.form = {
            name: '',
            type: '',
            department: '',
            handler: '',
            algorithm: [], // 关联算法改为数组
            location: [], // 将存储为[经度, 纬度, 地址]格式
            address: '',
            photos: [],
            content: '', // 新增字段,用于存储后端返回的 content
          }),
            this.fetchTableData();
        } else {
          throw new Error(response.data.msg || '保存失败');
        }
      } catch (error) {
        this.$message.error(error.message || '保存草稿失败,请稍后重试');
      } finally {
        this.draftLoading = false;
      }
    },
    handleCancel() {
      this.resetForm();
      this.dialogVisible = false;
    },
    handleLocationChange(val) {
      let locationValue = val.value;
      if (locationValue && locationValue.length >= 2) {
        // 兼容第三项为地址
        const [lng, lat] = gcj02ToWgs84(locationValue[0], locationValue[1]);
        this.form.location = [Number(lng), Number(lat), locationValue[2] || ''];
        this.form.address = locationValue[2] || '';
      } else {
        this.form.location = [];
        this.form.address = '';
      }
    },
    formatDate(date) {
      if (!date) return undefined;
@@ -2176,30 +1701,11 @@
      await this.fetchTableData();
    },
    handleAdd() {
      this.createoredit = 1;
  handleAdd() {
      this.editFormData = null; // 设置为 null 表示新建模式
      this.dialogVisible = true;
      this.mapParams.center = [...this.inputMapShowDefaultCenter];
      this.form.location = [];
    },
    resetForm() {
      this.form = {
        name: '',
        type: '',
        department: '',
        handler: '',
        algorithm: [], // 关联算法改为数组
        location: [], // 将存储为[经度, 纬度, 地址]格式
        address: '',
        content: '',
        photos: [],
        content: '', // 新增字段,用于存储后端返回的 content
      };
      if (this.$refs.form) {
        this.$refs.form.resetFields();
      }
    },
    formatLocation(location) {
      if (!Array.isArray(location)) {
@@ -2281,7 +1787,7 @@
      console.log('this.currentDetail', this.currentDetail);
      this.detailVisible = true;
      this.handleTypeChange(this.currentDetail.type);
      this.$nextTick(() => {
@@ -2402,47 +1908,6 @@
        工单状态: this.mapStatus(Number(item.status || 0)),
      };
    },
    handleDepartmentChange(deptId) {
      this.form.handler = '';
    },
    handleDispatchDepartmentChange(deptId) {
      this.dispatchForm.handler = ''; // 清空处理人选择
    },
    // 文件改变时的钩子
    handleFileChange(file, fileList) {
      // 保持最新的文件列表
      this.form.photos = fileList.map(item => ({
        ...item,
        existingUrl: item.url && !item.raw ? item.url : null, // 标记已存在的图片URL
      }));
      this.currentDetail.photos = this.form.photos;
    },
    // 文件移除时的钩子
    handleUploadRemove(file, fileList) {
      this.form.photos = fileList;
      this.currentDetail.photos = fileList;
    },
    // 上传前的验证
    beforeUpload(file) {
      const isImage = file.type.includes('image');
      const isLt5M = file.size / 1024 / 1024 < 5;
      if (!isImage) {
        this.$message.error('只能上传图片文件!');
        return false;
      }
      if (!isLt5M) {
        this.$message.error('图片大小不能超过5MB!');
        return false;
      }
      return true;
    },
    async approveTicket() {
      if (this.approveLoading) return;
      this.approveLoading = true;
@@ -2589,6 +2054,21 @@
      console.log('受理', this.currentDetail);
    },
      // 派发成功回调
    handleDispatchSuccess() {
      this.detailVisible = false;
      this.fetchTableData();
    },
    // 派发错误回调
    handleDispatchError(error) {
      // 可以在这里处理错误,或者保持空实现
      console.error('派发失败:', error);
    },
    hasProcessingBtnPermission() {
      // undefined 或 false 都返回 false,只有 true 返回 true
      //  console.log('权限检查:', this.permission.tickets_processing_btn)
@@ -2605,85 +2085,7 @@
      return this.permission && this.permission.tickets_review_btn === true;
    },
    async submitDispatch() {
      if (this.dispatchLoading) return;
      if (!this.currentDetail.orderName || !this.currentDetail.orderName.trim()) {
        this.$message.warning('请填写工单名称');
        return;
      }
      if (!this.currentDetail.type) {
        this.$message.warning('请选择工单类型');
        return;
      }
      if (!this.currentDetail.content || !this.currentDetail.content.trim()) {
        this.$message.warning('请填写工单内容');
        return;
      }
      if (!this.dispatchForm.department) {
        this.$message.warning('请选择部门');
        return;
      }
      if (!this.dispatchForm.handler) {
        this.$message.warning('请选择处理人');
        return;
      }
      this.dispatchLoading = true;
      console.log('派发成功', this.currentDetail);
      const isValue = this.algorithms.some(item => item.value === this.currentDetail.aiType);
      let resultValue;
      if (isValue) {
        // 如果已经是value,直接使用
        resultValue = this.currentDetail.aiType;
      } else {
        // 否则查找对应的value
        const matched = this.algorithms.find(
          item => item.dict_value === this.currentDetail.aiType ||
                  item.label === this.currentDetail.aiType
        );
        resultValue = matched ? matched.value : null;
      }
// console.log('resultValue',resultValue);
      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, // 工单名称
              eventNum: this.currentDetail.orderNumber,
              workOrderTypeDictKey: this.currentDetail.type, // 直接使用原始的 dict_key
              content: this.currentDetail.content, // 使用 content 替代原来的 remark
              createDept: this.dispatchForm.department, // 派发部门 ID
              updateUser: this.dispatchForm.handler, // 处理人 ID
              aiType:resultValue,
            };
            console.log('派发', data);
            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 || '派发失败,请稍后重试');
          } finally {
            this.dispatchLoading = false;
          }
        } else {
          this.dispatchLoading = false;
        }
      });
    },
    async finalizeTicket() {
      if (this.finalizeLoading) return;
      this.finalizeLoading = true;
@@ -2720,122 +2122,24 @@
    },
    // 添加编辑方法
    // 编辑工单 - 简化方法
    handleEdit(row) {
      this.createoredit = 2;
      console.log('编辑原始数据:', row);
      // 尝试从row.dept_id或通过部门名称查找对应的部门ID
      let deptId = row.dept_id; // 优先使用原始数据中的dept_id
      // 如果没有dept_id,则通过部门名称查找
      if (!deptId) {
        // 输出所有可用的部门数据用于调试
        console.log('可用部门列表:', this.departments);
        console.log('当前部门名称:', row.department);
        const deptInfo = this.departments.find(
          dept => dept.label && dept.label.trim() === row.department.trim()
        );
        deptId = deptInfo?.value;
      }
      // 获取工单类型值 - 从types中找到匹配的值
      const typeValue =
        this.types.find(t => t.value === row.type)?.value || row.work_order_type_dict_key;
      // 获取处理人ID - 使用userNameToIdMap映射
      const handlerId = this.userNameToIdMap[row.handler] || row.handler;
      console.log('数据映射:', {
        部门名称: row.department,
        找到的部门ID: deptId,
        原始处理人: row.handler,
        处理人ID: handlerId,
        原始工单类型: row.type,
        映射后类型值: typeValue,
      });
      // 修改算法数组的处理逻辑
      let algorithmArr = [];
      if (Array.isArray(row.aiType)) {
        algorithmArr = row.aiType;
      } else if (typeof row.aiType === 'string' && row.aiType) {
        // 首先尝试将字符串按照逗号或顿号分割
        algorithmArr = row.aiType.split(/[,、]/).map(item => item.trim());
      }
      // 确保算法值与选项匹配
      algorithmArr = algorithmArr
        .map(item => {
          // 如果是字符串值,尝试找到对应的 dict_key
          if (typeof item === 'string') {
            const matchedAlgorithm = this.algorithms.find(
              algo => algo.dict_value === item || algo.dict_key === item
            );
            return matchedAlgorithm ? matchedAlgorithm.dict_key : item;
          }
          return item;
        })
        .filter(Boolean); // 过滤掉无效值
      console.log('算法处理:', {
        原始值: row.aiType,
        分割后: algorithmArr,
      });
      this.form = {
        id: row.id,
        name: row.orderName,
        type: typeValue,
        department: deptId,
        handler: handlerId,
        algorithm: algorithmArr,
        location:
          Array.isArray(row.location) && row.location.length >= 2
            ? [Number(row.location[0]), Number(row.location[1])]
            : [],
        address: row.address || '',
        content: row.content,
        photos: [],
      };
      let curLocation = [];
      if (Array.isArray(row.location) && row.location.length >= 2) {
        let [lng, lat] = this.disposeLocation(false, row);
        curLocation = [lng, lat, row.location[2] || row.address || ''];
      }
      this.form.location = curLocation;
      this.form.address = this.form.location[2] || '';
      // 设置地图中心点
      if (Array.isArray(this.form.location) && this.form.location.length >= 2) {
        this.mapParams.center = [Number(this.form.location[0]), Number(this.form.location[1])];
      } else {
        this.mapParams.center = [...this.inputMapShowDefaultCenter];
      }
      // 如果有图片,添加到表单中
      if (row.photo_url) {
        // 创建一个带有必要信息的文件对象
        this.form.photos = [
          {
            name: 'existing-photo.jpg', // 添加默认扩展名
            url: row.photo_url, // 用于预览的URL
            status: 'success', // 标记为已上传成功
            raw: null, // 初始化为null
            existingUrl: row.photo_url, // 保存原始URL,用于区分是否为已存在的图片
          },
        ];
      }
      // 调试输出
      console.log('编辑表单数据:', {
        原始算法值: row.aiType,
        处理后算法值: algorithmArr,
        表单数据: this.form,
      });
      this.editFormData = row; // 设置编辑数据
      this.dialogVisible = true;
    },
    // 创建成功回调
    handleCreateSuccess() {
      this.fetchTableData();
    },
    // 草稿保存成功回调
    handleDraftSuccess() {
      this.fetchTableData();
    },
    // 创建失败回调
    handleCreateError(error) {
      console.error('工单操作失败:', error);
    },
    // 添加删除方法
@@ -3144,58 +2448,17 @@
    },
    // 复核按钮
    reCheck(row) {
  reCheck(row) {
      this.reCheckData = row;
      this.reCheckDialog = true;
    },
    // 复核确认框按钮事件
    reCheckConfirm(key) {
      const that = this;
      if (key == 1) {
        getReviewById(that.reCheckData.id).then(res => {
          that.reCheckDialog = false;
          that.page.currentPage = 1;
          that.fetchTableData();
          that.fetchTabCounts();
        });
      } else {
        const loading = ElLoading.service({
          lock: true,
          text: '复核任务创建中……',
          background: 'rgba(0, 0, 0, 0.7)',
        });
        function closeConfirm() {
          that.reCheckDialog = false;
          that.page.currentPage = 1;
          that.fetchTableData();
          that.fetchTabCounts();
          loading.close();
        }
        // 获取时间的接口
        getCreateEventJob(that.reCheckData.id)
          .then(res => {
            ElMessageBox.confirm(`预计复核执行时间为${res.data.data}`, '提示', {
              confirmButtonText: '确定',
              showCancelButton: false, // 关键配置
              closeOnClickModal: false,
              closeOnPressEscape: false,
              type: 'warning',
            })
              .then(() => {
                closeConfirm();
              })
              .catch(() => {
                closeConfirm();
              });
          })
          .catch(() => {
            closeConfirm();
          });
      }
 // 复核成功回调
    handleRecheckSuccess() {
      this.page.currentPage = 1;
      this.fetchTableData();
      this.fetchTabCounts();
    },
    // 导出工单报表
    exportTheTick(row){
      const params = {
src/views/tickets/ticketComponent/CreateTicketDialog.vue
New file
@@ -0,0 +1,616 @@
<template>
  <el-dialog
    v-model="dialogVisible"
    title="新建工单"
    width="70%"
    :close-on-click-modal="false"
    @close="handleClose"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="formRef"
      label-width="90px"
      class="create-ticket-form"
      @submit.prevent
    >
      <div class="form-section">
        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="工单名称" prop="name">
              <el-input
                v-model="form.name"
                placeholder="请输入工单名称"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工单类型" prop="type">
              <el-select
                @change="handleTypeChange"
                v-model="form.type"
                placeholder="请选择工单类型"
                class="full-width"
                clearable
              >
                <el-option
                  v-for="item in types"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="处理部门" prop="department">
              <el-select
                v-model="form.department"
                placeholder="请选择处理部门"
                @change="handleDepartmentChange"
                class="full-width"
                clearable
              >
                <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"
                clearable
              >
                <el-option
                  v-for="user in availableHandlers"
                  :key="user.id"
                  :label="user.name"
                  :value="user.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="关联算法" prop="algorithm">
              <el-select
                v-model="form.algorithm"
                multiple
                placeholder="请选择关联算法"
                class="full-width"
                :disabled="!form.type"
                clearable
              >
                <el-option
                  v-for="item in availableAlgorithms"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事件位置" prop="location">
              <div class="location-wrapper">
                <avue-input-map
                  v-model="form.location"
                  :clearable="false"
                  :params="mapParams"
                  @change="handleLocationChange"
                  type="button"
                >
                  <el-button type="primary" plain class="map-button">
                    <i class="el-icon-map-location"></i> 地图选点
                  </el-button>
                </avue-input-map>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="16">
          <el-col :span="12">
            <el-form-item label="工单内容" prop="content">
              <el-input
                type="textarea"
                v-model="form.content"
                :rows="4"
                placeholder="请输入工单内容描述"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事件图片" prop="photos" required class="upload-wrapper">
              <el-upload
                ref="uploadRef"
                :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/*"
                class="create-upload"
              >
                <template v-if="form.photos.length < 1">
                  <div class="el-icon-plus">
                    <span>+</span>
                  </div>
                </template>
              </el-upload>
              <div class="upload-tip">需上传含有地址信息的照片(jpg、jpeg、png),且不超过5M</div>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <template #footer>
      <div class="dialog-footer-new">
        <el-button
          type="danger"
          :loading="submitLoading"
          @click="handleSubmit"
          icon="el-icon-position"
        >
          发布
        </el-button>
        <el-button @click="handleClose" icon="el-icon-circle-close">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
import { createTicket } from '@/api/tickets/ticket';
import { gcj02ToWgs84, wgs84ToGcj02 } from '@/utils/coordinateTransformation';
export default {
  name: 'CreateTicketDialog',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    departments: {
      type: Array,
      default: () => []
    },
    departmentUsers: {
      type: Object,
      default: () => ({})
    },
    types: {
      type: Array,
      default: () => []
    },
    allAlgorithms: {
      type: Array,
      default: () => []
    },
    editData: {
      type: Object,
      default: null
    },
    mapCenter: {
      type: Array,
      default: () => [115.861365, 28.621311]
    }
  },
  emits: ['update:modelValue', 'create-success', 'draft-success', 'create-error'],
  data() {
    return {
      form: {
        name: '',
        type: '',
        department: '',
        handler: '',
        algorithm: [],
        location: [],
        address: '',
        content: '',
        photos: []
      },
      rules: {
        name: [{ required: true, message: '请输入工单名称', trigger: 'blur' }],
        type: [{ required: true, message: '请选择工单类型', trigger: 'change' }],
        department: [{ required: true, message: '请选择所属部门', trigger: 'change' }],
        handler: [{ required: true, message: '请选择处理人员', trigger: 'change' }],
        content: [{ required: true, message: '请输入工单内容', trigger: 'blur' }],
        algorithm: [{ required: true, message: '请选择关联算法', trigger: 'change' }],
        location: [
          {
            required: true,
            validator: (rule, value, callback) => {
              if (!value || value.length < 2) {
                callback(new Error('请选择位置信息'));
              } else if (!value[0] || !value[1]) {
                callback(new Error('请选择位置信息'));
              } else {
                callback();
              }
            },
            trigger: 'change',
          },
        ],
        photos: [
          {
            validator: (rule, value, callback) => {
              if (!this.form.photos || this.form.photos.length === 0) {
                callback(new Error('请上传工单图片'));
              } else {
                callback();
              }
            },
            trigger: 'change',
          },
        ],
      },
      availableAlgorithms: [],
      mapParams: {
        zoom: 15,
        center: null
      },
      submitLoading: false,
      draftLoading: false
    };
  },
  computed: {
    dialogVisible: {
      get() {
        return this.modelValue;
      },
      set(value) {
        this.$emit('update:modelValue', value);
      }
    },
    availableHandlers() {
      return this.form.department ? this.departmentUsers[this.form.department] || [] : [];
    },
    isEditMode() {
      return !!this.editData;
    }
  },
  watch: {
    modelValue(newVal) {
      if (newVal) {
        this.initForm();
        this.mapParams.center = [...this.mapCenter];
      }
    }
  },
  methods: {
    initForm() {
      if (this.isEditMode && this.editData) {
        // 编辑模式:填充表单数据
        this.loadEditData();
      } else {
        // 新建模式:重置表单
        this.resetForm();
      }
    },
    loadEditData() {
      const data = this.editData;
      // 获取部门ID
      let deptId = data.dept_id;
      if (!deptId) {
        const deptInfo = this.departments.find(
          dept => dept.label && dept.label.trim() === data.department.trim()
        );
        deptId = deptInfo?.value;
      }
      // 获取工单类型值
      const typeValue = this.types.find(t => t.value === data.type)?.value || data.work_order_type_dict_key;
      // 处理算法数组
      let algorithmArr = [];
      if (Array.isArray(data.aiType)) {
        algorithmArr = data.aiType;
      } else if (typeof data.aiType === 'string' && data.aiType) {
        algorithmArr = data.aiType.split(/[,、]/).map(item => item.trim());
      }
      // 确保算法值与选项匹配
      algorithmArr = algorithmArr
        .map(item => {
          if (typeof item === 'string') {
            const matchedAlgorithm = this.allAlgorithms.find(
              algo => algo.dict_value === item || algo.dict_key === item
            );
            return matchedAlgorithm ? matchedAlgorithm.dict_key : item;
          }
          return item;
        })
        .filter(Boolean);
      // 处理位置数据
      let curLocation = [];
      if (Array.isArray(data.location) && data.location.length >= 2) {
        let [lng, lat] = this.disposeLocation(false, data);
        curLocation = [lng, lat, data.location[2] || data.address || ''];
      }
      this.form = {
        id: data.id,
        name: data.orderName,
        type: typeValue,
        department: deptId,
        handler: data.handler,
        algorithm: algorithmArr,
        location: curLocation,
        address: curLocation[2] || '',
        content: data.content,
        photos: data.photo_url ? [{
          name: 'existing-photo.jpg',
          url: data.photo_url,
          status: 'success',
          raw: null,
          existingUrl: data.photo_url,
        }] : []
      };
      // 更新算法选项
      this.handleTypeChange(typeValue);
    },
    resetForm() {
      this.form = {
        name: '',
        type: '',
        department: '',
        handler: '',
        algorithm: [],
        location: [],
        address: '',
        content: '',
        photos: []
      };
      this.availableAlgorithms = [];
      if (this.$refs.formRef) {
        this.$refs.formRef.clearValidate();
      }
    },
    handleClose() {
      this.dialogVisible = false;
      this.resetForm();
    },
    handleTypeChange(typeValue) {
      this.form.algorithm = [];
      if (!typeValue) {
        this.availableAlgorithms = [];
        return;
      }
      const matchedCategory = this.allAlgorithms.find(category => category.dict_key === typeValue);
      if (!matchedCategory || !matchedCategory.algorithms || matchedCategory.algorithms.length === 0) {
        this.availableAlgorithms = [];
        this.$message.info('该工单类型暂无关联算法');
        return;
      }
      this.availableAlgorithms = matchedCategory.algorithms.map(algo => ({
        label: algo.dict_value,
        value: algo.dict_key,
        dict_key: algo.dict_key,
        dict_value: algo.dict_value,
      }));
    },
    handleDepartmentChange(deptId) {
      this.form.handler = '';
    },
    handleLocationChange(val) {
      let locationValue = val.value;
      if (locationValue && locationValue.length >= 2) {
        const [lng, lat] = gcj02ToWgs84(locationValue[0], locationValue[1]);
        this.form.location = [Number(lng), Number(lat), locationValue[2] || ''];
        this.form.address = locationValue[2] || '';
      } else {
        this.form.location = [];
        this.form.address = '';
      }
    },
    handleFileChange(file, fileList) {
      this.form.photos = fileList.map(item => ({
        ...item,
        existingUrl: item.url && !item.raw ? item.url : null,
      }));
    },
    handleUploadRemove(file, fileList) {
      this.form.photos = fileList;
    },
    beforeUpload(file) {
      const isImage = file.type.includes('image');
      const isLt5M = file.size / 1024 / 1024 < 5;
      if (!isImage) {
        this.$message.error('只能上传图片文件!');
        return false;
      }
      if (!isLt5M) {
        this.$message.error('图片大小不能超过5MB!');
        return false;
      }
      return true;
    },
    async handleSubmit() {
      if (this.submitLoading) return;
      try {
        await this.$refs.formRef.validate();
        // 验证位置信息
        if (!this.form.location || this.form.location.length < 2) {
          this.$message.warning('请在地图上选择位置');
          return;
        }
        // 验证图片
        if (!this.form.photos || this.form.photos.length === 0) {
          this.$message.warning('请上传工单图片');
          return;
        }
        this.submitLoading = true;
        let [lng, lat] = this.disposeLocation(true, this.form);
        const submitData = {
          eventName: this.form.name,
          content: this.form.content,
          workType: '1',
          longitude: lng,
          latitude: lat,
          address: this.form.address,
          workOrderTypeDictKey: this.form.type,
          aiType: Array.isArray(this.form.algorithm) ? this.form.algorithm : [this.form.algorithm],
          updateUser: this.form.handler,
          createDept: this.form.department,
          isDraft: 0,
        };
        if (this.form.id) {
          submitData.id = this.form.id;
        }
        // 获取文件
        let file = null;
        const photoInfo = this.form.photos[0];
        if (photoInfo.raw) {
          file = photoInfo.raw;
        } else if (photoInfo.existingUrl) {
          submitData.photoUrl = photoInfo.existingUrl;
        } else {
          this.$message.warning('图片文件无效,请重新上传');
          return;
        }
        const response = await createTicket(submitData, file);
        if (response.data.code === 0) {
          this.$message.success(this.isEditMode ? '工单编辑成功' : '工单创建成功');
          this.$emit('create-success');
          this.handleClose();
        } else {
          throw new Error(response.data.msg || '操作失败');
        }
      } catch (error) {
        if (error.message.includes('验证未通过')) {
          this.$message.warning('请填写完整的工单信息');
        } else {
          this.$message.error(error.message || '操作失败,请稍后重试');
          this.$emit('create-error', error);
        }
      } finally {
        this.submitLoading = false;
      }
    },
    disposeLocation(goWgs84 = false, data) {
      let lng = '', lat = '';
      if (Array.isArray(data.location) && data.location.length > 0) {
        if (goWgs84) {
          lng = data.location?.[0] ? String(data.location[0]) : undefined;
          lat = data.location?.[1] ? String(data.location[1]) : undefined;
          if (lng && lat) {
            [lng, lat] = gcj02ToWgs84(Number(lng), Number(lat));
          }
        } else {
          lng = Number(data.location[0]);
          lat = Number(data.location[1]);
          if (lng && lat) {
            [lng, lat] = this.wgs84ToGcj02(Number(lng), Number(lat));
          }
        }
      }
      return [String(lng), String(lat)];
    },
  }
};
</script>
<style lang="scss" scoped>
.full-width {
  width: 100%;
}
.location-wrapper {
  width: 100%;
  height: auto;
}
.map-button {
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-tip {
  font-size: 12px;
  color: #909399;
  margin-top: 8px;
}
/* 新建工单和处理工单的上传组件样式 */
.create-upload,
.detail-upload {
  :deep(.el-upload--picture-card) {
    width: 120px;
    height: 100px;
    line-height: 100px;
  }
  /* 隐藏额外的上传按钮 */
  :deep(.el-upload.el-upload--picture-card) {
    display: none;
  }
  /* 当没有图片时显示上传按钮 */
  :deep(.el-upload.el-upload--picture-card:first-child) {
    display: flex;
  }
  /* 上传组件的预览图片样式 */
  :deep(.el-upload-list--picture-card .el-upload-list__item) {
    width: 120px;
    height: 100px;
  }
}
</style>
src/views/tickets/ticketComponent/DispatchDialog.vue
New file
@@ -0,0 +1,229 @@
<template>
  <el-dialog
    v-model="dialogVisible"
    title="派发工单"
    width="40%"
    :close-on-click-modal="false"
    @close="handleClose"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="formRef"
      label-width="100px"
      @submit.prevent
    >
      <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>
      </el-form-item>
      <el-form-item label="选择处理人" prop="handler">
        <el-select
          filterable
          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-form>
    <template #footer>
      <el-button @click="handleClose" icon="el-icon-circle-close">取消</el-button>
      <el-button
        type="primary"
        :loading="loading"
        @click="handleSubmit"
        icon="el-icon-check"
      >
        确认派发
      </el-button>
    </template>
  </el-dialog>
</template>
<script>
import { flowEvent } from '@/api/tickets/ticket';
export default {
  name: 'DispatchDialog',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    currentDetail: {
      type: Object,
      default: () => ({})
    },
    departments: {
      type: Array,
      default: () => []
    },
    departmentUsers: {
      type: Object,
      default: () => ({})
    },
    algorithms: {
      type: Array,
      default: () => []
    },
    types: {
      type: Array,
      default: () => []
    }
  },
  emits: ['update:modelValue', 'dispatch-success', 'dispatch-error'],
  data() {
    return {
      form: {
        department: '',
        handler: ''
      },
      rules: {
        department: [{ required: true, message: '请选择部门', trigger: 'change' }],
        handler: [{ required: true, message: '请选择处理人', trigger: 'change' }]
      },
      loading: false
    };
  },
  computed: {
    dialogVisible: {
      get() {
        return this.modelValue;
      },
      set(value) {
        this.$emit('update:modelValue', value);
      }
    },
    availableHandlers() {
      return this.form.department ? this.departmentUsers[this.form.department] || [] : [];
    }
  },
  watch: {
    modelValue(newVal) {
      if (newVal) {
        this.resetForm();
      }
    }
  },
  methods: {
    resetForm() {
      this.form = {
        department: '',
        handler: ''
      };
      if (this.$refs.formRef) {
        this.$refs.formRef.clearValidate();
      }
    },
    handleClose() {
      this.dialogVisible = false;
      this.resetForm();
    },
    handleDepartmentChange(deptId) {
      this.form.handler = ''; // 清空处理人选择
    },
    async handleSubmit() {
      try {
        const valid = await this.$refs.formRef.validate();
        if (!valid) return;
        this.loading = true;
        // 验证必填字段
        if (!this.validateRequiredFields()) {
          return;
        }
        const algorithmValue = this.getAlgorithmValue();
        const data = {
          id: this.currentDetail.id,
          status: this.currentDetail.status,
          isPass: 0, // 0 表示通过
          eventName: this.currentDetail.orderName,
          eventNum: this.currentDetail.orderNumber,
          workOrderTypeDictKey: this.currentDetail.type,
          content: this.currentDetail.content,
          createDept: this.form.department,
          updateUser: this.form.handler,
          aiType: algorithmValue,
        };
        const response = await flowEvent(data);
        if (response.data.code === 0) {
          this.$message.success('工单已成功派发');
          this.$emit('dispatch-success');
          this.handleClose();
        } else {
          throw new Error(response.data.msg || '派发失败');
        }
      } catch (error) {
        console.error('派发失败:', error);
        this.$emit('dispatch-error', error);
        this.$message.error(error.message || '派发失败,请稍后重试');
      } finally {
        this.loading = false;
      }
    },
    validateRequiredFields() {
      if (!this.currentDetail.orderName || !this.currentDetail.orderName.trim()) {
        this.$message.warning('请填写工单名称');
        return false;
      }
      if (!this.currentDetail.type) {
        this.$message.warning('请选择工单类型');
        return false;
      }
      if (!this.currentDetail.content || !this.currentDetail.content.trim()) {
        this.$message.warning('请填写工单内容');
        return false;
      }
      return true;
    },
    getAlgorithmValue() {
      const isValue = this.algorithms.some(item => item.value === this.currentDetail.aiType);
      if (isValue) {
        return this.currentDetail.aiType;
      } else {
        const matched = this.algorithms.find(
          item => item.dict_value === this.currentDetail.aiType ||
                  item.label === this.currentDetail.aiType
        );
        return matched ? matched.value : null;
      }
    }
  }
};
</script>
<style scoped>
.full-width {
  width: 100%;
}
</style>
src/views/tickets/ticketComponent/RecheckDialog.vue
New file
@@ -0,0 +1,117 @@
<template>
  <el-dialog
    v-model="dialogVisible"
    title="工单复核"
    width="30%"
    append-to-body
    class="ztzf-dialog-mange"
    @close="handleClose"
  >
    <div class="dialog-footer">
      <el-button type="primary" @click="handleConfirm(1)">人工复核</el-button>
      <el-button type="primary" @click="handleConfirm(2)">无人机复核</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { ElMessageBox, ElLoading } from 'element-plus';
import { getReviewById, getCreateEventJob } from '@/api/tickets/ticket';
export default {
  name: 'RecheckDialog',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    recheckData: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ['update:modelValue', 'recheck-success'],
  computed: {
    dialogVisible: {
      get() {
        return this.modelValue;
      },
      set(value) {
        this.$emit('update:modelValue', value);
      }
    }
  },
  methods: {
    handleClose() {
      this.dialogVisible = false;
    },
    handleConfirm(key) {
      if (key === 1) {
        this.handleManualRecheck();
      } else {
        this.handleUAVRecheck();
      }
    },
    async handleManualRecheck() {
      try {
        await getReviewById(this.recheckData.id);
        this.$message.success('人工复核成功');
        this.$emit('recheck-success');
        this.dialogVisible = false;
      } catch (error) {
        this.$message.error('人工复核失败');
        console.error('人工复核失败:', error);
      }
    },
    async handleUAVRecheck() {
      const loading = ElLoading.service({
        lock: true,
        text: '复核任务创建中……',
        background: 'rgba(0, 0, 0, 0.7)',
      });
      try {
        const response = await getCreateEventJob(this.recheckData.id);
        const estimatedTime = response.data.data;
        loading.close();
        await ElMessageBox.confirm(
          `预计复核执行时间为${estimatedTime}`,
          '提示',
          {
            confirmButtonText: '确定',
            showCancelButton: false,
            closeOnClickModal: false,
            closeOnPressEscape: false,
            type: 'warning',
          }
        );
        this.$message.success('无人机复核任务创建成功');
        this.$emit('recheck-success');
        this.dialogVisible = false;
      } catch (error) {
        loading.close();
        if (error !== 'cancel') {
          this.$message.error('无人机复核任务创建失败');
          console.error('无人机复核失败:', error);
        }
        this.dialogVisible = false;
      }
    }
  }
};
</script>
<style scoped>
.dialog-footer {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 20px 0;
}
</style>