东风启辰小程序端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

311 lines
7.8KB

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