Printer.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <van-dialog v-model:show="printTrueFalseBy"
  3. title="打印机列表"
  4. :show-confirm-button="false"
  5. close-on-click-overlay
  6. >
  7. <div style="width:100%;max-height:65vh;overflow:auto">
  8. <van-radio-group v-model="print">
  9. <van-cell-group inset>
  10. <van-cell v-for="(item,i) in printList" :title="item.printer" clickable @click="onPrinter(item)" >
  11. <template #right-icon>
  12. <van-radio :name="item.server" />
  13. </template>
  14. </van-cell>
  15. </van-cell-group>
  16. </van-radio-group>
  17. </div>
  18. </van-dialog>
  19. </template>
  20. <script setup>
  21. import { ref } from 'vue'
  22. import { getPrinter } from '@/api/basic/index'
  23. import { closeLoading, showLoading } from '@/utils/loading'
  24. const printTrueFalseBy=ref(false)
  25. const print=ref('')
  26. const printList=ref([])
  27. const show=(code)=>{
  28. print.value=''
  29. if(localStorage.getItem('PRINTER:KEY')){
  30. const list=JSON.parse(localStorage.getItem('PRINTER:KEY'))
  31. printList.value=list.filter(item=>item.warehouseCode===code && item.enable===true)
  32. printTrueFalseBy.value=true
  33. return
  34. }
  35. showLoading()
  36. getPrinter().then(res => {
  37. printList.value=res.data.filter(item=>item.warehouseCode===code)
  38. localStorage.setItem('PRINTER:KEY',JSON.stringify(res.data))
  39. printTrueFalseBy.value=true
  40. }).finally(() => {
  41. closeLoading()
  42. })
  43. }
  44. const emit = defineEmits()
  45. const onPrinter=(item)=>{
  46. print.value = item.server
  47. printTrueFalseBy.value=false
  48. emit('onPrint', item)
  49. }
  50. defineExpose({show})
  51. </script>
  52. <style scoped lang="sass">
  53. </style>