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

315 satır
8.0KB

  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. submitBefore:true,//提交预测价格之前
  20. inputValue:"",//输入的价格
  21. stringValue:"",
  22. tipWindow:false,//是否显示价格超出的提示弹窗
  23. tipWindow2:false,
  24. focusState:false,
  25. tipImgShow:true,
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. app.globalData.nowPage = 3;
  32. // this.distanceDay();
  33. if (app.globalData.openid) {
  34. this.loadFun();
  35. } else {
  36. app.globalData.openidSuccessFuc = this.loadFun;
  37. }
  38. },
  39. loadFun:function(){
  40. if (!app.globalData.addPageEnterState.guessPrize) {
  41. app.addPageEnter("7C8AAA38F8D85EFC48C2995FB6EBAC19");
  42. app.globalData.addPageEnterState.guessPrize = true;
  43. }
  44. this.getFirstGuessInfo();
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload: function () {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh: function () {
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom: function () {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. return {
  81. title: '召唤预言帝!快来和我一起猜启辰星售价,赢升舱大奖!',
  82. imageUrl: this.data.imgUrl + "/versions/guessShareImg.jpg",
  83. path: "/pages/guess/guess"
  84. }
  85. },
  86. ruleControl:function(){//规则显示控制
  87. this.setData({
  88. ruleShow:!this.data.ruleShow
  89. })
  90. },
  91. shareWindowControl:function(){//邀请好友弹窗显示控制
  92. this.setData({
  93. shareShow:!this.data.shareShow
  94. })
  95. },
  96. lookConfigure:function(){//查看车型详细参数
  97. wx.navigateTo({
  98. url: '/pages/configure/configure',
  99. })
  100. },
  101. enterLucky:function(){//每日抽奖
  102. wx.navigateTo({
  103. url: '/pages/luckyStar/luckyStar'
  104. })
  105. },
  106. yuyueControl:function(){//预约
  107. this.setData({
  108. yuyueShow: !this.data.yuyueShow
  109. })
  110. },
  111. getFirstGuessInfo:function(){//获取首轮竞猜价格信息
  112. app.wxRequest(app.globalData.urlRoot + "guessPrice/getFirstGuessInfo", {}, res => {
  113. // res.data = null;
  114. if (res.code == 200 && res.data) {
  115. this.data.guessPriceArr = res.data.guess_price.toString().split("");
  116. for(let i=0;i<this.data.guessPriceArr.length;i++){
  117. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  118. }
  119. this.setData({
  120. submitBefore:false,
  121. firstPrice:true,
  122. guessPriceArr:this.data.guessPriceArr
  123. })
  124. }
  125. }, this);
  126. },
  127. submitPrice:function(){
  128. if(this.data.firstPrice){
  129. this.shareWindowControl();
  130. }else{
  131. this.submitFirstGuessInfo();
  132. }
  133. },
  134. submitFirstGuessInfo:function(){//提交首轮竞猜价格
  135. if(this.data.httpState){
  136. return;
  137. }
  138. this.data.httpState = true;
  139. app.wxRequest(app.globalData.urlRoot + "guessPrice/submitFirstGuessInfo", {guess_price:this.data.guessPrice,statistics_scene:app.globalData.sceneSource}, res => {
  140. this.data.httpState = false;
  141. if (res.code == 200) {
  142. this.setData({
  143. submitBefore:false,
  144. firstPrice:true
  145. })
  146. this.tipWindowControl2();
  147. this.shareWindowControl();
  148. }else{
  149. wx.showToast({
  150. title: res.msg,
  151. icon:"none"
  152. })
  153. }
  154. }, this,"POST");
  155. },
  156. stratMove:function(e){
  157. var index = e.currentTarget.dataset.index;
  158. if(index == 0){
  159. return;
  160. }
  161. this.setData({
  162. slideState:true
  163. })
  164. console.log(e);
  165. this.data.slideNum = e.changedTouches[0].pageY;
  166. },
  167. endMove:function(e){
  168. var index = e.currentTarget.dataset.index;
  169. if(index == 0){
  170. return;
  171. }
  172. this.setData({
  173. slideState:false
  174. })
  175. if(e.changedTouches[0].pageY-this.data.slideNum>=10){
  176. console.log("往下滑");
  177. if(index==1){
  178. this.data.guessPrice-=10000;
  179. }else if(index==2){
  180. this.data.guessPrice-=1000;
  181. }else if(index==3){
  182. this.data.guessPrice-=100;
  183. }else if(index==4){
  184. this.data.guessPrice-=10;
  185. }else if(index==5){
  186. this.data.guessPrice-=1;
  187. }
  188. if(this.data.guessPrice<110000){
  189. this.data.guessPrice = 110000;
  190. }
  191. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  192. for(let i=0;i<this.data.guessPriceArr.length;i++){
  193. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  194. }
  195. this.setData({
  196. guessPriceArr:this.data.guessPriceArr
  197. })
  198. }else if(e.changedTouches[0].pageY+10<=this.data.slideNum){
  199. console.log("往上滑");
  200. if(index==1){
  201. this.data.guessPrice+=10000;
  202. }else if(index==2){
  203. this.data.guessPrice+=1000;
  204. }else if(index==3){
  205. this.data.guessPrice+=100;
  206. }else if(index==4){
  207. this.data.guessPrice+=10;
  208. }else if(index==5){
  209. this.data.guessPrice+=1;
  210. }
  211. if(this.data.guessPrice>150000){
  212. this.data.guessPrice = 150000;
  213. }
  214. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  215. for(let i=0;i<this.data.guessPriceArr.length;i++){
  216. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  217. }
  218. this.setData({
  219. guessPriceArr:this.data.guessPriceArr
  220. })
  221. }
  222. },
  223. distanceDay:function(){//距离4月23日上市还有XX天
  224. var timestamp = Date.parse(new Date()); //今天的时间戳
  225. var timestamp2 = Date.parse(new Date('2020-04-23')); //上市时间时间戳
  226. if(timestamp2>timestamp){
  227. var slideNum = Math.ceil((timestamp2-timestamp)/60/60/24/1000).toString().split("");
  228. this.setData({
  229. slideDay:slideNum//距离上市时间
  230. })
  231. }
  232. },
  233. getValue:function(e){
  234. this.data.inputValue = e.detail.value;
  235. if(e.detail.value){
  236. this.setData({
  237. tipImgShow:false
  238. })
  239. }else{
  240. this.setData({
  241. tipImgShow:true
  242. })
  243. }
  244. this.setData({
  245. stringValue:e.detail.value
  246. })
  247. },
  248. submitPrice2:function(){
  249. if(this.data.inputValue>150000 || this.data.inputValue<110000){
  250. this.tipWindowControl();
  251. }else{
  252. this.data.guessPrice = this.data.inputValue;
  253. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  254. for(let i=0;i<this.data.guessPriceArr.length;i++){
  255. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  256. }
  257. this.setData({
  258. guessPriceArr:this.data.guessPriceArr
  259. })
  260. console.log(this.data.guessPrice);
  261. console.log(this.data.guessPriceArr);
  262. this.tipWindowControl2();
  263. }
  264. // this.submitFirstGuessInfo();
  265. },
  266. tipWindowControl:function(){
  267. this.setData({
  268. tipWindow:!this.data.tipWindow
  269. })
  270. if(!this.data.tipWindow){
  271. this.setData({
  272. stringValue:"",
  273. tipImgShow:true
  274. })
  275. }
  276. },
  277. tipWindowControl2:function(){
  278. this.setData({
  279. tipWindow2:!this.data.tipWindow2
  280. })
  281. },
  282. tipWindowControl3:function(){
  283. this.setData({
  284. stringValue:"",
  285. tipImgShow:true
  286. })
  287. this.setData({
  288. tipWindow2:!this.data.tipWindow2
  289. })
  290. },
  291. focusControl:function(){
  292. this.setData({
  293. focusState:true
  294. })
  295. },
  296. focusControl2:function(){
  297. this.setData({
  298. focusState:false
  299. })
  300. }
  301. })