myloan.js 3.5 KB

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