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

guessPrize.js 7.6KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 app.sharePack();
  77. },
  78. ruleControl:function(){//规则显示控制
  79. this.setData({
  80. ruleShow:!this.data.ruleShow
  81. })
  82. },
  83. shareWindowControl:function(){//邀请好友弹窗显示控制
  84. this.setData({
  85. shareShow:!this.data.shareShow
  86. })
  87. },
  88. lookConfigure:function(){//查看车型详细参数
  89. wx.navigateTo({
  90. url: '/pages/configure/configure',
  91. })
  92. },
  93. enterLucky:function(){//每日抽奖
  94. wx.navigateTo({
  95. url: '/pages/luckyStar/luckyStar'
  96. })
  97. },
  98. yuyueControl:function(){//预约
  99. this.setData({
  100. yuyueShow: !this.data.yuyueShow
  101. })
  102. },
  103. getFirstGuessInfo:function(){//获取首轮竞猜价格信息
  104. app.wxRequest(app.globalData.urlRoot + "guessPrice/getFirstGuessInfo", {}, res => {
  105. // res.data = null;
  106. if (res.code == 200 && res.data) {
  107. this.data.guessPriceArr = res.data.guess_price.toString().split("");
  108. for(let i=0;i<this.data.guessPriceArr.length;i++){
  109. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  110. }
  111. this.setData({
  112. submitBefore:false,
  113. firstPrice:true,
  114. guessPriceArr:this.data.guessPriceArr
  115. })
  116. }
  117. }, this);
  118. },
  119. submitPrice:function(){
  120. if(this.data.firstPrice){
  121. this.shareWindowControl();
  122. }else{
  123. this.submitFirstGuessInfo();
  124. }
  125. },
  126. submitFirstGuessInfo:function(){//提交首轮竞猜价格
  127. if(this.data.httpState){
  128. return;
  129. }
  130. this.data.httpState = true;
  131. app.wxRequest(app.globalData.urlRoot + "guessPrice/submitFirstGuessInfo", {guess_price:this.data.guessPrice,statistics_scene:app.globalData.sceneSource}, res => {
  132. this.data.httpState = false;
  133. if (res.code == 200) {
  134. this.setData({
  135. submitBefore:false,
  136. firstPrice:true
  137. })
  138. this.tipWindowControl2();
  139. this.shareWindowControl();
  140. }else{
  141. wx.showToast({
  142. title: res.msg,
  143. icon:"none"
  144. })
  145. }
  146. }, this,"POST");
  147. },
  148. stratMove:function(e){
  149. var index = e.currentTarget.dataset.index;
  150. if(index == 0){
  151. return;
  152. }
  153. this.setData({
  154. slideState:true
  155. })
  156. console.log(e);
  157. this.data.slideNum = e.changedTouches[0].pageY;
  158. },
  159. endMove:function(e){
  160. var index = e.currentTarget.dataset.index;
  161. if(index == 0){
  162. return;
  163. }
  164. this.setData({
  165. slideState:false
  166. })
  167. if(e.changedTouches[0].pageY-this.data.slideNum>=10){
  168. console.log("往下滑");
  169. if(index==1){
  170. this.data.guessPrice-=10000;
  171. }else if(index==2){
  172. this.data.guessPrice-=1000;
  173. }else if(index==3){
  174. this.data.guessPrice-=100;
  175. }else if(index==4){
  176. this.data.guessPrice-=10;
  177. }else if(index==5){
  178. this.data.guessPrice-=1;
  179. }
  180. if(this.data.guessPrice<110000){
  181. this.data.guessPrice = 110000;
  182. }
  183. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  184. for(let i=0;i<this.data.guessPriceArr.length;i++){
  185. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  186. }
  187. this.setData({
  188. guessPriceArr:this.data.guessPriceArr
  189. })
  190. }else if(e.changedTouches[0].pageY+10<=this.data.slideNum){
  191. console.log("往上滑");
  192. if(index==1){
  193. this.data.guessPrice+=10000;
  194. }else if(index==2){
  195. this.data.guessPrice+=1000;
  196. }else if(index==3){
  197. this.data.guessPrice+=100;
  198. }else if(index==4){
  199. this.data.guessPrice+=10;
  200. }else if(index==5){
  201. this.data.guessPrice+=1;
  202. }
  203. if(this.data.guessPrice>150000){
  204. this.data.guessPrice = 150000;
  205. }
  206. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  207. for(let i=0;i<this.data.guessPriceArr.length;i++){
  208. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  209. }
  210. this.setData({
  211. guessPriceArr:this.data.guessPriceArr
  212. })
  213. }
  214. },
  215. distanceDay:function(){//距离4月23日上市还有XX天
  216. var timestamp = Date.parse(new Date()); //今天的时间戳
  217. var timestamp2 = Date.parse(new Date('2020-04-23')); //上市时间时间戳
  218. if(timestamp2>timestamp){
  219. var slideNum = Math.ceil((timestamp2-timestamp)/60/60/24/1000).toString().split("");
  220. this.setData({
  221. slideDay:slideNum//距离上市时间
  222. })
  223. }
  224. },
  225. getValue:function(e){
  226. this.data.inputValue = e.detail.value;
  227. if(e.detail.value){
  228. this.setData({
  229. tipImgShow:false
  230. })
  231. }else{
  232. this.setData({
  233. tipImgShow:true
  234. })
  235. }
  236. this.setData({
  237. stringValue:e.detail.value
  238. })
  239. },
  240. submitPrice2:function(){
  241. if(this.data.inputValue>150000 || this.data.inputValue<110000){
  242. this.tipWindowControl();
  243. }else{
  244. this.data.guessPrice = this.data.inputValue;
  245. this.data.guessPriceArr = this.data.guessPrice.toString().split("");
  246. for(let i=0;i<this.data.guessPriceArr.length;i++){
  247. this.data.guessPriceArr[i] = parseInt(this.data.guessPriceArr[i]);
  248. }
  249. this.setData({
  250. guessPriceArr:this.data.guessPriceArr
  251. })
  252. console.log(this.data.guessPrice);
  253. console.log(this.data.guessPriceArr);
  254. this.tipWindowControl2();
  255. }
  256. // this.submitFirstGuessInfo();
  257. },
  258. tipWindowControl:function(){
  259. this.setData({
  260. tipWindow:!this.data.tipWindow
  261. })
  262. if(!this.data.tipWindow){
  263. this.setData({
  264. stringValue:"",
  265. tipImgShow:true
  266. })
  267. }
  268. },
  269. tipWindowControl2:function(){
  270. this.setData({
  271. tipWindow2:!this.data.tipWindow2
  272. })
  273. },
  274. tipWindowControl3:function(){
  275. this.setData({
  276. stringValue:"",
  277. tipImgShow:true
  278. })
  279. this.setData({
  280. tipWindow2:!this.data.tipWindow2
  281. })
  282. },
  283. focusControl:function(){
  284. this.setData({
  285. focusState:true
  286. })
  287. },
  288. focusControl2:function(){
  289. this.setData({
  290. focusState:false
  291. })
  292. }
  293. })