yuminge-app/yun-min-program-plugin-master/packageC/o2o/createGroup/createGroup.js

1054 lines
27 KiB
JavaScript

// packageC/o2o/createGroup/createGroup.js
var app = getApp();
import uitil from '../../../utils/util.js';
Page({
/**
* 页面的初始数据
*/
data: {
isLoadMore: true,
page: 1,
total_page: 0,
id: 0,
store_id: 0,
disableds: false,
titleText: '创建活动',
kwd: "",
show: false,
showSearchGood: false,
listOne: [],
start_time: "",
end_time: "",
cat_level: 2, //分类等级 2级或者3级
category1: 0,
category2: 0,
category1_disabled: false,
category2_disabled: true,
categoryOption1: [{
text: "不限分类",
value: 0
}],
categoryOption2: [{
text: "不限分类",
value: 0,
child: []
}],
activeCategoryID: "",
minDate: new Date().getTime(),
showStartTime: false,
currentStartTime: "",
showEndTime: false,
currentEndTime: "",
goodradio: "",
tab: "all",
new_url: false, //新增活动弹出框
step: 1, //下一步
has_option: 0, //是否开启规格
search_form: {},
search_goods: {},
category_list: [],
goods_list: [],
list: [],
keywords: '',
form: {},
fight_groups_lottery_set: '',
data: '',
// has_many_options:has_many_options,//规格
has_one_goods: '', //回显商品信息
is_edit: '', //是否允许编辑
//商品分页
goods_total: 0,
goods_per_size: 0,
goods_current_page: 0,
// 优惠券
coupon_result: [],
coupon_show: false,
coupon_keyword: "",
coupon_list: [],
// choose_coupon_list:[],
// 爱心值
love_name: '',
loves: '',
is_open_integral: '',
//门店
store_show: false,
store_list: [],
store_keyword: "",
store_obj: '',
loading: false,
table_loading: false,
rules: {
title: {
required: true,
message: "请输入活动标题"
}
},
startPos: undefined
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (options.store_id) {
this.data.store_id = options.store_id;
}
if(options.id){
this.setData({
disableds: true
});
this.data.id = options.id;
this.editData();
}else{
this.initFun();
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
initFun(_editData) {
let _data = {
fight_groups_lottery: false,
keywords: {
share_title: ["\u62fc\u56e2\u6d3b\u52a8\u540d\u79f0", "\u5546\u54c1\u6700\u9ad8\u4ef7", "\u5546\u54c1\u6700\u4f4e\u4ef7"],
share_content: ["\u62fc\u56e2\u6d3b\u52a8\u540d\u79f0", "\u5546\u54c1\u6700\u9ad8\u4ef7", "\u5546\u54c1\u6700\u4f4e\u4ef7"],
desc_title: [
"\u56e2\u957f\u540d\u79f0",
"\u62fc\u56e2\u65f6\u95f4\u5012\u8ba1\u65f6",
"\u62fc\u56e2\u6d3b\u52a8\u540d\u79f0",
"\u5546\u54c1\u6700\u9ad8\u4ef7",
"\u5546\u54c1\u6700\u4f4e\u4ef7",
"\u62fc\u56e2\u4eba\u6570"
],
desc_content: [
"\u56e2\u957f\u540d\u79f0",
"\u62fc\u56e2\u65f6\u95f4\u5012\u8ba1\u65f6",
"\u62fc\u56e2\u6d3b\u52a8\u540d\u79f0",
"\u5546\u54c1\u6700\u9ad8\u4ef7",
"\u5546\u54c1\u6700\u4f4e\u4ef7",
"\u62fc\u56e2\u4eba\u6570"
]
},
loves: true,
love_name: "\u7231\u5fc3\u503c",
is_open_integral: false
};
let data = _editData ? _editData : _data;
let keywords = data.keywords;
let love_name = data.love_name ? data.love_name : "";
let loves = data.loves ? data.loves : false;
let fight_groups_lottery_set = data.fight_groups_lottery_set ? data.fight_groups_lottery_set : false;
let fight_groups_lottery_info = data.fight_groups_lottery_info ? data.fight_groups_lottery_info : {};
let is_open_integral = data.is_open_integral ? data.is_open_integral : false;
let store_obj = data.has_one_store_cashier ? data.has_one_store_cashier : {};
if (fight_groups_lottery_set.open_type == 1 && fight_groups_lottery_info.is_open == undefined) {
fight_groups_lottery_info.is_open = 1;
}
console.log(fight_groups_lottery_info.is_separate_rules);
let form = {
goods_id: "",
goods_name: "",
is_lead: 0,
barrage: 0,
hide_num: "1",
setting: "",
share_title: "原价¥<<商品最高价>>,现价¥<<商品最低价>>起,参加<<拼团活动名称>>即可享受",
share_content: "活动商品数量有限,先到先得。",
desc_title: "我已经参加了<<团长名称>>发起的拼团。",
desc_content: "凑足<<拼团人数>>人即可享受拼团优惠,我已经参加,你也来吧。",
has_many_level: [],
has_many_options: [], //规格
is_love: 0,
love: "",
is_balance: 0,
balance: "",
is_coupon: 0,
fight_groups_lottery_info: fight_groups_lottery_info,
coupon: [], //优惠券
business_type: 1,
store_id: this.data.store_id,
start_time: '',
end_time: '',
...data
};
let has_one_goods = {};
let is_edit = false;
if (form.id) {
if (form.start_time) {
form.start_time = parseInt(form.start_time * 1000);
}
if (form.end_time) {
form.end_time = parseInt(form.end_time * 1000);
}
has_one_goods = {
...form.has_one_goods
};
if (form.status == 1 || form.status == 0) {
is_edit = true;
}
}
this.setData({
keywords: keywords,
form: form,
fight_groups_lottery_set: fight_groups_lottery_set,
data: data,
has_one_goods: has_one_goods,
is_edit: is_edit,
love_name: love_name,
loves: loves,
is_open_integral: is_open_integral,
store_obj: store_obj
});
},
showTextPopup(){
wx.showModal({
title: '提示',
showCancel: false,
content: '勾选此选项则手机端商品详情页底部仅展示“去参团”,不展示“一键开团”',
success (res) {
if (res.confirm) {
console.log('用户点击确定');
}
}
});
},
showTextPopup1(){
wx.showModal({
title: '提示',
showCancel: false,
content: '参与过该活动一次的视为老用户,老用户只允许开团不允许参团。此场景适合设置特价商品,用于鼓励老用户开团,协助店铺拉新。',
success (res) {
if (res.confirm) {
console.log('用户点击确定');
}
}
});
},
editData() {
//获取活动数据
let that = this;
let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.edit");
app._getNetWork({
url: urlStr,
data: {
store_id: that.data.store_id,
id: that.data.id
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.initFun(res.data);
that.setData({
start_time: uitil.formatTimeTwo(res.data.start_time, 'Y/M/D h:m:s'),
currentStartTime: res.data.start_time*1000,
currentEndTime: res.data.end_time*1000
});
if(res.data.end_time){
that.setData({
end_time: uitil.formatTimeTwo(res.data.end_time, 'Y/M/D h:m:s')
});
}
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 1000
});
}
},
fail: function (res) {
console.log(res);
}
});
},
onChangetitle(event) {
this.data.form.title = event.detail;
},
getCategoryOne() {
if (this.data.disableds) {
return;
}
if (this.data.listOne.length > 0) {
this.setData({
showSearchGood: true
});
return;
}
//获取一级分类列表
let that = this;
let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.get-category");
app._getNetWork({
url: urlStr,
data: {
store_id: that.data.store_id
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
let category1_list = res.data;
let categoryOption1 = that.data.categoryOption1;
if (category1_list.length > 0) {
category1_list.forEach((val, index) => {
categoryOption1.push({
text: val.name,
value: val.id
});
});
that.getChildCate(1, "", false);
}
that.setData({
categoryOption1,
showSearchGood: true
});
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 1000
});
}
},
fail: function (res) {
console.log(res);
}
});
},
onChangeCate(e) {
this.setData({
kwd: e.detail,
});
},
getChildCate() {
let that = this;
let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.search-goods");
app._getNetWork({
url: urlStr,
data: {
store_id: that.data.store_id,
category: that.data.activeCategoryID,
goods_name: that.data.kwd,
page: that.data.page
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
listOne: res.data.data,
isLoadMore: res.data.last_page > 1?true:false,
total_page: res.data.last_page
});
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 1000
});
}
},
fail: function (res) {
console.log(res);
}
});
},
getMore(){
this.data.page +=1;
let that = this;
let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.search-goods");
app._getNetWork({
url: urlStr,
data: {
store_id: that.data.store_id,
category: that.data.activeCategoryID,
goods_name: that.data.kwd,
page: that.data.page
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
let listOne = that.data.listOne.concat(res.data.data);
that.setData({
listOne: listOne,
isLoadMore: that.data.page >= res.data.total_page ?false:true
});
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 1000
});
}
},
fail: function (res) {
console.log(res);
}
});
},
cloneSearchGood() {
this.setData({
showSearchGood: false
});
},
selectCate1({ detail }) {
//一级分类发生变化触发
this.data.kwd = "";
if (detail) {
this.data.activeCategoryID = detail;
this.getCategorytwo(detail, true);
this.getChildCate();
} else {
console.log("不限一级分类");
this.initData();
this.data.activeCategoryID = "";
this.getChildCate();
}
},
selectCate2({ detail }) {
//二级分类发生变化触发
if (detail) {
this.data.activeCategoryID = detail;
this.getChildCate();
} else {
console.log("不限二级分类");
this.data.activeCategoryID = this.data.category1;
this.getChildCate();
}
},
getCategorytwo(_cid, _open) {
//获取一级分类的下级分类列表(二级三级)
let that = this;
let categoryOption2 = [{
text: "不限分类",
value: 0,
child: []
}];
this.setData({
categoryOption2,
category2: 0,
category2_disabled: true
});
if (_cid == 0) {
return;
}
let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.get-category-json");
app._getNetWork({
url: urlStr,
data: {
store_id: that.data.store_id,
parent_id: _cid,
level: 2
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
let category2_list = response.data;
let categoryOption2 = that.data.categoryOption2;
if (category2_list.length > 0) {
category2_list.forEach((val, index) => {
categoryOption2.push({
text: val.name,
value: val.id
});
});
that.setData({
categoryOption2,
});
if (_open) {
that.setData({
category2_disabled: false
});
that.selectComponent('#categoryShow2').toggle();
}
}
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 1000
});
}
},
fail: function (res) {
console.log(res);
}
});
},
initData() {
this.setData({
kwd: '',
isLoadMore: true,
page: 1,
total_page: 0,
listOne: [],
cat_level: 2,
category1: 0,
category2: 0,
category1_disabled: false,
category2_disabled: true,
categoryOption2: [{
text: "不限分类",
value: 0,
child: []
}]
});
},
clickGoodRadio(e) {
let data = e.currentTarget.dataset.item;
let index = e.currentTarget.dataset.index;
if(data.has_many_activity_goods_count >= 1){
return;
}
this.setData({
goodradio: index,
['has_one_goods.title']: data.title,
['has_one_goods.id']: data.id,
['has_one_goods.thumb']: data.thumb,
['has_one_goods.price']: data.price,
['has_one_goods.stock']: data.stock,
['has_one_goods.sku']: data.sku,
});
this.data.new_url = false;
this.data.has_option = data.has_option; //是否开启规格
if (this.data.has_option) {
this.setData({
['form.has_many_options']: data.has_many_options //规格
});
} else {
this.setData({
['form.has_many_options']: []
});
}
// 规格价格数据处理
// if(this.form.has_many_options.length>0) {
if (this.data.has_option) {
this.data.form.has_many_options.forEach((item, index) => {
this.data.form.has_many_options[index].option_price = item.product_price;
this.data.form.has_many_options[index].option_id = item.id;
this.data.form.has_many_options[index].option_title = item.title;
this.data.form.has_many_options[index].has_many_option_level = [];
this.data.form.has_many_options[index].buy_limit = "0";
this.data.form.has_many_options[index].stock = item.stock;
});
} else {
this.data.form.has_many_options.push({
option_title: "单规格",
option_price: data.price,
stock: data.stock,
buy_limit: "0",
has_many_option_level: []
});
}
console.log(this.data.form.has_many_options);
let form = this.data.form;
this.setData({
form,
['form.goods_id']: this.data.has_one_goods.id,
['form.goods_name']: this.data.has_one_goods.title,
showSearchGood: false
});
},
showTime(e) {
let tag = e.currentTarget.dataset.index;
if (this.data.disableds) {
return;
}
if (tag == 1) {
this.setData({
showStartTime: true
});
}
if (tag == 2) {
this.setData({
showEndTime: true
});
}
},
confirmStartTime(value) {
this.setData({
showStartTime: false,
start_time: uitil.formatTimeTwo(value.detail / 1000, 'Y/M/D h:m:s'),
['form.start_time']: parseInt(value.detail / 1000)
});
},
confirmEndtTime(value) {
this.setData({
showEndTime: false,
end_time: uitil.formatTimeTwo(value.detail / 1000, 'Y/M/D h:m:s'),
['form.end_time']: parseInt(value.detail / 1000)
});
},
cancelStartTime() {
this.setData({
showStartTime: false,
start_time: '',
['form.start_time']: ''
});
},
cancelEndtTime() {
this.setData({
showEndTime: false,
end_time: '',
['form.end_time']: ''
});
},
// 新增层级
addTier() {
if (this.data.form.has_many_level.length >= 3) {
wx.showToast({
title: '最多可设置3个阶梯',
icon: 'none',
duration: 1000
});
return;
}
let has_many_level = this.data.form.has_many_level;
has_many_level.push({
level_num: this.data.form.has_many_level.length + 1,
member_num: "",
expire_in: ""
});
this.setData({
['form.has_many_level']: has_many_level
});
},
delTier(e) {
let index = e.currentTarget.dataset.index;
let has_many_level = this.data.form.has_many_level;
has_many_level.splice(index, 1);
// 层级重新排序
has_many_level.forEach((item, index1) => {
item.level_num = index1 + 1;
});
this.setData({
['form.has_many_level']: has_many_level
});
},
changeLevelInput(e) {
//修改层级信息
let index = e.currentTarget.dataset.index;
let tag = e.currentTarget.dataset.tag;
if (tag == 'member_num') {
this.setData({
['form.has_many_level[' + index + '].member_num']: e.detail.value
});
} else {
this.setData({
['form.has_many_level[' + index + '].expire_in']: e.detail.value
});
}
},
onChangeMenu(event) {
this.setData({
['form.menu_show']: event.detail
});
},
inputHideNum(event) {
this.setData({
['form.hide_num']: event.detail
});
},
onChangeCoupon(event) {
this.setData({
['form.is_coupon']: event.detail
});
},
// 打开选择优惠券
openCoupon() {
this.searchCoupon(1);
},
onChangeCouInput(e) {
this.setData({
coupon_keyword: e.detail,
});
},
// 搜索优惠券
searchCoupon(tag) {
var that = this;
if (tag==1&&that.data.coupon_list.length > 0) {
this.setData({
coupon_show: true
});
return;
}
let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.coupon");
app._getNetWork({
url: urlStr,
data: {
store_id: that.data.store_id,
keyword: that.data.coupon_keyword
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
coupon_list: res.data,
coupon_show: true
});
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 1000
});
}
},
fail: function (res) {
console.log(res);
}
});
},
chooseCoupon(e) {
let item = e.currentTarget.dataset.item;
let index = e.currentTarget.dataset.index + '';
let is_true = true;
let that = this;
let coupon = this.data.form.coupon;
let coupon_result = that.data.coupon_result;
coupon.some((item1, index1) => {
if (item1.id == item.id) {
is_true = false;
coupon.splice(index1, 1);
coupon_result.splice(index, 1);
that.setData({
['form.coupon']: coupon,
coupon_result: coupon_result
});
return true;
}
});
if (is_true) {
coupon.push({
id: item.id,
name: item.name,
coupon_num: "1"
});
coupon_result.push(index);
that.setData({
['form.coupon']: coupon,
coupon_result: coupon_result
});
}
},
// 删除优惠券
delCoupon(e) {
let index = e.currentTarget.dataset.index;
this.data.form.coupon.splice(index, 1);
this.data.coupon_result.splice(index, 1);
this.setData({
['form.coupon']: this.data.form.coupon,
coupon_result: this.data.coupon_result
});
},
onCloneCoupon() {
this.setData({
coupon_show: false
});
},
changeCouponInput(e) {
//修改层级信息
let index = e.currentTarget.dataset.index;
this.setData({
['form.coupon[' + index + '].coupon_num']: e.detail.value
});
},
onChangeLead(event) {
this.setData({
['form.is_lead']: event.detail
});
},
inputLead(event) {
this.setData({
['form.setting']: event.detail
});
},
inputShare(event){
let tag = event.currentTarget.dataset.tag;
this.setData({
startPos: event.detail.cursor,
['form.'+tag]: event.detail.value
});
},
inputblurShare(event){
this.setData({
startPos: event.detail.cursor,
});
},
// 添加关键词
addContent(event) {
let name = event.currentTarget.dataset.name;
let index = event.currentTarget.dataset.index;
let x = event.currentTarget.dataset.num;
// console.log(name,this.selectComponent('#'+name));
// let ref = this.selectComponent('#'+name)
// this.$refs[name];
let words = "";
if (x == 1) {
words = "<<" + this.data.keywords.share_title[index] + ">>";
}
if (x == 2) {
words = "<<" + this.data.keywords.share_content[index] + ">>";
}
if (x == 3) {
words = "<<" + this.data.keywords.desc_title[index] + ">>";
}
if (x == 4) {
words = "<<" + this.data.keywords.desc_content[index] + ">>";
}
console.log(words);
setTimeout(() => {
this.insertInputTxt(name, words, x);
}, 200);
},
insertInputTxt(ref, words, x) {
// let name = "";
// name = this.selectComponent('#'+name).value;
var startPos = this.data.startPos;
var endPos = this.data.startPos;
var txt = this.data.form[ref];
// const query = wx.createSelectorQuery()
// // query.select('#share_title').focus()
// console.log('txttxttxttxttxttxttxt',query.select('#share_title'));
if (startPos === undefined || endPos === undefined) {
startPos = txt.length;
endPos= txt.length;
console.log('startPos==========',startPos);
}
var result = txt.substring(0, startPos) + words + txt.substring(endPos);
// name.value = result;
// name.focus();
// name.selectionStart = startPos + words.length;
// name.selectionEnd = startPos + words.length;
// console.log(name.value);
this.setData({
startPos:undefined,
['form.'+ref]: result
});
},
// 下一步
next() {
console.log(this.data.form);
if (!this.data.form.title) {
wx.showToast({
title: '活动标题不能为空!',
icon: 'none',
duration: 1000
});
return false;
}
if (!this.data.has_one_goods.title) {
wx.showToast({
title: '请选择活动商品!',
icon: 'none',
duration: 1000
});
return false;
}
if (this.data.form.has_many_level.length == 0) {
wx.showToast({
title: '层级不能为空!',
icon: 'none',
duration: 1000
});
return false;
}
if (!this.data.form.start_time) {
wx.showToast({
title: '开始时间不能为空!',
icon: 'none',
duration: 1000
});
return false;
}
if (this.data.form.end_time && this.data.form.start_time >= this.data.form.end_time) {
wx.showToast({
title: '开始时间不能大于或者等于结束时间!',
icon: 'none',
duration: 1000
});
return false;
}
if (this.data.form.menu_show == 1) {
if (this.data.form.hide_num < 1) {
wx.showToast({
title: '展示设置->可参的团数不能少于1',
icon: 'none',
duration: 1000
});
return false;
}
}
this.data.form.has_many_level.some(item => {
if (!item.member_num || !item.expire_in) {
wx.showToast({
title: '层级信息不完成!',
icon: 'none',
duration: 1000
});
return true;
} else if (item.member_num == 1) {
wx.showToast({
title: '拼团人数不能为1',
icon: 'none',
duration: 1000
});
return true;
} else {
this.setData({
step:2
});
}
console.log(this.data.step);
});
// 添加层级价格
if (!this.data.form.id) {
let has_many_options = this.data.form.has_many_options;
if (this.data.has_option) {
for (let i = 0; i < has_many_options.length; i++) {
has_many_options[i].has_many_option_level = [];
}
for (let i = 0; i < has_many_options.length; i++) {
for (let j = 0; j < this.data.form.has_many_level.length; j++) {
has_many_options[i].has_many_option_level.push({ group_price: "", member_num: this.data.form.has_many_level[j].member_num });
}
}
console.log(this.data.form);
} else {
has_many_options[0].has_many_option_level = [];
for (let j = 0; j < this.data.form.has_many_level.length; j++) {
has_many_options[0].has_many_option_level.push({ group_price: "0", member_num: this.data.form.has_many_level[j].member_num });
}
}
this.setData({
['form.has_many_options']: has_many_options
});
}
},
last() {
this.setData({
step:1
});
},
changeGroupPrice(event) {
let index = event.currentTarget.dataset.index;
let index1 = event.currentTarget.dataset.index1;
this.setData({
['form.has_many_options[' + index + '].has_many_option_level[' + index1 + '].group_price']: event.detail.value
});
},
changeStock(event) {
let index = event.currentTarget.dataset.index;
this.setData({
['form.has_many_options[' + index + '].stock']: event.detail.value
});
},
changeLimit(event) {
let index = event.currentTarget.dataset.index;
this.setData({
['form.has_many_options[' + index + '].buy_limit']: event.detail.value
});
},
submitForm() {
var that = this;
delete this.data.form.goods_name;
delete this.data.form.loves;
delete this.data.form.love_name;
//手机端创建门店拼团活动暂时没有拼团奖励对接 start
delete this.data.form.is_open_integral;
delete this.data.form.fight_groups_lottery;
delete this.data.form.fight_groups_lottery_info;
//手机端创建门店拼团活动暂时没有拼团奖励对接 end
console.log(this.data.form);
let urlStr = app.getNetAddresss("plugin.fight-groups.frontend.store.fight-groups-store.save");
app._postNetWork({
url: urlStr,
data: {
form_data: that.data.form
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
wx.navigateTo({
url: '/packageC/o2o/storeManage/storeManage'
});
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 1000
});
}
},
fail: function (res) {
console.log(res);
}
});
}
});