帮你贷的小程序

details.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/details/details.js
  2. var app = getApp();
  3. Page({
  4. data: {
  5. info: null,
  6. id: 129,
  7. remmondList: [],
  8. isShow: false,
  9. initPerid: null,
  10. loanMoney: 0,
  11. money: 0,
  12. time: 0,
  13. valLoan: 0,
  14. index: 0,
  15. hiddenThis: true,
  16. appid: 0
  17. },
  18. onLoad: function (options) {
  19. var id = options.id, tmplmsg = options.tmplmsg || 0;
  20. if (id) {
  21. this.setData({id: id})
  22. }
  23. this.initDetails(tmplmsg);
  24. this.getRemmondList();
  25. // this.showConcact(null, true);
  26. // console.log(this.data.remmondList);
  27. },
  28. bindPickerChange: function(e) {
  29. var that = this, time = 0, idx = e.detail.value ;
  30. time = that.data.initPerid[idx].k
  31. this.setData({
  32. index: e.detail.value,
  33. time: parseFloat(time)
  34. })
  35. that.caculateMoney();
  36. // console.log(time);
  37. },
  38. initDetails (tmplmsg) {
  39. var that = this, data = null;
  40. wx.request({
  41. url: app.globalData.HOST + '/user/product/detail',
  42. method: "POST",
  43. data: Object.assign({}, app.globalData.common, {id: that.data.id, tmplmsg: tmplmsg}),
  44. success: function (res) {
  45. if (res.data.errno == '0') {
  46. data = res.data.rst;
  47. }
  48. that.setData({ info: data, initPerid: data.loan_period, money: data.upper_amount, time: data.loan_period[0].k, rate: data.day_rate});
  49. that.caculateMoney()
  50. },
  51. complete: function () {
  52. // that.setData({ hidden:true});//加载成功
  53. wx.stopPullDownRefresh() //停止下拉刷新
  54. }
  55. });
  56. },
  57. getRemmondList () {
  58. var that = this, list = [];
  59. wx.request({
  60. url: app.globalData.HOST + '/user/product/getSameAmountByProductId',
  61. method: "POST",
  62. data: Object.assign({}, app.globalData.common, {id: that.data.id, platform: app.globalData.platform}),
  63. success: function (res) {
  64. if (res.data.errno == '0') {
  65. list = res.data.rst.data;
  66. }
  67. that.setData({ remmondList: list});
  68. },
  69. complete: function () {
  70. // that.setData({ hidden:true});//加载成功
  71. wx.stopPullDownRefresh() //停止下拉刷新
  72. }
  73. });
  74. },
  75. showMore () {
  76. var that = this;
  77. that.setData({isShow: !that.data.isShow})
  78. },
  79. goRemmond (event) {
  80. var id = event.currentTarget.dataset.id;
  81. wx.redirectTo({
  82. url: '/pages/details/details?id=' + id
  83. })
  84. // console.log(id);
  85. },
  86. caculateMoney () {
  87. var that = this, loanMoney = 0;
  88. var valLoan = that.data.money, rate = that.data.rate, time = that.data.time;
  89. // console.log(valLoan);
  90. // console.log(rate);
  91. console.log(time);
  92. loanMoney = valLoan + valLoan * rate * time / 100;
  93. // console.log(loanMoney);
  94. that.setData({loanMoney: loanMoney.toFixed(0)})
  95. },
  96. changeMoney (e) {
  97. var that = this;
  98. var money = e.detail.value, max = that.data.info.lower_amount, min = that.data.info.upper_amount;
  99. if (money < min) {
  100. money = min
  101. }else if(money > max){
  102. money = max
  103. }else{
  104. money = parseFloat(e.detail.value)
  105. }
  106. that.setData({money: money})
  107. that.caculateMoney();
  108. },
  109. showConcact (event) {
  110. var that = this;
  111. var tel = wx.getStorageSync('tel') || '0', user_id = wx.getStorageSync('user').user_id || '0', id = event.currentTarget.dataset.id;
  112. if (user_id != '0' || tel != '0') {
  113. // 绑定了手机号
  114. this.setData({hiddenThis: false, appid: id});
  115. wx.request({
  116. url: app.globalData.HOST + '/user/wx/known',
  117. method: "POST",
  118. data: Object.assign({}, app.globalData.common, {id: id}),
  119. success: function (res) {
  120. },
  121. complete: function () {
  122. }
  123. });
  124. }else{
  125. // 未绑定手机号
  126. wx.navigateTo({
  127. url: "/pages/getPhone/getPhone?from=details&preid=" + id
  128. })
  129. }
  130. },
  131. onReady: function () {
  132. },
  133. onShow: function () {
  134. },
  135. onHide: function () {
  136. this.setData({hiddenThis: true})
  137. },
  138. onUnload: function () {
  139. },
  140. //FormId
  141. formSubmit(e) {
  142. var formId = e.detail.formId;
  143. this.getFromid(formId);
  144. console.log(formId+"formID")
  145. },
  146. getFromid(formId) {
  147. wx.request({
  148. url: app.globalData.HOST + '/user/wx/getFromid',
  149. method: "POST",
  150. data: Object.assign({}, app.globalData.common, { from_id: formId }),
  151. success: function (res) {
  152. },
  153. complete: function () {
  154. }
  155. });
  156. }
  157. })