index.js 4.9 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3
const app = getApp();
Page({
  data: {
G
gongfuxiang 已提交
4
    load_status: 0,
D
v1.2.0  
devil_gong 已提交
5 6 7
    data_list_loding_status: 1,
    data_bottom_line_status: false,
    data_list: [],
8 9
    banner_list: [],
    navigation: [],
D
v1.2.0  
devil_gong 已提交
10 11 12
    common_shop_notice: null,
    common_app_is_enable_search: 1,
    common_app_is_enable_answer: 1,
G
gongfuxiang 已提交
13
    common_app_is_header_nav_fixed: 0,
G
gongfuxiang 已提交
14 15 16 17 18 19

    // 限时秒杀插件
    common_app_is_limitedtimediscount : 0,
    plugins_limitedtimediscount_data: null,
    plugins_limitedtimediscount_timer_title: '距离结束',
    plugins_limitedtimediscount_is_show_time: true,
D
v1.2.0  
devil_gong 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  },
  
  onShow() {
    this.init();
  },

  // 获取数据列表
  init() {
    var self = this;

    // 加载loding
    this.setData({
      data_list_loding_status: 1,
    });

    // 加载loding
D
1.6  
devil_gong 已提交
36
    my.request({
D
v1.2.0  
devil_gong 已提交
37 38 39 40
      url: app.get_request_url("index", "index"),
      method: "POST",
      data: {},
      dataType: "json",
D
1.6  
devil_gong 已提交
41
      header: { 'content-type': 'application/x-www-form-urlencoded' },
D
v1.2.0  
devil_gong 已提交
42 43 44 45 46 47 48
      success: res => {
        my.stopPullDownRefresh();
        self.setData({load_status: 1});

        if (res.data.code == 0) {
          var data = res.data.data;
          self.setData({
G
gongfuxiang 已提交
49
            data_bottom_line_status: true,
50 51 52
            banner_list: data.banner_list || [],
            navigation: data.navigation || [],
            data_list: data.data_list || [],
D
v1.2.0  
devil_gong 已提交
53 54 55
            common_shop_notice: data.common_shop_notice || null,
            common_app_is_enable_search: data.common_app_is_enable_search,
            common_app_is_enable_answer: data.common_app_is_enable_answer,
G
gongfuxiang 已提交
56
            common_app_is_header_nav_fixed: data.common_app_is_header_nav_fixed,
D
v1.2.0  
devil_gong 已提交
57
            data_list_loding_status: data.data_list.length == 0 ? 0 : 3,
G
gongfuxiang 已提交
58 59
            common_app_is_limitedtimediscount: data.common_app_is_limitedtimediscount || 0,
            plugins_limitedtimediscount_data: data.plugins_limitedtimediscount_data || null,
D
v1.2.0  
devil_gong 已提交
60
          });
G
gongfuxiang 已提交
61 62 63 64 65 66

          // 限时秒杀倒计时
          if (this.data.common_app_is_limitedtimediscount == 1 && this.data.plugins_limitedtimediscount_data != null)
          {
            this.plugins_limitedtimediscount_countdown();
          }
D
v1.2.0  
devil_gong 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        } else {
          self.setData({
            data_list_loding_status: 0,
            data_bottom_line_status: true,
          });

          my.showToast({
            type: "fail",
            content: res.data.msg
          });
        }
      },
      fail: () => {
        my.stopPullDownRefresh();
        self.setData({
          data_list_loding_status: 2,
          data_bottom_line_status: true,
          load_status: 1,
        });

        my.showToast({
          type: "fail",
          content: "服务器请求出错"
        });
      }
    });
  },

  // 搜索事件
  search_input_event(e) {
    var keywords = e.detail.value || null;
    if (keywords == null) {
      my.showToast({content: '请输入搜索关键字'});
      return false;
    }

    // 进入搜索页面
    my.navigateTo({
      url: '/pages/goods-search/goods-search?keywords='+keywords
    });
  },

  // 下拉刷新
  onPullDownRefresh() {
    this.init();
  },

G
gongfuxiang 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  // 显示秒杀插件-倒计时
  plugins_limitedtimediscount_countdown() {
    var hours = this.data.plugins_limitedtimediscount_data.time.hours || 0;
    var minutes = this.data.plugins_limitedtimediscount_data.time.minutes || 0;
    var seconds = this.data.plugins_limitedtimediscount_data.time.seconds || 0;
    var self = this;
    if (hours > 0 || minutes > 0 || seconds > 0) {
      // 秒
      var timer = setInterval(function () {
        if (seconds <= 0) {
          if (minutes > 0) {
            minutes--;
            seconds = 59;
          } else if (hours > 0) {
            hours--;
            minutes = 59;
            seconds = 59;
          }
        } else {
          seconds--;
        }

        self.setData({
G
gongfuxiang 已提交
137 138 139
          'plugins_limitedtimediscount_data.time.hours': (hours < 10 && hours.length == 1) ? 0 + hours : hours,
          'plugins_limitedtimediscount_data.time.minutes': (minutes < 10 && minutes.length == 1) ? 0 + minutes : minutes,
          'plugins_limitedtimediscount_data.time.seconds': (seconds < 10 && seconds.length == 1) ? 0 + seconds : seconds,
G
gongfuxiang 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
        });

        if (hours <= 0 && minutes <= 0 && seconds <= 0) {
          // 停止时间
          clearInterval(timer);

          // 活动已结束
          self.setData({
            plugins_limitedtimediscount_timer_title: '活动已结束',
            plugins_limitedtimediscount_is_show_time: false,
          });
        }
      }, 1000);
    } else {
      // 活动已结束
      self.setData({
        plugins_limitedtimediscount_timer_title: '活动已结束',
        plugins_limitedtimediscount_is_show_time: false,
      });
    }
  },

D
v1.2.0  
devil_gong 已提交
162 163 164 165 166 167 168 169 170 171
  // 自定义分享
  onShareAppMessage() {
    return {
      title: app.data.application_title,
      desc: app.data.application_describe,
      path: '/pages/index/index?share=index'
    };
  },

});