|
@@ -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 {
|