首页/ mobileweb/ 小草二手房/ 代码预览

💻 代码预览 · 小草二手房

mw_house · 上传者 小草网络
← 返回详情
小草二手房_H5/app.js · 约 1673 字符
1// 小草二手房 · 交互逻辑
2document.addEventListener('click', function (e) {
3  var t = e.target.closest('[data-toast]');
4  if (t) { toast(t.getAttribute('data-toast')); }
5  var f = e.target.closest('.filter-bar span');
6  if (f) {
7    var wrap = f.parentElement;
8    [...wrap.children].forEach(function (x) { x.classList.remove('on'); });
9    f.classList.add('on');
10  }
11});
12function toast(msg) {
13  var d = document.createElement('div');
14  d.style.cssText = 'position:fixed;left:50%;bottom:110px;transform:translateX(-50%);background:rgba(26,47,85,.85);color:#fff;padding:10px 20px;border-radius:20px;font-size:13px;z-index:999';
15  d.textContent = msg;
16  document.body.appendChild(d);
17  setTimeout(function () { d.remove(); }, 1800);
18}
19function calcMortgage() {
20  var total = parseFloat(document.getElementById('total').value) || 0;
21  var down = parseFloat(document.getElementById('down').value) || 30;
22  var years = parseFloat(document.getElementById('years').value) || 30;
23  var rate = parseFloat(document.getElementById('rate').value) || 3.1;
24  var loan = total * (1 - down / 100);
25  var mr = rate / 100 / 12;
26  var n = years * 12;
27  var month = n > 0 && mr >= 0 ? (loan * mr * Math.pow(1 + mr, n)) / (Math.pow(1 + mr, n) - 1) : 0;
28  document.getElementById('mMonth').textContent = month ? Math.round(month).toLocaleString() : '--';
29  document.getElementById('mLoan').textContent = Math.round(loan).toLocaleString();
30  document.getElementById('mDown').textContent = Math.round(total * down / 100).toLocaleString();
31  document.getElementById('mInterest').textContent = month ? Math.round(month * n - loan).toLocaleString() : '--';
32}
33