Page({
  data: {
    posterList: [
      { url: "/images/img_ad1.png", selected: true },
      { url: "/images/img_ad2.png", selected: false },
      { url: "/images/img_ad1.png", selected: false },
      { url: "/images/img_ad2.png", selected: false }
    ],
  },
  onLoad() {
    // let context = this;
    // this.setData({
    //   posterList: context.requestPosterList()
    // });
  },

  onPosterItemClicked(event) {
    console.log("event==>" + JSON.stringify(event));
    //获取点击的index
    var index = event.target.dataset.index;
    var tempList = [];
    tempList = tempList.concat(this.data.posterList);
    //遍历改变posterList状态
    for (var i = 0; i < tempList.length; i++) {
      if (i == index) {
        tempList[i].selected = true;
      } else {
        tempList[i].selected = false;
      }
    }
    this.setData({
      posterList: tempList
    })
  },

  /** 请求服务器加载海报图片*/
  requestPosterList() {
    //just test
    return [
      { url: "/images/img_ad1.png", selected: true },
      { url: "/images/img_ad2.png", selected: false },
      { url: "/images/img_ad1.png", selected: false },
      { url: "/images/img_ad2.png", selected: false }
    ];
  },

  /**
   * 返回按钮 
   */
  onPosterPageBack(event) {
    console.log("event==>" + JSON.stringify(event));
  }
});
