|
@@ -142,6 +142,17 @@
|
|
|
</uni-popup-dialog>
|
|
|
</uni-popup>
|
|
|
</view>
|
|
|
+ <view class="popup">
|
|
|
+ <uni-popup ref="printerDialog" type="dialog">
|
|
|
+ <uni-popup-dialog type="center" cancelText="取消" confirmText="确认" title="设置打印机" @confirm="connectThenPrint" @close="cancelConfig">
|
|
|
+ <view class="printconfig">
|
|
|
+ <view style="font-size: 20rpx;">使用须知</view>
|
|
|
+ <view style="font-size: 16rpx;color:brown;margin-bottom: 20rpx;">*使用前先连接wifi打印机</view>
|
|
|
+ <uni-easyinput class="input" confirm-type="done" v-model="printInfo.ip" placeholder="请输入打印机ip地址" @confirm="connectThenPrint"></uni-easyinput>
|
|
|
+ </view>
|
|
|
+ </uni-popup-dialog>
|
|
|
+ </uni-popup>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
@@ -154,16 +165,67 @@
|
|
|
<script setup>
|
|
|
import { onMounted, ref, getCurrentInstance } from 'vue'
|
|
|
import { selectOrderDetail, upload, sendToUser, updateOrderStatus } from "@/static/js/request.js"
|
|
|
-import { saveDepoly } from '@/static/js/api.js'
|
|
|
+import { saveDepoly, setIp } from '@/static/js/api.js'
|
|
|
import debounce from 'lodash.debounce'
|
|
|
|
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
|
|
|
|
+
|
|
|
+const printInfo = ref({
|
|
|
+ ip: '',
|
|
|
+ port: '9100'
|
|
|
+})
|
|
|
+
|
|
|
const urlConfig = ref('http://zhongyao.fscuc.cn')
|
|
|
// #ifdef APP-PLUS
|
|
|
const plug= uni.requireNativePlugin('Html5app-Gprinter');
|
|
|
// #endif
|
|
|
|
|
|
+
|
|
|
+const connectThenPrint = ()=>{
|
|
|
+ const ipReg = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
|
|
|
+ if(ipReg.test(printInfo.value.ip)){
|
|
|
+ if(RegExp.$1<256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256){
|
|
|
+ plug.connectIP({"ip":printInfo.value.ip,"port":printInfo.value.port},ret=>{
|
|
|
+ console.log('connectPrint>>ret',ret)
|
|
|
+ const res = JSON.parse(JSON.stringify(ret))
|
|
|
+ console.log('connectPrint>>res',res.code)
|
|
|
+ if(res.code==3){
|
|
|
+ // initPrint.value = true
|
|
|
+ console.log('printInfo>>>', printInfo.value)
|
|
|
+ uni.setStorageSync('hasPrinter', '1')
|
|
|
+ uni.setStorageSync('printerIp', printInfo.value.ip)
|
|
|
+ // _this.tip=JSON.stringify(ret);
|
|
|
+ // console.log(_this.tip);
|
|
|
+ // 关闭配置弹窗
|
|
|
+ proxy.$refs.printerDialog.close()
|
|
|
+ printerTsc()
|
|
|
+
|
|
|
+ // // 打印成功后调用/userPrescription/sendToUser
|
|
|
+ // const res1 = sendToUser({
|
|
|
+ // token: uni.getStorageSync('token'),
|
|
|
+ // data: JSON.stringify({id:uni.getStorageSync('userId')})
|
|
|
+ // })
|
|
|
+ // console.log('sendToUser res1',res1)
|
|
|
+ // if (res1.code !== 200){
|
|
|
+ // uni.$showMsg(res1.msg, 2000)
|
|
|
+ // }
|
|
|
+
|
|
|
+ uni.redirectTo({
|
|
|
+ url:"/pages/index/index"
|
|
|
+ })
|
|
|
+
|
|
|
+ } else{
|
|
|
+ uni.$showMsg('打印机连接失败,请重试!', 500)
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ } else{
|
|
|
+ uni.$showMsg('ip地址有误,请重试!', 2000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// const preseId = ref(11220822134401)
|
|
|
const preseObj = ref({
|
|
|
code: '',
|
|
@@ -451,19 +513,14 @@ const handleBack =()=>{
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+const cancelConfig = () => {
|
|
|
+ console.log('不配置打印ip')
|
|
|
+ proxy.$refs.printerDialog.close()
|
|
|
+}
|
|
|
+
|
|
|
const handleSubmit = debounce(async()=>{
|
|
|
console.log('handleSubmit>>>',editForm.value)
|
|
|
|
|
|
- const {data:res} = await saveDepoly({
|
|
|
- token: uni.getStorageSync('token'),
|
|
|
- data: JSON.stringify(editForm.value)
|
|
|
- })
|
|
|
- if(res.code===200){
|
|
|
- console.log('depoly success>>>')
|
|
|
-
|
|
|
- } else {
|
|
|
- uni.$showMsg(res.msg, 2000)
|
|
|
- }
|
|
|
if(isPrint.value){
|
|
|
// 直接调用接口,然后打印
|
|
|
// print("#printMe")
|
|
@@ -479,26 +536,24 @@ const handleSubmit = debounce(async()=>{
|
|
|
// return
|
|
|
// }
|
|
|
|
|
|
- printerTsc()
|
|
|
- console.log("uni.getStorageSync('token')",uni.getStorageSync('token'))
|
|
|
- const res = await sendToUser({
|
|
|
- token: uni.getStorageSync('token'),
|
|
|
- data: JSON.stringify({id:uni.getStorageSync('userId')})
|
|
|
- })
|
|
|
- const ret = await updateOrderStatus({
|
|
|
- token: uni.getStorageSync('token'),
|
|
|
- data: {
|
|
|
- id:v.value.id,
|
|
|
- status:'1',
|
|
|
- }
|
|
|
- })
|
|
|
- uni.redirectTo({
|
|
|
- url:"/pages/index/index"
|
|
|
- })
|
|
|
+ // todo 判断打印机是否连接成功,hasPrinter=='1'连接成功则开始打印,否则弹窗配置打印机,配置成功打印机后关闭弹窗直接打印
|
|
|
+ if(uni.getStorageSync('hasPrinter') == '1'){
|
|
|
+ printerTsc()
|
|
|
+ console.log("uni.getStorageSync('token')",uni.getStorageSync('token'))
|
|
|
+
|
|
|
+ uni.redirectTo({
|
|
|
+ url:"/pages/index/index"
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // todo 判断打印机是否连接成功,hasPrinter空值则连接不成功,弹窗配置打印机,配置成功打印机后关闭弹窗直接打印
|
|
|
+ proxy.$refs.printerDialog.open('center')
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
} else {
|
|
|
- // 弹窗提醒
|
|
|
- console.log("handleSubmit proxy.$refs.alertDialog",proxy.$refs.alertDialog)
|
|
|
+ // todo 打印预览弹窗显示
|
|
|
+ console.log("cancelConfig proxy.$refs.alertDialog",proxy.$refs.alertDialog)
|
|
|
proxy.$refs.alertDialog.open('center')
|
|
|
}
|
|
|
|
|
@@ -514,23 +569,43 @@ const dialogConfirm = debounce(async()=>{
|
|
|
// } else {
|
|
|
// uni.$showMsg('打印失败,打印机未连接,请先连接打印机', 2000)
|
|
|
// }
|
|
|
- printerTsc()
|
|
|
-
|
|
|
- // 打印成功后调用/userPrescription/sendToUser
|
|
|
- const res = await sendToUser({
|
|
|
- token: uni.getStorageSync('token'),
|
|
|
- data: JSON.stringify({id:uni.getStorageSync('userId')})
|
|
|
- })
|
|
|
- console.log('sendToUser res',res)
|
|
|
- if (res.code !== 200){
|
|
|
- uni.$showMsg(res.msg, 2000)
|
|
|
+ if(uni.getStorageSync('hasPrinter') == '1'){
|
|
|
+ printerTsc()
|
|
|
+ console.log("uni.getStorageSync('token')",uni.getStorageSync('token'))
|
|
|
+ // const res = await sendToUser({
|
|
|
+ // token: uni.getStorageSync('token'),
|
|
|
+ // data: JSON.stringify({id:uni.getStorageSync('userId')})
|
|
|
+ // })
|
|
|
+ // const ret = await updateOrderStatus({
|
|
|
+ // token: uni.getStorageSync('token'),
|
|
|
+ // data: {
|
|
|
+ // id:v.value.id,
|
|
|
+ // status:'1',
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ uni.redirectTo({
|
|
|
+ url:"/pages/index/index"
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // todo 判断打印机是否连接成功,hasPrinter空值则连接不成功,弹窗配置打印机,配置成功打印机后关闭弹窗直接打印
|
|
|
+ proxy.$refs.alertDialog.close()
|
|
|
+ proxy.$refs.printerDialog.open('center')
|
|
|
+
|
|
|
}
|
|
|
- uni.redirectTo({
|
|
|
- url:"/pages/index/index"
|
|
|
- })
|
|
|
},500)
|
|
|
const dialogClose = debounce(async()=>{
|
|
|
console.log('dialogClose直接调用接口,不打印')
|
|
|
+ const {data:res} = saveDepoly({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: JSON.stringify(editForm.value)
|
|
|
+ })
|
|
|
+ if(res.code===200){
|
|
|
+ console.log('depoly success>>>')
|
|
|
+ }
|
|
|
+ const res1 = sendToUser({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: JSON.stringify({id:uni.getStorageSync('userId')})
|
|
|
+ })
|
|
|
const ret = await updateOrderStatus({
|
|
|
token: uni.getStorageSync('token'),
|
|
|
data: {
|
|
@@ -678,6 +753,33 @@ const printerTsc = ()=>{
|
|
|
if(ret.code==1){
|
|
|
uni.$showMsg('打印失败,打印机未连接,请先连接打印机', 2000)
|
|
|
console.log('666')
|
|
|
+ } else {
|
|
|
+ const {data:res} = saveDepoly({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: JSON.stringify(editForm.value)
|
|
|
+ })
|
|
|
+ if(res.code===200){
|
|
|
+ console.log('depoly success>>>')
|
|
|
+ }
|
|
|
+ const res1 = sendToUser({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: JSON.stringify({id:uni.getStorageSync('userId')})
|
|
|
+ })
|
|
|
+ const ret = updateOrderStatus({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: {
|
|
|
+ id:v.value.id,
|
|
|
+ status:'1',
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 保持ip和端口
|
|
|
+ const res2 = setIp({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: JSON.stringify({userId:uni.getStorageSync('userId'),ip:printInfo.value.ip,port:printInfo.value.port})
|
|
|
+ })
|
|
|
+ if (res2.code !== 200){
|
|
|
+ uni.$showMsg(res2.msg, 2000)
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
// #endif
|
|
@@ -1115,6 +1217,23 @@ const printerTsc = ()=>{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+.printconfig{
|
|
|
+ background-color: #fff;
|
|
|
+ width: 500rpx;
|
|
|
+ height: 100rpx;
|
|
|
+ padding: 20rpx;
|
|
|
+ .initPrint{
|
|
|
+ .title{
|
|
|
+ font-size: 20rpx;
|
|
|
+ }
|
|
|
+ .tips{
|
|
|
+ font-size: 16rpx;
|
|
|
+ }
|
|
|
+ .input{
|
|
|
+ width: 300rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
</style>
|