index.vue 9.8 KB

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