| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 | const _Http = getApp().globalData.http;import {	fileList} from "../../utils/FormatTheAttachment";Page({	data: {		loading: true,		active: "",		list: [],		groupList: [],		pageNumber: 1,		pageTotal: 1,	},	onLoad(options) {		if (options.id) this.setData({			sa_promotionid: options.id		})		this.getDetail();	},	/* 获取详情 */	getDetail() {		_Http.basic({			"id": "20221230144703",			"version": 1,			"content": {				"sa_promotionid": this.data.sa_promotionid			}		}).then(res => {			if (res.msg != '成功') return wx.showToast({				title: res.msg,				icon: "none"			})			this.handleFiles(res.data.attinfos)			this.setData({				detail: res.data,				loading: false			});			this.getGroup()		})	},	/* 获取组 */	getGroup() {		_Http.basic({			"id": 20230102112303,			"version": 1,			"content": {				"sa_promotionid": this.data.sa_promotionid			}		}).then(res => {			console.log("获取商品分类", res)			if (res.msg != '成功') return wx.showToast({				title: res.msg,				icon: "none"			})			if (res.data.length != 0) this.setData({				groupList: res.data,				active: res.data[0].sa_promotion_itemgroupid			});			if (res.data.length) this.getProductList();		})	},	/* 切换商品tab */	tabChange(e) {		this.setData({			active: e.detail.name,			pageNumber: 1,			pageTotal: 1		});		this.getProductList();	},	/* 获取产品列表 */	getProductList() {		let pageNumber = this.data.pageNumber,			pageTotal = this.data.pageTotal;		if (pageNumber > pageTotal) return;		_Http.basic({			"id": 20230116094803,			"version": 1,			"content": {				sa_promotionid: this.data.sa_promotionid,				"sa_promotion_itemgroupid": this.data.active,				pageNumber,				pageTotal,				"where": {					"condition": ""				}			}		}).then(res => {			console.log('活动产品列表', res)			if (res.msg != '成功') return wx.showToast({				title: res.msg,				icon: "none"			})			res.data = res.data.map(value => {				if (value.attinfos.length != 0) {					value.attinfos = fileList(value.attinfos)					let image = value.attinfos.find(v => v.fileType == "image");					value.cover = image ? image.cover : "";				}				return value;			})			this.setData({				list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),				pageNumber: res.pageNumber + 1,				pageTotal: res.pageTotal			})		})	},	/* 预览图片 */	viewImage(e) {		const {			file		} = e.currentTarget.dataset;		if (file.length) wx.previewMedia({			sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {				return {					url: v.url,					type: v.fileType				}			}),			current: 0,			showmenu: true		})	},	/* 预览媒体 */	viewMedias(e) {		const {			index,			type		} = e.currentTarget.dataset;		wx.previewMedia({			current: index,			sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,		})	},	/* 处理附件 */	handleFiles(arr) {		let files = {				images: [],				viewImages: [],				videos: [],				viewVideos: [],				files: []			},			list = fileList(arr);		list.forEach(v => {			switch (v.fileType) {				case "video":					files.videos.push(v)					files.viewVideos.push({						url: v.url,						type: "video",						poster: v.subfiles[0].url					})					break;				case "image":					files.images.push(v)					files.viewImages.push({						url: v.url,						type: "image"					})					break;				default:					files.files.push(v)					break;			}		});		this.setData({			files		})	},	/* 去下单 */	clickBut() {		wx.navigateTo({			url: '/packageA/activity/selectProduct/index?params=' + JSON.stringify({				"id": 20230116094803,				"version": 1,				"content": {					nocache: true,					sa_promotionid: this.data.sa_promotionid,					sa_promotion_itemgroupid: this.data.active,					"where": {						"condition": ""					}				}			}),		});		getApp().globalData.handleSelect = this.creadedOrderForm.bind(this);	},	creadedOrderForm({		list	}) {		console.log(list)		let that = this;		wx.showModal({			title: '提示',			content: '是否确定创建促销订单?',			complete: (res) => {				if (res.confirm) _Http.basic({					"id": 20221108111402,					content: {						sa_orderid: 0,						sa_accountclassid: that.data.detail.sa_accountclassid,						rec_contactsid: 0,						pay_enterpriseid: 0,						sa_contractid: 0,						sa_projectid: 0,						sa_promotionid: that.data.detail.sa_promotionid,						"sa_brandid": that.data.detail.sa_brandid, //品牌ID						"type": "促销订单", //订单类型						"tradefield": that.data.detail.tradefield, //必选					}				}).then(res => {					console.log("创建促销订单", res);					wx.showToast({						title: res.msg != '成功' ? res.msg : '创建成功',						icon: "none"					});					/* 绑定产品 */					_Http.basic({						"id": 20221109093602,						"content": {							"sa_orderid": res.data.sa_orderid,							"sa_contractid": res.data.sa_contractid,							"sys_enterpriseid": res.data.sys_enterpriseid,							"type": "促销订单",							"items": list.map(v => {								return {									"sa_orderitemsid": 0,									"itemid": v.itemid,									"qty": v.qty,									price: v.price								}							})						}					}).then(s => {						if (s.msg == '成功') setTimeout(() => {							wx.redirectTo({								url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,							});						}, 500)					})				})			}		})	},	onReachBottom() {		this.getProductList();	}})
 |