index.vue 9.7 KB

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