myloan.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.setData(stylemap);
  26. this.getRate();
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面隐藏
  40. */
  41. onHide: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面卸载
  45. */
  46. onUnload: function () {
  47. },
  48. /**
  49. * 页面相关事件处理函数--监听用户下拉动作
  50. */
  51. onPullDownRefresh: function () {
  52. },
  53. /**
  54. * 页面上拉触底事件的处理函数
  55. */
  56. onReachBottom: function () {
  57. },
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {
  62. },
  63. getRate:function(){
  64. var _self=this;
  65. var mobile = wx.getStorageSync("mobile");
  66. get(pathmap.rates,{
  67. mobile:mobile
  68. },function(json){
  69. _self.setData(json.data);
  70. })
  71. },
  72. getPrice:function(e){
  73. var price = e.detail.value;
  74. this.setData({price:price});
  75. this.getResult();
  76. },
  77. getFirstPay:function(e){
  78. var scale = e.detail.value;
  79. this.setData({scale:scale});
  80. this.getResult();
  81. },
  82. getTime:function(e){
  83. var time = e.detail.value;
  84. this.setData({time:time});
  85. this.getResult();
  86. },
  87. getResult:function(){
  88. var price = this.data.price*10000;
  89. var scale = this.data.scale;
  90. var time = this.data.time;
  91. var interestrate = this.data[this.data.timetorate[time]]/100;
  92. var firstpay = price*scale/10000;
  93. var premonthpay = (price-firstpay)*interestrate*(Math.pow((1+interestrate),time))/(Math.pow((1+interestrate),time)-1);
  94. this.setData({
  95. firstpay:firstpay,
  96. premonthpay:Math.round(premonthpay)
  97. })
  98. }
  99. })