GGDemo 1 month ago
parent
commit
5d2d39f32f
4 changed files with 102 additions and 109 deletions
  1. 66 90
      src/pages/printer/printer.vue
  2. 1 1
      src/pages/weigh/weigh.vue
  3. 35 9
      src/services/printer.ts
  4. 0 9
      src/services/weigh.ts

+ 66 - 90
src/pages/printer/printer.vue

@@ -5,7 +5,7 @@
     </view>
 
     <uni-forms
-      ref="valiForm"
+      ref="valiFormRef"
       label-align="right"
       :label-width="80"
       :rules="rules"
@@ -143,11 +143,10 @@ import {
   onNavigationBarButtonTap,
 } from '@dcloudio/uni-app'
 import { checkPermission } from '@/utils'
+import { getPrinterList, printWaybillLabel, printCustomerLabel } from '@/services/printer'
+import type { Printers } from '@/types/printer'
 
-let printCustomerLabelURL = ''
-let getPrinterListURL = ''
-let printWaybillLabelURL = ''
-
+const valiFormRef = ref()
 const token = ref()
 const loading = ref(false)
 const hidePage = ref(false)
@@ -169,9 +168,8 @@ const printType = ref([
 ])
 const printerDialog = ref()
 const subLoading = ref(false)
-const printerList = ref([])
+const printerList = ref<Printers>()
 const printers = ref([] as any)
-const downloadFile = ref([])
 const sendToPeinter = ref([1])
 const selectPrinter = ref(0)
 const printLogHistory = ref([] as any)
@@ -241,9 +239,9 @@ const sendToPeinterFun = (res: any) => {
     selectPrinter.value = printers.value[0].value
   }
 }
-const printConfirm = () => {
+const printConfirm = async () => {
   subLoading.value = true
-  const url = selectType.value === 1 ? printWaybillLabelURL : printCustomerLabelURL
+  const requestFun = selectType.value === 1 ? printWaybillLabel : printCustomerLabel
   let data = {
     order_no: valiFormData.value.order_code,
     printer_code: selectPrinter.value,
@@ -257,94 +255,74 @@ const printConfirm = () => {
     data.style = 'simple'
     type = '打印客户联(简单)'
   }
-  uni.request({
-    url: url,
-    method: 'POST',
-    header: {
-      batoken: token.value,
-    },
-    data: data,
-    success: (res: any) => {
-      subLoading.value = false
-      console.log('打印成功', res)
-      messageType.value = res.data.code ? 'success' : 'error'
-      messageText.value = res.data.msg
-      messageRef.value.open()
 
-      const historyItem = {
-        order_code: valiFormData.value.order_code,
-        createTime: new Date(),
-        type: type,
-        status: res.data.code,
-      }
-      printLogHistory.value.unshift(historyItem)
-      uni.setStorageSync('printLogHistory', printLogHistory.value)
-      getHistory()
-      close()
-    },
-    fail: (err: any) => {
-      subLoading.value = false
-      console.log('打印失败', err)
-      messageType.value = 'error'
-      messageText.value = '打印失败'
-      messageRef.value.open()
-      const historyItem = {
-        order_code: valiFormData.value.order_code,
-        createTime: new Date(),
-        type: type,
-        status: false,
-      }
-      printLogHistory.value.unshift(historyItem)
-      uni.setStorageSync('printLogHistory', printLogHistory.value)
-      getHistory()
-      close()
-    },
-  })
-}
+  const res = await requestFun(data)
 
-const getPrinterList = () => {
-  uni.request({
-    url: getPrinterListURL,
-    method: 'GET',
-    header: {
-      batoken: token.value,
-    },
-    success: (res: any) => {
-      if (res.data.code === 1) {
-        printerList.value = res.data.data.printers
-        printers.value = Object.values(printerList.value).map((item: any) => {
-          return {
-            text: item.name,
-            value: item.value,
-          }
-        })
-      }
-    },
-    fail(e) {
-      console.log('fail--', e)
-    },
-  })
-}
+  if (res.code === 1) {
+    subLoading.value = false
+    console.log('打印成功', res)
+    messageType.value = res.code ? 'success' : 'error'
+    messageText.value = res.msg
+    messageRef.value.open()
 
-const onsubmit = () => {
-  if (valiFormData.value.order_code) {
-    loading.value = true
-    st && clearTimeout(st)
-    selectPrinter.value = sendToPeinter.value.length > 0 ? printers.value[0].value : 0
-    printerDialog.value.open()
-    loading.value = false
+    // const historyItem = {
+    //   order_code: valiFormData.value.order_code,
+    //   createTime: new Date(),
+    //   type: type,
+    //   status: res.data.code,
+    // }
+    // printLogHistory.value.unshift(historyItem)
+    // uni.setStorageSync('printLogHistory', printLogHistory.value)
+    // getHistory()
+    close()
   } else {
+    subLoading.value = false
     messageType.value = 'error'
-    messageText.value = '请填写运单号'
+    messageText.value = '打印失败'
     messageRef.value.open()
+    // const historyItem = {
+    //   order_code: valiFormData.value.order_code,
+    //   createTime: new Date(),
+    //   type: type,
+    //   status: false,
+    // }
+    // printLogHistory.value.unshift(historyItem)
+    // uni.setStorageSync('printLogHistory', printLogHistory.value)
+    // getHistory()
+    close()
+  }
+}
+
+const _getPrinterList = async () => {
+  const res = await getPrinterList()
+  if (res.code === 1) {
+    printerList.value = res.data.printers
+    printers.value = Object.values(printerList.value).map((item: any) => {
+      return {
+        text: item.name,
+        value: item.value,
+      }
+    })
   }
 }
 
-const getHistory = () => {
-  printLogHistory.value = uni.getStorageSync('printLogHistory') || []
+const onsubmit = async () => {
+  const valiRes: any = await valiFormRef.value.validate()
+  if (!valiRes) {
+    return
+  }
+
+  loading.value = true
+  st && clearTimeout(st)
+  selectPrinter.value = sendToPeinter.value.length > 0 ? printers.value[0].value : 0
+  printerDialog.value.open()
+  loading.value = false
 }
+
+// const getHistory = () => {
+//   printLogHistory.value = uni.getStorageSync('printLogHistory') || []
+// }
 const keypress = (e: any) => {
-  console.log(e, '按键码')
   // 102  左侧    103  右侧   104  中间按键
   if (e.keyCode === 102 || e.keyCode === 103 || e.keyCode === 104) {
     //这里按键成功
@@ -395,10 +373,9 @@ onBackPress(() => {
 })
 
 onShow(() => {
-  token.value = uni.getStorageSync('token')
   hidePage.value = false
-  getHistory()
-  getPrinterList()
+  // getHistory()
+  _getPrinterList()
 })
 
 onNavigationBarButtonTap((event) => {
@@ -435,7 +412,6 @@ onNavigationBarButtonTap((event) => {
     height: 35px;
     width: 50%;
     margin-left: 10px;
-    font-size: 16rpx;
   }
 
   .uni-icons {

+ 1 - 1
src/pages/weigh/weigh.vue

@@ -298,13 +298,13 @@ import {
   weigh,
   getWarehouseSpace,
   getBindParams,
-  getPrinterList,
   checkWaybillGoods,
   printWaybillLabel,
 } from '@/services/weigh'
 
 import { uuid } from '@/utils/random'
 import type { Printers } from '@/types/printer'
+import { getPrinterList } from '@/services/printer'
 const alertDialog = ref()
 const message = ref()
 const valiForm = ref()

+ 35 - 9
src/services/printer.ts

@@ -1,17 +1,43 @@
 import { http } from '@/utils/http'
-import type { PageParams } from '@/types/global'
-import type { HotResult } from '@/types/hot'
+import type { PrintersResult } from '@/types/printer'
 
-type HotParams = PageParams & { subType?: string }
 /**
- * 通用热门推荐类型
- * @param url 请求地址
- * @param data 请求参数
+ * 获取打印机列表
  */
-export const getHotRecommendAPI = (url: string, data?: HotParams) => {
-  return http<HotResult>({
+export const getPrinterList = () => {
+  return http<PrintersResult>({
     method: 'GET',
-    url,
+    url: '/admin/printer/getPrinterList',
+  })
+}
+
+/**
+ * 打印尾程面单
+ * @param
+ */
+export const printWaybillLabel = (data: {
+  order_no: string
+  printer_code: string
+  style: string
+}) => {
+  return http<{ is_goods_empty: boolean }>({
+    method: 'POST',
+    url: '/admin/order.ScanOrder/printWaybillLabel',
+    data,
+  })
+}
+/**
+ * 打印尾程面单
+ * @param
+ */
+export const printCustomerLabel = (data: {
+  order_no: string
+  printer_code: string
+  style: string
+}) => {
+  return http<{ is_goods_empty: boolean }>({
+    method: 'POST',
+    url: '/admin/order.ScanOrder/printCustomerLabel',
     data,
   })
 }

+ 0 - 9
src/services/weigh.ts

@@ -64,15 +64,6 @@ export const instock = (data: {
     data,
   })
 }
-/**
- * 获取打印机列表
- */
-export const getPrinterList = () => {
-  return http<PrintersResult>({
-    method: 'GET',
-    url: '/admin/printer/getPrinterList',
-  })
-}
 /**
  * 获取 扫描 托盘号、批次号
  */