index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. this.onTapHistory({ tracCode: res.result });
  154. }
  155. },
  156. fail: (err) => {
  157. if (err.errMsg.includes("scanCode:fail cancel")) {
  158. console.log("用户取消了扫码");
  159. console.log("scan fail", err);
  160. } else {
  161. uni.showToast({
  162. title: "扫码失败,请重试",
  163. icon: "none",
  164. duration: 2000,
  165. }); // 这里可以看到具体失败原因
  166. }
  167. },
  168. });
  169. },
  170. onQuery() {
  171. if (!this.canQuery) return;
  172. this.onTapHistory({ tracCode: this.traceCode.replace(/\s+/g, "") });
  173. },
  174. onHistoryScrollToLower() {
  175. if (this.isLoading) return;
  176. if (this.history.length >= this.totalCount) return;
  177. this.isLoading = true;
  178. this.pageNum++;
  179. this.getHistoryData();
  180. },
  181. onTapHistory(item) {
  182. uni.navigateTo({
  183. url:
  184. "/traceCodePackages/traceabilityCodeQuery/pages/detail/index" +
  185. (item ? "?traceCode=" + item.tracCode : ""),
  186. });
  187. },
  188. },
  189. };
  190. </script>
  191. <style>
  192. .scan-tip {
  193. margin-top: -40rpx;
  194. color: #2c69ff;
  195. font-size: 24rpx;
  196. width: 100%;
  197. text-align: right;
  198. padding-bottom: 40rpx;
  199. display: flex;
  200. justify-content: flex-end;
  201. align-items: center;
  202. }
  203. .nav {
  204. position: fixed;
  205. top: 0;
  206. left: 0;
  207. right: 0;
  208. height: 44px;
  209. background-color: #2c69ff;
  210. display: flex;
  211. align-items: center;
  212. justify-content: center;
  213. }
  214. .nav-back {
  215. position: absolute;
  216. left: 40rpx;
  217. top: 12rpx;
  218. width: 20rpx;
  219. height: 20rpx;
  220. color: #fff;
  221. border-left: 3rpx solid #fff;
  222. border-bottom: 3rpx solid #fff;
  223. transform: rotate(45deg) translateY(49rpx);
  224. margin-left: 34rpx;
  225. }
  226. .nav-title {
  227. font-size: 36rpx;
  228. color: #fff;
  229. font-weight: 700;
  230. }
  231. .page {
  232. box-sizing: border-box;
  233. display: flex;
  234. flex-direction: column;
  235. align-items: center;
  236. padding: 55rpx;
  237. padding-bottom: calc(55rpx + env(safe-area-inset-bottom));
  238. background-color: rgb(243, 246, 249);
  239. overflow-y: auto;
  240. }
  241. .scan-card {
  242. flex-shrink: 0;
  243. width: 320rpx;
  244. height: 320rpx;
  245. background-color: #fff;
  246. border-radius: 20rpx;
  247. box-shadow: 0 1rpx 16rpx rgba(0, 0, 0, 0.1);
  248. display: flex;
  249. flex-direction: column;
  250. align-items: center;
  251. justify-content: center;
  252. }
  253. .scan-icon {
  254. width: 100rpx;
  255. height: 100rpx;
  256. margin-bottom: 16rpx;
  257. }
  258. .scan-text {
  259. font-size: 32rpx;
  260. color: #2c69ff;
  261. font-weight: 1000;
  262. }
  263. .hint {
  264. margin-top: 35rpx;
  265. color: #727a86;
  266. font-size: 24rpx;
  267. width: 100%;
  268. text-align: center;
  269. border-bottom: 1rpx dashed #727a8663;
  270. padding-bottom: 40rpx;
  271. }
  272. .input-wrap {
  273. width: 640rpx;
  274. margin-top: 40rpx;
  275. }
  276. .input {
  277. box-sizing: border-box;
  278. width: 100%;
  279. height: 80rpx;
  280. border: 2rpx solid #2c69ff;
  281. border-radius: 12rpx;
  282. padding: 0 20rpx;
  283. font-size: 28rpx;
  284. }
  285. .count {
  286. width: 640rpx;
  287. text-align: right;
  288. color: #99a1ad;
  289. font-size: 22rpx;
  290. margin-top: 8rpx;
  291. }
  292. .query-btn {
  293. flex-shrink: 0;
  294. width: 640rpx;
  295. height: 80rpx;
  296. line-height: 80rpx;
  297. text-align: center;
  298. margin-top: 40rpx;
  299. background-color: #2c69ff;
  300. color: #fff;
  301. font-size: 30rpx;
  302. }
  303. .query-btn.disabled {
  304. background-color: rgb(192, 210, 224);
  305. color: #fff;
  306. }
  307. .tip {
  308. margin-top: 12rpx;
  309. color: #99a1ad;
  310. font-size: 22rpx;
  311. }
  312. .section-title {
  313. width: 640rpx;
  314. margin-top: 30rpx;
  315. font-size: 28rpx;
  316. color: #000;
  317. font-weight: 1000;
  318. }
  319. .history-list {
  320. width: 640rpx;
  321. height: 600rpx;
  322. }
  323. .history-item {
  324. background-color: #fff;
  325. border-radius: 16rpx;
  326. padding: 24rpx;
  327. margin-top: 16rpx;
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. }
  332. .history-title {
  333. font-size: 28rpx;
  334. color: #2c69ff;
  335. }
  336. .history-sub {
  337. margin-top: 6rpx;
  338. font-size: 24rpx;
  339. color: #727a86;
  340. }
  341. .arrow {
  342. font-size: 40rpx;
  343. color: #cbd3e6;
  344. }
  345. .loading-row {
  346. justify-content: center;
  347. }
  348. .loading-wrapper {
  349. width: 100%;
  350. height: 76rpx;
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. }
  355. .loading-icon {
  356. width: 40rpx;
  357. height: 40rpx;
  358. animation: spin 1s linear infinite;
  359. }
  360. @keyframes spin {
  361. from {
  362. transform: rotate(0deg);
  363. }
  364. to {
  365. transform: rotate(360deg);
  366. }
  367. }
  368. .loading-view {
  369. margin-top: 20rpx;
  370. display: flex;
  371. flex-direction: column;
  372. align-items: center;
  373. justify-content: space-around;
  374. }
  375. </style>