PublicIoOrderPage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <PublicMobileShell>
  3. <div class="public-pl-site-page public-pl-transport-page">
  4. <van-nav-bar :title="navTitle" :border="false" class="site-nav-bar" />
  5. <van-loading v-if="loading" vertical class="page-loading">加载中...</van-loading>
  6. <van-empty v-else-if="errorMessage" :description="errorMessage" />
  7. <template v-else-if="page">
  8. <van-notice-bar
  9. v-if="isReadOnly"
  10. left-icon="info-o"
  11. color="#92400e"
  12. background="#fffbeb"
  13. text="单据已作废,仅可查看"
  14. />
  15. <van-cell-group inset class="section-card">
  16. <van-cell title="业务类型" :value="page.businessType || '—'" />
  17. <van-cell title="日期" :value="page.planDate || '—'" />
  18. <van-cell title="往来单位" :value="page.partnerCompany || '—'" />
  19. <van-cell title="车牌" :value="page.vehicleNo || '—'" />
  20. <van-cell title="计划号" :value="page.planNo || '—'" />
  21. <van-cell title="单号" :value="page.orderNo || '—'" />
  22. <van-cell title="状态" :value="statusLabel(page.status)" />
  23. <van-cell
  24. v-if="page.planRemark"
  25. title="备注"
  26. :value="page.planRemark"
  27. class="multiline-cell"
  28. />
  29. </van-cell-group>
  30. <van-cell-group inset class="section-card" title="取货信息">
  31. <van-cell title="取货地址" class="address-cell multiline-cell">
  32. <template #value>
  33. <div class="address-cell__content">
  34. <span class="address-cell__text">{{ page.pickupAddress || '—' }}</span>
  35. <van-button
  36. v-if="pickupNavUrl"
  37. size="mini"
  38. type="primary"
  39. round
  40. class="address-nav-btn"
  41. @click="openNavigation(pickupNavUrl)"
  42. >
  43. 导航
  44. </van-button>
  45. </div>
  46. </template>
  47. </van-cell>
  48. <van-cell title="取货时间" :value="formatDateTime(page.pickupTime)" />
  49. <van-cell title="注意事项" :value="page.pickupNotes || '—'" class="multiline-cell" />
  50. </van-cell-group>
  51. <van-cell-group inset class="section-card" title="送货信息">
  52. <van-cell title="送货地址" class="address-cell multiline-cell">
  53. <template #value>
  54. <div class="address-cell__content">
  55. <span class="address-cell__text">{{ deliveryAddressDisplay }}</span>
  56. <van-button
  57. v-if="destinationNavUrl"
  58. size="mini"
  59. type="primary"
  60. round
  61. class="address-nav-btn"
  62. @click="openNavigation(destinationNavUrl)"
  63. >
  64. 导航
  65. </van-button>
  66. </div>
  67. </template>
  68. </van-cell>
  69. <van-cell title="送达时间" :value="formatDateTime(page.deliveryTime)" />
  70. <van-cell title="注意事项" :value="page.destinationNotes || '—'" class="multiline-cell" />
  71. </van-cell-group>
  72. <van-cell-group inset class="section-card" title="产品实际数量">
  73. <div
  74. v-for="(item, idx) in editableItems"
  75. :key="item.id"
  76. class="product-card"
  77. >
  78. <div class="product-card__head">
  79. <div class="product-card__name">{{ item.productName || '产品' }}</div>
  80. <span class="product-card__badge">产品 {{ idx + 1 }}/{{ editableItems.length }}</span>
  81. </div>
  82. <div class="meta-grid">
  83. <div class="meta-item">
  84. <div class="meta-item__label">规格型号</div>
  85. <div class="meta-item__value">{{ item.specification || '—' }}</div>
  86. </div>
  87. <div class="meta-item">
  88. <div class="meta-item__label">包装规格</div>
  89. <div class="meta-item__value">{{ item.packageSpec || '—' }}</div>
  90. </div>
  91. <div class="meta-item meta-item--span">
  92. <div class="meta-item__label">计划数量</div>
  93. <div class="meta-item__value meta-item__value--plan">
  94. {{ formatPlanQty(item) }}
  95. </div>
  96. </div>
  97. </div>
  98. <div class="actual-box">
  99. <div class="actual-box__label">
  100. <strong>实际数量</strong>
  101. <span>请按现场实装填写</span>
  102. </div>
  103. <div class="actual-box__row">
  104. <van-field
  105. v-model="item.actualQtyText"
  106. type="number"
  107. class="actual-box__field"
  108. placeholder="请输入"
  109. :border="false"
  110. :readonly="isReadOnly"
  111. />
  112. <span class="actual-box__unit">{{ item.unit || '吨' }}</span>
  113. </div>
  114. </div>
  115. </div>
  116. </van-cell-group>
  117. <van-cell-group inset class="section-card" title="回执上传">
  118. <div class="uploader-wrap">
  119. <van-uploader
  120. v-model="uploaderFiles"
  121. multiple
  122. :max-count="9"
  123. :deletable="!isReadOnly"
  124. :show-upload="!isReadOnly"
  125. :after-read="handleAfterRead"
  126. :before-delete="handleBeforeDelete"
  127. />
  128. </div>
  129. </van-cell-group>
  130. <van-cell-group v-if="!isReadOnly" inset class="section-card" title="单据状态">
  131. <div class="status-radio-wrap">
  132. <van-radio-group v-model="selectedStatus" direction="horizontal">
  133. <van-radio name="in_progress">进行中</van-radio>
  134. <van-radio name="completed">已完成</van-radio>
  135. <van-radio name="voided">已作废</van-radio>
  136. </van-radio-group>
  137. </div>
  138. </van-cell-group>
  139. <van-cell-group inset class="section-card" title="现场备注">
  140. <van-field
  141. v-model="feedbackRemark"
  142. rows="4"
  143. autosize
  144. type="textarea"
  145. maxlength="500"
  146. show-word-limit
  147. placeholder="填写现场备注"
  148. :readonly="isReadOnly"
  149. />
  150. </van-cell-group>
  151. <van-cell-group v-if="page.siteFeedbackTime" inset class="section-card">
  152. <van-cell title="上次保存" :value="formatDateTime(page.siteFeedbackTime)" />
  153. </van-cell-group>
  154. <footer v-if="!isReadOnly" class="page-footer">
  155. <van-button type="primary" block round :loading="saving" @click="handleSave">
  156. 提交
  157. </van-button>
  158. </footer>
  159. </template>
  160. </div>
  161. </PublicMobileShell>
  162. </template>
  163. <script setup lang="ts">
  164. import type { UploaderFileListItem } from 'vant'
  165. import { showConfirmDialog, showFailToast, showSuccessToast } from 'vant'
  166. import {
  167. createPublicIoOrderApi,
  168. type PublicIoOrderItem,
  169. type PublicIoOrderPage
  170. } from '@/api/pl/public-io-order'
  171. import PublicMobileShell from '@/layouts/PublicMobileShell.vue'
  172. import { buildAmapNavigationUrl } from '@/utils/amap/navigation'
  173. import 'vant/es/dialog/style'
  174. import 'vant/es/toast/style'
  175. import '@/styles/public-mobile-vant.scss'
  176. type IoOrderStatus = 'in_progress' | 'completed' | 'voided'
  177. const props = defineProps<{ kind: 'inbound' | 'outbound' }>()
  178. const api = createPublicIoOrderApi(props.kind)
  179. const route = useRoute()
  180. const token = computed(() => String(route.params.token || ''))
  181. const navTitle = computed(() =>
  182. props.kind === 'inbound' ? '入库单 · 现场回执' : '出库单 · 现场回执'
  183. )
  184. const loading = ref(true)
  185. const saving = ref(false)
  186. const errorMessage = ref('')
  187. const page = ref<PublicIoOrderPage | null>(null)
  188. const feedbackRemark = ref('')
  189. const feedbackImages = ref<string[]>([])
  190. const uploaderFiles = ref<UploaderFileListItem[]>([])
  191. const editableItems = ref<(PublicIoOrderItem & { actualQtyText: string })[]>([])
  192. const selectedStatus = ref<IoOrderStatus>('in_progress')
  193. const isReadOnly = computed(() => Boolean(page.value?.voided))
  194. const deliveryAddressDisplay = computed(() => {
  195. if (!page.value) return '—'
  196. return page.value.destinationAddress || page.value.destinationName || '—'
  197. })
  198. const pickupNavUrl = computed(() => {
  199. if (!page.value) return null
  200. return buildAmapNavigationUrl(
  201. page.value.pickupLng,
  202. page.value.pickupLat,
  203. page.value.pickupAddress || '取货点'
  204. )
  205. })
  206. const destinationNavUrl = computed(() => {
  207. if (!page.value) return null
  208. return buildAmapNavigationUrl(
  209. page.value.destinationLng,
  210. page.value.destinationLat,
  211. page.value.destinationAddress || page.value.destinationName || '送货点'
  212. )
  213. })
  214. function openNavigation(url: string) {
  215. window.location.href = url
  216. }
  217. function formatDateTime(value?: string) {
  218. if (!value) return '—'
  219. const normalized = String(value).replace('T', ' ')
  220. return normalized.length > 16 ? normalized.slice(0, 16) : normalized
  221. }
  222. function formatPlanQty(item: PublicIoOrderItem) {
  223. const qty = item.planQty
  224. const unit = item.unit || ''
  225. if (qty == null) return '—'
  226. return unit ? `${qty} ${unit}` : String(qty)
  227. }
  228. function statusLabel(s?: string) {
  229. const map: Record<string, string> = {
  230. in_progress: '进行中',
  231. completed: '已完成',
  232. voided: '已作废'
  233. }
  234. return (s && map[s]) || s || '—'
  235. }
  236. function resolveFileUrl(url: string) {
  237. if (!url) return ''
  238. if (/^https?:\/\//i.test(url)) return url
  239. const base = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
  240. return base ? `${base}/${url.replace(/^\//, '')}` : url
  241. }
  242. function syncUploaderFromImages() {
  243. uploaderFiles.value = feedbackImages.value.map((url, index) => ({
  244. url: resolveFileUrl(url),
  245. isImage: /\.(png|jpe?g|gif|webp|bmp)$/i.test(url),
  246. name: `附件${index + 1}`,
  247. fileUrl: url
  248. })) as UploaderFileListItem[]
  249. }
  250. async function loadPage() {
  251. loading.value = true
  252. errorMessage.value = ''
  253. try {
  254. const data = await api.getPage(token.value)
  255. page.value = data
  256. feedbackRemark.value = data.siteFeedbackRemark || ''
  257. feedbackImages.value = [...(data.siteFeedbackImages || [])]
  258. editableItems.value = (data.items || []).map(it => ({
  259. ...it,
  260. actualQtyText: it.actualQty != null ? String(it.actualQty) : ''
  261. }))
  262. selectedStatus.value = (
  263. ['in_progress', 'completed', 'voided'].includes(data.status || '')
  264. ? data.status
  265. : 'in_progress'
  266. ) as IoOrderStatus
  267. syncUploaderFromImages()
  268. } catch (e: any) {
  269. errorMessage.value = e?.message || '链接无效或已失效'
  270. page.value = null
  271. } finally {
  272. loading.value = false
  273. }
  274. }
  275. async function handleAfterRead(item: UploaderFileListItem | UploaderFileListItem[]) {
  276. if (isReadOnly.value) return
  277. const files = Array.isArray(item) ? item : [item]
  278. for (const fileItem of files) {
  279. if (!fileItem.file) continue
  280. fileItem.status = 'uploading'
  281. fileItem.message = '上传中...'
  282. try {
  283. const res = await api.uploadAttachment(token.value, fileItem.file as File)
  284. if (res.fileUrl) {
  285. feedbackImages.value.push(res.fileUrl)
  286. ;(fileItem as UploaderFileListItem & { fileUrl?: string }).fileUrl = res.fileUrl
  287. fileItem.url = resolveFileUrl(res.fileUrl)
  288. fileItem.status = 'done'
  289. fileItem.message = ''
  290. }
  291. } catch (e: any) {
  292. fileItem.status = 'failed'
  293. fileItem.message = e?.message || '上传失败'
  294. }
  295. }
  296. }
  297. function handleBeforeDelete(item: UploaderFileListItem) {
  298. if (isReadOnly.value) return false
  299. const fileUrl = (item as UploaderFileListItem & { fileUrl?: string }).fileUrl
  300. if (fileUrl) {
  301. feedbackImages.value = feedbackImages.value.filter(u => u !== fileUrl)
  302. }
  303. return true
  304. }
  305. async function handleSave() {
  306. if (isReadOnly.value) return
  307. if (selectedStatus.value === 'voided') {
  308. try {
  309. await showConfirmDialog({
  310. title: '确认作废',
  311. message: '确认作废本出入库单?作废后不可再提交。'
  312. })
  313. } catch {
  314. return
  315. }
  316. }
  317. saving.value = true
  318. try {
  319. await api.saveFeedback(token.value, {
  320. status: selectedStatus.value,
  321. remark: feedbackRemark.value,
  322. images: feedbackImages.value,
  323. items: editableItems.value.map(it => ({
  324. id: it.id,
  325. actualQty: Number(it.actualQtyText || 0)
  326. }))
  327. })
  328. showSuccessToast('提交成功')
  329. await loadPage()
  330. } catch (e: any) {
  331. showFailToast(e?.message || '提交失败')
  332. } finally {
  333. saving.value = false
  334. }
  335. }
  336. watch(token, loadPage, { immediate: true })
  337. </script>
  338. <style scoped lang="scss">
  339. .page-loading {
  340. display: flex;
  341. justify-content: center;
  342. padding: 48px 0;
  343. }
  344. .site-nav-bar {
  345. margin: -12px -16px 12px;
  346. border-radius: 0 0 12px 12px;
  347. overflow: hidden;
  348. :deep(.van-nav-bar) {
  349. background: #059669;
  350. }
  351. :deep(.van-nav-bar__title) {
  352. color: #fff;
  353. font-weight: 600;
  354. }
  355. }
  356. .section-card {
  357. margin-bottom: 10px;
  358. }
  359. .uploader-wrap {
  360. padding: 8px 14px 12px;
  361. }
  362. .status-radio-wrap {
  363. padding: 12px 16px 16px;
  364. }
  365. .page-footer {
  366. padding: 16px;
  367. }
  368. .multiline-cell :deep(.van-cell__value) {
  369. text-align: left;
  370. line-height: 1.35;
  371. white-space: normal;
  372. }
  373. .address-cell__content {
  374. display: flex;
  375. flex-wrap: wrap;
  376. align-items: center;
  377. gap: 4px 8px;
  378. justify-content: flex-start;
  379. }
  380. .address-cell__text {
  381. line-height: 1.35;
  382. color: #1e293b;
  383. font-weight: 600;
  384. }
  385. .address-nav-btn {
  386. flex-shrink: 0;
  387. height: 22px;
  388. padding: 0 8px;
  389. font-size: 11px;
  390. line-height: 22px;
  391. }
  392. .product-card {
  393. margin: 10px 12px;
  394. padding: 14px;
  395. border-radius: 12px;
  396. background: linear-gradient(180deg, #f0fdf4 0%, #fff 48%);
  397. border: 1px solid #d1fae5;
  398. }
  399. .product-card__head {
  400. display: flex;
  401. align-items: flex-start;
  402. justify-content: space-between;
  403. gap: 8px;
  404. margin-bottom: 10px;
  405. }
  406. .product-card__name {
  407. font-size: 15px;
  408. font-weight: 700;
  409. color: #0f172a;
  410. line-height: 1.35;
  411. }
  412. .product-card__badge {
  413. flex-shrink: 0;
  414. font-size: 10px;
  415. font-weight: 600;
  416. padding: 2px 8px;
  417. border-radius: 999px;
  418. background: #d1fae5;
  419. color: #047857;
  420. }
  421. .meta-grid {
  422. display: grid;
  423. grid-template-columns: 1fr 1fr;
  424. gap: 8px;
  425. margin-bottom: 12px;
  426. }
  427. .meta-item {
  428. background: rgb(255 255 255 / 85%);
  429. border: 1px solid #e2e8f0;
  430. border-radius: 8px;
  431. padding: 8px 10px;
  432. }
  433. .meta-item--span {
  434. grid-column: 1 / -1;
  435. }
  436. .meta-item__label {
  437. font-size: 11px;
  438. color: #64748b;
  439. margin-bottom: 2px;
  440. }
  441. .meta-item__value {
  442. font-size: 13px;
  443. font-weight: 600;
  444. color: #1e293b;
  445. word-break: break-all;
  446. }
  447. .meta-item__value--plan {
  448. color: #059669;
  449. font-size: 15px;
  450. }
  451. .actual-box {
  452. background: #fff;
  453. border: 1px solid #a7f3d0;
  454. border-radius: 10px;
  455. padding: 10px 12px;
  456. }
  457. .actual-box__label {
  458. display: flex;
  459. align-items: center;
  460. justify-content: space-between;
  461. margin-bottom: 8px;
  462. font-size: 12px;
  463. color: #64748b;
  464. strong {
  465. color: #1e293b;
  466. font-size: 13px;
  467. }
  468. }
  469. .actual-box__row {
  470. display: flex;
  471. align-items: center;
  472. gap: 8px;
  473. }
  474. .actual-box__field {
  475. flex: 1;
  476. padding: 0;
  477. background: #ecfdf5;
  478. border: 1.5px solid #6ee7b7;
  479. border-radius: 8px;
  480. overflow: hidden;
  481. :deep(.van-field__control) {
  482. height: 40px;
  483. padding: 0 12px;
  484. font-size: 18px;
  485. font-weight: 700;
  486. color: #059669;
  487. line-height: 40px;
  488. }
  489. }
  490. .actual-box__unit {
  491. flex-shrink: 0;
  492. font-size: 14px;
  493. font-weight: 700;
  494. color: #059669;
  495. min-width: 28px;
  496. }
  497. </style>