db-pound-qrcode-popup.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <view v-if="show" class="pound-qr-mask" @click="close">
  3. <view class="pound-qr-panel" @click.stop>
  4. <view class="pound-qr-panel__close" @click.stop="close">×</view>
  5. <view class="pound-qr-panel__title">{{ title }}</view>
  6. <view v-if="loading" class="pound-qr-panel__loading">加载中...</view>
  7. <view v-else-if="row" class="pound-slip-capture-inline">
  8. <view class="capture-card">
  9. <view class="capture-row capture-row-plate">
  10. <view class="vehicle-plate">
  11. <view class="vehicle-plate-dot vehicle-plate-dot-lt" />
  12. <view class="vehicle-plate-dot vehicle-plate-dot-lb" />
  13. <text class="vehicle-plate-text">{{ row.vehicleNo || '未填车牌' }}</text>
  14. <view class="vehicle-plate-dot vehicle-plate-dot-rt" />
  15. <view class="vehicle-plate-dot vehicle-plate-dot-rb" />
  16. </view>
  17. </view>
  18. <view class="capture-row capture-row-large">
  19. <text class="label">往来单位:</text>
  20. <text class="value">{{ row.partnerCompany || '--' }}</text>
  21. </view>
  22. <view class="capture-row capture-row-large">
  23. <text class="label">物料名称:</text>
  24. <text class="value">{{ productLine }}</text>
  25. </view>
  26. <view v-if="remarksText" class="capture-row">
  27. <text class="label">备注:</text>
  28. <text class="value">{{ remarksText }}</text>
  29. </view>
  30. </view>
  31. <view class="capture-card capture-qrcode">
  32. <view class="capture-id">
  33. {{ row.date || '' }}
  34. {{ row.businessType === '出库' ? '出库单ID:' : '入库单ID:' }}{{ row.id }}
  35. </view>
  36. <view class="capture-qr-wrap">
  37. <image v-if="qrPath" class="capture-qr-img" :src="qrPath" mode="aspectFit" />
  38. </view>
  39. <view class="capture-desc">出入库单标识(扫码核验)</view>
  40. </view>
  41. </view>
  42. <!-- 隐藏 canvas,供 uqrcodejs 绘制 -->
  43. <canvas
  44. canvas-id="poundQrCanvas"
  45. id="poundQrCanvas"
  46. class="pound-qr-canvas"
  47. :style="{ width: canvasSize + 'px', height: canvasSize + 'px' }"
  48. />
  49. </view>
  50. </view>
  51. </template>
  52. <script setup>
  53. import { computed, getCurrentInstance, ref, watch } from 'vue'
  54. import db from '@/utils/dbRequest'
  55. import {
  56. formatPoundQrProductLine,
  57. normalizePoundQrRemarks,
  58. poundQrDialogTitle
  59. } from '@/utils/dbPoundQr'
  60. import { makeQrTempFile } from '@/utils/makeQrTempFile'
  61. const props = defineProps({
  62. show: Boolean,
  63. inventoryId: { type: String, default: '' },
  64. /** 列表行快照(可选);缺字段时走公开磅单接口补全 */
  65. snapshot: { type: Object, default: null }
  66. })
  67. const emit = defineEmits(['close', 'update:show'])
  68. const loading = ref(false)
  69. const row = ref(null)
  70. const qrPath = ref('')
  71. let loadSeq = 0
  72. const canvasSize = 200
  73. const instance = getCurrentInstance()
  74. const title = computed(() => poundQrDialogTitle(row.value?.businessType))
  75. const productLine = computed(() => {
  76. if (!row.value) return ''
  77. const unit = row.value.quantityUnit || row.value.quantity_unit || '吨'
  78. return formatPoundQrProductLine(row.value, unit)
  79. })
  80. const remarksText = computed(() => (row.value ? normalizePoundQrRemarks(row.value) : ''))
  81. function close() {
  82. emit('update:show', false)
  83. emit('close')
  84. }
  85. function reset() {
  86. loadSeq += 1
  87. row.value = null
  88. qrPath.value = ''
  89. loading.value = false
  90. }
  91. function unwrapData(data) {
  92. if (!data || typeof data !== 'object') return data
  93. if (data.code != null && data.data !== undefined) return data.data
  94. return data
  95. }
  96. async function fetchPoundQr(id) {
  97. const raw = await db.get(`/public/db/inventory/${id}/pound-qr`, undefined, {
  98. showError: false
  99. })
  100. return unwrapData(raw)
  101. }
  102. async function load() {
  103. const seq = ++loadSeq
  104. const id = String(props.inventoryId || '').trim()
  105. if (!id) {
  106. uni.showToast({ title: '缺少单据ID', icon: 'none' })
  107. close()
  108. return
  109. }
  110. loading.value = true
  111. row.value = null
  112. qrPath.value = ''
  113. try {
  114. let data = props.snapshot && String(props.snapshot.id) === id ? { ...props.snapshot } : null
  115. // 快照已含数量即可展示;否则走公开接口(主包组件不可依赖 db 分包 inventoryApi)
  116. if (!data || data.quantity == null) {
  117. data = await fetchPoundQr(id)
  118. }
  119. if (!data || !data.id) throw new Error('单据不存在')
  120. if (seq !== loadSeq) return
  121. row.value = data
  122. await new Promise((r) => setTimeout(r, 50))
  123. const proxy = instance?.proxy
  124. const path = await makeQrTempFile({
  125. text: data.id,
  126. canvasId: 'poundQrCanvas',
  127. componentInstance: proxy,
  128. size: canvasSize
  129. })
  130. if (seq !== loadSeq) return
  131. qrPath.value = path
  132. } catch (e) {
  133. if (seq !== loadSeq) return
  134. uni.showToast({ title: e?.message || '加载二维码失败', icon: 'none' })
  135. close()
  136. } finally {
  137. if (seq === loadSeq) loading.value = false
  138. }
  139. }
  140. watch(
  141. () => [props.show, props.inventoryId],
  142. ([show]) => {
  143. if (show) load()
  144. else reset()
  145. }
  146. )
  147. </script>
  148. <style scoped lang="scss">
  149. .pound-qr-mask {
  150. position: fixed;
  151. inset: 0;
  152. z-index: 1100;
  153. background: rgba(0, 0, 0, 0.92);
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. padding: 24px 8px;
  158. box-sizing: border-box;
  159. }
  160. .pound-qr-panel {
  161. width: 100%;
  162. max-width: 360px;
  163. max-height: 90vh;
  164. overflow: auto;
  165. background: #f5f7fa;
  166. border-radius: 12px;
  167. position: relative;
  168. box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  169. }
  170. .pound-qr-panel__close {
  171. position: absolute;
  172. top: 8px;
  173. right: 8px;
  174. z-index: 2;
  175. width: 36px;
  176. height: 36px;
  177. display: flex;
  178. align-items: center;
  179. justify-content: center;
  180. font-size: 22px;
  181. line-height: 1;
  182. color: #94a3b8;
  183. font-weight: 400;
  184. }
  185. .pound-qr-panel__title {
  186. text-align: left;
  187. font-size: 17px;
  188. font-weight: 700;
  189. color: #1e293b;
  190. padding: 14px 44px 12px 16px;
  191. border-bottom: 1px solid #d1fae5;
  192. background: linear-gradient(90deg, #ecfdf5 0%, #f5f7fa 55%);
  193. }
  194. .pound-qr-panel__loading {
  195. text-align: center;
  196. color: #9ca3af;
  197. padding: 40px 0;
  198. font-size: 14px;
  199. }
  200. .pound-qr-canvas {
  201. position: fixed;
  202. left: -9999px;
  203. top: 0;
  204. width: 200px;
  205. height: 200px;
  206. }
  207. .pound-slip-capture-inline {
  208. background: #f5f7fa;
  209. padding: 4px 4px 12px;
  210. margin: 0 3px 10px;
  211. }
  212. .capture-card {
  213. background: #fff;
  214. border-radius: 8px;
  215. margin: 10px 5px;
  216. padding: 6px 8px;
  217. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  218. }
  219. .capture-row {
  220. display: flex;
  221. justify-content: center;
  222. align-items: center;
  223. margin-bottom: 4px;
  224. font-size: 13px;
  225. }
  226. .capture-row .label {
  227. color: #1e293b;
  228. min-width: 82px;
  229. font-size: 12px;
  230. font-weight: 400;
  231. }
  232. .capture-row .value {
  233. color: #1e293b;
  234. flex: 1;
  235. font-size: 13px;
  236. }
  237. .capture-row-large .value {
  238. font-size: 15px;
  239. font-weight: 600;
  240. }
  241. .capture-row-plate {
  242. width: 100%;
  243. margin-bottom: 8px;
  244. }
  245. .vehicle-plate {
  246. position: relative;
  247. display: flex;
  248. align-items: center;
  249. justify-content: center;
  250. width: 100%;
  251. padding: 10px 16px;
  252. box-sizing: border-box;
  253. background: #f5d000;
  254. border: 3px solid #fff;
  255. border-radius: 8px;
  256. box-shadow: 0 0 0 2px #fff;
  257. }
  258. .vehicle-plate-text {
  259. font-size: 24px;
  260. font-weight: 700;
  261. color: #000;
  262. letter-spacing: 1px;
  263. white-space: nowrap;
  264. }
  265. .vehicle-plate-dot {
  266. position: absolute;
  267. width: 8px;
  268. height: 8px;
  269. border-radius: 50%;
  270. background: #fff;
  271. }
  272. .vehicle-plate-dot-lt {
  273. left: 6px;
  274. top: 8px;
  275. }
  276. .vehicle-plate-dot-lb {
  277. left: 6px;
  278. bottom: 8px;
  279. }
  280. .vehicle-plate-dot-rt {
  281. right: 6px;
  282. top: 8px;
  283. }
  284. .vehicle-plate-dot-rb {
  285. right: 6px;
  286. bottom: 8px;
  287. }
  288. .capture-qrcode {
  289. text-align: center;
  290. }
  291. .capture-id {
  292. font-size: 16px;
  293. font-weight: 700;
  294. color: #1e293b;
  295. margin-bottom: 6px;
  296. word-break: break-all;
  297. padding: 0 4px;
  298. }
  299. .capture-qr-wrap {
  300. padding: 8px 0;
  301. min-height: 200px;
  302. }
  303. .capture-qr-img {
  304. width: 200px;
  305. height: 200px;
  306. display: inline-block;
  307. }
  308. .capture-desc {
  309. font-size: 11px;
  310. font-weight: 500;
  311. color: #64748b;
  312. margin-top: 4px;
  313. padding-bottom: 8px;
  314. }
  315. </style>