detail.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <script setup>
  2. import { ref, computed } from 'vue'
  3. import { onLoad, onShow } from '@dcloudio/uni-app'
  4. import { getPlan, getPlanArrangeInfo, archivePlan } from '@/api/pl'
  5. import {
  6. dash,
  7. planTypeLabel,
  8. followStatusLabel,
  9. transportStatusLabel,
  10. archiveStatusLabel,
  11. planCardSub,
  12. formatQty
  13. } from '@/utils/plLabels'
  14. import { PAGE_PATHS } from '@/config/api'
  15. const id = ref('')
  16. const readonly = ref(false)
  17. const detail = ref(null)
  18. const arrange = ref(null)
  19. const acting = ref(false)
  20. const phaseFollow = computed(() => followStatusLabel(detail.value?.followStatus))
  21. const phaseTransport = computed(() => transportStatusLabel(detail.value?.transportStatus))
  22. const phaseArchive = computed(() => archiveStatusLabel(detail.value?.archiveStatus))
  23. const products = computed(() =>
  24. Array.isArray(detail.value?.products) ? detail.value.products : []
  25. )
  26. const canArrange = computed(
  27. () =>
  28. !readonly.value &&
  29. detail.value?.transportStatus === 'pending' &&
  30. detail.value?.followStatus !== 'cancelled' &&
  31. detail.value?.followStatus !== 'completed'
  32. )
  33. const canArchive = computed(
  34. () =>
  35. !readonly.value &&
  36. detail.value?.archiveStatus !== 'archived' &&
  37. detail.value?.transportStatus === 'arranged' &&
  38. detail.value?.followStatus !== 'cancelled'
  39. )
  40. const goBack = () => {
  41. uni.navigateBack({
  42. fail: () =>
  43. uni.navigateTo({
  44. url: readonly.value ? PAGE_PATHS.plArchiveList : PAGE_PATHS.plPlanList
  45. })
  46. })
  47. }
  48. const goArrange = () =>
  49. uni.navigateTo({ url: `${PAGE_PATHS.plPlanArrange}?id=${id.value}` })
  50. const load = async () => {
  51. if (!id.value) return
  52. try {
  53. detail.value = await getPlan(id.value)
  54. if (detail.value?.transportStatus === 'arranged') {
  55. try {
  56. arrange.value = await getPlanArrangeInfo(id.value)
  57. } catch {
  58. arrange.value = null
  59. }
  60. } else {
  61. arrange.value = null
  62. }
  63. } catch (e) {
  64. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  65. }
  66. }
  67. const onArchive = () => {
  68. const list = products.value
  69. if (!list.length) {
  70. uni.showToast({ title: '无产品明细,无法归档', icon: 'none' })
  71. return
  72. }
  73. uni.showModal({
  74. title: '确认归档',
  75. content: '将按计划数量写入实际数量并归档。复杂调整请在 Web 端操作。',
  76. success: async (r) => {
  77. if (!r.confirm) return
  78. acting.value = true
  79. try {
  80. await archivePlan(id.value, {
  81. products: list.map((p) => ({
  82. id: p.id,
  83. actualQty: Number(p.actualQty != null ? p.actualQty : p.quantity) || 0
  84. }))
  85. })
  86. uni.showToast({ title: '已归档', icon: 'success' })
  87. load()
  88. } catch (e) {
  89. uni.showToast({ title: e.message || '归档失败', icon: 'none' })
  90. } finally {
  91. acting.value = false
  92. }
  93. }
  94. })
  95. }
  96. onLoad((q) => {
  97. id.value = q?.id || ''
  98. readonly.value = q?.readonly === '1' || q?.mode === 'archive'
  99. })
  100. onShow(() => load())
  101. </script>
  102. <template>
  103. <view class="mp-page mp-page--sub mp-page--with-bottom">
  104. <view class="mp-header mp-header--pl">
  105. <text class="mp-subpage-back" @click="goBack">← 返回</text>
  106. <text class="mp-header__title" style="margin-top: 16rpx">
  107. {{ readonly ? '归档详情' : '计划详情' }}
  108. </text>
  109. </view>
  110. <view v-if="detail" class="mp-detail-hero">
  111. <view class="mp-detail-hero__top">
  112. <view>
  113. <text class="mp-detail-hero__title">{{ dash(detail.planNo) }}</text>
  114. <text class="mp-detail-hero__sub">{{ planCardSub(detail) }}</text>
  115. </view>
  116. <text class="mp-tag" :class="'mp-tag--' + phaseTransport.tag">{{ phaseTransport.text }}</text>
  117. </view>
  118. <view class="mp-detail-hero__meta">
  119. <text class="mp-detail-hero__chip">{{ planTypeLabel(detail.planType) }}</text>
  120. <text class="mp-detail-hero__chip">{{ phaseFollow.text }}</text>
  121. <text class="mp-detail-hero__chip">{{ phaseArchive.text }}</text>
  122. </view>
  123. </view>
  124. <view class="mp-block">
  125. <text class="mp-block__title">基本信息</text>
  126. <view class="mp-block__panel">
  127. <view class="mp-kv"><text class="mp-kv__label">计划日期</text><text class="mp-kv__value">{{ dash(detail?.planDate) }}</text></view>
  128. <view class="mp-kv"><text class="mp-kv__label">客户</text><text class="mp-kv__value">{{ dash(detail?.customerName) }}</text></view>
  129. <view class="mp-kv"><text class="mp-kv__label">供应商</text><text class="mp-kv__value">{{ dash(detail?.supplierName) }}</text></view>
  130. <view class="mp-kv"><text class="mp-kv__label">取货地址</text><text class="mp-kv__value">{{ dash(detail?.pickupAddress) }}</text></view>
  131. <view class="mp-kv"><text class="mp-kv__label">送货地址</text><text class="mp-kv__value">{{ dash(detail?.destinationAddress) }}</text></view>
  132. <view class="mp-kv"><text class="mp-kv__label">联系人</text><text class="mp-kv__value">{{ dash(detail?.contactName) }} {{ dash(detail?.contactPhone) }}</text></view>
  133. <view class="mp-kv"><text class="mp-kv__label">跟进人</text><text class="mp-kv__value">{{ dash(detail?.followUserName) }}</text></view>
  134. <view class="mp-kv"><text class="mp-kv__label">备注</text><text class="mp-kv__value">{{ dash(detail?.remark) }}</text></view>
  135. </view>
  136. </view>
  137. <view class="mp-block">
  138. <text class="mp-block__title">产品明细</text>
  139. <mp-empty v-if="!products.length" compact title="暂无明细" />
  140. <view v-else class="mp-block__panel">
  141. <view v-for="p in products" :key="p.id" class="mp-kv">
  142. <text class="mp-kv__label">{{ dash(p.productName) }}</text>
  143. <text class="mp-kv__value">{{ formatQty(p.quantity, p.unit) }}</text>
  144. </view>
  145. </view>
  146. </view>
  147. <view v-if="detail?.transportStatus === 'arranged'" class="mp-block">
  148. <text class="mp-block__title">运输安排</text>
  149. <view class="mp-block__panel">
  150. <view class="mp-kv">
  151. <text class="mp-kv__label">车牌</text>
  152. <text class="mp-kv__value">{{ dash(arrange?.licensePlate || detail.licensePlate) }}</text>
  153. </view>
  154. <view class="mp-kv">
  155. <text class="mp-kv__label">司机</text>
  156. <text class="mp-kv__value">{{ dash(detail.driverName) }}</text>
  157. </view>
  158. <view class="mp-kv">
  159. <text class="mp-kv__label">承运商</text>
  160. <text class="mp-kv__value">{{ dash(detail.carrierName) }}</text>
  161. </view>
  162. <view v-if="arrange?.driverUrl" class="mp-kv">
  163. <text class="mp-kv__label">司机扫码</text>
  164. <text class="mp-kv__value">已生成链接</text>
  165. </view>
  166. </view>
  167. </view>
  168. <view v-if="canArrange || canArchive" class="mp-bottom-bar">
  169. <button v-if="canArrange" class="mp-btn mp-btn--primary mp-btn--block" :disabled="acting" @click="goArrange">
  170. 安排运输
  171. </button>
  172. <button v-if="canArchive" class="mp-btn mp-btn--primary mp-btn--block" :disabled="acting" @click="onArchive">
  173. 归档
  174. </button>
  175. </view>
  176. </view>
  177. </template>