东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

291 linhas
6.6KB

  1. // pages/everyday/everyday.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. showClose:false,
  10. maskShow: false,
  11. taskShow: false,
  12. taskName:'',
  13. taskImgUrl:'',
  14. isSign:false,
  15. isShare:false,
  16. picturlList: [],
  17. picturlCurrent:0,
  18. isRegister:false,//是否已注册
  19. shareId:null,
  20. isFriendShare:false,//是否朋友分享过来的
  21. isAddress:false,//是否有地址
  22. },
  23. /**
  24. * 关闭任务窗
  25. */
  26. hiddenTask:function(){
  27. this.setData({
  28. maskShow: false,
  29. taskShow: false
  30. })
  31. },
  32. /**
  33. * 签到
  34. */
  35. signIn() {
  36. app.wxRequest(app.globalData.urlRoot +"task/signToday",{},res=>{
  37. if (res.code == 200) {
  38. if (!this.data.shareId) {
  39. this.setData({
  40. maskShow: false
  41. })
  42. } else {
  43. this.setData({
  44. isSign: false,
  45. isShare: true,
  46. showClose: true
  47. })
  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. wx.navigateTo({
  83. url: '../scout/scout'
  84. })
  85. },
  86. /**
  87. * 生命周期函数--监听页面加载
  88. */
  89. onLoad: function (options) {
  90. app.globalData.nowPage = 2;
  91. if (options.shareId) {
  92. this.data.isFriendShare = options.shareId;
  93. }
  94. if (app.globalData.openid) {
  95. this.loadFun();
  96. } else {
  97. app.globalData.openidSuccessFuc = this.loadFun;
  98. }
  99. },
  100. loadFun: function () {
  101. this.getTaskProgress();
  102. this.getOrderInfo();
  103. this.getShareId();
  104. this.getAddress();
  105. if (this.data.isFriendShare) {
  106. this.useShareId();
  107. }
  108. },
  109. /**
  110. * 生命周期函数--监听页面初次渲染完成
  111. */
  112. onReady: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面显示
  116. */
  117. onShow: function () {
  118. },
  119. /**
  120. * 生命周期函数--监听页面隐藏
  121. */
  122. onHide: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面卸载
  126. */
  127. onUnload: function () {
  128. },
  129. /**
  130. * 页面相关事件处理函数--监听用户下拉动作
  131. */
  132. onPullDownRefresh: function () {
  133. },
  134. /**
  135. * 页面上拉触底事件的处理函数
  136. */
  137. onReachBottom: function () {
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. return {
  144. title: '我正在参与“星探计划”,快来帮我解锁拼图吧,共享大奖!',
  145. imageUrl: this.data.imgUrl + "/shareImgs/" + Math.floor(Math.random() * 8 + 1)+".jpg",
  146. path: this.data.shareId ? "/pages/everyday/everyday?shareId=" + this.data.shareId :"/pages/everyday/everyday"
  147. }
  148. },
  149. getTaskProgress: function () {//获取任务完成度
  150. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: 1 }, res => {
  151. if (res.code == 200) {
  152. this.setData({
  153. picturlList: res.data
  154. })
  155. } else {
  156. wx.showToast({
  157. title: res.msg,
  158. icon: "none"
  159. })
  160. }
  161. }, this);
  162. },
  163. getOrderInfo: function () {//查询是否已注册
  164. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  165. if (res.code == 200) {
  166. if (res.data) {
  167. this.setData({
  168. isRegister: true
  169. })
  170. // app.globalData.isRegister = true;
  171. app.globalData.userMobile = res.data.mobile;
  172. }
  173. } else {
  174. console.log(res.msg)
  175. }
  176. }, this);
  177. },
  178. receive:function(){//领取购车红包
  179. this.getTaskAward();
  180. },
  181. getAddress: function () {//获取地址
  182. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  183. if (res.code == 200) {
  184. if(res.data){
  185. this.data.isAddress = true;
  186. }
  187. } else {
  188. wx.showToast({
  189. title: res.msg,
  190. icon: "none"
  191. })
  192. }
  193. }, this);
  194. },
  195. getTaskAward:function(){//领取购车券
  196. wx.wxRequest(app.globalData.urlRoot + "task/getTaskAward", { awardGiveId: this.data.picturlList[this.data.picturlCurrent]['awardGiveId']},res=>{
  197. if(res.code==200){
  198. if (this.data.isRegister){
  199. // if (res.data.needAddress) {
  200. // if (!this.data.isAddress) {
  201. // wx.navigateTo({
  202. // url: '../address/address',
  203. // })
  204. // }else{
  205. // wx.redirectTo({
  206. // url: '../myCenter/myCenter'
  207. // })
  208. // }
  209. // }else{
  210. wx.redirectTo({
  211. url: '../myCenter/myCenter'
  212. })
  213. // }
  214. }else{
  215. wx.navigateTo({
  216. url: '../receiveRegister/receiveRegister',
  217. })
  218. }
  219. }else{
  220. wx.showToast({
  221. title: res.msg,
  222. icon:"none"
  223. })
  224. }
  225. },this);
  226. },
  227. getSignInfo: function () {//查看当日是否签到
  228. app.wxRequest(app.globalData.urlRoot + "task/getSignInfo", {}, res => {
  229. if(res.code==200){
  230. if (res.data.state==0) {//未签到
  231. this.setData({
  232. showClose: false,
  233. maskShow: true,
  234. taskShow: true,
  235. isSign: true
  236. })
  237. }else{
  238. if (this.data.shareId){
  239. this.setData({
  240. showClose: true,
  241. maskShow: true,
  242. taskShow: true,
  243. isShare: true
  244. })
  245. }
  246. }
  247. }
  248. },this)
  249. },
  250. getShareId: function () {//获取分享id(查询今日是否已被助力)
  251. app.wxRequest(app.globalData.urlRoot + "task/getShareId", {}, res => {
  252. this.getSignInfo();
  253. if (res.code == 200) {
  254. this.setData({
  255. taskName: "集齐启辰星【" + res.data.shortName+"】碎片1/4",
  256. taskImgUrl: res.data.popPicUrl,
  257. })
  258. this.data.shareId = res.data.shareId;
  259. }
  260. }, this)
  261. },
  262. useShareId: function (shareId) {//发起助力
  263. app.wxRequest(app.globalData.urlRoot + "task/useShareId", { shareId: this.data.isFriendShare}, res => {
  264. console.log(res);
  265. this.setData({
  266. maskShow:false
  267. })
  268. }, this,"POST")
  269. },
  270. swiperChange(e) {//通过鼠标滑动改变swiper时
  271. if (e.detail.source == "touch") {
  272. this.setData({
  273. picturlCurrent: e.detail.current,
  274. })
  275. }
  276. }
  277. })