| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- var util = require('../../utils/util.js')
- var app = getApp();
- Page({
- data: {
- inTheaters: {},
- comingSoon: {},
- top250: {},
- searchResult: {},
- containerShow: true,
- searchPanelShow: false,
- searchText:""
- },
-
- onLoad: function (event) {
- // var inTheatersUrl = app.globalData.doubanBase +
- // "/v2/movie/in_theaters" + "?start=0&count=6";
- // var comingSoonUrl = app.globalData.doubanBase +
- // "/v2/movie/coming_soon" + "?start=0&count=6";
- // var top250Url = app.globalData.doubanBase +
- // "/v2/movie/top250" + "?start=0&count=6";
- // this.getMovieListData(inTheatersUrl, "inTheaters", "正在热映");
- // this.getMovieListData(comingSoonUrl, "comingSoon", "即将上映");
- // this.getMovieListData(top250Url, "top250", "豆瓣Top250");
- },
- onMoreTap: function (event) {
- var category = event.currentTarget.dataset.category;
- wx.navigateTo({
- url: "more-movie/more-movie?category=" + category
- })
- },
- open : function (e){
-
- }
- ,
- onMovieTap: function (event) {
- var movieId = event.currentTarget.dataset.movieid;
- wx.navigateTo({
- url: "movie-detail/movie-detail?id=" + movieId
- })
- },
- //onload方法中调用
- getMovieListData: function (url, settedKey, categoryTitle) {
- wx.showNavigationBarLoading()
- var that = this;
- wx.request({
- url: url,
- method: 'GET',
- header: {
- "Content-Type": "json"
- },
- success: function (res) {
- that.processDoubanData(res.data, settedKey, categoryTitle)
- },
- fail: function (error) {
- console.log(error)
- }
- })
- },
- processDoubanData: function (moviesDouban, settedKey, categoryTitle) {
- var movies = [];
- for (var idx in moviesDouban.subjects) {
- var subject = moviesDouban.subjects[idx];
- var title = subject.title;
- if (title.length >= 6) {
- title = title.substring(0, 6) + "...";
- }
- var score = subject.rating.average + "";
- var temp = {
- stars: util.convertToStarsArray(subject.rating.stars),
- title: title,
- average: score.length == 1 ? subject.rating.average + '.0' : subject.rating.average,
- coverageUrl: subject.images.large,
- movieId: subject.id
- }
- movies.push(temp)
- }
- var readyData = {};
- readyData[settedKey] = {
- categoryTitle: categoryTitle,
- movies: movies
- }
- this.setData(readyData);
- wx.hideNavigationBarLoading();
- },
- //点击搜索框,让container隐藏,搜索条显示
- onBindFocus: function (event) {
- this.setData({
- containerShow: false,
- searchPanelShow: true
- })
- },
- //搜索框失去焦点开始搜索
- onBindBlur: function (event) {
- var text = event.detail.value;
- var searchUrl = app.globalData.doubanBase + "/v2/movie/search?q=" + text;
- this.getMovieListData(searchUrl, "searchResult", "");
- },
- //点击输入框的X 关闭
- onCancelImgTap: function (event) {
- this.setData({
- containerShow: true,
- searchPanelShow: false,
- searchResult: {},
- searchText:""
- });
- },
- onShareAppMessage: function () {
- return {
- title: '豆瓣电影',
- desc: '一起看电影吧~'
- }
- }
- })
|