<!-- 新增库存页 -->
<template>
	<view class="page1" style="padding-bottom: 120rpx;">
		<view style="display: flex;">
			<view class="box" style="margin: 20rpx 10rpx 0;">
				<view class="title-box">
					<view style="display: flex;border-bottom: 1px solid #eee;">
						<view style="width: 70%;">
							<view class="circle">
								发货人
							</view>
						</view>
						<view @tap.stop="addressBook('ji')" class="add-book">
							地址簿
						</view>
					</view>
					<view style='width: 100%;padding-left: 5px;'>
						<!-- <text>{{voiceData.shipperName}}</text>
						<text style="padding-left: 5px;">{{voiceData.shipperMobile}}</text> -->
						<view v-if="newFa" class="new-circle">
							新
						</view>
						<view style="display: flex;border-bottom: 1px solid #eee;">
							<view style="width: 26%;">
								名称:
							</view>
							<input type="text" v-model="voiceData.shipperName" @input="sreachName($event,'ji')"
								@focus="inputFocus($event,'fa')" placeholder="请输入名称"
								class="title-input" />
						</view>
						<view style="display: flex;border-bottom: 1px solid #eee;">
							<view style="width: 26%;">
								电话:
							</view>
							<input type="number" v-model="voiceData.shipperMobile" placeholder="请输入电话" class="title-input" />
						</view>
						<view style="display: flex;border-bottom: 1px solid #eee;">
							<view style="width: 26%;">
								地址:
							</view>
							<input type="text" v-model="voiceData.shipperAddress" placeholder="请输入地址" class="title-input" />
						</view>
						<view v-if="voiceData.newShipperName !=''" @tap="checkNewPeople('fa')" class="new-user">
							{{voiceData.newShipperName}}(更换)
						</view>
					</view>
				</view>
				<view @tap="faBookShow = false" v-if="faBookShow" style="z-index:98;position: fixed;top: 0;left: 0;width: 100%;height: 100%;">
					<view class="book-mask" v-if="faBookShow" style="position: absolute;top: 15%;left:5%;">
						<view v-if="customList.length == 0"
							style="color: #777;width: 100%;height: 70rpx;line-height: 70rpx;text-align: center;">
							暂无匹配项
						</view>
						<view v-for="(item,index) in customList" :key="index" @tap="checkName(item,'fa')" v-else
							style="height: 70rpx;line-height: 70rpx;">
							{{item.shipperOrReceiverName}} {{item.mobile == null ? '' : item.mobile}} {{item.addressInfo == null ? '' : item.addressInfo}}
						</view> 
					</view>
				</view>
			</view>
			<view class="box" style="margin: 20rpx 10rpx 0;">
				<view class="title-box">
					<view style="display: flex;border-bottom: 1px solid #eee;">
						<view style="width: 70%;">
							<view class="circle">
								收货人
							</view>
						</view>
						<view @tap.stop="addressBook('shou')" class="add-book">
							地址簿
						</view>
					</view>
					<view style='width: 100%;padding-left: 5px;'>
						<!-- <text>{{voiceData.shipperName}}</text>
						<text style="padding-left: 5px;">{{voiceData.shipperMobile}}</text> -->
						<view v-if="newShou" class="new-circle">
							新
						</view>
						<view style="display: flex;border-bottom: 1px solid #eee;">
							<view style="width: 26%;">
								名称:
							</view>
							<input type="text" @input="sreachName($event,'shou')" v-model="voiceData.receiverName"
								@focus="inputFocus($event,'shou')" placeholder="请输入名称"
								class="title-input" />
						</view>
						<view style="display: flex;border-bottom: 1px solid #eee;">
							<view style="width: 26%;">
								电话:
							</view>
							<input type="number" v-model="voiceData.receiverMobile"  placeholder="请输入电话"
								class="title-input" />
						</view>
						<view style="display: flex;border-bottom: 1px solid #eee;">
							<view style="width: 26%;">
								地址:
							</view>
							<input type="text" v-model="voiceData.receiverAddress" placeholder="请输入地址" class="title-input" />
						</view>
						<view v-if="voiceData.newReceiverName !=''" @tap="checkNewPeople('shou')" class="new-user">
							{{voiceData.newReceiverName}}(更换)
						</view>
					</view>
				</view>
				<view @tap="shouBookShow = false" v-if="shouBookShow" style="z-index:98;position: fixed;top: 0;left: 0;width: 100%;height: 100%;">
					<view class="book-mask" v-if="shouBookShow" style="position: absolute;top: 15%;left:30%;">
						<view v-if="customList.length == 0"
							style="color: #777;width: 100%;height: 70rpx;line-height: 70rpx;text-align: center;">
							暂无匹配项
						</view>
						<view v-for="(item,index) in customList" :key="index" @tap="checkName(item,'shou')" v-else
							style="height: 70rpx;line-height: 70rpx;">
							{{item.shipperOrReceiverName}} {{item.mobile == null ? '' : item.mobile}} {{item.addressInfo == null ? '' : item.addressInfo}}
						</view> 
					</view>
				</view>
				
			</view>
		</view>
		<view class="box">
			<view class="content" style="display: none;">
				<view class="name-box">出发站</view>
				<view style="width: 80%;">
					<uni-data-select class="uni-data-select" :localdata="goStationList" v-model="voiceData.goStationId"
						placeholder="出发站" :clear="false" @change="goStationChange" style="width: 60%;">
					</uni-data-select>
				</view>
			</view>
			<view class="content">
				<view class="name-box" style="float: left;">始发站</view>
				<view style="width: 80%;float: left;">
					<input type="text" v-model="voiceData.goStationName" placeholder="请输入始发站" class="input-box">
				</view>
			</view>
			<view class="content">
				<view class="name-box" style="float: left;">到达站</view>
				<view style="width: 80%;float: left;">
					<uni-combox style="width: 60%;height: 76rpx !important;"
					      label=" " 
					      v-model="voiceData.arrivalStationName" 
					      :candidates="arrivalStationList1" 
					      placeholder="请输入或选择到达站" 
					      @input="arrivalStationChange"
					    ></uni-combox>
				</view>
			</view>
			<view class="content" style="min-height: 80rpx;">
				<view class="name-box" style="float: left;">中转站</view>
				<view style="width: 80%;float: left;">
					<view v-for="(item,index) in transferStationList" :key='index' style="display: flex;">
						<view style="flex: 1;">{{item.goStation}}——{{item.arrivalStation}}</view>
						<view style="flex: 1;">运费：{{item.transitFee}}</view>
					</view>
				</view>
			</view>
			<view class="content">
				<view class="name-box" style="float: left;">中转另付</view>
				<view style="width: 60%;float: left;">
					<radio-group style="display: flex;">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in priceItems"
							:key="item.value" style="margin-right:0">
							<view>
								<radio :value="item.value" @tap.stop="priceChange(item.value,index)"
									:checked="index === priceCurrent" />
							</view>
							<view style="width: 100rpx;">{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view @tap.stop="getGuadan()" class="add-book" style="float: right;">
					<!-- <img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/2ae0487e2a2e408197daa4cee3fbed07.png"
						alt="" style="width: 53rpx;height: 64rpx;padding-top: 13rpx;float: right;"/> -->
					挂单列表
				</view>
			</view>
			<view class="content" style="display: flex;width:100%;">
				<view @tap="kuaijieName('fuzhuang')" class="kuaijie">服装</view>
				<view @tap="kuaijieName('xiezi')" class="kuaijie">鞋子</view>
				<view @tap="kuaijieName('qita')" class="kuaijie">其他</view>
				<view style="height: 60rpx;line-height: 60rpx;font-size: 26rpx;font-weight: bold;margin: 5rpx auto;">*点击快捷选择物品名称</view>
			</view>
			<view class="content">
				<view class="name-box" style="width: 18%;float: left;">物品名</view>
				<view style="width: 33%;float: left;">
					<input type="text" v-model="voiceData.objectName" @focus="kuaijieFocus" @blur="kuaijieBlur" placeholder="请输入物品名" class="input-box">
				</view>
				<view class="name-box" style="float: left;width: 18%;font-weight: bold;">总费用</view>
				<view style="width: 26%;float: left;">
					<input type="digit" v-model="voiceData.allCost" @blur="getAllCost($event,'zongfeiyong')"
						@focus="obtainPrice($event,'zongfeiyong')" placeholder="请输入总费用" class="input-box">
				</view>
			</view>
			<view class="content">
				<view class="name-box" style="width: 21%;float: left;height: 80rpx;">重量(KG)</view>
				<view style="width: 19%;float: left;height: 80rpx;">
					<input type="digit" @focus="obtainPrice($event,'zhongliang')" @blur="freightCount"
						v-model="voiceData.weight" class="input-box">
						
				</view>
				<view class="name-box" style="width: 11%;float: left;height: 80rpx;">
					<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/d66b96dbcfab426aa4346f26f297ffb4.png"
						alt="" style="width: 53rpx;height: 64rpx;padding-top: 13rpx;" @tap.stop="addWeight()" />
				</view>
				<view class="name-box" style="float: left;width: 17%;">数量</view>
				<view style="width: 27%;float: left;">
					<input type="number" @blur="shuliangChange($event)"
						@focus="obtainPrice($event,'shuliang')" v-model="voiceData.count" class="input-box">
				</view>
				
			</view>
			<view class="content">
				<view class="name-box" style="float: left;width: 21%;">运输费</view>
				<view style="width: 30%;float: left;">
					<input type="digit" @blur="getAllCost($event,'yunshufei')"
						@focus="obtainPrice($event,'yunshufei')" v-model="voiceData.freight" class="input-box">
				</view>
				<view class="name-box" style="width: 17%;float: left;">中转费</view>
				<view style="width: 27%;float: left;">
					<input type="digit" @blur="getAllCost($event,'zhongzhuanfei')" @focus="obtainPrice($event,'zhongzhuanfei')"
						v-model="voiceData.transitFee" class="input-box">
				</view>
				
			</view>
			<view class="content">
				<view class="name-box" style="float: left;width: 21%;">落地费</view>
				<view style="width: 30%;float: left;">
					<input type="digit" @blur="getAllCost($event,'luodifei')" @focus="obtainPrice($event,'luodifei')"
						v-model="voiceData.landingFee" class="input-box">
				</view>
				<view class="name-box" style="float: left;width: 17%;">送货费</view>
				<view style="width: 27%;float: left;">
					<input type="digit" @blur="getAllCost($event,'songhuofei')" @focus="obtainPrice($event,'songhuofei')"
						v-model="voiceData.deliveryFee" class="input-box">
				</view>
			</view>
			<view class="content">
				<view class="name-box" style="width: 21%;float: left;">小费</view>
				<view style="width: 30%;float: left;">
					<input type="digit" @blur="getAllCost($event,'xiaofei')" @focus="obtainPrice($event,'xiaofei')"
						v-model="voiceData.tips" class="input-box">
				</view>
				<view class="name-box" style="float: left;width: 17%;">保费</view>
				<view style="width: 27%;float: left;">
					<input type="digit" @blur="getAllCost($event,'baofei')" @focus="obtainPrice($event,'baofei')"
						v-model="voiceData.premium" class="input-box">
				</view>
			</view>
			<view class="content">
				<view class="name-box" style="float: left;width: 21%;">工本费</view>
				<view style="width: 30%;float: left;">
					<input type="digit" @blur="getAllCost($event,'gongbenfei')" @focus="obtainPrice($event,'gongbenfei')"
						v-model="voiceData.cost" class="input-box">
				</view>
				<view class="name-box" style="float: left;width: 17%;">标签数</view>
				<view style="width: 27%;float: left;">
					<input type="digit" v-model="printcount" class="input-box">
				</view>
			</view>
			<view style="display: flex;width: 100%;">
				<view class="content" style="width: 50%;">
					<view class="name-box" style="width: 41%;float: left;">结算方式</view>
					<view style="width: 52%;float: left;">
						<uni-data-select class="uni-data-select" :localdata="payTypeList"
							v-model="voiceData.methodOfSettlement" placeholder="结算方式" :clear="false"
							@change="payTypeChange" style="width: 60%;">
						</uni-data-select>
					</view>
				</view>
				<view class="content" style="width: 50%;">
					<view class="name-box" style="float: left;width: 35%;">接站人</view>
					<view style="width: 62%;float: left;">
						<uni-data-select class="uni-data-select" :localdata="userList" v-model="voiceData.receivingUserId"
							placeholder="接站人" :clear="false" @change="stationUserChange" style="width: 60%;">
						</uni-data-select>
					</view>
				</view>
			</view>
			<view class="content" style="height:150rpx;">
				<view class="name-box" style="float: left;">图片上传</view>
				<view class="upload-img" @tap="pictureAdd"
					style="float: left;background: #eee;text-align: center;line-height: 160rpx;">
					<uni-icons type="camera" size="28" color="#777"></uni-icons>
				</view>
				<view style="float: left;overflow-x: scroll;display: flex;width: 350rpx;">
					<view v-if="productPicture !=''" v-for="(item,index) in productPicture" :key="index"
						style="width: 160rpx;height: 160rpx;margin-left: 20rpx;">
						<img :src="item" alt="" class="upload-img">
					</view>
				</view>
			</view>
		</view>
		<view class="box" style="height: 260rpx;">
			<!-- <view class="content">
				<view class="name-box">代收货款</view>
				<view style="width: 80%;">
					<input type="text" v-model="voiceData.paymentForGoods" placeholder="请输入代收货款" class="input-box">
				</view>
			</view> -->
			<view class="content">
				<view class="name-box" style='float: left;'>备注</view>
				<view style="float: left;width: 80%;height: 220rpx;border: 1.5px solid #eee;border-radius: 10px;">
					<textarea name="" id="" v-model="voiceData.remark" placeholder="请输入备注" cols="30" rows="10" style="width: 100%;height: 200rpx;padding: 20rpx;"></textarea>
				</view>
			</view>
		</view>
		<view class="bottom-btn">
			<view @tap="toggle"
				style="background: linear-gradient(90deg, #FF9797, #FFC1E0);margin: 10rpx auto;height: 80rpx;width: 30%;border-radius: 10px;text-align: center;line-height: 80rpx;">
				语音录入
			</view>
			<view @tap="setGuaBill"
				style="background: linear-gradient(90deg, #FF9797, #FFC1E0);margin: 10rpx auto;height: 80rpx;width: 30%;border-radius: 10px;text-align: center;line-height: 80rpx;">
				挂单
			</view>
			<view @tap="setBill"
				style="background: linear-gradient(90deg, #60F3FF, #088FEB);margin: 10rpx auto;height: 80rpx;width: 30%;border-radius: 10px;text-align: center;line-height: 80rpx;">
				开单
			</view>
		</view>
		<!-- 多个收货人选择弹窗 -->
		<uni-popup ref="moreShouPopup" background-color="#fff" :is-mask-click="true">
			<view class="type-popup" style="margin-bottom: 0;border-radius: 0;">
				<view style="height: 80rpx;font-size: 36rpx;font-weight: bold;line-height: 80rpx;text-align: center;">
					查询到名称相似的收货人
				</view>
				<view class="card-list" style="margin:0 auto;">
					<view class="right-box" v-for="(item,index) in moreShouList" :key='index'>
						<view @tap="clickGetOneShou(item)" style="height: 140rpx;line-height: 70rpx;border-bottom: 1px solid #eee;border-top: 1px solid #eee;padding-left: 20rpx;font-size: 30rpx;font-weight: bold;">
							<view class="">
								姓名:{{item.shipperOrReceiverName == null ?'':item.shipperOrReceiverName}}
							</view>
							<view class="">
								手机号:{{item.mobile == null ?'':item.mobile}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 多个收货人选择弹窗 -->
		<uni-popup ref="moreFaPopup" background-color="#fff" :is-mask-click="true">
			<view class="type-popup" style="margin-bottom: 0;border-radius: 0;">
				<view style="height: 80rpx;font-size: 36rpx;font-weight: bold;line-height: 80rpx;text-align: center;">
					查询到名称相似的发货人
				</view>
				<view class="card-list" style="margin:0 auto;">
					<view class="right-box" v-for="(item,index) in moreFaList" :key='index'>
						<view @tap="clickGetOneFa(item)" style="height: 140rpx;line-height: 70rpx;border-bottom: 1px solid #eee;border-top: 1px solid #eee;padding-left: 20rpx;font-size: 30rpx;font-weight: bold;">
							<view style="">
								姓名:{{item.shipperOrReceiverName == null ?'':item.shipperOrReceiverName}}
							</view>
							<view class="">
								手机号:{{item.mobile == null ?'':item.mobile}}
							</view>
							
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 语音识别弹出层 -->
		<uni-popup ref="popup" background-color="#fff" @change="yuyinChange">
			<view class="voice-popup-content">
				<view class="voice-popup-title">
					<text>语音录入</text>
					<uni-icons @tap='$refs.popup.close()' type="closeempty" color='red' size="16"
						style="height:40rpx;line-height: 40rpx;position: absolute !important;bottom:0;right: 30rpx;"></uni-icons>
				</view>
				<view style="width: 100%;line-height: 40rpx;font-size: 11px;color: #777;">
					示例：
				</view>
				<view
					style="width: 100%;line-height: 40rpx;font-size: 11px;color: #777;display: flex;text-align: center;">
					<view style="flex: 1;">发货人:</view>
					<view style="flex: 1;">发货电话:</view>
				</view>
				<view
					style="width: 100%;line-height: 40rpx;font-size: 11px;color: #777;display: flex;text-align: center;">

					<view style="flex: 1;">收货人:</view>
					<view style="flex: 1;">收货电话:</view>
				</view>
				<view
					style="width: 100%;line-height: 40rpx;font-size: 11px;color: #777;display: flex;text-align: center;">
					<view style="flex: 1;">物品名称:</view>
					<view style="flex: 1;">到达站:</view>
				</view>
				<view
					style="width: 100%;line-height: 40rpx;font-size: 11px;color: #777;display: flex;text-align: center;">
					<view style="flex: 1;">重量:</view>
					<view style="flex: 1;">数量:</view>
				</view>
				<view
					style="width: 100%;line-height: 40rpx;font-size: 11px;color: #777;display: flex;text-align: center;">

					<view style="flex: 1;">小费:</view>
					<view style="flex: 1;">保费:</view>

				</view>
				<view class="voice-popup-container">
					<textarea name="" id="" style="width:100%;height:240rpx;border:1px solid #eee;margin:0;"
						v-model="voiceText" placeholder="请按照示例要求录入信息"></textarea>
					<view>
						<text style="color:red;font-size:22rpx;">*长按“语音”按钮录入，系统将自动识别</text>
					</view>
					<view class="voice-popup-bottom">
						<view class="voice-popup-btn" @tap="clearText">清空</view>
						<view class="voice-popup-btn" @tap="getVoiceData">确认</view>
					</view>
				</view>
				<view class="voice-btn" @touchstart="kaishi" @touchend="jieshu">
					<img src="/static/images/maikefeng.png" style="width: 80%;height: 80%;margin: 10%;" alt="">
				</view>
			</view>
		</uni-popup>
		<view class="voice-model" v-if="recordState == true">
			<img src="/static/images/maikefeng.png" alt="">
			<view class="voice-text">语音识别中...</view>
		</view>
		<view class="mask-model" v-if="isVoice">貌似没有检测到您上次的语音录入信息，正在反复识别中</view>
		<view class="kk-printer">
			<view class="kk-shadow" :class="isShowSearch?'show':''" @tap="handleSearchClose">
				<view class="kk-modal" @tap.stop="doNothing">
					<view class="kk-search-device">
						<view class="kk-btn-wrap">
							<view class="kk-btn-item confirm-btn" @tap="sousuo" v-if="!isSearching">
								搜索设备
							</view>
							<view class="kk-btn-item confirm-btn" v-else>
								搜索中...
							</view>
							<view class="kk-btn-item" @tap="stopSearchBtnTap">
								停止搜索
							</view>
						</view>
						<view class="kk-devices-wrap">
							<view class="empty-wrap" v-if="devicesList.length <= 0">
								<view class="empty-icon"></view>
								<view class="empty-text">无可搜索到的设备</view>
							</view>
							<view class="" v-else>
								<view class="kk-devices-item" v-for="(item,index) in devicesList" :key="index">
									<view @tap="lianejieshebei(item.deviceId)" class="name" style="color:#000;display: flex;flex-direction: column;">
										<text>设备名称：</text>
										<text>{{item.name?item.name:'未命名'}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="shopPopup" background-color="#fff">
			<view class="shop-popup-content" style="height: 1100rpx;">
				<view class="shop-popup-container" style="position: relative;">
					<ul class="inventoryList" style="height:1100rpx;overflow: scroll;" v-if="orderList.length > 0">
						<li v-for="(item,index) in orderList" :key="index">
							<uni-card :title="item.companyName == null ?'暂无':item.companyName"
								:sub-title="item.createTime" :extra="'￥'+(item.allCost == null ?'暂无':item.allCost)">
								<view class="uni-body"> 
									<text class="cardText">单号：</text>
									{{item.orderNumber}}
								</view>
								<view class="uni-body">
									<text class="cardText">到达站：</text>
									{{item.arrivalStationName}}
								</view>
								<view class="uni-body">
									(发){{ item.shipperName == null ?'暂无':item.shipperName}} -
									(收){{ item.receiverName == null ?'暂无':item.receiverName }}
								</view>
								<view class="uni-body"> 
									<text class="cardText">重量：{{item.weight}}</text>
									<text class="cardText" style="padding-left: 20rpx;">件数：{{item.count}}</text>
								</view>
								<view class="uni-body">
									<text class="cardText">接站人：{{item.receivingUserName}}</text>
								</view>
								<view @tap.stop="goAddOrderPage(item)" style="position: absolute;bottom: 20rpx;right:  20rpx;color: #00B5FF;">
									修改订单
								</view>
								<view @tap.stop="delOrder(item)" style="position: absolute;bottom: 100rpx;right:  20rpx;color: #00B5FF;">
									删除订单
								</view>
								<view v-if="item.changeCount != '0'" style="position: absolute;top: 140rpx;right: 20rpx;color: #00B5FF;">
									修改次数:{{item.changeCount}}
								</view>
							</uni-card>
						</li>
					</ul>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="inputDialog" background-color="#fff" :is-mask-click="true">
			<view class="type-popup" style="min-height: 270rpx;!important">
				<view style="height: 100rpx;font-size: 36rpx;font-weight: bold;line-height: 120rpx;text-align: center;">
					增加重量
				</view>
				<view v-if="voiceData.weightHistory !=''" style="width: 95%;font-size: 13px;font-weight: bold;line-height: 45rpx;text-align: center;overflow-wrap: break-word;">
					{{voiceData.weightHistory}}
				</view>
				<uni-forms :modelValue="addForm" ref="addForm" validateTrigger="bind" :rules="rules" label-width="130rpx"
					label-align="right">
					<view class="name-box" style="width: 30%;float: left;height: 80rpx;margin-top: 40rpx;">重量(KG)</view>
					<view style="width: 65%;float: left;height: 80rpx;margin-top: 20rpx;">
						<input type="digit" @focus="obtainPrice($event,'zhongliangAdd')" v-model="weigthAdd"  @blur="addWeight1" class="input-box">
					</view>
				</uni-forms>
				<view
					style="width: 100%;height: 90rpx;line-height: 90rpx;text-align: center;border-radius: 0;background: linear-gradient(90deg, #60F3FF, #088FEB);color: #fff;display: flex;">
					<view style="width:50%;" @tap="$refs.inputDialog.close()">取消</view>
					<view style="width:50%;background: linear-gradient(90deg, #FF9797, #FFC1E0);"
						@tap="$refs.inputDialog.close()">确认</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	var plugin = requirePlugin("WechatSI")
	let manager = plugin.getRecordRecognitionManager()
	import * as blesdk from '@/components/kk-printer/utils/bluetoolth.js';
	import gbk from '@/components/kk-printer/utils/printUtil-GBK.js';
	export default {
		data() {
			return {
				faBookShow: false,
				weightCount:1,
				printcount:'',
				shouBookShow: false,
				moreShouList:[],
				weigthAdd:'',
				moreFaList:[],
				newFa:false,
				orderList:[],
				daodaList:[],
				newShou:false,
				linshiPrice: 0,
				addForm: {
					nickName: '',
					mobile: '',
					address: ''
				},
				pageNum: 1,
				bufferData: [],
				voiceText: '',
				addressType: '',
				isVoice: false,
				priceCurrent: 0,
				arrivalStationList1:[],
				priceItems: [{
					value: 0,
					name: '否'
				}, {
					value: 1,
					name: '是'
				}],
				arrivalStationList: [],
				goStationList: [],
				payTypeList: [{
					value: "0",
					text: "现金"
				}, {
					value: "1",
					text: "月付"
				}, {
					value: "2",
					text: "提付"
				}],
				userData: {},
				//是否正在搜索设备
				isSearching: false,
				//是否显示蓝牙列表
				isShowSearch: false,
				//设备列表
				devicesList: [],
				//连接的设备ID
				deviceId: '',
				//根据设备ID获取的服务
				services: '',
				//获取特征值时返回的三要素
				serviceId: '',
				deviceType: 'ios',
				voiceDataPrint:{},
				voiceData: {
					createBy: uni.getStorageSync('contacts'),
					companyId: uni.getStorageSync('transCompany'),
					companyName: uni.getStorageSync('companyName'),
					imagePath: '',
					weightHistory:'',
					circuitId: '', // 线路id
					circuitName: '', // 线路名称
					shipperName: '', // 发货人名-
					shipperMobile: '', // 发货人电话-
					shipperAddress: '', // 发货人地址
					receiverName: '', // 收货人名-
					receiverMobile: '', // 收货人电话-
					receiverAddress: '', // 收货人地址
					newReceiverName:"",
					newShipperName:"",
					goStationId: '', // 出发站id-
					goStationName: '沧州', // 出发站名称-
					arrivalStationId: '', // 到达站id-
					arrivalStationName: '', // 到达站名称-
					landingFee: 0, //落地费
					deliveryFee: 0, //送货费
					weight: 0, // 重量-
					count: 1, // 件数-
					freight: 0, // 运输费-
					premium: 0, // 保费-
					transitFee: 0, // 中转费
					transferAddition: 0,
					paymentForGoods: 0, // 代收货款
					tips: 0, // 拉包小费
					methodOfSettlement: "2", // 结算方式
					cost: 0, // 工本费
					allCost: 0, // 总费用
					orderNumber: '', // 票号
					objectName: '', // 物体名称
					remark: '', // 备注
					receivingUserId: '', // 收货站人id
					receivingUserName: '' // 收货站人名称
				},
				recordState: false,
				userList: [],
				isEdit: false,
				transferStationList: [],
				productPicture: [],
				customList: [],
				shopRemark:[],
			}
		},
		onShow() {
			let that = this
			uni.getSystemInfo({
				success(res) {
					that.deviceType = res.osName
				},
				fail(err) {
					
				}
			})
			if(uni.getStorageSync('transCompany') == '1751796589518786560' || uni.getStorageSync('transCompany') == '1899371352842964992' || uni.getStorageSync('transCompany') == '1782981706819702784'){
				// 初始化蓝牙模块
				wx.openBluetoothAdapter({ //111
					mode: 'central',
					success: (res2) => {
						wx.createBLEConnection({ //555
							deviceId: uni.getStorageSync('deviceId'), // 搜索到设备的 deviceId
							success: () => {
							},
							fail: (res) => {
								
							}
						})
					},
					fail: (res) => {
						
						if (res.errCode == '10001') {
							
							// that.tui.toast('请打开蓝牙后，再进行连接')
							uni.showToast({
								duration: 2000,
								title: "请打开蓝牙后，再进行连接",
								icon: 'none',
								mask: true
							})
						} else {
							that.tui.toast('连接失败，请重启蓝牙或删除小程序重新进入-1')
							
							that.isShowSearch = true
						}
						setTimeout(res => {
							uni.hideLoading();
						}, 2000)
					}
				})
			}
			uni.authorize({
				scope: 'scope.record',
				success() {

				},
				fail() {
					this.tui.toast("您未授权，语音功能可能会出现错误")
				}
			})
			
			if (this.userData) {
				if (this.userData.userType == 'ji') {
					this.voiceData.shipperName = this.userData.shipperOrReceiverName
					this.voiceData.shipperMobile = this.userData.mobile
					this.voiceData.shipperAddress = this.userData.addressInfo
					this.voiceData.shipperId = this.userData.id
				} else if (this.userData.userType == 'shou') {
					this.voiceData.receiverName = this.userData.shipperOrReceiverName
					this.voiceData.receiverMobile = this.userData.mobile
					this.voiceData.receiverAddress = this.userData.addressInfo
					this.voiceData.receiverId = this.userData.id
				}

			}
			this.getStationByCompanyId()
			this.getGoStationList()
			this.getUserList()
		},
		onLoad(option) {
			if(uni.getStorageSync('remark')){
				let remark = uni.getStorageSync('remark')
				this.shopRemark = remark.split('\n');
			}
			if(uni.getStorageSync('transCompany') =='1751797599075176448'){
				this.voiceData.cost = 2
			}
			if (option.editData) {
				this.isEdit = true
				let editData = JSON.parse(option.editData)
				this.voiceData.imagePath = editData.imagePath
				this.voiceData.circuitId = editData.circuitId
				this.voiceData.circuitName = editData.circuitName
				this.voiceData.shipperName = editData.shipperName
				this.voiceData.shipperMobile = editData.shipperMobile
				this.voiceData.shipperAddress = editData.shipperAddress
				this.voiceData.receiverName = editData.receiverName
				this.voiceData.receiverMobile = editData.receiverMobile
				this.voiceData.receiverAddress = editData.receiverAddress
				this.voiceData.goStationId = editData.goStationId
				this.voiceData.goStationName = editData.goStationName
				this.voiceData.arrivalStationId = editData.arrivalStationId
				this.voiceData.arrivalStationName = editData.arrivalStationName
				this.voiceData.landingFee = editData.landingFee
				this.voiceData.deliveryFee = editData.deliveryFee
				this.voiceData.weight = editData.weight
				this.voiceData.count = editData.count
				this.voiceData.freight = editData.freight
				this.voiceData.premium = editData.premium
				this.voiceData.transitFee = editData.transitFee
				this.voiceData.paymentForGoods = editData.paymentForGoods
				this.voiceData.tips = editData.tips
				this.voiceData.methodOfSettlement = editData.methodOfSettlement
				this.voiceData.cost = editData.cost
				this.voiceData.allCost = editData.allCost
				this.voiceData.orderNumber = editData.orderNumber
				this.voiceData.objectName = editData.objectName
				this.voiceData.remark = editData.remark
				this.voiceData.weightHistory = editData.weightHistory
				this.voiceData.receivingUserId = editData.receivingUserId
				this.voiceData.receivingUserName = editData.receivingUserName
				this.voiceData.id = editData.id
				this.getStationByCompanyId()
				this.arrivalStationChange(editData.arrivalStationId)
			}

		},
		methods: {
			countPrint(){
				return this.yNum += 40
			},
			doNothing() {
				
				return;
			},
			addWeight(){
				if(this.voiceData.weightHistory == '' || this.voiceData.weightHistory == undefined){
					this.voiceData.weightHistory = this.voiceData.weight + '+'
				}
				this.$refs.inputDialog.open()
			},
			addWeight1(e){
				if(e.target.value > 0){
					if(e.target.value.indexOf('.') == -1 && String(this.voiceData.weight).indexOf('.') == -1){
						this.voiceData.weight = Number(this.voiceData.weight) + Number(e.target.value)
					}else{
						this.voiceData.weight = (Number(this.voiceData.weight) + Number(e.target.value)).toFixed(2)
					}
					this.voiceData.weightHistory += e.target.value + '+'
				}
			},
			priceChange(e, index) {
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				let that = this;
				this.voiceData.transferAddition = e
				that.priceCurrent = index
				if (e == 0) {
					this.voiceData.transitFee = 0
					for (let i = 0; i < this.transferStationList.length; i++) {
						
						this.voiceData.transitFee = (Number(this.voiceData.transitFee) + (Number(this.transferStationList[
							i].transitFee) * Number(this.voiceData.weight))).toFixed(2)
					}
				} else if (e == 1) {
					this.voiceData.transitFee = 0
				}

				setTimeout(res => {
					this.getAllCost()
					uni.hideLoading();
				}, 500)
				this.$forceUpdate()
			},
			//查看地址簿
			addressBook(type) {
				uni.navigateTo({
					url: '/package2/other/logisticsAddressBook?userType=' + type
				})
			},
			inputFocus(e,type){
				if(e.target.value != ''){
					this.getCustomList(e.target.value,type)
				}else{
					this.customList = []
				}
				
				if(type=='fa'){
					this.newFa = true
					this.shipperId = ''
					this.faBookShow = true
				}else if(type == 'shou'){
					this.newShou = true
					this.receiverId = ''
					this.shouBookShow = true
				}
			},
			checkNewPeople(type){
				if(type == 'fa'){
					this.newFa = true
					this.voiceData.shipperName = this.voiceData.newShipperName
					this.voiceData.shipperMobile = this.voiceData.newShipperMobile
					this.voiceData.shipperId = ""
				}else{
					this.newShou = true
					this.voiceData.receiverName = this.voiceData.newReceiverName
					this.voiceData.receiverMobile = this.voiceData.newReceiverMobile
					this.voiceData.receiverId = ""
				}
				this.$forceUpdate()
			},
			kuaijieName(name){
				if(name == 'fuzhuang'){
					this.voiceData.objectName = '服装'
				}else if(name == 'xiezi'){
					this.voiceData.objectName = '鞋子'
				}else{
					this.voiceData.objectName = '其他'
				}
			},
			//计算总金额
			getAllCost(e,type) {
				if(type=='yunshufei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.freight = e.target.value
					} else {
						if (e.target.value == '') {
							this.voiceData.freight = this.linshiPrice
						} else {
							this.voiceData.freight = e.target.value
						}
					}
				}else if(type=='zhongzhuanfei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.transitFee = e.target.value
					} else {
						if (e.target.value == '') {
							this.voiceData.transitFee = this.linshiPrice
						} else {
							this.voiceData.transitFee = e.target.value
						}
					}
				}else if(type=='luodifei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.landingFee = Number(e.target.value)
					} else {
						if (e.target.value == '') {
							this.voiceData.landingFee = Number(this.linshiPrice)
						} else {
							this.voiceData.landingFee = Number(e.target.value)
						}
					}
				}else if(type=='zhongzhuanfei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.songhuofei = e.target.value
					} else {
						if (e.target.value == '') {
							this.voiceData.songhuofei = this.linshiPrice
						} else {
							this.voiceData.songhuofei = e.target.value
						}
					}
				}else if(type=='baofei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.premium = e.target.value
					} else {
						if (e.target.value == '') {
							this.voiceData.premium = this.linshiPrice
						} else {
							this.voiceData.premium = e.target.value
						}
					}
				}else if(type=='xiaofei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.tips = e.target.value
					} else {
						if (e.target.value == '') {
							this.voiceData.tips = this.linshiPrice
						} else {
							this.voiceData.tips = e.target.value
						}
					}
				}else if(type=='gongbenfei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.cost = e.target.value
					} else {
						if (e.target.value == '') {
							this.voiceData.cost = this.linshiPrice
						} else {
							this.voiceData.cost = e.target.value
						}
					}
				}else if(type=='songhuofei'){
					if (this.linshiPrice == e.target.value) {
						this.voiceData.deliveryFee = e.target.value
					} else {
						if (e.target.value == '') {
							this.voiceData.deliveryFee = this.linshiPrice
						} else {
							this.voiceData.deliveryFee = e.target.value
						}
					}
				}
				if(type !='zongfeiyong'){
					this.voiceData.allCost =
						Number(Number(this.voiceData.landingFee) +
							Number(this.voiceData.deliveryFee) +
							Number(this.voiceData.freight) +
							Number(this.voiceData.premium) +
							Number(this.voiceData.transitFee) +
							Number(this.voiceData.tips) +
							Number(this.voiceData.cost)).toFixed(2)
				}
				
			},
			//获取员工列表
			getUserList() {
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsUser/getLogisticsUserPageList',
					data: {
						pageNum: 1,
						pageSize: "100",
						companyId: uni.getStorageSync('transCompany'),
						nickName: ""
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							for (let i = 0; i < res.data.result.records.length; i++) {
								res.data.result.records[i].value = res.data.result.records[i].id
								res.data.result.records[i].text = res.data.result.records[i].nickName
								if (res.data.result.records[i].userRole == '2') {
									this.voiceData.receivingUserId = res.data.result.records[i].id
									this.voiceData.receivingUserName = res.data.result.records[i].nickName
								}
							}
							setTimeout(res1 => {
								
								this.userList = res.data.result.records
							}, 200)
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			getOrderList(){
				let that = this
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsOrder/getLogisticsOrderPageList',
					data:{ //stationId
						pageNum:1,
						pageSize:"100",
						companyId:uni.getStorageSync('transCompany'),
						orderStatus:2
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						this.status = 'nomore';
						if(res.data.code == 401){
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200){
							if (this.pages == 1) {
								this.orderList = res.data.result.records
							} else {
								this.orderList = [...this.orderList, ...res.data.result.records]
							}
							this.pages = res.data.result.pages
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			checkName(item, type) {
				if (type == 'fa') {
					this.newFa = false
					this.voiceData.shipperName = item.shipperOrReceiverName
					this.voiceData.shipperMobile = item.mobile
					this.voiceData.shipperAddress = item.addressInfo
					this.voiceData.shipperId = item.id
				} else {
					this.newShou = false
					this.voiceData.receiverName = item.shipperOrReceiverName
					this.voiceData.receiverMobile = item.mobile
					this.voiceData.receiverAddress = item.addressInfo
					this.voiceData.receiverId = item.id
				}
				this.shouBookShow = false
				this.faBookShow = false
				this.$forceUpdate()
			},
			getGuadan(){
				this.getOrderList()
				this.$refs.shopPopup.open('bottom')
			},
			sreachName(e, type) {
				if (type == 'ji') {
					
					this.voiceData.shipperName = e.detail.value
					this.getCustomList(e.detail.value,type)
				} else {
					
					this.voiceData.receiverName = e.detail.value
					this.getCustomList(e.detail.value,type)
				}
			},
			//获取地址簿列表
			getCustomList(name,type) {
				this.customList = []
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsAddressBook/getLogisticsAddressBookPageList',
					data: {
						pageNum: this.pageNum,
						pageSize: 100,
						keyWord: name,
						companyId:uni.getStorageSync('transCompany'),
						addressType:type == 'ji'?'1':type == 'shou'?'2':''
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST',
					dataType: 'json',
					success: (res) => {
						this.status = 'loading';
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							if(res.data.result.records.length == 0){
								if(type == 'ji'){
									this.newFa = true
									this.voiceData.shipperId = ''
									this.voiceData.shipperMobile = ''
									this.voiceData.shipperAddress = ''
								}else{
									this.newShou = true
									this.voiceData.receiverId = ''
									this.voiceData.receiverMobile = ''
									this.voiceData.receiverAddress = ''
								}
							}else{
								this.status = 'nomore';
								if (this.pages == 1) {
									this.customList = res.data.result.records
								} else {
									this.customList = [...this.customList, ...res.data.result.records]
								}
								this.pages = res.data.result.pages
							}
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			getStationByCompanyId() {
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsStation/getLogisticsStationListByCompanyId',
					data: {
						companyId: uni.getStorageSync('transCompany')
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							for (let i = 0; i < res.data.result.length; i++) {
								this.daodaList.push(res.data.result[i].stationName)
								res.data.result[i].value = res.data.result[i].id
								res.data.result[i].text = res.data.result[i].stationName + '(' + res.data
									.result[i].freightRules + '元/每公斤)'
								if (this.voiceData.arrivalStationId == res.data.result[i].id) {
									this.voiceData.arrivalStationId = res.data.result[i].id
									this.voiceData.arrivalStationName = res.data.result[i].stationName
									this.voiceData.freight = (this.voiceData.weight * res.data.result[i]
										.freightRules).toFixed(
										2)
									this.voiceData.circuitId = res.data.result[i].circuitId
									this.voiceData.freightRules = res.data.result[i].freightRules
									this.voiceData.landingFee = Number(res.data.result[i].landingFeeRules)
									this.voiceData.deliveryFee = res.data.result[i].deliveryFeeRules
								}
								this.arrivalStationList1.push(res.data.result[i].stationName)
							}
							setTimeout(res1 => {
								
								this.arrivalStationList = res.data.result

							}, 200)
						}

					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			getGoStationList() {
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsStation/getLogisticsStationListByCompanyId',
					data: {
						companyId: uni.getStorageSync('transCompany')
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							for (let i = 0; i < res.data.result.length; i++) {
								res.data.result[i].value = res.data.result[i].id
								res.data.result[i].text = res.data.result[i].stationName
								if (res.data.result[i].stationName == '沧州') {
									this.voiceData.goStationId = res.data.result[i].id
									this.voiceData.goStationName = res.data.result[i].stationName
								}
							}
							setTimeout(res1 => {
								this.goStationList = res.data.result
							}, 200)

						}

					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			//按住语音识别，开始
			kaishi() {
				if (this.isVoice == false) {
					this.recordState = true
					uni.vibrateShort();
					manager.start({
						duration: 60000,
						lang: "zh_CN"
					});
				}
			},
			//松开语音识别，结束
			jieshu() {
				this.recordState = false
				manager.stop()
			},
			extractInfo(str) {
				const info = {};
				const regexes = [{
					name: 'shipperName',
					regex: /发货人:(.*?)，/
				}, {
					name: 'shipperMobile',
					regex: /发货电话:(.*?)，/
				}, {
					name: 'receiverName',
					regex: /收货人:(.*?)，/
				}, {
					name: 'receiverMobile',
					regex: /收货电话:(.*?)，/
				}, {
					name: 'arrivalStationName',
					regex: /到达站:(.*)，/
				}, {
					name: 'arrivalStationName',
					regex: /物品名称:(.*)，/
				}, {
					name: 'weight',
					regex: /重量:(.*?)，/
				}, {
					name: 'count',
					regex: /数量:(.*?)，/
				}, {
					name: 'tips',
					regex: /小费:(.*?)，/
				}, {
					name: 'premium',
					regex: /保费:(.*?)/
				}];

				regexes.forEach(({
					name,
					regex
				}) => {
					const match = str.match(regex);
					if (match && match[1]) {
						// 去除可能的前后空格
						info[name] = match[1].trim();
					}
				});

				return info;
			},
			//切换结算方式
			payTypeChange(e) {
				for (let i = 0; i < this.payTypeList.length; i++) {
					if (this.payTypeList[i].value == e) {
						this.voiceData.methodOfSettlement = e;
					}
				}
			},
			arrivalStationChange(e) {
				
				for (let i = 0; i < this.arrivalStationList.length; i++) {
					if (this.arrivalStationList[i].stationName == e || this.arrivalStationList[i].id == e) {
						this.voiceData.arrivalStationId = this.arrivalStationList[i].id
						this.voiceData.arrivalStationName = this.arrivalStationList[i].stationName
						this.voiceData.freight = (this.voiceData.weight * this.arrivalStationList[i].freightRules).toFixed(
							2)
						this.voiceData.circuitId = this.arrivalStationList[i].circuitId
						this.voiceData.freightRules = this.arrivalStationList[i].freightRules
						this.voiceData.landingFee = Number(this.arrivalStationList[i].landingFeeRules)
						this.voiceData.deliveryFee = this.arrivalStationList[i].deliveryFeeRules
					}
				}
				setTimeout(res => {
					this.getTransferStation()
				}, 300)
			},
			getTransferStation() {
				uni.request({
					url: this.tui.interfaceUrl() +
						'/app/logisticsTransferStation/getLogisticsTransferStationPageList',
					data: {
						arrivalStation: "",
						goStation: "",
						pageNum: 1,
						pageSize: 100,
						stationId: this.voiceData.arrivalStationId
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							this.voiceData.transitFee = 0
							this.transferStationList = res.data.result.records
							if (this.priceCurrent == 0) {
								for (let i = 0; i < res.data.result.records.length; i++) {
									this.voiceData.transitFee += Number(res.data.result.records[i]
										.transitFee) * Number(this.voiceData.weight).toFixed(2)
								}
							}

							setTimeout(res1 => {
								this.getAllCost()
							}, 300);
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			goAddOrderPage(data){
				this.$refs.shopPopup.close()
				uni.navigateTo({
					url:'/package2/other/newLogisticsBill?editData='+JSON.stringify(data)
				})
			},
			delOrder(item){
				this.$refs.shopPopup.close()
				let that = this;
				uni.showModal({
					title: "提示",
					content: "确定删除此条信息吗？",
					success: function(res) {
						uni.showLoading({
							title: '加载中...'
						})
						if (res.confirm) {
							uni.request({
								url: that.tui.interfaceUrl() + '/app/logisticsOrder/deleteLogisticsOrder',
								data:{
									id:item.id
								},
								header: {
									'content-type': 'application/x-www-form-urlencoded',
									'appWLToken': that.tui.getToken()
								},
								method: 'POST', //'GET','POST'
								dataType: 'json',
								success: (res) => {
									if(res.data.code == 401){
										uni.clearStorage()
										uni.navigateTo({
											url: '/package2/login/login'
										})
									}
									if(res.data.code == 200){
										uni.showToast({
											title:'删除成功'
										})
										setTimeout(res1=>{
											that.pageNum = 1
											that.orderList = []
											that.getOrderList()
											that.getAllNum()
										},500)
									}
								},
								fail: (res) => {
									that.tui.toast("网络不给力，请稍后再试~")
								}
							})
						}
						setTimeout(res => {
							uni.hideLoading();
						}, 500)
					}
				})
			},
			goStationChange(e) {
				
				for (let i = 0; i < this.goStationList.length; i++) {
					if (this.goStationList[i].id == e) {
						this.voiceData.goStationId = this.goStationList[i].id
						this.voiceData.goStationName = this.goStationList[i].stationName
					}
				}
			},
			stationUserChange(e) {

				for (let i = 0; i < this.userList.length; i++) {

					if (this.userList[i].id == e) {
						
						this.voiceData.receivingUserId = this.userList[i].id
						this.voiceData.receivingUserName = this.userList[i].nickName
					}
				}
			},
			freightCount(e) {
				if (this.linshiPrice == e.target.value) {
					this.voiceData.weight = e.target.value
				} else {
					if (e.target.value == '') {
						this.voiceData.weight = this.linshiPrice
					} else {
						this.voiceData.weight = e.target.value
					}
				}
				this.voiceData.weightHistory = this.voiceData.weight + '+'
				this.voiceData.freight = Number((this.voiceData.freightRules == undefined?0:this.voiceData.freightRules) * this.voiceData.weight).toFixed(2)
				this.voiceData.transitFee = 0
				if (this.priceCurrent == 0) {
					for (let i = 0; i < this.transferStationList.length; i++) {
						
						this.voiceData.transitFee = (Number(this.voiceData.transitFee) + (Number(this.transferStationList[
							i].transitFee) * Number(this.voiceData.weight))).toFixed(2)
					}
				}
				this.getAllCost()
			},
			clickGetOneShou(item){
				this.voiceData.receiverName = item.shipperOrReceiverName
				this.voiceData.receiverMobile = item.mobile
				this.voiceData.receiverId = item.id
				this.voiceData.receiverAddress = item.addressInfo
				if(item.id == ''){
					this.newShou = true
				}
				this.$forceUpdate()
				this.$refs.moreShouPopup.close()
			},
			clickGetOneFa(item){
				this.voiceData.shipperName = item.shipperOrReceiverName
				this.voiceData.shipperMobile = item.mobile
				this.voiceData.shipperId = item.id
				this.voiceData.shipperAddress = item.addressInfo
				if(item.id == ''){
					this.newFa = true
				}
				this.$forceUpdate()
				this.$refs.moreFaPopup.close()
			},
			yuyinChange() {
				
				this.isVoice = false
			},
			//去掉空格和换行
			trimWhitespace(str) {
				return str.replace(/\s+/g, '');
			},
			replaceCharAfterNumber(str, charToFind, charToReplace) {
				// 正则表达式匹配字符前是否有数字，并且该字符与charToFind相同
				const regex = new RegExp(`\\d${charToFind}`, 'g');
				// 使用replace方法进行替换
				return str.replace(regex, (match) => {
					// 将匹配到的字符中的指定字符替换为charToReplace
					return match.replace(charToFind, charToReplace);
				});
			},
			timestampToDatetime() {
				const dateObj = new Date();

				const year = dateObj.getFullYear();
				const month = dateObj.getMonth() + 1;
				const day = dateObj.getDate();
				const hours = dateObj.getHours();
				const minutes = dateObj.getMinutes();
				const seconds = dateObj.getSeconds();

				return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
			},
			kuaijieFocus(){
				this.kjFocus = this.voiceData.objectName
				this.voiceData.objectName = ""
			},
			kuaijieBlur(){
				if(this.voiceData.objectName == ""){
					this.voiceData.objectName = this.kjFocus
				}
			},
			obtainPrice(e, type, num, num1) {
				this.linshiPrice = e.target.value
				if (type == 'zhongliang') {
					this.voiceData.weight = ''
				} else if (type == 'shuliang') {
					this.voiceData.count = ''
				} else if (type == 'yunshufei') {
					this.voiceData.freight = ''
				} else if (type == 'xiaofei') {
					this.voiceData.tips = ''
				} else if (type == 'zongfeiyong') {
					this.voiceData.allCost = ''
				} else if (type == 'baofei') {
					this.voiceData.premium = ''
				} else if (type == 'zhongzhuanfei') {
					this.voiceData.transitFee = ''
				} else if (type == 'luodifei') {
					this.voiceData.landingFee = ''
				} else if (type == 'songhuofei') {
					this.voiceData.deliveryFee = ''
				} else if (type == 'gongbenfei') {
					this.voiceData.cost = ''
				} else if (type == 'zhongliangAdd') {
					this.weigthAdd = ''
				} 
			},
			getVoiceData() {
				
				if (this.voiceText == '') {
					this.tui.toast('识别内容不能为空')
					return
				}
				uni.showLoading({
					title: 'Ai识别中...'
				})
				let convertedStr = this.trimWhitespace(this.voiceText);

				if (convertedStr.indexOf('点') != -1) {
					convertedStr = this.replaceCharAfterNumber(convertedStr, '点', '.')
				}
				if (convertedStr.indexOf('发货人，') != -1) {
					convertedStr = convertedStr.replace(/发货人，/g, '发货人')
				}
				if (convertedStr.indexOf('发货人::') != -1) {
					convertedStr = convertedStr.replace(/发货人::/g, '发货人')
				}
				if (convertedStr.indexOf('发货人:') != -1) {
					convertedStr = convertedStr.replace(/发货人:/g, '发货人')
				}
				if (convertedStr.indexOf('发货人') != -1) {
					convertedStr = convertedStr.replace(/发货人/g, '，发货人:')
				}
				if (convertedStr.indexOf('，发货电话') != -1) {
					convertedStr = convertedStr.replace(/，发货电话/g, '发货电话')
				}
				if (convertedStr.indexOf('发货电话，') != -1) {
					convertedStr = convertedStr.replace(/发货电话，/g, '发货电话')
				}
				if (convertedStr.indexOf('发货电话::') != -1) {
					convertedStr = convertedStr.replace(/发货电话::/g, '发货电话')
				}
				if (convertedStr.indexOf('发货电话:') != -1) {
					convertedStr = convertedStr.replace(/发货电话:/g, '发货电话')
				}
				if (convertedStr.indexOf('发货电话') != -1) {
					convertedStr = convertedStr.replace(/发货电话/g, '，发货电话:')
				}

				if (convertedStr.indexOf('，收货人') != -1) {
					convertedStr = convertedStr.replace(/，收货人/g, '收货人')
				}
				if (convertedStr.indexOf('收货人，') != -1) {
					convertedStr = convertedStr.replace(/收货人，/g, '收货人')
				}
				if (convertedStr.indexOf('收货人::') != -1) {
					convertedStr = convertedStr.replace(/收货人::/g, '收货人')
				}
				if (convertedStr.indexOf('收货人:') != -1) {
					convertedStr = convertedStr.replace(/收货人:/g, '收货人')
				}
				if (convertedStr.indexOf('收货人') != -1) {
					convertedStr = convertedStr.replace(/收货人/g, '，收货人:')
				}

				if (convertedStr.indexOf('，收货电话') != -1) {
					convertedStr = convertedStr.replace(/，收货电话/g, '收货电话')
				}
				if (convertedStr.indexOf('收货电话，') != -1) {
					convertedStr = convertedStr.replace(/收货电话，/g, '收货电话')
				}
				if (convertedStr.indexOf('收货电话::') != -1) {
					convertedStr = convertedStr.replace(/收货电话::/g, '收货电话')
				}
				if (convertedStr.indexOf('收货电话:') != -1) {
					convertedStr = convertedStr.replace(/收货电话:/g, '收货电话')
				}
				if (convertedStr.indexOf('收货电话') != -1) {
					convertedStr = convertedStr.replace(/收货电话/g, '，收货电话:')
				}

				if (convertedStr.indexOf('，重量') != -1) {
					convertedStr = convertedStr.replace(/，重量/g, '重量')
				}
				if (convertedStr.indexOf('重量，') != -1) {
					convertedStr = convertedStr.replace(/重量，/g, '重量')
				}
				if (convertedStr.indexOf('重量::') != -1) {
					convertedStr = convertedStr.replace(/重量::/g, '重量')
				}
				if (convertedStr.indexOf('重量:') != -1) {
					convertedStr = convertedStr.replace(/重量:/g, '重量')
				}
				if (convertedStr.indexOf('重量') != -1) {
					convertedStr = convertedStr.replace(/重量/g, '，重量:')
				}

				if (convertedStr.indexOf('，数量') != -1) {
					convertedStr = convertedStr.replace(/，数量/g, '数量')
				}
				if (convertedStr.indexOf('数量，') != -1) {
					convertedStr = convertedStr.replace(/数量，/g, '数量')
				}
				if (convertedStr.indexOf('数量::') != -1) {
					convertedStr = convertedStr.replace(/数量::/g, '数量')
				}
				if (convertedStr.indexOf('数量:') != -1) {
					convertedStr = convertedStr.replace(/数量:/g, '数量')
				}
				if (convertedStr.indexOf('数量') != -1) {
					convertedStr = convertedStr.replace(/数量/g, '，数量:')
				}

				if (convertedStr.indexOf('，小费') != -1) {
					convertedStr = convertedStr.replace(/，小费/g, '小费')
				}
				if (convertedStr.indexOf('小费，') != -1) {
					convertedStr = convertedStr.replace(/小费，/g, '小费')
				}
				if (convertedStr.indexOf('小费::') != -1) {
					convertedStr = convertedStr.replace(/小费::/g, '小费')
				}
				if (convertedStr.indexOf('小费:') != -1) {
					convertedStr = convertedStr.replace(/小费:/g, '小费')
				}
				if (convertedStr.indexOf('小费') != -1) {
					convertedStr = convertedStr.replace(/小费/g, '，小费:')
				}

				if (convertedStr.indexOf('，保费') != -1) {
					convertedStr = convertedStr.replace(/，保费/g, '保费')
				}
				if (convertedStr.indexOf('保费，') != -1) {
					convertedStr = convertedStr.replace(/保费，/g, '保费')
				}
				if (convertedStr.indexOf('保费::') != -1) {
					convertedStr = convertedStr.replace(/保费::/g, '保费')
				}
				if (convertedStr.indexOf('保费:') != -1) {
					convertedStr = convertedStr.replace(/保费:/g, '保费')
				}
				if (convertedStr.indexOf('保费') != -1) {
					convertedStr = convertedStr.replace(/保费/g, '，保费:')
				}

				if (convertedStr.indexOf('，物品') != -1) {
					convertedStr = convertedStr.replace(/，物品/g, '物品')
				}
				if (convertedStr.indexOf('物品，') != -1) {
					convertedStr = convertedStr.replace(/物品，/g, '物品')
				}
				if (convertedStr.indexOf('物品::') != -1) {
					convertedStr = convertedStr.replace(/物品::/g, '物品')
				}
				if (convertedStr.indexOf('物品:') != -1) {
					convertedStr = convertedStr.replace(/物品:/g, '物品')
				}
				if (convertedStr.indexOf('物品') != -1) {
					convertedStr = convertedStr.replace(/物品/g, '，物品:')
				}

				if (convertedStr.indexOf('，到达站') != -1) {
					convertedStr = convertedStr.replace(/，到达站/g, '到达站')
				}
				if (convertedStr.indexOf('到达站，') != -1) {
					convertedStr = convertedStr.replace(/到达站，/g, '到达站')
				}
				if (convertedStr.indexOf('到达站::') != -1) {
					convertedStr = convertedStr.replace(/到达站::/g, '到达站')
				}
				if (convertedStr.indexOf('到达站:') != -1) {
					convertedStr = convertedStr.replace(/到达站:/g, '到达站')
				}
				if (convertedStr.indexOf('到达站') != -1) {
					convertedStr = convertedStr.replace(/到达站/g, "，到达站:'")
					if (convertedStr.charAt(convertedStr.length - 1) == '。' || convertedStr.charAt(convertedStr.length -
							1) == '，') {
						convertedStr = convertedStr.slice(0, -1)
					}
					convertedStr = convertedStr + "'"
				}
				if (convertedStr.indexOf('13行') != -1) {
					convertedStr = convertedStr.replace(/13行/g, '十三行')
				}
				convertedStr = this.convertStringCorrectly(convertedStr)
				convertedStr = this.spliceMsg(convertedStr)
				if (convertedStr.indexOf('，') == 0) {
					convertedStr = convertedStr.substr(1)
				}
				
				var now = new Date();
				var year = now.getFullYear();
				var month = now.getMonth() + 1;
				var day = now.getDate();
				var hour = now.getHours();
				var minute = now.getMinutes();
				var second = now.getSeconds();

				var currentDate = year + '/' + month + '/' + day + ' ' + hour + ':' + minute + ':' + second;
				
				this.$refs.popup.close()
				uni.request({
					url: this.tui.interfaceUrl() + '/purchaseOcrPicture/getLogisticsOrderOfAi',
					data: {
						questionMsg: convertedStr,
						arrivalStation:JSON.stringify(this.daodaList)
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST',
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							if(res.data.result.data[0].receiverList != null && res.data.result.data[0].receiverList.length > 1){
								this.newShou = false
								this.voiceData.newReceiverName = ""
								this.voiceData.newReceiverMobile = ""
								res.data.result.data[0].receiverList.push({
									mobile: res.data.result.data[0].receiverMobile,
									shipperOrReceiverName: res.data.result.data[0].receiverName,
									id:""
								})
								this.moreShouList = res.data.result.data[0].receiverList
								this.$refs.moreShouPopup.open()
							}
							if(res.data.result.data[0].shipperList != null && res.data.result.data[0].shipperList.length > 1){
								this.newFa = false
								this.voiceData.newShipperName = ""
								this.voiceData.newShipperMobile = ""
								res.data.result.data[0].shipperList.push({
									mobile: res.data.result.data[0].shipperMobile,
									shipperOrReceiverName: res.data.result.data[0].shipperName,
									id:""
								})
								this.moreFaList = res.data.result.data[0].shipperList
								this.$refs.moreFaPopup.open()
							}
							for (let key in res.data.result.data[0]) {
								
								if (res.data.result.data[0][key] != '' && res.data.result.data[0][key] !=
									null && res.data.result.data[0][key] != 0) {
									if (res.data.result.data[0].arrivalStationName && key ==
										'arrivalStationName') {
										this.pinyinMatch(res.data.result.data[0].arrivalStationName)
									}
									if (res.data.result.data[0].hasOwnProperty(key) && this.voiceData
										.hasOwnProperty(key) && res.data.result.data[0][key] != 'receiverName' && res.data.result.data[0][key] != 'receiverMobile' && res.data.result.data[0][key] != 'shipperName' && res.data.result.data[0][key] != 'shipperMobile') {
										this.voiceData[key] = res.data.result.data[0][key];
									}
									if(res.data.result.data[0].receiverList != null && res.data.result.data[0].receiverList.length == 0){
										this.voiceData.receiverName = res.data.result.data[0].receiverName
										this.voiceData.receiverMobile = res.data.result.data[0].receiverMobile
										this.voiceData.newReceiverName = ""
										this.voiceData.newReceiverMobile = ""
										this.newShou = true
									}else if(res.data.result.data[0].receiverList != null && res.data.result.data[0].receiverList.length == 1){
										this.newShou = false
										this.voiceData.receiverName = res.data.result.data[0].receiverList[0].shipperOrReceiverName
										this.voiceData.receiverMobile = res.data.result.data[0].receiverList[0].mobile
										this.voiceData.receiverAddress = res.data.result.data[0].receiverList[0].addressInfo
										this.voiceData.receiverId = res.data.result.data[0].receiverList[0].id
										this.voiceData.newReceiverName = res.data.result.data[0].receiverName
										this.voiceData.newReceiverMobile = res.data.result.data[0].receiverMobile
										
									}
									
									if(res.data.result.data[0].shipperList != null &&  res.data.result.data[0].shipperList.length == 0){
										this.voiceData.shipperName = res.data.result.data[0].shipperName
										this.voiceData.shipperMobile = res.data.result.data[0].shipperMobile
										this.newFa = true
										this.voiceData.newShipperName = ""
										this.voiceData.newShipperMobile = ""
									}else if(res.data.result.data[0].shipperList != null &&  res.data.result.data[0].shipperList.length == 1){
										this.voiceData.shipperName = res.data.result.data[0].shipperList[0].shipperOrReceiverName
										this.voiceData.shipperMobile = res.data.result.data[0].shipperList[0].mobile
										this.voiceData.shipperAddress = res.data.result.data[0].shipperList[0].addressInfo
										this.voiceData.shipperId = res.data.result.data[0].shipperList[0].id
										this.voiceData.newShipperName = res.data.result.data[0].shipperName
										this.voiceData.newShipperMobile = res.data.result.data[0].shipperMobile
										this.newFa = false
									}
									this.$forceUpdate()
								}

							}
						}
						uni.hideLoading()
						setTimeout(res=>{
							
							this.getAllCost()
						},300)
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
						uni.hideLoading()
					}
				})
			},
			//数量失去焦点
			shuliangChange(e){
				if (this.linshiPrice == e.target.value) {
					this.voiceData.count = e.target.value
				} else {
					if (e.target.value == '') {
						this.voiceData.count = this.linshiPrice
					} else {
						this.voiceData.count = e.target.value
					}
				}
			},
			pinyinMatch(name) {
				if (name.indexOf('。') != -1) {
					name = name.split('。')[0]
				}
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsStation/getLogisticsStationPageList',
					data: {
						pageNum: 1,
						pageSize: 10,
						circuitId: "",
						stationName: name
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST',
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							if (res.data.result.records != '') {
								for (let i = 0; i < this.arrivalStationList.length; i++) {
									for(let m = 0; m < res.data.result.records.length; m++){
										if (this.arrivalStationList[i].id == res.data.result.records[m].id) {
											this.voiceData.arrivalStationId = res.data.result.records[m].id
											this.voiceData.arrivalStationName = res.data.result.records[m]
												.stationName
											this.arrivalStationChange(res.data.result.records[m].id)
										}
									}
								}
							} else {
								this.tui.toast("当前到达站查无此信息，请确认")
							}

						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			//获取当月1日到当前时间
			getMonth() {
				let date = new Date()
				let year = date.getFullYear().toString() //'年'
				let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1)
					.toString() //'月'
				let da = date.getDate() < 10 ? '0' + date.getDate().toString() : date.getDate().toString() //'日'
				let end = year + '-' + month + '-' + da //当天
				return end
			},
			//正则匹配处理“2十9”等情况
			convertStringCorrectly(str) {
				var regexForSingleTen = /(\d+)十(?!\d)/g;
				var regexForFollowedByDigit = /(\d+)十(?=\d)/g;
				var step1Result = str.replace(regexForSingleTen, '$10');
				var finalResult = step1Result.replace(regexForFollowedByDigit, '$1');

				return finalResult;
			},
			convertChineseToArabic(str) {
				const chineseNumToArabic = {
					'零': 0,
					'一': 1,
					'二': 2,
					'两': 2,
					'三': 3,
					'四': 4,
					'五': 5,
					'六': 6,
					'七': 7,
					'八': 8,
					'九': 9,
					'时1': '11',
					'时2': '12',
					'时3': '13',
					'时4': '14',
					'时5': '15',
					'时6': '16',
					'时7': '17',
					'时8': '18',
					'时9': '19',
					'消费': '小费',
					'报废': '保费',
					'报费': '保费',
				};
				const regex = /(零|一|二|两|三|四|五|六|七|八|九|时1|时2|时3|时4|时5|时6|时7|时8|时9|消费|报废|报费)/g;
				return str.replace(regex, match => chineseNumToArabic[match]);
			},
			spliceMsg(res) {
				let regex = /嗯|啊|儿|阿|恩/g;
				return res.replace(regex, '')
			},

			//弹出
			toggle(type, id) {
				this.initRecord();
				this.voiceText = ''
				this.$refs.popup.open('center')
			},
			//清空语音输入的文字
			clearText() {
				this.voiceText = ''
			},
			//语音识别功能初始化
			initRecord() {
				let that = this;
				manager.stop()
				// 识别结束事件
				manager.onStop = (res) => {
					that.voiceText = res.result
					
				}

				// 识别错误事件
				manager.onError = (res) => {
					if (res.retcode == '-30011') {
						that.isVoice = true
					}
					if (res.retcode == '-30004') {
						// uni.hideLoading()
						that.isVoice = false
						uni.hideToast()
						uni.showToast({
							title: "未识别到声音信息,请重新录入",
							icon: 'none'
						})
					}
					if (res.retcode == '-40001') {
						uni.showToast({
							title: '使用次数超限制，请联系管理员！',
							icon: 'none'
						})
					}
				}
			},
			setGuaBill() {
				if(this.voiceData.receiverName == '' || this.voiceData.arrivalStationId == ''){
					uni.showToast({
						title:(this.voiceData.receiverName == ''?'收货人':this.voiceData.arrivalStationId == ''?'到达站':"") +'不能为空',
						icon:'none'
					})
					return
				}
				this.voiceData.orderStatus = 2
				let url
				if (this.isEdit != true) {
					url = '/app/logisticsOrder/addLogisticsOrder'
				} else {
					url = '/app/logisticsOrder/updateLogisticsOrder'
				}
				uni.request({
					url: this.tui.interfaceUrl() + url,
					data: this.voiceData,
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 401) {
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200) {
							this.tui.toast('挂单成功',500)
							this.clearData('')
							this.$forceUpdate()
							if (this.isEdit != true) {
							}else{
								setTimeout(res1 => {
									uni.navigateBack()
								}, 500)
							}
							
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			setBill() {
				
				this.voiceDataPrint = this.voiceData
				if(this.voiceData.receiverName == '' || this.voiceData.arrivalStationId == '' || this.voiceData.objectName == ''){
					uni.showToast({
						title:(this.voiceData.receiverName == ''?'收货人':this.voiceData.arrivalStationId == ''?'到达站':this.voiceData.objectName == ''?'物品名':"")+'不能为空',
						icon:'none'
					})
					return
				}
				this.voiceData.orderStatus = 1
				
				
				
						let url
						if (this.isEdit != true) {
							url = '/app/logisticsOrder/addLogisticsOrder'
						} else {
							url = '/app/logisticsOrder/updateLogisticsOrder'
						}
						uni.request({
							url: this.tui.interfaceUrl() + url,
							data: this.voiceData,
							header: {
								'content-type': 'application/json',
								'appWLToken': this.tui.getToken()
							},
							method: 'POST', //'GET','POST'
							dataType: 'json',
							success: (res) => {
								if (res.data.code == 401) {
									uni.clearStorage()
									uni.navigateTo({
										url: '/package2/login/login'
									})
								}
								if (res.data.code == 200) {
									this.tui.toast('开单成功',500)
									
									if (this.isEdit != true) {
										
										if(uni.getStorageSync('transCompany') == '1899370468356526080' || uni.getStorageSync('transCompany') == '1751796589518786560' || uni.getStorageSync('transCompany') == '1899371352842964992' || uni.getStorageSync('transCompany') == '1782981706819702784' || uni.getStorageSync('transCompany') == '1751797599075176448'){
											console.log('打印数据',uni.getStorageSync('deviceId'))
											// if(uni.getStorageSync('deviceId') != '' && uni.getStorageSync('deviceId') != undefined){
											// 	console.log('11111111111')
											// 	this.huoqufuwu(uni.getStorageSync('deviceId'))
											// }else{
											// 	console.log('2222222')
												this.handlePrintTap()
											// }
											this.voiceData.orderNumber = res.data.result.orderNumber
										}else{
											this.clearData("1")
										}
									}else{
										setTimeout(res1 => {
											uni.navigateBack()
										}, 500)
									}
									
								}
							},
							fail: (res) => {
								this.tui.toast("网络不给力，请稍后再试~")
							}
						})
					
			},
			pictureAdd() {
				let that = this
				uni.chooseMedia({
					count: 1,
					mediaType: ['image'],
					sourceType: ['album', 'camera'],
					success(res) {
						uni.showLoading({
							title: '加载中...',
							mask: true
						})
						that.upLoadFile(res.tempFiles[0].tempFilePath)
					}
				})
			},
			async upLoadFile(path) {
				let that = this;
				let hiver_token = uni.getStorageSync("hiver_token")
				that.productPicture = []
				await uni.uploadFile({
					url: that.tui.interfaceUrl() + '/upload/file',
					filePath: path,
					name: 'file',
					header: {
						"content-type": "multipart/form-data",
						'appWLToken': hiver_token
					},
					formData: {},
					success: (uploadFileRes) => {
						let pathData = JSON.parse(uploadFileRes.data)
						that.voiceData.imagePath = pathData.result
						that.productPicture.push(pathData.result)
						that.$forceUpdate()
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							title: JSON.stringify(err),
							icon: 'none'
						})
					}
				});
				await setTimeout(res => {
					uni.hideLoading();
				}, 1000)
			},
			//点击打印按钮
			handlePrintTap() {
				let that = this
				uni.showLoading({
					mask: true,
					title: '打印中...'
				});
				uni.getSystemInfo({
					success(res) {
						that.deviceType = res.osName
					},
					fail(err) {
						
					}
				})
				// 初始化蓝牙模块
				wx.openBluetoothAdapter({ //111
					mode: 'central',
					success: (res2) => {
						that.sousuo()
					},
					fail: (res) => {
						
						if (res.errCode == '10001') {
							
							// that.tui.toast('请打开蓝牙后，再进行连接')
							uni.showToast({
								duration: 2000,
								title: "请打开蓝牙后，再进行连接",
								icon: 'none',
								mask: true
							})
						} else {
							that.tui.toast('连接失败，请重启蓝牙或删除小程序重新进入-1')
							
							that.isShowSearch = true
						}
						setTimeout(res => {
							uni.hideLoading();
						}, 2000)
					}
				})
			},
			// 开始搜索附近的蓝牙外围设备
			sousuo() {
				let that = this;
				this.devicesList = []
				wx.startBluetoothDevicesDiscovery({ //222
					success(res3) {
						that.jiantingshebei()
					},
					fail(err) {
						that.tui.toast('连接失败，请重启蓝牙或删除小程序重新进入-2', err)
						
						wx.closeBLEConnection({
							deviceId: uni.getStorageSync('deviceId'),
							success(res2) {

							}
						})
						wx.closeBluetoothAdapter()
						uni.removeStorageSync('deviceId')
						that.handlePrintTap()
						that.isShowSearch = true
						setTimeout(res => {
							uni.hideLoading();
						}, 2000)
					}
				})
			},
			//停止搜索蓝牙设备
			stopSearchBtnTap() {
				wx.stopBluetoothDevicesDiscovery()
			},
			jiantingshebei() {
				let that = this;
				if (uni.getStorageSync('deviceId')) {
					
					that.lianejieshebei(uni.getStorageSync('deviceId'))
				} else {
					
					uni.hideLoading();
					that.clearData('1');
					that.isShowSearch = true
					
					that.$forceUpdate()
					// 监听扫描到新设备事件
					wx.onBluetoothDeviceFound((res4) => { //333
						res4.devices.forEach((device) => {
							if (!device.name && !device.localName) {
								return
							}
							that.devicesList.push(device)
						})
					})
				}

			},
			lianejieshebei(deviceId) {
				let that = this;
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let timerId = setTimeout(() => {
					
					wx.closeBLEConnection({
						deviceId: deviceId,
						success(res2) {

						}
					})
					
					wx.closeBluetoothAdapter()
					
					uni.removeStorageSync('deviceId')
					
					that.handlePrintTap()
					that.isShowSearch = true
					return
				}, 5000);
				// 连接设备
				
				wx.createBLEConnection({ //555
					deviceId: deviceId, // 搜索到设备的 deviceId
					success: () => {
						clearTimeout(timerId);
						that.isShowSearch = false
						that.huoqufuwu(deviceId)
					},
					fail: (res) => {
						
						clearTimeout(timerId);
						if(res.errno == '1509007'){
							that.huoqufuwu(deviceId)
						}
						if(res.errno == '1509003'){
							that.lianejieshebei(deviceId)
						}
					}
				})
			},
			huoqufuwu(deviceId) {
				let that = this;
				//获取服务
				uni.getBLEDeviceServices({ //666
					deviceId: deviceId, // 搜索到设备的 deviceId
					success: (res5) => {
						console.log('333333333')
						that.duxietezhengzhi(deviceId, res5)
					},
					fail: (res) => {
						that.tui.toast('连接失败，请重启蓝牙或删除小程序重新进入-4', res)
						console.log('777777777',res)
						wx.closeBLEConnection({
							deviceId: deviceId,
							success(res2) {
						
							}
						})
						
						wx.closeBluetoothAdapter()
						
						uni.removeStorageSync('deviceId')
						that.handlePrintTap()
						that.isShowSearch = true
						setTimeout(res => {
							uni.hideLoading();
						}, 2000)
					}
				})
			},
			duxietezhengzhi(deviceId, res5) {
				let that = this;
				//读写特征值
				wx.getBLEDeviceCharacteristics({ //777
					deviceId: deviceId, // 搜索到设备的 deviceId
					serviceId: res5.services[0].uuid, // 上一步中找到的某个服务
					success: (res6) => {
						console.log('444444444')
						for (let i = 0; i < res6.characteristics.length; i++) {
							let item = res6.characteristics[i]
							that.startNoticeBle(deviceId, res5.services[0].uuid, res6.characteristics[2].uuid)
							if (item.properties.write) { // 该特征值可写

								uni.setStorageSync('deviceId', deviceId);
								uni.setStorageSync('serviceId', res5.services[0].uuid);
								uni.setStorageSync('characteristicId', item.uuid);
								that.xierushuju()
								return;
							}
						}
					},
					fail: (res) => {
						that.tui.toast('连接失败，请重启蓝牙或删除小程序重新进入-5', res)
						
						wx.closeBLEConnection({
							deviceId: uni.getStorageSync('deviceId'),
							success(res) {

							}
						})
						uni.removeStorageSync('deviceId')
						
						that.$forceUpdate()
						that.sousuo()
						that.isShowSearch = true
						uni.hideLoading()
						
						setTimeout(res => {
							uni.hideLoading();
						}, 2000)
					}
				})
			},
			// 开启蓝牙数据监听
			startNoticeBle(deviceId, serviceId, characteristicId) {
				let _this = this
				uni.notifyBLECharacteristicValueChange({
					state: true, // 启用 notify 功能
					deviceId: deviceId,
					serviceId: serviceId,
					characteristicId: characteristicId,
					success(res) {
						_this.GetDataFromBle();
					}
				})
			},
			// 设备返回的数据接收
			GetDataFromBle() {
				var that = this; 
				uni.onBLECharacteristicValueChange((res) => {
					uni.hideLoading()
					that.clearData('')
					that.$forceUpdate()
					uni.closeBLEConnection({
						deviceId: uni.getStorageSync('deviceId')
					})
				})
			},
			clearData(type){
				let that = this
				if(type == ''){
					that.bufferData = []
				}
				that.productPicture = []
				that.newFa = false
				that.newShou = false
				that.transferStationList = []
				this.printcount = ""
				that.voiceData = {
					createBy: uni.getStorageSync('contacts'),
					companyId: uni.getStorageSync('transCompany'),
					companyName: uni.getStorageSync('companyName'),
					imagePath: '',
					circuitId: '', // 线路id
					circuitName: '', // 线路名称
					shipperName: '', // 发货人名-
					shipperMobile: '', // 发货人电话-
					shipperAddress: '', // 发货人地址
					receiverName: '', // 收货人名-
					receiverMobile: '', // 收货人电话-
					receiverAddress: '', // 收货人地址
					goStationId: '', // 出发站id-
					goStationName: '沧州', // 出发站名称-
					arrivalStationId: '', // 到达站id-
					arrivalStationName: '', // 到达站名称-
					landingFee: 0, //落地费
					deliveryFee: 0, //送货费
					weight: 0, // 重量-
					weightHistory:'',
					count: 0, // 件数-
					freight: 0, // 运输费-
					premium: 0, // 保费-
					transitFee: 0, // 中转费
					transferAddition: 0,
					paymentForGoods: 0, // 代收货款
					tips: 0, // 拉包小费
					methodOfSettlement: "2", // 结算方式
					cost: 0, // 工本费
					allCost: 0, // 总费用
					orderNumber: '', // 票号
					objectName: '', // 物体名称
					remark: '', // 备注
					newShipperName:"",
					newReceiverName:'',
					newReceiverMobile:'',
					newShipperMobile:'',
					receivingUserId: '', // 收货站人id
					receivingUserName: '' // 收货站人名称
				}
				if(uni.getStorageSync('transCompany') =='1751797599075176448'){
					this.voiceData.cost = 2
				}
				that.$forceUpdate()
			},
			getPrintByte(data) {
				if (data == undefined || data == null) {
					return ''
				} else {
					if(data == '冀J059DE' || data == '测试勿选'){
						return '顺达快运'
					}else{
						return data
					}
					
				}
			},
			//获取打印小标签的数据
			smallData(){
				let that = this
				
				return new Promise((resolve, reject) => {
					let strCmd = ''
					let count = that.voiceDataPrint.count == 0 ? 1 :that.voiceDataPrint.count
					if(this.printcount != '' && this.printcount > 0){
						count = this.printcount
					}
					for(let i=1;i<=count;i++){
						let strCmd = blesdk.CreatCPCLPage(600, 480, 1, 0,0);
						strCmd += blesdk.addCPCLBox(10,10,570,450,3) //画框
						
						strCmd += blesdk.addCPCLLocation(2);
						strCmd += blesdk.addCPCLSETMAG(2, 2)
						strCmd += blesdk.addCPCLText('0', 20, '24', '0', 0, that.voiceDataPrint.companyName)
						
						strCmd += blesdk.addCPCLLine(10,80,570,80,2) //画线
						
						strCmd += blesdk.addCPCLLocation(0);
						strCmd += blesdk.addCPCLSETMAG(1, 1)
						strCmd += blesdk.addCPCLText('20', 100, '24', '0', 0, '开票日期:'+ that.getMonth())
						
						strCmd += blesdk.addCPCLLine(10,140,570,140,2) //画线
						strCmd += blesdk.addCPCLLine(382,140,382,316,2) //画线
						
						strCmd += blesdk.addCPCLSETMAG(2, 2)
						strCmd += blesdk.addCPCLText('20', 160, '24', '0', 0, '到站:'+ that.voiceDataPrint.arrivalStationName)
						
						strCmd += blesdk.addCPCLLine(10,220,382,220,2) //画线
						strCmd += blesdk.addCPCLText('20', 248, '24', '0', 0, '收:'+that.voiceDataPrint.receiverName)
						
						strCmd += blesdk.addCPCLLine(10,316,570,316,2) //画线
						
						strCmd += blesdk.addCPCLSETMAG(1, 1)
						strCmd += blesdk.addCPCLText('20', 336, '24', '0', 0, '共'+count + '件')
						
						let jiesuan = ''
						if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '0') {
							jiesuan = '现金'
						} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '1') {
							jiesuan = '月付'
						} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '2') {
							jiesuan = '提付'
						}
						strCmd += blesdk.addCPCLText('112', 336, '24', '0', 0, jiesuan)
						
						strCmd += blesdk.addCPCLLine(170,316,170,450,2) //画线
						// strCmd += blesdk.addCPCLText('10', that.yNum+=40, '24', '0', 0, '单  号：'+ that.voiceDataPrint.orderNumber + '-' +i)
						strCmd += blesdk.addCPCLText('186', 336, '24', '0', 0, '单号:'+that.voiceDataPrint.orderNumber+'-' +i)
						
						strCmd += blesdk.addCPCLLine(10,376,570,376,2) //画线
						strCmd += blesdk.addCPCLText('20', 396, '24', '0', 0, that.voiceDataPrint.receiverMobile == 'undefined' ? '' : that.voiceDataPrint.receiverMobile)
						strCmd += blesdk.addCPCLText('186', 396, '24', '0', 0, '备注:' + that.voiceDataPrint.remark)
						
						// strCmd += blesdk.addCPCLQRCode(400, 150 , 'H', '1', 4, orderNumber) //二维码
						strCmd += blesdk.addCPCLQRCode(400, 150 , 'H', '1', 4, that.voiceDataPrint.orderNumber) //二维码
						
						strCmd += blesdk.addCPCLPrint();
						that.bufferData.push(strCmd);
						resolve(that.bufferData)
					}
				})
				
			},
			//获取打印物流单的数据
			wuliuData(){
				let that = this
				
				return new Promise((resolve, reject) => {
					let wlNum = uni.getStorageSync('wlNum')
					for(let i=0;i<wlNum;i++){
						let strCmd1 = ''
						if(uni.getStorageSync('zhiType') == 1){
							strCmd1 = blesdk.CreatCPCLPage(600, 1800, 1, 0,0);
							strCmd1 += blesdk.addCPCLSETMAG(2, 2)
							strCmd1 += blesdk.addCPCLLocation(2);
							strCmd1 += blesdk.addCPCLText('30', '30', '24', '0', '0', this.getPrintByte(uni.getStorageSync(
								'companyName')))
							
							strCmd1 += blesdk.addCPCLSETMAG(1, 1)
							strCmd1 += blesdk.addCPCLLocation(0);
							let orderNum = that.voiceDataPrint.orderNumber
							if(uni.getStorageSync('transCompany') == '1899370468356526080' || uni.getStorageSync('transCompany') == '1782981706819702784'){
								orderNum = that.voiceDataPrint.orderNumber.split('-')[1] + that.voiceDataPrint.orderNumber.split('-')[2].replace('-', '');
							}
							strCmd1 += blesdk.addCPCLSETMAG(2, 2)
							strCmd1 += blesdk.addCPCLText('30', '150', '24', '0', '0', ('单号:'+this.getPrintByte(orderNum)))
							strCmd1 += blesdk.addCPCLSETMAG(1, 1)
							strCmd1 += blesdk.addCPCLText('30', '210', '24', '0', '0', that.timestampToDatetime())
							
							strCmd1 += blesdk.addCPCLLine(25,270,1080,270,2) //画线
							strCmd1 += blesdk.addCPCLText('30', '290', '24', '0', '0', ('始发站:' + this.getPrintByte(that.voiceDataPrint.goStationName)))
							strCmd1 += blesdk.addCPCLText('300', '290', '24', '0', '0', ('到达站:' + this.getPrintByte(that.voiceDataPrint.arrivalStationName)))
							strCmd1 += blesdk.addCPCLSETMAG(2, 2)
							strCmd1 += blesdk.addCPCLText('30', '340', '24', '0', '0', ('收:'+ this.getPrintByte(that.voiceDataPrint.receiverName)))
							strCmd1 += blesdk.addCPCLSETMAG(1, 2)
							strCmd1 += blesdk.addCPCLText('300', '340', '24', '0', '0', (' '+ this.getPrintByte(that.voiceDataPrint.receiverMobile)))
							strCmd1 += blesdk.addCPCLSETMAG(1, 1)
							strCmd1 += blesdk.addCPCLText('30', '410', '24', '0', '0', ('地址:'+ this.getPrintByte(that.voiceDataPrint.receiverAddress)))
							strCmd1 += blesdk.addCPCLLine(25,470,1080,470,2) //画线
							strCmd1 += blesdk.addCPCLText('30', '490', '24', '0', '0', ('发货人:'+ this.getPrintByte(that.voiceDataPrint.shipperName)))
							strCmd1 += blesdk.addCPCLText('300', '490', '24', '0', '0', ('电话:' + this.getPrintByte(that.voiceDataPrint.shipperMobile)))
							strCmd1 += blesdk.addCPCLLine(25,550,1080,550,2) //画线
						
							
							strCmd1 += blesdk.addCPCLText('30', '570', '24', '0', '0', ('重量:' + that.getPrintByte(that.voiceDataPrint
								.weight) + 'kg'))
							strCmd1 += blesdk.addCPCLText('300', '570', '24', '0', '0', ('件数:' + that.getPrintByte(that.voiceDataPrint
								.count)))
							strCmd1 += blesdk.addCPCLText('30', '630', '24', '0', '0', ('运费:' + that.getPrintByte(that.voiceDataPrint
								.freight) + '元'))
							strCmd1 += blesdk.addCPCLSETMAG(2, 2)
							strCmd1 += blesdk.addCPCLText('300', '620', '24', '0', '0', ('物品:' + that.getPrintByte(that.voiceDataPrint
								.objectName)))
							strCmd1 += blesdk.addCPCLSETMAG(1, 1)
								
							strCmd1 += blesdk.addCPCLText('30', '690', '24', '0', '0', ('小费:' + that.getPrintByte(that.voiceDataPrint
								.tips) + '元'))
							let jiesuan = ''
							if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '0') {
								jiesuan = '现付'
							} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '1') {
								jiesuan = '月付'
							} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '2') {
								jiesuan = '提付'
							}
							strCmd1 += blesdk.addCPCLText('300', '690', '24', '0', '0', ('结算:' + jiesuan))
							
								
							strCmd1 += blesdk.addCPCLText('30', '750', '24', '0', '0', ('中转费:' + that.getPrintByte(that.voiceDataPrint
								.transitFee) + '元'))
							strCmd1 += blesdk.addCPCLText('300', '750', '24', '0', '0', ('落地费:' + that.getPrintByte(that.voiceDataPrint
								.landingFee) + '元'))
								
								
							strCmd1 += blesdk.addCPCLText('30', '810', '24', '0', '0', ('送货费:' + that.getPrintByte(that.voiceDataPrint
								.deliveryFee) + '元'))
							strCmd1 += blesdk.addCPCLText('300', '810', '24', '0', '0', ('保费:' + that.getPrintByte(that.voiceDataPrint
								.premium) + '元'))
							strCmd1 += blesdk.addCPCLSETMAG(2, 2)
							strCmd1 += blesdk.addCPCLText('30', '860', '24', '0', '0', ('总费用:' + that.getPrintByte(that.voiceDataPrint
								.allCost) + '元'))
							
							strCmd1 += blesdk.addCPCLLine(25,920,1080,920,2) //画线
							
							strCmd1 += blesdk.addCPCLSETMAG(1, 1)
							strCmd1 += blesdk.addCPCLText('30', '940', '24', '0', '0', ('备注:'+this.getPrintByte(that.voiceDataPrint.remark)))
							strCmd1 += blesdk.addCPCLText('30' , '1000', '24', '0', '0', '收货人签字:')
							
							strCmd1 += blesdk.addCPCLLine(25,1060,1080,1060,2) //画线
							this.yNum = 1060
							strCmd1 += blesdk.addCPCLSETMAG(1, 1)
							//店铺备注
							
							if (this.shopRemark.length > 0) {
								for (let i = 0; i < this.shopRemark.length; i++) {
									strCmd1 += blesdk.addCPCLText('30', this.countPrint(), '24', '0', 0, this.shopRemark[i])
								}
							}
							
						}else{
							strCmd1 = blesdk.CreatCPCLPage(600, 480, 1, 0, 0);
							strCmd1 += blesdk.addCPCLBox(10,10,570,450,3)
							strCmd1 += blesdk.addCPCLSETMAG(2, 2)
							strCmd1 += blesdk.addCPCLSETBOLD('2')
							strCmd1 += blesdk.addCPCLLocation(0);
							strCmd1 += blesdk.addCPCLText('30', '30', '24', '0', '0', that.getPrintByte(uni.getStorageSync(
								'companyName')))
							strCmd1 += blesdk.addCPCLSETMAG(1, 1)
							strCmd1 += blesdk.addCPCLSETBOLD('2')
							strCmd1 += blesdk.addCPCLText('300', '30', '24', '0', '0', ('单号:' + that.voiceDataPrint.orderNumber))
							// strCmd1 += blesdk.addCPCLText('300', '30', '24', '0', '0', ('单号:1321646846846546'))
							strCmd1 += blesdk.addCPCLSETBOLD('2')
							strCmd1 += blesdk.addCPCLBox(25,50,555,50,2) //画框
							strCmd1 += blesdk.addCPCLText('30', '90', '24', '0', '0', ('收货人:' + that.getPrintByte(that.voiceDataPrint
								.receiverName)))
							strCmd1 += blesdk.addCPCLText('300', '90', '24', '0', '0', ('到达站：' + that.getPrintByte(that.voiceDataPrint
								.arrivalStationName)))
							strCmd1 += blesdk.addCPCLText('30', '140', '24', '0', '0', ('地址：' + that.getPrintByte(that.voiceDataPrint
								.receiverAddress)))
								strCmd1 += blesdk.addCPCLText('300', '140', '24', '0', '0', ('电话：' + that.getPrintByte(that.voiceDataPrint
									.receiverMobile)))
							strCmd1 += blesdk.addCPCLLine(25,180,555,180,2) //画线
							strCmd1 += blesdk.addCPCLText('30', '190', '24', '0', '0', ('发货人:' + that.getPrintByte(that.voiceDataPrint
								.shipperName)))
							
							strCmd1 += blesdk.addCPCLText('300', '190', '24', '0', '0', ('电话：' + that.getPrintByte(that.voiceDataPrint
								.shipperMobile)))
							strCmd1 += blesdk.addCPCLLine(25,240,555,240,2) //画线
							if(uni.getStorageSync('transCompany') != '1751796589518786560' && uni.getStorageSync('transCompany') != '1899371352842964992' && uni.getStorageSync('transCompany') != '1782981706819702784'){
								strCmd1 += blesdk.addCPCLText('30', '250', '24', '0', '0', ('重量:' + that.getPrintByte(that.voiceDataPrint
									.weight)))
								strCmd1 += blesdk.addCPCLText('300', '250', '24', '0', '0', ('件数:' + that.getPrintByte(that.voiceDataPrint
									.count) + '件'))
								let jiesuan = ''
								if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '0') {
									jiesuan = '现金'
								} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '1') {
									jiesuan = '月付'
								} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '2') {
									jiesuan = '提付'
								}
								strCmd1 += blesdk.addCPCLText('30', '290', '24', '0', '0', ('结算方式:' + jiesuan))
								if(uni.getStorageSync('transCompany') != '1751796589518786560'){
									strCmd1 += blesdk.addCPCLText('300', '290', '24', '0', '0', ('总运费:' + that.getPrintByte(Number(that.voiceDataPrint.freight) + Number(that.voiceDataPrint.cost)) + '元'))
								}
								
							}else{
								let beginWidth = 0
								let beginNum = 0
								if(that.voiceDataPrint.weight != 0){
									if(beginNum == 0){
										beginWidth = 30
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '250', '24', '0', '0', ('重量:' + that.getPrintByte(that.voiceDataPrint
										.weight)))
									beginNum = 1
								}
								if(that.voiceDataPrint.count != 0){
									if(beginNum == 0){
										beginWidth = 30
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '250', '24', '0', '0', ('件数:' + that.getPrintByte(that.voiceDataPrint
										.count)))
									beginNum = 1
								}
								if(that.voiceDataPrint.freight != 0){
									if(beginNum == 0){
										beginWidth = 30
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '250', '24', '0', '0', ('运费:' + that.getPrintByte(that.voiceDataPrint
										.freight)))
									beginNum = 1
								}
								if(that.voiceDataPrint.tips != 0 && uni.getStorageSync('transCompany') != '1751796589518786560'){
									if(beginNum == 0){
										beginWidth = 30
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '250', '24', '0', '0', ('小费:' + that.getPrintByte(that.voiceDataPrint
										.tips)))
									beginNum = 1
								}
								beginWidth = 0
								beginNum = 0
								
								let jiesuan = ''
								if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '0') {
									jiesuan = '现金'
								} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '1') {
									jiesuan = '月付'
								} else if (that.getPrintByte(that.voiceDataPrint.methodOfSettlement) == '2') {
									jiesuan = '提付'
								}
								strCmd1 += blesdk.addCPCLText('30', '290', '24', '0', '0', ('结算:' + jiesuan))
								if(that.voiceDataPrint.transitFee != 0){
									if(beginNum == 0){
										beginWidth = 160
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '290', '24', '0', '0', ('中转费:' + that.getPrintByte(that.voiceDataPrint
										.transitFee)))
									beginNum = 1
								}
								if(that.voiceDataPrint.landingFee != 0){
									if(beginNum == 0){
										beginWidth = 160
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '290', '24', '0', '0', ('落地费:' + that.getPrintByte(that.voiceDataPrint
										.landingFee)))
									beginNum = 1
								}
								if(that.voiceDataPrint.premium != 0){
									if(beginNum == 0){
										beginWidth = 160
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '290', '24', '0', '0', ('保费:' + that.getPrintByte(that.voiceDataPrint
										.premium)))
									beginNum = 1
								}
								if(that.voiceDataPrint.deliveryFee != 0){
									if(beginNum == 0){
										beginWidth = 160
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '290', '24', '0', '0', ('送货费:' + that.getPrintByte(that.voiceDataPrint
										.deliveryFee)))
									beginNum = 1
								}
								if(that.voiceDataPrint.objectName != 0){
									if(beginNum == 0){
										beginWidth = 160
									}else{
										beginWidth += 130
									}
									strCmd1 += blesdk.addCPCLText(beginWidth.toString(), '290', '24', '0', '0', ('物品:' + that.getPrintByte(that.voiceDataPrint
										.objectName)))
									beginNum = 1
								}
								
							}
							
							strCmd1 += blesdk.addCPCLLine(25,330,555,330,2) //画线
							strCmd1 += blesdk.addCPCLText('30', '340', '24', '0', '0', ('备注:' + that.getPrintByte(that.voiceDataPrint
								.remark)))
							strCmd1 += blesdk.addCPCLLine(25,400,555,400,2) //画线
							strCmd1 += blesdk.addCPCLText('30', '410', '24', '0', '0', ('操作人:' + that.getPrintByte(that.voiceDataPrint
								.createBy)))
							strCmd1 += blesdk.addCPCLText('300', '410', '24', '0', '0', that.timestampToDatetime())
						}
						
						strCmd1 += blesdk.addCPCLPrint();
						that.bufferData.push(strCmd1);
						resolve(that.bufferData)
					}
					
				})
				
			},
			async xierushuju() {
				let that = this;
				if(uni.getStorageSync('xbqNum') == 1){
					await this.smallData()
				}
				
				await this.wuliuData()
				
				that.$nextTick(() => {
					var dataStr = ''
					for (let m = 0; m < that.bufferData.length; m++) {
						dataStr += that.bufferData[m]
					}
					const maxChunk = that.deviceType == 'android' ? 20 : 180;
					const delay = that.deviceType == 'android' ? 20 : 180;

					let buffer = gbk.strToGBKByte(dataStr)
					for (let i = 0, j = 0, length = buffer.byteLength; i < length; i += maxChunk, j++) {
						let subPackage = buffer.slice(i, i + maxChunk <= length ? (i + maxChunk) : length);
						setTimeout(that._writeBLECharacteristicValue, j * delay, subPackage);
					}

				})
				return;
			},
			_writeBLECharacteristicValue(buffer) {
				let that = this;
				wx.writeBLECharacteristicValue({
					deviceId: uni.getStorageSync('deviceId'),
					serviceId: uni.getStorageSync('serviceId'),
					characteristicId: uni.getStorageSync('characteristicId'),
					value: buffer,
					success(res) {

					},
					fail(res) {
						wx.closeBLEConnection({
							deviceId: uni.getStorageSync('deviceId'),
							success(res) {

							}
						})
						if (uni.getStorageSync('deviceId')) {
							that.xierushuju()
						} else {
							that.jiantingshebei()
						}
						uni.hideLoading();
					}
				})

			},
			handleSearchClose() {
				wx.closeBluetoothAdapter()
				this.isShowSearch = false
			}
		}
	}
</script>

<style lang="scss">
	page,
	.page1 {
		background: #eee;
		height: auto;
	}

	.box {
		width: 95%;
		margin: 20rpx auto 0;
		background: #fff;
		border-radius: 10px;
		padding: 10px;
		position: relative;
	}

	.bottom-btn {
		position: fixed;
		bottom: 0;
		height: 100rpx;
		background: #fff;
		width: 100%;
		font-size: 36rpx;
		color: #fff;
		display: flex;
		z-index: 99
	}

	.circle {
		width: 120rpx;
		text-align: center;
		line-height: 40rpx;
		font-size: 36rpx;
		font-weight: bold;
		margin-top: 20rpx;
	}

	.content {
		height: 80rpx;
		line-height: 80rpx;
	}

	.input-box {
		width: 100%;
		height: 60rpx;
		line-height: 60rpx;
		display: inline-block;
		margin-top: 5px;
		border-bottom: 1px solid #eee;
		padding-left: 10px;
	}

	.name-box {
		width: 20%;
		height:70rpx;
	}

	.voice-popup-content {
		align-items: center;
		justify-content: center;
		padding: 15px;
		width: 500rpx;
		border-radius: 10px;
		height: 740rpx;
		background-color: #fff;
	}

	.voice-popup-title {
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
		position: relative;
	}

	.voice-popup-container {
		margin-top: 20rpx;
	}

	.voice-popup-bottom {
		display: flex;
		height: 80rpx;
		color: #fff;
		line-height: 80rpx;
		margin-top: 30rpx;
	}

	.uni-list-cell {
		margin-right: 110rpx;
		display: flex;
		float: left;
	}

	.voice-popup-btn {
		flex: 1;
		text-align: center;
		background: linear-gradient(90deg, #FF9797, #FFC1E0);
	}

	.voice-popup-btn:last-child {
		background: linear-gradient(90deg, #60F3FF, #088FEB);
	}

	.voice-model {
		width: 300rpx;
		height: 300rpx;
		display: flex;
		justify-content: center;
		flex-flow: column;
		position: fixed;
		top: 50%;
		left: 50%;
		background: rgba(0, 0, 0, 0.5);
		border-radius: 20rpx;
		color: #fff;
		text-align: center;
		margin-left: -150rpx;
		z-index: 999;
	}

	.voice-model img {
		width: 200rpx;
		height: 200rpx;
		margin: 0 auto;
	}

	.voice-btn {
		position: absolute;
		bottom: -250rpx;
		left: 30%;
		width: 180rpx;
		height: 180rpx;
		background: #eee;
		border-radius: 50%;
	}

	.mask-model {
		width: 60%;
		height: 100rpx;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
		text-align: center;
		background: rgba(0, 0, 0, 0.7);
		color: #eee;
		padding: 5px;
		border-radius: 5px;
		z-index: 99;
	}

	.upload-img {
		width: 160rpx;
		height: 160rpx;
	}

	.type-popup {
		width: 500rpx;
		height: 570rpx;
		background: #fff;
		border-radius: 10px;
		position: relative;
		padding: 0 20rpx;
		overflow: scroll;
	}

	.kk-printer {
		&-btn {
			width: 100%;
			height: 100%;
		}

		.kk-shadow {
			display: none;
			z-index: 999;

			&.show {
				display: block;
				width: 100vw;
				height: 100vh;
				background: rgba(0, 0, 0, 0.4);
				position: fixed;
				top: 0;
				left: 0;
				display: flex;
				justify-content: center;
				align-items: center;

				.kk-modal {
					width: 420upx;
					height: 600upx;
					padding: 24upx;
					box-sizing: border-box;
					overflow-y: auto;
					border-radius: 20upx;
					background: #ffffff;
					display: flex;
					justify-content: center;
					align-items: center;

					.kk-search-device {
						width: 100%;
						height: 100%;

						.kk-filter-wrap {
							width: 100%;
							height: 160upx;
							display: flex;
							flex-direction: column;
							justify-content: flex-start;
							align-items: flex-start;

							.filter-title {
								line-height: 70upx;
								font-size: 30upx;
								color: #999999;
							}

							&>slider {
								width: 90%;
								height: 90upx;
							}

							&>input {
								padding: 0 20upx;
								box-sizing: border-box;
								border-radius: 10upx;
								height: 90upx;
								width: 100%;
								border: 1upx solid #ebebeb;
							}
						}

						.kk-btn-wrap {
							width: 100%;
							height: 90upx;
							display: flex;
							justify-content: space-between;
							align-items: center;
							padding: 20rpx;

							&>view {
								flex: 1 1 auto;
								height: 60upx;
								line-height: 60upx;
								border-radius: 16upx;
								text-align: center;
								color: #ffffff;
								font-size: 26rpx;

								&.confirm-btn {
									background: #007AFF;
									margin-right: 30upx;
								}

								&:nth-last-child(1) {
									background: #DD524D;
								}
							}
						}

						.kk-devices-wrap {
							height: calc(100% - 80upx);
							overflow-y: auto;
							padding: 10upx 20upx;
							box-sizing: border-box;
							border: 1upx solid #ebebeb;
							box-sizing: border-box;
							border-radius: 20upx;

							.empty-wrap {
								width: 100%;
								height: 100%;
								display: flex;
								flex-direction: column;
								justify-content: center;
								align-items: center;

								.empty-icon {
									width: 268upx;
									height: 240upx;
									background-size: 100% 100%;
									margin-bottom: 26upx;
								}

								.empty-text {
									width: 100%;
									line-height: 50upx;
									font-size: 30upx;
									text-align: center;
									color: #999999;
								}
							}

							.kk-devices-item {
								width: 100%;
								border-bottom: 1upx solid #ebebeb;
								padding: 10upx 0;
								box-sizing: border-box;
								z-index: 500;

								&:nth-last-child(1) {
									border-bottom: none;
								}

								&>view {
									width: 100%;
									font-size: 30upx;
								}
							}
						}
					}
				}
			}

		}
	}

	.kk-placeholder-class {
		font-size: 30upx;
		color: #999999;
	}

	.title-input {
		width: 70%;
		height: 80rpx;
		line-height: 80rpx;
	}

	.add-book {
		font-size: 26rpx;
		font-weight: bold;
		color: #088FEB;
	}

	.title-box {
		display: flex;
		line-height: 80rpx;
		flex-direction: column;
	}

	.book-mask {
		z-index: 99;
		position: absolute;
		top: 190rpx;
		left: 20%;
		width: 500rpx;
		max-height: 300rpx;
		overflow: scroll;
		background: #fff;
		padding: 10rpx;
		border-radius: 5px;
		border: 1px solid #e5e5e5;
	}
	.new-circle{
		position: absolute;
		right: 20rpx;
		top: 115rpx;
		width: 50rpx;
		height: 50rpx;
		border-radius: 60rpx;
		background: red;
		color: #fff;
		text-align: center;
		line-height: 50rpx;
	}
	.new-user{
		background: #088FEB;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		margin-top: 20rpx;
		color: #fff;
		border-radius: 10px;
	}
	.kuaijie{
		border-radius:10px;
		width: 100rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		margin: 5rpx auto;
		border: 1px solid #FFE4E1;
		color: #87CEFA;
	}
	.uni-combox{
		height: 76rpx !important;
	}
</style>