import { getClaimList, getClaimDetail, getClaimAttachments, getClaimAuditList, addClaimAudit, updateClaimAudit, removeClaimAudit } from '@/api/claim/index' import { formatFileSize } from '@/util/util' import { mapGetters } from 'vuex' export default { data() { return { form: {}, query: {}, loading: true, page: { pageSize: 10, currentPage: 1, total: 0 }, selectionList: [], detailVisible: false, attachmentVisible: false, auditVisible: false, auditFormVisible: false, claimDetail: null, attachmentList: [], auditList: [], attachmentLoading: false, auditLoading: false, auditFormLoading: false, currentClaimRow: null, auditFormMode: 'add', // 'add' | 'edit' auditForm: { id: null, claimId: null, claimNo: '', auditResult: null, auditAmount: 0, reasonDetail: '', auditorId: null, auditorName: '', auditTime: '', feedbackChannel: '', feedbackDesc: '', feedbackTime: '', appealStatus: 0, appealResult: '', appealTime: '' }, auditFormRules: { auditResult: [ { required: true, message: '请选择审核结果', trigger: 'change' } ], auditAmount: [ { required: true, message: '请输入审核金额', trigger: 'blur' } ], reasonDetail: [ { required: true, message: '请输入审核说明', trigger: 'blur' }, { min: 10, message: '审核说明至少10个字符', trigger: 'blur' } ], auditorName: [ { required: true, message: '请输入审核人姓名', trigger: 'blur' } ], auditTime: [ { required: true, message: '请选择审核时间', trigger: 'change' } ] }, // 添加图片预览相关状态 imagePreviewVisible: false, previewImageUrl: '', previewImageList: [], currentPreviewIndex: 0, option: { height: 'auto', calcHeight: 30, tip: false, searchShow: true, searchMenuSpan: 6, border: true, index: true, indexLabel: '序号', selection: true, viewBtn: false, editBtn: false, delBtn: false, addBtn: false, column: [ { label: '理赔编号', prop: 'claimNo', search: true }, { label: '来源类型', prop: 'claimSourceType', type: 'select', dicData: [ { label: '经销商', value: 1 }, { label: '门店', value: 2 } ], search: true, slot: true }, { label: '来源名称', prop: 'sourceName', search: true }, { label: '来源编码', prop: 'sourceCode', search: true }, { label: '消费者姓名', prop: 'consumerName', search: true }, { label: '消费者电话', prop: 'consumerPhone', search: true }, { label: '轮胎编号', prop: 'tyreNo', search: true }, { label: '轮胎规格', prop: 'tyreSpecs' }, { label: '理赔金额', prop: 'claimAmount', type: 'number' }, { label: '审核状态', prop: 'auditStatus', type: 'select', dicData: [ { label: '待审核', value: 0 }, { label: '审核通过', value: 1 }, { label: '审核拒绝', value: 2 } ], search: true, slot: true }, { label: '提交时间', prop: 'submitTime', type: 'datetime', format: 'yyyy-MM-dd HH:mm:ss', valueFormat: 'yyyy-MM-dd HH:mm:ss' } ] }, data: [] } }, computed: { ...mapGetters(['permission']) }, methods: { /** * 获取列表数据 * @param {Object} page - 分页参数 * @param {Object} params - 查询参数 */ async onLoad(page, params = {}) { try { this.loading = true const res = await getClaimList(page.currentPage, page.pageSize, Object.assign(params, this.query)) const data = res.data.data this.page.total = data.total this.data = data.records } catch (error) { console.error('获取理赔列表失败:', error) this.$message.error('获取理赔列表失败') } finally { this.loading = false } }, /** * 搜索 * @param {Object} params - 搜索参数 * @param {Function} done - 完成回调 */ searchChange(params, done) { this.query = params this.onLoad(this.page, params) done() }, /** * 搜索重置 */ searchReset() { this.query = {} this.onLoad(this.page) }, /** * 选择改变 * @param {Array} list - 选中的列表 */ selectionChange(list) { this.selectionList = list }, /** * 当前页改变 * @param {number} currentPage - 当前页码 */ currentChange(currentPage) { this.page.currentPage = currentPage }, /** * 页大小改变 * @param {number} pageSize - 页大小 */ sizeChange(pageSize) { this.page.pageSize = pageSize }, /** * 刷新 */ refreshChange() { this.onLoad(this.page, this.query) }, /** * 查看详情 * @param {Object} row - 行数据 */ async handleDetail(row) { try { const res = await getClaimDetail(row.id) this.claimDetail = res.data.data this.detailVisible = true } catch (error) { console.error('获取理赔详情失败:', error) this.$message.error('获取理赔详情失败') } }, /** * 查看附件 * @param {Object} row - 行数据 */ async handleAttachments(row) { try { this.attachmentLoading = true this.attachmentVisible = true const res = await getClaimAttachments(1, 1000, row.id) this.attachmentList = res.data.data.records || [] } catch (error) { console.error('获取理赔附件失败:', error) this.$message.error('获取理赔附件失败') } finally { this.attachmentLoading = false } }, /** * 查看审核记录 * @param {Object} row - 行数据 */ async handleAudit(row) { try { this.currentClaimRow = row this.auditLoading = true this.auditVisible = true const res = await getClaimAuditList(1, 100, row.id) this.auditList = res.data.data.records || [] } catch (error) { console.error('获取审核记录失败:', error) this.$message.error('获取审核记录失败') } finally { this.auditLoading = false } }, /** * 新增审核记录 */ handleAddAudit() { this.auditFormMode = 'add' this.resetAuditForm() this.auditForm.claimId = this.currentClaimRow.id this.auditForm.claimNo = this.currentClaimRow.claimNo this.auditFormVisible = true }, /** * 编辑审核记录 * @param {Object} row - 审核记录数据 */ handleEditAudit(row) { this.auditFormMode = 'edit' this.auditForm = { id: row.id, claimId: row.claimId, claimNo: row.claimNo, auditResult: row.auditResult, auditAmount: row.auditAmount, reasonDetail: row.reasonDetail, auditorId: row.auditorId, auditorName: row.auditorName, auditTime: row.auditTime, feedbackChannel: row.feedbackChannel || '', feedbackDesc: row.feedbackDesc || '', feedbackTime: row.feedbackTime || '', appealStatus: row.appealStatus || 0, appealResult: row.appealResult || '', appealTime: row.appealTime || '' } this.auditFormVisible = true }, /** * 删除审核记录 * @param {Object} row - 审核记录数据 */ async handleDeleteAudit(row) { try { await this.$confirm('确定删除该审核记录吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }) await removeClaimAudit(row.id) this.$message.success('删除成功') this.refreshAuditList() } catch (error) { if (error !== 'cancel') { console.error('删除审核记录失败:', error) this.$message.error('删除审核记录失败') } } }, /** * 保存审核记录 */ async handleSaveAudit() { try { const valid = await this.$refs.auditFormRef.validate() if (!valid) return this.auditFormLoading = true // 设置审核人ID(这里可以从用户信息中获取) if (!this.auditForm.auditorId) { this.auditForm.auditorId = 10001 // 默认审核人ID,实际应该从当前登录用户获取 } if (this.auditFormMode === 'add') { await addClaimAudit(this.auditForm) this.$message.success('新增审核记录成功') } else { await updateClaimAudit(this.auditForm) this.$message.success('更新审核记录成功') } this.auditFormVisible = false this.refreshAuditList() } catch (error) { console.error('保存审核记录失败:', error) this.$message.error('保存审核记录失败') } finally { this.auditFormLoading = false } }, /** * 重置审核表单 */ resetAuditForm() { this.auditForm = { id: null, claimId: null, claimNo: '', auditResult: null, auditAmount: 0, reasonDetail: '', auditorId: null, auditorName: '', auditTime: '', feedbackChannel: '', feedbackDesc: '', feedbackTime: '', appealStatus: 0, appealResult: '', appealTime: '' } this.$nextTick(() => { if (this.$refs.auditFormRef) { this.$refs.auditFormRef.clearValidate() } }) }, /** * 刷新审核记录列表 */ async refreshAuditList() { if (!this.currentClaimRow) return try { this.auditLoading = true const res = await getClaimAuditList(1, 100, this.currentClaimRow.id) this.auditList = res.data.data.records || [] } catch (error) { console.error('刷新审核记录失败:', error) this.$message.error('刷新审核记录失败') } finally { this.auditLoading = false } }, /** * 下载文件 * @param {Object} file - 文件信息 */ downloadFile(file) { window.open(file.fileUrl) }, /** * 判断文件是否为图片 * @param {string} fileName - 文件名 * @returns {boolean} 是否为图片 */ isImageFile(fileName) { if (!fileName) return false const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg'] const extension = fileName.toLowerCase().substring(fileName.lastIndexOf('.')) return imageExtensions.includes(extension) }, /** * 判断文件是否为视频 * @param {string} fileName - 文件名 * @returns {boolean} 是否为视频 */ isVideoFile(fileName) { if (!fileName) return false const videoExtensions = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.webm', '.mkv'] const extension = fileName.toLowerCase().substring(fileName.lastIndexOf('.')) return videoExtensions.includes(extension) }, /** * 预览图片 * @param {Object} file - 文件信息 * @param {number} index - 当前图片索引 */ previewImage(file, index = 0) { // 获取所有图片文件 const imageFiles = this.attachmentList.filter(item => this.isImageFile(item.fileName)) this.previewImageList = imageFiles.map(item => item.fileUrl) this.currentPreviewIndex = imageFiles.findIndex(item => item.id === file.id) this.previewImageUrl = file.fileUrl this.imagePreviewVisible = true }, /** * 关闭图片预览 */ closeImagePreview() { this.imagePreviewVisible = false this.previewImageUrl = '' this.previewImageList = [] this.currentPreviewIndex = 0 }, /** * 处理图片加载错误 * @param {Event} event - 错误事件 */ handleImageError(event) { event.target.src = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCA0MCA0MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjQwIiBoZWlnaHQ9IjQwIiBmaWxsPSIjRjVGNUY1Ii8+CjxwYXRoIGQ9Ik0yMCAyNkM5LjUgMjYgMSAxNy41IDEgN0MxIDMuNSA0IDEgNyAxSDMzQzM2IDEgMzkgMy41IDM5IDdDMzkgMTcuNSAzMC41IDI2IDIwIDI2WiIgZmlsbD0iI0NDQ0NDQyIvPgo8L3N2Zz4K' }, // 添加公共方法引用 formatFileSize, /** * 获取审核状态类型 * @param {number} status - 审核状态 * @returns {string} 状态类型 */ getAuditStatusType(status) { const typeMap = { 0: 'warning', 1: 'success', 2: 'danger' } return typeMap[status] || 'info' }, /** * 获取审核状态文本 * @param {number} status - 审核状态 * @returns {string} 状态文本 */ getAuditStatusText(status) { const textMap = { 0: '待审核', 1: '审核通过', 2: '审核拒绝' } return textMap[status] || '未知' }, /** * 获取审核结果类型 * @param {number} result - 审核结果 * @returns {string} 结果类型 */ getAuditResultType(result) { const typeMap = { 1: 'success', 2: 'danger' } return typeMap[result] || 'info' }, /** * 获取审核结果文本 * @param {number} result - 审核结果 * @returns {string} 结果文本 */ getAuditResultText(result) { const textMap = { 1: '通过', 2: '拒绝' } return textMap[result] || '未知' } } }