123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- const _Http = getApp().globalData.http;
- import {
- fileList
- } from "../../utils/FormatTheAttachment";
- Page({
- data: {
- hidePrice: wx.getStorageSync('hidePrice'),
- 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.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");
- if (image) {
- try {
- value.cover = image.subfiles.find(v => v.type == "thumbnail").url;
- } catch (error) {
- value.cover = image.url;
- }
- }
- }
- if (value.islimit == 0) value.groupqty = 0;
- if (value.gradeprice) value.gradeprice = (value.gradeprice - 0).toFixed(2)
- if (value.oldprice) value.oldprice = (value.oldprice - 0).toFixed(2)
- if (value.price) value.price = (value.price - 0).toFixed(2)
- 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_brandid: this.data.detail.sa_brandid,
- sa_promotionid: this.data.sa_promotionid,
- sa_promotion_itemgroupid: this.data.active,
- "where": {
- "condition": ""
- }
- }
- }),
- });
- getApp().globalData.handleSelect = this.creadedOrderForm.bind(this);
- },
- creadedOrderForm({
- list
- }) {
- let that = this;
- wx.showModal({
- title: '提示',
- content: '是否确定创建促销订单?',
- complete: (res) => {
- if (res.confirm)
- _Http.basic({
- "id": 20221128183202,
- "content": {
- istool: 0,
- type: "促销订单",
- 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.join(','), //必选
- "items": list.map(v => {
- return {
- "sa_orderitemsid": 0,
- "itemid": v.itemid,
- "qty": v.qty,
- price: v.price,
- length: v.length,
- width: v.width,
- sa_promotion_itemsid: v.sa_promotion_itemsid
- }
- })
- }
- }).then(res => {
- console.log("转化促销订单", res)
- wx.showToast({
- title: res.msg != '成功' ? res.msg : '创建成功',
- icon: "none"
- });
- if (res.msg == '成功') setTimeout(() => {
- wx.redirectTo({
- url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
- });
- }, 300)
- })
- }
- })
- },
- onReachBottom() {
- this.getProductList();
- }
- })
|