|
|
// pages/index/index.js
|
|
|
import {
|
|
|
httpUtil,
|
|
|
location_city
|
|
|
} from '../../../utils/util'
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
latitude: '',
|
|
|
longitude: '',
|
|
|
city: '',
|
|
|
swiperIdx: 0,
|
|
|
swith_area: 0,
|
|
|
swich_space: ['综合排序', '近期上演', '限时钜惠'],
|
|
|
show_list: [
|
|
|
{ sort_type: '1', list: 'newMake', page: '1', has_more: 'false' },
|
|
|
{ sort_type: '2', list: 'newMake', page: '1', has_more: 'false' },
|
|
|
{ sort_type: '3', list: 'newMake', page: '1', has_more: 'false' },
|
|
|
],
|
|
|
screen_list: [], //开屏广告信息
|
|
|
// screen_imgUrl: 'https://mahuaimage2.oss-cn-qingdao.aliyuncs.com/mini_app/video/61382ab58bf84d41d8cd98f00b204e9800998ecf8427e.jpg',
|
|
|
isActionMarkShow: false, //开屏广告
|
|
|
isGiftMarkShow: false //首页弹窗
|
|
|
},
|
|
|
// 轮播图
|
|
|
bindchange(e) {
|
|
|
this.setData({
|
|
|
swiperIdx: e.detail.current
|
|
|
})
|
|
|
},
|
|
|
swith_tab: function (e) {
|
|
|
let swith_area = e.currentTarget.dataset.index
|
|
|
this.setData({
|
|
|
swith_area
|
|
|
})
|
|
|
if ('newMake' == this.data.show_list[swith_area].list) {
|
|
|
this.get_show_list(this.data.city_id, swith_area + 1, 1)
|
|
|
} else {
|
|
|
this.setData({ current_list: this.data.show_list[swith_area].list, no_more: !this.data.show_list[swith_area].has_more })
|
|
|
}
|
|
|
},
|
|
|
|
|
|
write_in(e) {
|
|
|
this.setData({ keyword: e.detail.value })
|
|
|
},
|
|
|
search(e) {
|
|
|
this.setData({ keyword: e.detail.value })
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/index/search/search?city_id=' + this.data.city_id + "&keyword=" + e.detail.value,
|
|
|
})
|
|
|
},
|
|
|
search1() {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/index/search/search?city_id=' + this.data.city_id + "&keyword=" + this.data.keyword,
|
|
|
})
|
|
|
},
|
|
|
|
|
|
// 封装 获取banner|获取城市列表|获取演出列表
|
|
|
// 方便刷新全局数据
|
|
|
refresh_info: function (city_id) {
|
|
|
var that = this
|
|
|
// 获取banner列表
|
|
|
httpUtil("/api/v1/banner-list", "get", {
|
|
|
city_id
|
|
|
}).then(res => {
|
|
|
if (0 != res.banner_list.length) {
|
|
|
that.setData({
|
|
|
banner_list: res.banner_list
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
// 获取search关键词
|
|
|
httpUtil("/api/v1/hot-search", "get").then(res => {
|
|
|
that.setData({ placeholder: res.keyword })
|
|
|
})
|
|
|
// 获取演出城市列表
|
|
|
httpUtil("/api/v1/city-list", "get", {
|
|
|
city_id
|
|
|
}).then(res2 => {
|
|
|
that.setData({
|
|
|
city_list: res2,
|
|
|
city_id: res2.current.city_id,
|
|
|
city: res2.current.city_name
|
|
|
})
|
|
|
})
|
|
|
|
|
|
// 获取演出列表
|
|
|
let sort_type = 1
|
|
|
let page = 1
|
|
|
this.get_show_list(city_id, sort_type, page)
|
|
|
// 获取开屏广告
|
|
|
httpUtil("/api/v1/home-promotion", "get", {
|
|
|
city_id
|
|
|
}).then(res => {
|
|
|
if (res.length == 0) {
|
|
|
return
|
|
|
}
|
|
|
let key = wx.getStorageSync('key')
|
|
|
// console.log(key);
|
|
|
// console.log(key.indexOf(res.id));
|
|
|
if(key.indexOf(res.id)!=-1){
|
|
|
// console.log('我尊在');
|
|
|
return
|
|
|
}
|
|
|
this.setData({
|
|
|
screen_list: res,
|
|
|
isActionMarkShow: true
|
|
|
})
|
|
|
})
|
|
|
wx.stopPullDownRefresh()
|
|
|
},
|
|
|
// 获取演出列表方法封装
|
|
|
get_show_list(city_id, sort_type, page) {
|
|
|
httpUtil("/api/v1/show-list", "get", {
|
|
|
city_id,
|
|
|
sort_type,
|
|
|
page
|
|
|
}).then(res => {
|
|
|
let show_list = this.data.show_list
|
|
|
show_list[sort_type - 1].list = res.show_list
|
|
|
show_list[sort_type - 1].has_more = res.has_more
|
|
|
this.setData({
|
|
|
show_list,
|
|
|
current_list: res.show_list,
|
|
|
no_more: !res.has_more
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
|
|
|
banner_nav: function (e) {
|
|
|
let url = e.currentTarget.dataset.key
|
|
|
console.log("前往地址:", url)
|
|
|
wx.navigateTo({
|
|
|
// url: '/pages/opera/show/show_detail'+e.currentTarget.dataset.key,
|
|
|
url
|
|
|
})
|
|
|
},
|
|
|
calendar_nav: function () {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/index/calendar/calendar?city_id=' + this.data.city_id,
|
|
|
})
|
|
|
},
|
|
|
area_nav: function () {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/index/city/selectcity?city_list=' + JSON.stringify(this.data.city_list),
|
|
|
// url: '/pages/index/city/selectcity'
|
|
|
})
|
|
|
},
|
|
|
|
|
|
show_detail: function (e) {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/opera/show/show_detail?cycle_id=' + e.currentTarget.dataset.cycle_id,
|
|
|
})
|
|
|
},
|
|
|
cancle_mark(e) {
|
|
|
let id=e.currentTarget.dataset.id
|
|
|
let key=wx.getStorageSync('key')
|
|
|
if(key.indexOf(id)==-1){
|
|
|
wx.setStorageSync('key',[...key,id])
|
|
|
}
|
|
|
this.setData({
|
|
|
isActionMarkShow: false,
|
|
|
isGiftMarkShow: true
|
|
|
})
|
|
|
},
|
|
|
advertisementMark_show() {
|
|
|
this.setData({
|
|
|
isActionMarkShow: true,
|
|
|
isGiftMarkShow: false
|
|
|
})
|
|
|
},
|
|
|
onlinkurl(e) {
|
|
|
let link_url = e.currentTarget.dataset.link_url
|
|
|
wx.navigateTo({
|
|
|
url: link_url
|
|
|
})
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
if (!getApp().globalData.city_id) {
|
|
|
// 默认北京写法
|
|
|
//location_city("beijing").then(res=>{
|
|
|
location_city().then(res => {
|
|
|
var city = res.city_info.city_name
|
|
|
var city_id = res.city_info.city_id
|
|
|
getApp().globalData.city_id = city_id
|
|
|
this.refresh_info(city_id)
|
|
|
})
|
|
|
} else {
|
|
|
this.refresh_info(getApp().globalData.city_id)
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function () {
|
|
|
wx.setStorageSync('key',[])
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () { },
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh: function () {
|
|
|
// wx.reLaunch({
|
|
|
// url: '/pages/index/index/index'
|
|
|
// })
|
|
|
this.refresh_info(getApp().globalData.city_id)
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function () {
|
|
|
let show_list = this.data.show_list
|
|
|
let current = show_list[this.data.swith_area]
|
|
|
if (current.has_more) {
|
|
|
wx.showNavigationBarLoading(); //在标题栏中显示加载图标
|
|
|
let page = parseInt(current.page) + 1
|
|
|
let city_id = this.data.city_id
|
|
|
let sort_type = current.sort_type
|
|
|
httpUtil("/api/v1/show-list", "get", { city_id, page, sort_type }).then(res => {
|
|
|
wx.hideNavigationBarLoading(); //完成停止加载图标
|
|
|
show_list[this.data.swith_area].list = current.list.concat(res.show_list)
|
|
|
show_list[this.data.swith_area].page = page
|
|
|
show_list[this.data.swith_area].has_more = res.has_more
|
|
|
this.setData({
|
|
|
show_list,
|
|
|
current_list: show_list[this.data.swith_area].list,
|
|
|
no_more: !res.has_more
|
|
|
})
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
this.setData({ no_more: true })
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage: function () {
|
|
|
return {
|
|
|
title: '开心麻花小程序 - 优惠购票',
|
|
|
path: '/pages/index/index/index',
|
|
|
imageUrl: 'https://mahuaimage.oss-cn-qingdao.aliyuncs.com/mini_app/share/home-share.png'
|
|
|
}
|
|
|
}
|
|
|
}) |