list.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="bx-page pl-driver-plan-page">
  3. <view class="topbar" :style="safeAreaStyle">
  4. <view class="topbar-left">
  5. <text class="topbar-back" @click="goBack">←</text>
  6. <text class="topbar-title">司机运输计划单</text>
  7. </view>
  8. <view class="topbar-right" />
  9. </view>
  10. <view class="filters">
  11. <uni-calendar
  12. :insert="true"
  13. :date="selectedDate"
  14. :selected="calendarSelected"
  15. :showMonth="false"
  16. @change="onCalendarChange"
  17. @monthSwitch="onMonthSwitch"
  18. />
  19. </view>
  20. <view class="list-body">
  21. <view v-if="loading" class="page-loading">加载中...</view>
  22. <view v-else-if="!records.length" class="empty-hint">暂无运输记录</view>
  23. <view
  24. v-for="(row, index) in records"
  25. :key="row.planId || index"
  26. class="record-card"
  27. @click="openRecord(row)"
  28. >
  29. <text class="index-tag">{{ index + 1 }}</text>
  30. <view class="record-top">
  31. <text class="card-title">{{ cardTitle(row) }}</text>
  32. <view class="record-top-actions" @click.stop>
  33. <view class="pound-qr-btn" @click="openPoundQr(row)">磅单二维码</view>
  34. <text class="tag" :class="tagClass(row)">{{ row.statusLabel || '进行中' }}</text>
  35. </view>
  36. </view>
  37. <view class="meta">
  38. 车牌:<text class="plate-hl">{{ row.licensePlate || '—' }}</text>
  39. </view>
  40. <template v-if="(row.stops || []).length">
  41. <view
  42. v-for="(stop, sIndex) in row.stops"
  43. :key="`${stop.stopType}-${stop.seq ?? sIndex}`"
  44. class="stop-block"
  45. >
  46. <view class="stop-block__title"
  47. >{{ stop.label }} · {{ stop.customerName || '—' }}</view
  48. >
  49. <view class="meta">时间:{{ formatDay(stop.stopTime) }}</view>
  50. <view class="meta">地址:{{ stop.address || '—' }}</view>
  51. <template v-if="!(stop.products || []).length">
  52. <view class="meta">产品:—</view>
  53. </template>
  54. <template v-for="(prod, pIndex) in stop.products || []" :key="pIndex">
  55. <view class="meta">产品:{{ prod.productName || '—' }}</view>
  56. <view class="meta">规格型号:{{ prod.model || '—' }}</view>
  57. <view class="meta">包装规格:{{ prod.packageSpec || '—' }}</view>
  58. <view class="meta"
  59. >数量:{{ formatQty(prod.quantity) }} · 单位:{{ prod.unit || '—' }}</view
  60. >
  61. </template>
  62. </view>
  63. </template>
  64. <view class="meta">运输计划号:{{ row.planNo || '—' }}</view>
  65. </view>
  66. </view>
  67. <db-pound-qrcode-popup
  68. :show="poundQrOpen"
  69. :inventory-id="poundQrId"
  70. :snapshot="poundQrSnapshot"
  71. @close="poundQrOpen = false"
  72. @update:show="(v) => (poundQrOpen = v)"
  73. />
  74. </view>
  75. </template>
  76. <script setup>
  77. import { ref } from 'vue'
  78. import { onShow } from '@dcloudio/uni-app'
  79. import { PAGE_PATHS } from '@/config/api'
  80. import { driverPlanApi } from '@/api/pl'
  81. import { getSafeAreaStyle } from '@/utils/safeArea'
  82. import DbPoundQrcodePopup from '@/components/db-ui/db-pound-qrcode-popup.vue'
  83. const safeAreaStyle = getSafeAreaStyle()
  84. const poundQrOpen = ref(false)
  85. const poundQrId = ref('')
  86. const poundQrSnapshot = ref(null)
  87. function todayStr() {
  88. const d = new Date()
  89. const m = `${d.getMonth() + 1}`.padStart(2, '0')
  90. const day = `${d.getDate()}`.padStart(2, '0')
  91. return `${d.getFullYear()}-${m}-${day}`
  92. }
  93. const selectedDate = ref(todayStr())
  94. const records = ref([])
  95. const loading = ref(false)
  96. const calendarSelected = ref([])
  97. let calendarMonth = selectedDate.value.slice(0, 7)
  98. function formatDay(value) {
  99. if (!value) return '—'
  100. const normalized = String(value).replace('T', ' ')
  101. return normalized.length >= 10 ? normalized.slice(0, 10) : normalized
  102. }
  103. function formatQty(value) {
  104. if (value == null || value === '') return '—'
  105. return String(value)
  106. }
  107. function cardTitleDate(row) {
  108. const stopTimes = (row.stops || [])
  109. .map((stop) => formatDay(stop.stopTime))
  110. .filter((value) => value !== '—')
  111. if (stopTimes.length) return stopTimes[0]
  112. const fromPickup = formatDay(row.pickupTime)
  113. if (fromPickup !== '—') return fromPickup
  114. const fromDelivery = formatDay(row.deliveryTime)
  115. if (fromDelivery !== '—') return fromDelivery
  116. return selectedDate.value
  117. }
  118. function cardTitle(row) {
  119. return cardTitleDate(row)
  120. }
  121. function tagClass(row) {
  122. if (row.planVoided || row.statusLabel === '已作废') return 'tag--danger'
  123. if (row.planArchived || row.statusLabel === '已归档') return 'tag--muted'
  124. return 'tag--success'
  125. }
  126. async function loadList() {
  127. loading.value = true
  128. try {
  129. const res = await driverPlanApi.history({ date: selectedDate.value })
  130. records.value = res.records || []
  131. } catch (e) {
  132. records.value = []
  133. } finally {
  134. loading.value = false
  135. }
  136. }
  137. async function loadCalendarCounts(month) {
  138. const m = String(month || '').slice(0, 7)
  139. if (!/^\d{4}-\d{2}$/.test(m)) return
  140. calendarMonth = m
  141. const today = todayStr()
  142. try {
  143. const counts = await driverPlanApi.calendarCounts(m)
  144. calendarSelected.value = Object.keys(counts || {})
  145. .filter((date) => Number(counts[date]) > 0 && date >= today)
  146. .map((date) => ({ date, info: String(counts[date]) }))
  147. } catch (e) {
  148. calendarSelected.value = []
  149. }
  150. }
  151. function onCalendarChange(e) {
  152. const v = e?.fulldate || e?.date || (typeof e === 'string' ? e : '')
  153. if (typeof v === 'string' && /^\d{4}-\d{2}-\d{2}/.test(v)) {
  154. selectedDate.value = v.slice(0, 10)
  155. const month = selectedDate.value.slice(0, 7)
  156. if (month !== calendarMonth) {
  157. loadCalendarCounts(month)
  158. }
  159. loadList()
  160. }
  161. }
  162. function onMonthSwitch(e) {
  163. const year = e?.year
  164. const month = e?.month
  165. if (year == null || month == null) return
  166. const m = `${year}-${`${month}`.padStart(2, '0')}`
  167. loadCalendarCounts(m)
  168. }
  169. function openRecord(row) {
  170. const id = row.planId || row.plan_id
  171. if (!id) {
  172. uni.showToast({ title: '计划无效', icon: 'none' })
  173. return
  174. }
  175. uni.navigateTo({ url: `${PAGE_PATHS.plDriverPlanDetail}?planId=${id}` })
  176. }
  177. function poundItemsOf(row) {
  178. const items = row?.poundQrcodeItems || row?.pound_qrcode_items || []
  179. return Array.isArray(items) ? items : []
  180. }
  181. function openPoundForInventoryId(inventoryId) {
  182. const id = String(inventoryId || '').trim()
  183. if (!id) {
  184. uni.showToast({ title: '缺少出入库单', icon: 'none' })
  185. return
  186. }
  187. poundQrId.value = id
  188. poundQrSnapshot.value = null
  189. poundQrOpen.value = true
  190. }
  191. function openPoundQr(row) {
  192. const items = poundItemsOf(row)
  193. if (!items.length) {
  194. uni.showToast({ title: '暂无磅单二维码', icon: 'none' })
  195. return
  196. }
  197. if (items.length === 1) {
  198. openPoundForInventoryId(items[0].inventoryId || items[0].inventory_id)
  199. return
  200. }
  201. uni.showActionSheet({
  202. itemList: items.map((item) => item.label || item.partnerCompany || '磅单'),
  203. success: (res) => {
  204. const picked = items[res.tapIndex]
  205. if (!picked) return
  206. openPoundForInventoryId(picked.inventoryId || picked.inventory_id)
  207. }
  208. })
  209. }
  210. function goBack() {
  211. uni.navigateBack({ fail: () => uni.reLaunch({ url: PAGE_PATHS.workbench }) })
  212. }
  213. onShow(() => {
  214. loadCalendarCounts(calendarMonth || selectedDate.value.slice(0, 7))
  215. loadList()
  216. })
  217. </script>
  218. <!-- 微信端:scss 须在 style 中 @import;script 里 import 只会生成空 js,H5 有样式而小程序无样式 -->
  219. <style lang="scss">
  220. @import '@/styles/bx-theme.scss';
  221. @import '@/styles/pl-driver-plan.scss';
  222. </style>
  223. <style lang="scss" scoped>
  224. :deep(.uni-calendar__backtoday) {
  225. display: none;
  226. }
  227. :deep(.uni-calendar),
  228. :deep(.uni-calendar__content),
  229. :deep(.uni-calendar__box) {
  230. box-shadow: none !important;
  231. border: none !important;
  232. background: transparent !important;
  233. }
  234. :deep(.uni-calendar-item--checked),
  235. :deep(.uni-calendar-item--isDay),
  236. :deep(.uni-calendar-item--multiple) {
  237. background-color: #0a9f6d !important;
  238. color: #fff !important;
  239. }
  240. :deep(.uni-calendar-item--isDay-text) {
  241. color: #0a9f6d !important;
  242. }
  243. :deep(.uni-calendar-item--checked.uni-calendar-item--isDay-text),
  244. :deep(.uni-calendar-item--isDay.uni-calendar-item--isDay-text) {
  245. color: #fff !important;
  246. }
  247. </style>