index.vue 9.3 KB

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