소스 검색

出库打印

wangchao 3 년 전
부모
커밋
8e599ea76a
5개의 변경된 파일952개의 추가작업 그리고 50개의 파일을 삭제
  1. 12 0
      pages.json
  2. 112 50
      pages/erp/exWarehousing/exWarehousing.vue
  3. 5 0
      pages/erp/index.vue
  4. 375 0
      pages/erpbusiness/exbleConnect.vue
  5. 448 0
      pages/erpbusiness/exsendCommand.vue

+ 12 - 0
pages.json

@@ -438,12 +438,24 @@
 				"navigationBarTitleText": "质检打印小票"
 			}
 		},
+		{
+			"path": "pages/erpbusiness/exbleConnect",
+			"style": {
+				"navigationBarTitleText": "出库打印小票"
+			}
+		},
 		{
 			"path": "pages/erpbusiness/jjbleConnect",
 			"style": {
 				"navigationBarTitleText": "检斤打印小票"
 			}
 		},
+		{
+			"path": "pages/erpbusiness/exbleConnect",
+			"style": {
+				"navigationBarTitleText": "出库打印小票"
+			}
+		},
 		{
 			"path": "pages/erpbusiness/sendCommand",
 			"style": {

+ 112 - 50
pages/erp/exWarehousing/exWarehousing.vue

@@ -41,7 +41,8 @@
 			</view>
 			<view class="row row-bottom">
 				<view class="left">皮重(吨)</view>
-				<input type="digit" @input='calculate' v-model='detailData.tare' class="right-bottom" placeholder="输入皮重"></input>
+				<input type="digit" @input='calculate' v-model='detailData.tare' class="right-bottom"
+					placeholder="输入皮重"></input>
 			</view>
 			<view class="row row-bottom">
 				<view class="left">净重(吨)</view>
@@ -109,8 +110,10 @@
 				<input v-model='detailData.carNo' class="right-bottom" placeholder="请输入车牌号" v-if="!showCar"></input>
 				<!-- <view @click='slectCarNo' v-if="isPC">{{detailData.carNo}}</view> -->
 				<!-- 自运合同车牌号需下拉 -->
-				<view v-if="!carno" v-show="showCar" @click="carno = true">{{detailData.carNo?detailData.carNo :"请选择车牌号"}}</view>
-				<u-picker :range="carList" range-key="carNo" @confirm='carPicker($event)' v-model="carno" mode="selector">
+				<view v-if="!carno" v-show="showCar" @click="carno = true">
+					{{detailData.carNo?detailData.carNo :"请选择车牌号"}}</view>
+				<u-picker :range="carList" range-key="carNo" @confirm='carPicker($event)' v-model="carno"
+					mode="selector">
 				</u-picker>
 			</view>
 			<view class="row row-bottom" v-if="detailData.outType=='火运'">
@@ -121,20 +124,18 @@
 				class="row row-bottom">
 				<view class="left">箱号</view>
 				<input v-model='detailData.boxNo' class="right-bottom" placeholder="请输入箱号" type="digit"></input>
-				<input v-model='detailData.boxNoOther' class="right-bottom" type="digit"
-					placeholder="请输入箱号"></input>
+				<input v-model='detailData.boxNoOther' class="right-bottom" type="digit" placeholder="请输入箱号"></input>
 			</view>
-			<view v-if='!detailData.outType||detailData.outType=="汽运" || detailData.outType=="集装箱船"' class="row row-bottom">
+			<view v-if='!detailData.outType||detailData.outType=="汽运" || detailData.outType=="集装箱船"'
+				class="row row-bottom">
 				<view class="left">封号</view>
-				<input v-model='detailData.titleNo' class="right-bottom"
-					placeholder="请输入封号" type="digit"></input>
-				<input v-model='detailData.titleNoOther' class="right-bottom"
-					placeholder="请输入封号" type="digit"></input>
+				<input v-model='detailData.titleNo' class="right-bottom" placeholder="请输入封号" type="digit"></input>
+				<input v-model='detailData.titleNoOther' class="right-bottom" placeholder="请输入封号" type="digit"></input>
 			</view>
 			<view v-if='detailData.outType=="火运"' class="row row-bottom">
 				<view class="left">车厢号</view>
-				<input v-model='detailData.wingNumber' @input="toUpperCase2" class="right-bottom"
-					placeholder="请输入车厢号" type="digit"></input>
+				<input v-model='detailData.wingNumber' @input="toUpperCase2" class="right-bottom" placeholder="请输入车厢号"
+					type="digit"></input>
 				<input v-model='detailData.wingNumberOther' @input="toUpperCase3" class="right-bottom"
 					placeholder="请输入车厢号" type="digit"></input>
 			</view>
@@ -198,6 +199,12 @@
 			<u-button type="primary" class="submit" hover-class="none" @click="submit(1)">暂存</u-button>
 			<u-button type="primary" class="submit" hover-class="none" @click="submit(2)">提交</u-button>
 		</view>
+		<u-popup v-model="isShowPrint" class="popup" @close="close" mode="bottom" border-radius="30" :closeable="true">
+			<view class="buns_item">
+				<view class="but_css" @click="print">打印小票</view>
+				<view class="but_css" @click="close">返回</view>
+			</view>
+		</u-popup>
 	</view>
 </template>
 <script>
@@ -212,6 +219,8 @@
 		},
 		data() {
 			return {
+				weightbills: {},
+				isShowPrint: false,
 				show: false,
 				show1: false,
 				show2: false,
@@ -222,7 +231,7 @@
 				show7: false,
 				isPC: true,
 				show8: false,
-				carno:false,
+				carno: false,
 				usestart: '',
 				multiSelector: [{
 						name: '汽运',
@@ -312,8 +321,8 @@
 				netWeight: "",
 				inOutShow: false,
 				inOutNoList: [],
-				carList:[],//车牌号下拉
-				showCar:false,
+				carList: [], //车牌号下拉
+				showCar: false,
 			}
 		},
 		computed: {
@@ -333,7 +342,7 @@
 			this.binNumber = helper.erpWarehouse.binNumber
 			this.warehouseName = helper.erpWarehouse.warehouseName
 			this.detailData.goodsName = _data.goodsName;
-			this.detailData.inOutType = _data.inOutType;
+			this.detailData.inOutType = _data.inOutType ? _data.inOutType : '';
 			if (this.detailData.inOutType == '销售出库') {
 				this.detailData.inOutTypeKey = 1
 			} else if (this.detailData.inOutType == '移库出库') {
@@ -348,7 +357,7 @@
 			// if (_data.contractNo) {
 			// 	this.detailData.contractNo = _data.contractNo;
 			// }
-			this.detailData.goodsNameKey = _data.goodsNameKey;
+			this.detailData.goodsNameKey = _data.goodsNameKey ? _data.goodsNameKey : '';
 			if (!_data.tranCarInfoList) {
 				this.isPC = false
 				_data.tranCarInfoList = []
@@ -390,14 +399,24 @@
 			this.handler()
 		},
 		methods: {
+			print() {
+				uni.navigateTo({
+					url: '/pages/erpbusiness/exbleConnect'
+				})
+			},
+			close() {
+				this.isShowPrint = false
+				uni.navigateBack({})
+			},
 			inOutNo() {
 				this.$api.doRequest('get', '/inOutWarehouseTask/selectInOutWarehouseNo', {
 					flag: 1,
-					warehouseName:this.warehouseName,
-					agentKey : this.userInfo.id
+					warehouseName: this.warehouseName,
+					agentKey: this.userInfo.id
 				}).then(res => {
 					this.inOutNoList = res.data.data
-					this.detailData.inOutTaskNo = this.inOutNoList[0].inOutTaskNo
+					this.detailData.inOutTaskNo = this.inOutNoList[0].inOutTaskNo ? this.inOutNoList[0]
+						.inOutTaskNo : ''
 					this.detailData.agent = this.inOutNoList[0].agent
 					if (this.inOutNoList[0].contractNo) {
 						this.detailData.contractNo = this.inOutNoList[0].contractNo
@@ -413,21 +432,21 @@
 						compId: helper.erpWarehouse.compId,
 					}).then(res => {
 						if (res.data.code == 200) {
-							for(let i = 0 ; i < res.data.data.length ; i++){
-								 // "MYCGYMHLJ2021102401"
-								if(res.data.data[i].contractNo == this.detailData.contractNo){//如果查到该合同
-								if(res.data.data[i].deliverType == '1'){//判断自运1,他运2合同
-									this.showCar = true
-								}else{
-									this.showCar = false
-								}
-								if(res.data.data[i].tranCarInfoList){
-									this.carList = res.data.data[i].tranCarInfoList   //车牌号下拉列表
+							for (let i = 0; i < res.data.data.length; i++) {
+								// "MYCGYMHLJ2021102401"
+								if (res.data.data[i].contractNo == this.detailData.contractNo) { //如果查到该合同
+									if (res.data.data[i].deliverType == '1') { //判断自运1,他运2合同
+										this.showCar = true
+									} else {
+										this.showCar = false
+									}
+									if (res.data.data[i].tranCarInfoList) {
+										this.carList = res.data.data[i].tranCarInfoList //车牌号下拉列表
+									}
 								}
-							 }
-						  }
+						 }
 						}
-					})	
+					})
 				})
 				// this.$api.doRequest('get', 'warehouseBaseInfo/selectContractNoList', ).then(res => {
 				// 	this.contractNoList = res.data.data
@@ -453,16 +472,21 @@
 				this.detailData.goodsName = this.inOutNoList[e[0]].goodsName
 				this.detailData.grade = this.inOutNoList[e[0]].grade
 				this.detailData.inOutType = this.inOutNoList[e[0]].inOutType
+				this.weightbills.goodsName = this.inOutNoList[e[0]].goodsName
 				if (this.detailData.inOutType == '销售出库') {
-					if(this.detailData.tips = '买方' + this.contractNoList[e[0]].buyer){
-						this.detailData.tips = '买方' + this.contractNoList[e[0]].buyer+
-						'( ' +
-						this.contractNoList[e[0]].unitContractPrice +
-						'元/吨)'
-					}else{
+					this.weightbills.buyer = this.inOutNoList[e[0]].buyer
+					this.weightbills.seller = uni.getStorageSync('compName')
+					if (this.detailData.tips = '买方' + this.contractNoList[e[0]].buyer) {
+						this.detailData.tips = '买方' + this.contractNoList[e[0]].buyer +
+							'( ' +
+							this.contractNoList[e[0]].unitContractPrice +
+							'元/吨)'
+					} else {
 						this.detailData.tips = '买方' + this.contractNoList[e[0]].buyer
 					}
 				} else if (this.detailData.inOutType == '移库出库') {
+					this.weightbills.buyer = this.inOutNoList[e[0]].receiveWarehouse
+					this.weightbills.seller = uni.getStorageSync('compName')
 					this.detailData.tips = '入货库' + this.inOutNoList[e[0]].warehouseName
 				}
 			},
@@ -571,7 +595,7 @@
 			carPicker(e) {
 				// this.detailData.gradeKey = e[0] + 1
 				this.detailData.carNo = this.carList[e].carNo
-				this.detailData.carId=this.carList[e].id
+				this.detailData.carId = this.carList[e].id
 			},
 			onProgress(e) {},
 			onRemove() {
@@ -698,14 +722,17 @@
 					this.$api.msg('出库类型不能为空')
 					return
 				}
-				if (!this.detailData.carNo && num == 2) {
-					this.$api.msg('车牌号不能为空')
-					return
-				}
-				if (this.detailData.carNo.length != 7) {
-					this.$api.msg('车牌号输入有误!')
-					return
+				if(this.detailData.outType=="集装箱船"||this.detailData.outType=="汽运"){
+					if (!this.detailData.carNo && num == 2) {
+						this.$api.msg('车牌号不能为空')
+						return
+					}
+					if (this.detailData.carNo.length != 7) {
+						this.$api.msg('车牌号输入有误!')
+						return
+					}
 				}
+				
 				if (!this.detailData.addressUrl && num == 2) {
 					this.$api.msg('请上传磅单')
 					return
@@ -842,10 +869,30 @@
 								that.detailData).then(res => {
 								console.log(res, "报异常")
 								if (res.data.code == 200) {
+									that.weightbills.carNo = that.detailData.carNo
+									that.weightbills.boxNo = that.detailData.boxNo
+									that.weightbills.boxNoOther = that.detailData.boxNoOther
+									that.weightbills.wingNumber = that.detailData.wingNumber
+									that.weightbills.wingNumberOther = that.detailData.wingNumberOther
+									that.weightbills.shipName = that.detailData.shipName
+									that.weightbills.shipNumber = that.detailData.shipNumber
+									that.weightbills.type = that.detailData.type
+									that.weightbills.grossWeight = that.detailData.grossWeight
+									that.weightbills.tare = that.detailData.tare
+									that.weightbills.netWeight = that.detailData.netWeight
+									that.weightbills.outType = that.detailData.outType
+									that.weightbills.backOffice = that.detailData.outType
+									var date = new Date()
+									that.weightbills.updateDate = date.getFullYear() + '-' + (date
+											.getMonth() + 1) + '-' + date.getDate() + ' ' + date
+									.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds()
+									
 									that.$api.msg(title)
-									setTimeout(() => {
-										uni.navigateBack()
-									}, 1000)
+									that.isShowPrint = true
+									uni.setStorageSync("exWarehousing_print", that.weightbills)
+									// setTimeout(() => {
+									// 	uni.navigateBack()
+									// }, 1000)
 								} else {
 									that.$api.msg(res.data.message)
 								}
@@ -964,4 +1011,19 @@
 		display: flex;
 		z-index: 9999;
 	}
+
+	.buns_item {
+		display: flex;
+		padding: 80rpx 0 50rpx 0;
+		justify-content: space-around;
+	}
+
+	.but_css {
+		background: #22C572;
+		width: 40%;
+		padding: 20rpx;
+		color: #fff;
+		text-align: center;
+		border-radius: 20rpx;
+	}
 </style>

+ 5 - 0
pages/erp/index.vue

@@ -215,6 +215,10 @@
 			...mapState(['hasLogin', 'userInfo']),
 		},
 		onShow() {
+			uni.showLoading({
+				title:"加载中...",
+				mask:true
+			})
 			this.$api.doRequest('get', '/commonUser/api/checkSession').then(res => {
 				if (res.data.data == "INVALID") {
 					this.isShowAlert1 = true;
@@ -358,6 +362,7 @@
 						this.allWarehouse = res.data.data
 						this.warehouseList = res.data.data
 						this.isShowBtn = true
+						uni.hideLoading()
 						if (_showData) {
 							this.warehouseName = _showData.warehouseName
 							this.compId = _showData.compId

+ 375 - 0
pages/erpbusiness/exbleConnect.vue

@@ -0,0 +1,375 @@
+<template>
+	<view class="content">
+		
+		<button class="btn" type="primary" :loading="isSearching" @tap="startSearch">搜索打印机</button>
+		<button class="btn" type="warn" @tap="stopSearch">停止搜索</button>
+		
+		
+		<view v-for="(item) in list" :data-title="item.deviceId" :data-name="item.name" :data-advertisData="item.advertisServiceUUIDs"
+		 :key="item.deviceId" @tap="bindViewTap">
+			<view class="item">
+				<view class="deviceId block">{{item.deviceId}}</view>
+				<view class="name block">{{item.name}}</view>
+			</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	import {
+		mapState
+	} from 'vuex';
+	export default {
+		data() {
+			return {
+				isSearching: false, //是否正在搜索中
+				list: [],
+				services: [],
+				serviceId: 0,
+				writeCharacter: false,
+				readCharacter: false,
+				notifyCharacter: false
+			};
+		},
+		computed: mapState(['sysinfo', 'Bluetooth']),
+		onLoad() {
+			// console.log(this.Bluetooth)
+			
+		},
+		onUnload() {
+			//停止搜索蓝牙设备
+			if (this.isSearching) {
+				uni.stopBluetoothDevicesDiscovery();
+			}
+		},
+		methods: {
+			//错误码提示
+			errorCodeTip(code) {
+				if (code == 0) {
+					//正常
+				} else if (code == 10000) {
+					uni.showToast({
+						title: '未初始化蓝牙适配器',
+						icon: 'none'
+					})
+				} else if (code == 10001) {
+					uni.showToast({
+						title: '当前蓝牙适配器不可用',
+						icon: 'none'
+					})
+				} else if (code == 10002) {
+					uni.showToast({
+						title: '没有找到指定设备',
+						icon: 'none'
+					})
+				} else if (code == 10003) {
+					uni.showToast({
+						title: '连接失败',
+						icon: 'none'
+					})
+				} else if (code == 10004) {
+					uni.showToast({
+						title: '没有找到指定服务',
+						icon: 'none'
+					})
+				} else if (code == 10005) {
+					uni.showToast({
+						title: '没有找到指定特征值',
+						icon: 'none'
+					})
+				} else if (code == 10006) {
+					uni.showToast({
+						title: '当前连接已断开',
+						icon: 'none'
+					})
+				} else if (code == 10007) {
+					uni.showToast({
+						title: '当前特征值不支持此操作',
+						icon: 'none'
+					})
+				} else if (code == 10008) {
+					uni.showToast({
+						title: '其余所有系统上报的异常',
+						icon: 'none'
+					})
+				} else if (code == 10009) {
+					uni.showToast({
+						title: 'Android 系统特有,系统版本低于 4.3 不支持 BLE',
+						icon: 'none'
+					})
+				}
+			},
+			//开始搜索蓝牙
+			startSearch() {
+				let that = this
+				uni.openBluetoothAdapter({
+					success(res) {
+						uni.getBluetoothAdapterState({
+							success(res2) {
+								console.log('getBluetoothAdapterState:', res2)
+								if (res2.available) {
+									that.isSearching = true;
+									if (res2.discovering) {
+										uni.showToast({
+											title: '正在搜索附近打印机设备',
+											icon: "none"
+										})
+										return;
+									}
+			
+									//获取蓝牙设备信息
+									that.getBluetoothDevices()
+			
+									// that.checkPemission()
+								} else {
+									uni.showModal({
+										title: '提示',
+										content: '本机蓝牙不可用',
+									})
+								}
+							}
+						});
+					},
+					fail() {
+						uni.showModal({
+							title: '提示',
+							content: '蓝牙初始化失败,请打开蓝牙',
+						})
+					}
+				})
+			},
+			stopSearch() {
+				uni.stopBluetoothDevicesDiscovery({
+					success: (res) => {
+						this.isSearching = false;
+						console.log('stop:', res)
+					},
+					fail: (e) => {
+						console.log('stop:', e)
+						this.errorCodeTip(e.errCode);
+					}
+				})
+			},
+			//校验权限
+			checkPemission() {
+				let that = this
+				let {
+					BLEInformation
+				} = that.Bluetooth;
+				let platform = BLEInformation.platform;
+				that.getBluetoothDevices();
+			},
+			//获取蓝牙设备信息
+			getBluetoothDevices() {
+				let that = this
+				that.list = [];
+				uni.startBluetoothDevicesDiscovery({
+					success(res) {
+						// console.log(res)
+						//蓝牙设备监听 uni.onBluetoothDeviceFound
+						plus.bluetooth.onBluetoothDeviceFound((result) => {
+							console.log('onBluetoothDeviceFound:', result)
+							let arr = that.list;
+							let devices = [];
+							let list = result.devices;
+							for (let i = 0; i < list.length; ++i) {
+								if (list[i].name && list[i].name != "未知设备") {
+									let arrNew = arr.filter((item) => {
+										return item.deviceId == list[i].deviceId;
+									});
+									// console.log('arrNew:',arrNew.length)
+									if (arrNew.length == 0) {
+										devices.push(list[i]);
+									}
+								}
+							}
+			
+							that.list = arr.concat(devices);
+						});
+						that.time = setTimeout(() => {
+							// uni.getBluetoothDevices
+							plus.bluetooth.getBluetoothDevices({
+								success(res2) {
+									let devices = [];
+									let list = res2.devices;
+									for (let i = 0; i < list.length; ++i) {
+										if (list[i].name && list[i].name != "未知设备") {
+											devices.push(list[i]);
+										}
+									}
+			
+									that.list = devices;
+									console.log('getBluetoothDevices:',res2);
+								},
+							})
+			
+							clearTimeout(that.time);
+						}, 3000);
+					}
+				});
+			
+			},
+			//绑定蓝牙
+			bindViewTap(e) {
+				let that = this;
+				let {
+					title
+				} = e.currentTarget.dataset;
+				let {
+					BLEInformation
+				} = that.Bluetooth;
+				this.stopSearch();
+				
+				that.serviceId = 0;
+				that.writeCharacter = false;
+				that.readCharacter = false;
+				that.notifyCharacter = false;
+				uni.showLoading({
+					title: '正在连接',
+				})
+				console.log('deviceId:', title)
+				// uni.createBLEConnection
+				plus.bluetooth.createBLEConnection({
+					deviceId: title,
+					success(res) {
+						console.log('createBLEConnection success:', res)
+						BLEInformation.deviceId = title;
+						that.$store.commit('BLEInformationSet', BLEInformation);
+						uni.hideLoading()
+						that.getSeviceId()
+					},
+					fail(e) {
+						that.errorCodeTip(e.errCode);
+						uni.hideLoading()
+					}
+				})
+			},
+			//获取蓝牙设备所有服务(service)。
+			getSeviceId() {
+				let that = this;
+				let {
+					BLEInformation
+				} = that.Bluetooth;
+				console.log('BLEInformation.deviceId:',BLEInformation.deviceId)
+				// uni.getBLEDeviceServices
+				let t=setTimeout(()=>{
+					plus.bluetooth.getBLEDeviceServices({
+						deviceId: BLEInformation.deviceId,
+						success(res) {
+							console.log('getBLEDeviceServices success:',res)
+							that.services = res.services;
+							that.getCharacteristics()
+						},
+						fail: function(e) {
+							that.errorCodeTip(e.code);	
+							console.log('getBLEDeviceServices fail:',e)
+						}
+					})
+					clearTimeout(t);
+				},1500)
+			},
+			getCharacteristics() {
+				var that = this
+				let {
+					services: list,
+					serviceId: num,
+					writeCharacter: write,
+					readCharacter: read,
+					notifyCharacter: notify
+				} = that;
+				let {
+					BLEInformation
+				} = that.Bluetooth;
+				// uni.getBLEDeviceCharacteristics
+				plus.bluetooth.getBLEDeviceCharacteristics({
+					deviceId: BLEInformation.deviceId,
+					serviceId: list[num].uuid,
+					success(res) {
+						// console.log(res)
+						for (var i = 0; i < res.characteristics.length; ++i) {
+							var properties = res.characteristics[i].properties
+							var item = res.characteristics[i].uuid
+							if (!notify) {
+								if (properties.notify) {
+									BLEInformation.notifyCharaterId = item;
+									BLEInformation.notifyServiceId = list[num].uuid;
+									that.$store.commit('BLEInformationSet', BLEInformation);
+									notify = true
+								}
+							}
+							if (!write) {
+								if (properties.write) {
+									BLEInformation.writeCharaterId = item;
+									BLEInformation.writeServiceId = list[num].uuid;
+									that.$store.commit('BLEInformationSet', BLEInformation);
+									write = true
+								}
+							}
+							if (!read) {
+								if (properties.read) {
+									BLEInformation.readCharaterId = item;
+									BLEInformation.readServiceId = list[num].uuid;
+									that.$store.commit('BLEInformationSet', BLEInformation);
+									read = true
+								}
+							}
+						}
+						if (!write || !notify || !read) {
+							num++
+							that.writeCharacter = write;
+							that.readCharacter = read;
+							that.notifyCharacter = notify;
+							that.serviceId = num;
+							if (num == list.length) {
+								uni.showModal({
+									title: '提示',
+									content: '找不到该读写的特征值',
+								})
+							} else {
+								that.getCharacteristics()
+							}
+						} else {
+							that.openControl()
+						}
+					},
+					fail: function(e) {
+						console.log("getBLEDeviceCharacteristics fail:",e);
+						that.errorCodeTip(e.errCode);	
+					}
+				})
+			},
+			openControl: function() {
+				uni.navigateTo({
+					url: '/pages/erpbusiness/exsendCommand'
+				})
+			},
+		}
+	}
+</script>
+
+<style lang="less">
+	.btn {
+		margin-top: 50rpx;
+		height: 40px;
+		width: 600rpx;
+		line-height: 40px;
+		background: #22C572;
+	}
+
+	.item {
+		display: block;
+		font-family: Arial, Helvetica, sans-serif;
+		font-size: 14px;
+		margin: 0 30px;
+		margin-top: 10px;
+		background-color: #FFA850;
+		border-radius: 5px;
+		border-bottom: 2px solid #68BAEA;
+	}
+
+	.block {
+		display: block;
+		color: #ffffff;
+		padding: 5px;
+	}
+</style>

+ 448 - 0
pages/erpbusiness/exsendCommand.vue

@@ -0,0 +1,448 @@
+<template>
+	<view class="content">
+		<view class="body">
+			<!-- 	<view>
+				<textarea class="result" v-model="returnResult"></textarea>
+			</view>
+			<textarea class="input" @input="inputEvent" /> -->
+			<!-- <button type="primary" @tap="sendData">发送(票据可使用)</button> -->
+
+			<view style='margin-top:4%;display: flex;flex-direction: row;'>
+				<button type='primary' class="btn" @tap='receiptTest' :loading='isReceiptSend'
+					:disabled='isReceiptSend'>打印出库小票</button>
+				<!-- <button type='primary' @tap='labelTest' :loading='isLabelSend' :disabled='isLabelSend'>标签测试</button> -->
+			</view>
+
+			<view style='margin-top:4%;display: flex;flex-direction: row;'>
+				<!-- hidden='true' -->
+				<canvas canvas-id='edit_area_canvas'
+					:style="{width:canvasWidth+'px',height:canvasHeight+'px'}"></canvas>
+			</view>
+
+			<!-- <picker style='margin:20px' mode='selector' :range='buffSize' :value='buffIndex' @change='buffBindChange'>
+				当前每次发送字节数为(点击可更换):{{buffSize[buffIndex]}}
+			</picker>
+		
+			<picker style='margin:20px' mode='selector' :range='printNum' :value='printNumIndex' @change='printNumBindChange'>
+				当前打印份数(点击可更换):{{printNum[printNumIndex]}}
+			</picker> -->
+
+		</view>
+	</view>
+</template>
+
+<script>
+	var tsc = require("../../util/ble/tsc.js");
+	var esc = require("../../util/ble/esc.js");
+	var encode = require("../../util/ble/encoding.js");
+	import {
+		mapState
+	} from 'vuex';
+	export default {
+		data() {
+			return {
+				sendContent: "",
+				looptime: 0,
+				currentTime: 1,
+				lastData: 0,
+				oneTimeData: 0,
+				returnResult: "",
+				canvasWidth: 180,
+				canvasHeight: 180,
+				imageSrc: '../../static/img/abc_ic_star_black_16dp.png',
+				buffSize: [],
+				buffIndex: 0,
+				printNum: [],
+				printNumIndex: 0,
+				printerNum: 1,
+				currentPrint: 1,
+				isReceiptSend: false,
+				isLabelSend: false,
+				gridList: {}
+			};
+		},
+		computed: mapState(['sysinfo', 'Bluetooth']),
+		onLoad() {
+			let that = this;
+			let {
+				BLEInformation
+			} = that.Bluetooth;
+			uni.notifyBLECharacteristicValueChange({
+				deviceId: BLEInformation.deviceId,
+				serviceId: BLEInformation.notifyServiceId,
+				characteristicId: BLEInformation.notifyCharaterId,
+			 state: true,
+				success(res) {
+					uni.onBLECharacteristicValueChange(function(r) {
+						console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
+					})
+				},
+			 fail: function(e) {
+					console.log(e)
+			 },
+				complete: function(e) {
+					console.log(e)
+				}
+			})
+		},
+		onReady() {
+			let list = []
+			let numList = []
+			let j = 0
+			for (let i = 20; i < 200; i += 10) {
+				list[j] = i;
+				j++
+			}
+			for (let i = 1; i < 10; i++) {
+				numList[i - 1] = i
+			}
+			this.buffSize = list;
+			this.oneTimeData = list[0];
+			this.printNum = numList;
+			this.printerNum = numList[0];
+		},
+		onShow() {
+			this.gridList = uni.getStorageSync("exWarehousing_print")
+			console.log(this.gridList)
+			let that = this;
+			let width;
+			let height;
+			uni.getImageInfo({
+				src: that.imageSrc,
+				success(res) {
+					console.log(res.width)
+					console.log(res.height)
+					width = res.width
+					height = res.height
+					that.canvasWidth = res.width;
+					that.canvasHeight = res.height;
+				}
+			})
+			const ctx = uni.createCanvasContext("edit_area_canvas", this);
+			// if (app.globalData.platform == "android") {
+			//   ctx.translate(width, height)
+			//   ctx.rotate(180 * Math.PI / 180)
+			// }
+			ctx.drawImage(this.imageSrc, 0, 0, width, height);
+			ctx.draw();
+		},
+		onUnload() {
+			let that = this;
+			let {
+				BLEInformation
+			} = that.Bluetooth;
+			// uni.closeBLEConnection({
+			//      deviceId: BLEInformation.deviceId,
+			//      success: function(res) {
+			//        console.log("关闭蓝牙成功")
+			//      },
+			//    })	
+		},
+		methods: {
+			//获取输入内容
+			inputEvent(e) {
+				this.sendContent = e.detail.value;
+			},
+			//输入框点击发送
+			sendData() {
+				let data = this.sendContent + "\n"
+				this.looptime = 0;
+				var content = new encode.TextEncoder(
+					'gb18030', {
+						NONSTANDARD_allowLegacyEncoding: true
+					}).encode(data);
+
+				this.prepareSend(content);
+			},
+			//打印票据数据
+			receiptTest() {
+				var that = this;
+				var canvasWidth = that.canvasWidth
+				var canvasHeight = that.canvasHeight
+				var command = esc.jpPrinter.createNew()
+				command.init()
+				// 标题
+				command.bold(1); //加粗
+				command.setFontSize(16); //字体大小
+				command.setSelectJustification(1) //居中
+				// command.rowSpace(10);
+				command.setText("出库检斤单");
+				command.setPrint();
+				command.rowSpace(60);
+				command.bold(0); //取消加粗
+				command.setFontSize(0); //正常字体
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("时间:" + that.gridList.updateDate);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("送货单位:" + that.gridList.seller);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("收货单位:" + that.gridList.buyer);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("货名:" + that.gridList.goodsName);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("质检员:" + that.gridList.backOffice);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("毛重(吨)" + that.gridList.grossWeight);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("皮重(吨)" + that.gridList.tare);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("净重(吨)" + that.gridList.netWeight);
+				command.setPrint();
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("运输方式:" + that.gridList.outType);
+				command.setPrint();
+				
+				if(that.gridList.outType=="集装箱船"||taht.gridList.outType=="汽运"){
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("车牌号:" + that.gridList.carNo);
+					command.setPrint();
+				}else if(that.gridList.outType=="火运"){
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("车号:" + that.gridList.carNo);
+					command.setPrint();
+				}else if(that.gridList.outType=="散船"){
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("船名:" + that.gridList.shipName);
+					command.setPrint();
+				}
+				if (that.gridList.outType=="集装箱船"||that.gridList.outType=="汽运") {
+					//箱号
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("箱号-1:" + that.gridList.boxNo);
+					command.setPrint();
+					//箱号
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("箱号-2:" + that.gridList.boxNoOther);
+					command.setPrint();
+				}else if(that.gridList.outType=="火运"){
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("车厢号-1:" + that.gridList.wingNumber);
+					command.setPrint();
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("车厢号-2:" + that.gridList.wingNumberOther);
+					command.setPrint();
+				}else if(that.gridList.outType=="散船"){
+					command.setSelectJustification(0); //居左
+					command.setLeftMargin(30)
+					command.setText("船次:" + that.gridList.shipNumber);
+					command.setPrint();
+				}
+
+				//客户签名
+				command.rowSpace(100);
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("客户签名:");
+				command.setPrint();
+				command.rowSpace(100);
+				//收货单位签名或盖章
+				command.setSelectJustification(0); //居左
+				command.setLeftMargin(30)
+				command.setText("收货单位签名或盖章:");
+				command.setPrintAndFeed(150);
+				command.setPrintAndFeedRow(8);
+				that.isReceiptSend = true;
+				that.prepareSend(command.getData());
+			},
+
+			//准备发送,根据每次发送字节数来处理分包数量
+			prepareSend(buff) {
+				console.log(buff);
+				let that = this
+				let time = that.oneTimeData
+				let looptime = parseInt(buff.length / time);
+				let lastData = parseInt(buff.length % time);
+				console.log(looptime + "---" + lastData)
+				this.looptime = looptime + 1;
+				this.lastData = lastData;
+				this.currentTime = 1;
+				that.Send(buff)
+			},
+			//查询打印机状态
+			queryStatus() {
+				let command = esc.jpPrinter.Query();
+				command.getRealtimeStatusTransmission(1);
+			},
+			//分包发送
+			Send(buff) {
+				let that = this
+				let {
+					currentTime,
+					looptime: loopTime,
+					lastData,
+					oneTimeData: onTimeData,
+					printerNum: printNum,
+					currentPrint
+				} = that;
+				let buf;
+				let dataView;
+				if (currentTime < loopTime) {
+					buf = new ArrayBuffer(onTimeData)
+					dataView = new DataView(buf)
+					for (var i = 0; i < onTimeData; ++i) {
+						dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
+					}
+				} else {
+					buf = new ArrayBuffer(lastData)
+					dataView = new DataView(buf)
+					for (var i = 0; i < lastData; ++i) {
+						dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
+					}
+				}
+				console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
+				let {
+					BLEInformation
+				} = that.Bluetooth;
+
+				plus.bluetooth.writeBLECharacteristicValue({
+					deviceId: BLEInformation.deviceId,
+					serviceId: BLEInformation.writeServiceId,
+					characteristicId: BLEInformation.writeCharaterId,
+					value: buf,
+					success: function(res) {
+						console.log(res)
+					},
+					fail: function(e) {
+						console.log(e)
+					},
+					complete: function() {
+						currentTime++
+						if (currentTime <= loopTime) {
+							that.currentTime = currentTime;
+							that.Send(buff)
+						} else {
+							uni.showToast({
+								title: '已打印第' + currentPrint + '张',
+							})
+							if (currentPrint == printNum) {
+								that.looptime = 0;
+								that.lastData = 0;
+								that.currentTime = 1;
+								that.isReceiptSend = false;
+								that.isLabelSend = false;
+								that.currentPrint = 1;
+							} else {
+								currentPrint++;
+								that.currentPrint = currentPrint;
+								that.currentTime = 1;
+								that.Send(buff)
+							}
+						}
+					}
+				})
+			},
+			buffBindChange: function(res) { //更改打印字节数
+				let index = res.detail.value
+				let time = this.buffSize[index]
+				this.buffIndex = index;
+				this.oneTimeData = time;
+			},
+			printNumBindChange: function(res) { //更改打印份数
+				let index = res.detail.value
+				let num = this.printNum[index]
+				this.printNumIndex = index;
+				this.printerNum = num;
+			},
+		}
+	}
+</script>
+
+<style lang="less">
+	.input {
+		text-align: top;
+		width: 90%;
+		height: 150px;
+		margin-left: 4%;
+		margin-right: 4%;
+		margin-top: 10px;
+		margin-bottom: 12px;
+		border: 1px solid slategray;
+	}
+
+	.receiver_info_scroll_view {
+		width: 90%;
+		height: 200px;
+		margin-left: 4%;
+		margin-right: 4%;
+		margin-top: 10px;
+		margin-bottom: 25px;
+		border: 1px solid black;
+	}
+
+	.result {
+		width: 90%;
+		height: 150px;
+		border: 1px solid black;
+		margin-left: 4%;
+		margin-bottom: 4%;
+		margin-top: 5%;
+	}
+
+	button {
+		width: 90%;
+		margin-left: 5%;
+		margin-right: 5%;
+	}
+
+	.switch {
+		float: right;
+		margin-right: 20px;
+		margin-bottom: 16px;
+	}
+
+	text {
+		color: #fff;
+		display: block;
+	}
+
+	input {
+		color: gainsboro;
+		float: left;
+	}
+
+	.v_net_ssid {
+		width: 100%;
+		background: #fff;
+	}
+
+	.v_net_passw {
+		width: 100%;
+		background: antiquewhite;
+	}
+
+	.swiper {
+		width: 100%;
+		height: 100%;
+	}
+	.btn{
+		margin-top: 50rpx;
+		background: #22C572;
+	}
+	uni-button[loading][type=primary] {
+	    color: hsla(0,0%,100%,.6);
+	    background-color: #22C572;
+	}
+</style>