东风启辰小程序端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

227 lines
5.7KB

  1. // pages/guessPrize/guessPrize.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. ruleShow:false,//是否显示规则
  10. yuyueShow:false,//是否显示预约
  11. firstPrice:false,//是否有首轮竞猜价格
  12. httpState:false,//是否正在进行http请求
  13. guessPrice:123456,//竞猜价格
  14. guessPriceArr:['1','2','3','4','5','6'],
  15. shareShow:false,//是否显示分享弹窗
  16. slideState:false,//滑动状态
  17. slideNum:0,//滑动距离
  18. slideDay:['0','0'],//距离上市时间
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. app.globalData.nowPage = 3;
  25. this.distanceDay();
  26. if (app.globalData.openid) {
  27. this.loadFun();
  28. } else {
  29. app.globalData.openidSuccessFuc = this.loadFun;
  30. }
  31. },
  32. loadFun:function(){
  33. if (!app.globalData.addPageEnterState.guessPrize) {
  34. app.addPageEnter("7C8AAA38F8D85EFC48C2995FB6EBAC19");
  35. app.globalData.addPageEnterState.guessPrize = true;
  36. }
  37. this.getFirstGuessInfo();
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面隐藏
  51. */
  52. onHide: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面卸载
  56. */
  57. onUnload: function () {
  58. },
  59. /**
  60. * 页面相关事件处理函数--监听用户下拉动作
  61. */
  62. onPullDownRefresh: function () {
  63. },
  64. /**
  65. * 页面上拉触底事件的处理函数
  66. */
  67. onReachBottom: function () {
  68. },
  69. /**
  70. * 用户点击右上角分享
  71. */
  72. onShareAppMessage: function () {
  73. return {
  74. title: '召唤预言帝!快来和我一起猜启辰星售价,赢升舱大奖!',
  75. imageUrl: this.data.imgUrl + "/versions/guessShareImg.jpg",
  76. path: "/pages/guess/guess"
  77. }
  78. },
  79. ruleControl:function(){//规则显示控制
  80. this.setData({
  81. ruleShow:!this.data.ruleShow
  82. })
  83. },
  84. shareWindowControl:function(){//邀请好友弹窗显示控制
  85. this.setData({
  86. shareShow:!this.data.shareShow
  87. })
  88. },
  89. lookConfigure:function(){//查看车型详细参数
  90. wx.navigateTo({
  91. url: '/pages/configure/configure',
  92. })
  93. },
  94. enterLucky:function(){//每日抽奖
  95. wx.navigateTo({
  96. url: '/pages/luckyStar/luckyStar'
  97. })
  98. },
  99. yuyueControl:function(){//预约
  100. this.setData({
  101. yuyueShow: !this.data.yuyueShow
  102. })
  103. },
  104. getFirstGuessInfo:function(){//获取首轮竞猜价格信息
  105. app.wxRequest(app.globalData.urlRoot + "guessPrice/getFirstGuessInfo", {}, res => {
  106. // res.data = null;
  107. if (res.code == 200 && res.data) {
  108. this.data.guessPriceArr = res.data.guess_price.toString().split("");
  109. this.setData({
  110. firstPrice:true,
  111. guessPriceArr:this.data.guessPriceArr
  112. })
  113. }
  114. }, this);
  115. },
  116. submitPrice:function(){
  117. if(this.data.firstPrice){
  118. this.shareWindowControl();
  119. }else{
  120. this.submitFirstGuessInfo();
  121. }
  122. },
  123. submitFirstGuessInfo:function(){//提交首轮竞猜价格
  124. if(this.data.httpState){
  125. return;
  126. }
  127. this.data.httpState = true;
  128. app.wxRequest(app.globalData.urlRoot + "guessPrice/submitFirstGuessInfo", {guess_price:this.data.guessPrice,statistics_scene:app.globalData.sceneSource}, res => {
  129. this.data.httpState = false;
  130. if (res.code == 200) {
  131. this.setData({
  132. firstPrice:true
  133. })
  134. this.shareWindowControl();
  135. }else{
  136. wx.showToast({
  137. title: res.msg,
  138. icon:"none"
  139. })
  140. }
  141. }, this,"POST");
  142. },
  143. stratMove:function(e){
  144. var index = e.currentTarget.dataset.index;
  145. if(index == 0){
  146. return;
  147. }
  148. this.setData({
  149. slideState:true
  150. })
  151. this.data.slideNum = e.changedTouches[0].pageY;
  152. },
  153. endMove:function(e){
  154. var index = e.currentTarget.dataset.index;
  155. if(index == 0){
  156. return;
  157. }
  158. this.setData({
  159. slideState:false
  160. })
  161. if(e.changedTouches[0].pageY-this.data.slideNum>=10){
  162. console.log("往下滑");
  163. if(index==1){
  164. this.data.guessPrice-=10000;
  165. }else if(index==2){
  166. this.data.guessPrice-=1000;
  167. }else if(index==3){
  168. this.data.guessPrice-=100;
  169. }else if(index==4){
  170. this.data.guessPrice-=10;
  171. }else if(index==5){
  172. this.data.guessPrice-=1;
  173. }
  174. if(this.data.guessPrice<110000){
  175. this.data.guessPrice = 110000;
  176. }
  177. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  178. this.setData({
  179. guessPriceArr:this.data.guessPriceArr
  180. })
  181. }else if(e.changedTouches[0].pageY+10<=this.data.slideNum){
  182. console.log("往上滑");
  183. if(index==1){
  184. this.data.guessPrice+=10000;
  185. }else if(index==2){
  186. this.data.guessPrice+=1000;
  187. }else if(index==3){
  188. this.data.guessPrice+=100;
  189. }else if(index==4){
  190. this.data.guessPrice+=10;
  191. }else if(index==5){
  192. this.data.guessPrice+=1;
  193. }
  194. if(this.data.guessPrice>150000){
  195. this.data.guessPrice = 150000;
  196. }
  197. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  198. this.setData({
  199. guessPriceArr:this.data.guessPriceArr
  200. })
  201. }
  202. },
  203. distanceDay:function(){//距离4月23日上市还有XX天
  204. var timestamp = Date.parse(new Date()); //今天的时间戳
  205. var timestamp2 = Date.parse(new Date('2020-04-23')); //上市时间时间戳
  206. if(timestamp2>timestamp){
  207. var slideNum = Math.ceil((timestamp2-timestamp)/60/60/24/1000).toString().split("");
  208. this.setData({
  209. slideDay:slideNum//距离上市时间
  210. })
  211. }
  212. }
  213. })