detail.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onLoad, onShow } from '@dcloudio/uni-app'
  4. import { getPlan, getPlanRelated, createInventoryLinkForPlan } from '@/api/db'
  5. import { planStatusLabel, dash, formatWeight } from '@/utils/dbLabels'
  6. import { PAGE_PATHS } from '@/config/api'
  7. const id = ref('')
  8. const detail = ref(null)
  9. const related = ref({ inventories: [], weighings: [] })
  10. const acting = ref(false)
  11. const goBack = () => {
  12. uni.navigateBack({
  13. fail: () => uni.navigateTo({ url: PAGE_PATHS.dbPlansList })
  14. })
  15. }
  16. const load = async () => {
  17. if (!id.value) return
  18. try {
  19. detail.value = await getPlan(id.value)
  20. related.value = await getPlanRelated(id.value)
  21. } catch (e) {
  22. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  23. }
  24. }
  25. const createLink = () => {
  26. uni.showModal({
  27. title: '生成出入库单',
  28. content: '为该计划创建可填写的出入库关联单?',
  29. success: async (r) => {
  30. if (!r.confirm) return
  31. acting.value = true
  32. try {
  33. const inv = await createInventoryLinkForPlan(id.value)
  34. uni.showToast({ title: '已生成', icon: 'success' })
  35. if (inv?.id) {
  36. uni.navigateTo({ url: `${PAGE_PATHS.dbInventoryDetail}?id=${inv.id}` })
  37. } else {
  38. load()
  39. }
  40. } catch (e) {
  41. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  42. } finally {
  43. acting.value = false
  44. }
  45. }
  46. })
  47. }
  48. const openWeighing = (w) =>
  49. uni.navigateTo({ url: `${PAGE_PATHS.dbWeighingDetail}?id=${w.id}` })
  50. const openInventory = (inv) =>
  51. uni.navigateTo({ url: `${PAGE_PATHS.dbInventoryDetail}?id=${inv.id}` })
  52. onLoad((q) => {
  53. id.value = q?.id || ''
  54. })
  55. onShow(() => load())
  56. </script>
  57. <template>
  58. <view class="mp-page mp-page--sub mp-page--with-bottom">
  59. <view class="mp-header mp-header--db">
  60. <text class="mp-subpage-back" @click="goBack">← 返回</text>
  61. <text class="mp-header__title" style="margin-top: 16rpx">计划详情</text>
  62. </view>
  63. <view v-if="detail" class="mp-detail-hero">
  64. <view class="mp-detail-hero__top">
  65. <view>
  66. <text class="mp-detail-hero__title">{{ dash(detail.planNo) }}</text>
  67. <text class="mp-detail-hero__sub">{{ dash(detail.product) }}</text>
  68. </view>
  69. <text class="mp-tag" :class="'mp-tag--' + planStatusLabel(detail.executionStatus).tag">
  70. {{ planStatusLabel(detail.executionStatus).text }}
  71. </text>
  72. </view>
  73. <view class="mp-detail-hero__meta">
  74. <text class="mp-detail-hero__chip">{{ dash(detail.businessType) }}</text>
  75. <text class="mp-detail-hero__chip">
  76. {{ formatWeight(detail.executedQuantity) }} / {{ formatWeight(detail.plannedQuantity) }}
  77. </text>
  78. </view>
  79. </view>
  80. <view class="mp-block">
  81. <text class="mp-block__title">基本信息</text>
  82. <view class="mp-block__panel">
  83. <view class="mp-kv"><text class="mp-kv__label">计划日期</text><text class="mp-kv__value">{{ dash(detail?.planDate) }}</text></view>
  84. <view class="mp-kv"><text class="mp-kv__label">起止</text><text class="mp-kv__value">{{ dash(detail?.startDate) }} ~ {{ dash(detail?.endDate) }}</text></view>
  85. <view class="mp-kv"><text class="mp-kv__label">规格</text><text class="mp-kv__value">{{ dash(detail?.specification) }}</text></view>
  86. <view class="mp-kv"><text class="mp-kv__label">车牌</text><text class="mp-kv__value">{{ dash(detail?.vehicleNo) }}</text></view>
  87. <view class="mp-kv"><text class="mp-kv__label">客户</text><text class="mp-kv__value">{{ dash(detail?.customerName) }}</text></view>
  88. <view class="mp-kv"><text class="mp-kv__label">备注</text><text class="mp-kv__value">{{ dash(detail?.remarks) }}</text></view>
  89. </view>
  90. </view>
  91. <view class="mp-block">
  92. <text class="mp-block__title">关联出入库({{ related.inventories?.length || 0 }})</text>
  93. <mp-empty v-if="!related.inventories?.length" compact title="暂无出入库单" />
  94. <view v-else class="mp-list">
  95. <view
  96. v-for="inv in related.inventories"
  97. :key="inv.id"
  98. class="mp-card"
  99. @click="openInventory(inv)"
  100. >
  101. <text class="mp-card__title">{{ dash(inv.batchNo || inv.id) }}</text>
  102. <text class="mp-card__sub">{{ dash(inv.vehicleNo) }} · {{ dash(inv.status) }}</text>
  103. </view>
  104. </view>
  105. </view>
  106. <view class="mp-block">
  107. <text class="mp-block__title">关联地磅单({{ related.weighings?.length || 0 }})</text>
  108. <mp-empty v-if="!related.weighings?.length" compact title="暂无地磅单" />
  109. <view v-else class="mp-list">
  110. <view
  111. v-for="w in related.weighings"
  112. :key="w.id"
  113. class="mp-card"
  114. @click="openWeighing(w)"
  115. >
  116. <text class="mp-card__title">{{ dash(w.vehicleNo) }}</text>
  117. <text class="mp-card__sub">净重 {{ formatWeight(w.netWeight) }}</text>
  118. </view>
  119. </view>
  120. </view>
  121. <view class="mp-bottom-bar">
  122. <view class="mp-btn mp-btn--primary" @click="createLink">
  123. {{ acting ? '…' : '生成出入库关联单' }}
  124. </view>
  125. </view>
  126. </view>
  127. </template>