123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841 |
- <template>
- <view class="bluetooths">
- <view class="bluetooths_btn">
- <text class="bluetooths_txt1">搜索打印机/停止搜索</text>
- <u-switch v-model="checked" size='40' @change='change'></u-switch>
- </view>
- <view class="text-red">已连接设备</view>
- <view>
- <view v-if="connected===''">
- <view style="padding:30rpx 0;color: #cccc;">暂未连接任何设备</view>
- </view>
- <view v-else style="display: flex;align-items: center;justify-content: space-between;padding:30rpx 0;">
- <view style="display: flex;align-items: center;">
- <image src="../../static/img/dyj.svg" mode="widthFix" style="width: 60rpx;height: 60rpx;"></image>
- <view style="margin-left: 30rpx;color: #040203;font-size: 35rpx;">
- {{connected==''?'打印机未命名':connected}}
- </view>
- </view>
- <view>
- <view style="text-decoration: underline;">{{close}}</view>
- </view>
- </view>
- </view>
- <view class="text-red">可连接设备</view>
- <view v-if="devices.length==0">
- <view style="padding:30rpx 0;color: #cccc;">暂无可连接设备</view>
- </view>
- <view v-else>
- <view v-for="(item, index) in devices" :key="index">
- <view v-if="item.name!=''" style="display: flex;align-items: center;justify-content: space-between;padding:30rpx 0;" @click="onConn(item)">
- <view style="display: flex;align-items: center;">
- <image src="../../static/img/dyj.svg" mode="widthFix" style="width: 60rpx;height: 60rpx;">
- </image>
- <view style="margin-left: 30rpx;color: #040203;font-size: 35rpx;">
- {{item.name==''?'打印机未命名':item.name}}
- </view>
- </view>
- <view>
- <u-icon name="info-circle" color="#7c7a7b" size="30"></u-icon>
- </view>
- </view>
- </view>
- </view>
- <u-button type="primary" :disabled="disabled" style="margin-top: 100upx;" @click="senBleLabel2()">票据打印</u-button>
- </view>
- </template>
- <script>
- import tsc from '../../../pages_warehouse/static/libs/tsc.js'
- import esc from '../../../pages_warehouse/static/libs/esc.js'
- export default {
- data() {
- return {
-
- Admin_rh:this.$store.state.Admin_rh,//控制登录用户显示湿度 0隐藏 1显示
- bool:true,//链接成功可打印 true未连接
- onConns:true,//打印机是否链接 true未链接
- devices: [],
- disabled:false,//防止多次触发
- disBoll:null,
- currDev: null,
- connId: '',
- checked: false,
- connected: '', //已连接蓝牙
- tableDomId: '',
- tableImgPath: '',
- dangTime:null,//打印时间
- songhuo: this.$store.state.FirmList.songhuo, //送货公司
- shouhuo: this.$store.state.FirmList.shouhuo, //收货公司
- PrinList: this.$store.state.PrinList, //打印T_sn与主机名
- wdList:[] ,//数据包
- Admin_name:this.$store.state.Admin_name ,//公司名称
- maxData:[
- {T_name:'T1传感器',Maxwen: '',Minwen: '',pingjue: 0,},
- {T_name:'T2传感器',Maxwen: '',Minwen: '',pingjue: 0,},
- {T_name:'T3传感器',Maxwen: '',Minwen: '',pingjue: 0,},
- {T_name:'T4传感器',Maxwen: '',Minwen: '',pingjue: 0,}
- ]
- }
- },
- watch:{
- bool(newName, oldName) {
- console.log('是否变化',newName, oldName)
- if(newName){
- this.senBleLabel2()
- }
- },
- },
- created() {
- this.wdList = this.$store.state.PrinData.wdList
- console.log('created================1',this.$store.state.PrinData.wdList)
- // console.log('created================2',this.$store.state.PrinData.wdList.reverse())
- console.log('created================3',this.wdList)
- },
- mounted() {
- console.log('1================1',this.wdList)
- var staTime = this.wdList[this.wdList.length-1].T_time
- var endTime = this.wdList[0].T_time
-
- this.ewApi()
- console.log('2================1',this.wdList)
- },
- onUnload() {
- this.closeBluetoothAdapter()
- },
- methods: {
- ewApi() {
- console.log('wdList数据',this.wdList)
- var arr = this.wdList
- var _this = this;
- var Arr1 = []//T1数据
- var Arr2 = []//T2数据
- var Arr3 = []//T3数据
- var Arr4 = []//T4数据
- arr.forEach(function(item,index){
-
- Arr1.push(item.T1)
- Arr2.push(item.T2)
- Arr3.push(item.T3)
- Arr4.push(item.T4)
- })
- console.log('检查t1-t4',Arr1,Arr2,Arr3,Arr4)
- if(Arr1[0]!=null){
- var it1 = ''
- var iArr1 = []
- var sum = 0 //求和
- Arr1.forEach(function(item,index){
- var T_it = item.T_t
- it1 = item.T_t
- iArr1.push(it1)
- sum = Number(sum) + Number(T_it)//求和
- })
- this.maxData[0].Maxwen = Math.max(...iArr1)
- this.maxData[0].Minwen = Math.min(...iArr1)
- console.log('====================================888')
- this.maxData[0].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
- console.log('====================================999')
- console.log('iArr1',iArr1,this.maxData)
- }
- if(Arr2[0]!=null){
- console.log('进入iArr2')
- var it1 = ''
- var iArr1 = []
- var sum = 0 //求和
- Arr2.forEach(function(item,index){
- console.log('循环====',item,index)
- var T_it = item.T_t
- it1 = item.T_t
- iArr1.push(it1)
- sum = Number(sum) + Number(T_it)//求和
- })
- console.log('=================进入iArr288888888888')
- this.maxData[1].Maxwen = Math.max(...iArr1)
- this.maxData[1].Minwen = Math.min(...iArr1)
- console.log('=================进入iArr2')
- this.maxData[1].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
- console.log('iArr2',iArr1,this.maxData)
- }
- if(Arr3[0]!=null){
- var it1 = ''
- var iArr1 = []
- var sum = 0 //求和
- Arr3.forEach(function(item,index){
- var T_it = item.T_t
- it1 = item.T_t
- iArr1.push(it1)
- sum = Number(sum) + Number(T_it)//求和
- })
- this.maxData[2].Maxwen = Math.max(...iArr1)
- this.maxData[2].Minwen = Math.min(...iArr1)
- this.maxData[2].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
- console.log('iArr1',iArr1,this.maxData)
- }
- if(Arr4[0]!=null){
- var it1 = ''
- var iArr1 = []
- var sum = 0 //求和
- Arr4.forEach(function(item,index){
- var T_it = item.T_t
- it1 = item.T_t
- iArr1.push(it1)
- sum = Number(sum) + Number(T_it)//求和
- })
- this.maxData[3].Maxwen = Math.max(...iArr1)
- this.maxData[3].Minwen = Math.min(...iArr1)
- this.maxData[3].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
- console.log('iArr1',iArr1,this.maxData)
- }
- console.log('检查最大值',this.maxData)
- },
- getCurrentTime() { //获取当前时间
- var _this = this;
- let yy = new Date().getFullYear();
- let mm = new Date().getMonth() + 1;
- let dd = new Date().getDate();
- let hh = new Date().getHours();
- let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
- let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
- if (hh < 10) {
- hh = '0' + hh
- }
- if (mm < 10) {
- mm = '0' + mm
- }
- if (dd < 10) {
- dd = '0' + dd
- }
- _this.dangTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
- },
- change(status) {
- console.log('sss', status)
- if (status) { //搜索打印机
- this.searchBle()
- } else { //停止搜索
- this.closeBluetoothAdapter()
- this.stopFindBule()
- }
- },
- //关闭蓝牙模块
- closeBluetoothAdapter() {
- uni.closeBluetoothAdapter({
- success(res) {
- uni.showToast({
- title:'关闭蓝牙模块',
- icon:'none'
- })
- }
- })
- },
- destroyed: function() {
- if (this.connId != '') {
- uni.closeBLEConnection({
- deviceId: this.connId,
- success(res) {
- console.log(res)
- }
- })
- }
- },
- searchBle() {
- var that = this
- console.log("initBule")
- uni.openBluetoothAdapter({success(res) {
- console.log("打开 蓝牙模块",res)
- that.onDevice()
- uni.getBluetoothAdapterState({
- success: function(res) {
- console.log(res)
- if (res.available) {
- if (res.discovering) {
- that.stopFindBule()
- }
- //搜索蓝牙
- //开始搜寻附近的蓝牙外围设备
- console.log("开始搜寻附近的蓝牙外围设备")
- uni.startBluetoothDevicesDiscovery({
- success(res) {
- console.log(res)
- }
- })
- } else {
- console.log('本机蓝牙不可用')
- }
- },
- })
- },
- fail:err=>{ //未打开
- uni.showToast({icon:'none',title: '查看手机蓝牙是否打开'});
- that.checked = false
- }
- })
- },
- onDevice() {//寻找到蓝牙设备
- var that = this
- //监听寻找到新设备的事件
- uni.onBluetoothDeviceFound(function(devices) {
- console.log(JSON.stringify(devices))
- var re = JSON.parse(JSON.stringify(devices))
- console.log(re.devices[0].name + " " + re.devices[0].deviceId)
- let name = re.devices[0].name
- if (name != "未知设备") {
- let deviceId = re.devices[0].deviceId
- that.devices.push({
- name: name,
- deviceId: deviceId,
- services: []
- })
- }
- })
- },
- stopFindBule() {//停止搜寻附近的蓝牙外围设备
- var that = this
- uni.stopBluetoothDevicesDiscovery({
- success(res) {
- console.log(res)
- that.checked = false
- }
- })
- },
- onConn(item) {//点击连接相应蓝牙设备
- var that = this
- let deviceId = item.deviceId
- uni.showLoading({
- title:'连接中...'
- })
- uni.createBLEConnection({
- deviceId: deviceId,
- complete(res) {
- if (res.errMsg == "createBLEConnection:ok") {
- that.connected = item.name
- uni.hideLoading()
- uni.showToast({
- title: "蓝牙连接成功",
- icon: 'none',
- })
- that.onConns = false
- that.connId = deviceId;
- that.currDev = item
- setTimeout(function() {
- that.getBLEServices(deviceId)
- }, 2000)
- } else {
- console.log(res)
- }
- //连接成功 关闭搜索
- that.stopFindBule()
- },
- })
- },
- getBLEServices(_deviceId) {//获取蓝牙设备所有服务(service)
- var that = this;
- let deviceId = _deviceId
- uni.getBLEDeviceServices({
- // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
- deviceId: deviceId,
- complete(res) {
- console.log(res)
- let serviceId = ""
- for (var s = 0; s < res.services.length; s++) {
- console.log(res.services[s].uuid)
- let serviceId = res.services[s].uuid
- uni.getBLEDeviceCharacteristics({
- // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
- deviceId: deviceId,
- // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
- serviceId: serviceId,
- success(res) {
- var re = JSON.parse(JSON.stringify(res))
- console.log('re',re)
- for (var c = 0; c < re.characteristics.length; c++) {
- if (re.characteristics[c].properties.write == true) {
- let uuid = re.characteristics[c].uuid
- console.log(' deviceId = [' + deviceId + '] serviceId = [' + serviceId + '] characteristics=[' + uuid)
- for (var index in that.devices) {
- if (that.devices[index].deviceId == deviceId) {
- that.devices[index].services.push({
- serviceId: serviceId,
- characteristicId: uuid
- })
- break
- }
- }
- that.bool = false
- console.log(JSON.stringify(that.devices))
-
- }
- }
- }
- })
- }
- },
- fail(res) {
- console.log(res)
- },
- })
- },
- senBlData(deviceId, serviceId, characteristicId, uint8Array) {
- var that = this
- var uint8Buf = Array.from(uint8Array);
- function split_array(datas, size) {
- uni.showLoading({
- title:'打印中..',
- })
- var result = {};
- var j = 0
- if (datas.length < size) {
- size = datas.length
- }
- for (var i = 0; i < datas.length; i += size) {
- result[j] = datas.slice(i, i + size)
- j++
- }
- // result[j] = datas
- console.log('打印result',result,j)
- that.disBoll = j
- return result
- }
- var sendloop = split_array(uint8Buf, 20);
- function realWriteData(sendloop, i) {
- console.log('发送数据2',sendloop, i)
- if(that.disBoll===i){
- that.disabled = false
- uni.hideLoading()
- console.log('此处设置为false',that.disabled)
- }
- var data = sendloop[i]
- if (typeof(data) == "undefined") {
- return
- }
- var buffer = new ArrayBuffer(data.length)
- var dataView = new DataView(buffer)
- for (var j = 0; j < data.length; j++) {
- dataView.setUint8(j, data[j]);
- }
- uni.writeBLECharacteristicValue({
- deviceId,
- serviceId,
- characteristicId,
- value: buffer,
- success(res) {
- realWriteData(sendloop, i + 1);
- // if(uni.getSystemInfoSync().platform == 'ios'){
- // console.log('ios系统')
- // setTimeout(() =>{
-
- // },50)
- // }else if(uni.getSystemInfoSync().platform == 'android'){
- // console.log('android系统')
- // realWriteData(sendloop, i + 1);
- // }
- },
- fail(e) {
- uni.showToast({
- title:"发送数据失败",
- icon:'error',
- duration:'5000'
- })
- console.log(e)
- }
- })
- }
- var i = 0;
- realWriteData(sendloop, i);
- // if(uni.getSystemInfoSync().platform == 'ios'){
- // console.log('ios系统')
- // setTimeout(() =>{
-
- // },50)
- // }else if(uni.getSystemInfoSync().platform == 'android'){
- // console.log('android系统')
- // var i = 0;
- // realWriteData(sendloop, i);
- // }
- },
- senBleLabel2() {
- console.log('=======================================')
- console.log(this.wdList)
- //票据模式
- if(this.onConns){
- uni.showToast({
- title:'打印机未连接哦',
- icon:'none'
- })
- }else if(this.bool){
- uni.showToast({
- title:'正在读取数据...',
- icon:'none'
- })
- }else{
- uni.hideLoading()
- this.disabled = true
- console.log('此处设置为true',this.disabled)
- var Arr1 = []//T1数据
- var Arr2 = []//T2数据
- var Arr3 = []//T3数据
- var Arr4 = []//T4数据
- this.wdList.forEach(function(item,index){
- Arr1.push(item.T1)
- Arr2.push(item.T2)
- Arr3.push(item.T3)
- Arr4.push(item.T4)
- })
- if(Arr2[0]==null && Arr3[0]==null && Arr4[0]==null){
- console.log('等于一个探头')
- var wenyu = this.PrinList.T_Tlower+'~'+this.PrinList.T_Tupper//温度阈值
- var shiyu = this.PrinList.T_RHlower+'~'+this.PrinList.T_RHupper//湿度阈值
- this.getCurrentTime()
- let deviceId = this.currDev.deviceId;
- let serviceId = this.currDev.services[0].serviceId;
- let characteristicId = this.currDev.services[0].characteristicId;
- var tm1 = this.wdList[0].T_time
- var tm2 = this.wdList[this.wdList.length-1].T_time
-
- var staTime = tm1.slice(0,tm1.length-3)
- var endTime = tm2.slice(0,tm2.length-3)
-
- var command = esc.jpPrinter.createNew()
- command.init()
- command.setText("#冷链记录单");
- command.setPrint();
- command.setText(`${this.Admin_name}`);
- command.setPrint();
- command.setText(`送货单位:${this.songhuo===null?'':this.songhuo}`);
- command.setPrint();
- command.setText(`收货单位:${this.shouhuo===null?'':this.shouhuo}`);
- command.setPrint();
- // command.setText(`打印时间:${this.dangTime}\n`);
- command.setText(`-------------------------------`);
- command.setPrint();
- command.setText(`设备号:${this.PrinList.T_sn}`);
- command.setPrint();
- command.setText(`标识名:${this.PrinList.T_devName}`);
- command.setPrint();
- command.setText(`温度阈值:${wenyu}°C`);
- command.setPrint();
- if(this.Admin_rh===1){
- command.setText(`湿度阈值:${shiyu}Rh`);
- command.setPrint();
- }
- command.setText(`-------------------------------`);
- command.setText("探头");
- command.setAbsolutePrintPosition(50);
- command.setText("|");//20
- command.setAbsolutePrintPosition(70);
- command.setText("最大值");//80
- command.setAbsolutePrintPosition(150);
- command.setText("|");//----80
- command.setAbsolutePrintPosition(170);
- command.setText("最小值");//80
- command.setAbsolutePrintPosition(250);
- command.setText("|");//20
- command.setAbsolutePrintPosition(270);
- command.setText("平均值");
- command.setPrint()
-
-
- command.setText("T1");
- command.setAbsolutePrintPosition(50);
- command.setText("|");//20
- command.setAbsolutePrintPosition(70);
- command.setText(`${this.maxData[0].Maxwen==''?'----':parseFloat(this.maxData[0].Maxwen).toFixed(1)}`);//80
- command.setAbsolutePrintPosition(150);
- command.setText("|");//----80
- command.setAbsolutePrintPosition(170);
- command.setText(`${this.maxData[0].Minwen==''?'----':parseFloat(this.maxData[0].Minwen).toFixed(1)}`);//80
- command.setAbsolutePrintPosition(250);
- command.setText("|");//20
- command.setAbsolutePrintPosition(270);
- command.setText(`${this.maxData[0].pingjue==''?'----':this.maxData[0].pingjue}`);
- command.setPrint()
- command.setText(`-------------------------------`);
- command.setPrint()
- let times = ''
- let dataTM = [] //筛选出日期
- let _this = this
- let array = this.wdList
- console.log('检查数据包array',array)
- for(var i=0;i<array.length;i++){
- if (times.substr(0, 10) != array[i].T_time.substr(0, 10)) {
- times = array[i].T_time.substr(0, 10);
- if (array[i].T_time.substr(0, 10) != _this.times) {
- dataTM.push(times)
- }
- }
- }
- const set = new Set(dataTM); //[1,1,1,2,2,3,4]
- dataTM = [...set] //去除重复的数据
- console.log('检查数据包dataTM',dataTM)
- for(var i=0;i<dataTM.length;i++){
- command.setPrint()
- command.setText(`日期:${dataTM[i]} (单位:°C)`)
- command.setPrint()
- if(Arr2[0]==null && Arr3[0]==null && Arr4[0]==null){
- command.setText("时间");
- command.setAbsolutePrintPosition(75);
- command.setText("|");//20
- command.setAbsolutePrintPosition(100);
- command.setText("T1");//80
- command.setAbsolutePrintPosition(160);
- command.setText("||");//----80
- command.setAbsolutePrintPosition(200);
- command.setText("时间");//80
- command.setAbsolutePrintPosition(275);
- command.setText("|");//20
- command.setAbsolutePrintPosition(300);
- command.setText("T1");
- command.setPrint()
- }else{
- command.setText("时间");
- command.setAbsolutePrintPosition(75);
- command.setText("|");//20
- command.setAbsolutePrintPosition(100);
- command.setText("T1");//80
- command.setAbsolutePrintPosition(160);
- command.setText("|");//----80
- command.setAbsolutePrintPosition(200);
- command.setText("T2");//80
- command.setAbsolutePrintPosition(275);
- command.setText("|");//20
- command.setAbsolutePrintPosition(300);
- command.setText("T3");
- command.setAbsolutePrintPosition(360);
- command.setText("T4");
- command.setPrint()
- }
- // var xc_l = Math.ceil(array.length / 2);
- var xc_l_j = 0
- // console.log("xc_l:",xc_l)
- for(var j=0;j<array.length;j++){
- console.log('dayin',array[j].T1.times1)
- if (dataTM[i] != array[j].T_time.substr(0,10)) {
- continue;
- }
- if(xc_l_j == 0 ){
- command.setText(`${array[j].T1.times1}`);
- command.setAbsolutePrintPosition(75);
- command.setText("|");
- command.setAbsolutePrintPosition(100);
- command.setText(`${array[j].T1==null?'----':parseFloat(array[j].T1.T_t).toFixed(1)}`);
- command.setAbsolutePrintPosition(160);
- command.setText("||");
- xc_l_j =1
- }else{
- command.setAbsolutePrintPosition(200);
- command.setText(`${array[j].T1.times1}`);
- command.setAbsolutePrintPosition(275);
- command.setText("|");
- command.setAbsolutePrintPosition(300);
- command.setText(`${array[j].T1==null?'----':parseFloat(array[j].T1.T_t).toFixed(1)}`);
- command.setPrint()
- xc_l_j =0
- }
- }
- // 强行换行
- if(xc_l_j == 1){
- command.setPrint()
- xc_l_j =0
- }
- }
- command.setText(`-------------------------------`);
- command.setPrint()
- command.setText(`开始时间:${staTime}`);
- command.setPrint()
- command.setText(`结束时间:${endTime}`);
- command.setPrint()
- command.setText(`-------------------------------`);
- command.setPrint()
- command.setText(`配送人:`);
- command.setPrint()
- command.setPrint()
- command.setText(`接收人:`);
- command.setPrint()
- command.setPrint()
- command.setPrint()
- command.setPrintAndFeedRow(1)
- this.senBlData(deviceId, serviceId, characteristicId, command.getData())
- }else{
- console.log('大于一个探头')
- var wenyu = this.PrinList.T_Tlower+'~'+this.PrinList.T_Tupper//温度阈值
- var shiyu = this.PrinList.T_RHlower+'~'+this.PrinList.T_RHupper//湿度阈值
- var staTime = this.wdList[0].T_time
- var endTime = this.wdList[this.wdList.length-1].T_time
- this.getCurrentTime()
- let deviceId = this.currDev.deviceId;
- let serviceId = this.currDev.services[0].serviceId;
- let characteristicId = this.currDev.services[0].characteristicId;
- var command = esc.jpPrinter.createNew()
- command.init()
- command.setText(`#冷链记录单`);
- command.setPrint();
- command.setText(`${this.Admin_name}`);
- command.setPrint();
- command.setText(`送货单位:${this.songhuo===null?'':this.songhuo}`);
- command.setPrint();
- command.setText(`收货单位:${this.shouhuo===null?'':this.shouhuo}`);
- command.setPrint();
- // command.setText(`打印时间:${this.dangTime}\n`);
- command.setText(`-------------------------------`);
- command.setPrint();
- command.setText(`设备号:${this.PrinList.T_sn}`);
- command.setPrint();
- command.setText(`标识名:${this.PrinList.T_devName}`);
- command.setPrint();
- command.setText(`温度阈值:${wenyu}°C`);
- command.setPrint();
- if(this.Admin_rh==1){
- command.setText(`湿度阈值:${shiyu}Rh`);
- command.setPrint();
- }
- command.setText(`-------------------------------`);
- command.setPrint();
-
- command.setText("探头");
- command.setAbsolutePrintPosition(50);
- command.setText("|");//20
- command.setAbsolutePrintPosition(70);
- command.setText("最大值");//80
- command.setAbsolutePrintPosition(150);
- command.setText("|");//----80
- command.setAbsolutePrintPosition(170);
- command.setText("最小值");//80
- command.setAbsolutePrintPosition(250);
- command.setText("|");//20
- command.setAbsolutePrintPosition(270);
- command.setText("平均值");
- command.setPrint()
-
- for(var i= 0 ;i<this.maxData.length;i++){
- console.log('开始打印',this.maxData[i])
- command.setText("T"+(i+1));
- command.setAbsolutePrintPosition(50);
- command.setText("|");//20
- command.setAbsolutePrintPosition(70);
- command.setText(`${this.maxData[i].Maxwen==''?'---':parseFloat(this.maxData[i].Maxwen).toFixed(1)}`);//80
- command.setAbsolutePrintPosition(150);
- command.setText("|");//----80
- command.setAbsolutePrintPosition(170);
- command.setText(`${this.maxData[i].Minwen==''?'---':parseFloat(this.maxData[i].Minwen).toFixed(1)}`);//80
- command.setAbsolutePrintPosition(250);
- command.setText("|");//20
- command.setAbsolutePrintPosition(270);
- command.setText(`${this.maxData[i].pingjue==''?'---':this.maxData[i].pingjue}`);
- command.setPrint()
- }
- command.setText(`-------------------------------`);
- let times = ''
- let dataTM = [] //筛选出日期
- let _this = this
- let array = this.wdList//数据包this.wdList 已经在data函数反转.reverse() 最早一条在最前面 最新一条在最后面
- for(var i=0;i<array.length;i++){
- if (times.substr(0, 10) != array[i].T_time.substr(0, 10)) {
- times = array[i].T_time.substr(0, 10);
- if (array[i].T_time.substr(0, 10) != _this.times) {
- dataTM.push(times)
- }
- }
- }
- const set = new Set(dataTM); //[1,1,1,2,2,3,4]
- dataTM = [...set] //去除重复的数据
- for(var i=0;i<dataTM.length;i++){
- command.setPrint()
- command.setText(`日期:${dataTM[i]} (单位:°C)\n`)
- command.setText("时间");
- command.setAbsolutePrintPosition(70);
- command.setText("|");//20
- command.setAbsolutePrintPosition(90);
- command.setText("T1");//80
- command.setAbsolutePrintPosition(140);
- command.setText("|");//----80
- command.setAbsolutePrintPosition(160);
- command.setText("T2");//80
- command.setAbsolutePrintPosition(210);
- command.setText("|");//20
- command.setAbsolutePrintPosition(230);
- command.setText("T3");
- command.setAbsolutePrintPosition(280);
- command.setText("|");//20
- command.setAbsolutePrintPosition(300);
- command.setText("T4");
- command.setPrint()
- for(var j=0;j<array.length;j++){
- if (dataTM[i] == array[j].T_time.substr(0,10)) { //根据你遍历的年月日和数据里面的日期进行对比,满足就是那个日期的数据,打印对应的数据应该就可以了
- command.setText(`${array[j].T1.times1}`);
- command.setAbsolutePrintPosition(70);
- command.setText("|");//20
- command.setAbsolutePrintPosition(90);
- command.setText(`${array[j].T1==null?'---':parseFloat(array[j].T1.T_t).toFixed(1)}`);//80
- command.setAbsolutePrintPosition(140);
- command.setText("|");//----80
- command.setAbsolutePrintPosition(160);
- command.setText(`${array[j].T2==null?'---':parseFloat(array[j].T2.T_t).toFixed(1)}`);//80
- command.setAbsolutePrintPosition(210);
- command.setText("|");//20
- command.setAbsolutePrintPosition(230);
- command.setText(`${array[j].T3==null?'---':parseFloat(array[j].T3.T_t).toFixed(1)}`);
- command.setAbsolutePrintPosition(280);
- command.setText("|");//20
- command.setAbsolutePrintPosition(300);
- command.setText(`${array[j].T4==null?'---':parseFloat(array[j].T4.T_t).toFixed(1)}`);
- command.setPrint()
- }
- }
- }
- command.setText(`-------------------------------\n`);
- command.setText(`开始时间:${staTime}\n`);
- command.setText(`结束时间:${endTime}\n`);
- command.setText(`-------------------------------\n`);
- command.setText(`配送人:\n`);
- command.setText(`\n`);
- command.setText(`接收人:\n`);
- command.setText(`\n`);
- command.setText(`\n`);
- command.setPrintAndFeedRow(1)
- this.senBlData(deviceId, serviceId, characteristicId, command.getData())
- }
- }
- },
- }
- }
- </script>
- <style lang="scss">
- .bluetooths {
- padding: 10px 20px;
- .bluetooths_btn {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 15px 0;
- background: #fff;
- border-bottom: 1px solid #F1F1F1;
- .bluetooths_txt1 {
- font-size: 30rpx;
- font-weight: bold;
- color: #007AFF;
- }
- }
- .blueBTn {
- font-size: 25rpx;
- flex: 1;
- }
- }
- .text-red {
- margin-top: 20px;
- color: #7c7a7b;
- font-size: 30rpx;
- }
- </style>
|