<template>
	<view class="page1">
		<view class="title-box" style="height:8%;">
			<uni-search-bar class="uni-mt-10" radius="5" placeholder="商品名称/货号/供应商" cancelButton="none"
				@input="search" @clear="clearSearch" />
		</view>
		<view class="content-left">
			<view class="left-box" v-if="gateType == ''" v-for="(item, index) in indexList" :key="index"
				:class="item.parentId ? 'left-box-hover':''" @tap="clickLeftBtn(index)">
				<text style="width: 100%;height: 90rpx;line-height: 90rpx;display: inline-block;overflow: hidden;"
					:class="item.parentId ? 'red' :''">{{item.categoryName}}</text>
			</view>
		</view>
		<view class="content-right">
			<view class="right-box" v-for="(item,index) in shopList" :key="index" @tap="toggle('bottom',item)">
				<!-- 当商品的delFlag=0和未入库状态时，显示此遮罩，点击弹出弹窗提示不能操作 -->
				<!-- <view class="shop-mask" v-if="item.delFlag == 0"></view> -->
				<view class="box-left" @tap.stop="largeImg(item)">
					<view v-if="(item.buyCountNew!= null && item.buyCountNew!= undefined)" style="position: absolute;left: 110rpx;color: #fff;background: red;width: 45rpx;height: 40rpx;font-size: 28rpx;text-align: center;line-height: 40rpx;border-radius: 5px;">
						{{item.buyCountNew}}
					</view>
					<img class="img-radius" :src="item.productPicture" alt="" v-if="item.productPicture">
					<view class="noPic" v-else>暂无图片</view>
				</view>
				<view class="box-right">
					<view class="box-right-name">
						{{item.productSn==null?'':item.productSn}}({{item.productName == null ?'':item.productName}})
						<text style="color: red;" v-if="item.delFlag == 0">(已下架)</text>
					</view>
					<view class="box-right-num">供应商:{{item.supplierName== null?'':item.supplierName}}</view>
					<view class="box-right-price">
						<!-- <view class="price-box" v-if="storageType== 0">
							<text>{{item.inStorageStatus==0?'待入库':item.purchasePrice == null ?'新商品':item.purchasePrice}}</text>
							<text>采购价</text>
						</view> -->
						<view class="price-box">
							<text>{{item.wholesalePrice}}</text>
							<text>{{shopId == '1960543009070256129' ? '直播价' : '批发价'}}</text>
						</view>
						<view class="price-box">
							<text>{{item.price}}</text>
							<text>{{shopId == '1960543009070256129' ? '日常价' : '零售价'}}</text>
						</view>
						<view class="price-box" v-if="item.customPrice != '' && item.customPrice != null">
							<text>{{item.customPrice}}</text>
							<text>客户价</text>
						</view>
						<view class="price-box" @tap.stop="seeStockCount(item.stockCount,item.minusStockCount)">
							<text>{{item.stockCount + item.minusStockCount}}</text>
							<view>
								库存
								<uni-icons type="help" size="15"></uni-icons>
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="right-box" v-for="(item,index) in shopList1" :key="index" @tap="toggle('bottom',item)">
				<!-- 当商品的delFlag=0和未入库状态时，显示此遮罩，点击弹出弹窗提示不能操作 -->
				<!-- <view class="shop-mask" v-if="item.delFlag == 0 || item.purchasePrice==null || item.inStorageStatus == 0" @tap.stop="clickMask"></view> -->
				<view class="box-left" @tap.stop="largeImg(item)">
					<view v-if="(item.buyCountNew!= null && item.buyCountNew!= undefined)" style="position: absolute;left: 110rpx;color: #fff;background: red;width: 45rpx;height: 40rpx;font-size: 28rpx;text-align: center;line-height: 40rpx;border-radius: 5px;">
						{{item.buyCountNew}}
					</view>
					<img class="img-radius" :src="item.productPicture" alt="" v-if="item.productPicture">
					<view class="noPic" v-else>暂无图片</view>
				</view>
				<view class="box-right">
					<view class="box-right-name">
						{{item.productSn}}
						<text v-if="item.productName">({{item.productName == null ?'':item.productName}})</text>
					</view>
					<view class="box-right-num">供应商:{{item.supplierName== null?'':item.supplierName}}</view>
					<view class="box-right-price">
						<!-- <view class="price-box" v-if="storageType== 0">
							<text>{{item.inStorageStatus==0?'待入库':item.purchasePrice == null ?'新商品':item.purchasePrice}}</text>
							<text>采购价</text>
						</view> -->
						<view class="price-box">
							<text>{{item.wholesalePrice}}</text>
							<text>{{shopId == '1960543009070256129' ? '直播价' : '批发价'}}</text>
						</view>
						<view class="price-box">
							<text>{{item.price}}</text>
							<text>{{shopId == '1960543009070256129' ? '日常价' : '零售价'}}</text>
						</view>
						<view class="price-box" v-if="item.customPrice != '' && item.customPrice != null">
							<text>{{item.customPrice}}</text>
							<text>客户价</text>
						</view>
						<view class="price-box" @tap.stop="seeStockCount(item.stockCount,item.minusStockCount)">
							<text>{{item.stockCount}}</text>
							<view>
								库存
								<uni-icons type="help" size="15"></uni-icons>
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
		<view class="bottom-box" style="position: fixed;bottom: 0;">
			<view class="bottom-left" @tap="toggle('carPopup')">
				<view class="bottom-left-box">
					<uni-icons type="cart" size="20" color="#646566"></uni-icons>
					<text class="uni-tab__text">已选择</text>
				</view>
				<text style="background-color:#ff0000;color:#fff;position: absolute;top: 0;right: 10rpx;"
					class="uni-tab__dot">{{carList.length}}</text>
			</view>
			<view class="bottom-right">
				<view class="bottom-btn" @tap="backPrevPage">选好了</view>
			</view>
		</view>
		<!-- 弹出层 -->
			<uni-popup ref="popup" background-color="#fff" @change="change">
				<view class="popup-content">
					<view class="popup-title">
						<view class="popup-title-left">
							<img class="img-radius" :src="goodsDetail.productPicture" alt=""
								v-if="goodsDetail.productPicture">
							<view class="noPic" v-else>暂无图片</view>
						</view>
						<view class="popup-title-right">
							<view class="popup-title-right-box" style="color: #088FEB;">{{goodsDetail.productName == null ?'':goodsDetail.productName}}
							</view>
							<view class="popup-title-right-box">{{goodsDetail.productSn}}</view>
						</view>
					</view>
					<view class="popup-container" style="position: relative;">
						<view @tap="saveCheck"
							style="position: absolute;top: 10rpx;right: 20rpx;color: #088FEB;text-decoration: underline;">
							保存已选
						</view>
						<ul style="border-top:20rpx;">
							<li v-for="(items,index) in goodsDetail.attributeList" :key="index">
								<view class="title-fur">
									<view class="name"  v-if='index == 0'>{{items.name}}</view>
									<view class="name"  v-if="index == 1 && (shopId == '1822829636942434305')">{{items.name}}</view>
								</view>
								<view class="attrs" v-if='index == 0'>
									<uni-data-checkbox v-model="value" :localdata="range"
										@change="change"></uni-data-checkbox>
									<view class="suibian" v-for="(itemTag, index1) in items.value" :key="index1"
										@tap.stop="attrNameChange(index,itemTag.value,index1) "
										:class="itemTag.isChecked ? 'checkedText' : '' " style="position: relative;">
										{{itemTag.value}}
										<view class="kucun" v-if="itemTag.isKucun"></view>
									</view>
								</view>
								<view class="attrs" v-if="index == 1 && (shopId == '1822829636942434305')">
									<uni-data-checkbox v-model="value" :localdata="range"
										@change="change"></uni-data-checkbox>
									<view class="suibian" v-for="(itemTag, index1) in items.value" :key="index1"
										@tap.stop="attrNameChange(index,itemTag.value,index1) "
										:class="itemTag.isChecked ? 'checkedText' : '' " style="position: relative;">
										{{itemTag.value}}
										<view class="kucun" v-if="itemTag.isKucun"></view>
									</view>
								</view>
							</li>
						</ul>
						<view style="padding-bottom: 100rpx;">
							<view class="checkList" v-if="temporaryList != ''">
								<view class="checkList-box" style="width: 69.5%;">
									<text
										style="width: 300rpx;display: inline-block;font-size: 30rpx;font-weight: bold;padding-left: 40rpx;">
										规格
									</text>
									<text
										style="font-size: 30rpx;color: #000;font-weight: bold;width: 110rpx;display: inline-block;text-align: right;">
										库存
									</text>
								</view>
								<view class="zuni-numbox">
									<view @tap="minusNum" class="zuni-numbox__minus zuni-numbox-btns"
										style="background: #f5f5f5;">
										<text class="zuni-numbox--text">-</text>
									</view>
									<input v-model="allChangeNum" @tap="obtainPrice($event,'zongjishu')" disabled
										class="zuni-numbox__value" type="number" />
									<view @tap="plusNum" class="zuni-numbox__plus zuni-numbox-btns"
										style="background: #f5f5f5;">
										<text class="zuni-numbox--text">+</text>
									</view>
								</view>
								<!-- <uni-number-box max='1000000' @minus='minusNum' @plus="plusNum" /> -->
							</view>
							<view class="checkList" v-for="(item,index) in temporaryList" :key="index">
								<view @tap.stop="delCarData(index)" style="margin-right: 20rpx;width: 7%;">
									<uni-icons color="red" type="minus" size="26"></uni-icons>
								</view>
								<view class="checkList-box">
									<text style="width: 69%;display: inline-block;">{{item.name}}</text>
									<text
										style="color:#777;font-size: 24rpx;width: 25%;display: inline-block;text-align: center;">
										{{item.productNum==null?'无库存':item.productNum}}
									</text>
								</view>
								<!-- <uni-number-box min="-10000" max="100000" v-model="item.productCount" @focus="obtainPrice($event,'danjishu',index)" @blur="numChange($event,index)" /> -->
								<view class="zuni-numbox">
									<view @tap="oneMinusNum(index)" class="zuni-numbox__minus zuni-numbox-btns"
										style="background: #f5f5f5;">
										<text class="zuni-numbox--text">-</text>	
									</view>
									<input v-model="item.productCount" @tap="obtainPrice($event,'danjishu',index)"
										disabled class="zuni-numbox__value" type="number" />
									<view @tap="onePlusNum(index)" class="zuni-numbox__plus zuni-numbox-btns"
										style="background: #f5f5f5;">
										<text class="zuni-numbox--text">+</text>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="popup-bottom">
						<view class="popup-bottom-left">
							<text>{{zNum}} 件</text>
							<!-- <text>￥{{zPrice}}</text> -->
						</view>
						<view class="popup-bottom-right">
							<view class="bottom-btn" @tap="temporaryCheck">选好了</view>
						</view>
					</view>
				</view>
				
			</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' :src="item.productPicture" alt="" style="width: 100%;height: 100%;border-radius: 10px;" /></image>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</uni-popup>
		<uni-popup ref="goodsNumDialog" @change="keyWordChange" background-color="#fff">
			<view class="add-popup-content">
				<view class="add-popup-title">
					<text>请输入拿货数量</text>
					<uni-icons @tap='$refs.goodsNumDialog.close()' type="closeempty" color='red' size="16"
						style="height:40rpx;line-height: 40rpx;position: absolute !important;bottom:0;right: 30rpx;"></uni-icons>
				</view>
				<view class="add-popup-container">
					<view>
						<text style="color:red;font-size:22rpx;">*您的此款商品只有一个“{{oneGoodsName}}”，可直接输入拿货数量即可</text>
					</view>
					<input type="idcard" v-model="goodsNum" @tap="show=true"
						style="width: 100%;border: 1px solid #eee;height: 80rpx;padding-left: 20rpx;margin:20rpx 0;font-size: 25rpx;line-height: 80rpx;"
						placeholder="请输入此商品拿货数量" disabled>
					<view class="add-popup-bottom">
						<view class="add-popup-btn" @tap="oneGoodsToCarList">确认</view>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 购物车弹出层 -->
		<uni-popup ref="carPopup" background-color="#fff" @change="change">
			<view class="popup-content">
				<view v-for="(item,index) in carList" :key="index" style="position: relative;">
					<view class="popup-title">
						<view class="popup-title-left">
							<img class="img-radius" :src="item.productPicture" alt="" v-if="item.productPicture">
							<view class="noPic" v-else>暂无图片</view>
						</view>
						<view class="popup-title-right">
							<view class="popup-title-right-box" style="color: #088FEB;">{{item.productName == null?'':item.productName}}</view>
							<view class="popup-title-right-box">{{item.productSn}}</view>
							<view class="popup-title-right-box">
								<text style="margin-right:20rpx;">供应商：{{item.supplierName==null?"":item.supplierName}}</text>
								<view style="position: absolute;top: 30rpx;right: 30rpx;" @tap.stop="delShop(item)">
									<uni-icons color="red" type="trash" size="26"></uni-icons>
								</view>
							</view>
						</view>
					</view>
					<view class="popup-container1" v-for="(item1,index1) in item.saleDetailQueryDTO" :key="index1">
						<view class="checkList" style="padding-bottom:160rpx;">
							<view style="margin-right:5%;" @tap="delShopSpec(item.id,item1.attributeList)">
								<uni-icons color="red" type="minus" size="26"></uni-icons>
							</view>
							<view class="checkList-box">
								{{item1.attributeList | sliceMsg}}
							</view>
							<!-- <uni-number-box min="-10000" max="100000" v-model="item1.productCount"
								@focus="obtainPrice($event,'chejishu',index,index1)" @blur="chenumChange($event,index,index1)" /> -->
							<view class="zuni-numbox">
								<view @tap="mapMinusNum(index,index1)" class="zuni-numbox__minus zuni-numbox-btns"
									style="background: #f5f5f5;">
									<text class="zuni-numbox--text">-</text>
								</view>
								<input v-model="item1.productCount" @tap="obtainPrice($event,'chejishu',index,index1)"
									disabled class="zuni-numbox__value" type="number" /> 
								<view @tap="mapPlusNum(index,index1)" class="zuni-numbox__plus zuni-numbox-btns"
									style="background: #f5f5f5;">
									<text class="zuni-numbox--text">+</text>
								</view>
							</view>
						</view>
					</view>
				</view>

				<view class="popup-bottom">
					<view class="popup-bottom-left">
						<text>{{carType}} 款 {{carNum}} 件</text>
					</view>
					<view class="popup-bottom-right">
						<view class="bottom-btn" @tap="this.$refs.carPopup.close()">关闭</view>
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="customPopup" background-color="#fff" @change="noChangeCustomPopup">
			<view class="popup-content" style="width:600rpx;height: auto;max-height: 1288rpx;margin-bottom: 0;overflow: scroll;">
				<view style="height: 80rpx;font-size: 36rpx;font-weight: bold;line-height: 80rpx;text-align: center;">
					超出最大可退货数量
				</view>
				<view v-for="(item,index) in checkCanBuy" :key="index">
					<view style="height: auto;line-height: 60rpx;border-bottom: 1px solid #eee;">
						<view style="font-weight: bold;">货号:{{item.productSn}}规格:{{item.attributeList}}</view>
						<view>总售出数:{{item.buyCountAll}} 总退回数:{{item.returnCountAll}} <text style="color:red;padding-left:10rpx;"> 本次退货数:{{item.returnCountAllNew}}</text></view>
					</view>
					
				</view>
				<view @tap="closeCustomPopup"
					style="text-align:center;margin-top:20rpx;width: 100%;height: 60rpx;line-height: 60rpx;background: #088FEB;color: #fff;">
					确认
				</view>
			</view>
		</uni-popup>
		<!-- 显示正负库存弹窗 -->
		<uni-popup ref="showPopup" background-color="#fff">
			<view class="popup-pay-content" style="width: 550rpx;">
				<view class="popup-pay-title">
					<text>库存数</text>
				</view>
				<view style="width: 100%;height: 150rpx;">
					<view
						style="width: 200rpx;height: 130rpx;border: 3px solid #FFE4C4;border-radius: 10px;margin-top: 20rpx;padding-top: 20rpx;display: flex;flex-direction: column;text-align: center;float: left;margin-left: 20rpx;">
						<text style="font-weight: bold;">
							正数库存
						</text>
						<text style="font-size: 30rpx;color: #000;font-weight: bold;">
							{{zheng}}
						</text>
					</view>
					<view
						style="width: 200rpx;height: 130rpx;border: 3px solid #FFE4C4;border-radius: 10px;margin-top: 20rpx;padding-top: 20rpx;display: flex;flex-direction: column;text-align: center;float: left;margin-left: 40rpx;">
						<text style="font-weight: bold;">
							负数库存
						</text>
						<text style="font-size: 30rpx;color: #000;font-weight: bold;">
							{{fu}}
						</text>
					</view>
				</view>
				<view class="popup-pay-container" style="display: flex;margin-top: 50rpx;background: #89CFF0;">
					<view @tap='$refs.showPopup.close()'
						style="flex:1;text-align: center;border-right: 1px solid #eee;background: #088FEB;font-size:32rpx;">
						确认
					</view>
				</view>
			</view>
		</uni-popup>
		<u-keyboard ref="uKeyboard" :overlay='false' @confirm='keyboardConfirm' @cancel="keyCancel" @change="valChange"
			:defaultText="keyboardNum" @close="keyCancel" @backspace="backspace" mode="card" :show="show"></u-keyboard>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				indexList: [],
				focus: false,
				pageNum: 1, //分页的页码
				shopList: [],
				shopList1: [],
				show: false,
				categoryId: '', //分类id
				searchName: '', //搜索框输入值
				checkbox: [], //需要分享的商品id
				temporaryNum: 0,
				allChangeNum: 0,
				defaultText: 0,
				checkCanBuy:[],
				oneGoodsSpec: [],
				goodsDetail: [],
				attrNameList: [],
				keyboard: '',
				oneGoodsName: '',
				temporaryList: [],
				isPlusAndMinus: false,
				carList: [],
				zheng:'',
				fu:'',
				shopId:uni.getStorageSync('shopId'),
				attributeList: [],
				purchasePrice: 0,
				keyboardIndex: '',
				zPrice: 0,
				zNum: 0,
				goodsNum: '',
				storageType: '',
				keyboardNum: "",
				carNum: 0,
				carType: 0,
				type: '',
				productId: '',
				productNum: null,
				height: 0,
				pecsList: [],
				// status: 'loadmore',
				pageOldTemList: [],
				oldTemList: [],
				bigImg:[],
				swiperDotIndex:0,
				goodsList: [],
				khId:'',
				customerId:'',
				customerName:'',
				evalue: [],
				newTemList: [],
				dataObj: new Map(),
				gateType: '',
				yanseList: new Map(),
				chimaList: new Map()
			}
		},
		filters: {
			sliceMsg(val) {
				var name = ''
				if (typeof(val) == 'string') {
					let newObj = JSON.parse(val)
					for (let as in newObj) {
						name += newObj[as] + ' | '
					}
				}
				return name;
			}
		},
		onReachBottom() {
			if (this.pageNum >= this.pages) return;
			// this.status = 'loading';
			this.pageNum++;
			if(this.gateType == 'search'){
				this.getShareList('search');
			}else{
				this.getShareList();
			}
			
		},
		onLoad(option) {
			let that = this
			
			this.khId = option.khId
			this.customerId = option.customerId
			this.customerName = option.customerName
			this.height = wx.getSystemInfoSync().windowHeight
			this.carList = JSON.parse(option.arr)
			for(let i=0;i<that.carList.length;i++){
				if(that.carList[i].returnList != '' && that.carList[i].returnList != undefined){
					that.carList[i].returnList = new Map(JSON.parse(decodeURIComponent(that.carList[i].returnList)))
					that.carList[i].returnList.forEach(function(value1, key1) {
						for(let j = 0;j<that.carList[i].saleDetailQueryDTO.length;j++){
							if(key1 == that.carList[i].saleDetailQueryDTO[j].attributeList && value1.productCount == that.carList[i].saleDetailQueryDTO[j].productCount){
								
								that.carList[i].returnList.delete(key1)
							}
						}
					})
				}
			}
			this.getGategoryList()
			this.storageType = uni.getStorageSync('type')
			uni.setStorageSync('clearMsg', '1')
			
			this.$forceUpdate()
		},
		methods: {
			lunbochange(e) {
				this.current = e.detail.current
			},
			seeCustomCategory(){
				this.$refs.customPopup.open()
			},
			noChangeCustomPopup(e){
				if(e.show == false){
					this.checkCanBuy = []
				}
			},
			closeCustomPopup(){
				this.checkCanBuy = []
				this.$refs.customPopup.close()
			},
			//初始化获取分类列表
			getGategoryList() {
				this.tui.request("/app/productCategory/list", "get", {}, false, true).then((res) => {
					if (res.code == 200) {
						this.indexList = res.result;
						for (var i = 0; i < this.indexList.length; i++) {
							if (i == 0) {
								this.indexList[i].parentId = true
							} else {
								this.indexList[i].parentId = false
							}
						}
						this.categoryId = this.indexList[0].id
						this.getShareList();
					} else {
						this.tui.toast(res.message)
					}
				}).catch((res) => {})
			},
			// 按键被点击(点击退格键不会触发此事件)
			valChange(val) {
				// 将每次按键的值拼接到value变量中，注意+=写法
				this.keyboardNum += val.toString()
				if (this.keyboard == 'goodsNum') {
					this.goodsNum = this.keyboardNum
				}
			},
			// 退格键被点击
			backspace(val) {
				this.keyboardNum = val
				this.goodsNum = val
			},
			//保存已选
			saveCheck() {
				this.pageOldTemList = this.temporaryList
				for (var i = 0; i < this.goodsDetail.attributeList.length; i++) {
					this.goodsList[i].specs = []
					for (var m = 0; m < this.goodsDetail.attributeList[i].value.length; m++) {
						this.goodsDetail.attributeList[i].value[m].isChecked = false
					}
				}
			},
			chenumChange(e, index, index1) {
				let oldProductCount = this.carList[index].saleDetailQueryDTO[index1].productCount
				this.carList[index].saleDetailQueryDTO[index1].productCount = e
				if(this.carList[index].saleDetailQueryDTO[index1].productCount < 0 && this.customerName!='散客'){
					this.checkCanReturn(this.carList[index].productSn,this.carList[index].id,this.carList[index].saleDetailQueryDTO[index1].attributeList,this.customerId,this.carList[index].saleDetailQueryDTO[index1].productCount)
				}
				setTimeout(res => {
					if(this.checkCanBuy.length > 0){
						this.seeCustomCategory()
					}
				}, 500)
				if(this.shopList.length > 0){
					for(let i = 0;i<this.shopList.length;i++){
						if(this.shopList[i].id == this.carList[index].id){
							this.shopList[i].buyCountNew += e - oldProductCount
						}
					}
				}
				if(this.shopList1.length > 0){
					for(let i = 0;i<this.shopList1.length;i++){
						if(this.shopList1[i].id == this.carList[index].id){
							this.shopList1[i].buyCountNew += e - oldProductCount
						}
					}
				}
				this.$forceUpdate()
				this.carChange()
			},
			numChange(e, index) {
				if(e > this.temporaryList[index].productNum && (this.shopId == '1838094297858183168' || this.shopId == '1811579958284390400' || this.shopId == '1818888277105709056')){
					this.tui.toast("已超出可售数量",300)
				}else{
					this.temporaryList[index].productCount = e
					if(this.temporaryList[index].productCount < 0 && this.customerName!='散客'){
						this.checkCanReturn(this.goodsDetail.productSn,this.goodsDetail.id,this.temporaryList[index].attributeList,this.customerId,this.temporaryList[index].productCount)
					}
					setTimeout(res => {
						if(this.checkCanBuy.length > 0){
							this.seeCustomCategory()
						}
					}, 500)
					this.$forceUpdate()
					this.temporaryChange()
				}
			},
			allChange(e) {
				this.allChangeNum = e
				//监听到输入框改变，给所有的都赋值
				if (this.isPlusAndMinus == false) {
					for (var i = 0; i < this.temporaryList.length; i++) {
						if (this.evalue.length == 0) {
							if(Number(this.allChangeNum) > this.temporaryList[i].productNum && (this.shopId == '1838094297858183168' || this.shopId == '1811579958284390400' || this.shopId == '1818888277105709056')){
								this.tui.toast(this.temporaryList[i].name + "已超出可售数量",300)
							}else{
								this.temporaryList[i].productCount = Number(this.allChangeNum)
								if(this.temporaryList[i].productCount < 0 && this.customerName!='散客'){
									this.checkCanReturn(this.goodsDetail.productSn,this.goodsDetail.id,this.temporaryList[i].attributeList,this.customerId,this.temporaryList[i].productCount)
								}
							}
							
						} else {
							for (var j = 0; j < this.evalue.length; j++) {
								if (this.evalue[j] == this.temporaryList[i].name) {
									if(Number(this.allChangeNum) > this.temporaryList[i].productNum && (this.shopId == '1838094297858183168' || this.shopId == '1811579958284390400' || this.shopId == '1818888277105709056')){
										this.tui.toast(this.temporaryList[i].name + "已超出可售数量",300)
									}else{
										this.temporaryList[i].productCount = Number(this.allChangeNum)
										if(this.temporaryList[i].productCount < 0 && this.customerName!='散客'){
											this.checkCanReturn(this.goodsDetail.productSn,this.goodsDetail.id,this.temporaryList[i].attributeList,this.customerId,this.temporaryList[i].productCount)
										}
									}
								}
							}
						}


						for (var m = 0; m < this.pageOldTemList.length; m++) {
							if (this.temporaryList[i].attributeList == this.pageOldTemList[m].attributeList) {
								this.pageOldTemList[m].productCount = this.temporaryList[i].productCount
							}
						}
						for (var j = 0; j < this.oldTemList.length; j++) {
							if (this.temporaryList[i].attributeList == this.oldTemList[j].attributeList) {
								this.oldTemList[j].productCount = this.temporaryList[i].productCount
							}
						}
					}
				}
				setTimeout(res => {
					if(this.checkCanBuy.length > 0){
						this.seeCustomCategory()
					}
				}, 500)
				this.isPlusAndMinus == false
				this.temporaryChange()
			},
			plusNum() {
				this.isPlusAndMinus == true
				//监听到点击+的操作，给所有的都+1
				for (var i = 0; i < this.temporaryList.length; i++) {
					if (this.evalue.length == 0) {
						if (this.temporaryList[i].productCount == undefined) {
							this.temporaryList[i].productCount = 1
						} else {
							if(this.temporaryList[i].productCount + 1 > this.temporaryList[i].productNum && (this.shopId == '1838094297858183168' || this.shopId == '1811579958284390400' || this.shopId == '1818888277105709056')){
								this.tui.toast(this.temporaryList[i].name + "已超出可售数量",300)
							}else{
								this.temporaryList[i].productCount++
							}
						}
					} else {
						for (var j = 0; j < this.evalue.length; j++) {
							if (this.evalue[j] == this.temporaryList[i].name) {
								if (this.temporaryList[i].productCount == undefined) {
									this.temporaryList[i].productCount = 1
								} else {
									if(this.temporaryList[i].productCount + 1 > this.temporaryList[i].productNum && (this.shopId == '1838094297858183168' || this.shopId == '1811579958284390400' || this.shopId == '1818888277105709056')){
										this.tui.toast(this.temporaryList[i].name + "已超出可售数量",300)
									}else{
										this.temporaryList[i].productCount++
									}
								}
							}
						}
					}

					for (var m = 0; m < this.pageOldTemList.length; m++) {
						if (this.temporaryList[i].attributeList == this.pageOldTemList[m].attributeList) {
							this.pageOldTemList[m].productCount = this.temporaryList[i].productCount
						}
					}
					for (var j = 0; j < this.oldTemList.length; j++) {
						if (this.temporaryList[i].attributeList == this.oldTemList[j].attributeList) {
							this.oldTemList[j].productCount = this.temporaryList[i].productCount
						}
					}
				}
				this.temporaryChange()
			},
			minusNum() {
				this.isPlusAndMinus == true
				//监听到点击-的操作，给所有的都-1
				for (var i = 0; i < this.temporaryList.length; i++) {
					if (this.evalue.length == 0) {
						this.temporaryList[i].productCount--
						if(this.temporaryList[i].productCount < 0 && this.customerName!='散客'){
							this.checkCanReturn(this.goodsDetail.productSn,this.goodsDetail.id,this.temporaryList[i].attributeList,this.customerId,this.temporaryList[i].productCount)
						}
					} else {
						for (var j = 0; j < this.evalue.length; j++) {
							if (this.evalue[j] == this.temporaryList[i].name) {
								this.temporaryList[i].productCount--
								if(this.temporaryList[i].productCount < 0 && this.customerName!='散客'){
									this.checkCanReturn(this.goodsDetail.productSn,this.goodsDetail.id,this.temporaryList[i].attributeList,this.customerId,this.temporaryList[i].productCount)
								}
							}
						}
					}

					for (var m = 0; m < this.pageOldTemList.length; m++) {
						if (this.temporaryList[i].attributeList == this.pageOldTemList[m].attributeList) {
							this.pageOldTemList[m].productCount = this.temporaryList[i].productCount
						}
					}
					for (var j = 0; j < this.oldTemList.length; j++) {
						if (this.temporaryList[i].attributeList == this.oldTemList[j].attributeList) {
							this.oldTemList[j].productCount = this.temporaryList[i].productCount
						}
					}
				}
				setTimeout(res => {
					if(this.checkCanBuy.length > 0){
						this.seeCustomCategory()
					}
				}, 500)
				this.temporaryChange()
			},
			mapMinusNum(index, index1) {
				this.carList[index].saleDetailQueryDTO[index1].productCount--
				if(this.carList[index].saleDetailQueryDTO[index1].productCount < 0 && this.customerName!='散客'){
					this.checkCanReturn(this.carList[index].productSn,this.carList[index].id,this.carList[index].saleDetailQueryDTO[index1].attributeList,this.customerId,this.carList[index].saleDetailQueryDTO[index1].productCount)
				}
				setTimeout(res => {
					if(this.checkCanBuy.length > 0){
						this.seeCustomCategory()
					}
				}, 500)
				if(this.shopList.length > 0){
					for(let i = 0;i<this.shopList.length;i++){
						if(this.shopList[i].id == this.carList[index].id){
							this.shopList[i].buyCountNew--
						}
					}
				}
				if(this.shopList1.length > 0){
					for(let i = 0;i<this.shopList1.length;i++){
						if(this.shopList1[i].id == this.carList[index].id){
							this.shopList1[i].buyCountNew--
						}
					}
				}
				this.carChange()
				this.$forceUpdate()
			},
			mapPlusNum(index, index1) {
				this.carList[index].saleDetailQueryDTO[index1].productCount++
				if(this.shopList.length > 0){
					for(let i = 0;i<this.shopList.length;i++){
						if(this.shopList[i].id == this.carList[index].id){
							this.shopList[i].buyCountNew++
						}
					}
				}
				if(this.shopList1.length > 0){
					for(let i = 0;i<this.shopList1.length;i++){
						if(this.shopList1[i].id == this.carList[index].id){
							this.shopList1[i].buyCountNew++
						}
					}
				}
				this.carChange()
				this.$forceUpdate()
			},
			oneMinusNum(index) {
				this.temporaryList[index].productCount--
				if(this.temporaryList[index].productCount < 0 && this.customerName!='散客'){
					this.checkCanReturn(this.goodsDetail.productSn,this.goodsDetail.id,this.temporaryList[index].attributeList,this.customerId,this.temporaryList[index].productCount)
				}
				setTimeout(res => {
					if(this.checkCanBuy.length > 0){
						this.seeCustomCategory()
					}
				}, 500)
				this.temporaryChange()
			},
			onePlusNum(index) {
				if(this.temporaryList[index].productCount + 1 > this.temporaryList[index].productNum && (this.shopId == '1838094297858183168' || this.shopId == '1811579958284390400' || this.shopId == '1818888277105709056')){
					this.tui.toast("已超出可售数量",300)
				}else{
					this.temporaryList[index].productCount++
					this.temporaryChange()
				}
			},
			obtainPrice(e, type, index, index1) {
				this.show = true
				if (type == 'zongjishu') {
					this.keyboard = 'zongjishu'
				} else if (type == 'danjishu') {
					// numChange
					this.keyboard = 'danjishu'
					this.keyboardIndex = index
					// this.temporaryList[index].productCount = ''
				} else if (type == 'chejishu') {
					// chenumChange
					this.keyboard = 'chejishu'
					this.keyboardIndex = [index, index1]
					// this.carList[index].saleDetailQueryDTO[index1].productCount = ''
					// this.$forceUpdate()
				}
			},
			attrNameChange(index, data1, index1) {
				uni.showLoading({
					title: '加载中...'
				})
				this.goodsDetail.attributeList[index].isChecked = !this.goodsDetail.attributeList[index].isChecked;
				this.goodsDetail.attributeList[index].value[index1].isChecked = !this.goodsDetail.attributeList[index]
					.value[index1].isChecked;
				this.evalue = []
				var value = []
				for (let i = 0, data = this.goodsDetail.attributeList[0].value; i < data.length; i++) {
					if (data[i].isChecked) {
						for (let j = 0, dataJ = this.goodsDetail.attributeList[1].value; j < dataJ.length; j++) {
							if(this.shopId != '1822829636942434305'){
								var name = ''
								let value1 = "{"
								
								name = data[i].value + ' | ' + dataJ[j].value
								value1 += '"' + '颜色' + '":"' + data[i].value + '",'
								value1 += '"' + '尺码' + '":"' + dataJ[j].value + '"'
								value1 += "}"
								value.push(value1)
								this.evalue.push(name)
							}else{
								if(dataJ[j].isChecked){
									var name = ''
									let value1 = "{"
									
									name = data[i].value + ' | ' + dataJ[j].value
									value1 += '"' + '颜色' + '":"' + data[i].value + '",'
									value1 += '"' + '尺码' + '":"' + dataJ[j].value + '"'
									value1 += "}"
									value.push(value1)
									this.evalue.push(name)
								}
							}
						}
					}
				}
				if (value.length == 0) {
					this.temporaryList = this.pageOldTemList
				}
				if (this.temporaryList.length == 0) {
					for (var i = 0; i < value.length; i++) {
						this.attributeList = {
							attributeList: value[i],
							productCount: this.temporaryNum,
							productNum: null,
							name: this.evalue[i],
							price: this.purchasePrice
						}
						this.temporaryList.push(this.attributeList);
					}
				} else {
					let newProductCount = 0;
					for (var i = 0; i < value.length; i++) {
						for (var m = 0; m < this.temporaryList.length; m++) {
							if (this.temporaryList[m].attributeList == value[i]) {
								newProductCount = this.temporaryList[m].productCount
							}
						}
						this.attributeList = {
							attributeList: value[i],
							productCount: newProductCount,
							productNum: null,
							name: this.evalue[i],
							price: this.purchasePrice
						}

						this.newTemList.push(this.attributeList);
						newProductCount = 0;
					}
					for (var i = 0; i < this.oldTemList.length; i++) {
						let oldAttributeList = '';
						let oldProductCount = '';
						let notChcek = true;
						for (var m = 0; m < this.newTemList.length; m++) {
							if (this.oldTemList[i].attributeList == this.newTemList[m].attributeList) {
								this.newTemList[m].productCount = this.oldTemList[i].productCount
								notChcek = false;
							}
						}
						if (this.newTemList.length > 0 && notChcek) {
							this.newTemList.push(this.oldTemList[i]);
						}
					}

					for (var i = 0; i < this.pageOldTemList.length; i++) {
						let oldAttributeList = '';
						let oldProductCount = '';
						let notChcek = true;
						for (var m = 0; m < this.newTemList.length; m++) {
							if (this.pageOldTemList[i].attributeList == this.newTemList[m].attributeList) {
								this.newTemList[m].productCount = this.pageOldTemList[i].productCount
								notChcek = false;
							}
						}
						if (this.newTemList.length > 0 && notChcek) {
							this.newTemList.push(this.pageOldTemList[i]);
						}
					}
				}
				this.$nextTick(() => {
					for (var i = 0; i < this.temporaryList.length; i++) {
						for (var m = 0; m < this.pecsList.length; m++) {
							if (this.temporaryList[i].attributeList == this.pecsList[m].attributeList) {
								this.temporaryList[i].productNum = this.pecsList[m].stockCount
							}
							this.$forceUpdate()
						}
					}
				})

				if (this.newTemList.length != 0) {
					this.temporaryList = this.newTemList;
					this.oldTemList = []
					this.newTemList = []
				}
				setTimeout(res => {
					uni.hideLoading();
				}, 200)
			},
			temporaryChange(val) {
				this.zNum = 0
				for (var i = 0; i < this.temporaryList.length; i++) {
					this.zNum += Number(this.temporaryList[i].productCount)
				}
				this.zPrice = this.zNum * this.purchasePrice
			},
			//点击底部选好了，返回上一页
			backPrevPage() {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				uni.setStorageSync('KuCunBack',true)
				for(let i=0;i<this.carList.length;i++){
					if(this.carList[i].returnList != '' && this.carList[i].returnList != undefined){
						this.carList[i].returnList = encodeURIComponent(JSON.stringify(Array.from(this.carList[i].returnList.entries())))
					}
				}
				prevPage.$vm.carList1 = this.carList
				uni.navigateBack({
					delta: 1
				})
			},
			//顶部搜索框
			search(e) {
				this.pageNum = 1
				this.shopList1 = []
				this.shopList = []
				if (e == '') {
					this.searchName = ""
					this.getShareList()
				} else {
					this.searchName = e
					this.getShareList('search')

				}
			},
			//清空搜索条件
			clearSearch() {
				this.searchName = ''
				this.getShareList()
			},
			seeStockCount(zheng,fu){
				this.zheng = zheng;
				this.fu = fu;
				this.$refs.showPopup.open()
			},
			//点击分类获取商品列表
			getShareList(type) {
				let data = {}
				if (type == 'search') {
					this.gateType = 'search'
					data = {
						categoryId: "",
						customerId:this.customerId,
						searchStr: this.searchName,
						pageNum: this.pageNum,
						pageSize: '10'
					}
				} else {
					this.gateType = ''
					data = {
						categoryId: this.categoryId,
						customerId:this.customerId,
						searchStr: this.searchName,
						pageNum: this.pageNum,
						pageSize: '10'
					}
				}
				let that = this
				this.tui.request("/app/product/getShareList", "POST", data, false, false).then((res) => {
					if (res.code == 200) {
						if (type == 'search') {
							this.shopList = []
							this.status = 'nomore';
							if (this.pages == 1) {
								this.shopList1 = res.result.records
							} else {
								this.shopList1 = [...this.shopList1, ...res.result.records]
							}
							if(this.khId != null && this.khId != ''){
								for(let i=0;i<this.shopList1.length;i++){
									this.shopList1[i].customPrice = ''
									if(this.shopList1[i].customerCategoryRule != null && this.shopList1[i].customerCategoryRule != ''){
										let customerCategoryRule = JSON.parse(this.shopList1[i].customerCategoryRule)
										for(let j=0;j<customerCategoryRule.length;j++){
											if(customerCategoryRule[j].categoryId == this.khId){
												this.shopList1[i].customPrice = customerCategoryRule[j].categoryPrice
											}
										}
									}
									if(that.carList.length > 0){
										for(let j=0;j<that.carList.length;j++){
											if(that.carList[j].id == that.shopList1[i].id){
												that.shopList1[i].buyCountNew = that.carList[j].num
												that.shopList1[i].returnList = that.carList[j].returnList
											}
										}
									}
								}
							}
							
							this.pages = res.result.pages
						} else {
							this.shopList1 = []
							this.status = 'nomore';
							if (this.pages == 1) {
								this.shopList = res.result.records
							} else {
								this.shopList = [...this.shopList, ...res.result.records]
							}
							if(this.khId != null && this.khId != ''){
								for(let i=0;i<this.shopList.length;i++){
									this.shopList[i].customPrice = ''
									if(this.shopList[i].customerCategoryRule != null && this.shopList[i].customerCategoryRule != ''){
										let customerCategoryRule = JSON.parse(this.shopList[i].customerCategoryRule)
										for(let j=0;j<customerCategoryRule.length;j++){
											if(customerCategoryRule[j].categoryId == this.khId){
												this.shopList[i].customPrice = customerCategoryRule[j].categoryPrice
											}
										}
									}
									if(that.carList.length > 0){
										for(let j=0;j<that.carList.length;j++){
											if(that.carList[j].id == that.shopList[i].id){
												that.shopList[i].buyCountNew = that.carList[j].num
												that.shopList[i].returnList = that.carList[j].returnList
											}
										}
									}
								}
							}
							this.pages = res.result.pages
						}
					} else {
						this.tui.toast(res.message)
					}
				}).catch((res) => {})
			},
			change() {
				this.oldTemList = []
			},
			keyboardConfirm() {
				if (this.keyboardNum != '') {
					if (this.keyboard == 'goodsNum') {
						this.goodsNum = Number(this.keyboardNum)
					} else if (this.keyboard == 'zongjishu') {
						this.allChange(Number(this.keyboardNum))
					} else if (this.keyboard == 'danjishu') {
						this.numChange(Number(this.keyboardNum), this.keyboardIndex)
					} else if (this.keyboard == 'chejishu') {
						this.chenumChange(Number(this.keyboardNum), this.keyboardIndex[0], this.keyboardIndex[1])
					}
				}


				this.show = false
				this.keyboardNum = ''
			},
			keyCancel() {
				this.show = false
				this.keyboardNum = ''
			},
			carChange(e, index, index1) {
				this.carNum = 0
				for (let i = 0; i < this.carList.length; i++) {
					this.carList[i].num = 0
					for (let m = 0; m < this.carList[i].saleDetailQueryDTO.length; m++) {
						this.carList[i].num += Number(this.carList[i].saleDetailQueryDTO[m].productCount)
					}
					this.carNum += this.carList[i].num
				}
			},
			//弹出购物车或者商品规格选择弹窗
			toggle(type, item) {
				if (type == 'carPopup') {
					this.oldList = this.carList
					this.carNum = 0
					for (let i = 0; i < this.carList.length; i++) {
						this.carNum += this.carList[i].num
					}
					this.$refs.carPopup.open('bottom')
					this.carType = this.carList.length
				} else {
					uni.showLoading({
						title: '加载中...'
					})
					this.productId = item.id
					this.goodsList = []
					this.allChangeNum = 0
					this.checkGoods(item);
				}

			},
			//选择商品查询商品规格
			async checkGoods(item) {
				uni.showLoading({
					title: '加载中...'
				})
				let that = this;
				that.goodsDetail = item;
				this.temporaryList = []
				this.pageOldTemList = []
				if (this.carList != '') {
					this.zNum = 0
					for (let i = 0; i < this.carList.length; i++) {
						if (item.id == that.carList[i].id) {
							if(that.carList[i].saleDetailQueryDTO.length > 0){
								that.goodsNum = that.carList[i].saleDetailQueryDTO[0].productCount
							}else{
								that.goodsNum = 0
							}
							that.zNum = that.carList[i].num
							that.temporaryList = that.carList[i].saleDetailQueryDTO
							that.pageOldTemList = that.carList[i].saleDetailQueryDTO
							that.oldTemList = that.carList[i].saleDetailQueryDTO
						}
					}

				}
				await this.tui.request("/app/productAttribute/selectAttributeAndValueByCategoryId", "POST", {
					categoryId: this.goodsDetail.attrId
				}, false, true).then((res1) => {
					if (res1.code == 200) {
						if (typeof(res1.result.attributeAndValue) == 'string') {
							let newObj = JSON.parse(res1.result.attributeAndValue)
							let newArr = []
							let dataArr = []
							for (let val in newObj) {
								let valueObj = [];
								let isTrue = false
								for (var i = 0; i < newObj[val].length; i++) {
									for (var m = 0; m < this.oldTemList.length; m++) {
										var data = this.oldTemList[m].name.split('/')
										for (var j = 0; j < data.length; j++) {
											if (data[j] == newObj[val][i]) {
												isTrue = true
											}
										}
									}
									for (var m = 0; m < this.pageOldTemList.length; m++) {
										var data = this.pageOldTemList[m].name.split('/')
										for (var j = 0; j < data.length; j++) {
											if (data[j] == newObj[val][i]) {
												isTrue = true
											}
										}
									}
									valueObj.push({
										value: newObj[val][i],
										isChecked: false
									})
									that.dataObj.set(newObj[val][i], val)
									isTrue = false
								}
								newArr.push({
									name: val,
									value: valueObj
								})
							}
							this.focus = false
							if (newArr[0].value.length == 1 && newArr[1].value.length == 1) {
								// uni.hideKeyboard()
								this.keyboard = 'goodsNum'
								this.keyboardNum = this.goodsNum
								this.show = true
								this.oneGoodsName = newArr[0].value[0].value + ' | ' + newArr[1].value[0].value
								this.oneGoodsSpec = newArr
								// this.oneGoodsToCarList(newArr)
								this.$refs.goodsNumDialog.open('center')
								this.$nextTick(() => {
									this.focus = true
								})
								this.getKCList(res1.result.stock);
							} else {
								// newArr[0].value[0].isChecked = true
								this.$refs.popup.open('bottom')
								this.goodsDetail.attributeList = newArr;
								for (var i = 0; i < this.goodsDetail.attributeList.length; i++) {
									let oldCheck = false
									let oldValue = []
									for (var m = 0; m < this.goodsDetail.attributeList[i].value.length; m++) {
										if (this.goodsDetail.attributeList[i].value[m].isChecked == true) {
											oldCheck = true
											oldValue.push(this.goodsDetail.attributeList[i].value[m].value)
										}
									}
									if (oldCheck) {
										let specs1 = {
											specs: []
										}

										specs1.specs = oldValue
										this.goodsList.push(specs1)
									} else {
										let specs1 = {
											specs: []
										}
										this.goodsList.push(specs1)
									}
									oldCheck = false
									oldValue = []
								}
								this.getKCList(res1.result.stock);
							}
							if (this.temporaryList == '' && that.shopId != '1822829636942434305') {
								this.attrNameChange(0, this.goodsDetail.attributeList[0].value[0].value, 0)
							}
						}

					} else {
						this.tui.toast(res.message)
					}
				}).catch((res) => {})
				await uni.hideLoading()
			},
			handleNumber(num) {
				num = num.toString()
				// 1. 过滤非法字符（只保留数字、负号、小数点）
				let str = num.replace(/[^0-9.-]/g, '');
				if (str === '') return '0';
			
				let sign = '';
				// 2. 处理负号：只保留开头的负号
				if (str.startsWith('-')) {
					sign = '-';
					str = str.substring(1).replace(/-/g, ''); // 移除其他负号
				} else {
					str = str.replace(/-/g, ''); // 移除所有负号
				}
			
				// 3. 处理小数点：只保留第一个
				let parts = str.split('.');
				if (parts.length > 1) {
					str = parts[0] + '.' + parts.slice(1).join('');
				}
			
				let integerPart = '';
				let decimalPart = '';
				// 4. 分割整数和小数部分
				if (str.includes('.')) {
					[integerPart, decimalPart] = str.split('.');
				} else {
					integerPart = str;
				}
			
				// 5. 处理整数部分：删除前导零
				integerPart = integerPart.replace(/^0+/, '');
				if (integerPart === '') integerPart = '0'; // 如 "." → "0"
			
				// 6. 组合数字
				let numberStr = decimalPart === '' ? integerPart : `${integerPart}.${decimalPart}`;
			
				// 7. 处理负零：数值为0时移除负号
				if (integerPart === '0' && (decimalPart === '' || /^0*$/.test(decimalPart))) {
					numberStr = '0';
					sign = '';
				}
			
				return sign + numberStr;
			},
			async oneGoodsToCarList() {
				let that = this;
				// this.oneGoodsSpec //规格
				// this.goodsNum  //数量
				this.goodsNum = this.handleNumber(this.goodsNum)
				if(this.shopId == '1838094297858183168' || this.shopId == '1811579958284390400' || this.shopId == '1818888277105709056'){
					if(this.goodsNum > this.goodsDetail.stockCount){
						this.tui.toast("已超出可售数量",1000)
						return
					}
				}
				
				if(that.shopList.length > 0){
					for(let j = 0; j < this.shopList.length; j++){
						if(this.goodsDetail.id == this.shopList[j].id){
							this.shopList[j].buyCountNew = this.goodsNum == '' ? 0 : this.goodsNum
						}
					}
				}
				if(this.shopList1.length > 0){
					for(let n = 0; n < this.shopList1.length; n++){
						if(this.goodsDetail.id == this.shopList1[n].id){
							this.shopList1[n].buyCountNew = this.goodsNum == '' ? 0 : this.goodsNum
						}
					}
				}
				this.show = false
				this.evalue = []
				var value = []
				var name = ''
				let value1 = "{"
				name = this.oneGoodsSpec[0].value[0].value + ' | ' + this.oneGoodsSpec[1].value[0].value
				value1 += '"' + this.oneGoodsSpec[0].name + '":"' + this.oneGoodsSpec[0].value[0].value + '",'
				value1 += '"' + this.oneGoodsSpec[1].name + '":"' + this.oneGoodsSpec[1].value[0].value + '"'
				value1 += "}"
				value.push(value1)
				this.evalue.push(name)
				await this.$nextTick(() => {
					for (var i = 0; i < value.length; i++) {
						if(Number(this.goodsNum) < 0 && this.customerName != '散客'){
							let attrList = value[i]
							this.$nextTick(() => {
								this.checkCanReturn(this.goodsDetail.productSn,this.goodsDetail.id,attrList,this.customerId,this.goodsNum)
							})
						}
						
						this.attributeList = {
							attributeList: value[i],
							productCount: Number(this.goodsNum),
							productNum: 0,
							name: this.evalue[i],
							price: this.goodsDetail.purchasePrice
						}
						this.temporaryList = []
						this.temporaryList.push(this.attributeList);
					}
					setTimeout(res => {
						if(this.checkCanBuy.length > 0){
							this.seeCustomCategory()
						}
					}, 500)
				})

				await this.$nextTick(() => {
					for (var i = 0; i < this.temporaryList.length; i++) {
						for (var m = 0; m < this.pecsList.length; m++) {
							if (this.temporaryList[i].attributeList == this.pecsList[m].attributeList) {
								this.temporaryList[i].productNum = this.pecsList[m].stockCount
							}
							this.$forceUpdate()
						}
					}

				})
				await this.$nextTick(() => {
					let data = {
						attrId:this.goodsDetail.attrId,
						id: this.goodsDetail.id,
						price: this.zPrice,
						num: this.goodsNum == '' ? 0 : this.goodsNum,
						buyCount:this.goodsDetail.buyCount,
						customerCategoryRule:this.goodsDetail.customerCategoryRule != null ?JSON.parse(this.goodsDetail.customerCategoryRule): null,
						categoryId: this.goodsDetail.categoryId,
						productName: this.goodsDetail.productName,
						productSn: this.goodsDetail.productSn,
						returnPrice: this.goodsDetail.wholesalePrice,
						returnList: this.goodsDetail.returnList,
						productPicture: this.goodsDetail.productPicture,
						supplierName: this.goodsDetail.supplierName,
						saleDetailQueryDTO: this.temporaryList,
						saleDetailQueryDTO1: [],
						purchasePrice: this.goodsDetail.purchasePrice,
						unitPrice: this.goodsDetail.wholesalePrice,
						wholesalePrice: this.goodsDetail.wholesalePrice,
						lsprice: this.goodsDetail.price
					}
					if (this.carList.length == 0) {
						this.carList.push(data)
					} else {
						let aa = true;
						for (let i = 0; i < this.carList.length; i++) {
							if (this.carList[i].id == data.id) {
								this.carList[i] = data
								aa = false
							}
						}
						if (aa) {
							this.carList.push(data)
						}
					}
				})
				await this.$nextTick(() => {
					that.$refs.goodsNumDialog.close()
					that.goodsNum = ''
				})
				this.$forceUpdate()
			},
			checkCanReturn(productSn,productId,attributeList,customerId,goodsNumNew){
				this.tui.request(
					"/app/customer/getCustomerBuyHistory",
					"POST", {
						productId: productId,
						attributeList: attributeList,
						customerId: customerId
					}, false, true).then((res1) => {
					if (res1.code == 200) {
						let buyCount = res1.result.buyCount==null?0:res1.result.buyCount
						let returnCount = res1.result.returnCount==null?0:res1.result.returnCount
						if(Number(buyCount) <= 0 || (Number(buyCount) - Number(returnCount) + Number(goodsNumNew)) < 0){
							let obj = {
								productSn:productSn,
								attributeList:attributeList,
								buyCountAll:buyCount,
								returnCountAll:returnCount,
								returnCountAllNew:goodsNumNew
							}
							this.checkCanBuy.push(obj)
						}
					} 
				}).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()
			},
			//库存商品详情
			getKCList(list) {
				this.yanseList = new Map()
				this.chimaList = new Map()
				this.pecsList = list

				for (let i = 0; i < list.length; i++) {
					let attributeList = JSON.parse(list[i].attributeList)
					Object.keys(attributeList).forEach(key => {
						if (key == '颜色') {
							if (this.yanseList.has(attributeList[key]) != true) {
								this.yanseList.set(attributeList[key], attributeList[key])
							}

						}
					})
				}
				for (let i = 0; i < this.goodsDetail.attributeList[0].value.length; i++) { //颜色
					if (this.yanseList.has(this.goodsDetail.attributeList[0].value[i].value) == true) {
						this.goodsDetail.attributeList[0].value[i].isKucun = true
					}
				}
			},

			//未入库遮罩
			clickMask() {
				uni.showToast({
					title: '请将商品上架或入库后再操作！',
					icon: 'none'
				})
			},
			//点击左侧菜单切换
			clickLeftBtn(index) {
				for (var i = 0; i < this.indexList.length; i++) {
					if (i == index) {
						this.indexList[i].parentId = true
					} else {
						this.indexList[i].parentId = false
					}
				}
				this.categoryId = this.indexList[index].id
				this.pageNum = 1
				this.searchName = ""
				this.shopList1 = []
				this.shopList = []
				this.getShareList()
			},
			//临时改价
			changePrice(val) {
				this.goodsDetail.price = this.temporaryList[0].price = val
			},
			//弹窗选择规格后，点击弹窗中选好了按钮
			temporaryCheck() {
				let newList = []
				for (let i = 0; i < this.temporaryList.length; i++) {
					if (this.temporaryList[i].productCount != 0) {
						newList.push(this.temporaryList[i])
					}
				}
				this.$nextTick(() => {
					let data = {
						attrId:this.goodsDetail.attrId,
						id: this.goodsDetail.id,
						price: this.zPrice,
						num: this.zNum,
						buyCount:this.goodsDetail.buyCount,
						categoryId: this.goodsDetail.categoryId,
						productName: this.goodsDetail.productName,
						productSn: this.goodsDetail.productSn,
						returnList:this.goodsDetail.returnList,
						returnPrice: this.goodsDetail.wholesalePrice,
						customerCategoryRule:this.goodsDetail.customerCategoryRule != null ? JSON.parse(this.goodsDetail.customerCategoryRule):null,
						productPicture: this.goodsDetail.productPicture,
						supplierName: this.goodsDetail.supplierName,
						saleDetailQueryDTO: newList,
						saleDetailQueryDTO1: [],
						unitPrice:this.goodsDetail.wholesalePrice,
						purchasePrice: this.goodsDetail.purchasePrice,
						wholesalePrice: this.goodsDetail.wholesalePrice,
						lsprice: this.goodsDetail.price
					}
					if (this.carList.length == 0) {
						this.carList.push(data)
					} else {
						let aa = true;
						for (let i = 0; i < this.carList.length; i++) {
							if (this.carList[i].id == data.id) {
								this.carList[i] = data
								aa = false
							}
						}
						if (aa) {
							this.carList.push(data)
						}
					}


					for (let i = 0; i < this.carList.length; i++) {
						this.carList[i].num = 0
						for (let m = 0; m < this.carList[i].saleDetailQueryDTO.length; m++) {
							this.carList[i].num += this.carList[i].saleDetailQueryDTO[m].productCount
						}
						if(this.shopList.length > 0){
							for(let j = 0; j < this.shopList.length; j++){
								if(this.carList[i].id == this.shopList[j].id){
									this.shopList[j].buyCountNew = this.carList[i].num
								}
							}
						}
						if(this.shopList1.length > 0){
							for(let n = 0; n < this.shopList1.length; n++){
								if(this.carList[i].id == this.shopList1[n].id){
									this.shopList1[n].buyCountNew = this.carList[i].num
								}
							}
						}
					}

					this.temporaryList = []
					this.oldTemList = []
					this.purchasePrice = ''
					this.zPrice = ''
					this.zNum = ''
					for (let i = 0; i < this.goodsDetail.attributeList.length; i++) {
						this.goodsDetail.attributeList[i].isChecked = false;
						for (let m = 0; m < this.goodsDetail.attributeList[i].value.length; m++) {
							this.goodsDetail.attributeList[i].value[m].isChecked = false
						}
					}
					this.$refs.popup.close()
				})

			},
			//删除整条商品
			delShop(item) {
				var that = this;
				uni.showModal({
					title: "提示",
					content: "确定删除此条商品吗？",
					success: function(res) {
						if (res.confirm) {
							for (let i = 0; i < that.carList.length; i++) {
								if (that.carList[i].id == item.id) {
									that.carNum -= that.carList[i].num
									that.carList.splice(i, 1)
								}
							}
							that.carType = that.carList.length
						}
						that.$forceUpdate()
					}
				})
			},
			//选商品的时候能删除规格
			delCarData(index) {
				this.temporaryList.splice(index, 1);
				this.temporaryChange()
			},
			//删除商品下的某一个规格
			delShopSpec(index, index1) {
				var that = this;
				uni.showModal({
					title: "提示",
					content: "确定删除此条商品吗？",
					success: function(res) {
						if (res.confirm) {
							for (let i = 0; i < that.carList.length; i++) {
								for (let m = 0; m < that.carList[i].saleDetailQueryDTO.length; m++) {
									if (that.carList[i].id == index) {
										if (that.carList[i].saleDetailQueryDTO[m].attributeList == index1) {
											that.carList[i].num -= that.carList[i].saleDetailQueryDTO[m]
												.productCount
											that.carNum -= that.carList[i].saleDetailQueryDTO[m].productCount
											that.carList[i].saleDetailQueryDTO.splice(m, 1)
											continue;
										}
									}

								}
								if (that.carList[i].saleDetailQueryDTO.length == 0) {
									that.carList.splice(i, 1)
								}
							}
							that.carType = that.carList.length
						}
						that.$forceUpdate()
					}
				})
			},
			//选择是零售价还是批发价
			checkPay(price) {
				this.purchasePrice = price;
				this.$refs.inputDialog.close()
			},
			keyWordChange(e) {
				if (e.show == false) {
					this.show = false
					this.keyboardNum = ''
					setTimeout(res=>{
						this.goodsNum = ''
					},500)
				}

			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.page1 {
		font-size: 28rpx;
	}

	.uni-tab__dot {
		padding: 0 8rpx;
		line-height: 30rpx;
		color: #ffffff;
		text-align: center;
		font-size: 24rpx;
		background-color: #ff0000;
		border-radius: 30rpx;
	}

	.popup-content {
		align-items: center;
		justify-content: center;
		padding: 30rpx;
		height: 1200rpx;
		background-color: #fff;
		overflow: scroll;
	}

	.popup-pay-content {
		align-items: center;
		justify-content: center;
		padding: 30rpx;
		width: 500rpx;
		height: auto;
		background-color: #fff;
	}

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

	.popup-pay-container {
		margin-top: 20rpx;
		height: 100rpx;
		border-radius: 10px;
		background: #088FEB;
		line-height: 100rpx;
		text-align: center;
		border-bottom: 1px solid #eee;
		border-top: 1px solid #eee;
		color: #fff;
	}

	.popup-title-right-box {
		height: 50rpx;
		line-height: 50rpx;
	}

	.popup-title-right {
		width: 400rpx;
		margin-left: 30rpx;
	}

	.popup-title-left {
		width: 150rpx;
		height: 150rpx;
	}

	.popup-title-left image {
		width: 150rpx;
		height: 150rpx;

	}

	.popup-title {
		display: flex;
		height: 180rpx;
		border-bottom: 1px solid #eee;
		margin-top: 20rpx;
	}

	.popup-container {
		width: 100%;
		background: #fff;
		height: 50rpx;
	}
	.popup-container1 {
		width: 100%;
		background: #fff;
		height: 50rpx;
	}
	.uni-tab__text {
		font-size: 24rpx;
		color: #646566;
	}

	.title-box {
		background: #fff;
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 99;
	}

	.bottom-box {
		width: 100%;
		height: 120rpx;
		display: flex;
		background: #fff;
		z-index: 98;
	}

	.bottom-left {
		width: 15%;
		position: relative;
		padding-top: 20rpx;
	}

	.bottom-right {
		width: 85%;
		padding-top: 20rpx;

		.bottom-btn {
			width: 85%;
			line-height: 70rpx;
			height: 70rpx;
			text-align: center;
			margin-top: 10rpx;
			color: #fff;
			font-size: 28rpx;
			margin: 0 auto;
			background: linear-gradient(90deg, #60F3FF, #088FEB);
			border-radius: 70rpx;
		}
	}

	.bottom-left-box {
		display: flex;
		flex-direction: column;
		text-align: center;
	}

	.content-box {
		background: #fff;
		flex: 1;
		display: flex;
		overflow: hidden;
	}

	.content-left {
		width: 170rpx;
		background: #eee;
		overflow: scroll;
		height: 84%;
		float: left;
		position: fixed;
		top: 8%;
	}

	.left-box {
		width: 100%;
		height: 90rpx;
		font-size: 30rpx;
		text-align: center;
		line-height: 90rpx;
		border-bottom: 1px solid #fff;
	}

	.purchase-price {
		display: flex;
		line-height: 80rpx;
		height: 80rpx;
		width: 95%;
		margin: 20rpx auto;
	}

	.left-box-hover {
		width: 100%;
		height: 90rpx;
		font-size: 30rpx;
		text-align: center;
		line-height: 90rpx;
		border-bottom: 1px solid #fff;
		background-color: #fff;
	}

	.red {
		border-right: 3px solid red;
	}

	.content-right {
		flex: 1;
		overflow-y: scroll;
		height: 100%;
		width: 570rpx;
		background: #fff;
		margin:0 0 150rpx 170rpx;
		padding-top: 16%;
	}

	.right-box {
		width: 100%;
		height: 190rpx;
		display: flex;
		border-bottom: 1px solid #eee;
		position: relative;
	}

	.box-left {
		width: 130rpx;
		height: 131rpx;
		background-size: 100%;
		margin: 25rpx 30rpx 35rpx 10rpx;
		border-radius: 20rpx;
	}

	.box-left img {
		width: 100%;
		height: 100%;

	}

	.box-right {
		margin-top: 17rpx;
	}

	.box-right-name {
		font-size: 30rpx;
		font-weight: bold;
	}

	.box-right-num {
		padding: 5rpx 0;
		color: #777;
	}

	.box-right-price {
		display: flex;
		font-size: 25rpx;
	}

	.checkbox {
		width: 40rpx;
		height: 40rpx;
		position: absolute;
		top: 20rpx;
		right: 30rpx;
	}

	.price-box {
		display: flex;
		flex-direction: column;
		margin-right: 20rpx;
	}

	.price-box text:first-child {
		color: #ffa200
	}

	.uni-tab__cart-button-right,
	.uni-tab__cart-sub-right {
		display: none;
		flex: none;
	}

	.title-fur {
		width: 95%;
		height: 50rpx;
		margin: 0 auto;
	}

	.name {
		font-size: 30rpx;
		width: 50%;
		float: left;
		height: 50rpx;
		line-height: 70rpx;
	}

	.content-fur {
		padding-bottom: 25rpx;
	}

	.content-low {
		width: auto;
		border: 1px solid #eee;
		display: inline-block;
		min-width: 90rpx;
		padding: 5rpx;
		font-size: 35rpx;
		text-align: center;
		color: #777;
		margin: 20rpx 0 0 20rpx;
	}

	.content-low:hover {
		background: #eee;
	}

	.checkList {
		display: flex;
		height: 50rpx;
		font-size: 28rpx;
		line-height: 50rpx;
		margin: 20rpx 0;
	}

	.checkList-box {
		height: 50rpx;
		width: 60%;
	}

	.popup-bottom {
		width: 95%;
		height: 100rpx;
		position: fixed;
		bottom: 0;
		left: 2.5%;
		display: flex;
		z-index: 99;
		background: #fff;
	}

	.popup-bottom-left {
		width: 50%;
		line-height: 80rpx;
	}

	.popup-bottom-right {
		width: 50%;
		line-height: 100rpx;

		.bottom-btn {
			width: 70%;
			line-height: 70rpx;
			height: 70rpx;
			text-align: center;
			/* margin-top: 10rpx; */
			color: #fff;
			font-size: 28rpx;
			margin: 0 auto;
			background: linear-gradient(90deg, #60F3FF, #088FEB);
			border-radius: 70rpx;
		}
	}

	.attrs {
		.suibian {
			display: inline-block;
			border: 1px solid #5fd9ee;
			margin: 20rpx;
			margin-bottom: 0;
			margin-left: 0;
			background-color: #fff;
			color: #5fd9ee;
			padding: 0 20rpx;
			min-width: 100rpx;
			line-height: 70rpx;
			height: 70rpx;
			text-align: center;
			border-radius: 20rpx;
		}

		.checkedText {
			background-color: #5fd9ee;
			color: #fff;
			border-radius: 20rpx;
		}
	}

	.shop-mask {
		width: 100%;
		height: 190rpx;
		position: absolute;
		top: 0;
		left: 0;
		background: rgba(0, 0, 0, 0.1);
	}

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

	.kucun {
		background: url(https://jewel-shop.oss-cn-beijing.aliyuncs.com/9428d632981647728829da336a1d24b3.png) no-repeat;
		width: 50rpx;
		height: 25rpx;
		position: absolute;
		top: -14rpx;
		right: -15rpx;
		background-size: 100%;
	}
	.showImg-box{
		width: 700rpx;
		height: 1100rpx;
		border-radius: 10px;
	}
	.swiper-box {
		height: 1100rpx;
	}
	.swiper-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 1100rpx;
		color: #fff;
		background-color: #cee1fd;
		border-radius: 10px;
	}
	.zuni-numbox {
		height: 60rpx;
		display: flex;
		flex-direction: row;
	}

	.zuni-numbox-btns {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		padding: 0 16rpx;
		cursor: pointer;
	}

	.zuni-numbox__value {
		margin: 0 4rpx;
		width: 80rpx;
		text-align: center;
		font-size: 40rpx;
		line-height: 60rpx;
		height: 60rpx;
		border-left-width: 0;
		border-right-width: 0;
	}


	.zuni-numbox--text {
		line-height: 40rpx;

		font-size: 64rpx;
		font-weight: 300;
	}

	.zuni-numbox .zuni-numbox--disabled {
		color: #c0c0c0 !important;
		cursor: not-allowed;
	}

	.add-popup-content {
		align-items: center;
		justify-content: center;
		margin-bottom: 180rpx;
		padding: 30rpx;
		width: 500rpx;
		height: 410rpx;
		background-color: #fff;
	}

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

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

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

	.add-popup-btn {
		flex: 1;
		text-align: center;
		background: linear-gradient(90deg, #60F3FF, #088FEB);
	}

	.right-box:last-child {
		margin-bottom: 100rpx;
	}
	.tan-1{
		padding-bottom:160rpx;
	}
	@media screen and (min-width: 470px) {

		/* 适配宽度为375px及以上的屏幕 */
		.popup-content {
			height: 900rpx;
		}
	}
	@media screen and (min-width: 760px) {
		/* 适配宽度为760px及以上的屏幕 */
		.popup-content {
			height: 800px !important;
		}
		.vue-ref{
			padding-bottom:0 !important;
		}
		.popup-title {
			height: 150px;
		}
		.popup-container {
			height: 480px !important;
		}
		.u-keyboard__button-wrapper__button{
			height:70px !important;
		}
		.popup-bottom {
			height:100px;
		}
		.content-left {
			height: 76%;
			top: 10%;
		}
		.content-right {
			padding-bottom:100px;
		}
	}
</style>