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(); getApp().globalData.Language.getLanguagePackage(this, 'E-订单'); }, /* 获取详情 */ getDetail() { _Http.basic({ "id": "20221230144703", "version": 1, "content": { "sa_promotionid": this.data.sa_promotionid } }).then(res => { if (res.code != '1') 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.code != '1') 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.code != '1') 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() { let that = this; wx.showModal({ cancelText: getApp().globalData.Language.getMapText('取消'), confirmText: getApp().globalData.Language.getMapText('确定'), title: getApp().globalData.Language.getMapText('提示'), content: getApp().globalData.Language.getMapText('是否确定创建促销订单') + '?', 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.code != '1' ? res.msg : getApp().globalData.Language.getMapText('创建成功'), icon: "none" }); if (res.code == '1') setTimeout(() => { wx.navigateTo({ url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid, }); }, 500) }) } }) }, onReachBottom() { this.getProductList(); } })