myloan.js 2.5 KB

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