index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="nav" :style="{ paddingTop: statusBarHeight + 'px' }">
  3. <text class="nav-back" :style="{ top: statusBarHeight + 'px' }" @click="onBack"></text>
  4. <text class="nav-title">药品追溯码查询</text>
  5. </view>
  6. <view class="page" :style="{
  7. marginTop: statusBarHeight + 44 + 'px',
  8. height: pageHeight + 'px',
  9. }">
  10. <view class="scan-tip" @click="handleScanTipClick">
  11. <uni-icons type="help" size="18" color="#2c69ff"></uni-icons>
  12. <text :style="{ marginLeft: '5rpx', paddingBottom: '5rpx' }">可扫码生产企业及药品</text>
  13. </view>
  14. <view class="scan-card" @click="handleScan">
  15. <image src="../../static/images/camera.png" mode="scaleToFill" class="scan-icon" />
  16. <text class="scan-text">扫码查询</text>
  17. </view>
  18. <text class="hint">请扫描药品最小销售包装上的追溯码</text>
  19. <view class="input-wrap">
  20. <input class="input" v-model="traceCode" maxlength="23" @input="onTraceInput" placeholder="请输入 20 位药品追溯码" />
  21. </view>
  22. <view class="count">已输入 {{ traceCode.replace(/\s+/g, "").length }}/20 位</view>
  23. <button class="query-btn" :class="{ disabled: !canQuery }" @click="onQuery">
  24. 查询
  25. </button>
  26. <text class="tip">若扫码失败,可手动输入追溯码查询</text>
  27. <view class="section-title">扫码历史</view>
  28. <scroll-view class="history-list" v-if="history.length != 0 && !loading" :scroll-y="history.length > 4"
  29. @scrolltolower="onHistoryScrollToLower">
  30. <view class="history-item" v-for="item in history" :key="item.code" @click="onTapHistory(item)">
  31. <view class="history-left">
  32. <view class="history-title">{{ item.physicName }}</view>
  33. <view class="history-sub">追溯码:{{ item.tracCode }}</view>
  34. </view>
  35. <text class="arrow">›</text>
  36. </view>
  37. <view class="loading-row" v-if="history.length < totalCount">
  38. <view class="loading-wrapper">
  39. <image class="loading-icon" :src="loadingImg" />
  40. </view>
  41. </view>
  42. </scroll-view>
  43. <Empty text="暂无扫码历史" v-else-if="!loading" />
  44. <view class="loading-view" v-else="loading">
  45. <image class="loading-icon" src="../../static/images/loading.png" mode="scaleToFill"
  46. :style="{ width: '66rpx', height: '50rpx' }" />
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import loadingImg from "../../static/images/loading.png";
  52. import Empty from "../../wigets/empty.vue";
  53. import request from '../../request/index.js'
  54. export default {
  55. components: {
  56. Empty,
  57. },
  58. data() {
  59. return {
  60. statusBarHeight: 20,
  61. pageHeight: 0,
  62. traceCode: "",
  63. history: [],
  64. totalCount: 20,
  65. pageNum: 1,
  66. pageSize: 7,
  67. loading: true,
  68. isLoading: false,
  69. };
  70. },
  71. onLoad() {
  72. const info = uni.getSystemInfoSync();
  73. this.statusBarHeight = info.statusBarHeight || 20;
  74. const navH = 44 + this.statusBarHeight;
  75. const winH =
  76. info.windowHeight ||
  77. (info.screenHeight ? info.screenHeight - this.statusBarHeight : 0);
  78. if (winH) {
  79. this.pageHeight = Math.max(0, winH - navH);
  80. }
  81. this.getHistoryData();
  82. },
  83. computed: {
  84. canQuery() {
  85. return this.traceCode.replace(/\s+/g, "").length === 20;
  86. },
  87. },
  88. methods: {
  89. onBack() {
  90. try {
  91. uni.navigateBack();
  92. } catch (e) { }
  93. },
  94. handleScanTipClick() {
  95. uni.navigateTo({
  96. url: "/traceCodePackages/traceabilityCodeQuery/pages/scanRange/index",
  97. });
  98. },
  99. formatTraceCode(code) {
  100. const raw = code.replace(/\s+/g, "").slice(0, 20);
  101. const parts = raw.match(/.{1,5}/g) || [];
  102. return parts.join(" ");
  103. },
  104. onTraceInput(e) {
  105. const val = (e && e.detail && e.detail.value) || "";
  106. this.traceCode = this.formatTraceCode(val);
  107. },
  108. getHistoryData() {
  109. request('/bills/getScanHistory', {
  110. pageNum: this.pageNum,
  111. pageSize: this.pageSize,
  112. path: '/traceabilityCodeQuery/pages/index.vue',
  113. }).then(res => {
  114. if (res.code == 200) {
  115. const { total, list } = res.data || {};
  116. this.totalCount = total || 0;
  117. this.history = Array.isArray(list)
  118. ? [...this.history, ...list]
  119. : [...this.history];
  120. }
  121. this.isLoading = false;
  122. this.loading = false;
  123. })
  124. },
  125. handleScan() {
  126. uni.scanCode({
  127. onlyFromCamera: false,
  128. success: (res) => {
  129. if (!res.result) {
  130. console.log("scanCode fail", res);
  131. uni.showToast({
  132. title: "扫码失败,请重试",
  133. icon: "none",
  134. duration: 2000,
  135. });
  136. return;
  137. }
  138. this.traceCode = this.formatTraceCode(res.result || "");
  139. if (res.result.length !== 20) {
  140. uni.showToast({
  141. title: "追溯码通常为20位,请尝试重新扫描完整的条形码",
  142. icon: "none",
  143. duration: 2000,
  144. });
  145. } else {
  146. uni.showToast({
  147. title: "扫码成功,点击查询查看详情",
  148. icon: "none",
  149. duration: 2000,
  150. });
  151. }
  152. },
  153. fail: (err) => {
  154. if (err.errMsg.includes("scanCode:fail cancel")) {
  155. console.log("用户取消了扫码");
  156. console.log("scan fail", err);
  157. } else {
  158. uni.showToast({
  159. title: "扫码失败,请重试",
  160. icon: "none",
  161. duration: 2000,
  162. }); // 这里可以看到具体失败原因
  163. }
  164. },
  165. });
  166. },
  167. onQuery() {
  168. if (!this.canQuery) return;
  169. this.onTapHistory({ tracCode: this.traceCode.replace(/\s+/g, "") });
  170. },
  171. onHistoryScrollToLower() {
  172. if (this.isLoading) return;
  173. if (this.history.length >= this.totalCount) return;
  174. this.isLoading = true;
  175. this.pageNum++;
  176. this.getHistoryData();
  177. },
  178. onTapHistory(item) {
  179. uni.navigateTo({
  180. url:
  181. "/traceCodePackages/traceabilityCodeQuery/pages/detail/index" +
  182. (item ? "?traceCode=" + item.tracCode : ""),
  183. });
  184. },
  185. },
  186. };
  187. </script>
  188. <style>
  189. .scan-tip {
  190. margin-top: -40rpx;
  191. color: #2c69ff;
  192. font-size: 24rpx;
  193. width: 100%;
  194. text-align: right;
  195. padding-bottom: 40rpx;
  196. display: flex;
  197. justify-content: flex-end;
  198. align-items: center;
  199. }
  200. .nav {
  201. position: fixed;
  202. top: 0;
  203. left: 0;
  204. right: 0;
  205. height: 44px;
  206. background-color: #2c69ff;
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. }
  211. .nav-back {
  212. position: absolute;
  213. left: 40rpx;
  214. top: 12rpx;
  215. width: 20rpx;
  216. height: 20rpx;
  217. color: #fff;
  218. border-left: 3rpx solid #fff;
  219. border-bottom: 3rpx solid #fff;
  220. transform: rotate(45deg) translateY(49rpx);
  221. margin-left: 34rpx;
  222. }
  223. .nav-title {
  224. font-size: 36rpx;
  225. color: #fff;
  226. font-weight: 700;
  227. }
  228. .page {
  229. box-sizing: border-box;
  230. display: flex;
  231. flex-direction: column;
  232. align-items: center;
  233. padding: 55rpx;
  234. padding-bottom: calc(55rpx + env(safe-area-inset-bottom));
  235. background-color: rgb(243, 246, 249);
  236. overflow-y: auto;
  237. }
  238. .scan-card {
  239. flex-shrink: 0;
  240. width: 320rpx;
  241. height: 320rpx;
  242. background-color: #fff;
  243. border-radius: 20rpx;
  244. box-shadow: 0 1rpx 16rpx rgba(0, 0, 0, 0.1);
  245. display: flex;
  246. flex-direction: column;
  247. align-items: center;
  248. justify-content: center;
  249. }
  250. .scan-icon {
  251. width: 100rpx;
  252. height: 100rpx;
  253. margin-bottom: 16rpx;
  254. }
  255. .scan-text {
  256. font-size: 32rpx;
  257. color: #2c69ff;
  258. font-weight: 1000;
  259. }
  260. .hint {
  261. margin-top: 35rpx;
  262. color: #727a86;
  263. font-size: 24rpx;
  264. width: 100%;
  265. text-align: center;
  266. border-bottom: 1rpx dashed #727a8663;
  267. padding-bottom: 40rpx;
  268. }
  269. .input-wrap {
  270. width: 640rpx;
  271. margin-top: 40rpx;
  272. }
  273. .input {
  274. box-sizing: border-box;
  275. width: 100%;
  276. height: 80rpx;
  277. border: 2rpx solid #2c69ff;
  278. border-radius: 12rpx;
  279. padding: 0 20rpx;
  280. font-size: 28rpx;
  281. }
  282. .count {
  283. width: 640rpx;
  284. text-align: right;
  285. color: #99a1ad;
  286. font-size: 22rpx;
  287. margin-top: 8rpx;
  288. }
  289. .query-btn {
  290. flex-shrink: 0;
  291. width: 640rpx;
  292. height: 80rpx;
  293. line-height: 80rpx;
  294. text-align: center;
  295. margin-top: 40rpx;
  296. background-color: #2c69ff;
  297. color: #fff;
  298. font-size: 30rpx;
  299. }
  300. .query-btn.disabled {
  301. background-color: rgb(192, 210, 224);
  302. color: #fff;
  303. }
  304. .tip {
  305. margin-top: 12rpx;
  306. color: #99a1ad;
  307. font-size: 22rpx;
  308. }
  309. .section-title {
  310. width: 640rpx;
  311. margin-top: 30rpx;
  312. font-size: 28rpx;
  313. color: #000;
  314. font-weight: 1000;
  315. }
  316. .history-list {
  317. width: 640rpx;
  318. height: 600rpx;
  319. }
  320. .history-item {
  321. background-color: #fff;
  322. border-radius: 16rpx;
  323. padding: 24rpx;
  324. margin-top: 16rpx;
  325. display: flex;
  326. align-items: center;
  327. justify-content: space-between;
  328. }
  329. .history-title {
  330. font-size: 28rpx;
  331. color: #2c69ff;
  332. }
  333. .history-sub {
  334. margin-top: 6rpx;
  335. font-size: 24rpx;
  336. color: #727a86;
  337. }
  338. .arrow {
  339. font-size: 40rpx;
  340. color: #cbd3e6;
  341. }
  342. .loading-row {
  343. justify-content: center;
  344. }
  345. .loading-wrapper {
  346. width: 100%;
  347. height: 76rpx;
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. }
  352. .loading-icon {
  353. width: 40rpx;
  354. height: 40rpx;
  355. animation: spin 1s linear infinite;
  356. }
  357. @keyframes spin {
  358. from {
  359. transform: rotate(0deg);
  360. }
  361. to {
  362. transform: rotate(360deg);
  363. }
  364. }
  365. .loading-view {
  366. margin-top: 20rpx;
  367. display: flex;
  368. flex-direction: column;
  369. align-items: center;
  370. justify-content: space-around;
  371. }
  372. </style>