Authored by lijing

代码优化

... ... @@ -107,6 +107,7 @@ const store = (params) => {
if (result[2] && result[2].data) {
let build = [];
result[2].data.forEach(val => {
build.push({
img: val.thumbnailUrl,
... ... @@ -117,7 +118,6 @@ const store = (params) => {
resu.storeSon = build;
}
}
return resu;
});
};
... ... @@ -136,7 +136,6 @@ const articleDetail = (params) => {
if (result && result.data) {
resu = result.data;
}
return resu;
});
};
... ... @@ -149,10 +148,11 @@ const articleList = (params) => {
}, {
code: 200
}).then(result => {
let resu = {
infos: []
};
if (result && result.data) {
resu.infos = result.data;
}
... ... @@ -164,9 +164,9 @@ const articleList = (params) => {
// 文章详情
const useList = (params) => {
return service.get('ActivityConfigController/getActivityNowList', {
storeId: params.storeId,
activityType: params.activityType,
isFront: params.isFront
storeId: params.storeId,
activityType: params.activityType,
isFront: params.isFront
}, {
code: 200
}).then(result => {
... ... @@ -177,9 +177,9 @@ const useList = (params) => {
// 文章详情-过期
const oldList = (params) => {
return service.get('ActivityConfigController/getActivityEndList', {
storeId: params.storeId,
activityType: params.activityType,
isFront: params.isFront
storeId: params.storeId,
activityType: params.activityType,
isFront: params.isFront
}, {
code: 200
}).then(result => {
... ... @@ -299,13 +299,14 @@ const classActList = (params) => {
// 潮流课堂,活动详情
const classActDetail = (params) => {
return service.get('ActivityConfigController/getFrontDetailById', {
activityId: params.activityId,
isFront: params.isFront
activityId: params.activityId,
isFront: params.isFront
}, {
code: 200
}).then(result => {
let resu = {};
if (result && result.data) {
resu = {
content: result.data.detail,
... ... @@ -336,6 +337,7 @@ const travelDetail = (params) => {
}).then(result => {
let resu = '';
if (result && result.data) {
Object.assign(params, {hairStylistId: result.data.id});
}
... ... @@ -399,10 +401,10 @@ const travel = (params) => {
});
resu.adviser = build;
let build2 = [];
for(let item in result[0].dateList){
for (let item in result[0].dateList) {
build2.push({
date: _MD(item),
week: result[0].dateList[item],
... ... @@ -410,7 +412,7 @@ const travel = (params) => {
dateParse: Date.parse(item) / 1000
});
}
resu.dateList = build2;
resu.dateList = build2;
}
return resu;
... ... @@ -456,7 +458,7 @@ const adviser = (params) => {
if (result && result[1] && result[1].data) {
for(let item in result[1].data){
for (let item in result[1].data) {
build.push({
date: _MD(item),
week: result[1].data[item],
... ... @@ -549,12 +551,13 @@ const getTimeList = (params) => {
}
let ajaxUrl = '';
if (params.userId) {
ajaxUrl = 'ActivityConfigController/getAppointTimeForTour';
} else {
ajaxUrl = 'AppointmentController/getAppointTime';
}
return service.get(ajaxUrl, {
storeId: params.storeId,
activityId: params.activityId,
... ... @@ -575,7 +578,7 @@ const getTimeList = (params) => {
let build = [];
if (result && result.data && result.data.timeMap) {
for(let item in result.data.timeMap){
for (let item in result.data.timeMap) {
build.push({
time: _HM(new Date(item * 1000)),
originTime: item,
... ... @@ -778,6 +781,7 @@ const chosenPackage = (params) => {
if (result && result[0] && result[0].data) {
let build = [];
result[0].data.forEach(val => {
build.push({
name: val.activityName,
... ... @@ -841,7 +845,7 @@ const chosenTime = (params) => {
if (result && result[0] && result[0].data) {
for(let item in result[0].data){
for (let item in result[0].data) {
build.push({
date: _MD(item),
week: result[0].data[item],
... ... @@ -868,6 +872,7 @@ const chosenCutter = (params) => {
if (result[0] && result[0].data) {
let build = [];
result[0].data.forEach(val => {
build.push({
name: val.stylistName,
... ... @@ -899,19 +904,19 @@ const chosenAdviser = (params) => {
if (result && result[0] && result[0].data) {
let build = [];
let build = [];
result[0].data.forEach(val => {
build.push({
name: val.consultantName,
summary: val.summary,
image: val.image,
id: val.id
});
result[0].data.forEach(val => {
build.push({
name: val.consultantName,
summary: val.summary,
image: val.image,
id: val.id
});
});
resu.adviser = build;
}
resu.adviser = build;
}
return resu;
});
... ... @@ -971,6 +976,7 @@ const orderList = (params) => {
if (result) {
if (result[0] && result[0].data) {
let build = [];
result[0].data.forEach(val => {
build.push({
name: val.activityName,
... ... @@ -989,6 +995,7 @@ const orderList = (params) => {
if (result[1] && result[1].data) {
let build = [];
result[1].data.forEach(val => {
build.push({
name: val.activityName,
... ... @@ -1044,7 +1051,11 @@ const orderDetail = (params) => {
};
}
if (result[0] && result[0].data) {
let appointContent = JSON.parse(result[0].data[0].appointContent);
let appointContent = result[0].data[0].appointContent;
appointContent = appointContent.replace(/[\n]/g, ' ');
appointContent = JSON.parse(appointContent);
resu.userInfo = {
babyName: appointContent.name,
babyAge: appointContent.age === 'NaN' ? '' : appointContent.age,
... ... @@ -1069,6 +1080,7 @@ const orderDetail = (params) => {
}
let newNarams = '';
if (result[0] && result[0].data) {
newNarams = {
id: result[0].data[0].activityId,
... ... @@ -1078,6 +1090,7 @@ const orderDetail = (params) => {
return adviserDetail(newNarams).then(newResult => {
let adviserDetail= '';
if (newResult && newResult.data) {
adviserDetail = {
name: newResult.data.activityName,
... ... @@ -1101,7 +1114,7 @@ const orderDetail = (params) => {
adviserDetail = {
adviser: true,
hideAd: true
}
};
}
resu = Object.assign(resu, {adviserDetail: adviserDetail});
return resu;
... ... @@ -1147,6 +1160,7 @@ const kidStyle = (params) => {
if (result[0] && result[0].data) {
let build = [];
result[0].data.forEach(val => {
build.push({
name: val.stylistName,
... ... @@ -1207,6 +1221,7 @@ const kids = (params) => {
if (result && result[0] && result[0].data) {
let build = [];
result[0].data.forEach(val => {
build.push({
img: val.thumbnailUrl,
... ... @@ -1228,7 +1243,7 @@ const cutter = (params) => {
adviserList(params),
getDate2(params)
]).then(result => {
let resu = {
packageList: [],
stylist: [],
... ... @@ -1240,18 +1255,20 @@ const cutter = (params) => {
if (result[0] && result[0].data) {
let val = result[0].data[0];
resu = {
image: val.stylistPhoto,
name: val.stylistName,
summary: val.stylistLevelStr,
intro: val.introduction,
};
resu.showBtn = val.isAppointment ===1;
};
resu.showBtn = val.isAppointment === 1;
resu.stylist = val.stylistWorks.split(',');
}
if (result[1] && result[1].data) {
let build = [];
result[1].data.forEach(val => {
build.push({
... ... @@ -1270,8 +1287,7 @@ const cutter = (params) => {
let build = [];
if (result && result[2] && result[2].data) {
for(let item in result[2].data){
for (let item in result[2].data) {
build.push({
date: _MD(item),
week: result[2].data[item],
... ... @@ -1303,6 +1319,7 @@ const delOrder = (params) => {
const changeDate = (params) => {
let appointTimeStr = _originDay(params.appointTimeStr);
return service.get('AppointmentController/updateFrontAppointTime', {
id: params.id,
appointTimeStr: appointTimeStr,
... ...
require('../common');
var tip = require('../plugin/tip'),
IScroll = require('yoho-iscroll'),
diaLog = require('../plugin/dialog'),
... ... @@ -25,954 +26,1013 @@ if ($('#map').length > 0) {
require('../../scss/activity/trend/map.css');
}
$(
function() {
// 地图初始化
if ($('#map').length > 0) {
var w_height = $(window).height();
var h_height = $('.yoho-header').height();
$('#map').css('height', (w_height - h_height) + 'px');
var mapPic = decodeURI(window.queryString.pic);
var mapName = decodeURI(window.queryString.name);
var napAdr = decodeURI(window.queryString.adr);
var mapIntro = decodeURI(window.queryString.intro);
var mapTel = decodeURI(window.queryString.tel);
var mapJD = decodeURI(window.queryString.jd);
var mapWD = decodeURI(window.queryString.wd);
function formatDate(time) {
var week = new Array('周一', '周二', '周三', '周四', '周五', '周六', '周日');
var time = new Date(time);
var year = time.getYear();
var month = time.getMonth() + 1;
var date = time.getDate();
var day = time.getDay();
var hour = time.getHours();
var minutes = time.getMinutes();
// 百度地图API功能
var map = new BMap.Map('map');
var point = new BMap.Point(mapJD, mapWD); // 坐标点
map.centerAndZoom(point, 100); // 缩放比例
map.enableScrollWheelZoom();
var content = '<div style="margin:0;line-height:20px;padding:2px;font-size:12px;">' +
'<img src="' + mapPic + '" style="float:right;zoom:1;overflow:hidden;width:100px;height:100px;margin-left:3px;"/>' +
'地址:' + napAdr + '<br/>电话:' + mapTel + '<br/>简介:' + mapIntro +
'</div>';
if (year < 1900) {
year = year + 1900;
}
if (month < 10) {
month = '0' + month;
}
if (date < 10) {
date = '0' + date;
}
if (hour < 10) {
hour = '0' + hour;
}
if (minutes < 10) {
minutes = '0' + minutes;
}
return year + '年' + month + '月' + date + '日' + ' ' + week[day-1] + ' ' + hour + ':' + minutes;
}
// 创建检索信息窗口对象
var searchInfoWindow = null;
searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
title: mapName, // 标题
width: 290, // 宽度
height: 105, // 高度
panel: 'panel', // 检索结果面板
enableAutoPan: true, // 自动平移
searchTypes:[
// BMAPLIB_TAB_SEARCH, // 周边检索
BMAPLIB_TAB_TO_HERE, // 到这里去
// BMAPLIB_TAB_FROM_HERE // 从这里出发
]
});
var marker = new BMap.Marker(point); // 创建marker对象
marker.enableDragging(); // marker可拖拽
marker.addEventListener('click', function(e){
searchInfoWindow.open(marker);
})
map.addOverlay(marker); // 在地图中添加marker
var label = new BMap.Label(mapName, {offset:new BMap.Size(30, -20)});
marker.setLabel(label);
var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT});// 左上角,添加比例尺
map.addControl(top_left_control);
var ctrl_nav = new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_LARGE});
map.addControl(ctrl_nav);
}
function autoScroll(thisPo) {
$navUl.find('.nav-item:eq(' + thisPo + ')').addClass('active').siblings('li').removeClass('active');
if (thisPo >= 2) {
// 批量设置isFront参数
if (window.queryString.isFront) {
window.setCookie('isFront', window.queryString.isFront);
} else {
window.setCookie('isFront', '1');
// 倒数三个不触发效果
if ((sNum - thisPo) >= 3) {
myScroll.scrollTo((0 - (thisPo - 2) * sWidth), 0, 400);
}
}
}
if ($('.travel').length > 0) {
window.setCookie('travelType', '3');
}
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
lazyLoading: true,
lazyLoadingInPrevNext: true,
paginationClickable: true,
// 风格详情页图片点击放大
$('.pull-pic-list').on('click', function() {
var w_height = $(window).height();
$('.big-pic').show();
$('.swiper-slide img').each(
function() {
if ($(this).height() > w_height) {
$(this).css('height', '90%');
$(this).css('width', 'auto');
var newTop = (w_height - $(this).height()) / 2;
$(this).css('margin-top', newTop + 'px');
} else {
var newTop = (w_height - $(this).height()) / 2;
$(this).css('margin-top', newTop + 'px');
}
}
);
$('.swiper-slide').on('click', function() {
$('.big-pic').hide();
});
});
// loop: true,
autoplay: 3000,
slidesPerView: 'auto',
centeredSlides: true,
observer: true,
observeParents: true,
paginationBulletRender: function(index, className) {
return '<span class="' + className + '">' + (index + 1) + '</span>';
}
});
// 瀑布流
if ($('.pull-pic-list').length > 0) {
setTimeout(function() {
var box = $('.pull-pic-list .box');
var boxWidth = box.eq(0).width();
var num = 2;
var boxArr = [];
var maxHeight = 0;
box.each(function(index, value) {
var boxHeight = box.eq(index).height();
if (index < num) {
boxArr[index] = boxHeight;
} else {
var minBoxHeight = Math.min.apply(null, boxArr);
var minBoxIndex = $.inArray(minBoxHeight, boxArr);
$(value).css({
'position': 'absolute',
'top': minBoxHeight,
'left': box.eq(minBoxIndex).position().left
});
boxArr[minBoxIndex] += box.eq(index).height();
var newHeight = $(this).position().top + box.eq(index).height();
if (newHeight > maxHeight) {
maxHeight = newHeight;
}
$('.pull-pic-list').css('height', maxHeight + 'px');
}
});
}, 500);
}
function getTimeList() {
var $date = $('.nav-ul').find('.active').attr('data');
if ($('.adviser-info').length > 0) {
window.setCookie('adviserId', window.queryString.id);
}
if (window.cookie('limitPerson')) {
$('#num').attr('max', window.cookie('limitPerson'));
}
if ($('#num').attr('max') === '1') {
$('#num').next('.plus-btn').addClass('opacity');
}
// 选择套餐优先级最高,改变套餐,其他选项要重新选择
$('.chosen-select .need').on('click', function() {
var $depend = $('.chosen-select').find('.depend');
var chosenAble = false;
$depend.each(
function() {
if ($(this).find('input').val() === '') {
var errText = $(this).closest('.depend').find('.label').text();
tip.show('请先选择' + errText);
chosenAble = false;
return false;
} else {
chosenAble = true;
}
}
);
if (chosenAble) {
return true;
} else {
return false;
$.ajax({
url: '/activity/trend/getTimeList',
data: {
dateTime: $date,
storeId: window.queryString.storeId,
appointType: window.queryString.typeStatus || window.cookie('travelType'),
activityId: window.queryString.activityId || window.queryString.id || '',
travelId: window.cookie('travelId'),
userId: window.queryString.id
},
success: function(result) {
var timeList = '';
var timeStr = '';
$('.time-list').empty();
$('.date-list').empty();
if ($('.chosen-time').length > 0) {
window.setCookie('limitPerson', result.appointNum);
}
});
for (var i = 0; i < result.getTimeList.length; i++) {
var useClass = 'use';
$('.chosen-select .depend').on('click', function() {
if ($(this).find('.chosen-cutter').length > 0) {
clearCookieArr(2);
} else {
if (!($('.chosen-style').val() && !$('.chosen-package').val())) {
clearCookieArr(1);
if (result.getTimeList[i].use === 2) {
var useClass = 'disable';
}
timeList = timeList + '<a date2="' + result.getTimeList[i].date2 + '" date="' + result.getTimeList[i].date + '" data="' + result.getTimeList[i].originTime + '" class="time-item ' + useClass + '">' + result.getTimeList[i].time + '</a>';
}
});
if ($('.time-list').length > 0) {
$('.time-list').append(timeList);
}
if ($('.date-list').length > 0) {
$('.date-list').append(timeList);
}
$('.time-list .time-item').on('click', function() {
if (!$(this).hasClass('disable')) {
$(this).addClass('chosen').siblings('.time-item').removeClass('chosen');
timeStr = $(this).attr('data');
window.setCookie('timeStr', timeStr);
// 限制文本框输入长度
$('#note').on('keyup', function() {
var obj = $(this);
limitInp(obj, 200, true);
});
$('#name').on('keyup', function() {
var obj = $(this);
limitInp(obj, 10, false);
});
$('#tel').on('keyup', function() {
var obj = $(this);
limitInp(obj, 11, false);
});
$('#age').on('keyup', function() {
var obj = $(this);
limitInp(obj, 2, false);
});
// 如果是从预约订单详情页过来
if (window.queryString.order == 'true') {
var detailtTimeStr = $(this).attr('date');
// 默认勾选
if (window.queryString.chosenType === '4') {
$('.package-item').each(
function() {
if ($(this).find('.name').text() === window.cookie('chosenPackage')) {
$(this).find('input').attr('checked', 'checked');
}
}
);
}
if (window.queryString.chosenType === '3') {
$('.item').each(
function() {
if ($(this).find('.name').text() === window.cookie('chosenAdviser')) {
$(this).find('input').attr('checked', 'checked');
}
}
);
}
if (window.queryString.chosenType === '1') {
$('.style-ul:eq(0) li').each(
function() {
if (window.cookie('chosenStyle').indexOf($(this).text()) > -1) {
$(this).addClass('chosen');
styleNow ++;
window.setCookie('detailtTimeStr', detailtTimeStr);
}
}
);
}
if (window.queryString.chosenType === '5') {
$('.cutter-item').each(
function() {
if ($(this).find('.name').text() === window.cookie('chosenCutter')) {
$(this).find('input').attr('checked', 'checked');
}
}
);
}
if (window.queryString.chosenType === '2') {
var autoIndex = 0;
$('.nav-item').each(
function() {
if ($(this).find('p:first').text()) {
if (window.cookie('chosenTime').indexOf($(this).find('p:first').text()) > -1) {
autoIndex = $(this).index();
}
}
}
);
setTimeout(function() {
$('.nav-ul .nav-item:eq(' + autoIndex + ')').click();
setTimeout(function() {
$('.time-item').each(
function() {
if (window.cookie('chosenTime').indexOf($(this).text()) > -1) {
$(this).addClass('chosen');
}
}
);
}, 100);
}, 100);
});
},
error: function() {
tip.show('获取时间列表失败~');
}
});
}
// 发型师的套餐详情页
if (($('.package-detail').length > 0) && window.queryString.type === 'cutter') {
$('.foot-btn').attr('href', '//m.yohobuy.com/activity/trend/appointment?storeId=66&typeStatus=5')
function orderSubmit() {
var type = 1;
var storeId = window.queryString.storeId;
var appointTime = parseInt(window.cookie('timeStr'));
var appointUserName = $('#name').val();
var appointMobile = parseInt($('#tel').val());
var uid = parseInt($('#uid').val());
var activityId = window.cookie('packageId') || window.cookie('adviserId') || window.cookie('travelId');
var userNote = $('#note').val();
var appointPersonNum = parseInt($('#num').val());
var age = parseInt($('#age').val()) || '';
var ageType = $('#age').parents('.chose-item').find('input:checked').next('label').text();
var styles = window.cookie('styleStr');
var sex = $('input[name=sex]:checked').next('label').attr('name') || '';
var appointContent = '{"name":"' + appointUserName + '","age":"' + age + ageType + '","sex":"' + sex + '","mobile":' + appointMobile + ',"num":' + appointPersonNum + ',"remark":"' + userNote + '"}';
if (!window.cookie('packageId') && !window.cookie('adviserId')) {
type = 2;
}
userNote = userNote.replace(/[\r\n]/g, ' ');
if (userNote === '添加备注(选填)') {
userNote = '';
}
$.ajax({
url: '/activity/trend/addOrder',
data: {
storeId: storeId,
appointTime: appointTime,
appointUserName: appointUserName,
appointMobile: appointMobile,
uid: uid,
activityId: activityId,
appointContent: appointContent,
userNote: userNote,
appointPersonNum: appointPersonNum,
styles: styles,
type: type
},
success: function(result) {
if (result.code === 200) {
document.location.href = '//m.yohobuy.com/activity/trend/success?storeId=' + window.queryString.storeId + '&typeStatus=' + window.queryString.typeStatus;
} else {
tip.show(result.message);
}
},
error: function() {
tip.show('网络断开了~~~');
}
});
}
// 将表单数据存入cookie
if ($('#detail-time').length > 0 && window.cookie('detailtTimeStr')) {
$('#detail-time').html(window.cookie('detailtTimeStr'));
function diaHide() {
$('#dialog-wrapper').hide();
}
// 修改预约时间
$.ajax({
url: '/activity/trend/changeDate',
data: {
id: $('.chan-btn').attr('id'),
appointTimeStr: window.cookie('detailtTimeStr')
},
success: function(result) {
if (result.code === 200) {
window.setCookie('detailtTimeStr', '');
window.location.href = window.location.href;
// tip.show('修改成功');
} else {
// tip.show(result.message);
}
},
error: function() {
tip.show('网络断开了~~~');
}
});
function removeByValue(arr, val) {
for (var i=0; i<arr.length; i++) {
if (arr[i] == val) {
arr.splice(i, 1);
break;
}
}
}
if ($('.chosen-select').length > 0) {
$('.chosen-package').val(window.cookie('chosenPackage'));
$('.chosen-style').val(window.cookie('chosenStyle'));
$('.chosen-style').attr('id', window.cookie('styleId'));
// 默认已勾选风格,根据后选套餐是否包含该风格,判断时候清空风格
if (window.cookie('packageStyle') && window.cookie('styleId')) {
var idArr = window.cookie('packageStyle').split(',');
var hasId = false;
for (var i = 0; i < idArr.length; i++) {
if (idArr[i] === $('.chosen-style').attr('id')) {
hasId = true;
break;
function checkSubmit() {
var needNnow = $('.need-know').find('input:checked').length;
if (needNnow > 0) {
var $require = $('.require');
var checkSubmit = false;
$require.each(
function() {
if ($(this).val() === '') {
var errText = $(this).attr('label');
tip.show('请输入' + errText);
checkSubmit = false;
return false;
} else {
var thisId = $(this).attr('id');
switch (thisId) {
case 'name' :
var reg = /^[\u4e00-\u9fa5]{1,10}$/;
var val = $(this).val();
if (!reg.test(val)) {
tip.show('姓名请输入10个以内汉字');
checkSubmit = false;
return false;
} else {
checkSubmit = true;
}
break;
case 'tel' :
var reg = /^1[34578]\d{9}$/;
var val = $(this).val();
if (!reg.test(val)) {
tip.show('手机号请输入11位数字');
checkSubmit = false;
} else {
checkSubmit = true;
}
return false;
break;
default:
checkSubmit = true;
}
}
if (!hasId) {
$('.chosen-style').val('');
clearCookieArr(1);
}
window.setCookie('styleId', '');
}
$('.chosen-time').val(window.cookie('chosenTime'));
$('.chosen-cutter').val(window.cookie('chosenCutter'));
$('.chosen-adviser').val(window.cookie('chosenAdviser'));
$('.chosen-class').val(window.cookie('chosenClass'));
if (window.cookie('chosenClass')) {
var timeResult = getAbleTime();
if (timeResult.data) {
$('.chosen-time').val(_formatDay(new Date(timeResult.data * 1000))).addClass('disabled');
$('.chosen-time').parents('a').attr('href', 'javascript:void(0)');
window.setCookie('timeStr', timeResult.data);
}
}
if (!window.cookie('chosenCutter') && window.cookie('chosenPackage')) {
$('.chosen-cutter').val('不预约发型师');
}
if (!window.cookie('chosenAdviser') && window.cookie('chosenTime')) {
$('.chosen-adviser').val('不预约潮流顾问');
}
if ($('.chosen-adviser').val() === '不预约潮流顾问') {
window.setCookie('adviserId', '');
}
if (($('.chosen-select .chose-item:eq(0)').find('input').val() !== '') && window.cookie('chosenTime')) {
$('.chosen-select .chose-item:eq(0)').addClass('depend');
$('.chosen-select .chose-item:eq(1)').addClass('need');
$('.chosen-select .depend').on('click', function() {
if ($(this).find('.chosen-cutter').length > 0) {
clearCookieArr(2);
} else {
clearCookieArr(1);
}
});
}
);
if (checkSubmit) {
submitDia();
}
$cookie = $('.chosen-info').find('.cookie');
$cookie2 = $('.chosen-info').find('.cookie2');
} else {
tip.show('请先接受上述条款');
}
}
// 修改表单存储cookie
$('.chosen').on('click', function() {
setCookieArr();
});
$('.chosen .cookie').on('keyup', function() {
setCookieArr();
});
if ($('.chosen-info').find('.cookie').length > 0) {
if (window.cookie('cookieArr') !== undefined && (window.cookie('cookieArr'))) {
var getCookie = window.cookie('cookieArr').split(',');
var inpNum = 0;
$cookie.each(
function() {
$(this).val(getCookie[inpNum]);
inpNum ++;
}
);
}
}
$('.cookie2').on('click', function() {
var radioIndex = $(this).index() === 2 ? 0 : 1;
window.setCookie('radio' + $(this).attr('name'), radioIndex);
});
if ($('.chosen-info').find('.cookie2').length > 0) {
$('.chose-item').find('.cookie2[name=sex]:eq(' + window.cookie('radiosex') + ')').attr('checked', 'checked');
$('.chose-item').find('.cookie2[name=birth]:eq(' + window.cookie('radiobirth') + ')').attr('checked', 'checked');
function submitDia() {
diaLog.showDialog({
hasHeader: '温馨提示',
dialogText: '1、如需取消预约,可在预约时间前3天取消预约;<br />2、未取消的预约请按时到店。如未及时到店,我们将按爽约进行处理,一年中有3次爽约行为,本年内就无法再参与本店活动了哦。',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
diaHide();
orderSubmit();
});
if ($('.clearCookie').length > 0) {
clearCookieArr(3);
}
// 修改弹框样式
$('.tap-hightlight').css('color', '#007aff');
$('.dialog-content').css({'text-align': 'left', 'padding': '0 0.75rem 0.5rem'});
}
if ($('.textarea textarea').val() === '添加备注(选填)') {
$('.textarea textarea').addClass('disabled');
$('.textarea textarea').on('focus', function() {
$(this).val('').removeClass('disabled');
});
};
function setCookieArr() {
var cookieArr = new Array();
// 默认选中菜单
if ($('.class-detail').length > 0) {
window.setCookie('chosenClass', $('.class-detail').find('.name').text());
window.setCookie('packageId', $('.class-detail').find('.name').attr('id'));
}
if ($('.adviser-info').find('.name').length > 0) {
window.setCookie('chosenCutter', $('.adviser-info').find('.name').text());
window.setCookie('chosenAdviser', $('.adviser-info').find('.name').text());
}
if ($('.style-detail').length > 0) {
window.setCookie('styleId', window.queryString.id);
window.setCookie('chosenStyle', ' ' + decodeURI(window.queryString.styleName) + ' ');
$cookie.each(
function() {
cookieArr.push($(this).val());
}
if ($('.package-detail').length > 0) {
window.setCookie('chosenPackage', $('.package-detail').find('.name').text());
window.setCookie('packageLimit', $('.package-detail').find('.limit').val());
window.setCookie('packageStyle', $('.package-detail').find('.styleid').val());
window.setCookie('packageId', window.queryString.id);
);
window.setCookie('cookieArr', cookieArr);
}
// 限制输入长度
function limitInp(obj, limit, show) {
var textLen = obj.val();
if (textLen.length > limit) {
if (show) {
tip.show('最多输入' + limit + '字');
}
textLen = textLen.substring(0, limit);
obj.val(textLen);
return false;
}
}
// 立即预约按钮
$('.chosen-btn').on('click', function() {
var $checkedItem = $(this).siblings('.side-main').find('input:checked');
var $chosenItem = $(this).siblings('.side-main').find('.chosen');
var checkedNum = $checkedItem.length;
var chosenNum = $chosenItem.length;
var chosenType = window.queryString.chosenType;
var tipMsg = '';
if ((checkedNum <= 0) && (chosenNum <= 0)) {
switch (chosenType) {
case '1' : tipMsg = '风格';
break;
case '2' : tipMsg = '时间';
break;
case '3' : tipMsg = '潮流顾问';
break;
case '4' : tipMsg = '套餐';
break;
case '5' : tipMsg = '发型师';
break;
}
tip.show('请选择' + tipMsg);
function getAbleTime() {
var timeResult = '';
$.ajax({
url: '/activity/trend/getAbleTime',
data: {
activityType: window.queryString.typeStatus,
activityId: window.queryString.activityId || window.cookie('packageId') || window.cookie('travelId')
},
async: false,
success: function(result) {
if (result.code === 200) {
timeResult = result;
} else {
var chosenText = $checkedItem.attr('data') || $chosenItem.text();
var chosenText2 = $chosenItem.attr('date2');
var packageId = $checkedItem.attr('id');
switch (chosenType) {
case '4' :
window.setCookie('chosenPackage', chosenText);
window.setCookie('packageId', packageId);
window.setCookie('packageLimit', $checkedItem.attr('limit'));
window.setCookie('packageStyle', $checkedItem.attr('styleid'));
break;
case '1' :
window.setCookie('chosenStyle', chosenText);
break;
case '2' :
window.setCookie('chosenTime', chosenText2);
break;
case '3' :
window.setCookie('chosenAdviser', chosenText);
window.setCookie('adviserId', packageId);
break;
case '5' :
window.setCookie('chosenCutter', chosenText);
break;
}
document.location.href = document.referrer;
// tip.show(result.message);
}
});
},
error: function() {
tip.show('网络断开了~~~');
}
});
return timeResult;
}
// 取消订单
$('.order-btn a').on('click', function() {
diaLog.showDialog({
dialogText: '确认取消预约吗?',
hasFooter: {
leftBtnText: '我再想想',
rightBtnText: '确认取消'
}
},function() {
$.ajax({
url: '/activity/trend/delOrder',
data: {
id: $('.order-btn a').attr('id')
},
success: function(result) {
if (result.code === 200) {
document.location.href = '//m.yohobuy.com/activity/trend/order-list?storeId=' + window.queryString.storeId;
} else {
tip.show(result.message);
}
},
error: function() {
tip.show('网络断开了~~~');
}
});
});
// 修改弹框样式
$('.dialog-left-btn').css('color', '#999');
$('.dialog-right-btn').css('color', '#007aff');
});
function _formatDay(day) {
return moment(day).format('MM月DD日 HH:mm');
}
// 加减人数按钮
$num.find('.plus-btn').on('click', function() {
if (!$('.chosen-time').val()) {
tip.show('请先选择预约时间');
} else {
var limitNum = parseInt($num.find('input').attr('max'));
if (parseInt($num.find('input').val()) < limitNum) {
num = parseInt($num.find('input').val()) + 1;
$num.find('input').val(num);
} else {
tip.show('可预约人数已达上限');
}
}
});
$num.find('.minus-btn').on('click', function() {
if (parseInt($num.find('input').val()) > 1) {
num = parseInt($num.find('input').val()) - 1;
$num.find('input').val(num);
} else {
tip.show('人数不能小于1');
}
});
// 清除cookie
function clearCookieArr(type) {
switch (type) {
case 1 :
window.setCookie('chosenStyle', '');
window.setCookie('chosenTime', '');
break;
case 2 :
window.setCookie('chosenPackage', '');
window.setCookie('chosenStyle', '');
window.setCookie('chosenTime', '');
break;
case 3 :
window.setCookie('chosenPackage', '');
window.setCookie('packageId', '');
window.setCookie('chosenStyle', '');
window.setCookie('chosenTime', '');
window.setCookie('chosenAdviser', '');
window.setCookie('adviserId', '');
window.setCookie('chosenCutter', '');
window.setCookie('iscutter', '');
window.setCookie('styleStr', '');
window.setCookie('timeStr', '');
window.setCookie('detailtTimeStr', '');
window.setCookie('radiobirth', '');
window.setCookie('radiosex', '');
window.setCookie('cookieArr', '');
window.setCookie('limitPerson', '');
window.setCookie('packageLimit', '');
window.setCookie('packageStyle', '');
window.setCookie('chosenClass', '');
window.setCookie('styleId', '');
break;
}
}
sNum = $navUl.find('.nav-item').length;
sWidth = $navUl.find('.nav-item').width();
$navUl.width(sNum * sWidth);
$(
function() {
if ($('.wrapper').length > 0) {
myScroll = new IScroll('.wrapper', {
scrollX: true,
scrollY: false,
preventDefault: false,
});
// 地图初始化
if ($('#map').length > 0) {
var w_height = $(window).height();
var h_height = $('.yoho-header').height();
// 通过拖拽选择时间段
myScroll.on('scrollStart', function() {
$navUl.addClass('srolling');
return false;
});
myScroll.on('scrollEnd', function() {
if ($navUl.hasClass('srolling')) {
$navUl.removeClass('srolling');
var thisPo = Math.ceil((0 - myScroll.x) / sWidth + 1.5);
autoScroll(thisPo);
getTimeList();
}
});
}
$('#map').css('height', (w_height - h_height) + 'px');
var mapPic = decodeURI(window.queryString.pic);
var mapName = decodeURI(window.queryString.name);
var napAdr = decodeURI(window.queryString.adr);
var mapIntro = decodeURI(window.queryString.intro);
var mapTel = decodeURI(window.queryString.tel);
var mapJD = decodeURI(window.queryString.jd);
var mapWD = decodeURI(window.queryString.wd);
var map = new BMap.Map('map');
var point = new BMap.Point(mapJD, mapWD); // 坐标点
var searchInfoWindow = null;
var content = '<div style="margin:0;line-height:20px;padding:2px;font-size:12px;">' +
'<img src="' + mapPic + '" style="float:right;zoom:1;overflow:hidden;width:100px;height:100px;margin-left:3px;"/>' +
'地址:' + napAdr + '<br/>电话:' + mapTel + '<br/>简介:' + mapIntro +
'</div>';
var marker = new BMap.Marker(point); // 创建marker对象
var label = new BMap.Label(mapName, {offset: new BMap.Size(30, -20)});
var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT});// 左上角,添加比例尺
var ctrl_nav = new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_LARGE});
// 通过点击选择时间段
$navUl.find('.nav-item').on('click', function() {
if (!$(this).hasClass('disable')) {
var thisPo = $(this).index();
autoScroll(thisPo);
getTimeList();
}
});
// 百度地图API功能
map.centerAndZoom(point, 15); // 缩放比例
map.enableScrollWheelZoom();
$('.open-right').on('click', function() {
openId = $(this).attr('open-data');
$("#" + openId).removeClass('back');
$("#" + openId).addClass('active');
});
// 创建检索信息窗口对象
searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
title: mapName, // 标题
width: 290, // 宽度
height: 105, // 高度
panel: 'panel', // 检索结果面板
enableAutoPan: true, // 自动平移
searchTypes: [
$('.dia-tip').on('click', function() {
checkSubmit();
})
// BMAPLIB_TAB_SEARCH, // 周边检索
BMAPLIB_TAB_TO_HERE, // 到这里去
$('.tab .tab-top span').on('click', function() {
var $this = $(this);
$this.addClass('active').siblings('span').removeClass('active');
var tabIndex = $this.index();
$this.parents('.tab').find('.tab-item:eq(' + tabIndex + ')').show().siblings('.tab-item').hide();
});
// BMAPLIB_TAB_FROM_HERE // 从这里出发
]
});
marker.enableDragging(); // marker可拖拽
marker.addEventListener('click', function(e) {
searchInfoWindow.open(marker);
});
map.addOverlay(marker); // 在地图中添加marker
marker.setLabel(label);
map.addControl(top_left_control);
map.addControl(ctrl_nav);
}
$('.tab-item:first').show();
// 批量设置isFront参数
if (window.queryString.isFront) {
window.setCookie('isFront', window.queryString.isFront);
} else {
window.setCookie('isFront', '1');
}
// 选择风格
if ($('.style-ul').length > 0) {
styleTotal = window.cookie('packageLimit');
if (window.cookie('packageStyle')) {
$('.style-ul:eq(0) li').each(
function() {
var $totalId = $(this).attr('id');
var $packageStyle = window.cookie('packageStyle').split(',');
for (var i = 0; i < $packageStyle.length; i++) {
if ($totalId == $packageStyle[i]) {
$(this).removeClass('disabled');
}
}
}
);
}
$('.style-tip .total').text(styleTotal);
$('.style-tip .now').text(styleNow);
if ($('.travel').length > 0) {
window.setCookie('travelType', '3');
}
var styleStr = new Array();
$('.style-ul li').on('click', function() {
$(this).parents('.style-ul').siblings('.style-ul').find('li').removeClass('chosen');
var $this = $(this);
var $thisId = $(this).attr('id');
if (!$this.hasClass('disabled')) {
if ($this.hasClass('chosen')) {
$this.removeClass('chosen');
if (!$this.hasClass('not')) {
removeByValue(styleStr, $thisId);
styleNow --;
// 风格详情页图片点击放大
$('.pull-pic-list').on('click', function() {
var w_height = $(window).height();
$('.big-pic').show();
$('.swiper-slide img').each(
function() {
if ($(this).height() > w_height) {
$(this).css('height', '90%');
$(this).css('width', 'auto');
var newTop = (w_height - $(this).height()) / 2;
$(this).css('margin-top', newTop + 'px');
} else {
styleStr = [];
styleNow = 0;
var newTop = (w_height - $(this).height()) / 2;
$(this).css('margin-top', newTop + 'px');
}
} else {
if (!$this.hasClass('not')) {
var limitNum = $('.total').text();
if (styleNow >= limitNum) {
tip.show('超过最大可选风格数');
return false;
}
);
$('.swiper-slide').on('click', function() {
$('.big-pic').hide();
});
});
// 瀑布流
if ($('.pull-pic-list').length > 0) {
setTimeout(function() {
var box = $('.pull-pic-list .box');
var boxWidth = box.eq(0).width();
var num = 2;
var boxArr = [];
var maxHeight = 0;
box.each(function(index, value) {
var boxHeight = box.eq(index).height();
if (index < num) {
boxArr[index] = boxHeight;
} else {
var minBoxHeight = Math.min.apply(null, boxArr);
var minBoxIndex = $.inArray(minBoxHeight, boxArr);
$(value).css({
'position': 'absolute',
'top': minBoxHeight,
'left': box.eq(minBoxIndex).position().left
});
boxArr[minBoxIndex] += box.eq(index).height();
var newHeight = $(this).position().top + box.eq(index).height();
if (newHeight > maxHeight) {
maxHeight = newHeight;
}
$this.addClass('chosen');
styleStr.push($thisId);
styleNow ++;
$('.pull-pic-list').css('height', maxHeight + 'px');
}
});
}, 500);
}
if ($('.adviser-info').length > 0) {
window.setCookie('adviserId', window.queryString.id);
}
if (window.cookie('limitPerson')) {
$('#num').attr('max', window.cookie('limitPerson'));
}
if ($('#num').attr('max') === '1') {
$('#num').next('.plus-btn').addClass('opacity');
}
// 选择套餐优先级最高,改变套餐,其他选项要重新选择
$('.chosen-select .need').on('click', function() {
var $depend = $('.chosen-select').find('.depend');
var chosenAble = false;
$depend.each(
function() {
if ($(this).find('input').val() === '') {
var errText = $(this).closest('.depend').find('.label').text();
tip.show('请先选择' + errText);
chosenAble = false;
return false;
} else {
$this.addClass('chosen');
styleStr = [];
styleNow = 0;
chosenAble = true;
}
}
);
if (chosenAble) {
return true;
} else {
return false;
}
});
$('.chosen-select .depend').on('click', function() {
if ($(this).find('.chosen-cutter').length > 0) {
clearCookieArr(2);
} else {
if (!($('.chosen-style').val() && !$('.chosen-package').val())) {
clearCookieArr(1);
}
}
$('.style-tip .now').text(styleNow);
window.setCookie('styleStr', styleStr);
});
if ($('.time-nav').length > 0) {
$('.time-nav ul').find('.nav-item:eq(2)').addClass('active');
getTimeList();
// 限制文本框输入长度
$('#note').on('keyup', function() {
var obj = $(this);
limitInp(obj, 200, true);
});
$('#name').on('keyup', function() {
var obj = $(this);
limitInp(obj, 10, false);
});
$('#tel').on('keyup', function() {
var obj = $(this);
limitInp(obj, 11, false);
});
$('#age').on('keyup', function() {
var obj = $(this);
limitInp(obj, 2, false);
});
// 默认勾选
if (window.queryString.chosenType === '4') {
$('.package-item').each(
function() {
if ($(this).find('.name').text() === window.cookie('chosenPackage')) {
$(this).find('input').attr('checked', 'checked');
}
}
);
}
if (window.queryString.chosenType === '3') {
$('.item').each(
function() {
if ($(this).find('.name').text() === window.cookie('chosenAdviser')) {
$(this).find('input').attr('checked', 'checked');
}
}
);
}
if (window.queryString.chosenType === '1') {
$('.style-ul:eq(0) li').each(
function() {
if (window.cookie('chosenStyle').indexOf($(this).text()) > -1) {
$(this).addClass('chosen');
styleNow ++;
}
}
);
}
if (window.queryString.chosenType === '5') {
$('.cutter-item').each(
function() {
if ($(this).find('.name').text() === window.cookie('chosenCutter')) {
$(this).find('input').attr('checked', 'checked');
}
}
);
}
if (window.queryString.chosenType === '2') {
var autoIndex = 0;
if ($('.order-item').length > 0) {
$('.order-item').each(
$('.nav-item').each(
function() {
var time = $(this).find('.time').attr('date') * 1000;
var weekTime = formatDate(time);
$(this).find('.time').html(weekTime);
if ($(this).find('p:first').text()) {
if (window.cookie('chosenTime').indexOf($(this).find('p:first').text()) > -1) {
autoIndex = $(this).index();
}
}
}
);
setTimeout(function() {
$('.nav-ul .nav-item:eq(' + autoIndex + ')').click();
setTimeout(function() {
$('.time-item').each(
function() {
if (window.cookie('chosenTime').indexOf($(this).text()) > -1) {
$(this).addClass('chosen');
}
}
);
}, 100);
}, 100);
}
if ($('#detail-time').length > 0) {
var time = $('#detail-time').attr('date') * 1000;
var weekTime = formatDate(time);
$('#detail-time').html(weekTime);
var timeResult = getAbleTime();
if (timeResult.data === '') {
$('.chan-btn').show();
}
// 发型师的套餐详情页
if (($('.package-detail').length > 0) && window.queryString.type === 'cutter') {
$('.foot-btn').attr('href', '//m.yohobuy.com/activity/trend/appointment?storeId=66&typeStatus=5');
}
}
);
function formatDate(time) {
var week = new Array('周一', '周二', '周三', '周四', '周五', '周六', '周日');
var time = new Date(time);
var year = time.getYear();
if (year < 1900) {
year = year + 1900;
}
var month = time.getMonth() + 1;
if (month < 10) {
month = '0' + month;
}
var date = time.getDate();
if (date < 10) {
date = '0' + date;
}
var day = time.getDay();
var hour = time.getHours();
if (hour < 10) {
hour = '0' + hour;
}
var minutes = time.getMinutes();
if (minutes < 10) {
minutes = '0' + minutes;
}
return year + '年' + month + '月' + date + '日' + ' ' + week[day-1] + ' ' + hour + ':' + minutes;
}
// 将表单数据存入cookie
if ($('#detail-time').length > 0 && window.cookie('detailtTimeStr')) {
$('#detail-time').html(window.cookie('detailtTimeStr'));
function autoScroll (thisPo) {
$navUl.find('.nav-item:eq(' + thisPo + ')').addClass('active').siblings('li').removeClass('active');
if (thisPo >= 2) {
// 倒数三个不触发效果
if ((sNum - thisPo) >= 3) {
myScroll.scrollTo((0 - (thisPo - 2) * sWidth), 0, 400);
// 修改预约时间
$.ajax({
url: '/activity/trend/changeDate',
data: {
id: $('.chan-btn').attr('id'),
appointTimeStr: window.cookie('detailtTimeStr')
},
success: function(result) {
if (result.code === 200) {
window.setCookie('detailtTimeStr', '');
window.location.href = window.location.href;
// tip.show('修改成功');
} else {
// tip.show(result.message);
}
},
error: function() {
tip.show('网络断开了~~~');
}
});
}
}
}
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
lazyLoading: true,
lazyLoadingInPrevNext: true,
paginationClickable: true,
// loop: true,
autoplay: 3000,
slidesPerView: 'auto',
centeredSlides: true,
observer: true,
observeParents: true,
paginationBulletRender: function(index, className) {
return '<span class="' + className + '">' + (index + 1) + '</span>';
}
});
if ($('.chosen-select').length > 0) {
$('.chosen-package').val(window.cookie('chosenPackage'));
$('.chosen-style').val(window.cookie('chosenStyle'));
$('.chosen-style').attr('id', window.cookie('styleId'));
function getTimeList() {
var $date = $('.nav-ul').find('.active').attr('data');
$.ajax({
url: '/activity/trend/getTimeList',
data: {
dateTime: $date,
storeId: window.queryString.storeId,
appointType: window.queryString.typeStatus || window.cookie('travelType'),
activityId: window.queryString.activityId || window.queryString.id || '',
travelId: window.cookie('travelId'),
userId: window.queryString.id
},
success: function(result) {
$('.time-list').empty();
$('.date-list').empty();
if ($('.chosen-time').length > 0) {
window.setCookie('limitPerson', result.appointNum);
// 默认已勾选风格,根据后选套餐是否包含该风格,判断时候清空风格
if (window.cookie('packageStyle') && window.cookie('styleId')) {
var idArr = window.cookie('packageStyle').split(',');
var hasId = false;
for (var i = 0; i < idArr.length; i++) {
if (idArr[i] === $('.chosen-style').attr('id')) {
hasId = true;
break;
}
}
if (!hasId) {
$('.chosen-style').val('');
clearCookieArr(1);
}
window.setCookie('styleId', '');
}
let timeList = '';
for (var i = 0;i < result.getTimeList.length; i ++) {
var useClass = 'use';
if (result.getTimeList[i].use === 2) {
var useClass = 'disable';
$('.chosen-time').val(window.cookie('chosenTime'));
$('.chosen-cutter').val(window.cookie('chosenCutter'));
$('.chosen-adviser').val(window.cookie('chosenAdviser'));
$('.chosen-class').val(window.cookie('chosenClass'));
if (window.cookie('chosenClass')) {
var timeResult = getAbleTime();
if (timeResult.data) {
$('.chosen-time').val(_formatDay(new Date(timeResult.data * 1000))).addClass('disabled');
$('.chosen-time').parents('a').attr('href', 'javascript:void(0)');
window.setCookie('timeStr', timeResult.data);
}
timeList = timeList + '<a date2="' + result.getTimeList[i].date2 + '" date="' + result.getTimeList[i].date + '" data="' + result.getTimeList[i].originTime + '" class="time-item ' + useClass + '">' + result.getTimeList[i].time + '</a>';
}
if ($('.time-list').length > 0) {
$('.time-list').append(timeList);
if (!window.cookie('chosenCutter') && window.cookie('chosenPackage')) {
$('.chosen-cutter').val('不预约发型师');
}
if ($('.date-list').length > 0) {
$('.date-list').append(timeList);
if (!window.cookie('chosenAdviser') && window.cookie('chosenTime')) {
$('.chosen-adviser').val('不预约潮流顾问');
}
var timeStr = '';
$('.time-list .time-item').on('click', function() {
if(!$(this).hasClass('disable')) {
$(this).addClass('chosen').siblings('.time-item').removeClass('chosen');
timeStr = $(this).attr('data');
window.setCookie('timeStr', timeStr);
// 如果是从预约订单详情页过来
if (window.queryString.order == 'true') {
var detailtTimeStr = $(this).attr("date");
window.setCookie('detailtTimeStr', detailtTimeStr);
if ($('.chosen-adviser').val() === '不预约潮流顾问') {
window.setCookie('adviserId', '');
}
if (($('.chosen-select .chose-item:eq(0)').find('input').val() !== '') && window.cookie('chosenTime')) {
$('.chosen-select .chose-item:eq(0)').addClass('depend');
$('.chosen-select .chose-item:eq(1)').addClass('need');
$('.chosen-select .depend').on('click', function() {
if ($(this).find('.chosen-cutter').length > 0) {
clearCookieArr(2);
} else {
clearCookieArr(1);
}
});
}
}
$cookie = $('.chosen-info').find('.cookie');
$cookie2 = $('.chosen-info').find('.cookie2');
// 修改表单存储cookie
$('.chosen').on('click', function() {
setCookieArr();
});
$('.chosen .cookie').on('keyup', function() {
setCookieArr();
});
if ($('.chosen-info').find('.cookie').length > 0) {
if (window.cookie('cookieArr') !== undefined && (window.cookie('cookieArr'))) {
var getCookie = window.cookie('cookieArr').split(',');
var inpNum = 0;
$cookie.each(
function() {
$(this).val(getCookie[inpNum]);
inpNum++;
}
);
}
}
$cookie2.on('click', function() {
var radioIndex = $(this).index() === 2 ? 0 : 1;
window.setCookie('radio' + $(this).attr('name'), radioIndex);
});
if ($('.chosen-info').find('.cookie2').length > 0) {
$('.chose-item').find('.cookie2[name=sex]:eq(' + window.cookie('radiosex') + ')').attr('checked', 'checked');
$('.chose-item').find('.cookie2[name=birth]:eq(' + window.cookie('radiobirth') + ')').attr('checked', 'checked');
}
if ($('.clearCookie').length > 0) {
clearCookieArr(3);
}
if ($('.textarea textarea').val() === '添加备注(选填)') {
$('.textarea textarea').addClass('disabled');
}
$('.textarea textarea').on('focus', function() {
if ($('.textarea textarea').val() === '添加备注(选填)') {
$(this).val('').removeClass('disabled');
}
});
// 默认选中菜单
if ($('.class-detail').length > 0) {
window.setCookie('chosenClass', $('.class-detail').find('.name').text());
window.setCookie('packageId', $('.class-detail').find('.name').attr('id'));
}
if ($('.adviser-info').find('.name').length > 0) {
window.setCookie('chosenCutter', $('.adviser-info').find('.name').text());
window.setCookie('chosenAdviser', $('.adviser-info').find('.name').text());
}
if ($('.style-detail').length > 0) {
window.setCookie('styleId', window.queryString.id);
window.setCookie('chosenStyle', ' ' + decodeURI(window.queryString.styleName) + ' ');
}
if ($('.package-detail').length > 0) {
window.setCookie('chosenPackage', $('.package-detail').find('.name').text());
window.setCookie('packageLimit', $('.package-detail').find('.limit').val());
window.setCookie('packageStyle', $('.package-detail').find('.styleid').val());
window.setCookie('packageId', window.queryString.id);
}
// 立即预约按钮
$('.chosen-btn').on('click', function() {
var $checkedItem = $(this).siblings('.side-main').find('input:checked');
var $chosenItem = $(this).siblings('.side-main').find('.chosen');
var checkedNum = $checkedItem.length;
var chosenNum = $chosenItem.length;
var chosenType = window.queryString.chosenType;
var tipMsg = '';
if ((checkedNum <= 0) && (chosenNum <= 0)) {
switch (chosenType) {
case '1' : tipMsg = '风格';
break;
case '2' : tipMsg = '时间';
break;
case '3' : tipMsg = '潮流顾问';
break;
case '4' : tipMsg = '套餐';
break;
case '5' : tipMsg = '发型师';
break;
}
tip.show('请选择' + tipMsg);
} else {
var chosenText = $checkedItem.attr('data') || $chosenItem.text();
var chosenText2 = $chosenItem.attr('date2');
var packageId = $checkedItem.attr('id');
switch (chosenType) {
case '4' :
window.setCookie('chosenPackage', chosenText);
window.setCookie('packageId', packageId);
window.setCookie('packageLimit', $checkedItem.attr('limit'));
window.setCookie('packageStyle', $checkedItem.attr('styleid'));
break;
case '1' :
window.setCookie('chosenStyle', chosenText);
break;
case '2' :
window.setCookie('chosenTime', chosenText2);
break;
case '3' :
window.setCookie('chosenAdviser', chosenText);
window.setCookie('adviserId', packageId);
break;
case '5' :
window.setCookie('chosenCutter', chosenText);
break;
}
document.location.href = document.referrer;
}
});
// 取消订单
$('.order-btn a').on('click', function() {
diaLog.showDialog({
dialogText: '确认取消预约吗?',
hasFooter: {
leftBtnText: '我再想想',
rightBtnText: '确认取消'
}
}, function() {
$.ajax({
url: '/activity/trend/delOrder',
data: {
id: $('.order-btn a').attr('id')
},
success: function(result) {
if (result.code === 200) {
document.location.href = '//m.yohobuy.com/activity/trend/order-list?storeId=' + window.queryString.storeId;
} else {
tip.show(result.message);
}
},
error: function() {
tip.show('网络断开了~~~');
}
});
});
},
error: function() {
tip.show('获取时间列表失败~');
}
});
}
function orderSubmit() {
var type = 1;
var storeId = window.queryString.storeId;
var appointTime = parseInt(window.cookie('timeStr'));
var appointUserName = $('#name').val();
var appointMobile = parseInt($('#tel').val());
var uid = parseInt($('#uid').val());
var activityId = window.cookie('packageId') || window.cookie('adviserId') || window.cookie('travelId');
if (!window.cookie('packageId') && !window.cookie('adviserId')) {
type = 2;
}
var userNote = $('#note').val();
userNote = userNote.replace(/[\r\n]/g, "");
if (userNote === '添加备注(选填)') {
userNote = '';
}
var appointPersonNum = parseInt($('#num').val());
var age = parseInt($('#age').val()) || '';
var ageType = $('#age').parents('.chose-item').find('input:checked').next('label').text();
var styles = window.cookie('styleStr');
var sex = $('input[name=sex]:checked').next('label').attr('name') || '';
var appointContent = '{"name":"' + appointUserName + '","age":"' + age + ageType + '","sex":"' + sex + '","mobile":' + appointMobile + ',"num":' + appointPersonNum + ',"remark":"' + userNote + '"}';
$.ajax({
url: '/activity/trend/addOrder',
data: {
storeId: storeId,
appointTime: appointTime,
appointUserName: appointUserName,
appointMobile: appointMobile,
uid: uid,
activityId: activityId,
appointContent: appointContent,
userNote: userNote,
appointPersonNum: appointPersonNum,
styles: styles,
type: type
},
success: function(result) {
if (result.code === 200) {
document.location.href = '//m.yohobuy.com/activity/trend/success?storeId=' + window.queryString.storeId + '&typeStatus=' + window.queryString.typeStatus;
// 修改弹框样式
$('.dialog-left-btn').css('color', '#999');
$('.dialog-right-btn').css('color', '#007aff');
});
// 加减人数按钮
$num.find('.plus-btn').on('click', function() {
if (!$('.chosen-time').val()) {
tip.show('请先选择预约时间');
} else {
tip.show(result.message);
var limitNum = parseInt($num.find('input').attr('max'));
if (parseInt($num.find('input').val()) < limitNum) {
num = parseInt($num.find('input').val()) + 1;
$num.find('input').val(num);
} else {
tip.show('可预约人数已达上限');
}
}
},
error: function() {
tip.show('网络断开了~~~');
});
$num.find('.minus-btn').on('click', function() {
if (parseInt($num.find('input').val()) > 1) {
num = parseInt($num.find('input').val()) - 1;
$num.find('input').val(num);
} else {
tip.show('人数不能小于1');
}
});
sNum = $navUl.find('.nav-item').length;
sWidth = $navUl.find('.nav-item').width();
$navUl.width(sNum * sWidth);
if ($('.wrapper').length > 0) {
myScroll = new IScroll('.wrapper', {
scrollX: true,
scrollY: false,
preventDefault: false,
});
// 通过拖拽选择时间段
myScroll.on('scrollStart', function() {
$navUl.addClass('srolling');
return false;
});
myScroll.on('scrollEnd', function() {
if ($navUl.hasClass('srolling')) {
$navUl.removeClass('srolling');
var thisPo = Math.ceil((0 - myScroll.x) / sWidth + 1.5);
autoScroll(thisPo);
getTimeList();
}
});
}
});
}
function diaHide() {
$('#dialog-wrapper').hide();
}
// 通过点击选择时间段
$navUl.find('.nav-item').on('click', function() {
if (!$(this).hasClass('disable')) {
var thisPo = $(this).index();
autoScroll(thisPo);
getTimeList();
}
});
function removeByValue(arr, val) {
for (var i=0; i<arr.length; i++) {
if (arr[i] == val) {
arr.splice(i, 1);
break;
}
}
}
$('.open-right').on('click', function() {
openId = $(this).attr('open-data');
$('#' + openId).removeClass('back');
$('#' + openId).addClass('active');
});
function checkSubmit() {
var needNnow = $('.need-know').find('input:checked').length;
if (needNnow > 0) {
var $require = $('.require');
var checkSubmit = false;
$require.each(
function() {
if ($(this).val() === '') {
var errText = $(this).attr('label');
tip.show('请输入' + errText);
checkSubmit = false;
return false;
} else {
var thisId = $(this).attr('id');
switch (thisId) {
case 'name' :
var reg = /^[\u4e00-\u9fa5]{1,10}$/;
var val = $(this).val();
if (!reg.test(val)) {
tip.show('姓名请输入10个以内汉字');
checkSubmit = false;
return false;
} else {
checkSubmit = true;
}
break;
case 'tel' :
var reg = /^1[34578]\d{9}$/;
var val = $(this).val();
if (!reg.test(val)) {
tip.show('手机号请输入11位数字');
checkSubmit = false;
} else {
checkSubmit = true;
$('.dia-tip').on('click', function() {
checkSubmit();
});
$('.tab .tab-top span').on('click', function() {
var $this = $(this);
var tabIndex = $this.index();
$this.addClass('active').siblings('span').removeClass('active');
$this.parents('.tab').find('.tab-item:eq(' + tabIndex + ')').show().siblings('.tab-item').hide();
});
$('.tab-item:first').show();
// 选择风格
if ($('.style-ul').length > 0) {
styleTotal = window.cookie('packageLimit');
if (window.cookie('packageStyle')) {
$('.style-ul:eq(0) li').each(
function() {
var $totalId = $(this).attr('id');
var $packageStyle = window.cookie('packageStyle').split(',');
for (var i = 0; i < $packageStyle.length; i++) {
if ($totalId == $packageStyle[i]) {
$(this).removeClass('disabled');
}
}
}
);
}
$('.style-tip .total').text(styleTotal);
$('.style-tip .now').text(styleNow);
}
var styleStr = new Array();
$('.style-ul li').on('click', function() {
$(this).parents('.style-ul').siblings('.style-ul').find('li').removeClass('chosen');
var $this = $(this);
var $thisId = $(this).attr('id');
if (!$this.hasClass('disabled')) {
if ($this.hasClass('chosen')) {
$this.removeClass('chosen');
if (!$this.hasClass('not')) {
removeByValue(styleStr, $thisId);
styleNow--;
} else {
styleStr = [];
styleNow = 0;
}
} else {
if (!$this.hasClass('not')) {
var limitNum = $('.total').text();
if (styleNow >= limitNum) {
tip.show('超过最大可选风格数');
return false;
break;
default:
checkSubmit = true;
}
$this.addClass('chosen');
styleStr.push($thisId);
styleNow++;
} else {
$this.addClass('chosen');
styleStr = [];
styleNow = 0;
}
}
}
);
if (checkSubmit) {
submitDia();
}
} else {
tip.show('请先接受上述条款');
}
}
$('.style-tip .now').text(styleNow);
window.setCookie('styleStr', styleStr);
});
function submitDia() {
diaLog.showDialog({
hasHeader: '温馨提示',
dialogText: '1、如需取消预约,可在预约时间前3天取消预约;<br />2、未取消的预约请按时到店。如未及时到店,我们将按爽约进行处理,一年中有3次爽约行为,本年内就无法再参与本店活动了哦。',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
if ($('.time-nav').length > 0) {
$('.time-nav ul').find('.nav-item:eq(2)').addClass('active');
getTimeList();
}
}, function() {
diaHide();
orderSubmit();
});
// 修改弹框样式
$('.tap-hightlight').css('color', '#007aff');
$('.dialog-content').css({'text-align':'left', 'padding':'0 0.75rem 0.5rem'});
}
function setCookieArr() {
var cookieArr = new Array();
$cookie.each(
function() {
cookieArr.push($(this).val());
}
);
window.setCookie('cookieArr', cookieArr);
}
if ($('.order-item').length > 0) {
$('.order-item').each(
function() {
var time = $(this).find('.time').attr('date') * 1000;
var weekTime = formatDate(time);
// 限制输入长度
function limitInp (obj, limit, show) {
var textLen = obj.val();
if (textLen.length > limit) {
if (show) {
tip.show('最多输入' + limit + '字');
$(this).find('.time').html(weekTime);
}
);
}
textLen = textLen.substring(0, limit);
obj.val(textLen);
return false;
}
}
function getAbleTime() {
var timeResult = '';
$.ajax({
url: '/activity/trend/getAbleTime',
data: {
activityType: window.queryString.typeStatus,
activityId: window.queryString.activityId || window.cookie('packageId') || window.cookie('travelId')
},
async: false,
success: function(result) {
if (result.code === 200) {
timeResult = result;
} else {
// tip.show(result.message);
if ($('#detail-time').length > 0) {
var time = $('#detail-time').attr('date') * 1000;
var weekTime = formatDate(time);
var timeResult = getAbleTime();
$('#detail-time').html(weekTime);
if (timeResult.data === '') {
$('.chan-btn').show();
}
},
error: function() {
tip.show('网络断开了~~~');
}
});
return timeResult;
}
function _formatDay(day) {
return moment(day).format('MM月DD日 HH:mm');
};
// 清除cookie
function clearCookieArr (type) {
switch (type) {
case 1 :
window.setCookie('chosenStyle', '');
window.setCookie('chosenTime', '');
break;
case 2 :
window.setCookie('chosenPackage', '');
window.setCookie('chosenStyle', '');
window.setCookie('chosenTime', '');
break;
case 3 :
window.setCookie('chosenPackage', '');
window.setCookie('packageId', '');
window.setCookie('chosenStyle', '');
window.setCookie('chosenTime', '');
window.setCookie('chosenAdviser', '');
window.setCookie('adviserId', '');
window.setCookie('chosenCutter', '');
window.setCookie('iscutter', '');
window.setCookie('styleStr', '');
window.setCookie('timeStr', '');
window.setCookie('detailtTimeStr', '');
window.setCookie('radiobirth', '');
window.setCookie('radiosex', '');
window.setCookie('cookieArr', '');
window.setCookie('limitPerson', '');
window.setCookie('packageLimit', '');
window.setCookie('packageStyle', '');
window.setCookie('chosenClass', '');
window.setCookie('styleId', '');
break;
}
}
);
\ No newline at end of file
... ...