db-pound-qrcode-popup.vue 7.0 KB

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