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

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