index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <uni-popup v-model="printerList!.visible">
  3. {{printerList}}
  4. <uni-popup-dialog ref="inputClose" mode="input" title="输入内容" value="对话框预置提示内容!" placeholder="请输入内容" @confirm="dialogInputConfirm">
  5. <!-- <template #default>
  6. <text class="title">
  7. {{ printerList.title }}
  8. <text class="ml-2">{{ printerList?.postData?.order_no }}</text>
  9. </text>
  10. </template> -->
  11. <!-- <view v-if="printerList">
  12. <uni-data-checkbox multiple v-model="downloadFile" :disabled="true" :localdata=" [{
  13. text: '下载文件',
  14. value: 1
  15. }]">></uni-data-checkbox>
  16. <view><el-checkbox label="下载文件" v-model="downloadFile" :disabled="true"></el-checkbox></view>
  17. <view class="ml-4">
  18. <view>
  19. <el-checkbox label="发送到标签打印机打印" v-model="sendToPeinter" @change="sendToPeinterFun"></el-checkbox>
  20. </view>
  21. <el-radio-group v-model="printer_code">
  22. <el-radio v-for="(item, i) in printerList.printers as any" :key="i" :label="item.value">{{ item.name }}</el-radio>
  23. </el-radio-group>
  24. </view>
  25. </view> -->
  26. </uni-popup-dialog>
  27. <!-- <template #footer>
  28. <div>
  29. <el-button @click="printerList.visible = false">{{ t('Cancel') }}</el-button>
  30. <el-button :loading="submitLoading" @click="toPrint()" type="primary" v-blur>
  31. {{ '打印' }}
  32. </el-button>
  33. </div>
  34. </template> -->
  35. </uni-popup>
  36. </template>
  37. <script setup lang="ts">
  38. import { inject, ref } from 'vue';
  39. import { printWaybillLabelURL } from '../../utils/api';
  40. const printerList = inject('printerList') as any;
  41. const printer_code = ref('');
  42. const submitLoading = ref(false);
  43. const downloadFile = ref(true);
  44. const sendToPeinter = ref(true);
  45. const sendToPeinterFun = () => {
  46. if (!sendToPeinter.value) {
  47. printer_code.value = '';
  48. } else {
  49. printer_code.value = Object.keys(printerList.value.printers)[0];
  50. }
  51. };
  52. const dialogInputConfirm = () => {
  53. printerList.value && (printer_code.value = Object.keys(printerList.value.printers)[0]);
  54. };
  55. const openPrinterSelect = () => {
  56. printerList.value && (printer_code.value = Object.keys(printerList.value.printers)[0]);
  57. };
  58. const toPrint = async () => {
  59. const { batoken, postData, resetForm } = printerList.value;
  60. /*
  61. const loading = ElLoading.service({
  62. lock: true,
  63. text: 'Loading',
  64. background: 'rgba(0, 0, 0, 0.7)',
  65. })
  66. */
  67. submitLoading.value = true;
  68. uni.request({
  69. url: printWaybillLabelURL,
  70. method: 'POST',
  71. header: {
  72. batoken: batoken
  73. },
  74. data: {
  75. ...postData,
  76. printer_code: printer_code.value
  77. },
  78. success: (res) => {
  79. console.log(res);
  80. }
  81. });
  82. /*
  83. await postPrint({
  84. ...postData,
  85. printer_code: printer_code.value
  86. })
  87. .then((res: any) => {
  88. //loading.close()
  89. const list = res.data?.label_path || res.data?.labels || (res.data?.express_label ? [res.data?.express_label] : []);
  90. if (list.length === 0) {
  91. // ElMessage.error('没有可打印的文件');
  92. return;
  93. }
  94. list.map((url: string) => {
  95. let path = fullUrl(url);
  96. window.open(path, '_blank');
  97. });
  98. submitLoading.value = false;
  99. printerList.value.visible = false;
  100. resetForm();
  101. })
  102. .catch((error: any) => {
  103. console.log('error--', error);
  104. //loading.close()
  105. submitLoading.value = false;
  106. });
  107. */
  108. };
  109. </script>
  110. <script lang="ts">
  111. import { defineComponent } from 'vue'
  112. export default defineComponent({
  113. name: 'printer-list-scan',
  114. })
  115. </script>
  116. <style scoped lang="scss"></style>