<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Donation-management</title>
<link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="./css/base.css" />
<link rel="stylesheet" href="./css/index.css" />
<style>
</style>
</head>
<body>
<div class="donation-management">
<h3 class="title">捐赠管理</h3>
<div class="recipient">
<div class="content">
<span>受捐单位:</span>
<select class="searchOption">
<option>请选择</option>
<option>壹基金</option>
<option>嫣然基金</option>
<option>自然之友</option>
</select>
<button class="search">查询</button>
</div>
</div>
<div class="donor">
<div class="content">
<div class="person">
<span>捐赠人:</span>
<input type="text" class="getDonor" />
</div>
<div class="unit">
<span>受捐单位:</span>
<select class="getUnit">
<option>壹基金</option>
<option>嫣然基金</option>
<option>自然之友</option>
</select>
</div>
<div class="money">
<span>金额:</span>
<input type="text" class="getMoney" />
</div>
<div class="date">
<span>受捐日期:</span>
<input type="datetime-local" class="getDate test1" id="test1" placeholder="请选择日期" />
</div>
<button class="add">新增</button>
</div>
</div>
<table class="table table-bordered donation-list text-center">
<thead>
<tr class="bg-primary">
<th>序号</th>
<th>捐赠人</th>
<th>受捐单位</th>
<th>金额</th>
<th>受捐日期</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr class="table-content">
<td>1</td>
<td>这是姓名</td>
<td>这是单位</td>
<td>这是多少钱</td>
<td>这是捐赠日期</td>
<td>
<a href="#" class="del">删</a>
<a href="#" class="update" data-name="这是姓名" data-dep="这是单位">改</a>
</td>
</tr>
</tbody>
</table>
</div>
<script src="./libs/index/index3.js"></script>
<script src="./libs/jquery/jquery.min.js"></script>
<script src="./libs/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
数据模拟,数据渲染 数据统计 数据的新增删除,
window.addEventListener('load', function () {
let tbody = this.document.querySelector('tbody')
let add = this.document.querySelector('.add')
let getDonor = this.document.querySelector('.getDonor')
let getUnit = this.document.querySelector('.getUnit')
let getMoney = this.document.querySelector('.getMoney')
let getDate = this.document.querySelector('.getDate')
let search = this.document.querySelector('.search')
let searchOption = this.document.querySelector('.searchOption')
let donor = JSON.parse(this.localStorage.getItem('shu_12'))
function init(arr = donor) {
let htmlStr = ''
arr.forEach(function (item, index) {
htmlStr += `<tr class="table-content">
<td>1</td>
<td>${item.person}</td>
<td>${item.unit}</td>
<td>${item.money}</td>
<td>${setTime(item.date)}</td>
<td>
<a href="#" class="del" data-id=${item.id}>删</a>
<a href="#" class="update" data-name="这是姓名" data-dep="这是单位">改</a>
</td>
</tr>`
})
tbody.innerHTML = htmlStr
}
init()
save()
add.addEventListener('click', function () {
let obj = {
id: donor.length > 0 ? donor[donor.length - 1].id + 1 : 1,
person: getDonor.value,
unit: getUnit.value,
money: getMoney.value,
date: getDate.value
}
donor.push(obj)
init()
save()
})
tbody.addEventListener('click', function (e) {
if (e.target.className == 'del') {
let id = e.target.dataset.id
donor.forEach(function (v, i) {
if (v.id == id) {
donor.splice(i, 1)
init()
save()
}
})
}
})
function setTime(v) {
let date = new Date(v)
let year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
return `${year}-${month}-${day}`
}
search.addEventListener('click', function () {
let value = searchOption.value
if (value == '请选择') {
init()
} else {
let temp = []
donor.forEach(function (v, i) {
if (v.unit == value) {
temp.push(v)
}
})
init(temp)
save()
}
})
function save() {
localStorage.setItem('shu_12', JSON.stringify(donor))
}
})