lilei 2 gadi atpakaļ
vecāks
revīzija
3177a25e6e

+ 40 - 24
components/kk-printer/index.vue

@@ -1,8 +1,8 @@
 <template>
 	<view class="kk-printer">
 		<view class="kk-printer-btn">
-			<u-button v-if="printBtnStyle=='blue-large'" @tap="handlePrintTap" :loading="isPrinting" shape="circle" :custom-style="{background:$config('primaryColor')}" type="primary">{{isPrinting?printingText:defaultText}}</u-button>
-			<u-button v-if="printBtnStyle=='default-mid'" shape="circle" size="medium" hover-class="none" @tap="handlePrintTap" :loading="isPrinting">{{isPrinting?printingText:defaultText}}</u-button>
+			<u-button v-if="printBtnStyle=='blue-large'" @tap="handlePrintTap(1)" :loading="isPrinting||isConnecting" shape="circle" :custom-style="{background:$config('primaryColor')}" type="primary">{{isPrinting?printingText:defaultText}}</u-button>
+			<u-button v-if="printBtnStyle=='default-mid'" shape="circle" size="medium" hover-class="none" @tap="handlePrintTap(1)" :loading="isPrinting||isConnecting">{{isPrinting?printingText:defaultText}}</u-button>
 		</view>
 		<view class="kk-shadow" :class="isShowSearch?'show':''" @tap="handleSearchClose">
 			<view class="kk-modal" @tap.stop="doNothing">
@@ -162,7 +162,8 @@
 			}
 		},
 		mounted() {
-			
+			console.log('mounted')
+			this.handlePrintTap(0)
 		},
 		beforeDestroy(){
 			this.stopSearchBtnTap();
@@ -171,36 +172,46 @@
 			doNothing(){
 				return;
 			},
-			//点击打印按钮
-			handlePrintTap(){
+			//点击打印按钮,flag : true 如果已连接直接执行打印命令,false,不执行
+			handlePrintTap(flag){
 				//打开蓝牙适配器
 				blesdk.openBlue().then((res)=>{
 					//获取已连接设备
 					blesdk.getConnectedBluetoothDevices().then((res)=>{
-						//若没有已连接设备,弹框搜索设备
+						const lastDevice = uni.getStorageSync('vuex_lastBuleDevice')
+						console.log(lastDevice)
 						console.log(res,this.deviceId,this.serviceId,this.writeId,this.onPrintSuccess)
-						if(res.devices.length == 0){
-							this.isShowSearch = true
-							this.devicesList = []
-							if(this.deviceId){
-								this.closeConnect(this.deviceId)
-							}
-						}else{
-							const lastDevice = this.$store.state.vuex_lastBuleDevice
-							if(lastDevice && res.devices[0].deviceId == lastDevice.deviceId){
+						// 如果之前连接过设备
+						if(lastDevice){
+							// 有正在连接的设备,且和上次连接设备一样
+							if(res.devices.length && res.devices[0].deviceId == lastDevice.deviceId){
 								this.deviceId = lastDevice.deviceId
 								this.serviceId = lastDevice.serviceId
 								this.writeId = lastDevice.writeId
 								this.readId = lastDevice.readId
+								if(flag){
+									this.isPrinting = true;
+									this.$nextTick(()=>{
+										this.$emit("startPrint",{
+											deviceId: this.deviceId,
+											serviceId: this.serviceId,
+											writeId: this.writeId
+										},tsc,blesdk)
+									})
+								}
+							}else{
+								// 重新直接连接
+								this.handleConnectDevice(lastDevice)
 							}
-							this.isPrinting = true;
-							this.$nextTick(()=>{
-								this.$emit("startPrint",{
-									deviceId: this.deviceId,
-									serviceId: this.serviceId,
-									writeId: this.writeId
-								},tsc,blesdk)
-							})
+						}else{
+							//若没有已连接设备,弹框搜索设备
+							if(res.devices.length == 0){
+								this.isShowSearch = true
+								this.devicesList = []
+								if(this.deviceId){
+									this.closeConnect(this.deviceId)
+								}
+							} 
 						}
 					}).catch((err)=>{
 						blesdk.catchToast(err);
@@ -216,6 +227,7 @@
 			handleSearchClose(){
 				if(!this.isConnecting){
 					this.isShowSearch = false
+					this.stopSearchBtnTap()
 				}
 			},
 			handleSRRIChange(e){
@@ -281,7 +293,11 @@
 				this.writeId = res.writeId;
 				this.readId = res.readId;
 				this.isShowSearch = false;
-				this.$store.state.vuex_lastBuleDevice = {deviceId:this.deviceId,serviceId:this.serviceId,writeId:this.writeId,readId:this.readId}
+				try {
+					uni.setStorageSync('vuex_lastBuleDevice', {deviceId:this.deviceId,serviceId:this.serviceId,writeId:this.writeId,readId:this.readId});
+				} catch (e) {
+					// error
+				}
 			},
 			onGetCharacterFail(err){
 				console.log('特征值获取失败')

+ 47 - 21
libs/printTools.js

@@ -51,12 +51,12 @@ export const textFormat = function(command,text,maxFontNums,left,top,lightHeight
 		if(align=="center"){
 			const ltxt = textArr[i]
 			const ltlen = getBytesCount(ltxt)/2*fontSize
-			command.setText(left+((maxNums-ltlen)/2)*rowHeight, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
+			command.setText(left+((maxNums-ltlen)/2)*rowHeight-2, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
 		}
 		else{
 			command.setText(left, rowTop, "TSS24.BF2", fontSize, fontSize, textArr[i])
 		}
-		rowTop = rowTop+rowHeight*fontSize+10
+		rowTop = rowTop+rowHeight*fontSize+5
 	}
 	return rowTop
 }
@@ -72,15 +72,15 @@ export const printText = function(tsc,text){
 }
 // 60 * 40 尺寸模板
 export const printTempl = function(tsc,data){
-	let top = 24 // 距离顶部10点像素
+	let top = 48 // 距离顶部
 	const left = 8 // 距离左边
 	const lightHeight = 24 // 行高3mm,1mm = 8点
 	const pageW = 60 // 页签宽度mm
 	const pageH = 40 // 页签高度mm
 	const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
-	const leftMaxFnums = Math.floor(maxFontNums*0.6)
-	let rightTop = 0
-	let rightLeft = (leftMaxFnums+1.2)*lightHeight
+	const leftMaxFnums = Math.floor(maxFontNums*0.4)
+	const rightMaxFnums = maxFontNums*0.5
+	let rightLeft = (leftMaxFnums+1.5)*lightHeight
 	// 初始化打印机
 	const command = tsc.jpPrinter.createNew()
 	command.init()
@@ -90,22 +90,48 @@ export const printTempl = function(tsc,data){
 	// 经销商文字高度,是否换行
 	top = textFormat(command,data.dealerName,maxFontNums,left,top,lightHeight,"center",1)
 	// 数字货架名称文字
-	top = top+10
-	rightTop = top
-	// top = textFormat(command,data.shelfName,leftMaxFnums,left,top,lightHeight,"left",1)
-	// 产品编码 + 产品名称
-	// top = top+10
-	top = textFormat(command,data.shelfName +'/'+ data.productCode + '/' + data.productName,leftMaxFnums,left,top,lightHeight,"left",1)
-	// 产品名称
-	// top = top+6
-	// top = textFormat(command,data.productName,leftMaxFnums,left,top,lightHeight,"left",1)
-	// 打印人打印时间
-	top = top+10
-	top = textFormat(command,data.printDate+' '+data.printUser,leftMaxFnums,left,top,lightHeight,"left",1)
+	top = top+30
+	// 二维码
+	command.setQR(left*3, top, "M", 5, "A", data.barCode)
 	// 货位号
-	const qrtop = textFormat(command,data.shelfPlaceCode,maxFontNums-leftMaxFnums-1.2,rightLeft,rightTop,lightHeight,"center",2)
+	const rightTop = textFormat(command,data.shelfPlaceCode,rightMaxFnums,rightLeft,top,lightHeight,"left",4)
+	// 产品编码
+	top = rightTop
+	top = textFormat(command,data.productCode,rightMaxFnums,rightLeft,top,lightHeight,"left",1)
+	// 打印分数1,每个标签重发打印2次
+	command.setPagePrint(1,data.currentInven) 
+	return command
+}
+
+// 40 * 30 尺寸模板
+export const printMiniTempl = function(tsc,data){
+	let top = 24 // 距离顶部
+	const left = 4 // 距离左边
+	const lightHeight = 24 // 行高3mm,1mm = 8点
+	const pageW = 40 // 页签宽度mm
+	const pageH = 30 // 页签高度mm
+	const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
+	const leftMaxFnums = Math.floor(maxFontNums*0.5)
+	const rightMaxFnums = Math.floor(maxFontNums*0.4)
+	let rightLeft = (leftMaxFnums+1)*lightHeight
+	// 初始化打印机
+	const command = tsc.jpPrinter.createNew()
+	command.init()
+	command.setSize(pageW, pageH) // 标签纸张宽高,单位mm
+	command.setGap(3) // 标签上下间距,单位mm
+	command.setCls() // 清除缓冲区数据
+	// 经销商文字高度,是否换行
+	top = textFormat(command,data.dealerName,maxFontNums,left,top,lightHeight,"center",1)
+	// 数字货架名称文字
+	top = top+10
 	// 二维码
-	command.setQR(rightLeft, qrtop, "M", 5, "A", data.barCode)
-	command.setPagePrint(1,data.currentInven) // 打印分数1,每个标签重发打印2次
+	command.setQR(left, top, "M", 5, "A", data.barCode)
+	// 货位号
+	const rightTop = textFormat(command,data.shelfPlaceCode,rightMaxFnums,rightLeft,top,lightHeight,"left",3)
+	// 产品编码
+	top = rightTop
+	top = textFormat(command,data.productCode,rightMaxFnums,rightLeft,top,lightHeight,"left",1)
+	// 打印分数1,每个标签重发打印2次
+	command.setPagePrint(1,data.currentInven) 
 	return command
 }

+ 15 - 2
pages/shelfSetting/editShelfHw.vue

@@ -88,7 +88,7 @@
 		},
 		onLoad(opts) {
 			const _this = this
-			this.nowData = JSON.parse(decodeURIComponent(opts.detailData));
+			this.nowData = this.$store.state.vuex_tempData;
 			this.customerSn = this.nowData.customerSn
 			this.shelfSn = this.nowData.shelfSn
 			this.type = opts.type
@@ -122,6 +122,7 @@
 			console.log('-----')
 			uni.$off("addProductToHw")
 			uni.$off("updateHwNo")
+			this.$store.state.vuex_tempData = null
 		},
 		methods: {
 			// 小数点后两位
@@ -141,8 +142,13 @@
 			// 编辑货位号
 			editShelf(){
 				const type ='edit'
+				const params={
+					customerSn: this.nowData.customerSn,
+					shelfSn: this.nowData.shelfSn,
+					id: this.nowData.id,
+				}
 				uni.navigateTo({
-					url: "/pages/shelfSetting/addShelfHw?detailData="+encodeURIComponent(JSON.stringify(this.nowData))+"&type="+type+"&shelfPlaceCode="+this.shelfPlaceCode
+					url: "/pages/shelfSetting/addShelfHw?detailData="+encodeURIComponent(JSON.stringify(params))+"&type="+type+"&shelfPlaceCode="+this.shelfPlaceCode
 				})
 			},
 			// 获取产品信息
@@ -192,6 +198,13 @@
 			//  表单提交
 			formSubmit(){
 				const _this = this
+				if(!this.productEntity){
+					uni.showToast({
+						icon: "none",
+						title: '请先绑定产品'
+					})
+					return
+				}
 				this.$refs.uForm.validate(valid => {
 					if (valid) {
 						 const form = JSON.parse(JSON.stringify(_this.form))

+ 1 - 1
pages/shelfSetting/quickProductList.vue

@@ -33,7 +33,7 @@
 					<view class="pcurnums flex align_center">
 						<text>补货数量</text>
 						<view class="u-ninput">
-							<u-number-box color="#000" bg-color="#fff" v-model="item.printQty" :min="0" :max="item.maxQty"></u-number-box>
+							<u-number-box color="#000" bg-color="#fff" v-model="item.printQty" :min="0" :max="999999"></u-number-box>
 						</view>
 					</view>
 				</view>

+ 1 - 1
pages/shelfSetting/quickReplenish.vue

@@ -73,7 +73,7 @@
 			this.allChecked = true
 		},
 		onLoad(option) {
-			this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
+			this.basicInfoData = this.$store.state.vuex_tempData;
 			this.partList = this.basicInfoData.list
 			// 保持屏幕常亮
 			uni.setKeepScreenOn({

+ 3 - 1
pages/shelfSetting/searchShelfHw.vue

@@ -97,6 +97,7 @@
 			}
 		},
 		onLoad(opts) {
+			this.$store.state.vuex_tempData = null
 			this.shelfName = opts.shelfName
 			this.shelfSn = opts.shelfSn
 			this.getShelfPlace()
@@ -109,8 +110,9 @@
 			toEdit(item){
 				const type = 'edit'
 				const params = Object.assign({shelfSn: this.shelfSn,shelfName: this.shelfName},item)
+				this.$store.state.vuex_tempData = params
 				uni.navigateTo({
-					url: "/pages/shelfSetting/editShelfHw?detailData="+encodeURIComponent(JSON.stringify(params))+"&type=" + type
+					url: "/pages/shelfSetting/editShelfHw?type=" + type
 				})
 			},
 			getShelfPlace(flag){

+ 10 - 3
pages/shelfSetting/shelfSet.vue

@@ -125,8 +125,9 @@
 						console.log(res.data)
 						if(res.data&&res.data.length){
 							const params = Object.assign(this.detailData,{list:res.data})
+							this.$store.state.vuex_tempData = params
 							uni.navigateTo({
-								url: "/pages/shelfSetting/quickReplenish?data="+encodeURIComponent(JSON.stringify(params))
+								url: "/pages/shelfSetting/quickReplenish"
 							})
 						}else{
 							uni.showModal({
@@ -205,8 +206,9 @@
 				const hasProduct = item.shelfProductApiEntity && item.shelfProductApiEntity.productSn
 				const type = hasProduct ? 'edit':'bind'
 				const params = Object.assign(this.detailData,item)
+				this.$store.state.vuex_tempData = params
 				uni.navigateTo({
-					url: "/pages/shelfSetting/editShelfHw?detailData="+encodeURIComponent(JSON.stringify(params))+"&type=" + type
+					url: "/pages/shelfSetting/editShelfHw?type=" + type
 				})
 			},
 			// 新增货位
@@ -221,8 +223,13 @@
 					const nextNum = Number(num) + 1
 					shelfPlaceCode = this.curTab + (nextNum<10?'0':'') + nextNum
 				}
+				const params={
+					customerSn: this.detailData.customerSn,
+					shelfSn: this.detailData.shelfSn,
+					id: this.detailData.id
+				}
 				uni.navigateTo({
-					url: "/pages/shelfSetting/addShelfHw?detailData="+encodeURIComponent(JSON.stringify(this.detailData))+"&type="+type+"&shelfPlaceCode="+shelfPlaceCode
+					url: "/pages/shelfSetting/addShelfHw?detailData="+encodeURIComponent(JSON.stringify(params))+"&type="+type+"&shelfPlaceCode="+shelfPlaceCode
 				})
 			},
 			// 保存数字货架基本信息

+ 1 - 1
store/index.js

@@ -104,13 +104,13 @@ const store = new Vuex.Store({
 		vuex_reConnectId: null, // 重连id
 		vuex_messagUnReadCount: 0, // 消息未读数
 		vuex_messagLaster: [], // 最新消息
-		vuex_lastBuleDevice: null,
 		vuex_OrderAddress: {}, // 地址
 		vuex_allLookUp: [],  //  数据字典
 		vuex_paymentTypeList: [], // 收款方式
 		vuex_storeAuthState: [], // 门店审核状态
 		vuex_shelfSettleType: [], // 门店审核结算方式
 		vuex_tempPrintList:[], // 临时打印数据
+		vuex_tempData: null, // 临时数据
 	},
 	mutations: {
 		$uStore(state, payload) {