东风启辰小程序端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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