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

412 lines
9.9KB

  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. if (!app.globalData.addPageEnterState.everyday) {
  131. app.addPageEnter("800C896F3ED88D22DDE9C125CE61D0D2");
  132. app.globalData.addPageEnterState.everyday = true;
  133. }
  134. this.getTaskProgress();
  135. this.getAddress();
  136. // if (this.data.isFriendShare) {
  137. // this.useShareId();
  138. // }else{
  139. // }
  140. },
  141. /**
  142. * 生命周期函数--监听页面初次渲染完成
  143. */
  144. onReady: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload: function () {
  160. },
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh: function () {
  165. },
  166. /**
  167. * 页面上拉触底事件的处理函数
  168. */
  169. onReachBottom: function () {
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage: function (e) {
  175. if (e.from == "button") {
  176. return {
  177. title: '我正在参与“星探计划”,快来帮我解锁拼图吧,共享大奖!',
  178. imageUrl: this.data.taskImgUrl,
  179. // imageUrl: this.data.imgUrl + "/shareImgs/" + Math.floor(Math.random() * 8 + 1) + ".jpg",
  180. path: this.data.shareId ? "/pages/everyday/everyday?shareId=" + this.data.shareId : "/pages/everyday/everyday"
  181. }
  182. }else{
  183. return app.sharePack();
  184. }
  185. },
  186. getTaskProgress: function () {//获取任务完成度
  187. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: 1 }, res => {
  188. this.getSignInfo();
  189. if (res.code == 200) {
  190. this.setData({
  191. picturlList: res.data.taskData,
  192. totalSignDay: res.data.totalSignDay
  193. })
  194. } else {
  195. wx.showToast({
  196. title: res.msg,
  197. icon: "none"
  198. })
  199. }
  200. }, this);
  201. },
  202. receive:function(){//领取购车红包
  203. this.getTaskAward();
  204. },
  205. getAddress: function () {//获取地址
  206. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  207. if (res.code == 200) {
  208. if(res.data){
  209. this.data.isAddress = true;
  210. }
  211. } else {
  212. wx.showToast({
  213. title: res.msg,
  214. icon: "none"
  215. })
  216. }
  217. }, this);
  218. },
  219. getTaskAward:function(){//领取购车券
  220. if (!this.data.isAddress){
  221. this.setData({
  222. isAddressShow:true
  223. })
  224. return;
  225. }
  226. app.wxRequest(app.globalData.urlRoot + "award/getTaskAward", { awardGiveId: this.data.picturlList[this.data.picturlCurrent]['awardGiveId']},res=>{
  227. if(res.code==200){
  228. this.data.picturlList[this.data.picturlCurrent]['awardState'] = -1;
  229. this.setData({
  230. getReward:res.data[0],
  231. picturlList: this.data.picturlList
  232. })
  233. // if (res.data.needAddress != 0 && !this.data.isAddress){
  234. // this.setData({
  235. // tipWindow: 2
  236. // })
  237. // } else if (res.data.needAddress == 0){
  238. this.setData({
  239. tipWindow: 1
  240. })
  241. // }
  242. }else{
  243. wx.showToast({
  244. title: res.msg,
  245. icon:"none"
  246. })
  247. }
  248. },this);
  249. },
  250. userRegister: function () {
  251. wx.navigateTo({
  252. url: '/pages/address/address',
  253. })
  254. },
  255. getSignInfo: function () {//查看当日是否签到
  256. app.wxRequest(app.globalData.urlRoot + "task/getSignInfo", {}, res => {
  257. if(res.code==200){
  258. if (res.data.state==0) {//未签到
  259. this.aniFun(500, 0, res.data.popData.childId);
  260. setTimeout(()=>{
  261. this.aniFun(500, 1, res.data.popData.childId);
  262. setTimeout(() => {
  263. this.aniFun(500, 0, res.data.popData.childId);
  264. setTimeout(() => {
  265. this.aniFun(500, 1, res.data.popData.childId);
  266. setTimeout(() => {
  267. this.setData({
  268. signState: false,
  269. signData: res.data.popData,
  270. picturlCurrent: res.data.popData.parentId - 1
  271. })
  272. }, 500)
  273. }, 500)
  274. }, 500)
  275. }, 500)
  276. }
  277. }
  278. },this)
  279. },
  280. getShareId: function () {//获取分享id(查询今日是否已被助力)
  281. app.wxRequest(app.globalData.urlRoot + "task/getShareId", {}, res => {
  282. if (res.code == 200) {
  283. if (res.data.shareId){
  284. this.setData({
  285. showClose: true,
  286. maskShow: true,
  287. taskShow: true,
  288. isShare: true
  289. })
  290. }
  291. var taskName = "集齐启辰星【" + res.data.shortName + "】碎片" + res.data.completeNum + "/" + res.data.childTotal;
  292. this.setData({
  293. taskName: taskName,
  294. taskImgUrl: res.data.popPicUrl,
  295. })
  296. this.data.shareId = res.data.shareId;
  297. }
  298. }, this)
  299. },
  300. useShareId: function (shareId) {//发起助力
  301. app.wxRequest(app.globalData.urlRoot + "task/useShareId", { shareId: this.data.isFriendShare}, res => {
  302. if(res.code==200){
  303. this.setData({
  304. hiddenFriendFrame: true,
  305. useShareData: res.data,
  306. maskShow: false
  307. })
  308. } else {
  309. // this.getSignInfo();
  310. // wx.showToast({
  311. // title: res.msg,
  312. // icon:"none"
  313. // })
  314. }
  315. }, this,"POST")
  316. },
  317. swiperChange(e) {//通过鼠标滑动改变swiper时
  318. if (e.detail.source == "touch") {
  319. this.setData({
  320. picturlCurrent: e.detail.current,
  321. })
  322. }
  323. },
  324. ruleControl:function(e){
  325. wx.navigateTo({
  326. url: '/pages/fragmentRule/fragmentRule'
  327. })
  328. // this.setData({
  329. // showRule: e.currentTarget.dataset.state
  330. // })
  331. },
  332. hiddenFriendTip: function () {
  333. // this.getSignInfo();
  334. this.setData({
  335. hiddenFriendFrame:false
  336. })
  337. },
  338. getUserWxMsg: function (e) {
  339. if (e.detail.errMsg == "getUserInfo:ok") {
  340. this.setData({
  341. userData: e.detail.userInfo
  342. })
  343. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  344. }
  345. },
  346. closeWindow:function(){//
  347. this.setData({
  348. tipWindow:0
  349. })
  350. },
  351. lookAddress: function () {
  352. this.addressControl();
  353. },
  354. tipWindow: function () {
  355. this.setData({
  356. isAddressShow: false
  357. })
  358. },
  359. addressControl: function () {//跳转到地址管理
  360. this.setData({
  361. addressShow: !this.data.addressShow
  362. })
  363. if (this.data.addressShow == false){
  364. this.tipWindow();
  365. }
  366. if (this.data.isAddress == false && this.data.addressShow==false) {
  367. this.getAddress();
  368. }
  369. },
  370. aniFun(duration, opacity,nums,type) {
  371. var animation = wx.createAnimation({
  372. duration: duration
  373. });
  374. if (type) {
  375. animation.scale(type).step();
  376. } else {
  377. animation.opacity(opacity).step();
  378. }
  379. if (nums == 1) {
  380. this.setData({
  381. ani1: animation.export()
  382. })
  383. } else if (nums == 2) {
  384. this.setData({
  385. ani2: animation.export()
  386. })
  387. } else if (nums == 3) {
  388. this.setData({
  389. ani3: animation.export()
  390. })
  391. } else if (nums == 4) {
  392. this.setData({
  393. ani4: animation.export()
  394. })
  395. }
  396. }
  397. })