const app = getApp(); const api = require('../../api/api'); const storageManager = require("../../utils/storage-manager.js"); // pages/announce/announce.js Page({ /** * 页面的初始数据 */ data: { // 通用 navbarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '创建新拼团', //导航栏 中间的标题 capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页) }, index: 0, //当前步骤(0-拼团介绍;1-编辑商品;2-规则设置) type: '', //类型(add-创建新拼团;copy-复制往期拼团;edit-编辑拼团;) id: 0, //拼团ID /* 拼团介绍 */ arealength: 0, groupName: '', //拼团名称 groupDesc: '', //拼团描述 videoList: [], //拼团视频 bigImageList: [], //拼团大图 smallImageList: [], //拼团小图 /* 编辑商品 */ foottab: ['全部', '日用品', '熟食', '奶制品'], leiindex: 0, checked: false, mockData: [], //商品列表 openManageMode: false, //是否开启管理模式 checkBoxResult: [], //复选框结果 checkedAll: false, /* 规则设置 */ // planB-开始 startTuanTime: '', //开团时间 endTuanTime: '', //截团时间 daoHuoTime: '', //预计到货时间 // planB-开始 showDateTimePicker: false, //显示日期时间弹窗 selectDateTimeType: 0, //选择类型(0:开团时间;1:截团时间;2:预计到货时间) selectDateMode: true, //是否为选择日期 selectDate: [], //当前选中日期(开团日期) selectTime: [], //当前选中时间(开团时间) selectEndDate: [], //当前选中日期(截团日期) selectEndTime: [], //当前选中时间(截团时间) selectPlanDate: [], //当前选中日期(预计到货日期) selectPlanTime: [], //当前选中时间(截团到货时间) hours: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'], minutes: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59'], // 物流方式相关-开始 showShippingMethods: false, //显示物流方式 shippingMethods: [ { name: '取货点自提', index: 1, className: 'actions-first-child' }, { name: '送货或自提', index: 2 } ], logistics_mode: '', //物流方式(0没有物流,1取货点自提,2送货或者自提 // 物流方式相关-结束 // 提货点相关开始 pick_point: [], // 提货点相关结束 showPreviewImage: false, //显示预览图片 previewImageURL: 'https://s1.ax1x.com/2022/05/23/XpinUI.jpg', //预览图片地址 showPreviewImage2: false, //显示预览图片2 previewImageURL2: 'https://s1.ax1x.com/2022/05/23/Xpil28.jpg', //预览图片地址2 showPreviewImageMenus: false, //显示菜单 showPreviewImageMenus2: false, //显示菜单2 previewImageMenus: [{ name: '拍照', className: 'actions-first-child' }, { name: '相册' } ], wechat_payment: 0, search: 0, show_list: 0, comment: 0, seller_forwarding: 0, receiving_information: 0, wxpayservice: '', //微信支付手续费 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { app.clearSubPageResult(); let that = this; that.setData({ type: options.type, id: Number(options.id) }) if (that.data.type == 'edit') { that.setData({ navbarData: { showCapsule: 1, title: '编辑拼团', capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页) } }) } if (options.id) { wx.showLoading({ title: '加载中', mask: true }) wx.request({ url: api.Gang_info, header: { 'Authorization': wx.getStorageSync('token') }, data: { id: Number(options.id) }, method: 'POST', success(res) { console.log(res); if (res.data.code === 1) { // 对拼团大图/拼团小图/拼团视频做非空校验 let gang_video = res.data.data.gang_video; let gang_big_img = res.data.data.gang_big_img; let gang_small_img = res.data.data.gang_small_img; if(gang_video == null) { gang_video = []; }else{ gang_video = [gang_video]; } if(gang_big_img == null) { gang_big_img = []; }else{ gang_big_img = [gang_big_img]; } if(gang_small_img[0] == '') { gang_small_img = []; }else{ gang_small_img = gang_small_img; } that.setData({ groupName: res.data.data.gang_name, groupDesc: res.data.data.gang_describe, videoList: gang_video, bigImageList: gang_big_img, smallImageList: gang_small_img, startTuanTime: res.data.data.opening_time, endTuanTime: res.data.data.closing_time, logistics_mode: res.data.data.logistics_mode, daoHuoTime: res.data.data.expected_arrival_time, previewImageURL: res.data.data.background_img, previewImageURL2: res.data.data.cover_img, wechat_payment: res.data.data.wechat_payment, search: res.data.data.search, show_list: res.data.data.show_list, comment: res.data.data.comment, seller_forwarding: res.data.data.seller_forwarding, receiving_information: res.data.data.receiving_information }) } else { wx.showToast({ title: res.data.msg, mask: true, icon: 'none' }) } }, fail(err) { wx.showToast({ title: '发起网络请求失败', icon: 'none', mask: true }) }, complete() { wx.hideLoading() } }) wx.request({ url: api.commodity, header: { 'Authorization': wx.getStorageSync('token') }, data: { id: Number(options.id) }, method: 'POST', success(res) { console.log(res); if (res.data.code === 1) { that.setData({ mockData: res.data.data }) } else { wx.showToast({ title: res.data.msg, mask: true, icon: 'none' }) } }, fail(err) { wx.showToast({ title: '发起网络请求失败', icon: 'none', mask: true }) }, complete() { wx.hideLoading() } }) } // 获取微信支付手续费 that.getWXPayServiceCharge(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: async function () { let result = await storageManager.get('subPageResult'); let that = this; console.log(result); if (result !== null) { for (let i = 0; i < result.length; i++) { result[i].xuan = false } let mockData = that.data.mockData; mockData = mockData.concat(result); let newMockData = that.removeDuplicateObj(mockData); that.setData({ mockData: newMockData }) storageManager.set('subPageResult', null); } if(wx.getStorageSync('obj')) { let obj = wx.getStorageSync('obj'); console.log(obj); let mockData = that.data.mockData; mockData[obj.index].commodity_name = obj.name; mockData[obj.index].price = obj.price; mockData[obj.index].stock = obj.stock; wx.removeStorageSync('obj'); that.setData({ mockData }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { app.clearSubPageResult() }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /* 通用方法 */ // 下一步 nextone() { this.setData({ index: this.data.index += 1 }) }, // 选择顶部标签 selectTopTab(e) { this.setData({ index: Number(e.currentTarget.dataset.index) }) }, // 数组去重 removeDuplicateObj(arr) { let obj = {}; arr = arr.reduce((newArr, next) => { obj[next.id] ? "" : (obj[next.id] = true && newArr.push(next)); return newArr; }, []); return arr; }, /* 拼团介绍 */ // 输入拼团名称 inputGroupName(e) { this.setData({ groupName: e.detail.value }) }, // 输入拼团描述 inputGroupDesc(e) { this.setData({ groupDesc: e.detail.value }) }, // 当前输入字数 limitWord(e) { this.setData({ arealength: e.detail.value.length }) }, // 上传大图 uploadBigImage() { let that = this; if (that.data.bigImageList.length === 0) { // wx.showLoading({ // title: '文件上传中', // mask: true // }) wx.request({ url: api.getSignedUrl, data: { type: 'image' }, success: (oss) => { console.log(oss); wx.chooseMedia({ count: 1, mediaType: ['image'], success: (img) => { console.log(img); let key = "image/" + new Date().getTime() + Math.floor(Math.random() * 150) + '.png'; wx.showLoading({ title: '文件上传中', mask: true }) wx.uploadFile({ filePath: img.tempFiles[0].tempFilePath, name: 'file', url: 'https://' + oss.data.data.host, //输入你的bucketname.endpoint formData: { key: key, policy: oss.data.data.policy, // 输入你获取的的policy OSSAccessKeyId: oss.data.data.OSSAccessKeyId, // 输入你的AccessKeyId success_action_status: '200', // 让服务端返回200,不然,默认会返回204 signature: oss.data.data.Signature, // 输入你获取的的signature }, success: (res) => { if (res.statusCode == 200) { let src = 'https://' + oss.data.data.host + '/' + key; console.log(src); let arr = []; arr.push(src); that.setData({ bigImageList: arr }) } }, fail: (err) => { console.log(err); }, complete: () => { wx.hideLoading() } }) }, fail: (err) => { wx.hideLoading() } }) }, fail: (err) => { console.log(err); } }) } }, // 上传小图 uploadSmallImage() { let that = this; if (that.data.smallImageList.length < 5) { // wx.showLoading({ // title: '文件上传中', // mask: true // }) wx.request({ url: api.getSignedUrl, data: { type: 'image' }, success: (oss) => { console.log(oss); wx.chooseMedia({ count: 5, mediaType: ['image'], success: (img) => { this.uploadFileImg(img,0,oss) }, fail: (err) => { wx.hideLoading() } }) }, fail: (err) => { console.log(err); } }) } }, uploadFileImg(img,i,oss){ let that = this; let key = "image/" + new Date().getTime() + Math.floor(Math.random() * 150) + '.png'; wx.showLoading({ title: '文件上传中', mask: true }) wx.uploadFile({ filePath: img.tempFiles[i].tempFilePath, name: 'file', url: 'https://' + oss.data.data.host, //输入你的bucketname.endpoint formData: { key: key, policy: oss.data.data.policy, // 输入你获取的的policy OSSAccessKeyId: oss.data.data.OSSAccessKeyId, // 输入你的AccessKeyId success_action_status: '200', // 让服务端返回200,不然,默认会返回204 signature: oss.data.data.Signature, // 输入你获取的的signature }, success: (res) => { if (res.statusCode == 200) { let src = 'https://' + oss.data.data.host + '/' + key; console.log(src); let oldSmallImageList = that.data.smallImageList; oldSmallImageList.push(src); that.setData({ smallImageList: oldSmallImageList }) if (++i< img.tempFiles.length) { this.uploadFileImg(img,i,oss) // that.getammeternumber(fileList, i, length,dataset,skushowpricekey); }else{} } }, fail: (err) => { console.log(err); }, complete: (complete) => { console.log(complete) wx.hideLoading() } }) }, // 上传视频 uploadVideo() { let that = this; if (that.data.videoList.length === 0) { // wx.showLoading({ // title: '文件上传中', // mask: true // }) wx.request({ url: api.getSignedUrl, data: { type: 'video' }, success: (oss) => { console.log(oss); wx.chooseMedia({ count: 1, mediaType: ['video'], success: (video) => { console.log(video); let key = "video/" + new Date().getTime() + Math.floor(Math.random() * 150) + '.mp4'; wx.showLoading({ title: '文件上传中', mask: true }) wx.uploadFile({ filePath: video.tempFiles[0].tempFilePath, name: 'file', url: 'https://' + oss.data.data.host, //输入你的bucketname.endpoint formData: { key: key, policy: oss.data.data.policy, // 输入你获取的的policy OSSAccessKeyId: oss.data.data.OSSAccessKeyId, // 输入你的AccessKeyId success_action_status: '200', // 让服务端返回200,不然,默认会返回204 signature: oss.data.data.Signature, // 输入你获取的的signature }, success: (res) => { console.log(res); if (res.statusCode == 200) { let src = 'https://' + oss.data.data.host + '/' + key; console.log(src); let arr = []; arr.push(src); that.setData({ videoList: arr }) } }, fail: (err) => { console.log(err); }, complete: () => { wx.hideLoading() } }) }, fail: (err) => { wx.hideLoading() } }) }, fail: (err) => { console.log(err); } }) } }, // 清除视频列表 clearVideoList() { this.setData({ videoList: [] }) }, // 清除大图列表 clearBigImageList() { this.setData({ bigImageList: [] }) }, // 清除小图列表 clearSmallImageList() { this.setData({ smallImageList: [] }) }, // 删除某个视频 deleteVideo(e) { let that = this; let index = e.currentTarget.dataset.index; let videoList = that.data.videoList; videoList.splice(index, 1); this.setData({ videoList }) }, // 删除某个大图 deleteBigImage(e) { let that = this; let index = e.currentTarget.dataset.index; let bigImageList = that.data.bigImageList; bigImageList.splice(index, 1); this.setData({ bigImageList }) }, // 删除某个小图 deleteSmallImage(e) { let that = this; let index = e.currentTarget.dataset.index; let smallImageList = that.data.smallImageList; smallImageList.splice(index, 1); this.setData({ smallImageList }) }, /* 编辑商品 */ // 商品库选择 goodStockChoose() { wx.navigateTo({ url: '/pages/goodsbankchoose/goodsbankchoose', }) }, // 创建新商品 createNewGood() { wx.navigateTo({ url: '/pages/addtogood/addtogood?enterType=announce', }) }, // 点击切换类型 clickLeiXing(e) { this.setData({ leiindex: e.currentTarget.dataset.index }) }, // 点击管理按钮 bianJiManage() { this.setData({ openManageMode: !this.data.openManageMode }) }, // 复选框改变 checkBoxChange(event) { let that = this; that.setData({ checkBoxResult: event.detail, }) const items = that.data.mockData; const values = event.detail; console.log(event.detail) for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].xuan = false for (let j = 0, lenJ = values.length; j < lenJ; ++j) { console.log(items[i].commodity_id) console.log(values[j]) if (items[i].commodity_id == values[j]) { items[i].xuan = true break } } } that.setData({ mockData: items }) if (event.detail.length == that.data.mockData.length) { that.setData({ checkedAll: true }) } else { that.setData({ checkedAll: false }) } }, // 全选复选框 selectAll() { // 先将checkBoxResult数组清空,之后将所有添加项上 const items = this.data.mockData; const checkBoxResult = []; for (let i = 0; i < items.length; i++) { items[i].xuan = true; checkBoxResult.push(items[i].id); } this.setData({ mockData: items, checkedAll: true, checkBoxResult: checkBoxResult }) }, // 取消全选 cancleAll() { const items = this.data.mockData; for (let i = 0; i < items.length; i++) { items[i].xuan = false } this.setData({ mockData: items, checkedAll: false, checkBoxResult: [] }) }, // 编辑商品 editGoods(e) { let index = e.currentTarget.dataset.index; let id = this.data.mockData[index].id; let obj = { index: index, id: id } wx.setStorageSync('obj', obj); wx.navigateTo({ url: '/pages/addtogood/addtogood?enterType=edit&id=' + id, }) }, // 删除商品 deleteGoods() { console.log(this.data.checkBoxResult); let that = this; let arr = that.data.mockData; for (let i = 0; i < that.data.checkBoxResult.length; i++) { arr.splice(arr.findIndex(item => item.commodity_id === Number(that.data.checkBoxResult[i])), 1) } // console.log(arr); that.setData({ mockData: arr }) }, /* 规则设置 */ // planB开始 changeStartTuanTime(e) { // console.log(e.detail.dateString); this.setData({ startTuanTime: e.detail.dateString }) }, changEndTuanTime(e) { // console.log(e.detail.dateString); this.setData({ endTuanTime: e.detail.dateString }) }, changeDaoHuoTime(e) { // console.log(e.detail.dateString); this.setData({ daoHuoTime: e.detail.dateString }) }, // planB结束 // 选择开团时间(打开日期时间选择器) selectStartTime() { let that = this; // 如果日期没有值,以当前日期为初始值 if (that.data.selectDate.length === 0) { let arr = []; let year = new Date().getFullYear(); let month = new Date().getMonth() + 1; let day = new Date().getDate(); arr.push(year); arr.push(month); arr.push(day); that.setData({ selectDate: arr }) } // 如果时间没有值,以当前时间为初始值 if (that.data.selectTime.length === 0) { let arr = []; let hour = new Date().getHours(); if (hour < 10) { hour = '0' + hour } let minute = new Date().getMinutes(); if (minute < 10) { minute = '0' + minute } arr.push(hour); arr.push(minute); that.setData({ selectTime: arr }) } // 初始化选择日期模式/打开选择器 this.setData({ selectDateTimeType: 0, selectDateMode: true, showDateTimePicker: true }) }, // 选择结束时间 selectEndTime() { if (this.data.selectEndDate.length === 0) { let arr = []; let year = new Date().getFullYear(); let month = new Date().getMonth() + 1; let day = new Date().getDate(); arr.push(year); arr.push(month); arr.push(day); this.setData({ selectEndDate: arr }) } if (this.data.selectEndTime.length === 0) { let arr = []; let hour = new Date().getHours(); if (hour < 10) { hour = '0' + hour } let minute = new Date().getMinutes(); if (minute < 10) { minute = '0' + minute } arr.push(hour); arr.push(minute); this.setData({ selectEndTime: arr }) } this.setData({ selectDateTimeType: 1, selectDateMode: true, showDateTimePicker: true }) }, // 选择预计到货时间 selectPlanTime() { if (this.data.selectPlanDate.length === 0) { let arr = []; let year = new Date().getFullYear(); let month = new Date().getMonth() + 1; let day = new Date().getDate(); arr.push(year); arr.push(month); arr.push(day); this.setData({ selectPlanDate: arr }) } if (this.data.selectPlanTime.length === 0) { let arr = []; let hour = new Date().getHours(); if (hour < 10) { hour = '0' + hour } let minute = new Date().getMinutes(); if (minute < 10) { minute = '0' + minute } arr.push(hour); arr.push(minute); this.setData({ selectPlanTime: arr }) } this.setData({ selectDateTimeType: 2, selectDateMode: true, showDateTimePicker: true }) }, // 关闭日期时间选择器 closeDateTimePicker() { this.setData({ showDateTimePicker: false }) }, // 切换选择日期模式 selectDate() { this.setData({ selectDateMode: true }) }, // 切换选择时间模式 selectTime() { this.setData({ selectDateMode: false }) }, // 日历日期改变 dateChanged(e) { let str = e.detail.selectedDate; let arr = str.split('-'); if (this.data.selectDateTimeType === 0) { // 选择开团日期 this.setData({ selectDate: arr }) } else if (this.data.selectDateTimeType === 1) { // 选择截团日期 this.setData({ selectEndDate: arr }) } else if (this.data.selectDateTimeType === 2) { // 选择预计到货日期 this.setData({ selectPlanDate: arr }) } }, // 时间改变 timeChanged(e) { let arr = []; let hour = this.data.hours[e.detail.value[0]]; let minute = this.data.minutes[e.detail.value[1]]; arr.push(hour); arr.push(minute); if (this.data.selectDateTimeType === 0) { // 选择开团时间 this.setData({ selectTime: arr }) } else if (this.data.selectDateTimeType === 1) { // 选择截团时间 this.setData({ selectEndTime: arr }) } else if (this.data.selectDateTimeType === 2) { // 选择预计到货时间 this.setData({ selectPlanTime: arr }) } }, // 打开物流方式动作面板 openShippingMethods() { this.setData({ showShippingMethods: true }) }, // 关闭物流方式动作面板 closeShippingMethods() { this.setData({ showShippingMethods: false }) }, // 点击物流方式动作面板 selectShippingMethods(e) { // console.log(e); this.setData({ logistics_mode: e.detail.index, showShippingMethods: false }) }, // 添加提货点 addPickAddress() { let obj = { address: '', name: '', phone: '', remarks: '' } let arr = this.data.pick_point; arr.push(obj); this.setData({ pick_point: arr }) }, inputPickAddress(e) { // console.log(e); let idx = e.currentTarget.dataset.index; let arr = this.data.pick_point; arr[idx].address = e.detail.value; this.setData({ pick_point: arr }) }, inputPickName(e) { // console.log(e); let idx = e.currentTarget.dataset.index; let arr = this.data.pick_point; arr[idx].name = e.detail.value; this.setData({ pick_point: arr }) }, inputPickPhone(e) { // console.log(e); let idx = e.currentTarget.dataset.index; let arr = this.data.pick_point; arr[idx].phone = e.detail.value; this.setData({ pick_point: arr }) }, inputPickRemarks(e) { // console.log(e); let idx = e.currentTarget.dataset.index; let arr = this.data.pick_point; arr[idx].remarks = e.detail.value; this.setData({ pick_point: arr }) }, // 修改背景图片 modifyBackgroundImage() { this.setData({ showPreviewImage: !this.data.showPreviewImage }) }, // 修改封面图片 modifyCoverImage() { this.setData({ showPreviewImage2: !this.data.showPreviewImage2 }) }, // 打开更换图片菜单动作面板 openPreviewImageMenus() { this.setData({ showPreviewImageMenus: true }) }, // 打开更换图片菜单动作面板2 openPreviewImageMenus2() { this.setData({ showPreviewImageMenus2: true }) }, // 关闭更换图片菜单动作面板 closePreviewImageMenus() { this.setData({ showPreviewImageMenus: false }) }, // 关闭更换图片菜单动作面板2 closePreviewImageMenus2() { this.setData({ showPreviewImageMenus2: false }) }, // 点击更换图片菜单动作面板 selectPreviewImageMenus(e) { let that = this; console.log(e); this.setData({ showPreviewImageMenus: false }) if (e.detail.name === '拍照') { wx.chooseImage({ count: 1, sourceType: ['camera'], success(res) { console.log(res); wx.editImage({ src: res.tempFilePaths[0], // 图片路径 success(result) { console.log(result); // wx.showLoading({ // title: '文件上传中', // mask: true // }) wx.request({ url: api.getSignedUrl, data: { type: 'image' }, success: (oss) => { console.log(oss); let key = "image/" + new Date().getTime() + Math.floor(Math.random() * 150) + '.png'; wx.showLoading({ title: '文件上传中', mask: true }) wx.uploadFile({ filePath: result.tempFilePath, name: 'file', url: 'https://' + oss.data.data.host, formData: { key: key, policy: oss.data.data.policy, // 输入你获取的的policy OSSAccessKeyId: oss.data.data.OSSAccessKeyId, // 输入你的AccessKeyId success_action_status: '200', // 让服务端返回200,不然,默认会返回204 signature: oss.data.data.Signature, // 输入你获取的的signature }, success: (res) => { if (res.statusCode == 200) { let src = 'https://' + oss.data.data.host + '/' + key; console.log(src); that.setData({ previewImageURL: src, showPreviewImage: false }) } }, fail: (err) => { console.log(err); }, complete: () => { wx.hideLoading() } }) }, fail: (err) => { console.log(err); } }) }, fail(error) { console.log(error); } }) }, fail(err) { console.log(err); } }) } else if (e.detail.name === '相册') { wx.chooseImage({ count: 1, sourceType: ['album'], success(res) { console.log(res); wx.editImage({ src: res.tempFilePaths[0], // 图片路径 success(result) { console.log(result); // wx.showLoading({ // title: '文件上传中', // mask: true // }) wx.request({ url: api.getSignedUrl, data: { type: 'image' }, success: (oss) => { console.log(oss); let key = "image/" + new Date().getTime() + Math.floor(Math.random() * 150) + '.png'; wx.showLoading({ title: '文件上传中', mask: true }) wx.uploadFile({ filePath: result.tempFilePath, name: 'file', url: 'https://' + oss.data.data.host, formData: { key: key, policy: oss.data.data.policy, // 输入你获取的的policy OSSAccessKeyId: oss.data.data.OSSAccessKeyId, // 输入你的AccessKeyId success_action_status: '200', // 让服务端返回200,不然,默认会返回204 signature: oss.data.data.Signature, // 输入你获取的的signature }, success: (res) => { if (res.statusCode == 200) { let src = 'https://' + oss.data.data.host + '/' + key; console.log(src); that.setData({ previewImageURL: src, showPreviewImage: false }) } }, fail: (err) => { console.log(err); }, complete: () => { wx.hideLoading() } }) }, fail: (err) => { console.log(err); } }) }, fail(error) { console.log(error); } }) }, fail(err) { console.log(err); } }) } }, // 点击更换图片菜单动作面板2 selectPreviewImageMenus2(e) { let that = this; console.log(e); this.setData({ showPreviewImageMenus2: false }) if (e.detail.name === '拍照') { wx.chooseImage({ count: 1, sourceType: ['camera'], success(res) { console.log(res); wx.editImage({ src: res.tempFilePaths[0], // 图片路径 success(result) { console.log(result); // wx.showLoading({ // title: '文件上传中', // mask: true // }) wx.request({ url: api.getSignedUrl, data: { type: 'image' }, success: (oss) => { console.log(oss); let key = "image/" + new Date().getTime() + Math.floor(Math.random() * 150) + '.png'; wx.showLoading({ title: '文件上传中', mask: true }) wx.uploadFile({ filePath: result.tempFilePath, name: 'file', url: 'https://' + oss.data.data.host, formData: { key: key, policy: oss.data.data.policy, // 输入你获取的的policy OSSAccessKeyId: oss.data.data.OSSAccessKeyId, // 输入你的AccessKeyId success_action_status: '200', // 让服务端返回200,不然,默认会返回204 signature: oss.data.data.Signature, // 输入你获取的的signature }, success: (res) => { if (res.statusCode == 200) { let src = 'https://' + oss.data.data.host + '/' + key; console.log(src); that.setData({ previewImageURL2: src, showPreviewImage2: false }) } }, fail: (err) => { console.log(err); }, complete: () => { wx.hideLoading() } }) }, fail: (err) => { console.log(err); } }) }, fail(error) { console.log(error); } }) }, fail(err) { console.log(err); } }) } else if (e.detail.name === '相册') { wx.chooseImage({ count: 1, sourceType: ['album'], success(res) { console.log(res); wx.editImage({ src: res.tempFilePaths[0], // 图片路径 success(result) { console.log(result); // wx.showLoading({ // title: '文件上传中', // mask: true // }) wx.request({ url: api.getSignedUrl, data: { type: 'image' }, success: (oss) => { console.log(oss); let key = "image/" + new Date().getTime() + Math.floor(Math.random() * 150) + '.png'; wx.showLoading({ title: '文件上传中', mask: true }) wx.uploadFile({ filePath: result.tempFilePath, name: 'file', url: 'https://' + oss.data.data.host, formData: { key: key, policy: oss.data.data.policy, // 输入你获取的的policy OSSAccessKeyId: oss.data.data.OSSAccessKeyId, // 输入你的AccessKeyId success_action_status: '200', // 让服务端返回200,不然,默认会返回204 signature: oss.data.data.Signature, // 输入你获取的的signature }, success: (res) => { if (res.statusCode == 200) { let src = 'https://' + oss.data.data.host + '/' + key; console.log(src); that.setData({ previewImageURL2: src, showPreviewImage2: false }) } }, fail: (err) => { console.log(err); }, complete: () => { wx.hideLoading() } }) }, fail: (err) => { console.log(err); } }) }, fail(error) { console.log(error); } }) }, fail(err) { console.log(err); } }) } }, changeIsOpenWXPay(e) { this.setData({ wechat_payment: e.detail }) }, changeIsAllowSearch(e) { this.setData({ search: e.detail }) }, changeIsShowList(e) { this.setData({ show_list: e.detail }) }, changeIsAllowComment(e) { this.setData({ comment: e.detail }) }, changeIsSellerForwarding(e) { this.setData({ seller_forwarding: e.detail }) }, changeIsReceivingInformation(e) { this.setData({ receiving_information: e.detail }) }, // 确认发布 submit() { let that = this; // 拼团名称 let gang_name = that.data.groupName; // 拼团简介 let gang_describe = that.data.groupDesc; // 拼团大图 let gang_big_img = that.data.bigImageList[0]; // 拼团小图 let gang_small_img = ''; for (let i = 0; i < that.data.smallImageList.length; i++) { gang_small_img = gang_small_img + that.data.smallImageList[i] + '|' } gang_small_img = gang_small_img.slice(0, gang_small_img.length - 1); // 拼团视频 let gang_video = that.data.videoList[0]; // 拼团开团时间 let opening_time = that.data.startTuanTime; // 拼团闭团时间 let closing_time = that.data.endTuanTime; // 物流方式(0没有物流,1取货点自提,2送货或者自提) let logistics_mode = that.data.logistics_mode; // 自提点 let pick_point = that.data.pick_point; // 预计到货时间 let expected_arrival_time = that.data.daoHuoTime; // 拼团主页背景图 let background_img = that.data.previewImageURL; // 转发封面图 let cover_img = that.data.previewImageURL2; // 是否开启微信支付 let wechat_payment = that.data.wechat_payment; // 是否允许搜索 let search = that.data.search; // 是否在拼团中展示订单列表 let show_list = that.data.show_list; // 是否允许评论 let comment = that.data.comment; // 仅卖家可转发 let seller_forwarding = that.data.seller_forwarding; // 是否允许发货前买家可修改收货信息 let receiving_information = that.data.receiving_information; // 商品ID let commodity_id_array = []; for (let i = 0; i < that.data.mockData.length; i++) { if (that.data.mockData[i].id) { commodity_id_array.push(that.data.mockData[i].id) } if (that.data.mockData[i].commodity_id) { commodity_id_array.push(that.data.mockData[i].commodity_id) } } /* 必录校验-开始 */ // console.log(gang_name); //拼团名称 // console.log(gang_describe); // 拼团简介 // console.log(gang_big_img); // 拼团大图 // console.log(gang_small_img); // 拼团小图 // console.log(gang_video); // 拼团视频 // console.log(opening_time); // 拼团开团时间 // console.log(closing_time); // 拼团闭团时间 // console.log(logistics_mode); // 物流方式 // console.log(pick_point); // 自提点 // console.log(expected_arrival_time); // 预计到货时间 // console.log(background_img); // 拼团主页背景图 // console.log(cover_img); //转发封面图 // console.log(wechat_payment); //是否开启微信支付 // console.log(search); //是否允许搜索 // console.log(show_list); //是否在拼团中展示订单列表 // console.log(comment); //是否允许评论 // console.log(seller_forwarding); //仅卖家可转发 // console.log(receiving_information); //是否允许发货前买家可修改收货信息 // console.log(commodity_id_array); // 商品ID if (gang_name == '') { wx.showToast({ title: '拼团名称未录入', icon: 'none', mask: true }) return } if (gang_describe == '') { wx.showToast({ title: '拼团简介未录入', icon: 'none', mask: true }) return } /* if (that.data.bigImageList.length == 0) { wx.showToast({ title: '拼团大图未录入', icon: 'none', mask: true }) return } */ /* if (gang_small_img == '') { wx.showToast({ title: '拼团小图未录入', icon: 'none', mask: true }) return } */ /* if (that.data.videoList.length == 0) { wx.showToast({ title: '拼团视频未录入', icon: 'none', mask: true }) return } */ if (opening_time == '') { wx.showToast({ title: '拼团开团时间未录入', icon: 'none', mask: true }) return } if (closing_time == '') { wx.showToast({ title: '拼团闭团时间未录入', icon: 'none', mask: true }) return } if (pick_point.length == 0 && that.data.type != 'edit') { wx.showToast({ title: '自提点未录入', icon: 'none', mask: true }) return } // if (expected_arrival_time == '') { // wx.showToast({ // title: '预计到货时间未录入', // icon: 'none', // mask: true // }) // return // } if (commodity_id_array.length == 0) { wx.showToast({ title: '拼团商品未录入', icon: 'none', mask: true }) return } /* 必录校验-结束 */ // return; // 开始提交 wx.showLoading({ title: '提交中', mask: true }) if (that.data.type == 'edit') { console.log({ id: that.data.id, gang_name: gang_name, gang_describe: gang_describe, gang_big_img: gang_big_img, gang_small_img: gang_small_img, gang_video: gang_video, opening_time: opening_time, closing_time: closing_time, logistics_mode: logistics_mode, expected_arrival_time: expected_arrival_time, background_img: background_img, cover_img: cover_img, wechat_payment: wechat_payment, search: search, show_list: show_list, comment: comment, seller_forwarding: seller_forwarding, receiving_information: receiving_information },) wx.request({ url: api.Gang_edit, header: { 'Authorization': wx.getStorageSync('token') }, method: 'POST', data: { id: that.data.id, gang_name: gang_name, gang_describe: gang_describe, gang_big_img: gang_big_img, gang_small_img: gang_small_img, gang_video: gang_video, opening_time: opening_time, closing_time: closing_time, logistics_mode: logistics_mode, expected_arrival_time: expected_arrival_time, background_img: background_img, cover_img: cover_img, wechat_payment: wechat_payment, search: search, show_list: show_list, comment: comment, seller_forwarding: seller_forwarding, receiving_information: receiving_information }, success(res) { console.log(res); wx.hideLoading() if (res.data.code === 1) { wx.showToast({ title: '提交成功', icon: 'success', mask: true, success() { setTimeout(() => { wx.reLaunch({ url: '/pages/pintuanmanage/pintuanmanage', }) }, 1500) } }) } else { wx.showToast({ title: res.data.msg, mask: true, icon: 'none', duration: 2000, success() { setTimeout(() => { if (res.data.msg === '请先进行个人认证') { wx.navigateTo({ url: '/pages/phonenumber/phonenumber', }) } }, 2000) } }) } }, fail(err) { wx.hideLoading() wx.showToast({ title: '发起网络请求失败', icon: 'none', mask: true }) }, complete() { // wx.hideLoading() } }) } else { wx.request({ url: api.Gang_add, header: { 'Authorization': wx.getStorageSync('token') }, method: 'POST', data: { gang_name: gang_name, gang_describe: gang_describe, gang_big_img: gang_big_img, gang_small_img: gang_small_img, gang_video: gang_video, opening_time: opening_time, closing_time: closing_time, logistics_mode: logistics_mode, pick_point: pick_point, expected_arrival_time: expected_arrival_time, background_img: background_img, cover_img: cover_img, wechat_payment: wechat_payment, search: search, show_list: show_list, comment: comment, seller_forwarding: seller_forwarding, receiving_information: receiving_information, commodity_id_array: commodity_id_array }, success(res) { console.log(res); wx.hideLoading() if (res.data.code === 1) { wx.showToast({ title: '提交成功', icon: 'success', mask: true, success() { setTimeout(() => { wx.reLaunch({ url: '/pages/publish/publish', }) }, 1500) } }) } else { wx.showToast({ title: res.data.msg, mask: true, icon: 'none', duration: 2000, success() { setTimeout(() => { if (res.data.msg === '请先进行个人认证') { wx.navigateTo({ url: '/pages/phonenumber/phonenumber', }) } }, 2000) } }) } }, fail(err) { wx.hideLoading() wx.showToast({ title: '发起网络请求失败', icon: 'none', mask: true }) }, complete() { // wx.hideLoading() } }) } }, // 获取微信支付手续费 getWXPayServiceCharge() { let that = this; wx.showLoading({ title: '加载中', mask: true }) wx.request({ url: api.Service, header: { 'Authorization': wx.getStorageSync('token') }, method: 'POST', success(res) { wx.hideLoading() that.setData({ wxpayservice: res.data.data * 100 }) }, fail(err) { wx.hideLoading() } }) }, })