myloan.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // pages/myloan/myloan.js
  2. import { get,post } from "../../common/request.js"
  3. import pathmap from "../../common/pathmap"
  4. import stylemap from "../../common/stylemap"
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. windowh: app.globalData.windowh,
  12. timetorate:{
  13. "12":"rates_a",
  14. "24":"rates_b",
  15. "36":"rates_c"
  16. },
  17. price:50,
  18. time:12,
  19. scale:0,
  20. scalename:"零",
  21. number:["零","一","二","三","四","五","六","七","八","九"]
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. this.setData(stylemap);
  28. this.getRate();
  29. this.getWheres();
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady: function () {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow: function () {
  40. },
  41. /**
  42. * 生命周期函数--监听页面隐藏
  43. */
  44. onHide: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面卸载
  48. */
  49. onUnload: function () {
  50. },
  51. /**
  52. * 页面相关事件处理函数--监听用户下拉动作
  53. */
  54. onPullDownRefresh: function () {
  55. },
  56. /**
  57. * 页面上拉触底事件的处理函数
  58. */
  59. onReachBottom: function () {
  60. },
  61. /**
  62. * 用户点击右上角分享
  63. */
  64. onShareAppMessage: function () {
  65. },
  66. getWheres:function(){
  67. var _self = this;
  68. var wheres = wx.getStorageSync("wheres");
  69. if(wheres){
  70. _self.setData({
  71. wheres: wheres
  72. })
  73. }else{
  74. get(pathmap.wheres, {
  75. no_brand_series:1
  76. }, function (json) {
  77. _self.setData({
  78. wheres: json.data
  79. })
  80. wx.setStorageSync("wheres",json.data);
  81. })
  82. }
  83. },
  84. getRate:function(){
  85. var _self=this;
  86. var mobile = wx.getStorageSync("mobile");
  87. get(pathmap.rates,{
  88. mobile:mobile
  89. },function(json){
  90. _self.setData(json.data);
  91. })
  92. },
  93. getPrice:function(e){
  94. var price = e.detail.value;
  95. this.setData({price:price});
  96. this.getResult();
  97. },
  98. getFirstPay:function(e){
  99. var scale = e.detail.value;
  100. this.setData({scale:scale});
  101. this.getResult();
  102. },
  103. getTime:function(e){
  104. var time = e.detail.value;
  105. this.setData({time:time});
  106. this.getResult();
  107. },
  108. getResult:function(){
  109. var price = this.data.price*10000;
  110. var scale = this.data.scale;
  111. var scales = (""+scale/10).split(".");
  112. var scalename =this.data.number[scales[0]];
  113. if(scales[1]){
  114. scalename+=this.data.number[scales[1]]
  115. }
  116. var time = this.data.time;
  117. var interestrate = this.data[this.data.timetorate[time]]/100;
  118. var firstpay = price*scale/10000;
  119. var premonthpay = (price-firstpay)*interestrate*(Math.pow((1+interestrate),time))/(Math.pow((1+interestrate),time)-1);
  120. this.setData({
  121. firstpay:firstpay,
  122. premonthpay:Math.round(premonthpay),
  123. scalename:scalename
  124. })
  125. },
  126. toBuy:function(){
  127. var list = this.data.wheres.price.map(function(item){
  128. var price = item.price_name.split("-");
  129. var pricelist = price.map(function(item2){
  130. return parseInt(item2);
  131. })
  132. return {
  133. price_id:item.price_id,
  134. pricelist:pricelist
  135. }
  136. })
  137. var price = this.data.price;
  138. var price_id = 0;
  139. list.forEach(function(item){
  140. if(item.pricelist[0]<price&&price<item.pricelist[1]){
  141. price_id=item.price_id;
  142. }
  143. })
  144. if(price_id){
  145. wx.redirectTo({url:"../buy/buy?price="+price_id});
  146. }else{
  147. wx.redirectTo({url:"../buy/buy"});
  148. }
  149. }
  150. })