poster.js 3.8 KB
Newer Older
D
devil 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
const app = getApp();
Page({
  data: {
    data_list_loding_status: 1,
    data_list_loding_msg: '加载中...',
    data_bottom_line_status: false,
    user_share_poster: null,
    user_share_qrode: null,
    user_share_url: null,
  },

  onLoad() {
    this.init();
  },

  onShow() {
    app.set_nav_bg_color_main('#ff6a80');
  },

  init() {
    var self = this;
    my.showLoading({ content: "加载中..." });
    this.setData({
      data_list_loding_status: 1
    });

    my.request({
      url: app.get_request_url("index", "poster", "distribution"),
      method: "POST",
      data: {},
      dataType: "json",
      success: res => {
        my.hideLoading();
        my.stopPullDownRefresh();
        if (res.data.code == 0) {
          var data = res.data.data;
          self.setData({
            user_share_poster: data.user_share_poster || null,
            user_share_qrode: data.user_share_qrode || null,
            user_share_url: data.user_share_url || null,
            data_list_loding_status: 3,
            data_bottom_line_status: true,
            data_list_loding_msg: '',
          });

          // 是否全部没数据
          if (self.data.user_share_poster == null && self.data.user_share_qrode == null && self.data.user_share_url == null)
          {
            self.setData({
              data_list_loding_status: 0,
              data_bottom_line_status: false,
            });
          }
        } else {
          self.setData({
            data_list_loding_status: 2,
            data_bottom_line_status: false,
            data_list_loding_msg: res.data.msg,
          });
          if (app.is_login_check(res.data, self, 'init')) {
            app.showToast(res.data.msg);
          }
        }
      },
      fail: () => {
        my.hideLoading();
        my.stopPullDownRefresh();
        self.setData({
          data_list_loding_status: 2,
          data_bottom_line_status: false,
          data_list_loding_msg: '服务器请求出错',
        });

        app.showToast("服务器请求出错");
      }
    });
  },

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

  // 刷新海报
  poster_refresh_event(e) {
    my.showLoading({ content: "处理中..." });
    my.request({
      url: app.get_request_url("refresh", "poster", "distribution"),
      method: "POST",
      data: {},
      dataType: "json",
      success: res => {
        my.hideLoading();
        if (res.data.code == 0) {
          this.setData({ user_share_poster: res.data.data});
          app.showToast(res.data.msg, "success");
        } else {
          if (app.is_login_check(res.data, self, 'init')) {
            app.showToast(res.data.msg);
          }
        }
      },
      fail: () => {
        my.hideLoading();
        app.showToast("服务器请求出错");
      }
    });
  },

  // 图片查看事件
  images_show_event(e) {
    var value = e.currentTarget.dataset.value || null;
    if (value != null) {
      my.previewImage({
        current: 0,
        urls: [value]
      });
    } else {
      app.showToast('宣传图片地址有误');
    }
  },

  // 二维码保存事件
  qrcode_save_event(e) {
    var value = e.currentTarget.dataset.value || null;
    if (value != null) {
      my.saveImage({
        url: value,
        showActionSheet: true,
        success: () => {
          app.showToast('保存成功', 'success');
        },
        fail: (res) => {
          app.showToast('保存失败');
        },
      });
    } else {
      app.showToast('图片地址有误');
    }
  },

  // url事件
  url_event(e) {
    if ((this.data.user_share_url || null) != null) {
      my.setClipboard({
        text: this.data.user_share_url,
        success(res) {
          app.showToast('复制成功', 'success');
        }
      })
    } else {
      app.showToast('链接地址有误');
    }
  },
});