index.vue 9.5 KB

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