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

230 line
5.6KB

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