scanPanel.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <script>
  2. import {dispatchList} from '@/api/pda';
  3. import {getExpressRecordParams} from '@/api/prescription/prescriptionAudit';
  4. import {sf_express_print} from '@/tools/print.tool';
  5. import dayjs from 'dayjs';
  6. let TAG;
  7. export default {
  8. name: 'ScanPanel',
  9. data() {
  10. return {
  11. loading: false,
  12. keyword: '',
  13. logs: [],
  14. };
  15. },
  16. methods: {
  17. async open() {
  18. this.nonsupport();
  19. },
  20. async close() {
  21. if (TAG) window.cancelAnimationFrame(TAG);
  22. this.logs = [];
  23. this.loading = false;
  24. },
  25. async search() {
  26. if (this.loading) return;
  27. this.loading = true;
  28. const keyword = this.keyword.trim();
  29. try {
  30. let result = await dispatchList({pageNum: 1, pageSize: 1, orderNo: keyword});
  31. if (result.code !== 200) throw {message: result.msg};
  32. let data = result.rows[0];
  33. if (!data) throw {message: `未查询到数据`};
  34. if (data.expressExecutor !== '顺丰') throw {message: `无法打印,配送方式不是顺丰`};
  35. result = await getExpressRecordParams({prescriptionCoreId: data.id});
  36. if (result.code !== 200) throw {message: result.msg};
  37. data = result.data;
  38. await sf_express_print(data);
  39. this.$message.success(`发送打印任务成功`);
  40. this.logs.push({
  41. time: dayjs().format('HH:mm:ss'),
  42. state: 'success', keyword,
  43. icon: 'el-icon-check', color: 'green',
  44. message: `发送打印任务成功`,
  45. });
  46. } catch (error) {
  47. this.$message.error(error.message);
  48. this.logs.push({
  49. time: dayjs().format('HH:mm:ss'),
  50. state: 'danger', keyword,
  51. icon: 'el-icon-close', color: 'red',
  52. message: error.message,
  53. });
  54. }
  55. this.$refs.input.focus();
  56. this.$refs.main.scrollTop = 0;
  57. this.keyword = '';
  58. this.loading = false;
  59. },
  60. nonsupport() {
  61. if (TAG) window.cancelAnimationFrame(TAG);
  62. TAG = window.requestAnimationFrame(() => {
  63. this.$refs.input.focus();
  64. this.nonsupport();
  65. });
  66. },
  67. },
  68. };
  69. </script>
  70. <template>
  71. <div class="wrapper">
  72. <div class="header">
  73. <el-input ref="input" style="width: 80%;" v-model="keyword" placeholder="请输入或使用扫码枪操作" clearable
  74. size="small" :disabled="loading"
  75. @keyup.enter.native="search"/>
  76. </div>
  77. <div class="main" ref="main">
  78. <el-timeline reverse>
  79. <el-timeline-item
  80. v-for="(log, index) in logs"
  81. :key="index"
  82. :icon="log.icon"
  83. :color="log.color"
  84. size="large" :type="log.state"
  85. :timestamp="log.time" placement="top">
  86. [{{ log.keyword }}] {{ log.message }}
  87. </el-timeline-item>
  88. </el-timeline>
  89. </div>
  90. </div>
  91. </template>
  92. <style scoped lang="scss">
  93. .wrapper {
  94. display: flex;
  95. flex-direction: column;
  96. height: 60vmin;
  97. }
  98. .header {
  99. flex: none;
  100. text-align: center;
  101. }
  102. .main {
  103. flex: auto;
  104. padding-top: 24px;
  105. overflow-y: auto;
  106. }
  107. </style>