东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

331 linhas
7.7KB

  1. // pages/everyday/everyday.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. showRule:false,//是否显示游戏规则
  10. showClose:true,
  11. maskShow: false,
  12. taskShow: false,
  13. taskName:'',
  14. taskImgUrl:'',
  15. isSign:false,
  16. isShare:false,
  17. picturlList: [],
  18. picturlCurrent:0,
  19. shareId:null,
  20. isFriendShare:false,//是否朋友分享过来的
  21. isAddress:false,//是否有地址
  22. getReward:null,
  23. tipWindow:0,
  24. hiddenFriendFrame: false,
  25. userData: null,
  26. },
  27. /**
  28. * 关闭任务窗
  29. */
  30. hiddenTask:function(){
  31. this.setData({
  32. maskShow: false,
  33. taskShow: false
  34. })
  35. },
  36. /**
  37. * 签到
  38. */
  39. signIn() {
  40. app.wxRequest(app.globalData.urlRoot +"task/signToday",{},res=>{
  41. if (res.code == 200) {
  42. this.getTaskProgress();
  43. this.getShareId();
  44. this.setData({
  45. maskShow: false,
  46. isSign: false,
  47. isShare: false,
  48. showClose: true
  49. })
  50. }else{
  51. wx.showToast({
  52. title: res.msg,
  53. icon:"none"
  54. })
  55. }
  56. },this,"POST");
  57. },
  58. /**
  59. * 下个碎片
  60. */
  61. nextPicturl(){
  62. var max = this.data.picturlList.length-1;
  63. var current = this.data.picturlCurrent + 1;
  64. if (current <= max){
  65. this.setData({
  66. picturlCurrent: current
  67. })
  68. }
  69. },
  70. //上一个碎片
  71. prevPicturl(){
  72. var current = this.data.picturlCurrent - 1;
  73. if (current >= 0) {
  74. this.setData({
  75. picturlCurrent: current
  76. })
  77. }
  78. },
  79. /**
  80. * 星探任务
  81. */
  82. goScout() {
  83. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfo", {}, res => {
  84. if (res.code == 200) {
  85. app.globalData.certificationState = res.data.certificationState;
  86. wx.navigateTo({
  87. url: '/pages/scout/scout'
  88. })
  89. } else if (res.code == -307) {
  90. wx.navigateTo({
  91. url: '/pages/mobileVerification/mobileVerification'
  92. })
  93. } else if (res.code == -308) {
  94. wx.navigateTo({
  95. url: '/pages/scout/register/register'
  96. })
  97. }
  98. }, this);
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad: function (options) {
  104. app.globalData.nowPage = 2;
  105. if (app.globalData.userInfoData) {
  106. this.setData({
  107. userData: app.globalData.userInfoData
  108. })
  109. }
  110. if (options.shareId) {
  111. this.data.isFriendShare = options.shareId;
  112. }
  113. if (app.globalData.openid) {
  114. this.loadFun();
  115. } else {
  116. app.globalData.openidSuccessFuc = this.loadFun;
  117. }
  118. },
  119. loadFun: function () {
  120. this.getTaskProgress();
  121. this.getAddress();
  122. if (this.data.isFriendShare) {
  123. this.useShareId();
  124. }else{
  125. this.getSignInfo();
  126. }
  127. },
  128. /**
  129. * 生命周期函数--监听页面初次渲染完成
  130. */
  131. onReady: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面显示
  135. */
  136. onShow: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面隐藏
  140. */
  141. onHide: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面卸载
  145. */
  146. onUnload: function () {
  147. },
  148. /**
  149. * 页面相关事件处理函数--监听用户下拉动作
  150. */
  151. onPullDownRefresh: function () {
  152. },
  153. /**
  154. * 页面上拉触底事件的处理函数
  155. */
  156. onReachBottom: function () {
  157. },
  158. /**
  159. * 用户点击右上角分享
  160. */
  161. onShareAppMessage: function (e) {
  162. if (e.from == "button") {
  163. return {
  164. title: '我正在参与“星探计划”,快来帮我解锁拼图吧,共享大奖!',
  165. imageUrl: this.data.imgUrl + "/shareImgs/" + Math.floor(Math.random() * 8 + 1) + ".jpg",
  166. path: this.data.shareId ? "/pages/everyday/everyday?shareId=" + this.data.shareId : "/pages/everyday/everyday"
  167. }
  168. }else{
  169. return app.sharePack();
  170. }
  171. },
  172. getTaskProgress: function () {//获取任务完成度
  173. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: 1 }, res => {
  174. if (res.code == 200) {
  175. this.setData({
  176. picturlList: res.data
  177. })
  178. } else {
  179. wx.showToast({
  180. title: res.msg,
  181. icon: "none"
  182. })
  183. }
  184. }, this);
  185. },
  186. receive:function(){//领取购车红包
  187. this.getTaskAward();
  188. },
  189. getAddress: function () {//获取地址
  190. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  191. if (res.code == 200) {
  192. if(res.data){
  193. this.data.isAddress = true;
  194. }
  195. } else {
  196. wx.showToast({
  197. title: res.msg,
  198. icon: "none"
  199. })
  200. }
  201. }, this);
  202. },
  203. getTaskAward:function(){//领取购车券
  204. app.wxRequest(app.globalData.urlRoot + "award/getTaskAward", { awardGiveId: this.data.picturlList[this.data.picturlCurrent]['awardGiveId']},res=>{
  205. if(res.code==200){
  206. this.data.picturlList[this.data.picturlCurrent]['awardState'] = -1;
  207. this.setData({
  208. getReward:res.data,
  209. picturlList: this.data.picturlList
  210. })
  211. if (res.data.needAddress != 0 && !this.data.isAddress){
  212. this.setData({
  213. tipWindow: 2
  214. })
  215. } else if (res.data.needAddress == 0){
  216. this.setData({
  217. tipWindow: 1
  218. })
  219. }
  220. }else{
  221. wx.showToast({
  222. title: res.msg,
  223. icon:"none"
  224. })
  225. }
  226. },this);
  227. },
  228. userRegister: function () {
  229. wx.navigateTo({
  230. url: '/pages/address/address',
  231. })
  232. },
  233. getSignInfo: function () {//查看当日是否签到
  234. app.wxRequest(app.globalData.urlRoot + "task/getSignInfo", {}, res => {
  235. if(res.code==200){
  236. if (res.data.state==0) {//未签到
  237. this.setData({
  238. showClose: false,
  239. maskShow: true,
  240. taskShow: true,
  241. isSign: true
  242. })
  243. }else{
  244. this.getShareId();
  245. }
  246. }
  247. },this)
  248. },
  249. getShareId: function () {//获取分享id(查询今日是否已被助力)
  250. app.wxRequest(app.globalData.urlRoot + "task/getShareId", {}, res => {
  251. if (res.code == 200) {
  252. if (res.data.shareId){
  253. this.setData({
  254. showClose: true,
  255. maskShow: true,
  256. taskShow: true,
  257. isShare: true
  258. })
  259. }
  260. var taskName = "集齐启辰星【" + res.data.shortName + "】碎片" + res.data.completeNum + "/" + res.data.childTotal;
  261. this.setData({
  262. taskName: taskName,
  263. taskImgUrl: res.data.popPicUrl,
  264. })
  265. this.data.shareId = res.data.shareId;
  266. }
  267. }, this)
  268. },
  269. useShareId: function (shareId) {//发起助力
  270. app.wxRequest(app.globalData.urlRoot + "task/useShareId", { shareId: this.data.isFriendShare}, res => {
  271. if(res.code==200){
  272. this.setData({
  273. hiddenFriendFrame: true,
  274. useShareData: res.data,
  275. maskShow: false
  276. })
  277. } else {
  278. this.getSignInfo();
  279. // wx.showToast({
  280. // title: res.msg,
  281. // icon:"none"
  282. // })
  283. }
  284. }, this,"POST")
  285. },
  286. swiperChange(e) {//通过鼠标滑动改变swiper时
  287. if (e.detail.source == "touch") {
  288. this.setData({
  289. picturlCurrent: e.detail.current,
  290. })
  291. }
  292. },
  293. ruleControl:function(e){
  294. this.setData({
  295. showRule: e.currentTarget.dataset.state
  296. })
  297. },
  298. hiddenFriendTip: function () {
  299. this.getSignInfo();
  300. this.setData({
  301. hiddenFriendFrame:false
  302. })
  303. },
  304. getUserWxMsg: function (e) {
  305. if (e.detail.errMsg == "getUserInfo:ok") {
  306. this.setData({
  307. userData: e.detail.userInfo
  308. })
  309. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  310. }
  311. },
  312. closeWindow:function(){//
  313. this.setData({
  314. tipWindow:0
  315. })
  316. }
  317. })