index.vue 10 KB

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