forked from nsjcy/frontEnd/nsjcy

liuwh
2020-03-29 9c7c21e8eacda173feb418bdfe739f7f97358233
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// pages/fzpxInfo/fzpxInfo.js
var app = getApp();
var Validator = require("../../utils/validate.tools.js");
const verify = Validator.Validator;
 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    user: app.globalData.imgUrl + '/image/user.svg',
    loading: false,
    peopleInfo: {},
    signStatus: '',
    id: "",
    topattList: [],
    bottomattList: [],
    statequeId: ''
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({
      id: options.id,
      signStatus: options.signStatus || '',
      flag: options.flag || '',
      loading: true
    });
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.url + '/api/activity/find?id=' + options.id,
      success: function(res) {
        console.log(res);
        that.setData({
          loading: false
        });
        wx.hideLoading();
        if (res.data.code == 0) {
          res.data.data.startTime = app.formatDate(res.data.data.startTime)
          if (res.data.data.activityStatus == 3) {
            if (res.data.data.queId) {
              that.setData({
                statequeId: res.data.data.queId
              })
            }
          } else {
            that.setData({
              statequeId: ''
            })
          }
          that.setData({
            activity: res.data.data,
            bottomattList: res.data.data.attList.filter((item) => (item.associateType == 1020)),
            topattList: res.data.data.attList.filter((item) => (item.associateType == 1000))
          })
          console.log('传过来', options.flag)
          console.log('传过来', options.signStatus)
          // 处理报名状态
          if (options.signStatus) {
            that.setData({
              signStatus: options.signStatus
            })
          } else {
            if (options.flag == 'true') {
              //可报名
              console.log('可报名')
              if (res.data.data.activityPersonNum < res.data.data.activityPersonQuota) {
                if (res.data.data.activityStatus == 1) {
                  that.setData({
                    canApply: true
                  })
                }
                if (res.data.data.activityStatus == 2) {
                  that.setData({
                    canApply: false,
                    statusWord: '活动正在进行'
                  })
                }
                if (res.data.data.activityStatus == 3) {
                  that.setData({
                    canApply: false,
                    statusWord: '活动已结束'
                  })
                }
              } else {
                that.setData({
                  canApply: false,
                  statusWord: '报名人数已满'
                })
              }
 
            } else {
              //不可报名
              console.log('不可报名')
              that.setData({
                canApply: false,
                statusWord: '您已报名'
              })
            }
          }
 
        }
      }
    })
  },
 
  // 跳转
  linkFunction: function() {
    wx.showToast({
      title: '抱歉,报名人数已满',
      icon: 'none',
      duration: 2000
    })
  },
 
  // 呼叫组织方
  makePhoneCall: function(e) {
    var phone = e.currentTarget.dataset['phone'];
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },
 
  //跳转问卷调查
  businessSchedule: function(e) {
    var id = e.currentTarget.dataset['id'];
    wx.navigateTo({
      url: '/pages/createSub/createSub?id=' + id,
    })
  },
 
  inputChange: function(e) {
    var name = e.currentTarget.dataset.name;
    this.setData({
      peopleInfo: {
        ...this.data.peopleInfo,
        [name]: e.detail.value
      }
    })
  },
 
  // 签到
  sign: function() {
    var id = this.data.id;
    var userinfo = wx.getStorageSync("user");
    var userId = userinfo.id;
    // 只允许从相机扫码
    wx.scanCode({
      onlyFromCamera: true,
      success(res) {
        console.log(res)
        wx.showLoading({
          title: '识别中',
        })
        wx.request({
          url: app.globalData.url + '/api/activity/sign?id=' + id + '&code=' + res.result + '&userId=' + userId,
          method: 'GET',
          header: {
            "Content-Type": "application/json"
          },
          success: function(res) {
            wx.hideLoading();
            if (res.data.code == 0) {
              wx.showToast({
                title: '签到成功!',
                icon: 'success',
                duration: 2000
              })
            } else {
              wx.showToast({
                title: '签到失败,请稍后重试!',
                icon: 'none'
              })
            }
          }
        })
      }
    })
  },
 
  // 返回
  goBack: function() {
    wx.navigateBack({
      delta: 1
    });
  },
 
  // 提交报名
  submit: function() {
    var peopleInfo = this.data.peopleInfo;
    var userinfo = wx.getStorageSync("user");
    var personId = userinfo.id;
 
    peopleInfo.personId = personId;
    peopleInfo.activityInfoId = this.data.id;
    peopleInfo.isHit = 0;
    if (!peopleInfo.proposerName) {
      return wx.showToast({
        title: '请填写姓名',
        icon: 'none'
      })
    }
    if (!peopleInfo.proposerPhone) {
      return wx.showToast({
        title: '请填写联系电话',
        icon: 'none'
      })
    } else {
      if (!verify.phone(peopleInfo.proposerPhone)) {
        return wx.showToast({
          title: '联系电话格式不正确',
          icon: 'none'
        })
      }
    }
    var that = this;
    wx.showLoading({
      title: '报名中',
    })
    wx.request({
      url: app.globalData.url + '/api/activity/activityApply',
      data: peopleInfo,
      method: 'POST',
      header: {
        "Content-Type": "application/json"
      },
      success: function(res) {
        wx.hideLoading();
        if (res.data.code == 0) {
          wx.reLaunch({
            url: '../index/index',
          }, wx.showToast({
            title: '报名成功!',
            icon: 'success',
            duration: 2000
          }))
        } else {
          wx.showToast({
            title: '报名失败,请稍后重试!',
            icon: 'none'
          })
        }
      }
    })
  }
})