| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630 |
- import { getList, getDetail, update, getAttachmentList } from '@/api/order/image-store-apply'
- import { formatFileSize } from '@/util/util'
- import { mapGetters } from 'vuex'
- import {
- APPLICANT_TYPE,
- APPLICANT_TYPE_OPTIONS,
- AUDIT_STATUS,
- AUDIT_STATUS_OPTIONS,
- NEED_REIMBURSE,
- NEED_REIMBURSE_OPTIONS,
- getApplicantTypeLabel,
- getApplicantTypeType,
- getAuditStatusLabel,
- getAuditStatusType,
- getNeedReimburseLabel,
- getNeedReimburseType,
- canAudit,
- isAuditCompleted,
- isDealerApplicant,
- isStoreApplicant
- } from '@/constants/image-store-apply'
- /**
- * @typedef {import('@/api/order/image-store-apply').ImageStoreApplyRecord} ImageStoreApplyRecord
- * @typedef {import('@/api/order/image-store-apply').QualificationItem} QualificationItem
- * @typedef {import('@/api/order/image-store-apply').ApplyAttachmentRecord} ApplyAttachmentRecord
- * @typedef {import('@/api/order/image-store-apply').ImageStoreApplyQueryParams} ImageStoreApplyQueryParams
- */
- /**
- * 形象申请页面业务逻辑 Mixin
- * @mixin
- */
- export default {
- data() {
- return {
- /** @type {ImageStoreApplyRecord[]} */
- data: [],
- /** @type {ImageStoreApplyRecord} */
- form: {},
- /** @type {ImageStoreApplyQueryParams} */
- query: {},
- loading: true,
- // 分页信息
- page: {
- pageSize: 10,
- currentPage: 1,
- total: 0
- },
- // 详情对话框
- detailVisible: false,
- /** @type {ImageStoreApplyRecord|null} */
- detailData: null,
- /** @type {QualificationItem[]} */
- qualificationList: [],
- /** @type {ApplyAttachmentRecord[]} */
- attachmentList: [],
- attachmentLoading: false,
- // 审核相关
- auditVisible: false,
- rejectVisible: false,
- auditLoading: false,
- /** @type {Object} */
- rejectForm: {
- id: '',
- applyNo: '',
- customerName: '',
- auditRemark: ''
- },
- /** @type {Object} */
- rejectRules: {
- auditRemark: [
- { required: true, message: '请输入拒绝原因', trigger: 'blur' },
- { min: 5, max: 200, message: '拒绝原因长度在5到200个字符', trigger: 'blur' }
- ]
- },
- // 图片预览
- previewVisible: false,
- previewUrl: '',
- // 选择相关
- selectionList: [],
- // 表格配置
- option: {
- height: 'auto',
- calcHeight: 30,
- tip: false,
- searchShow: true,
- searchMenuSpan: 6,
- searchIndex: 3,
- border: true,
- index: true,
- viewBtn: false,
- editBtn: false,
- delBtn: false,
- addBtn: false,
- column: [
- {
- label: '申请编号',
- prop: 'applyNo',
- minWidth: 140,
- search: true,
- searchPlaceholder: '请输入申请编号'
- },
- {
- label: '申请方类型',
- prop: 'applicantType',
- minWidth: 100,
- slot: true,
- search: true,
- type: 'select',
- dicData: APPLICANT_TYPE_OPTIONS
- },
- {
- label: '客户编码',
- prop: 'customerCode',
- minWidth: 120,
- search: true,
- searchPlaceholder: '请输入客户编码'
- },
- {
- label: '客户名称',
- prop: 'customerName',
- minWidth: 180,
- search: true,
- searchPlaceholder: '请输入客户名称'
- },
- {
- label: '联系人',
- prop: 'contactName',
- minWidth: 100
- },
- {
- label: '联系电话',
- prop: 'contactPhone',
- minWidth: 120
- },
- {
- label: '品牌名称',
- prop: 'brandName',
- minWidth: 120,
- search: true,
- searchPlaceholder: '请输入品牌名称'
- },
- {
- label: '申请金额',
- prop: 'applyAmount',
- minWidth: 120,
- slot: true
- },
- {
- label: '审核状态',
- prop: 'auditStatus',
- minWidth: 100,
- slot: true,
- search: true,
- type: 'select',
- dicData: AUDIT_STATUS_OPTIONS
- },
- {
- label: '审核金额',
- prop: 'auditAmount',
- minWidth: 120,
- slot: true
- },
- {
- label: '审核人',
- prop: 'auditorName',
- minWidth: 100
- },
- {
- label: '审核时间',
- prop: 'auditTime',
- minWidth: 150
- },
- {
- label: '提交时间',
- prop: 'submitTime',
- minWidth: 150,
- search: true,
- type: 'daterange',
- searchPlaceholder: '请选择提交时间范围',
- formatter: (row, column, cellValue) => {
- if (!cellValue) return '-'
- // 如果是数组格式,取第一个元素
- if (Array.isArray(cellValue)) {
- return cellValue[0] || '-'
- }
- return cellValue
- }
- }
- ]
- }
- }
- },
- computed: {
- ...mapGetters(['permission']),
- /** @returns {Object} */
- permissionList() {
- return {
- viewBtn: false,
- editBtn: false,
- delBtn: false,
- addBtn: false,
- }
- },
- /** @returns {string[]} */
- ids() {
- const ids = []
- this.selectionList.forEach(ele => {
- ids.push(ele.id)
- })
- return ids
- }
- },
- methods: {
- isDealerApplicant,
- isStoreApplicant,
- /**
- * 格式化金额显示
- * @param {number|string} amount - 金额
- * @returns {string} 格式化后的金额
- */
- formatAmount(amount) {
- if (!amount || parseFloat(amount) === 0) return '0.00'
- return parseFloat(amount).toFixed(2)
- },
- getApplicantTypeLabel,
- getApplicantTypeType,
- getAuditStatusType,
- getAuditStatusLabel,
- /**
- * 获取是否需要报销标签
- * @param {number} value - 报销状态值
- * @returns {string} 对应的标签文本
- */
- getNeedReimburseText(value) {
- return getNeedReimburseLabel(value)
- },
- /**
- * 获取是否需要报销类型
- * @param {number} value - 报销状态值
- * @returns {string} 对应的Element UI标签类型
- */
- getNeedReimburseType(value) {
- return getNeedReimburseType(value)
- },
- /**
- * 判断是否为图片文件
- * @param {string} fileType - 文件类型
- * @returns {boolean} 是否为图片
- */
- isImageFile(fileType) {
- const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']
- return imageTypes.includes(fileType.toLowerCase())
- },
- /**
- * 判断是否为PDF文件
- * @param {string} fileType - 文件类型
- * @returns {boolean} 是否为PDF
- */
- isPdfFile(fileType) {
- return fileType.toLowerCase() === 'pdf'
- },
- /**
- * 格式化文件大小
- * @param {number} size - 文件大小(字节)
- * @returns {string} 格式化后的文件大小
- */
- formatFileSize(size) {
- return formatFileSize(size)
- },
- /**
- * 处理图片加载错误
- * @param {Event} event - 错误事件
- */
- handleImageError(event) {
- // 图片加载失败时显示默认图标
- event.target.style.display = 'none'
- const parent = event.target.parentNode
- if (parent && !parent.querySelector('.error-icon')) {
- const errorIcon = document.createElement('div')
- errorIcon.className = 'error-icon'
- errorIcon.innerHTML = '<i class="el-icon-picture-outline"></i>'
- parent.appendChild(errorIcon)
- }
- },
- /**
- * 预览PDF文件
- * @param {ApplyAttachmentRecord} row - 附件数据
- */
- handlePdfPreview(row) {
- if (!row.fileUrl) {
- this.$message.warning('文件链接不存在')
- return
- }
- // 在新窗口中打开PDF
- window.open(row.fileUrl, '_blank')
- },
- /**
- * 查看详情
- * @param {ImageStoreApplyRecord} row - 行数据
- * @returns {Promise<void>}
- */
- async handleView(row) {
- try {
- this.loading = true
- // 获取详情数据
- const detailRes = await getDetail(row.id)
- if (detailRes.data.success) {
- this.detailData = detailRes.data.data
- const qualificationList = JSON.parse(detailRes.data.data.qualificationInfo)
- this.qualificationList = qualificationList || []
- // 获取附件列表
- await this.loadAttachmentList(row.id)
- this.detailVisible = true
- } else {
- this.$message.error(detailRes.data.msg || '获取详情失败')
- }
- } catch (error) {
- console.error('获取详情失败:', error)
- this.$message.error('获取详情失败')
- } finally {
- this.loading = false
- }
- },
- /**
- * 加载附件列表
- * @param {string} applyId - 申请ID
- * @returns {Promise<void>}
- */
- async loadAttachmentList(applyId) {
- try {
- this.attachmentLoading = true
- const attachmentRes = await getAttachmentList(1, 100 ,{
- applyId
- })
- if (attachmentRes.data.success) {
- this.attachmentList = attachmentRes.data.data.records || []
- } else {
- this.$message.error(attachmentRes.data.msg || '获取附件列表失败')
- }
- } catch (error) {
- console.error('获取附件列表失败:', error)
- this.$message.error('获取附件列表失败')
- } finally {
- this.attachmentLoading = false
- }
- },
- /**
- * 处理审核通过操作
- * @param {ImageStoreApplyRecord} row - 行数据
- */
- handleApprove(row) {
- if (!canAudit(row.auditStatus)) {
- this.$message.warning('当前状态不允许审核操作')
- return
- }
- this.$confirm('确定要审核通过该申请吗?', '确认审核', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'success'
- }).then(async () => {
- await this.submitAudit(row, AUDIT_STATUS.APPROVED, '审核通过')
- }).catch(() => {
- // 用户取消操作
- })
- },
- /**
- * 处理审核不通过操作
- * @param {ImageStoreApplyRecord} row - 行数据
- */
- handleReject(row) {
- if (!canAudit(row.auditStatus)) {
- this.$message.warning('当前状态不允许审核操作')
- return
- }
- this.rejectForm = {
- id: row.id,
- applyNo: row.applyNo,
- customerName: row.customerName,
- auditRemark: ''
- }
- // 重置表单验证
- this.$nextTick(() => {
- if (this.$refs.rejectFormRef) {
- this.$refs.rejectFormRef.clearValidate()
- }
- })
- this.rejectVisible = true
- },
- /**
- * 提交拒绝审核
- * @returns {Promise<void>}
- */
- async submitReject() {
- try {
- // 表单验证
- await this.$refs.rejectFormRef.validate()
- // 找到对应的行数据
- const row = this.data.find(item => item.id === this.rejectForm.id)
- if (!row) {
- this.$message.error('未找到对应的申请记录')
- return
- }
- await this.submitAudit(row, AUDIT_STATUS.REJECTED, this.rejectForm.auditRemark)
- this.rejectVisible = false
- } catch (error) {
- if (error !== false) { // 不是表单验证失败
- console.error('提交拒绝审核失败:', error)
- this.$message.error('提交失败,请重试')
- }
- }
- },
- /**
- * 提交审核(通用方法)
- * @param {ImageStoreApplyRecord} row - 行数据
- * @param {number} auditStatus - 审核状态 1-通过 2-不通过
- * @param {string} auditRemark - 审核备注
- * @returns {Promise<void>}
- */
- async submitAudit(row, auditStatus, auditRemark) {
- try {
- this.auditLoading = true
- const params = {
- id: row.id,
- auditStatus,
- auditRemark
- }
- const res = await update(params)
- if (res.data.success) {
- this.$message.success('审核操作成功')
- // 更新列表数据
- const index = this.data.findIndex(item => item.id === row.id)
- if (index !== -1) {
- this.data[index].auditStatus = auditStatus
- this.data[index].auditRemark = auditRemark
- this.data[index].auditTime = new Date().toLocaleString()
- }
- // 如果详情对话框打开,也更新详情数据
- if (this.detailVisible && this.detailData && this.detailData.id === row.id) {
- this.detailData.auditStatus = auditStatus
- this.detailData.auditRemark = auditRemark
- this.detailData.auditTime = new Date().toLocaleString()
- }
- } else {
- this.$message.error(res.data.msg || '审核操作失败')
- }
- } catch (error) {
- console.error('审核操作失败:', error)
- this.$message.error('审核操作失败')
- } finally {
- this.auditLoading = false
- }
- },
- /**
- * 预览图片
- * @param {ApplyAttachmentRecord} row - 附件数据
- */
- handlePreview(row) {
- if (!row.fileUrl) {
- this.$message.warning('文件链接不存在')
- return
- }
- this.previewUrl = row.fileUrl
- this.previewVisible = true
- },
- /**
- * 下载文件
- * @param {ApplyAttachmentRecord} row - 附件数据
- */
- handleDownload(row) {
- if (!row.fileUrl) {
- this.$message.warning('文件链接不存在')
- return
- }
- // 创建下载链接
- const link = document.createElement('a')
- link.href = row.fileUrl
- link.download = row.fileName || '下载文件'
- link.target = '_blank'
- document.body.appendChild(link)
- link.click()
- document.body.removeChild(link)
- },
- /**
- * 搜索变化事件
- * @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} selection - 选中的数据
- */
- selectionChange(selection) {
- this.selectionList = selection
- },
- /**
- * 清空选择事件
- */
- selectionClear() {
- this.selectionList = []
- },
- /**
- * 当前页变化事件
- * @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 {Function} done - 完成回调
- * @param {string} type - 操作类型
- */
- beforeOpen(done, type) {
- done()
- },
- /**
- * 加载数据
- * @param {Object} page - 分页参数
- * @param {Object} params - 查询参数
- * @returns {Promise<void>}
- */
- async onLoad(page, params = {}) {
- try {
- this.loading = true
- const queryParams = {
- ...params,
- current: page.currentPage,
- size: page.pageSize
- }
- const res = await getList(
- queryParams.current,
- queryParams.size,
- queryParams
- )
- if (res.data.success) {
- this.data = res.data.data.records || []
- this.page.total = res.data.data.total || 0
- } else {
- this.$message.error(res.data.msg || '获取数据失败')
- }
- } catch (error) {
- console.error('获取数据失败:', error)
- this.$message.error('获取数据失败')
- } finally {
- this.loading = false
- }
- }
- }
- }
|