import { getGoodsDataApi,getProductDataApi,getPxClassDataApi } from "@/api/product/index";
import { getGhsProductList } from "@/api/product/index";
import { mapGetters, mapActions } from "vuex";
import { copyObject } from "@/utils/util";
export default {
	data() {
		return {
			options:'',
			pageType: "bill", //选择商品页面类别  用于区分不同功能的数据

			suitInfo: [], //成品-商品信息
			suitClassIndex: 0, //成品-当前商品类别下标

			productInfo: [], //商品信息
			pxClassInfo: [], //培训班开单列表
			classIndex: 0, //当前商品类别下标
			py: "", //拼音搜索条件
			type: "", //库存预警时，固定为waring，其他情况不传或者传空
			autoLoad: true, //自动获取商品信息
			isLimit: true, //选择数量不能大于库存限制

			//成品开单
			suit_scroll_into_view:"",
			suit_top_list:'',
			suitTimeFun:"",
			suitFilterProductInfo:'',
			//组合开单
			scroll_into_view:"",
			top_list:'',
			timeFun:"",
			filterProductInfo:'',

		};
	},
	onLoad(options) {
		this.options = options;
		const { pageType,shopId,id,name } = options;
		if (pageType) {
			this.pageType = pageType;
		}
		if(name){
			uni.setNavigationBarTitle({
				title: name
			});
		}
		if (this.autoLoad) {
			if(this.isGhsProduct){
				// this.initGhsData(id,shopId);//采购-进店下单
			}else{
				if(!this.$util.isEmpty(this.tabIndex)){
					this.initData();//组合
				}
				// this.initGoodsData();//成品
				// this.initPxClassData();//课程
			}
		}
	},
	onUnload() {},
	computed: {
		...mapGetters(["getSelectInfo"]),
		filterProductInfoxxxx() {
			let list = copyObject(this.productInfo);
			if (this.py) {
				let commonChildList = [];
				list.forEach(ele => {
					//过滤常用
					if(ele.classId != -2){
						if (!this.$util.isEmpty(ele.child)) {
							ele.child.forEach(obj => {
								let hasName = obj.itemName && obj.itemName.indexOf(this.py) >= 0;
								let elePy = (obj.py && obj.py.toLocaleUpperCase()) || "";
								let hasPy = elePy.indexOf(this.py.toLocaleUpperCase()) >= 0;
								if (hasName || hasPy) {
									if(this.$util.isEmpty(commonChildList)){
										commonChildList = [...commonChildList,{classId: ele.classId, className: ele.className,child:[obj]}];
									}else{
										commonChildList.forEach(res => {
											if(res.classId==ele.classId){
												res.child.push(obj)
											}else{
												commonChildList.push({classId: ele.classId, className: ele.className,child:[obj]});
											}
										})
									}
								}
							});
						}

					}
				});
				list = this.$util.unique(commonChildList)
				this.suitClassIndex = 0;
			}
			return list;
		},
		/**
			* 搜索、初始化数据
			* */
		suitFilterProductInfoxxx() {
			let list = copyObject(this.suitInfo);
			if (this.py) {
				let commonChildList = [];
				list.forEach(ele => {
					//过滤常用
					if(ele.classId != -2){
						if (!this.$util.isEmpty(ele.child)) {
							ele.child.forEach(obj => {
								let hasName = obj.goodsName && obj.goodsName.indexOf(this.py) >= 0;
								let elePy = (obj.py && obj.py.toLocaleUpperCase()) || "";
								let hasPy = elePy.indexOf(this.py.toLocaleUpperCase()) >= 0;
								if (hasName || hasPy) {
									if(this.$util.isEmpty(commonChildList)){
										commonChildList = [...commonChildList,{classId: ele.classId, className: ele.className,child:[obj]}];
									}else{
										commonChildList.forEach(res => {
											if(res.classId==ele.classId){
												res.child.push(obj)
											}else{
												commonChildList.push({classId: ele.classId, className: ele.className,child:[obj]});
											}
										})
									}
								}
							});
						}

					}
				});
				list = this.$util.unique(commonChildList)
				this.suitClassIndex = 0;
			}
			return list;
		},
		/**
			* 当前页面选中的商品列表
			*/
		selectList() {
			return this.getSelectInfo[this.pageType] || [];
		},
		scrollClassId() {
			const curClass = this.productInfo[this.classIndex];
			if (curClass) {
				return `class_${curClass.classId}`;
			}

			return "";
		},
		//选择商品总价
		allPrice() {
			let price = 0;

			if (this.selectList) {
				for (const item of this.selectList) {
					const itemInfo = this.getSelectItemById(item.id, item.classId);
					if (
						itemInfo &&
						!this.$util.isEmpty(itemInfo.bigPrice) &&
						!this.$util.isEmpty(itemInfo.smallPrice)
					) {
						price += item.bigCount * Number(itemInfo.bigPrice);
						price += item.smallCount * Number(itemInfo.smallPrice);
					}
				}
			}

			return Math.round(price * 100) / 100;
		},
		//选择商品总数
		allCount() {
			let bigLength = 0;
			let smallLength = 0;
			if (this.selectList) {
				for (const item of this.selectList) {
					bigLength += item.bigCount
					smallLength += item.smallCount
				}
			}
			return {bigLength:bigLength,smallLength:smallLength,};
		},
		/**
			* 描点-定位分类
			* */
		suitScrollClassId() {
			const curClass = this.suitInfo[this.suitClassIndex];
			if (curClass) {
				return `class_${curClass.classId}`;
			}

			return "";
		},
		/**
			* 多风格-选择商品总价
			* */
		allGoodsPrice() {
			let price = 0;
			if (this.selectList) {
				for (const item of this.selectList) {
					if(item.goodsStyle){
						if(item.goodsStyle==0){
							price += item.bigCount * Number(item.price);
						}else{
							price += item.bigCount * Number(item.goodsStyleList[item.goodsStyleSelectIndex].price);
						}
					}
				}
			}
			return Math.round(price * 100) / 100;
		},
		/**
			* 多风格-选择商品总数
			* */
		allGoodsCount() {
			let length = 0;
			this.selectList.forEach(element => {
				length += Number(element.bigCount)
			})
			return length;
		},
		/**
			* 当前选中商品列表中是否有没有库存的商品
			*/
		hasNoStock() {
			let has = false;
			if (this.selectList) {
				for (const item of this.selectList) {
					const {
						bigCount,
						smallCount,
						bigNum,
						bigUnit,
						smallNum,
						smallUnit,
						ratio
					} = item;
					const ratioNum = Number(ratio);
					if (
						Number(bigCount) * ratioNum + Number(smallCount) >
						Number(bigNum) * ratioNum + Number(smallNum)
					) {
						has = true;
						break;
					}
				}
			}
			return has;
		}
	},
	methods: {
		...mapActions(["setSelectInfoByType", "resetSelectInfoByType"]),
		/**
			* 请求商品数据
			*/
		async initGhsData(id,shopId) {
			//extendInfo调用时的扩展参数  如  shopId
			try {
				let params = {
					py: this.py,
					id:id,
					shopId:shopId
				};
				const { data } = await getGhsProductList(params);
				data.forEach(element => {
					element.child &&
					element.child.forEach(child => {
						child.classId = element.classId;
						child.className = element.className;
					});
				});
				this.productInfo = data;
				this.classIndex = 0;
				this.scrollPushList();
			} catch (error) {
			} finally {
				uni.hideLoading();
			}
		},
		async initData(extendInfo) {
			//extendInfo调用时的扩展参数  如  shopId
			try {
				let params = {
					py: this.py,
					type: this.type
				};
				if (extendInfo) {
					params = { ...params, ...extendInfo };
				}
				const { data } = await getProductDataApi(params);
				data.forEach(element => {
					element.child &&
					element.child.forEach(child => {
						child.classId = element.classId;
						child.className = element.className;
					});
				});
				this.productInfo = data;
				this.classIndex = 0;
				this.scrollPushList();
			} catch (error) {
			} finally {
				uni.hideLoading();
			}
		},
		/**
			* 滚动或切换分类 获取更多数据
			* **/
		scrollPushList(){
			let list = copyObject(this.productInfo);

			if(this.$util.isEmpty(this.filterProductInfo)){	//第一次进入无数据
				let classList = [];
				list.forEach(ele=>{
					classList = [...classList,{child:[],classId:ele.classId,className:ele.className}]
				})
				classList[this.classIndex].child = list[this.classIndex].child;
				this.filterProductInfo = classList;
				let classIndex = 1;
				this.timeFun = setInterval(()=>{
					if(classIndex<this.filterProductInfo.length){
						classList[classIndex].child = list[classIndex].child;
						this.filterProductInfo = classList;
						classIndex++
					}else{
						clearInterval(this.timeFun)
					}
				},600)
			}else{//获取更多数据
				if(this.$util.isEmpty(this.filterProductInfo[this.classIndex].child)){
					this.filterProductInfo[this.classIndex].child = list[this.classIndex].child;
				}
				if(this.classIndex+1<this.filterProductInfo.length-1){
					if(this.$util.isEmpty(this.filterProductInfo[this.classIndex+1].child)){
						this.filterProductInfo[this.classIndex+1].child = list[this.classIndex+1].child;
					}
				}
			}



		},
		/**
			* 滚动商品监听
			* **/
		scroll_detail(options){
			//options  为滚动信息。  options.detail.scrollTop  值为相对于scroll-view。
			if(!uni.getStorageSync("resolve")){
				this.get_node_details(options);
			};
		},
		/**
			* 获取商品节点信息
			* **/
		get_node_details(options){
			const query = uni.createSelectorQuery().in(this); //获得实力
			//获取多个节点方式
			query.selectAll(".selectAll").boundingClientRect(data=>{
				// console.log(data); //得到class类名为  selectAll的数组集合
				this.top_list = data.map(item=>{
					return Math.ceil(item.top);
				});
				this.async_detail_msg(options);
			}).exec();
		},
		async_detail_msg(options){
			//options  为滚动信息。  options.detail.scrollTop  值为相对于scroll-view。
			let top_page = options.detail.scrollTop + this.top_list[0];

			for(let i = 0;i < this.top_list.length; i++){
				let node1 = this.top_list[i];
				let node2 = this.top_list[i+1];
				if(node2 && top_page >= node1 && top_page < node2){
					this.classIndex = i;
					this.scrollPushList();
					break;
				}else if(node2 && top_page === node2){
					this.classIndex = i + 1;
					this.scrollPushList();
					break;
				}
			}
		},
		scroll_bottom(){
			this.classIndex = this.filterProductInfo.length-1
			this.scrollPushList();
		},
		/**
			* 获取当前选中商品总价
			*/
		getSelectItemPrice(item) {
			let price = 0;
			const { bigCount, smallCount, bigPrice, smallPrice } = item;
			let sum =
				Number(bigCount) * Number(bigPrice) +
				Number(smallCount) * Number(smallPrice);
			price = Math.round(sum * 100) / 100;
			return price;
		},
		/**
			* 成品-请求商品数据
			*/
		async initGoodsData(extendInfo) {
			//extendInfo调用时的扩展参数  如  shopId
			try {
				let params = {
					py: this.py,
					type: this.type
				};
				if (extendInfo) {
					params = { ...params, ...extendInfo };
				}
				const { data } = await getGoodsDataApi(params);
				data.forEach(element => {
					element.child &&
					element.child.forEach(child => {
						child.classId = element.classId;
						child.className = element.className;
					});
				});
				this.suitInfo = data;
				this.suitClassIndex = 0;
				this.suitScrollPushList();
			} catch (error) {
			} finally {
				uni.hideLoading();
			}
		},
		/**
			* 成品-滚动或切换分类 获取更多数据
			* **/
		suitScrollPushList(){
			let list = copyObject(this.suitInfo);

			if(this.$util.isEmpty(this.suitFilterProductInfo)){	//第一次进入无数据
				let classList = [];
				list.forEach(ele=>{
					classList = [...classList,{child:[],classId:ele.classId,className:ele.className}]
				})
				classList[this.suitClassIndex].child = list[this.suitClassIndex].child;
				this.suitFilterProductInfo = classList;
				let classIndex = 1;
				this.suitTimeFun = setInterval(()=>{
					if(classIndex<this.suitFilterProductInfo.length){
						classList[classIndex].child = list[classIndex].child;
						this.suitFilterProductInfo = classList;
						classIndex++
					}else{
						clearInterval(this.suitTimeFun)
					}
				},600)
			}else{//获取更多数据
				if(this.$util.isEmpty(this.suitFilterProductInfo[this.suitClassIndex].child)){
					this.suitFilterProductInfo[this.suitClassIndex].child = list[this.suitClassIndex].child;
				}
				if(this.suitClassIndex+1<this.suitFilterProductInfo.length-1){
					if(this.$util.isEmpty(this.suitFilterProductInfo[this.suitClassIndex+1].child)){
						this.suitFilterProductInfo[this.suitClassIndex+1].child = list[this.suitClassIndex+1].child;
					}
				}
			}



		},
		/**
			* 获取当前选中商品总价
			*/
		getSelectGoodsPrice(item) {
			let price = 0;

			if(item.goodsStyle==0){
				price = item.bigCount * Number(item.price);
			}else{
				price = item.bigCount * Number(item.goodsStyleList[item.goodsStyleSelectIndex].price);
			}
			// let sum = 0;
			// if()
			// 	Number(bigCount) * Number(bigPrice) +
			// 	Number(smallCount) * Number(smallPrice);
			// price = Math.round(sum * 100) / 100;
			return price;
		},
		/**
			* 通过id获取当前选中的商品信息
			*/
		getSelectItemById(id, classId) {
			let info = {
				bigCount: 0, //扎数
				smallCount: 0, //支数
				autoPrice: 0, //调价价格
				itemPrice: 0 //调价价格
			};
			const item =
				this.selectList &&
				this.selectList.find(ele => {
					return ele.id == id && ele.classId == classId;
				});
			if (item) {
				info = {
					...item,
					bigCount: Number(item.bigCount),
					smallCount: Number(item.smallCount),
					autoPrice: Number(item.autoPrice),
					itemPrice: Number(item.itemPrice),
				};
			}
			return info;
		},
		/**
			* 通过id获取当前选中的商品类别信息  左边菜单角标  当前选中该类别商品多少件
			*/
		getSelectClassById(classId) {
			let info = {
				bigCount: 0, //扎数
				smallCount: 0 //支数
			};

			const productItem =
				this.productInfo &&
				this.productInfo.find(ele => {
					return ele.classId == classId;
				});
			if (productItem && productItem.child) {
				for (const item of productItem.child) {
					for (const selectItem of this.selectList) {
						if (item.id == selectItem.id && item.classId == selectItem.classId) {
							info.bigCount += Number(selectItem.bigCount);
							info.smallCount += Number(selectItem.smallCount);
							info.itemPrice += selectItem.itemPrice?Number(selectItem.itemPrice):'';
						}
					}
				}
			}
			return info;
		},

		/**
			* 添加商品
			*/
		addEvent(item) {
			const list = this.selectList;
			let has = false;
			for (let index = 0; index < list.length; index++) {
				const element = list[index];
				if (element.id == item.id && element.classId == item.classId) {
					has = true;
					if(this.offVerifyRepertory){//去除库存验证
						if(this.isSmallCount){
							list[index] = { ...element, smallCount: ++element.smallCount };
						}else{
							list[index] = { ...element, bigCount: ++element.bigCount };
						}
					}else {
						if(!this.isSmallCount){
							list[index] = { ...element, bigCount: ++element.bigCount };
						}
						if(this.isSmallCount){
							list[index] = { ...element, smallCount: ++element.smallCount };
						}
						if (this.isLimit) {
							const {bigCount, smallCount} = list[index];
							//超过库存时 设置为库存最大值
							const ratio = Number(item.ratio);
							if (
								Number(bigCount) * ratio + Number(smallCount) >
								Number(item.bigNum) * ratio + Number(item.smallNum)
							) {
								list[index].bigCount = Number(item.bigNum);
								list[index].smallCount = Number(item.smallNum);
								this.$msg("库存不足");
								return;
							}
						}
					}

					break;
				}
			}
			if (!has) {
				let info = { classId: item.classId, id: item.id };

				const classInfo =
					this.productInfo &&
					this.productInfo.find(element => {
						return element.classId == item.classId && element.child;
					});
				if (classInfo) {
					info = classInfo.child.find(ele => {
						return ele.id == item.id;
					});
				}

				let params = {
					...info,
					bigCount: this.isSmallCount?0:1, //扎数
					smallCount: this.isSmallCount?1:0, //支数
					autoPrice: 0 //调价价格
				};
				if (info.bigNum && info.bigNum > 0) {
					list.push(params);
				} else {
					if(this.offVerifyRepertory){//盘点页面没有库存验证
						list.push(params);
					}else{
						this.$msg("库存不足");
						return;
					}
				}
			}
			this.setSelectInfoByType({ type: this.pageType, info: list });
			// this.$forceUpdate();
		},

		addCustomNumEvent(item,params1,type) {
			const list = this.selectList;

			// if (!has) {}
			let info = { classId: item.classId, id: item.id };

			const classInfo =
				this.productInfo &&
				this.productInfo.find(element => {
					return element.classId == item.classId && element.child;
				});
			if (classInfo) {
				info = classInfo.child.find(ele => {
					return ele.id == item.id;
				});
			}

			let params = {
				...info,
				bigCount: 0, //扎数
				smallCount: 0, //支数
				autoPrice: 0 //调价价格
			};
			list.push(params);
			if(type!='noAdd'){
				this.setSelectInfoByType({ type: this.pageType, info: list });
			}
			this.$nextTick(()=>{
				this.customNum(params1)
			})
			// this.$forceUpdate();
		},
		/**
			* 减去商品
			*/
		delEvent(item) {

			const list = copyObject(this.selectList);
			let has = false;
			for (let index = 0; index < list.length; index++) {
				let element = list[index];
				if (element.id == item.id && element.classId == item.classId) {
					has = true;
					if (element.bigCount > 0) {
						if (!this.isSmallCount) {
							list[index] = {...element, bigCount: --element.bigCount};
						}
					}
					if (element.smallCount > 0) {
						if (this.isSmallCount) {
							list[index] = {...element, smallCount: --element.smallCount};
						}
					}
					if (element.bigCount == 0 && element.smallCount == 0) {
						list.splice(index, 1);
					}
				}
			}
			this.setSelectInfoByType({type: this.pageType, info: list});
		},

		// 	const list = this.selectList;
		// 	let has = false;
		// 	for (let index = 0; index < list.length; index++) {
		// 		const element = list[index];
		// 		if (element.id == item.id && element.classId == item.classId) {
		// 			has = true;
		//
		// 			if (element.bigCount > 0) {
		// 				if(!this.isSmallCount){list[index] = { ...element, bigCount: --element.bigCount };}
		// 			}
		// 			if (element.smallCount > 0) {
		// 				if(this.isSmallCount){list[index] = { ...element, smallCount: --element.smallCount };}
		// 			}
		//
		// 			if (this.isLimit) {
		// 				const { bigCount, smallCount } = list[index];
		// 				//超过库存时 设置为库存最大值
		// 				const ratio = Number(item.ratio);
		// 				if (
		// 					Number(bigCount) * ratio + Number(smallCount) >
		// 					Number(item.bigNum) * ratio + Number(item.smallNum)
		// 				) {
		// 					list[index].bigCount = Number(item.bigNum);
		// 					list[index].smallCount = Number(item.smallNum);
		// 				}
		// 			}
		// 			if (element.bigCount == 0 && element.smallCount == 0) {
		// 				list.splice(index, 1);
		// 			}
		//
		// 			break;
		// 		}
		// 	}
		// 	if (!has) {
		// 		let info = { classId: item.classId, id: item.id };
		//
		// 		const classInfo =
		// 			this.productInfo &&
		// 			this.productInfo.find(element => {
		// 				return element.classId == item.classId && element.child;
		// 			});
		// 		if (classInfo) {
		// 			info = classInfo.child.find(ele => {
		// 				return ele.id == item.id;
		// 			});
		// 		}
		// 		let params = {
		// 			...info,
		// 			bigCount: 1, //扎数
		// 			smallCount: 0, //支数
		// 			autoPrice: 0 //调价价格
		// 		};
		//
		// 		list.push(params);
		// 	}
		// 	this.setSelectInfoByType({ type: this.pageType, info: list });
		// 	// this.$forceUpdate();
		// },
		// //减去所有商品
		delAllEvent(item) {
			const list = this.selectList;
			for (let index = 0; index < list.length; index++) {
				const element = list[index];
				if (element.id == item.id ) {
					list.splice(index, 1);
					break;
				}
			}
			this.setSelectInfoByType({ type: this.pageType, info: list });
		},
		/**
			* 通过id获取当前选中的商品类别信息  左边菜单角标  当前选中该类别商品多少件
			*/
		getSuitSelectClassById(classId) {
			let info = {
				bigCount: 0, //扎数
				smallCount: 0 //支数
			};

			const productItem =
				this.suitInfo &&
				this.suitInfo.find(ele => {
					return ele.classId == classId;
				});
			if (productItem && productItem.child) {
				for (const item of productItem.child) {
					for (const selectItem of this.selectList) {
						if (item.id == selectItem.id && item.classId == selectItem.classId) {
							info.bigCount += Number(selectItem.bigCount);
							info.smallCount += Number(selectItem.smallCount);
							info.itemPrice += selectItem.itemPrice?Number(selectItem.itemPrice):'';
						}
					}
				}
			}
			return info;
		},

		/**
			* 多风格-添加商品
			*/
		addGoodsEvent(item) {
			const list = this.selectList;
			//过滤空数据
			// if(item.bigCount==0||!item.bigCount){return}
			let has = false;
			for (let index = 0; index < list.length; index++) {
				const element = list[index];
				if (element.id == item.id && element.classId == item.classId) {
					has = true;
					list[index] = { ...element, bigCount: item.bigCount,goodsStyleSelectIndex: item.goodsStyleSelectIndex };

					break;
				}
			}
			if (!has) {
				let info = { classId: item.classId, id: item.id };

				const classInfo =
					this.suitInfo &&
					this.suitInfo.find(element => {
						return element.classId == item.classId && element.child;
					});
				if (classInfo) {
					info = classInfo.child.find(ele => {
						return ele.id == item.id;
					});
				}

				let params = {
					...info,
					bigCount: item.bigCount, //扎数
					goodsStyleSelectIndex: item.goodsStyleSelectIndex, //选中的风格
				};
				list.push(params);
			}

			this.setSelectInfoByType({ type: this.pageType, info: list });
			// this.$forceUpdate();
		},
		/**
			* 多风格-添加商品
			*/
		addGoods(item) {
			const list = this.selectList;
			let has = false;
			for (let index = 0; index < list.length; index++) {
				const element = list[index];
				if (element.id == item.id && element.classId == item.classId) {
					has = true;
					list[index] = { ...element, bigCount: ++element.bigCount };
					break;
				}
			}
			if (!has) {
				let info = { classId: item.classId, id: item.id };

				const classInfo =
					this.suitInfo &&
					this.suitInfo.find(element => {
						return element.classId == item.classId && element.child;
					});
				if (classInfo) {
					info = classInfo.child.find(ele => {
						return ele.id == item.id;
					});
				}

				let params = {
					...info,
					bigCount: 1, //扎数
					smallCount: 0, //支数
					autoPrice: 0 //调价价格
				};
				list.push(params);
			}

			this.setSelectInfoByType({ type: this.pageType, info: list });
			// this.$forceUpdate();
		},
		/**
			* 多风格-减去商品
			*/
		delGoodsEvent(item) {
			const list = this.selectList;
			for (let index = 0; index < list.length; index++) {
				const element = list[index];
				if (element.id == item.id && element.classId == item.classId) {

					if (element.bigCount > 0) {
						list[index] = { ...element, bigCount: --element.bigCount };
					}
					if (element.bigCount == 0 || !element.bigCount) {
						list.splice(index, 1);
					}
					break;
				}
			}
			this.setSelectInfoByType({ type: this.pageType, info: list });
		},
		/**
			* 更新商品
			*/
		updateItemEvent(item) {
			const list = this.selectList;

			for (let index = 0; index < list.length; index++) {
				const element = list[index];
				if (element.id == item.id && element.classId == item.classId) {
					const { bigCount, smallCount } = list[index];
					//超过库存时 设置为库存最大值
					const ratio = Number(item.ratio);
					if (this.isLimit) {
						if (
							Number(bigCount) * ratio + Number(smallCount) >
							Number(item.bigNum) * ratio + Number(item.smallNum)
						) {
							list[index].bigCount = Number(item.bigNum);
							list[index].smallCount = Number(item.smallNum);
							list[index].itemPrice = item.itemPrice?Number(item.itemPrice):'';
						}
					}
					list[index] = {
						...element,
						bigCount: Number(item.bigCount),
						smallCount: Number(item.smallCount),
						itemPrice: item.itemPrice?Number(item.itemPrice):''
					};
					break;
				}
			}
			this.setSelectInfoByType({ type: this.pageType, info: list });
			// this.$forceUpdate();
		},
		/**
			* 切换左侧商品类别
			*/
		swichClass(cur) {
			clearInterval(this.timeFun)
			this.classIndex = cur;
			this.scroll_into_view = '';
			this.$nextTick(()=>{this.scroll_into_view = 'class_'+cur;})
			this.scrollPushList();
			//解决最后一个 ***来回*** 问题 (由于点击左侧导航，右侧锚点位置信息变化，此时滚动事件也随之滚动。)
			uni.setStorageSync("resolve","last");
			setTimeout(()=>{
				uni.removeStorageSync("resolve")
			},400);
		},

		/**
			* 成品（多风格）-切换左侧商品类别
			*/
		suitSwichClass(cur) {
			clearInterval(this.suitTimeFun)
			this.suitClassIndex = cur;
			this.suit_scroll_into_view = '';
			this.$nextTick(()=>{this.suit_scroll_into_view = 'class_'+cur;})
			this.suitScrollPushList();
			// this.scrollPushList();
			//解决最后一个 ***来回*** 问题 (由于点击左侧导航，右侧锚点位置信息变化，此时滚动事件也随之滚动。)
			uni.setStorageSync("resolve","last");
			setTimeout(()=>{
				uni.removeStorageSync("resolve")
			},400);
		},
		/**
			* 滚动商品监听
			* **/
		suit_scroll_detail(options){
			//options  为滚动信息。  options.detail.scrollTop  值为相对于scroll-view。
			if(!uni.getStorageSync("resolve")){
				this.suit_get_node_details(options);
			};
		},
		/**
			* 获取商品节点信息
			* **/
		suit_get_node_details(options){
			const query = uni.createSelectorQuery().in(this); //获得实力
			//获取多个节点方式
			query.selectAll(".suitSelectAll").boundingClientRect(data=>{
				// console.log(data); //得到class类名为  selectAll的数组集合
				this.suit_top_list = data.map(item=>{
					return Math.ceil(item.top);
				});
				this.suit_async_detail_msg(options);
			}).exec();
		},
		suit_async_detail_msg(options){
			//options  为滚动信息。  options.detail.scrollTop  值为相对于scroll-view。
			let top_page = options.detail.scrollTop + this.suit_top_list[0];

			for(let i = 0;i < this.suit_top_list.length; i++){
				let node1 = this.suit_top_list[i];
				let node2 = this.suit_top_list[i+1];
				if(node2 && top_page >= node1 && top_page < node2){
					this.suitClassIndex = i;
					this.suitScrollPushList();
					break;
				}else if(node2 && top_page === node2){
					this.suitClassIndex = i + 1;
					this.suitScrollPushList();
					break;
				}
			}
		},
		suit_scroll_bottom(){
			this.suitClassIndex = this.suitFilterProductInfo.length-1
			this.suitScrollPushList();
		},
		/**
			* 搜索对应花材
			*/
		suitSearchFn() {
			let list = copyObject(this.suitFilterProductInfo);
			if(!this.$util.isEmpty(this.py)){
				clearInterval(this.suitTimeFun)
				let commonChildList = [];
				list.forEach(ele => {
					//过滤常用
					if(ele.classId != -2){
						if (!this.$util.isEmpty(ele.child)) {
							ele.child.forEach(obj => {
								let hasName = obj.goodsName && obj.goodsName.indexOf(this.py) >= 0;
								let elePy = (obj.py && obj.py.toLocaleUpperCase()) || "";
								let hasPy = elePy.indexOf(this.py.toLocaleUpperCase()) >= 0;
								if (hasName || hasPy) {
									if(this.$util.isEmpty(commonChildList)){
										commonChildList = [...commonChildList,{classId: ele.classId, className: ele.className,child:[obj]}];
									}else{
										commonChildList.forEach(res => {
											if(res.classId==ele.classId){
												res.child.push(obj)
											}else{
												commonChildList.push({classId: ele.classId, className: ele.className,child:[obj]});
											}
										})
									}
								}
							});
						}

					}
				});
				list = this.$util.unique(commonChildList)
				this.suitFilterProductInfo = list;
				this.suitClassIndex = 0;
			}else{
				this.suitFilterProductInfo = '';
				this.suitClassIndex = 0;
				this.suitScrollPushList();
			}
		},
		searchFn() {
			let list = copyObject(this.productInfo);
			if(!this.$util.isEmpty(this.py)){
				clearInterval(this.timeFun)
				let commonChildList = [];
				list.forEach(ele => {
					//过滤常用
					if(ele.classId != -2){
						if (!this.$util.isEmpty(ele.child)) {
							ele.child.forEach(obj => {
								let hasName = obj.itemName && obj.itemName.indexOf(this.py) >= 0;
								let elePy = (obj.py && obj.py.toLocaleUpperCase()) || "";
								let hasPy = elePy.indexOf(this.py.toLocaleUpperCase()) >= 0;
								if (hasName || hasPy) {
									if(this.$util.isEmpty(commonChildList)){
										commonChildList = [...commonChildList,{classId: ele.classId, className: ele.className,child:[obj]}];
									}else{
										commonChildList.forEach(res => {
											if(res.classId==ele.classId){
												res.child.push(obj)
											}else{
												commonChildList.push({classId: ele.classId, className: ele.className,child:[obj]});
											}
										})
									}
								}
							});
						}

					}
				});
				list = this.$util.unique(commonChildList)
				this.filterProductInfo = list;
				this.suitClassIndex = 0;
			}else{
				this.filterProductInfo = '';
				this.classIndex = 0;
				this.scrollPushList();
			}
		},


		/**
			* 请求课程数据
			*/
		async initPxClassData() {
			try {
				const { data } = await getPxClassDataApi({pageSize:50});
				this.pxClassInfo = data.list;
			} catch (error) {
			} finally {
				uni.hideLoading();
			}
		},
	}
};
