index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <template>
  2. <div class="container">
  3. <div class="processing-photo-task">
  4. <div class="top">
  5. <div class="nav-bar">
  6. <van-nav-bar
  7. title="加工拍照任务"
  8. left-arrow
  9. @click-left="goBack"
  10. @click-right="onRefresh"
  11. >
  12. <template #left>
  13. <van-icon name="arrow-left" size="25" />
  14. <div
  15. style="
  16. color: #fff;
  17. height: 46px;
  18. padding-right: 20px;
  19. line-height: 46px;
  20. "
  21. >
  22. 返回
  23. </div>
  24. </template>
  25. <template #right>
  26. <div class="nav-right" style="color: #fff">重置</div>
  27. </template>
  28. </van-nav-bar>
  29. </div>
  30. <div class="context">
  31. <!-- 筛选区域 -->
  32. <div class="filter-section">
  33. <van-row gutter="10">
  34. <van-col span="8">
  35. <van-field
  36. v-model="filterForm.owners"
  37. placeholder="请选择货主"
  38. readonly
  39. clickable
  40. clearable
  41. clear-trigger="always"
  42. @click="showOwnerDialog"
  43. @clear="onOwnerClear"
  44. />
  45. </van-col>
  46. <van-col span="8">
  47. <van-field
  48. v-model="filterForm.status"
  49. placeholder="请选择状态"
  50. readonly
  51. clickable
  52. @click="showStatusPicker = true"
  53. />
  54. </van-col>
  55. <van-col span="8">
  56. <van-button type="primary" size="small" block @click="onFilterSearch">
  57. 搜索
  58. </van-button>
  59. </van-col>
  60. </van-row>
  61. </div>
  62. <van-pull-refresh
  63. v-model="loading"
  64. @refresh="onRefresh"
  65. :style="{
  66. 'max-height': computedMaxHeight,
  67. 'min-height': computedMaxHeight,
  68. overflow: 'auto',
  69. }"
  70. >
  71. <table class="photo-task-table">
  72. <thead>
  73. <tr>
  74. <th style="width: 25%">货主</th>
  75. <th style="width: 35%">加工单号</th>
  76. <th style="width: 15%">状态</th>
  77. <th style="width: 12.5%">查看</th>
  78. <th style="width: 12.5%">操作</th>
  79. </tr>
  80. </thead>
  81. <tbody>
  82. <tr v-for="(row, rowIndex) in photoTasks" :key="rowIndex">
  83. <td>
  84. <span class="text-compact">{{ row.ownerName }}</span>
  85. </td>
  86. <td>
  87. <span class="text-sm code-link" @click="showNotes(row)">{{ row.code }}</span>
  88. </td>
  89. <td>
  90. <span class="text-compact">{{ row.status }}</span>
  91. </td>
  92. <td>
  93. <van-button type="primary" plain size="small" @click="showPhotos(row)" class="compact-button"
  94. >查看
  95. </van-button>
  96. </td>
  97. <td>
  98. <van-button v-if="row.status !== '完成'" type="primary" size="small" @click="toPhoto(row)" class="compact-button"
  99. >拍摄
  100. </van-button>
  101. </td>
  102. </tr>
  103. </tbody>
  104. </table>
  105. <!-- 分页控件 -->
  106. <van-pagination
  107. v-model="paginate.page"
  108. :page-size="paginate.size"
  109. :total-items="paginate.total"
  110. :page-count="paginate.pages"
  111. :show-page-size="5"
  112. model="simple"
  113. forced="true"
  114. @change="onPageChange"
  115. class="pagination"
  116. />
  117. </van-pull-refresh>
  118. </div>
  119. </div>
  120. <!-- 货主选择器弹窗 -->
  121. <Owner
  122. ref="ownerRef"
  123. @onOwner="onOwnerSelect"
  124. />
  125. <!-- 状态选择器弹窗 -->
  126. <van-popup v-model:show="showStatusPicker" position="bottom">
  127. <van-picker
  128. :columns="statusOptions"
  129. @confirm="onStatusConfirm"
  130. @cancel="showStatusPicker = false"
  131. />
  132. </van-popup>
  133. <!-- 图片上传弹窗 -->
  134. <van-popup v-model:show="showUpload" position="bottom" :style="{ height: '80%' }">
  135. <div class="upload-popup">
  136. <van-nav-bar
  137. title="图片上传"
  138. left-arrow
  139. @click-left="showUpload = false"
  140. >
  141. <template #left>
  142. <van-icon name="arrow-left" size="25" />
  143. <div style="color: #fff; height: 46px; padding-right: 20px; line-height: 46px;">
  144. 返回
  145. </div>
  146. </template>
  147. </van-nav-bar>
  148. <div class="upload-content">
  149. <van-uploader
  150. v-model="uploadImages"
  151. :max-count="9"
  152. :max-size="15 * 1024 * 1024"
  153. :before-read="beforeReadImage"
  154. :after-read="afterReadImage"
  155. multiple
  156. preview-full-image
  157. />
  158. <div class="upload-footer">
  159. <van-button
  160. type="primary"
  161. block
  162. :loading="uploading"
  163. @click="submitUpload"
  164. >
  165. {{ uploading ? '上传中...' : '提交上传' }}
  166. </van-button>
  167. </div>
  168. </div>
  169. </div>
  170. </van-popup>
  171. </div>
  172. </div>
  173. </template>
  174. <script setup>
  175. import { ref, computed, onMounted } from 'vue'
  176. import { useRoute } from 'vue-router'
  177. import { showNotify, showImagePreview, showFailToast, showLoadingToast, closeToast, showDialog } from 'vant'
  178. import {
  179. getProcessingPhotoTask,
  180. processingPhotoTaskItems,
  181. uploadPhoto,status
  182. } from '@/api/processing/index'
  183. import { getHeader, goBack } from '@/utils/android'
  184. import Owner from '@/components/Owner.vue'
  185. import { useStore } from '@/store/modules/user'
  186. try {
  187. getHeader()
  188. } catch (error) {
  189. console.log(error)
  190. }
  191. const store = useStore()
  192. const warehouse = store.warehouse
  193. const route = useRoute()
  194. const loading = ref(false)
  195. const photoTasks = ref([])
  196. const showUpload = ref(false)
  197. const uploadImages = ref([])
  198. const uploading = ref(false)
  199. const currentTaskId = ref(null)
  200. const ownerRef = ref(null)
  201. const paginate = ref({
  202. page: 1,
  203. size: 20,
  204. total: 0,
  205. pages: 0,
  206. })
  207. const reviewImages = ref([])
  208. // 筛选相关数据
  209. const filterForm = ref({
  210. owners: '',
  211. status: '',
  212. statusCode: ''
  213. })
  214. const showStatusPicker = ref(false)
  215. const statusOptions = ref([])
  216. // 计算最大高度适配手持设备
  217. const computedMaxHeight = computed(() => {
  218. return window.innerHeight - 46 - 20 + 'px'
  219. })
  220. // 获取从其他页面传递的参数
  221. onMounted(() => {
  222. // 可以从route.query或route.params中获取参数
  223. if (route.query.id) {
  224. // 如果有传入id参数,可以做特殊处理
  225. }
  226. status().then(res=>{
  227. if (res.data) {
  228. statusOptions.value = res.data.map(item=>{
  229. return {text:item.name,value:item.code}
  230. })
  231. }
  232. })
  233. })
  234. // 显示notes信息 - 改为弹框方式
  235. function showNotes(row) {
  236. const notes = row.notes || '暂无备注信息'
  237. showDialog({
  238. title: '任务备注',
  239. message: notes,
  240. confirmButtonText: '确定',
  241. messageAlign: 'left'
  242. })
  243. }
  244. function onRefresh() {
  245. // 刷新时重置到第一页
  246. paginate.value.page = 1
  247. filterForm.value.owners = null
  248. filterForm.value.status = null
  249. filterForm.value.statusCode = null
  250. listProcessingPhoto()
  251. }
  252. function listProcessingPhoto() {
  253. loading.value = true
  254. // 合并筛选条件和分页参数,使用statusCode而不是status
  255. const params = {
  256. ...paginate.value,
  257. warehouses: warehouse,
  258. owners: filterForm.value.owners,
  259. status: filterForm.value.statusCode
  260. }
  261. getProcessingPhotoTask(params).then((res) => {
  262. photoTasks.value = res?.data?.records || []
  263. // 更新分页信息
  264. if (res?.data) {
  265. paginate.value.size = res.data.size || 0
  266. paginate.value.total = res.data.total || 0
  267. paginate.value.page = res.data.current || 0
  268. paginate.value.pages = res.data.pages || 0
  269. }
  270. }).finally(() => {
  271. loading.value = false
  272. })
  273. }
  274. // 分页变更处理
  275. function onPageChange(page) {
  276. paginate.value.page = page
  277. listProcessingPhoto()
  278. }
  279. function showPhotos(row) {
  280. processingPhotoTaskItems(row.id).then((res) => {
  281. const items = res.data
  282. if (!items || items.length === 0) {
  283. showNotify({ type: 'warning', message: '没有对应的拍摄' })
  284. return
  285. }
  286. const baseUrl = import.meta.env.VITE_APP_BASE_API + 'statics/storage/'
  287. const paths = baseUrl.split('.')
  288. paths[1] = 'swms'
  289. const base = paths.join('.')
  290. // 解构图片url
  291. reviewImages.value = items.map(item => {
  292. const {path,module} = item
  293. return `${base}${module}/${path}`
  294. }).filter(url => url)
  295. // 预览图片
  296. if (reviewImages.value.length > 0) {
  297. showImagePreview({
  298. images: reviewImages.value,
  299. closeable: true,
  300. })
  301. } else {
  302. showNotify({ type: 'warning', message: '没有可预览的图片' })
  303. }
  304. }).catch(err => {
  305. showNotify({ type: 'danger', message: '获取图片失败' })
  306. })
  307. }
  308. function toPhoto(row) {
  309. currentTaskId.value = row.id
  310. uploadImages.value = []
  311. showUpload.value = true
  312. }
  313. // 检查图片格式和大小
  314. const beforeReadImage = (file) => {
  315. const files = Array.isArray(file) ? file : [file]
  316. for (const f of files) {
  317. // 检查文件格式
  318. if (f.name.toLowerCase().endsWith('.heic') || f.name.toLowerCase().endsWith('.heif')) {
  319. showFailToast('不支持HEIC/HEIF格式的图片')
  320. return false
  321. }
  322. // 检查文件类型
  323. const isImage = /^image\//.test(f.type)
  324. if (!isImage) {
  325. showFailToast('请上传图片文件')
  326. return false
  327. }
  328. // 检查文件大小 (15MB)
  329. if (f.size > 15 * 1024 * 1024) {
  330. showFailToast('图片大小不能超过15MB')
  331. return false
  332. }
  333. }
  334. return true
  335. }
  336. // 图片读取完成后处理
  337. const afterReadImage = (file) => {
  338. // file 是上传的文件信息,可以在这里进行额外处理
  339. }
  340. // 提交上传
  341. const submitUpload = async () => {
  342. if (!uploadImages.value.length) {
  343. showFailToast('请先选择图片')
  344. return
  345. }
  346. if (!currentTaskId.value) {
  347. showFailToast('任务ID无效')
  348. return
  349. }
  350. uploading.value = true
  351. const toast = showLoadingToast('上传中...')
  352. try {
  353. const totalImages = uploadImages.value.length
  354. let successCount = 0
  355. let failedImages = []
  356. // 逐个上传图片
  357. for (let i = 0; i < uploadImages.value.length; i++) {
  358. const image = uploadImages.value[i]
  359. try {
  360. const formData = new FormData()
  361. formData.append('file', image.file)
  362. // 调用上传API
  363. await uploadPhoto(currentTaskId.value, formData)
  364. successCount++
  365. } catch (err) {
  366. console.error(`第${i + 1}张图片上传失败:`, err)
  367. failedImages.push({
  368. index: i,
  369. image: image,
  370. error: err.message || '上传失败'
  371. })
  372. }
  373. }
  374. closeToast()
  375. if (successCount === totalImages) {
  376. // 全部上传成功
  377. showNotify({ type: 'success', message: '全部图片上传成功' })
  378. // 关闭弹窗并刷新列表
  379. showUpload.value = false
  380. uploadImages.value = []
  381. onRefresh()
  382. } else if (successCount > 0) {
  383. // 部分上传成功
  384. showNotify({
  385. type: 'warning',
  386. message: `${successCount}/${totalImages}张图片上传成功,${failedImages.length}张失败`
  387. })
  388. // 移除上传成功的图片,保留失败的图片
  389. uploadImages.value = failedImages.map(item => item.image)
  390. } else {
  391. // 全部上传失败
  392. showNotify({
  393. type: 'danger',
  394. message: '所有图片上传失败,请检查网络连接或重试'
  395. })
  396. // 保留所有失败的图片,让用户可以重试
  397. }
  398. } catch (err) {
  399. closeToast()
  400. showNotify({ type: 'danger', message: '上传过程发生异常: ' + (err.message || '未知错误') })
  401. // 发生异常时保留所有图片,让用户可以重试
  402. } finally {
  403. uploading.value = false
  404. }
  405. }
  406. function onFilterSearch() {
  407. // 搜索时重置到第一页
  408. paginate.value.page = 1
  409. listProcessingPhoto()
  410. }
  411. // 显示货主选择弹窗
  412. function showOwnerDialog() {
  413. if (ownerRef.value) {
  414. ownerRef.value.show('filter')
  415. }
  416. }
  417. // 处理货主选择
  418. function onOwnerSelect(item, type) {
  419. filterForm.value.owners = item.name
  420. // 选择货主后自动搜索
  421. onFilterSearch()
  422. }
  423. // 处理货主清空
  424. function onOwnerClear() {
  425. filterForm.value.owners = ''
  426. // 清空货主后自动搜索
  427. onFilterSearch()
  428. }
  429. function onStatusConfirm({ selectedOptions }) {
  430. filterForm.value.status = selectedOptions[0].text
  431. filterForm.value.statusCode = selectedOptions[0].value
  432. showStatusPicker.value = false
  433. // 选择状态后自动搜索
  434. onFilterSearch()
  435. }
  436. // 初始化加载数据
  437. onRefresh()
  438. </script>
  439. <style scoped lang="scss">
  440. // 确保van-field的清空按钮样式正确显示
  441. :deep(.van-field__clear) {
  442. display: flex !important;
  443. align-items: center;
  444. justify-content: center;
  445. color: #c8c9cc;
  446. font-size: 16px;
  447. cursor: pointer;
  448. &:active {
  449. color: #969799;
  450. }
  451. }
  452. // 确保van-field右侧区域有足够空间显示清空按钮
  453. :deep(.van-field__right-icon) {
  454. display: flex !important;
  455. align-items: center;
  456. }
  457. .photo-task-table {
  458. width: 100%;
  459. border-collapse: collapse;
  460. text-align: center;
  461. table-layout: fixed;
  462. font-size: 12px;
  463. thead {
  464. tr {
  465. background-color: #f5f5f5;
  466. th {
  467. padding: 6px 2px;
  468. font-weight: 500;
  469. }
  470. }
  471. }
  472. tbody {
  473. tr {
  474. height: 36px;
  475. border-bottom: 1px solid #e0e0e0;
  476. &:last-child {
  477. border-bottom: none;
  478. }
  479. td {
  480. padding: 3px 2px;
  481. overflow: hidden;
  482. text-overflow: ellipsis;
  483. white-space: nowrap;
  484. .text-compact {
  485. font-size: 12px;
  486. line-height: 1.2;
  487. display: block;
  488. white-space: nowrap;
  489. overflow: hidden;
  490. text-overflow: ellipsis;
  491. }
  492. .text-sm {
  493. font-size: 11px;
  494. line-height: 1.2;
  495. display: block;
  496. white-space: nowrap;
  497. overflow: hidden;
  498. text-overflow: ellipsis;
  499. }
  500. .compact-button {
  501. height: 24px;
  502. line-height: 22px;
  503. padding: 0 6px;
  504. font-size: 11px;
  505. min-width: 36px;
  506. }
  507. }
  508. }
  509. }
  510. }
  511. .pagination {
  512. padding: 10px 0;
  513. display: flex;
  514. justify-content: center;
  515. }
  516. .upload-popup {
  517. height: 100%;
  518. display: flex;
  519. flex-direction: column;
  520. .upload-content {
  521. flex: 1;
  522. padding: 10px;
  523. overflow-y: auto;
  524. .upload-footer {
  525. padding: 10px 0;
  526. }
  527. }
  528. }
  529. .filter-section {
  530. padding: 10px;
  531. background: #fff;
  532. border-bottom: 1px solid #e0e0e0;
  533. }
  534. .code-link {
  535. color: #1989fa;
  536. cursor: pointer;
  537. text-decoration: underline;
  538. &:hover {
  539. color: #0570db;
  540. }
  541. }
  542. </style>