东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

everyday.js 7.1KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. wx.navigateTo({
  84. url: '../scout/scout'
  85. })
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad: function (options) {
  91. app.globalData.nowPage = 2;
  92. if (app.globalData.userInfoData) {
  93. this.setData({
  94. userData: app.globalData.userInfoData
  95. })
  96. }
  97. if (options.shareId) {
  98. this.data.isFriendShare = options.shareId;
  99. }
  100. if (app.globalData.openid) {
  101. this.loadFun();
  102. } else {
  103. app.globalData.openidSuccessFuc = this.loadFun;
  104. }
  105. },
  106. loadFun: function () {
  107. this.getTaskProgress();
  108. this.getAddress();
  109. if (this.data.isFriendShare) {
  110. this.useShareId();
  111. }else{
  112. this.getSignInfo();
  113. }
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面显示
  122. */
  123. onShow: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面隐藏
  127. */
  128. onHide: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面卸载
  132. */
  133. onUnload: function () {
  134. },
  135. /**
  136. * 页面相关事件处理函数--监听用户下拉动作
  137. */
  138. onPullDownRefresh: function () {
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. },
  145. /**
  146. * 用户点击右上角分享
  147. */
  148. onShareAppMessage: function (e) {
  149. if (e.from == "button") {
  150. return {
  151. title: '我正在参与“星探计划”,快来帮我解锁拼图吧,共享大奖!',
  152. imageUrl: this.data.imgUrl + "/shareImgs/" + Math.floor(Math.random() * 8 + 1) + ".jpg",
  153. path: this.data.shareId ? "/pages/everyday/everyday?shareId=" + this.data.shareId : "/pages/everyday/everyday"
  154. }
  155. }else{
  156. return app.sharePack();
  157. }
  158. },
  159. getTaskProgress: function () {//获取任务完成度
  160. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: 1 }, res => {
  161. if (res.code == 200) {
  162. this.setData({
  163. picturlList: res.data
  164. })
  165. } else {
  166. wx.showToast({
  167. title: res.msg,
  168. icon: "none"
  169. })
  170. }
  171. }, this);
  172. },
  173. receive:function(){//领取购车红包
  174. this.getTaskAward();
  175. },
  176. getAddress: function () {//获取地址
  177. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  178. if (res.code == 200) {
  179. if(res.data){
  180. this.data.isAddress = true;
  181. }
  182. } else {
  183. wx.showToast({
  184. title: res.msg,
  185. icon: "none"
  186. })
  187. }
  188. }, this);
  189. },
  190. getTaskAward:function(){//领取购车券
  191. app.wxRequest(app.globalData.urlRoot + "award/getTaskAward", { awardGiveId: this.data.picturlList[this.data.picturlCurrent]['awardGiveId']},res=>{
  192. if(res.code==200){
  193. this.data.picturlList[this.data.picturlCurrent]['awardState'] = -1;
  194. this.setData({
  195. getReward:res.data,
  196. picturlList: this.data.picturlList
  197. })
  198. if (res.data.needAddress != 0 && !this.data.isAddress){
  199. this.setData({
  200. tipWindow: 2
  201. })
  202. } else if (res.data.needAddress == 0){
  203. this.setData({
  204. tipWindow: 1
  205. })
  206. }
  207. }else{
  208. wx.showToast({
  209. title: res.msg,
  210. icon:"none"
  211. })
  212. }
  213. },this);
  214. },
  215. userRegister: function () {
  216. wx.navigateTo({
  217. url: '/pages/address/address',
  218. })
  219. },
  220. getSignInfo: function () {//查看当日是否签到
  221. app.wxRequest(app.globalData.urlRoot + "task/getSignInfo", {}, res => {
  222. if(res.code==200){
  223. if (res.data.state==0) {//未签到
  224. this.setData({
  225. showClose: false,
  226. maskShow: true,
  227. taskShow: true,
  228. isSign: true
  229. })
  230. }else{
  231. this.getShareId();
  232. }
  233. }
  234. },this)
  235. },
  236. getShareId: function () {//获取分享id(查询今日是否已被助力)
  237. app.wxRequest(app.globalData.urlRoot + "task/getShareId", {}, res => {
  238. if (res.code == 200) {
  239. if (res.data.shareId){
  240. this.setData({
  241. showClose: true,
  242. maskShow: true,
  243. taskShow: true,
  244. isShare: true
  245. })
  246. }
  247. this.setData({
  248. taskName: "集齐启辰星【" + res.data.shortName+"】碎片1/4",
  249. taskImgUrl: res.data.popPicUrl,
  250. })
  251. this.data.shareId = res.data.shareId;
  252. }
  253. }, this)
  254. },
  255. useShareId: function (shareId) {//发起助力
  256. app.wxRequest(app.globalData.urlRoot + "task/useShareId", { shareId: this.data.isFriendShare}, res => {
  257. if(res.code==200){
  258. this.setData({
  259. hiddenFriendFrame: true,
  260. useShareData: res.data,
  261. maskShow: false
  262. })
  263. } else {
  264. this.getSignInfo();
  265. // wx.showToast({
  266. // title: res.msg,
  267. // icon:"none"
  268. // })
  269. }
  270. }, this,"POST")
  271. },
  272. swiperChange(e) {//通过鼠标滑动改变swiper时
  273. if (e.detail.source == "touch") {
  274. this.setData({
  275. picturlCurrent: e.detail.current,
  276. })
  277. }
  278. },
  279. ruleControl:function(e){
  280. this.setData({
  281. showRule: e.currentTarget.dataset.state
  282. })
  283. },
  284. hiddenFriendTip: function () {
  285. this.getSignInfo();
  286. this.setData({
  287. hiddenFriendFrame:false
  288. })
  289. },
  290. getUserWxMsg: function (e) {
  291. if (e.detail.errMsg == "getUserInfo:ok") {
  292. this.setData({
  293. userData: e.detail.userInfo
  294. })
  295. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  296. }
  297. },
  298. closeWindow:function(){//
  299. this.setData({
  300. tipWindow:0
  301. })
  302. }
  303. })