| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 | const _Http = getApp().globalData.http,	currency = require("../../../utils/currency"),	CNY = sum => currency(sum, {		symbol: "¥",		precision: 2	}).format();let downCount = {};import {	getCustomText} from "../../../utils/customItemType";Component({	options: {		addGlobalClass: true,	},	properties: {},	data: {		list: [],		results: [], //选中结果		sa_brandid: null, //当前选中品牌id		classList: [], //生成订单时所选		sum: 0, //价格合		allBrandList: [],		hidePrice: wx.getStorageSync('hidePrice'),	},	methods: {		init() {			this.getList()			getApp().globalData.customizedProduct = (item, custom) => {				return new Promise((resolve) => {					wx.showLoading({						title: '修改中...',					})					_Http.basic({						"id": 20220924104302,						"content": {							"sa_shoppingcartid": item.sa_shoppingcartid,							"qty": item.qty,							...custom						},					}).then(res => {						console.log("修改定制", res)						wx.showToast({							title: res.msg != '成功' ? res.msg : '修改成功',							icon: "none"						});						this.getList()						resolve(true)					})				})			}			let domainrelatedaccounts = wx.getStorageSync('domainrelatedaccounts');			if (domainrelatedaccounts.length) {				this.setData({					domainrelatedaccounts				})			} else {				_Http.basic({					"classname": "sysmanage.develop.optiontype.optiontype",					"method": "optiontypeselect",					"content": {						"pageNumber": 1,						"pageSize": 9999,						"typename": "domainrelatedaccounts"					}				}).then(res => {					console.log("查询领域对应列表", res)					if (res.msg == '成功' && res.data.length) {						domainrelatedaccounts = res.data;						wx.setStorageSync('domainrelatedaccounts', domainrelatedaccounts)						this.setData({							domainrelatedaccounts						})					}				})			}			console.log("domainrelatedaccounts", domainrelatedaccounts)			return true;		},		/* 获取列表 */		getList() {			_Http.basic({				"id": 20220924095302,				"content": {					nocache: true,					istool: 0,					"pageNumber": 1,					"pageSize": getApp().globalData.collectCount + 5,					"where": {						"condition": ""					}				}			}).then(res => {				console.log('购物车列表', res)				this.selectComponent('#ListBox').RefreshToComplete();				this.selectComponent("#ListBox").setHeight(".head", this);				if (res.msg != '成功') return wx.showToast({					title: res.msg,					icon: "none"				})				let list = [],					allBrandList = [];				list = res.data.map(v => {					v.showPrice = CNY(v.gradeprice)					let obj = allBrandList.find(s => s.sa_brandid == v.sa_brandid);					if (obj) {						obj.results.push(v.sa_shoppingcartid)					} else {						allBrandList.push({							brandname: v.brandname,							sa_brandid: v.sa_brandid,							results: [v.sa_shoppingcartid],						})					}					if (v.iscustomsize) v.customText = getCustomText(v);					return v				});				this.setData({					list,					allBrandList,					isGet: true				});				if (wx.getStorageSync('shopping')) {					this.setData({						...wx.getStorageSync('shopping')					});					this.computeSum();				}			})		},		clickBut(e) {			this.data.classList.length >= 2 ? wx.showToast({				title: '请选择订单领域(订单只允许同品牌/同领域的商品)',				icon: "none",				duration: 3000			}) : this.handleSubmit(0);		},		/* 提交 */		submit(e) {			this.handleSubmit(e.detail.value)		},		handleSubmit(index) {			let data = this.data.classList[index];			let tradefield = this.data.domainrelatedaccounts.find(v => v.value == data.type);			_Http.basic({				"id": 20221008134803,				"version": 1,				"content": {					"pageNumber": 1,					"pageTotal": 1,					"pageSize": 9999,					"where": {						"condition": "",						"isused": 1,						"isnotspecialfund": 0, //是否专用					},				}			}).then(acc => {				console.log("账户列表", acc)				let list = acc.data.filter(v => tradefield.subvalues.some(s => s == v.sa_accountclassid))				_Http.basic({					"id": 20221128183202,					"content": {						istool: 0,						type: "标准订单",						"tradefield": data.type, //必选						sa_accountclassid: list.length ? list[0].sa_accountclassid : 0,						"items": data.list.map(v => {							return {								"sa_orderitemsid": 0,								"itemid": v.itemid,								"sa_brandid": v.sa_brandid,								"qty": v.qty,								width: v.width || 0,								length: v.length || 0,								sa_shoppingcartid: v.sa_shoppingcartid || 0							}						})					}				}).then(res => {					console.log("转化订单", res)					if (res.msg != '成功') return wx.showToast({						title: res.msg,						icon: "none"					});					getApp().globalData.getCollectCount()					wx.showModal({						title: '提示',						content: '生成成功!是否立即前往',						complete: (s) => {							if (s.confirm) {								wx.navigateTo({									url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,								})							}						}					});					this.getList();				})			})		},		/* 是否选择全部 */		setIsAll() {			let isAll = this.data.isAll;			//取消全选			if (isAll) {				this.setData({					sa_brandid: null,					results: []				})			} else {				//已选品牌产品情况下				if (this.data.sa_brandid) {					let obj = this.data.allBrandList.find(v => v.sa_brandid == this.data.sa_brandid)					this.setData({						results: obj.results					})				} else {					if (this.data.allBrandList.length == 0) return;					this.setData({						sa_brandid: this.data.allBrandList[0].sa_brandid,						results: this.data.allBrandList[0].results					})				}			};			this.computeSum();		},		/* 切换选中项 */		changeResults(e, my = false) {			const {				item			} = my ? e : e.currentTarget.dataset;			let results = this.data.results,				sa_brandid = this.data.sa_brandid;			if (sa_brandid && sa_brandid != item.sa_brandid) return;			if (results.length == 0) {				results.push(item.sa_shoppingcartid);				sa_brandid = item.sa_brandid;			} else {				let index = results.findIndex(v => v == item.sa_shoppingcartid)				if (index == -1) {					results.push(item.sa_shoppingcartid);				} else {					results.splice(index, 1);					if (results.length == 0) sa_brandid = null;				}			};			this.setData({				results,				sa_brandid			})			this.computeSum();		},		customization(e) {			const {				item			} = e.target.dataset;			getApp().globalData.customizedProduct = (item, custom) => {				return new Promise((resolve) => {					wx.showLoading({						title: '修改中...',					})					_Http.basic({						"id": 20220924104302,						"content": {							"sa_shoppingcartid": item.sa_shoppingcartid,							"qty": item.qty,							...custom						},					}).then(res => {						console.log("修改定制", res)						wx.showToast({							title: res.msg != '成功' ? res.msg : '修改成功',							icon: "none"						});						this.getList()						resolve(true)					})				})			}			if (item) this.selectComponent("#Custom").onClick(item)		},		/* 计算总价/产品领域分类 */		computeSum() {			let results = this.data.results,				sum = 0,				classList = [];			if (results.length) results = results.filter(v => {				let item = this.data.list.find(va => va.sa_shoppingcartid == v);				if (item) {					sum = currency(sum).add(currency(item.qty).multiply(item.gradeprice)).value;					/* 领域分类 */					let index = classList.findIndex(value => value.type == item.tradefield_shoppingcart);					if (index == -1) {						classList.push({							type: item.tradefield_shoppingcart,							list: [item],							name: item.tradefield_shoppingcart + "(1件商品)"						})					} else {						classList[index].list.push(item)						classList[index].name = classList[index].type + `(${classList[index].list.length}件商品)`					}				};				return item			});			let sa_brandid = results.length ? this.data.sa_brandid : null;			wx.setStorageSync('shopping', {				results,				sa_brandid			})			let isAll = false;			if (sa_brandid) {				let brand = this.data.allBrandList.find(v => v.sa_brandid == sa_brandid)				isAll = brand.results.length == results.length			}			console.log(results)			this.setData({				sum: CNY(sum),				isAll,				results,				sa_brandid,				classList			});		},		/* 删除产品 */		deteleItem(e) {			const {				item			} = e.currentTarget.dataset;			wx.showModal({				title: '提示',				content: `是否确认删除${item.itemname}?`,				complete: ({					confirm				}) => {					e.detail.instance.close();					if (confirm) _Http.basic({						"id": 20220924095202,						"content": {							"sa_shoppingcartids": [item.sa_shoppingcartid]						}					}).then(res => {						wx.showToast({							title: res.msg != '成功' ? res.msg : "删除成功",							icon: "none"						});						if (res.msg != '成功') return;						this.getList(true)						getApp().globalData.getCollectCount()					})				}			})		},		/* 输入框失去焦点调整数量 */		inputBlur(e) {			const {				index			} = e.currentTarget.dataset;			let item = this.data.list[index];			let qty = 0;			if (item.orderminqty > e.detail.value) {				wx.showToast({					title: '输入数量低于最低起订量!',					icon: "none"				})				qty = item.orderminqty;			} else if (item.orderminqty < e.detail.value) {				var currencyRounding = value => currency(value, {					increment: item.orderaddqty				});				qty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;			} else {				qty = e.detail.value;			}			this.setData({				[`list[${index}].qty`]: 0			});			this.setData({				[`list[${index}].qty`]: qty			});			this.computeSum();			clearTimeout(downCount['count' + index])			downCount['count' + index] = setTimeout(() => {				_Http.basic({					"id": 20220924104302,					"content": {						"sa_shoppingcartid": item.sa_shoppingcartid,						"qty": item.qty,						"width": item.width || 0,						"length": item.length || 0					},				}, false).then(res => {					console.log("修改数量", res)				})			}, 2000)		},		/* 步进器调整数量 */		stepperChange(e) {			const {				index			} = e.currentTarget.dataset;			let item = this.data.list[index];			if (e.type == 'plus') {				item.qty += item.orderaddqty			} else {				item.qty -= item.orderaddqty			}			this.setData({				[`list[${index}]`]: item			})			this.computeSum();			clearTimeout(downCount['count' + index])			downCount['count' + index] = setTimeout(() => {				_Http.basic({					"id": 20220924104302,					"content": {						"sa_shoppingcartid": item.sa_shoppingcartid,						"qty": item.qty,						"width": item.width || 0,						"length": item.length || 0					},				}, false).then(res => {					console.log("修改数量", res)				})			}, 2000)		}	}})
 |