12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688 |
- 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()
- }
- })
- },
- })
|