...
|
...
|
@@ -4,6 +4,7 @@ require('bootstrap-daterangepicker'); |
|
|
const _ = require('lodash');
|
|
|
const $alert = $('#alert-modal');
|
|
|
const $confirm = $('#confirm-modal');
|
|
|
const $yohoodConfirm = $('#yohood-confirm-model');
|
|
|
|
|
|
$alert.showMsg = function(msg) {
|
|
|
this.find('.modal-text').text(msg);
|
...
|
...
|
@@ -13,6 +14,7 @@ $alert.showMsg = function(msg) { |
|
|
function bindListPageEvent() {
|
|
|
const $searchKey = $('#search-key');
|
|
|
const $statusSwitch = $('#status-switch');
|
|
|
const $channelSwitch = $('#channel-switch');
|
|
|
const $publishForm = $('#publish-form');
|
|
|
const $noticeModal = $('#notice-modal');
|
|
|
const $noticeForm = $noticeModal.find('#notice-form');
|
...
|
...
|
@@ -20,15 +22,23 @@ function bindListPageEvent() { |
|
|
const searchFn = function() {
|
|
|
let val = $searchKey.val();
|
|
|
let status = $statusSwitch.data('status');
|
|
|
let channel = $channelSwitch.data('channel');
|
|
|
|
|
|
let qs = [];
|
|
|
|
|
|
if (val) {
|
|
|
qs.push(val ? 'query=' + val : '');
|
|
|
}
|
|
|
if (status === '' || _.isNumber(+status)) {
|
|
|
if (status >= 0) {
|
|
|
qs.push(`status=${status}`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!_.isNaN(+status)) {
|
|
|
qs.push('status=' + status);
|
|
|
if (channel === '' || _.isNumber(+channel)) {
|
|
|
if (channel >= 0) {
|
|
|
qs.push(`channel=${channel}`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
location.href = `?${qs.join('&')}`;
|
...
|
...
|
@@ -40,6 +50,13 @@ function bindListPageEvent() { |
|
|
$statusSwitch.data('status', $this.data('status')).children('.btn-text').text($this.text());
|
|
|
};
|
|
|
|
|
|
// 渠道
|
|
|
const channelFn = function() {
|
|
|
let $this = $(this);
|
|
|
|
|
|
$channelSwitch.data('channel', $this.data('channel')).children('.btn-text').text($this.text());
|
|
|
};
|
|
|
|
|
|
const editFn = function() {
|
|
|
window.open('/admin/activity/zerobuy/edit?id=' +
|
|
|
$(this).data('id'), '_blank');
|
...
|
...
|
@@ -198,18 +215,30 @@ function bindListPageEvent() { |
|
|
|
|
|
$('#search-btn').on('click', searchFn);
|
|
|
$('.status-switch').on('click', statusFn);
|
|
|
|
|
|
$('.channel-switch').on('click', channelFn);
|
|
|
|
|
|
$('.btn-edit').on('click', editFn);
|
|
|
$('.btn-switch-open').on('click', switchFn);
|
|
|
$('.btn-switch-close').on('click', switchFn);
|
|
|
$('.btn-export').on('click', exportFn);
|
|
|
$('.btn-publish').on('click', function() {
|
|
|
$('input', $confirm).val('');
|
|
|
$('select', $confirm).val(0).change();
|
|
|
|
|
|
$confirm.data('id', $(this).data('id'));
|
|
|
$confirm.data('channel', $(this).data('channel'));
|
|
|
$confirm.modal('show');
|
|
|
// CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
|
|
|
const channel = $(this).data('channel');
|
|
|
|
|
|
if (+channel === 2) {
|
|
|
$('input', $yohoodConfirm).val('');
|
|
|
$('.error-message').text('');
|
|
|
$yohoodConfirm.modal('show');
|
|
|
$yohoodConfirm.data('id', $(this).data('id'));
|
|
|
$yohoodConfirm.data('channel', channel);
|
|
|
} else {
|
|
|
$('input', $confirm).val('');
|
|
|
$('select', $confirm).val(0).change();
|
|
|
$confirm.modal('show');
|
|
|
$confirm.data('id', $(this).data('id'));
|
|
|
$confirm.data('channel', channel);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
$('.btn-notice').on('click', function() {
|
|
|
let notice = $(this).parent().data('notice') || {};
|
...
|
...
|
@@ -233,6 +262,33 @@ function bindListPageEvent() { |
|
|
|
|
|
$('.sure-publish-btn').on('click', publishFn);
|
|
|
$('.sure-notice-btn').on('click', noticeFn);
|
|
|
$('.sure-yohood-publish-btn').on('click', function() {
|
|
|
const code = $('input[name="price-code"]', $yohoodConfirm).val();
|
|
|
|
|
|
if (code) {
|
|
|
$.ajax({
|
|
|
method: 'post',
|
|
|
url: '/admin/activity/yohood/publish',
|
|
|
data: {
|
|
|
id: $yohoodConfirm.data('id'),
|
|
|
channel: $yohoodConfirm.data('channel'),
|
|
|
code,
|
|
|
}
|
|
|
}).then(res=> {
|
|
|
if (res.code === 200) {
|
|
|
$('.error-message').text('');
|
|
|
$yohoodConfirm.modal('hide');
|
|
|
$alert.find('.modal-text').text('开奖成功,已提醒用户领奖');
|
|
|
$alert.modal('show');
|
|
|
$alert.on('hide.bs.modal', function() {
|
|
|
location.reload();
|
|
|
});
|
|
|
} else {
|
|
|
$('.error-message').text(res.message);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('.notice-btn-select').change(noticeBtnTypeChangeFn);
|
|
|
}
|
...
|
...
|
@@ -303,9 +359,47 @@ function generateCid(id) { |
|
|
return Math.floor(Date.now() + Math.random() * 10000000000 * (id + 1));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取yohood活动时间列表,用于判断活动时间是否重叠
|
|
|
*/
|
|
|
function YOHOODActivityApiGenerator() {
|
|
|
let isFetch = false;
|
|
|
let yohoodActivityTimeList = [];
|
|
|
|
|
|
function fetchTimeList() {
|
|
|
if (isFetch) {
|
|
|
return;
|
|
|
}
|
|
|
$.ajax({
|
|
|
method: 'get',
|
|
|
url: '/admin/activity/yohood/times',
|
|
|
}).then(function(res) {
|
|
|
isFetch = true;
|
|
|
yohoodActivityTimeList = res || [];
|
|
|
}).catch(()=> {
|
|
|
alert('获取yohood活动时间列表失败');
|
|
|
});
|
|
|
}
|
|
|
return {
|
|
|
fetchTimeList,
|
|
|
getList: function() {
|
|
|
return yohoodActivityTimeList;
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function bindEditPageEvent() {
|
|
|
initUpload();
|
|
|
|
|
|
// 获取yohood活动时间列表
|
|
|
const id = $('input[data-type="id"]').val();
|
|
|
const channel = $('select[name="actChannel"]').val();
|
|
|
const yohoodApi = YOHOODActivityApiGenerator();
|
|
|
|
|
|
if (!!id && +channel === 2) {
|
|
|
yohoodApi.fetchTimeList();
|
|
|
}
|
|
|
|
|
|
let $floorBox = $('.floor-view-box');
|
|
|
let floorContent = {};
|
|
|
const typeName = {
|
...
|
...
|
@@ -324,16 +418,62 @@ function bindEditPageEvent() { |
|
|
let resData = {};
|
|
|
let error;
|
|
|
|
|
|
/**
|
|
|
* 选择“YOHOOD渠道”带出如下字段:
|
|
|
* 商品名称(现有)、商品图⽚片(现 有)、抽奖价(新增)、商品价格(现有)、
|
|
|
* 活动有效时间(YOHOOD活动创建 提交时不不可以重叠,其他渠道不不影响),
|
|
|
* 排序(隐藏,默认为0)、详情内容 (隐藏,不不需要填写);
|
|
|
* CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
|
|
|
*/
|
|
|
const selectedChannel = $('select[name="actChannel"]').val();
|
|
|
|
|
|
$('.form-imput').each(function() {
|
|
|
let $this = $(this);
|
|
|
let val = $this.val();
|
|
|
let data = $this.data();
|
|
|
|
|
|
if (!val && !error && data.type !== 'id') {
|
|
|
error = data.empty || `请填写${data.type}`;
|
|
|
}
|
|
|
if (+selectedChannel === 2) {
|
|
|
if (data.type !== 'sort') {
|
|
|
error = data.empty || `请填写${data.type}`;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
if (data.type !== 'lotteryPrice') {
|
|
|
error = data.empty || `请填写${data.type}`;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
resData[data.type] = val;
|
|
|
}
|
|
|
if (+selectedChannel === 2) {
|
|
|
if (data.type !== 'sort') {
|
|
|
resData[data.type] = val;
|
|
|
}
|
|
|
if (data.type === 'time') {
|
|
|
const [startTime, endTime] = val.split(' - ');
|
|
|
const startTimeInSeconds = new Date(startTime).getTime() / 1000;
|
|
|
const endTimeInSeconds = new Date(endTime).getTime() / 1000;
|
|
|
|
|
|
// 时间段不能重叠
|
|
|
for (const timeInfo of yohoodApi.getList()) {
|
|
|
const {startTime: st, endTime: et, id: actId} = timeInfo;
|
|
|
|
|
|
if (+id !== +actId) {
|
|
|
if (startTimeInSeconds >= st && startTimeInSeconds <= et ||
|
|
|
endTimeInSeconds >= st && endTimeInSeconds <= et ||
|
|
|
startTimeInSeconds <= st && endTimeInSeconds >= et) {
|
|
|
error = new Error('YOHOOD活动时间重叠');
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (data.type !== 'lotteryPrice') {
|
|
|
resData[data.type] = val;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (error) {
|
...
|
...
|
@@ -447,7 +587,7 @@ function bindEditPageEvent() { |
|
|
if (typeof ($.fn.daterangepicker) !== 'undefined') {
|
|
|
$('#activityTime').daterangepicker({
|
|
|
timePicker: true,
|
|
|
timePickerIncrement: 30,
|
|
|
timePickerIncrement: 5,
|
|
|
locale: {
|
|
|
format: 'YYYY-MM-DD HH:mm:ss'
|
|
|
}
|
...
|
...
|
@@ -579,6 +719,22 @@ function bindEditPageEvent() { |
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
|
|
|
// YOHOOD渠道
|
|
|
$('select[name="actChannel"]').on('change', function(e) {
|
|
|
if (+e.target.value === 2) {
|
|
|
// 获取yohood活动时间列表
|
|
|
yohoodApi.fetchTimeList();
|
|
|
$('.content-detail').addClass('hide');
|
|
|
$('.sort').addClass('hide');
|
|
|
$('.lottery-price').removeClass('hide');
|
|
|
} else {
|
|
|
$('.content-detail').removeClass('hide');
|
|
|
$('.sort').removeClass('hide');
|
|
|
$('.lottery-price').addClass('hide');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if ($('.zerobuy-list-page').length) {
|
...
|
...
|
|