| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- <template>
- <div class="container">
- <div class="processing-photo-task">
- <div class="top">
- <div class="nav-bar">
- <van-nav-bar
- title="加工拍照任务"
- left-arrow
- @click-left="goBack"
- @click-right="onRefresh"
- >
- <template #left>
- <van-icon name="arrow-left" size="25" />
- <div
- style="
- color: #fff;
- height: 46px;
- padding-right: 20px;
- line-height: 46px;
- "
- >
- 返回
- </div>
- </template>
- <template #right>
- <div class="nav-right" style="color: #fff">重置</div>
- </template>
- </van-nav-bar>
- </div>
- <div class="context">
- <!-- 筛选区域 -->
- <div class="filter-section">
- <van-row gutter="10">
- <van-col span="8">
- <van-field
- v-model="filterForm.owners"
- placeholder="请选择货主"
- readonly
- clickable
- clearable
- clear-trigger="always"
- @click="showOwnerDialog"
- @clear="onOwnerClear"
- />
- </van-col>
- <van-col span="8">
- <van-field
- v-model="filterForm.status"
- placeholder="请选择状态"
- readonly
- clickable
- @click="showStatusPicker = true"
- />
- </van-col>
- <van-col span="8">
- <van-button type="primary" size="small" block @click="onFilterSearch">
- 搜索
- </van-button>
- </van-col>
- </van-row>
- </div>
- <van-pull-refresh
- v-model="loading"
- @refresh="onRefresh"
- :style="{
- 'max-height': computedMaxHeight,
- 'min-height': computedMaxHeight,
- overflow: 'auto',
- }"
- >
- <table class="photo-task-table">
- <thead>
- <tr>
- <th style="width: 25%">货主</th>
- <th style="width: 35%">加工单号</th>
- <th style="width: 15%">状态</th>
- <th style="width: 12.5%">查看</th>
- <th style="width: 12.5%">操作</th>
- </tr>
- </thead>
- <tbody>
- <tr v-for="(row, rowIndex) in photoTasks" :key="rowIndex">
- <td>
- <span class="text-compact">{{ row.ownerName }}</span>
- </td>
- <td>
- <span class="text-sm code-link" @click="showNotes(row)">{{ row.code }}</span>
- </td>
- <td>
- <span class="text-compact">{{ row.status }}</span>
- </td>
- <td>
- <van-button type="primary" plain size="small" @click="showPhotos(row)" class="compact-button"
- >查看
- </van-button>
- </td>
- <td>
- <van-button v-if="row.status !== '完成'" type="primary" size="small" @click="toPhoto(row)" class="compact-button"
- >拍摄
- </van-button>
- </td>
- </tr>
- </tbody>
- </table>
-
- <!-- 分页控件 -->
- <van-pagination
- v-model="paginate.page"
- :page-size="paginate.size"
- :total-items="paginate.total"
- :page-count="paginate.pages"
- :show-page-size="5"
- model="simple"
- forced="true"
- @change="onPageChange"
- class="pagination"
- />
- </van-pull-refresh>
- </div>
- </div>
- <!-- 货主选择器弹窗 -->
- <Owner
- ref="ownerRef"
- @onOwner="onOwnerSelect"
- />
- <!-- 状态选择器弹窗 -->
- <van-popup v-model:show="showStatusPicker" position="bottom">
- <van-picker
- :columns="statusOptions"
- @confirm="onStatusConfirm"
- @cancel="showStatusPicker = false"
- />
- </van-popup>
- <!-- 图片上传弹窗 -->
- <van-popup v-model:show="showUpload" position="bottom" :style="{ height: '80%' }">
- <div class="upload-popup">
- <van-nav-bar
- title="图片上传"
- left-arrow
- @click-left="showUpload = false"
- >
- <template #left>
- <van-icon name="arrow-left" size="25" />
- <div style="color: #fff; height: 46px; padding-right: 20px; line-height: 46px;">
- 返回
- </div>
- </template>
- </van-nav-bar>
- <div class="upload-content">
- <van-uploader
- v-model="uploadImages"
- :max-count="9"
- :max-size="15 * 1024 * 1024"
- :before-read="beforeReadImage"
- :after-read="afterReadImage"
- multiple
- preview-full-image
- />
- <div class="upload-footer">
- <van-button
- type="primary"
- block
- :loading="uploading"
- @click="submitUpload"
- >
- {{ uploading ? '上传中...' : '提交上传' }}
- </van-button>
- </div>
- </div>
- </div>
- </van-popup>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, computed, onMounted } from 'vue'
- import { useRoute } from 'vue-router'
- import { showNotify, showImagePreview, showFailToast, showLoadingToast, closeToast, showDialog } from 'vant'
- import {
- getProcessingPhotoTask,
- processingPhotoTaskItems,
- uploadPhoto,status
- } from '@/api/processing/index'
- import { getHeader, goBack } from '@/utils/android'
- import Owner from '@/components/Owner.vue'
- import { useStore } from '@/store/modules/user'
- try {
- getHeader()
- } catch (error) {
- console.log(error)
- }
- const store = useStore()
- const warehouse = store.warehouse
- const route = useRoute()
- const loading = ref(false)
- const photoTasks = ref([])
- const showUpload = ref(false)
- const uploadImages = ref([])
- const uploading = ref(false)
- const currentTaskId = ref(null)
- const ownerRef = ref(null)
- const paginate = ref({
- page: 1,
- size: 20,
- total: 0,
- pages: 0,
- })
- const reviewImages = ref([])
- // 筛选相关数据
- const filterForm = ref({
- owners: '',
- status: '',
- statusCode: ''
- })
- const showStatusPicker = ref(false)
- const statusOptions = ref([])
- // 计算最大高度适配手持设备
- const computedMaxHeight = computed(() => {
- return window.innerHeight - 46 - 20 + 'px'
- })
- // 获取从其他页面传递的参数
- onMounted(() => {
- // 可以从route.query或route.params中获取参数
- if (route.query.id) {
- // 如果有传入id参数,可以做特殊处理
- }
- status().then(res=>{
- if (res.data) {
- statusOptions.value = res.data.map(item=>{
- return {text:item.name,value:item.code}
- })
- }
- })
- })
- // 显示notes信息 - 改为弹框方式
- function showNotes(row) {
- const notes = row.notes || '暂无备注信息'
- showDialog({
- title: '任务备注',
- message: notes,
- confirmButtonText: '确定',
- messageAlign: 'left'
- })
- }
- function onRefresh() {
- // 刷新时重置到第一页
- paginate.value.page = 1
- filterForm.value.owners = null
- filterForm.value.status = null
- filterForm.value.statusCode = null
- listProcessingPhoto()
- }
- function listProcessingPhoto() {
- loading.value = true
- // 合并筛选条件和分页参数,使用statusCode而不是status
- const params = {
- ...paginate.value,
- warehouses: warehouse,
- owners: filterForm.value.owners,
- status: filterForm.value.statusCode
- }
- getProcessingPhotoTask(params).then((res) => {
- photoTasks.value = res?.data?.records || []
- // 更新分页信息
- if (res?.data) {
- paginate.value.size = res.data.size || 0
- paginate.value.total = res.data.total || 0
- paginate.value.page = res.data.current || 0
- paginate.value.pages = res.data.pages || 0
- }
- }).finally(() => {
- loading.value = false
- })
- }
- // 分页变更处理
- function onPageChange(page) {
- paginate.value.page = page
- listProcessingPhoto()
- }
- function showPhotos(row) {
- processingPhotoTaskItems(row.id).then((res) => {
- const items = res.data
- if (!items || items.length === 0) {
- showNotify({ type: 'warning', message: '没有对应的拍摄' })
- return
- }
- const baseUrl = import.meta.env.VITE_APP_BASE_API + 'statics/storage/'
- const paths = baseUrl.split('.')
- paths[1] = 'swms'
- const base = paths.join('.')
- // 解构图片url
- reviewImages.value = items.map(item => {
- const {path,module} = item
- return `${base}${module}/${path}`
- }).filter(url => url)
- // 预览图片
- if (reviewImages.value.length > 0) {
- showImagePreview({
- images: reviewImages.value,
- closeable: true,
- })
- } else {
- showNotify({ type: 'warning', message: '没有可预览的图片' })
- }
- }).catch(err => {
- showNotify({ type: 'danger', message: '获取图片失败' })
- })
- }
- function toPhoto(row) {
- currentTaskId.value = row.id
- uploadImages.value = []
- showUpload.value = true
- }
- // 检查图片格式和大小
- const beforeReadImage = (file) => {
- const files = Array.isArray(file) ? file : [file]
- for (const f of files) {
- // 检查文件格式
- if (f.name.toLowerCase().endsWith('.heic') || f.name.toLowerCase().endsWith('.heif')) {
- showFailToast('不支持HEIC/HEIF格式的图片')
- return false
- }
- // 检查文件类型
- const isImage = /^image\//.test(f.type)
- if (!isImage) {
- showFailToast('请上传图片文件')
- return false
- }
- // 检查文件大小 (15MB)
- if (f.size > 15 * 1024 * 1024) {
- showFailToast('图片大小不能超过15MB')
- return false
- }
- }
- return true
- }
- // 图片读取完成后处理
- const afterReadImage = (file) => {
- // file 是上传的文件信息,可以在这里进行额外处理
- }
- // 提交上传
- const submitUpload = async () => {
- if (!uploadImages.value.length) {
- showFailToast('请先选择图片')
- return
- }
- if (!currentTaskId.value) {
- showFailToast('任务ID无效')
- return
- }
- uploading.value = true
- const toast = showLoadingToast('上传中...')
- try {
- const totalImages = uploadImages.value.length
- let successCount = 0
- let failedImages = []
- // 逐个上传图片
- for (let i = 0; i < uploadImages.value.length; i++) {
- const image = uploadImages.value[i]
- try {
- const formData = new FormData()
- formData.append('file', image.file)
- // 调用上传API
- await uploadPhoto(currentTaskId.value, formData)
- successCount++
- } catch (err) {
- console.error(`第${i + 1}张图片上传失败:`, err)
- failedImages.push({
- index: i,
- image: image,
- error: err.message || '上传失败'
- })
- }
- }
- closeToast()
- if (successCount === totalImages) {
- // 全部上传成功
- showNotify({ type: 'success', message: '全部图片上传成功' })
- // 关闭弹窗并刷新列表
- showUpload.value = false
- uploadImages.value = []
- onRefresh()
- } else if (successCount > 0) {
- // 部分上传成功
- showNotify({
- type: 'warning',
- message: `${successCount}/${totalImages}张图片上传成功,${failedImages.length}张失败`
- })
- // 移除上传成功的图片,保留失败的图片
- uploadImages.value = failedImages.map(item => item.image)
- } else {
- // 全部上传失败
- showNotify({
- type: 'danger',
- message: '所有图片上传失败,请检查网络连接或重试'
- })
- // 保留所有失败的图片,让用户可以重试
- }
- } catch (err) {
- closeToast()
- showNotify({ type: 'danger', message: '上传过程发生异常: ' + (err.message || '未知错误') })
- // 发生异常时保留所有图片,让用户可以重试
- } finally {
- uploading.value = false
- }
- }
- function onFilterSearch() {
- // 搜索时重置到第一页
- paginate.value.page = 1
- listProcessingPhoto()
- }
- // 显示货主选择弹窗
- function showOwnerDialog() {
- if (ownerRef.value) {
- ownerRef.value.show('filter')
- }
- }
- // 处理货主选择
- function onOwnerSelect(item, type) {
- filterForm.value.owners = item.name
- // 选择货主后自动搜索
- onFilterSearch()
- }
- // 处理货主清空
- function onOwnerClear() {
- filterForm.value.owners = ''
- // 清空货主后自动搜索
- onFilterSearch()
- }
- function onStatusConfirm({ selectedOptions }) {
- filterForm.value.status = selectedOptions[0].text
- filterForm.value.statusCode = selectedOptions[0].value
- showStatusPicker.value = false
- // 选择状态后自动搜索
- onFilterSearch()
- }
- // 初始化加载数据
- onRefresh()
- </script>
- <style scoped lang="scss">
- // 确保van-field的清空按钮样式正确显示
- :deep(.van-field__clear) {
- display: flex !important;
- align-items: center;
- justify-content: center;
- color: #c8c9cc;
- font-size: 16px;
- cursor: pointer;
- &:active {
- color: #969799;
- }
- }
- // 确保van-field右侧区域有足够空间显示清空按钮
- :deep(.van-field__right-icon) {
- display: flex !important;
- align-items: center;
- }
- .photo-task-table {
- width: 100%;
- border-collapse: collapse;
- text-align: center;
- table-layout: fixed;
- font-size: 12px;
- thead {
- tr {
- background-color: #f5f5f5;
-
- th {
- padding: 6px 2px;
- font-weight: 500;
- }
- }
- }
- tbody {
- tr {
- height: 36px;
- border-bottom: 1px solid #e0e0e0;
-
- &:last-child {
- border-bottom: none;
- }
-
- td {
- padding: 3px 2px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-
- .text-compact {
- font-size: 12px;
- line-height: 1.2;
- display: block;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
-
- .text-sm {
- font-size: 11px;
- line-height: 1.2;
- display: block;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
-
- .compact-button {
- height: 24px;
- line-height: 22px;
- padding: 0 6px;
- font-size: 11px;
- min-width: 36px;
- }
- }
- }
- }
- }
- .pagination {
- padding: 10px 0;
- display: flex;
- justify-content: center;
- }
- .upload-popup {
- height: 100%;
- display: flex;
- flex-direction: column;
- .upload-content {
- flex: 1;
- padding: 10px;
- overflow-y: auto;
- .upload-footer {
- padding: 10px 0;
- }
- }
- }
- .filter-section {
- padding: 10px;
- background: #fff;
- border-bottom: 1px solid #e0e0e0;
- }
- .code-link {
- color: #1989fa;
- cursor: pointer;
- text-decoration: underline;
-
- &:hover {
- color: #0570db;
- }
- }
- </style>
|