You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

487 lines
12 KiB

5 years ago
// pages/activity/index.js
var app = getApp()
import util from "../../../utils/util"
import commonApi from "../../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
isYL: false,
selectDay: new Date().getTime(),
3 years ago
days: [ '日','一', '二', '三', '四', '五', '六'],
types: [null, 'show', 'exhibition', 'scene', 'movie', 'lecture', 'other','huimin'],
weeks: [],
pageNo: 1,
sort: "distance",
list: [],
date: null,
total: 1,
areas: ['姑苏', '吴江', '苏州'],
area: 0,
3 years ago
type: 9,
movieType: 1,
moreFlag: true,
lat: "",
lon: "",
keywords: "",
3 years ago
realKeywords: "",
movieAreas:[],
movieArea:0,
defaultDate: "2020-3-31",
startDay: "sunday",
showDate: ""
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
3 years ago
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
3 years ago
this.getMovieArea()
5 years ago
let d = new Date();
let year = d.getFullYear();
let month = d.getMonth() + 1;
let day = d.getDate();
// 接口用的格式 2026-02-09
let apiDate = [year, month > 9 ? month : '0' + month, day > 9 ? day : '0' + day].join('-');
// 显示用的格式 2026年2月9日
let showDateStr = `${year}${month}${day}`;
this.setData({
selectDay: d.getTime(),
date: apiDate,
showDate: showDateStr // 赋值给显示变量
})
5 years ago
this.getWeekDay();
commonApi._post("pbservice/Other/getSuzhouAreas").then(res => {
5 years ago
res.data.unshift({
area_code: "",
area_name: "苏州市"
5 years ago
})
if (options.area_code) {
let index = res.data.findIndex(item => item.area_code == options.area_code);
5 years ago
this.setData({
area: index
5 years ago
})
}
5 years ago
this.setData({
areas: res.data
})
let that = this
wx.getLocation({
type: 'gcj02',
success: function (res) {
that.setData({
lat: res.latitude,
lon: res.longitude
})
that.getList()
},
fail: function () {
that.getList()
}
5 years ago
})
})
},
formatChineseDate(dateStr) {
if (!dateStr) return "";
let d = typeof dateStr === 'object' ? dateStr : new Date(dateStr.replace(/-/g, '/'));
return `${d.getFullYear()}${d.getMonth() + 1}${d.getDate()}`;
},
selectDate: function (e) {
console.log(e.detail);
this.setData({
date: e.detail,
showDate: this.formatChineseDate(e.detail),
pageNo: 1,
list: [],
total: 1,
moreFlag: true
})
this.getList()
},
changeType: function (e) {
5 years ago
this.setData({
type: e.currentTarget.dataset.type,
list: [],
total: 1,
pageNo: 1,
moreFlag: true,
3 years ago
// keywords: "",
// realKeywords: ""
5 years ago
})
3 years ago
console.log(this.data.type);
5 years ago
this.getList();
},
3 years ago
getMovieArea(){
commonApi._post("act/get_suzhou_areas_syt").then(res => {
res.data.unshift({
area_id: "",
area_title: "苏州市"
})
this.setData({
movieAreas:res.data
})
this.getList()
})
},
changeArea: function (e) {
5 years ago
this.setData({
area: e.detail.value,
list: [],
total: 1,
pageNo: 1,
moreFlag: true
5 years ago
})
this.getList()
},
// 获取当前选择日期的一周日期范围
getWeekDay: function () {
var myDate = this.data.selectDay,
daySecond = 24 * 60 * 60 * 1000,
reslist = [];
for (let i = myDate - daySecond * 3; i <= myDate + daySecond * 3; i = i + daySecond) {
let day = new Date(i),
putDate = day.getDate();
putDate = putDate >= 10 ? putDate : '0' + putDate
5 years ago
let item = {
times: i,
day: this.data.days[day.getDay()],
date: putDate,
isSelect: i == myDate
};
3 years ago
5 years ago
reslist.push(item);
}
this.setData({
weeks: reslist
})
},
yulan: function (e) {
5 years ago
let flag = e.currentTarget.dataset.flag;
if (flag == 0 && this.data.isYL || flag == 1 && this.data.isYL == false) return;
5 years ago
this.setData({
isYL: flag == 0,
list: [],
pageNo: 1,
total: 1,
moreFlag: true,
selectDay: null
5 years ago
})
this.getList()
},
getYL: function () {
5 years ago
let list = this.data.list;
commonApi._post("pbservice/Actcalendar/getActPrevList", {
page_no: this.data.pageNo,
category: this.data.types[this.data.type],
keywords: this.data.realKeywords,
area_key: this.data.areas[this.data.area].area_code,
lon:this.data.lon,
lat:this.data.lat,
page_num: 10
}).then(res => {
5 years ago
this.setData({
total: res.data.total,
list: list.concat(res.data.rows),
pageNo: this.data.pageNo + 1
5 years ago
})
})
},
5 years ago
// picker修改日期
bindDateChange: function (e) {
5 years ago
this.setData({
selectDay: new Date(e.detail.value).getTime(),
list: [],
pageNo: 1,
total: 1,
date: e.detail.value,
moreFlag: true,
isYL: false
5 years ago
})
this.getWeekDay();
this.getList();
},
// 点击修改日期
changeDate: function (e) {
let times = e.currentTarget.dataset.times,
d = new Date(times);
let month = d.getMonth() + 1,
day = d.getDate();
let monthStr = month > 10 ? month : ('0' + month);
let dayStr = day > 10 ? day : ('0' + day);
// 接口格式
let apiDate = d.getFullYear() + "-" + monthStr + "-" + dayStr;
// 中文格式
let cnDate = `${d.getFullYear()}${month}${day}`;
this.setData({
selectDay: times,
date: apiDate,
showDate: cnDate, // 【新增】同步更新显示日期
list: [],
pageNo: 1,
total: 1,
moreFlag: true,
isYL: false
})
this.getList();
},
getList: function () {
5 years ago
let list = this.data.list;
if (this.data.isYL) {
5 years ago
this.getYL();
return;
}
if (this.data.type == 4) {
5 years ago
this.getMovie();
return;
}
if (list.length >= this.data.total) return;
commonApi._post('pbservice/Actcalendar/getActList', {
page_no: this.data.pageNo,
date: this.data.date,
category: this.data.types[this.data.type],
keywords: this.data.realKeywords,
area_key: this.data.areas[this.data.area].area_code,
lat: this.data.lat,
lon: this.data.lon,
page_num: 10
}).then(res => {
5 years ago
let now = new Date().getTime();
res.data.rows.map(item => {
if (item.end_date) {
5 years ago
let end_date = item.end_date;
if (end_date.indexOf(":") == -1) {
end_date = end_date + " 23:59:59";
5 years ago
}
end_date = new Date(end_date.replace(/-/g, '/')).getTime();
if (end_date < now) {
5 years ago
item.is_end = true;
} else {
5 years ago
item.is_end = false;
}
}
})
5 years ago
this.setData({
total: res.data.total,
list: list.concat(res.data.rows),
pageNo: this.data.pageNo + 1
5 years ago
})
})
},
getMovie: function (e) {
if (!this.data.moreFlag) return;
let service = {
11 months ago
1: "getHotChannelMovieList",
2: "getCinemaList",
3: 'getSoonShowsList'
5 years ago
};
let data = {
page: this.data.pageNo,
pageSize: 10,
title:this.data.realKeywords
5 years ago
};
if (this.data.movieType == 2) {
5 years ago
data.lat = this.data.lat;
data.lon = this.data.lon;
data.is_price_sort = this.data.sort == 'price';
data.is_distance_sort = this.data.sort == 'distance';
3 years ago
data.city_code=this.data.movieAreas[this.data.movieArea].area_id||""
5 years ago
}
// if(this.data.movieType==1){
// data.queryDate = this.data.date
// }
if (this.data.movieType == 2 && !this.data.lon) {
5 years ago
wx.getLocation({
type: 'gcj02',
success: (res) => {
5 years ago
this.setData({
lat: res.latitude,
lon: res.longitude
5 years ago
})
data.lat = res.latitude;
data.lon = res.longitude;
commonApi._post('Cinema/' + service[this.data.movieType], data).then(res => {
res.data.map(item => {
if (item.distance || item.distance == 0) {
if (item.distance >= 1000) {
item.distance = (item.distance / 1000).toFixed(2) + 'km';
} else {
item.distance = (item.distance).toFixed(2) + 'm';
5 years ago
}
}
})
this.setData({
list: this.data.list.concat(res.data),
pageNo: this.data.pageNo + 1,
moreFlag: res.data.length < 10 ? false : true
5 years ago
})
})
},
fail: () => {
5 years ago
wx.showToast({
title: '请打开位置授权',
icon: 'none'
5 years ago
})
commonApi._post('Cinema/' + service[this.data.movieType], data).then(res => {
5 years ago
this.setData({
list: this.data.list.concat(res.data),
pageNo: this.data.pageNo + 1,
moreFlag: res.data.length < 10 ? false : true
5 years ago
})
})
}
})
} else {
commonApi._post('Cinema/' + service[this.data.movieType], data).then(res => {
res.data.map(item => {
if (item.distance || item.distance == 0) {
if (item.distance >= 1000) {
item.distance = (item.distance / 1000).toFixed(2) + 'km';
} else {
item.distance = (item.distance).toFixed(2) + 'm';
5 years ago
}
}
})
this.setData({
list: this.data.list.concat(res.data),
pageNo: this.data.pageNo + 1,
moreFlag: res.data.length < 10 ? false : true
5 years ago
})
})
}
},
setSort: function (e) {
5 years ago
let sort = e.currentTarget.dataset.sort;
if (this.data.sort == sort) sort = "";
5 years ago
this.setData({
sort: sort,
list: [],
total: 1,
pageNo: 1,
moreFlag: true
5 years ago
})
this.getList();
},
3 years ago
setCity(e){
this.setData({
movieArea: e.detail.value,
list: [],
total: 1,
pageNo: 1,
moreFlag: true
})
this.getList()
},
changeMovieType: function (e) {
5 years ago
let type = e.currentTarget.dataset.type;
this.setData({
movieType: type,
list: [],
pageNo: 1,
total: 1,
moreFlag: true,
realKeywords:''
5 years ago
})
this.getList()
},
gotoDetail: function (e) {
5 years ago
let item = e.currentTarget.dataset.item;
if (this.data.type == 4 && this.data.movieType != 2) {
12 months ago
// wx.navigateTo({
// url: '/pages/list/movieticket/list/info/index?id=' + item.third_id
// })
util.goMovieDetail(item.third_id || item.id)
} else if (this.data.type == 4) {
5 years ago
wx.navigateTo({
url: '/pages/list/movieticket/list/cinema/index?id=' + item.third_id
5 years ago
})
} else {
5 years ago
wx.navigateTo({
url: '/pages/info/activityInfo/index?id=' + item.id,
5 years ago
})
}
},
changeKeywords: function (e) {
5 years ago
this.setData({
keywords: e.detail.value
5 years ago
})
},
search: function () {
5 years ago
this.setData({
realKeywords: this.data.keywords,
list: [],
pageNo: 1,
total: 1,
3 years ago
moreFlag: true,
date:null,
// showDate: "",
isYL: this.data.type == 4 ? false: true,
3 years ago
selectDay: null
5 years ago
})
this.getList();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
5 years ago
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getList()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
3 years ago
},
onShareTimeline: function() {
return {
title: '君到苏州-活动日历',
query: '',
imageUrl: 'https://static.ticket.sz-trip.com/xcxImages/index/icon1New.png'
}
5 years ago
}
3 years ago
5 years ago
})