东风启辰小程序端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

318 lines
7.2KB

  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. var taskName = "集齐启辰星【" + res.data.shortName + "】碎片" + res.data.completeNum + "/" + res.data.childTotal;
  248. this.setData({
  249. taskName: taskName,
  250. taskImgUrl: res.data.popPicUrl,
  251. })
  252. this.data.shareId = res.data.shareId;
  253. }
  254. }, this)
  255. },
  256. useShareId: function (shareId) {//发起助力
  257. app.wxRequest(app.globalData.urlRoot + "task/useShareId", { shareId: this.data.isFriendShare}, res => {
  258. if(res.code==200){
  259. this.setData({
  260. hiddenFriendFrame: true,
  261. useShareData: res.data,
  262. maskShow: false
  263. })
  264. } else {
  265. this.getSignInfo();
  266. // wx.showToast({
  267. // title: res.msg,
  268. // icon:"none"
  269. // })
  270. }
  271. }, this,"POST")
  272. },
  273. swiperChange(e) {//通过鼠标滑动改变swiper时
  274. if (e.detail.source == "touch") {
  275. this.setData({
  276. picturlCurrent: e.detail.current,
  277. })
  278. }
  279. },
  280. ruleControl:function(e){
  281. this.setData({
  282. showRule: e.currentTarget.dataset.state
  283. })
  284. },
  285. hiddenFriendTip: function () {
  286. this.getSignInfo();
  287. this.setData({
  288. hiddenFriendFrame:false
  289. })
  290. },
  291. getUserWxMsg: function (e) {
  292. if (e.detail.errMsg == "getUserInfo:ok") {
  293. this.setData({
  294. userData: e.detail.userInfo
  295. })
  296. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  297. }
  298. },
  299. closeWindow:function(){//
  300. this.setData({
  301. tipWindow:0
  302. })
  303. }
  304. })