东风启辰小程序端
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.

408 líneas
9.8KB

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