<template>
	<view class="container">
		<uni-card
			:title="(sales.supplierName == null ?'暂无':sales.supplierName)+'--'+(supplier.consigneeMobile == null ?'暂无':supplier.consigneeMobile)"
			thumbnail="/static/images/dingdan/dd0.png">
			<view class="uni-body" v-if="supplier.province">
				{{supplier.province + supplier.area + supplier.city + supplier.address}} </view>
		</uni-card>
		<button v-if="isShare ==false" open-type="share"
			style="font-size: 22rpx;position: absolute;top: 50rpx;right: 70rpx;background: blue;color: #fff;border-radius: 7px;">
			分享
		</button>
		<view class="tui-order-item boxbg">
			<view class="shop-box" style="border-top:5px solid #eee;" v-for="(item,index) in goodsList" :key="index">
				<view class="shop-name">
					<view style="width: 140rpx;height: 140rpx;margin: 30rpx 0 0 30rpx;position: relative;">
						<img class="img-radius" @tap.stop="getChildrenPic(item)" :src="item.productPicture" alt=""
							style="width: 140rpx;height: 140rpx;" v-if="item.productPicture">
						<view class="noPic" v-else>暂无图片</view>
						<view v-if="shopId == '1960543009070256129'" style="background: red;color: #fff;width: 100%;height: 30rpx;font-size: 26rpx;line-height:30rpx;position: absolute;bottom: 0;text-align: center;border-radius: 5px;">
							主播佣金{{item.commission == null ? 0:item.commission+'%'}}
						</view>
					</view>
					<view class="shop-productName" v-if="shopId != '1960543009070256129'">
						<view style="color:#FF5809;">
							{{item.productName == null ?'暂无':item.productName}}({{item.productSn == null ?'暂无':item.productSn}})
						</view>
						<view style="display: flex;height: 55rpx;line-height: 55rpx;" v-if="type==0">
							采购价: <input v-if="sales.inStorageStatus == 1" type="digit"
								:disabled="sales.inStorageStatus == 0?false:true"
								@blur="PriceAndWho($event,index,'caigou')" @focus="obtainPrice($event,'caigou',index)"
								v-model="item.stockLogList1[0].purchasePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							<input v-if="sales.inStorageStatus == null" type="digit" disabled
								@blur="PriceAndWho($event,index,'caigou')" @focus="obtainPrice($event,'caigou',index)"
								v-model="item.stockLogList1[0].purchasePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							<input v-if="sales.inStorageStatus == 0" type="digit"
								:disabled="sales.inStorageStatus == 0?false:true"
								@blur="PriceAndWho($event,index,'caigou')" @focus="obtainPrice($event,'caigou',index)"
								v-model="item.purchasePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							<view v-if="storeFlag == 1" style="display: flex;">欠货:<input type="number"
									@blur="PriceAndWho($event,index,'qianhuo')"
									@focus="obtainPrice($event,'qianhuo',index)" v-model="item.purchaseQian"
									style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							</view>
						</view>
						<view>
							<text style="padding: 0 5rpx;"> 数量： {{item.productCount == null ?'暂无':item.productCount}}
							</text>
							<text v-if="type==0 && sales.inStorageStatus == 1" style="padding-left: 10rpx;">
								总价：{{(item.productCount*item.stockLogList1[0].purchasePrice)== null?'暂无':(item.productCount*item.stockLogList1[0].purchasePrice).toFixed(2)}}</text>
							<text v-if="type==0 && sales.inStorageStatus == 0" style="padding-left: 10rpx;">
								总价：{{(item.productCount*item.purchasePrice)== null?'暂无':(item.productCount*item.purchasePrice).toFixed(2)}}</text>
						</view>
						<view v-if="isShare ==false" style="display: flex;height: 55rpx;line-height: 55rpx;">
							批发价: <input type="digit" @blur="PriceAndWho($event,index,'pi')"
								@focus="obtainPrice($event,'pifa',index)" v-model="item.wholesalePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;"
								:disabled="sales.inStorageStatus == 0?false:true">
							零售价:<input type="digit" @blur="PriceAndWho($event,index)"
								@focus="obtainPrice($event,'lingshou',index)" v-model="item.price"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;"
								:disabled="sales.inStorageStatus == 0?false:true">
						</view>
					</view>
					<view class="shop-productName" v-else>
						<view style="color:#FF5809;">
							{{item.productName == null ?'暂无':item.productName}}({{item.productSn == null ?'暂无':item.productSn}})
						</view>
						<view v-if='shopOwnerPhone == username || username == item.createBy' style="display: flex;height: 55rpx;line-height: 55rpx;">
							团长佣金(%): <input v-if="sales.inStorageStatus == 1" type="digit"
								:disabled="sales.inStorageStatus == 0?false:true"
								@blur="PriceAndWho($event,index,'caigou')" @focus="obtainPrice($event,'caigou',index)"
								v-model="item.stockLogList1[0].purchasePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							<input v-if="sales.inStorageStatus == null" type="digit" disabled
								@blur="PriceAndWho($event,index,'caigou')" @focus="obtainPrice($event,'caigou',index)"
								v-model="item.stockLogList1[0].purchasePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							<input v-if="sales.inStorageStatus == 0" type="digit"
								:disabled="sales.inStorageStatus == 0?false:true"
								@blur="PriceAndWho($event,index,'caigou')" @focus="obtainPrice($event,'caigou',index)"
								v-model="item.purchasePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							<view v-if="storeFlag == 1" style="display: flex;">欠货:<input type="number"
									@blur="PriceAndWho($event,index,'qianhuo')"
									@focus="obtainPrice($event,'qianhuo',index)" v-model="item.purchaseQian"
									style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;">
							</view>
						</view>
						<view>
							<text style="padding: 0 5rpx;"> 数量： {{item.productCount == null ?'暂无':item.productCount}}
							</text>
							<text v-if="type==0 && sales.inStorageStatus == 1" style="padding-left: 10rpx;">
								总价：{{(item.productCount*item.stockLogList1[0].purchasePrice)== null?'暂无':(item.productCount*item.stockLogList1[0].purchasePrice).toFixed(2)}}</text>
							<text v-if="type==0 && sales.inStorageStatus == 0" style="padding-left: 10rpx;">
								总价：{{(item.productCount*item.purchasePrice)== null?'暂无':(item.productCount*item.purchasePrice).toFixed(2)}}</text>
						</view>
						<view v-if="isShare ==false" style="display: flex;height: 55rpx;line-height: 55rpx;">
							直播价: <input type="digit" @blur="PriceAndWho($event,index,'pi')"
								@focus="obtainPrice($event,'pifa',index)" v-model="item.wholesalePrice"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;"
								:disabled="sales.inStorageStatus == 0?false:true">
							日常价:<input type="digit" @blur="PriceAndWho($event,index)"
								@focus="obtainPrice($event,'lingshou',index)" v-model="item.price"
								style="height: 55rpx;border-bottom: 1px solid #eee;color:#777;width: 100rpx;padding-left: 20rpx;"
								:disabled="sales.inStorageStatus == 0?false:true">
						</view>
					</view>
				</view>
				<view class="shop-type">
					<view class="shop-collapse" v-for="(items,index) in item.stockLogList1" :key='index'>
						<text>{{items.attributeList | sliceMsg}}</text>
						<!-- <text style="color: red;">单价：￥{{item.price}}</text> -->
						<text>数量：{{items.productCount == null ?'暂无':items.productCount}}</text>
					</view>
				</view>
			</view>
			<view class="tui-goods-info" style="width: 95%;margin: 0 auto;"
				v-if="type==0 && sales.inStorageStatus != 0">
				<view class="tui-price-flex tui-size32" v-if="returnInv != 1" style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">应付金额</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">{{ sales.shouldPay == null ?'暂无':sales.shouldPay }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" v-if="returnInv != 1" style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">已付金额</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">{{ sales.alreadyPay == null ?'暂无':sales.alreadyPay }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" v-if="returnInv == 1" style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">退货金额</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">{{ sales.alreadyPay == null ?'暂无':sales.alreadyPay }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">{{dealings.lastDebtAmount> 0?'之前欠款':'之前余额'}}</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">
							{{ dealings.lastDebtAmount == null ?'暂无':Math.abs(dealings.lastDebtAmount) }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" v-if="returnInv != 1" style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">余额抵扣</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">
							{{ sales.balanceDeductionAmount == null ?'暂无':sales.balanceDeductionAmount }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" v-if="dealings.balanceDue >= 0"
					style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">累计欠款</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">
							{{ dealings.balanceDue == null ?'暂无':Math.abs(dealings.balanceDue) }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" v-if="dealings.balanceDue < 0"
					style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">累计余额</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">
							{{ dealings.balanceDue == null ?'暂无':Math.abs(dealings.balanceDue) }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" v-if="sales.noPay >= 0 && returnInv != 1"
					style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">本次欠款</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">{{ sales.noPay == null ?'暂无': Math.abs(sales.noPay) }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" v-if="sales.noPay < 0 && returnInv != 1"
					style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">本次余额</view>
					<view class="tui-goods-price tui-primary-color">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">{{ sales.noPay == null ?'暂无':Math.abs(sales.noPay)}}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32" style="height: 80rpx;line-height: 80rpx;">
					<view class="tui-flex-shrink">其他费用</view>
					<view class="tui-goods-price">
						<view class="tui-size-24">￥</view>
						<view class="tui-price-large">{{ sales.otherPay == null ?'暂无': sales.otherPay }}</view>
					</view>
				</view>
				<view class="tui-price-flex tui-size32">
					<view class="tui-flex-shrink">备注</view>
					<view class="tui-goods-price">
						<uni-tooltip :content="sales.remark == null ?'暂无':sales.remark" placement="left">
							<view
								style="font-size: 13px;width: 200px;height: 40rpx;overflow: hidden;text-align: right;">
								{{ sales.remark == null ?'':sales.remark}}</view>
							<text style="color: blue;">查看更多</text>
						</uni-tooltip>
					</view>
				</view>
			</view>
			<view class="tui-goods-info" v-if="type==0 && sales.inStorageStatus == 0">
				<!-- 账号权限是否可以维护成本价格（主账号和被授权的账号可以维护），参数名：shop_admin_cost，维护在用户表中，存在前后端缓存里，把备注栏挪出来，谁都可以备注 -->
				<view class="price-box-list">
					<view class="price-box" v-if="type == 0">
						<view style="flex: 1;text-align: left;padding-left: 20rpx;">
							供应商:{{dealings.dealingsUserName?dealings.dealingsUserName:''}}
						</view>
						<view v-if="dealings.lastDebtAmount >= 0"
							style="flex: 1;text-align: right;padding-right: 20rpx;">
							之前欠款:{{dealings.lastDebtAmount}}
						</view>
						<view v-if="dealings.lastDebtAmount < 0"
							style="flex: 1;text-align: right;padding-right: 20rpx;">
							之前余额:{{Math.abs(dealings.lastDebtAmount)}}
						</view>
					</view>
					<view class="content-list" v-if="returnInv != 1">
						<view class="list-name">应付金额</view>
						<view class="list-val">
							<input type="text" v-model="shouldPay">
						</view>
					</view>
					<view class="content-list" v-if="returnInv == 1">
						<view class="list-name">退货金额</view>
						<view class="list-val">
							<input type="text" v-model="alreadyPay" @focus="obtainPrice($event,'alreadyPay')"
								@blur="changePay($event)">
						</view>
					</view>
					<view class="content-list" v-if="returnInv != 1">
						<view class="list-name">已付金额</view>
						<view class="list-val">
							<input type="text" v-model="alreadyPay" @focus="obtainPrice($event,'alreadyPay')"
								@blur="changePay($event)">
						</view>
					</view>

					<view class="content-list" v-if="yuedikou != 0 && type == 0 && returnInv != 1">
						<view class="list-name">余额抵扣</view>
						<view class="list-val">
							<input type="digit" v-model="yuedikou" disabled>
						</view>
						<!-- <view v-if="yuedikou > 0" @tap="noReturn" style="flex: 1;height: 30px;line-height: 30px;margin-top: 5px;font-size: 24rpx;background: #00BFFF;text-align: center;color: #fff;border-radius: 20px;">
							不抵扣
						</view> -->
					</view>
					<view class="content-list" v-if="zhiqianqiankuan > 0 && type == 0">
						<view class="list-name">累计欠款</view>
						<view class="list-val">
							<input type="digit" v-model="leijiqiankuan" disabled>
						</view>
					</view>
					<view class="content-list" v-if="leijiqiankuan < 0 && type == 0">
						<view class="list-name">累计余额</view>
						<view class="list-val">
							<input type="digit" v-model="Math.abs(leijiqiankuan)" disabled>
						</view>
					</view>
					<view class="content-list" v-if="noPay >= 0 && type == 0 && returnInv != 1">
						<view class="list-name">本次欠款</view>
						<view class="list-val">
							<input type="digit" v-model="noPay" disabled>
						</view>
					</view>
					<view class="content-list" v-if="noPay < 0 && type == 0 && returnInv != 1">
						<view class="list-name">本次余额</view>
						<view class="list-val">
							<input type="digit" v-model="Math.abs(noPay)" disabled>
						</view>
					</view>
					<view class="content-list">
						<view class="list-name">其他费用</view>
						<view class="list-val">
							<input type="text" v-model="otherPay">
						</view>
					</view>
					<view class="content-list">
						<view class="list-name">备注</view>
						<view class="">
							<textarea maxlength="-1" v-model="remark" />
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="tui-order-info boxbg">
			<view class="tui-order-title">
				订单信息
			</view>
			<view class="tui-order-content" style="border-bottom: 1px solid #E0E0E0;">
				<view class="tui-order-flex">
					<view class="tui-item-title">订单号:</view>
					<view class="tui-item-content">{{ sales.id }}</view>
				</view>
				<view class="tui-order-flex">
					<view class="tui-item-title">操作人:</view>
					<view class="tui-item-content">{{ sales.createByName }}</view>
				</view>
				<view class="tui-order-flex">
					<view class="tui-item-title">入库时间:</view>
					<view class="tui-item-content">{{ sales.createTime }}</view>
				</view>
			</view>
		</view>
		<view class="tui-tabbar" v-if="isShare == false">
			<view class="tui-btn-mr">
				<kk-printer ref="kkprinter" :bufferData="bufferData" :defaultText="'打印小票'"
					@onPrintSmall="onPrintSmall"></kk-printer>
			</view>
			<!-- <view class="tui-btn-mr" v-if="type==0 && sales.inStorageStatus == 1 && sales.noPay >0" @tap="inputDialogToggle">回款</view> -->
			<view class="tui-btn-mr" v-if="sales.inStorageStatus!= 0 && sales.delFlag != 1 && type==0 && storeFlag != 1"
				@tap.stop="returnPrice">撤销</view>
			<view class="tui-btn-mr" v-if="sales.inStorageStatus!= 0 && sales.delFlag != 1 && type==0 && storeFlag != 1"
				@tap.stop="cancelOrder">撤销并复制</view>
			<view class="tui-btn-mr" v-if="sales.inStorageStatus!= 0 && sales.delFlag == 1 && type==0 && storeFlag != 1"
				@tap.stop="goSaleGoods">重新入库</view>
			<view class="tui-btn-mr" v-if="type==0 && sales.inStorageStatus == 0 && storeFlag != 1"
				@click="inventorySubmit">确认提交</view>
			<view class="tui-btn-mr" v-if="sales.inStorageStatus == 1 && sales.delFlag != 1 && storeFlag != 1"
				@click="batchPrint">批量打印</view>
			<view class="tui-btn-mr" v-if="storeFlag == 1" @click="confirmInventory">确认入库</view>
		</view>
		<!-- 弹出输入框 -->
		<uni-popup ref="priceDialog" type="dialog">
			<uni-popup-dialog ref="purInput" mode="input" inputType="digit" title="采购价" placeholder="请输入采购价"
				@confirm="changePrice"></uni-popup-dialog>
		</uni-popup>
		<!-- 弹出多图轮播 -->
		<uni-popup ref="imgPopup" background-color="#fff">
			<view class="showImg-box">
				<swiper indicator-dots class="swiper-box" @change="lunbochange" circular autoplay
					:current="swiperDotIndex">
					<swiper-item v-for="(item, index) in bigImg" :key="index">
						<view class="swiper-item">
							<image mode='aspectFit' show-menu-by-longpress :src="item.productPicture" alt=""
								style="width: 100%;height: 100%;border-radius: 10px;" />
							</image>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</uni-popup>
		<!-- 回款金额输入框 -->
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" inputType="digit" title="回款金额" placeholder="请输入回款金额"
				@confirm="sureNpPay"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import util from '@/components/kk-printer/utils/util.js';
	import * as blesdk from '@/components/kk-printer/utils/bluetoolth.js';
	import kkPrinter from '@/components/kk-printer/index.vue';
	import gbk from '@/components/kk-printer/utils/printUtil-GBK.js';
	export default {
		data() {
			return {
				sales: {},
				goodsList: [],
				isReturn: false,
				shouldPay: 0,
				shopOwnerPhone:uni.getStorageSync('shopOwnerPhone'),
				username:uni.getStorageSync('username'),
				shopId:'',
				shopName: uni.getStorageSync('shopName'),
				noPay: 0,
				claerSubmitBtn: 0,
				alreadyPay: 0,
				otherPay: 0,
				bufferData: [],
				remark: '',
				list: [],
				printHeight: 0,
				qianhuoCount: 0,
				zhiqianqiankuan: 0,
				isShare: false,
				yuedikou: 0,
				leijiqiankuan: 0,
				id: '',
				type: '',
				bigImg: [],
				supplier: [],
				dealings: [],
				collection: [],
				returnInv: 0,
				storeFlag: ""
			}
		},
		components: {
			kkPrinter
		},
		filters: {
			sliceMsg(val) {
				var name = ''
				if (typeof(val) == 'string') {
					let newObj = JSON.parse(val)
					for (let as in newObj) {
						name += newObj[as] + '/'
					}
				}
				return name;
			}
		},
		onShareAppMessage() {
			//禁止转发
			wx.updateShareMenu({
				isPrivateMessage: true,
				success() {},
				fail() {}
			})
			if (this.returnInv == 1) {
				return {
					title: this.shopName + '  ' + this.sales.createTime + '的采购退货单',
					imageUrl: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/b28b3d46c21d4f60a334b25f56175cf3.jpg',
					path: '/package1/index/waitStorageDetail?returnInv=1&id=' + this.sales.id + '&shopId=' + uni
						.getStorageSync('shopId')
				}

			} else {
				return {
					title: this.shopName + '  ' + this.sales.createTime + '的采购单',
					imageUrl: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/b28b3d46c21d4f60a334b25f56175cf3.jpg',
					path: '/package1/index/waitStorageDetail?id=' + this.sales.id + '&shopId=' + uni.getStorageSync(
						'shopId')
				}
			}

		},
		onShow() {
			// 初始化蓝牙模块
			wx.openBluetoothAdapter({
				mode: 'central'
			})
			this.shopId = uni.getStorageSync('shopId')
		},
		onLoad(option) {
			this.id = option.id
			this.returnInv = option.returnInv
			this.storeFlag = option.storeFlag || ""
			if (option.returnInv == 1) {
				this.getWaitStorage(option.id)
				uni.setNavigationBarTitle({
					title: '采购退货详情'
				});
			} else {
				this.getWaitStorage(option.id)
				this.collectionList(option.id)
			}
			this.isShare = option.shopId ? true : false
			this.type = uni.getStorageSync('type')
		},
		methods: {
			confirmInventory() {
				let that = this;
				let countList = []
				for (let i = 0; i < that.goodsList.length; i++) {
					if (that.goodsList[i].purchaseQian > 0) {
						let data = {
							productName: that.goodsList[i].productName,
							productSn: that.goodsList[i].productSn,
							productId: that.goodsList[i].productId,
							productCount: that.goodsList[i].purchaseQian
						}
						countList.push(data)
					}
				}
				that.$nextTick(() => {
					that.tui.request("/app/purchaseConfirm/addPurchaseConfirm", "POST", {
						purchaseId: that.sales.id, //入库单id
						purchaseTime: that.sales.createTime, //入库单时间
						createBy: that.sales.createBy, //入库人
						createByName: that.sales.createByName,
						supplierName: that.sales.supplierName, //供应商名
						supplierId: that.sales.supplierId, // 供应商id
						purchaseConfirmDetailsList: countList //修改了的值
					}, false, false).then((res) => {
						if (res.code == 200) {
							uni.showToast({
								title: "确认成功！",
								icon: 'none',
								duration: 1000
							})
							uni.navigateBack();
						} else {
							that.tui.toast(res.message)
						}
					}).catch((res) => {})
				})
			},
			getPrintHeight() {
				let that = this;
				
				this.printHeight = 960
				for (let i = 0; i < that.newData.length; i++) {
					this.printHeight += 40
					for (let m = 0; m < that.newData[i].stockLogList1.length; m++) {
						this.printHeight += 40
					}
				}
				
			},
			getChildrenPic(img) {
				let that = this;
				this.tui.request("/app/productPicture/getProductPictureByProductId", "POST", {
					productId: img.productId,
				}, false, true).then((res) => {
					if (res.code == 200) {
						img.productPictures = []
						if (res.result.length > 0) {
							for (let i = 0; i < res.result.length; i++) {
								let data = {
									productPicture: res.result[i].productPicture
								}
								img.productPictures.push(data)
							}
						}

						setTimeout(res1 => {
							
							that.largeImg(img)
						}, 400);
					} else {
						this.tui.toast(res.message)
					}
				}).catch((res) => {})
			},
			largeImg(img) {
				
				if ((img.productPicture == null && img.productPictures == null) || (img.productPicture == '' && img
						.productPictures == null)) {
					this.tui.toast("暂无可展示的图片", 300)
					return
				}
				this.bigImg = []
				if (img.productPicture != null) {
					let data = {
						productPicture: img.productPicture
					}
					this.bigImg.push(data)
				}
				if (img.productPictures != null) {
					for (let i = 0; i < img.productPictures.length; i++) {
						this.bigImg.push(img.productPictures[i])
					}
				}
				this.$refs.imgPopup.open()
			},
			//回款历史
			collectionList(id) {
				///app/debt/selectByUserId
				this.tui.request('/app/dealingRecord/getDealingsRecordList', 'post', {
					orderId: id
				}, false, true).then(res => {
					this.collection = res.result
				}).catch(res => {});
			},
			getWaitStorage(id) {
				if (this.returnInv == 1) {
					this.tui.request("/app/purchaseReturn/getPurchaseReturnById", "post", {
						id: id
					}, false, true).then((res) => {

						if (res.code == 200) {
							for (let i = 0; i < res.result.purchaseReturnDetails.length; i++) {
								let obj = {}
								let attrMap = new Map()
								let newSaleDetailDTOList = []
								let num = 0

								for (let m = 0; m < res.result.purchaseReturnDetails[i].stockLogList1
									.length; m++) {
									if (attrMap.has(res.result.purchaseReturnDetails[i].stockLogList1[m]
											.attributeList) == true) {} else {
										newSaleDetailDTOList.push(res.result.purchaseReturnDetails[i]
											.stockLogList1[m])
										attrMap.set(res.result.purchaseReturnDetails[i].stockLogList1[m]
											.attributeList, num)
										num++
									}

								}
								res.result.purchaseReturnDetails[i].stockLogList1 = newSaleDetailDTOList
								if (res.result.purchaseReturnDetails[i].purchasePrice != null) {
									res.result.purchaseReturnDetails[i].zPrice = res.result.purchaseReturnDetails[
										i].purchasePrice * res.result.purchaseReturnDetails[i].productCount
								} else {
									res.result.purchaseReturnDetails[i].zPrice = 0
								}
								if (res.result.purchaseReturnDetails[i].purchasePrice == null || res.result
									.purchaseReturnDetails[i].purchasePrice == '') {
									res.result.purchaseReturnDetails[i].purchasePrice = 0
								}
								res.result.purchaseReturnDetails[i].lsPrice = res.result.purchaseReturnDetails[i]
									.lsPrice
							}
							setTimeout(res => {

							}, 500)
							if (res.result.purchaseReturn.inStorageStatus == 0) {
								this.tui.request('/app/debt/selectByUserId', 'post', {
									shopId: uni.getStorageSync('shopId'),
									userId: res.result.dealingsRecords[0].dealingsUserId
								}, false, true).then((res1) => {
									this.zhiqianqiankuan = res1.result.amountOwed
									this.dealings = res1.result
									this.dealings.lastDebtAmount = res1.result.amountOwed
									this.dealings.dealingsUserName = res1.result.userName
								}).catch(res => {});
							} else {
								if (res.result.dealingsRecords != '') {
									this.zhiqianqiankuan = res.result.dealingsRecords[0].lastDebtAmount
									this.dealings = res.result.dealingsRecords[0]
								}

							}
							this.list = res.result.purchaseReturnDetails
							for (var i = 0; i < this.list.length; i++) {
								if (this.list[i].realPrice != '' && this.list[i].discountAmount == null) {
									this.list[i].discountAmount = this.list[i].realPrice
								}

								this.list[i].chengben = this.list[i].productCount * this.list[i].purchasePrice
							}
							this.sales.zongchengben = 0
							for (var i = 0; i < this.list.length; i++) {
								this.sales.zongchengben += this.list[i].chengben
							}
							this.newData = JSON.parse(JSON.stringify(this.list))
							this.sales.inStorageStatus = null
							this.sales = res.result.purchaseReturn

							this.noPay = res.result.purchaseReturn.noPay
							this.supplier = res.result.supplier
							this.remark = res.result.purchaseReturn.remark
							this.goodsList = res.result.purchaseReturnDetails
							this.getAllPrice()
							this.$nextTick(() => {
								setTimeout(res => {
									this.getPrintHeight()
								}, 1000)
							})
						} else {
							this.tui.toast(res.message)
						}
					}).catch((res) => {})

				} else {
					this.tui.request("/app/purchase/getPurchaseAllData", "post", {
						id: id
					}, false, true).then((res) => {

						if (res.code == 200) {
							for (let i = 0; i < res.result.purchaseDetails.length; i++) {
								if (res.result.purchaseDetails[i].realPrice != '' && res.result.purchaseDetails[i]
									.discountAmount == null) {
									res.result.purchaseDetails[i].discountAmount = res.result.purchaseDetails[i]
										.realPrice
								}

								res.result.purchaseDetails[i].chengben = res.result.purchaseDetails[i]
									.productCount * res.result.purchaseDetails[i].purchasePrice
								res.result.purchase.zongchengben = 0
								res.result.purchase.zongchengben += res.result.purchaseDetails[i].chengben
								if (res.result.purchaseDetails[i].purchasePrice != null) {
									res.result.purchaseDetails[i].zPrice = res.result.purchaseDetails[i]
										.purchasePrice * res.result.purchaseDetails[i].productCount
								} else {
									res.result.purchaseDetails[i].zPrice = 0
								}
								if (res.result.purchaseDetails[i].purchasePrice == null || res.result
									.purchaseDetails[i].purchasePrice == '') {
									res.result.purchaseDetails[i].purchasePrice = 0
								}
								res.result.purchaseDetails[i].lsPrice = res.result.purchaseDetails[i].lsPrice
							}
							if (res.result.purchase.inStorageStatus == 0) {
								this.tui.request('/app/debt/selectByUserId', 'post', {
									shopId: uni.getStorageSync('shopId'),
									userId: res.result.supplier.id
								}, false, true).then((res1) => {
									this.zhiqianqiankuan = res1.result.amountOwed
									this.dealings = res1.result
									this.dealings.lastDebtAmount = res1.result.amountOwed
									this.dealings.dealingsUserName = res1.result.userName
								}).catch(res => {});
							} else {
								if (res.result.dealingsRecords != '') {
									this.zhiqianqiankuan = res.result.dealingsRecords[0].lastDebtAmount
									this.dealings = res.result.dealingsRecords[0]
								}

							}
							this.list = res.result.purchaseDetails

							this.newData = JSON.parse(JSON.stringify(this.list))
							
							this.sales = res.result.purchase

							this.noPay = res.result.purchase.noPay
							this.supplier = res.result.supplier
							this.remark = res.result.purchase.remark
							this.goodsList = res.result.purchaseDetails
							this.getAllPrice("1")
							this.$nextTick(() => {
								setTimeout(res => {
									this.getPrintHeight()
								}, 1000)
							})
						} else {
							this.tui.toast(res.message)
						}
					}).catch((res) => {})
				}

			},
			//计算欠款
			changePay(e) {
				if (this.linshiPrice == e.target.value) {
					this.alreadyPay = e.target.value
				} else if (Number(e.detail.value) > Number(this.shouldPay)) {
					this.alreadyPay = this.shouldPay
				} else {
					if (e.target.value == '') {
						this.alreadyPay = this.linshiPrice
					} else {
						this.alreadyPay = e.target.value
						if ((this.shouldPay - this.alreadyPay) <= Math.abs(this.zhiqianqiankuan) && this.zhiqianqiankuan <
							0) {
							this.yuedikou = this.shouldPay - this.alreadyPay
						} else if ((this.shouldPay - this.alreadyPay) > Math.abs(this.zhiqianqiankuan) && this
							.zhiqianqiankuan < 0) {
							this.yuedikou = Math.abs(this.zhiqianqiankuan)
						}

					}
				}
				this.noPay = this.shouldPay - this.alreadyPay - this.yuedikou
				this.noPay = this.noPay.toFixed(2)
				this.leijiqiankuan = Number(this.zhiqianqiankuan) + Number(this.yuedikou) + Number(this.noPay)
			},
			//打印小票
			onPrintSmall() {
				let that = this;
				let strCmd = ''
				let pageNum = 1
				let Xindex = 0
				that.yNum = 405

				strCmd = blesdk.CreatCPCLPage(1080, this.printHeight >= (1990 * pageNum) ? 1990 : this.printHeight, 1, 0,
					0);
				strCmd += blesdk.addCPCLSETMAG(4, 4)
				blesdk.addCPCLSETBOLD('bold')
				strCmd += blesdk.addCPCLLocation(2);
				strCmd += blesdk.addCPCLText('0', '120', '24', '0', 0, this.shopName)

				strCmd += blesdk.addCPCLSETMAG(1, 1)
				strCmd += blesdk.addCPCLLocation(0);
				blesdk.addCPCLSETBOLD('bold')
				strCmd += blesdk.addCPCLText('0', '300', '24', '0', 0, '供应商:' + (that.dealings.dealingsUserName ? that
					.dealings.dealingsUserName : '默认供应商'))
				strCmd += blesdk.addCPCLSETMAG(1, 1)
				strCmd += blesdk.addCPCLLocation(0);
				strCmd += blesdk.addCPCLText('500', '300', '24', '0', 0, '单号:' + that.sales.id)
				strCmd += blesdk.addCPCLText('0', '350', '24', '0', 0, '操作人:' + that.sales.createByName)
				strCmd += blesdk.addCPCLText('500', '350', '24', '0', 0, '日期:' + that.sales.createTime)


				strCmd += blesdk.addCPCLText('0', '390', '24', '0', 0,
					'-----------------------------------------------------------------------------------')
				strCmd += blesdk.addCPCLText('10', that.yNum += 40, '24', '0', 0, '货号(名称)')
				strCmd += blesdk.addCPCLText('320', that.yNum, '24', '0', 0, '规格')
				strCmd += blesdk.addCPCLText('520', that.yNum, '24', '0', 0, '数量')
				strCmd += blesdk.addCPCLText('620', that.yNum, '24', '0', 0, '单价')
				strCmd += blesdk.addCPCLText('720', that.yNum, '24', '0', 0, '总价')
				for (var i = 0; i < that.newData.length; i++) {
					if (that.yNum + 25 >= 1990) {
						strCmd += blesdk.addCPCLPrint();
						that.bufferData.push(strCmd);

						strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 25) >= 1990 ? 1990 : (this
							.printHeight - that.yNum + 25), 1, 0, 162);
						that.yNum = 0
						pageNum++

						strCmd += blesdk.addCPCLText('0', that.yNum += 25, '24', '0', 0,
							'-----------------------------------------------------------------------------------')
					} else {
						strCmd += blesdk.addCPCLText('0', that.yNum += 25, '24', '0', 0,
							'-----------------------------------------------------------------------------------')
					}

					if (that.yNum + 64 >= 1990) {
						strCmd += blesdk.addCPCLPrint();
						that.bufferData.push(strCmd);
						strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 64) >= 1990 ? 1990 : (this
							.printHeight - that.yNum + 64), 1, 0, 162);
						that.yNum = 0
						pageNum++

						for (var m = 0; m < that.newData[i].stockLogList1.length; m++) {
							if (that.yNum + 64 >= 1990) {
								strCmd += blesdk.addCPCLPrint();
								that.bufferData.push(strCmd);
								strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 64) >= 1990 ?
									1990 : (
										this.printHeight - that.yNum + 64), 1, 0, 162);
								that.yNum = 0

								pageNum++

								if (that.newData[i].productName == that.newData[i].productSn) {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
											1) + '.' + '【退】' + that.newData[i].productSn)
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
											1) + '. ' + that.newData[i].productSn)
									}
								} else {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '.' + '【退】' + that
											.newData[i].productSn + '(' + (that.newData[i]
												.productName == null ? '' : that.newData[i].productName) + ')')
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
											1) + '. ' + that.newData[i].productSn + '(' + (that.newData[i]
											.productName == null ? '' : that.newData[i].productName) + ')')
									}
								}


								if (that.shopId == '1820269107191353344' || that.shopId == '1818888277105709056') {
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均色') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均色/g, '分色')
									}
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均码') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均码/g, '分码')
									}
								}
								strCmd += blesdk.addCPCLText('320', that.yNum, '24', '0', 0, that
									.slicePrint(that.newData[i].stockLogList1[m].attributeList))

								strCmd += blesdk.addCPCLText('520', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].productCount)
								strCmd += blesdk.addCPCLText('620', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].purchasePrice)

								strCmd += blesdk.addCPCLText('720', that.yNum, '24', '0', 0, (that.newData[i]
									.stockLogList1[m].purchasePrice * that.newData[i].stockLogList1[m]
									.productCount))
							} else {

								if (that.newData[i].productName == that.newData[i].productSn) {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
											1) + '. ' + '【退】' + that.newData[i].productSn)
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
											1) + '. ' + that.newData[i].productSn)
									}


								} else {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '.' + '【退】' + that
											.newData[i].productSn + '(' + (that.newData[i]
												.productName == null ? '' : that.newData[i].productName) + ')')
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '. ' + that
											.newData[i].productSn + '(' + (that.newData[i]
												.productName == null ? '' : that.newData[i].productName) + ')')
									}
								}
								if (that.shopId == '1820269107191353344' || that.shopId == '1818888277105709056') {
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均色') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均色/g, '分色')
									}
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均码') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均码/g, '分码')
									}
								}
								strCmd += blesdk.addCPCLText('320', that.yNum, '24', '0', 0, that
									.slicePrint(that.newData[i].stockLogList1[m].attributeList))

								strCmd += blesdk.addCPCLText('520', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].productCount)
								strCmd += blesdk.addCPCLText('620', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].purchasePrice)

								strCmd += blesdk.addCPCLText('720', that.yNum, '24', '0', 0, (that.newData[i]
									.stockLogList1[m].purchasePrice * that.newData[i].stockLogList1[m]
									.productCount))
							}

						}
					} else {
						for (var m = 0; m < that.newData[i].stockLogList1.length; m++) {
							if (that.yNum + 64 >= 1990) {
								strCmd += blesdk.addCPCLPrint();
								that.bufferData.push(strCmd);
								strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 64) >= 1990 ?
									1990 : (
										this.printHeight - that.yNum + 64), 1, 0, 162);
								that.yNum = 0

								pageNum++

								if (that.newData[i].productName == that.newData[i].productSn) {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '.' + '【退】' + that
											.newData[i].productSn)
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '. ' + that
											.newData[i].productSn)
									}


								} else {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '.' + '【退】' + that
											.newData[i].productSn + '(' + (that.newData[i]
												.productName == null ? '' : that.newData[i].productName) + ')')
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '. ' + that
											.newData[i].productSn + '(' + (that.newData[i]
												.productName == null ? '' : that.newData[i].productName) + ')')
									}
								}


								if (that.shopId == '1820269107191353344' || that.shopId == '1818888277105709056') {
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均色') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均色/g, '分色')
									}
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均码') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均码/g, '分码')
									}
								}
								strCmd += blesdk.addCPCLText('320', that.yNum, '24', '0', 0, that
									.slicePrint(that.newData[i].stockLogList1[m].attributeList))

								strCmd += blesdk.addCPCLText('520', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].productCount)

								strCmd += blesdk.addCPCLText('620', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].purchasePrice)


								strCmd += blesdk.addCPCLText('720', that.yNum, '24', '0', 0, (that.newData[i]
									.stockLogList1[m].purchasePrice * that.newData[i].stockLogList1[m]
									.productCount))

							} else {

								if (that.newData[i].productName == that.newData[i].productSn) {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
											1) + '.' + '【退】' + that.newData[i].productSn)
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
											1) + '. ' + that.newData[i].productSn)
									}
								} else {
									if (that.returnInv == 1) {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '.' + '【退】' + that
											.newData[i].productSn + '(' + (that.newData[i]
												.productName == null ? '' : that.newData[i].productName) + ')')
									} else {
										strCmd += blesdk.addCPCLText('0', that.yNum += 40, '24', '0', 0, (Xindex +=
												1) + '. ' + that
											.newData[i].productSn + '(' + (that.newData[i]
												.productName == null ? '' : that.newData[i].productName) + ')')
									}
								}

								if (that.shopId == '1820269107191353344' || that.shopId == '1818888277105709056') {
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均色') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均色/g, '分色')
									}
									if (that.newData[i].stockLogList1[m].attributeList.indexOf('均码') != -1) {
										that.newData[i].stockLogList1[m].attributeList = that.newData[i].stockLogList1[
												m]
											.attributeList.replace(/均码/g, '分码')
									}
								}
								strCmd += blesdk.addCPCLText('320', that.yNum, '24', '0', 0, that
									.slicePrint(that.newData[i].stockLogList1[m].attributeList))


								strCmd += blesdk.addCPCLText('520', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].productCount)

								strCmd += blesdk.addCPCLText('620', that.yNum, '24', '0', 0, that.newData[i]
									.stockLogList1[m].purchasePrice)

								strCmd += blesdk.addCPCLText('720', that.yNum, '24', '0', 0, (that.newData[i]
									.stockLogList1[m].purchasePrice * that.newData[i].stockLogList1[m]
									.productCount))
							}
						}
					}

				}
				if (that.yNum + 25 >= 1990) {
					strCmd += blesdk.addCPCLPrint();
					that.bufferData.push(strCmd);

					strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 25) >= 1990 ? 1990 : (this
						.printHeight - that.yNum + 25), 1, 0, 162);
					that.yNum = 0
					pageNum++

					strCmd += blesdk.addCPCLText('0', that.yNum += 25, '24', '0', 0,
						'-----------------------------------------------------------------------------------')
				} else {
					strCmd += blesdk.addCPCLText('0', that.yNum += 25, '24', '0', 0,
						'-----------------------------------------------------------------------------------')
				}
				strCmd += blesdk.addCPCLSETMAG(1, 1)
				strCmd += blesdk.addCPCLLocation(0);

				if (that.yNum + 84 >= 1990) {
					strCmd += blesdk.addCPCLPrint();
					that.bufferData.push(strCmd);

					strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 84) >= 1990 ? 1990 : (this
						.printHeight - that.yNum + 84), 1, 0, 162);
					that.yNum = 0
					pageNum++
					if (that.returnInv == 1) {
						strCmd += blesdk.addCPCLText('0', that.yNum += 60, '24', '0', 0, '退货数量:' + this.sales.totalAmount)
						strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '退货金额:' + this.sales.alreadyPay)
					} else {
						strCmd += blesdk.addCPCLText('0', that.yNum += 60, '24', '0', 0, '采购数量:' + this.sales.totalAmount)
						strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '采购金额:' + this.sales.shouldPay)
					}

				} else {
					if (that.returnInv == 1) {
						strCmd += blesdk.addCPCLText('0', that.yNum += 60, '24', '0', 0, '退货数量:' + this.sales.totalAmount)
						strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '退货金额:' + this.sales.alreadyPay)
					} else {
						strCmd += blesdk.addCPCLText('0', that.yNum += 60, '24', '0', 0, '采购数量:' + this.sales.totalAmount)
						strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '采购金额:' + this.sales.shouldPay)
					}
				}

				if (this.returnInv != 1) {
					if (that.yNum + 84 >= 1990) {
						strCmd += blesdk.addCPCLPrint();
						that.bufferData.push(strCmd);
						strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 84) >= 1990 ? 1990 : (this
							.printHeight - that.yNum + 84), 1, 0, 162);
						that.yNum = 0
						pageNum++
						strCmd += blesdk.addCPCLText('610', that.yNum, '24', '0', 0, '余额抵扣:' + that.sales
							.balanceDeductionAmount)
					} else {
						strCmd += blesdk.addCPCLSETMAG(1, 1)
						strCmd += blesdk.addCPCLText('610', that.yNum, '24', '0', 0, '余额抵扣:' + that.sales
							.balanceDeductionAmount)
					}
				}


				if (that.yNum + 54 >= 1990) {
					strCmd += blesdk.addCPCLPrint();
					that.bufferData.push(strCmd);

					strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 54) >= 1990 ? 1990 : (this
						.printHeight - that.yNum + 54), 1, 0, 162);
					that.yNum = 0
					pageNum++
					if (that.dealings.lastDebtAmount >= 0) {
						strCmd += blesdk.addCPCLText('0', that.yNum += 54, '24', '0', 0, '之前欠款:' + that.dealings
							.lastDebtAmount)
					} else if (that.dealings.lastDebtAmount < 0) {
						strCmd += blesdk.addCPCLText('0', that.yNum += 54, '24', '0', 0, '之前余额:' + Math.abs(that
							.dealings
							.lastDebtAmount))
					} else {
						strCmd += blesdk.addCPCLText('0', that.yNum += 54, '24', '0', 0, '之前欠款:0')
					}
				} else {
					strCmd += blesdk.addCPCLSETMAG(1, 1)
					if (that.dealings.lastDebtAmount >= 0) {
						strCmd += blesdk.addCPCLText('0', that.yNum += 54, '24', '0', 0, '之前欠款:' + that.dealings
							.lastDebtAmount)
					} else if (that.dealings.lastDebtAmount < 0) {
						strCmd += blesdk.addCPCLText('0', that.yNum += 54, '24', '0', 0, '之前余额:' + Math.abs(that
							.dealings
							.lastDebtAmount))
					} else {
						strCmd += blesdk.addCPCLText('0', that.yNum += 54, '24', '0', 0, '之前欠款:0')
					}
				}

				if (this.returnInv != 1) {
					if (that.yNum + 54 >= 1990) {

						strCmd += blesdk.addCPCLPrint();
						that.bufferData.push(strCmd);

						strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 54) >= 1990 ? 1990 : (this
							.printHeight - that.yNum + 54), 1, 0, 162);
						that.yNum = 0
						pageNum++
						if (that.sales.noPay >= 0) {
							strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '本次欠款:' + that.sales.noPay)
						} else if (that.sales.noPay < 0) {
							strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '本次余额:' + Math.abs(that
								.sales.noPay))
						} else {
							strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '本次欠款:0')
						}
					} else {
						strCmd += blesdk.addCPCLSETMAG(1, 1)
						if (that.sales.noPay >= 0) {
							strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '本次欠款:' + that.sales.noPay)
						} else if (that.sales.noPay < 0) {
							strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '本次余额:' + Math.abs(that.sales
								.noPay))
						} else {
							strCmd += blesdk.addCPCLText('300', that.yNum, '24', '0', 0, '本次欠款:0')
						}
					}
				}
				let dayinWidth = 610
				if (this.returnInv == 1) {
					dayinWidth = 300
				}
				if (that.yNum + 54 >= 1990) {

					strCmd += blesdk.addCPCLPrint();
					that.bufferData.push(strCmd);

					strCmd = blesdk.CreatCPCLPage(1080, (this.printHeight - that.yNum + 54) >= 1990 ? 1990 : (this
						.printHeight - that.yNum + 54), 1, 0, 162);
					that.yNum = 0
					pageNum++
					if (that.dealings.balanceDue >= 0) {
						strCmd += blesdk.addCPCLText(dayinWidth, that.yNum, '24', '0', 0, '累计欠款:' + that.dealings
							.balanceDue)
					} else if (that.dealings.balanceDue < 0) {
						strCmd += blesdk.addCPCLText(dayinWidth, that.yNum, '24', '0', 0, '累计余额:' + Math.abs(that
							.dealings.balanceDue))
					} else {
						strCmd += blesdk.addCPCLText(dayinWidth, that.yNum, '24', '0', 0, '累计欠款:0')
					}
				} else {
					strCmd += blesdk.addCPCLSETMAG(1, 1)
					if (that.dealings.balanceDue >= 0) {
						strCmd += blesdk.addCPCLText(dayinWidth, that.yNum, '24', '0', 0, '累计欠款:' + that.dealings
							.balanceDue)
					} else if (that.dealings.balanceDue < 0) {
						strCmd += blesdk.addCPCLText(dayinWidth, that.yNum, '24', '0', 0, '累计余额:' + Math.abs(that
							.dealings.balanceDue))
					} else {
						strCmd += blesdk.addCPCLText(dayinWidth, that.yNum, '24', '0', 0, '累计欠款:0')
					}
					strCmd += blesdk.addCPCLPrint();
					that.bufferData.push(strCmd);
				}

				
				this.$nextTick(() => {
					that.bufferData = []
				})
			},
			//截取
			slicePrint(val) {
				var name = ''
				if (typeof(val) == 'string') {
					let newObj = JSON.parse(val)
					for (let as in newObj) {
						name += newObj[as] + '/'
					}
				}
				return name;
			},
			//回款金额输入框
			inputDialogToggle() {
				this.$refs.inputDialog.open()
			},
			sureNpPay(e) {
				if (e > this.noPay) {
					uni.showToast({
						title: "回款金额不应超过欠款金额！",
						icon: 'none'
					})
					return
				}
				this.tui.request('/app/purchase/editPayPrice', 'post', {
					id: this.sales.id,
					price: e
				}, false, true).then(res => {
					uni.showToast({
						title: "成功！",
						icon: 'none'
					})
					uni.navigateBack();
				}).catch(res => {});
			},
			PriceAndWho(e, id, type) {
				if (type == 'pi') {
					if (this.linshiPrice == e.target.value) {
						this.goodsList[id].wholesalePrice = e.target.value
					} else {
						if (e.detail.value == '') {
							this.goodsList[id].wholesalePrice = this.linshiPrice
						} else {
							this.goodsList[id].wholesalePrice = Number(e.detail.value)
						}
					}
				} else if (type == 'caigou') {
					this.shouldPay = 0
					if (this.linshiPrice == e.target.value) {
						this.goodsList[id].purchasePrice = e.target.value
					} else {
						if (e.detail.value == '') {
							this.goodsList[id].purchasePrice = this.linshiPrice
						} else {
							this.goodsList[id].purchasePrice = Number(e.detail.value)
						}
					}
					this.goodsList[id].zPrice = this.goodsList[id].purchasePrice * this.goodsList[id].productCount;
					this.getAllPrice()
				} else if (type == 'qianhuo') {
					if (this.qianhuoCount == e.target.value) {
						this.goodsList[id].purchaseQian = e.target.value
					} else {
						if (e.detail.value == '') {
							this.goodsList[id].purchaseQian = this.qianhuoCount
						} else {
							this.goodsList[id].purchaseQian = Number(e.detail.value)
						}
					}
				} else {
					if (this.linshiPrice == e.target.value) {
						// this.goodsList[id].price = e.target.value
						this.goodsList[id].lsPrice = e.target.value
					} else {
						if (e.detail.value == '') {
							// this.goodsList[id].price = this.linshiPrice
							this.goodsList[id].lsPrice = this.linshiPrice
						} else {
							// this.goodsList[id].price = Number(e.detail.value)
							this.goodsList[id].lsPrice = Number(e.detail.value)
						}
					}
				}
				this.$forceUpdate()
			},
			obtainPrice(e, type, num) {
				this.linshiPrice = e.target.value
				if (type == 'pifa') {
					this.goodsList[num].wholesalePrice = ''
					this.$forceUpdate()
				} else if (type == 'lingshou') {
					this.goodsList[num].price = ''
					this.$forceUpdate()
				} else if (type == 'caigou') {
					this.goodsList[num].purchasePrice = ''
					this.$forceUpdate()
				} else if (type == 'qianhuo') {
					this.qianhuoCount = e.target.value
					this.goodsList[num].purchaseQian = ''
					this.$forceUpdate()
				}
			},
			inventorySubmit() {
				this.claerSubmitBtn += 1
				if (this.claerSubmitBtn == 1) {
					let that = this;
					let purchase = {
						id: this.id,
						alreadyPay: this.alreadyPay, //已付金额
						noPay: this.noPay, //欠款
						balanceDeductionAmount: this.yuedikou,
						shouldPay: this.shouldPay, //应付金额
						totalAmount: this.sales.totalAmount, //总数量
						remark: this.remark,
						supplierId: this.sales.supplierId, //供应商id和姓名
						supplierName: this.sales.supplierName
					}
					
					for (let i = 0; i < this.goodsList.length; i++) {
						if (this.goodsList[i].wholesalePrice == '' || this.goodsList[i].wholesalePrice == null) {
							this.goodsList[i].wholesalePrice = 0
						}
						if (this.goodsList[i].purchasePrice == '' || this.goodsList[i].purchasePrice == null) {
							this.goodsList[i].purchasePrice = 0
						}
						for (let m = 0; m < this.goodsList[i].stockLogList1.length; m++) {
							if (this.goodsList[i].stockLogList1[m].productCount == '' || this.goodsList[i].stockLogList1[m]
								.productCount == null) {
								this.goodsList[i].stockLogList1[m].productCount = 0
							}
						}
					}
					setTimeout(res => {
						this.tui.request("/app/stock/putInPrice", "post", {
							purchase: purchase,
							purchaseDetails: this.goodsList
						}, false, false).then((res) => {
							if (res.code == 200) {
								uni.showToast({
									title: "入库成功",
									icon: 'none'
								})
								uni.navigateBack({
									delta: 2
								})
							} else {
								uni.showToast({
									title: "入库失败",
									icon: 'none'
								})
							}
						})
					}, 500)
				} else {
					this.tui.toast('请勿重复输入！')
				}

			},
			// 取消订单
			cancelOrder(item) {
				let that = this;
				// await this.getReturnOrder(item.id)
				this.tui.modal("提示", "您确定要撤销此采购单吗？", true, (res) => {
					if (res) {
						that.cancelOk(item)
					}
				})
			},
			// 取消订单
			cancelOk() {
				let that = this;
				that.tui.request('/app/purchase/cancelPurchase', "POST", {
					id: that.sales.id
				}, true, true).then((res1) => {
					if (res1.code == 200) {
						that.goSaleGoods()
					} else {
						that.tui.toast(res.message)
					}
				}).catch((res1) => {})
			},
			sliceMsg(val) {
				var name = ''
				if (typeof(val) == 'string') {
					let newObj = JSON.parse(val)
					for (let as in newObj) {
						name += newObj[as] + '/'
					}
				}
				return name;
			},
			//带参数跳转到入库页
			async goSaleGoods() {
				let that = this;
				let dataList = []
				
				if (!this.goodsList) {
					this.goodsList = []
				}
				if (this.goodsList) {
					for (let i = 0; i < this.goodsList.length; i++) {

						let obj = {}
						let attrMap = new Map()
						let newSaleDetailDTOList = []
						let num = 0

						for (let m = 0; m < this.goodsList[i].stockLogList1.length; m++) {
							if (attrMap.has(this.goodsList[i].stockLogList1[m].attributeList) == true) {
								let hasCount = attrMap.get(this.goodsList[i].stockLogList1[m].attributeList)
								newSaleDetailDTOList[hasCount].productCount = Number(newSaleDetailDTOList[hasCount]
									.productCount) + Number(this.goodsList[i].stockLogList1[m].productCount)
							} else {
								this.goodsList[i].stockLogList1[m].name = this.sliceMsg(this.goodsList[i]
									.stockLogList1[m].attributeList)
								newSaleDetailDTOList.push(this.goodsList[i].stockLogList1[m])
								attrMap.set(this.goodsList[i].stockLogList1[m].attributeList, num)
								num++
							}

						}
						obj.saleDetailQueryDTO = newSaleDetailDTOList
						obj.num = 0
						obj.attrId = this.goodsList[i].attrId
						obj.id = this.goodsList[i].productId
						obj.purchasePrice = this.goodsList[i].stockLogList1[0].purchasePrice
						obj.customerCategoryRule = this.goodsList[i].customerCategoryRule != null ? JSON.parse(this
							.goodsList[i].customerCategoryRule) : null
						obj.price = this.goodsList[i].price
						obj.categoryId = this.goodsList[i].categoryId
						obj.productName = this.goodsList[i].productName
						obj.productPicture = this.goodsList[i].productPicture
						obj.productSn = this.goodsList[i].productSn
						obj.productId = this.goodsList[i].productId
						obj.wholesalePrice = this.goodsList[i].wholesalePrice
						obj.saleId = this.sales.id
						obj.remark = this.sales.remark
						obj.xsyId = this.sales.createBy
						obj.createByName = this.sales.createByName
						dataList.push(obj)
					}
				} else {
					let obj = {}
					obj.num = 0
					obj.price = 0
					obj.saleId = this.sales.id
					obj.remark = this.sales.remark
					obj.xsyId = this.sales.createBy
					obj.createByName = this.sales.createByName
					dataList.push(obj)
				}
				uni.setStorageSync('AiInventoryId', "")

				
				await this.tui.request("/app/debt/selectByUserId", "post", {
					shopId: uni.getStorageSync('shopId'),
					userId: that.sales.supplierId
				}, false, true).then((res) => {
					if (res.code == 200) {
						
						res.result.noEarn = res.result.amountOwed
						res.result.consigneeName = res.result.userName
						res.result.id = res.result.userId
						uni.setStorageSync('khName', JSON.stringify(res.result))
						uni.setStorageSync('carList1', JSON.stringify(dataList))
						uni.setStorageSync('hangOrder', true)
						uni.navigateTo({
							url: '/package1/AI/voiceInventory',
						})
					}
				})
			},
			returnPrice() {
				let that = this;

				uni.showModal({
					title: "提示",
					content: "确定撤销该采购单吗？",
					success: function(res) {
						uni.showLoading({
							title: '加载中...'
						})
						if (res.confirm) {
							that.tui.request("/app/purchase/cancelPurchase", "POST", {
								id: that.sales.id,
							}, false, true).then((res) => {
								if (res.code == 200) {
									// that.pages = 1;
									// that.pageNum = 1;
									// that.list = [];
									// that.list[index].delFlag = 1
									that.$forceUpdate()
									// that.getList()
									uni.showToast({
										title: "撤销成功！",
										icon: 'none',
										duration: 1000
									})
									setTimeout(res1=>{
										uni.navigateBack()
									},1000)
									
								} else {
									that.tui.toast(res.message)
								}
							})
						}
						setTimeout(res => {
							uni.hideLoading();
						}, 500)
					}
				})
			},
			batchPrint() {
				uni.navigateTo({
					url: "/package1/inventory/batchPrint?purchase=" + JSON.stringify(this.sales) +
						'&purchaseDetails=' + JSON.stringify(this.goodsList)
				})
			},
			//编辑每一个的单价
			clickCollapse(index) {
				this.index = index
				this.$refs.priceDialog.val = ''
				this.$refs.priceDialog.open()
			},
			//计算价格
			changePrice(val) {
				let that = this;
				this.$refs.purInput.val = ''
				that.shouldPay = 0
				that.goodsList[that.index].purchasePrice = val
				that.goodsList[that.index].zPrice = val * that.goodsList[that.index].productCount;
				this.getAllPrice()
			},
			//计算总金额和总数量
			getAllPrice(type) {
				let that = this;
				this.shouldPay = 0
				this.totalAmount = 0
				this.goodsList.forEach(function(value, key) {
					if (type == '1') {
						value.purchaseQian = 0
					}
					that.shouldPay = that.shouldPay + value.zPrice
				})
				this.$nextTick(() => {
					if (parseFloat(that.zhiqianqiankuan) < 0) {
						if (that.shouldPay > Math.abs(that.zhiqianqiankuan)) {
							that.yuedikou = Math.abs(that.zhiqianqiankuan)
							this.alreadyPay = this.shouldPay - Math.abs(that.zhiqianqiankuan)
						} else if (that.shouldPay <= Math.abs(that.zhiqianqiankuan)) {
							that.yuedikou = that.shouldPay
							that.alreadyPay = 0
						}
					} else {
						this.alreadyPay = this.shouldPay
					}
					that.shouldPay = that.shouldPay.toFixed(2)

					that.noPay = this.shouldPay - (this.alreadyPay == '' ? 0 : this.alreadyPay) - that.yuedikou
					that.noPay = that.noPay.toFixed(2)
					this.leijiqiankuan = Number(this.zhiqianqiankuan) + Number(this.yuedikou) + Number(this.noPay)
					this.$forceUpdate()
				})
			},
		},
	}
</script>

<style lang="scss">
	.container {
		padding-bottom: 118rpx;

		.boxbg {
			background-color: #fff;
			margin: 30upx;
			padding: 20upx;
			border-radius: 10upx;
			box-shadow: 0px 1px 10px 2px #e2e2e2;
		}

		.tui-order-info {
			margin-top: 20rpx;
		}

		.tui-order-content {
			width: 100%;
			padding: 24rpx 30rpx;
			box-sizing: border-box;
			background: #fff;
			font-size: 24rpx;
			line-height: 30rpx;
		}

		.tui-order-flex {
			display: flex;
			padding-top: 18rpx;
		}

		.tui-order-flex:first-child {
			padding-top: 0
		}

		.tui-item-title {
			width: 132rpx;
			flex-shrink: 0;
		}

		.tui-item-content {
			color: #666;
			line-height: 32rpx;
		}

		.tui-order-title {
			position: relative;
			font-size: 28upx;
			line-height: 28upx;
			padding-left: 16upx;
			box-sizing: border-box;
		}

		.tui-order-title::before {
			content: '';
			position: absolute;
			left: 0;
			top: 0;
			border-left: 8upx solid $u-primary;
			height: 120%;
			border-radius: 4upx;
		}

		// .boxbg {
		// 	background-color: #fff;
		// 	margin: 30upx;
		// 	border-radius: 10upx;
		// 	box-shadow: 0px 1px 10px 2px #e2e2e2;
		// }

		.tui-order-item {
			.u-collapse-content {
				display: flex;
				justify-content: space-between;
				line-height: 30px;
			}


			.tui-goods-info {
				width: 100%;
				box-sizing: border-box;
				background: #fff;
				line-height: 26px;
				border-top: 10px solid #eee;

				.tui-price-flex {
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.tui-size32 {
					font-size: 32rpx;
					font-weight: 500;
				}

				.tui-size-24 {
					font-size: 24rpx;
				}

				.tui-price-large {
					font-size: 32rpx;

					.lineText {
						text-decoration: line-through;
						font-size: 12px;
						color: #888;
					}
				}

				.tui-flex-shrink {
					flex-shrink: 0;
				}

				.tui-goods-price {
					width: 100%;
					display: flex;
					align-items: flex-end;
					justify-content: flex-end;
					font-size: 24rpx;
				}

				.tui-primary-color {
					color: #EB0909;
				}

				.tui-pbtm20 {
					padding-bottom: 20rpx;
				}

			}
		}
	}

	.tui-tabbar {
		width: 100%;
		height: 98rpx;
		background: #fff;
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 26rpx;
		box-shadow: 0 0 1px rgba(0, 0, 0, .3);
		padding-bottom: env(safe-area-inset-bottom);
		z-index: 996;
	}

	.tui-btn-mr {
		width: 130rpx;
		height: 60rpx;
		background: #088FEB;
		color: #fff;
		border-radius: 10px;
		line-height: 60rpx;
		text-align: center;
		margin-right: 30rpx;
	}

	.shop-box {
		width: 95%;
		margin: 0 auto;
		position: relative;
	}

	.shop-name {
		width: 100%;
		height: 250rpx;
		line-height: 80rpx;
		border-top: 1px solid #eee;
		border-bottom: 1px solid #eee;
		font-size: 28rpx;
		font-weight: bold;
		display: flex;

		.uni-icons {
			color: #088FEB !important;
		}
	}

	.shop-productName {
		flex: 1;
		display: flex;
		flex-direction: column;
		padding-left: 20rpx;
	}

	.shop-productName view {
		height: 55rpx;
		line-height: 55rpx;
	}

	.shop-collapse {
		display: flex;
		height: 80rpx;
		font-size: 26rpx;
		line-height: 80rpx;
	}

	.shop-collapse text {
		flex: 1;
		text-align: center;
		padding-right: 40rpx;
		border-right: 1px solid #eee;
	}

	.content-list {
		width: 95%;
		margin: 0 auto;
		display: flex;
		height: 80rpx;
		border-bottom: 1px solid #eee;
	}

	.content-list:last-child {
		border-bottom: none;
		height: auto;
	}

	.list-name {
		width: 200rpx;
		text-align: left;
		line-height: 40px;
		height: 80rpx;
		padding-left: 20rpx;
	}

	.list-val {
		width: 560rpx;
		height: 80rpx;
		line-height: 80rpx;
	}

	.list-val input {
		width: 400rpx;
		height: 60rpx;
		display: inline-block;
		line-height: 60rpx;
		float: left;
		margin-top: 10rpx;
		padding-left: 20rpx;
		border-bottom: 1px solid #088FEB;
	}

	textarea {
		margin: 20rpx;
		border: 1px solid #eee;
		height: 150rpx;
		width: 500rpx;
	}

	.noPic {
		border-radius: 10px;
		width: 140rpx;
		height: 140rpx;
		text-align: center;
		line-height: 140rpx;
		color: #777;
		background: #eee;
	}

	.uni-tooltip {
		display: flex !important;
	}

	.price-box {
		width: 95%;
		margin: 10px auto;
		background: #eee;
		height: 80rpx;
		display: flex;
		line-height: 80rpx;
		text-align: center;
		overflow: hidden;
		border-radius: 10px;
		background: #FDF5E6;
		color: #EEB422;
		background: linear-gradient(180deg, #fff, #FDF5E6);
		border: 1px solid #FAEBD7;
	}

	.showImg-box {
		width: 700rpx;
		height: 1000rpx;
		border-radius: 10px;
	}

	.swiper-box {
		height: 1000rpx;
	}

	.swiper-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 1000rpx;
		color: #fff;
		background-color: #cee1fd;
		border-radius: 10px;
	}
</style>