Commit 318ee87f by shj

代码重构,全面使用ajax进行请求

parent 1394773f
......@@ -133,6 +133,21 @@
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
<!-- Json-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.55</version>
</dependency>
<!--Gson-->
<!--<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>-->
</dependencies>
</project>
\ No newline at end of file
......@@ -9,19 +9,19 @@ import java.util.Map;
* 经费报表对象,内含各种经费的集合
*/
public class Budget implements Serializable {
private Map<Equipment,Integer> equipments;
private Map<Material,Integer> materials;
private Map<TestAndProcess,Integer> testAndProcesses;
private Map<Power,Integer> powers;
private Map<Travel,Pair> travels;
private Map<Conference,Integer> conferences;
private Map<InternationalCommunication,Integer> internationalCommunications;
private Map<Property,Integer> properties;
private Map<Labour,Integer> labour;
private Map<Consultation,Integer> consultations;
private Map<Others,Integer> others;
private Map<Indirect,Integer> indirects;
private Requirement requirement=new Requirement();
private Map<Equipment, Integer> equipments;
private Map<Material, Integer> materials;
private Map<TestAndProcess, Integer> testAndProcesses;
private Map<Power, Integer> powers;
private Map<Travel, Pair> travels;
private Map<Conference, Pair> conferences;
private Map<InternationalCommunication, Integer> internationalCommunications;
private Map<Property, Integer> properties;
private Map<Labour, Integer> labour;
private Map<Consultation, Integer> consultations;
private Map<Others, Integer> others;
private Map<Indirect, Integer> indirects;
private Requirement requirement = new Requirement();
public Requirement getRequirement() {
return requirement;
......@@ -79,11 +79,11 @@ public class Budget implements Serializable {
this.travels = travels;
}
public Map<Conference, Integer> getConferences() {
public Map<Conference, Pair> getConferences() {
return conferences;
}
public void setConferences(Map<Conference, Integer> conferences) {
public void setConferences(Map<Conference, Pair> conferences) {
this.conferences = conferences;
}
......@@ -145,7 +145,7 @@ public class Budget implements Serializable {
*
* @return
*/
public Map<Indirect,Integer> computeIndirect() {
public Map<Indirect, Integer> computeIndirect() {
double direct = 0.0;
if (materials != null)
for (Material material : materials.keySet()) {
......@@ -165,23 +165,28 @@ public class Budget implements Serializable {
}
if (conferences != null)
for (Conference conference : conferences.keySet()) {
direct += conference.computeUnitPrice()*conferences.get(conference);
direct += conference.getPrice() * conferences.get(conference).getPeople() * conferences.get(conference).getDays();
}
if (consultations!=null) {
for (Consultation consultation : consultations.keySet()) {
direct+=consultation.getPrice()*consultations.get(consultation);
}
}
if (internationalCommunications != null)
for (InternationalCommunication internationalCommunication : internationalCommunications.keySet()) {
direct += internationalCommunication.computeUnitPrice()*internationalCommunications.get(internationalCommunication);
direct += internationalCommunication.computeUnitPrice() * internationalCommunications.get(internationalCommunication);
}
if (properties != null)
for (Property property : properties.keySet()) {
direct += property.computeUnitPrice()*properties.get(property);
direct += property.computeUnitPrice() * properties.get(property);
}
if (labour != null)
for (Labour labour1 : labour.keySet()) {
direct += labour1.computeUnitPrice()*labour.get(labour1);
direct += labour1.computeUnitPrice() * labour.get(labour1);
}
if (others != null)
for (Others other : others.keySet()) {
direct += other.computeUnitPrice()*others.get(other);
direct += other.computeUnitPrice() * others.get(other);
}
double indirect = 0.0;
......@@ -195,8 +200,8 @@ public class Budget implements Serializable {
Indirect result = new Indirect();
result.setPrice(indirect);
result.setName("间接费用");
Map<Indirect,Integer> map=new HashMap<>();
map.put(result,1);
Map<Indirect, Integer> map = new HashMap<>();
map.put(result, 1);
return map;
}
......
......@@ -35,4 +35,11 @@ public class Conference extends Item {
", people=" + people +
"} " + super.toString();
}
public double cost(Pair pair,Consultation consultation)
{
if(pair==null || pair.getDays()<=0 || pair.getPeople()<=0 || (consultation==null&&getExperts()!=0))
return 0.0;
double expert=(consultation==null)?0.0:consultation.getPrice();
return pair.getDays()*(getExperts()*expert+getPrice()*pair.getPeople());
}
}
......@@ -9,10 +9,11 @@ import java.util.Objects;
*/
public class Item implements Serializable {
private Integer id;
private String name=null;
private String name;
private double price;
private String comment;
/**
* 此方法返回每一类预算的价格,不等同于getPrice,由子类选择实现,因为存在差旅费等多个价格加算的预算
* 一般就是getPrice
......
......@@ -28,4 +28,12 @@ public class Pair implements Serializable {
public void setDays(int days) {
this.days = days;
}
@Override
public String toString() {
return "Pair{" +
"people=" + people +
", days=" + days +
'}';
}
}
......@@ -74,7 +74,8 @@ public class BudgetHandler {
} else if (item.contains("conference")) {
budget.setConferences(budgetService.doConference(number));
budget.getRequirement().setConference(number);
budget.setConsultations(budgetService.doConsultation(budget.getConferences()));
int experts=expertSum(budget.getConferences());
budget.setConsultations(budgetService.doConsultation(experts));
} else if (item.contains("international")) {
budget.setInternationalCommunications(budgetService.doInternationalCommunication(number));
budget.getRequirement().setInternational(number);
......@@ -117,6 +118,14 @@ public class BudgetHandler {
}
}
private int expertSum(Map<Conference, Pair> conferences) {
int experts=0;
for (Conference conference : conferences.keySet()) {
experts+=conference.getExperts()*conferences.get(conference).getDays();
}
return experts;
}
/**
* 下载最新报表
*
......@@ -489,45 +498,58 @@ public class BudgetHandler {
@Autowired
private IConferenceDao conferenceDao;
/**
* 修改预算中的劳务费、规则中的劳务费
*
* @param mode
* @param id
* @param name
* @param price
* @param conference
* @param pair
* @param nums
* @param curd
* @param request
* @param response
*/
@RequestMapping("/Modify/Conference")
public void modifyConference(Integer mode, Integer id, String name, Double price,Integer experts,Integer people, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) {
public void modifyConference(Integer mode, Conference conference,Pair pair, Integer nums, Integer curd, HttpServletRequest request, HttpServletResponse response) {
System.out.println("/Modify/Conference");
if (mode.equals(0))//修改预算
{
if (nums < 0) return;
if (pair==null || pair.getDays()<0 || pair.getPeople()<0) return;
String sessionID = getSessionID(request.getCookies());
Budget budget = retrieveBudget(sessionID);
assert budget != null;
Map<Conference, Integer> items = null;
items = budget.getConferences();
Conference mod=conferenceDao.selectById(id);
Map<Conference, Pair> items = budget.getConferences();
Conference mod=conferenceDao.selectById(conference.getId());
if(mod!=null)
items.put(mod,nums);
budget.setConsultations(budgetService.doConsultation(budget.getConferences()));
items.put(mod,pair);
int experts=0;
for (Conference item : items.keySet()) {
experts+=item.getExperts()*items.get(item).getDays();
}
budget.setConsultations(budgetService.doConsultation(experts));
try {
double sum=0.0;
Map<Conference, Pair> conferencesMap = budget.getConferences();
Map<Consultation, Integer> consultationsMap = budget.getConsultations();
Consultation consultation=null;
for (Consultation item : consultationsMap.keySet()) {
consultation=item;
}
for (Conference item : conferencesMap.keySet()) {
sum+=(consultation.getPrice()*item.getExperts()
+item.getPrice()*conferencesMap.get(item).getPeople())*conferencesMap.get(item).getDays();
}
response.getWriter().print(sum);
} catch (IOException e) {
e.printStackTrace();
}
serializeBudget(budget, getFilePath(sessionID));
} else//修改规则
{
Conference item = new Conference();
item.setId(id);
item.setName(name);
item.setPrice(price);
item.setExperts(experts);
item.setPeople(people);
Conference item =conference;
if (curd.equals(0))//增
{
conferenceDao.insertConference(item);
......@@ -668,7 +690,7 @@ public class BudgetHandler {
* @param cookies
* @return
*/
private String getSessionID(Cookie[] cookies) {
public static String getSessionID(Cookie[] cookies) {
String sessionID = null;
for (Cookie cookie : cookies) {
if (cookie.getName().equals("sessionID")) {
......@@ -687,7 +709,7 @@ public class BudgetHandler {
* @param sessionID
* @return
*/
private Budget retrieveBudget(String sessionID) {
public static Budget retrieveBudget(String sessionID) {
String filepath = getFilePath(sessionID);
ObjectInputStream inputStream = null;
try {
......@@ -712,7 +734,7 @@ public class BudgetHandler {
* @param sessionID
* @return
*/
private String getFilePath(String sessionID) {
public static String getFilePath(String sessionID) {
String filePath = BudgetHandler.class.getClassLoader().getResource("..").getPath() +
File.separator + "budgets" +
File.separator + sessionID;
......@@ -721,7 +743,7 @@ public class BudgetHandler {
}
private void serializeBudget(Budget budget, String filePath) {
public static void serializeBudget(Budget budget, String filePath) {
File budgetFile = new File(filePath);
ObjectOutputStream outputStream = null;
try {
......@@ -746,7 +768,7 @@ public class BudgetHandler {
* @param budget
* @param printWriter
*/
private void budgetToOutputStream(Budget budget, Writer printWriter) {
private static void budgetToOutputStream(Budget budget, Writer printWriter) {
BufferedWriter writer = new BufferedWriter(printWriter);
try {
writer.write("设备费,名称,单价,数量,小计");
......@@ -818,14 +840,14 @@ public class BudgetHandler {
writer.write("会议费,会议内容,费用标准,参会人数,会议次数,小计");
writer.newLine();
items = (Map) budget.getConferences();
for (Item item : items.keySet()) {
Map<Conference, Pair> conferences = budget.getConferences();
for (Item item : conferences.keySet()) {
if (item instanceof Conference) {
writer.write(comma + item.getName()
+ comma + item.getPrice()
+comma+((Conference) item).getPeople()
+ comma + items.get(item)
+ comma + item.computeUnitPrice() * items.get(item));
+comma+conferences.get(item).getPeople()
+ comma + conferences.get(item).getDays()
+ comma + item.getPrice()*conferences.get(item).getPeople()*conferences.get(item).getDays());
writer.newLine();
}
}
......@@ -873,7 +895,7 @@ public class BudgetHandler {
}
writer.newLine();
if (budget.getConferences() != null && budget.getConferences().size() > 0) {
if (budget.getConferences() != null && budget.getConferences().size() > 0 && budget.getConsultations()!=null) {
writer.write("咨询费,工作内容,人员类型,费用标准,每次人数,次数,小计");
writer.newLine();
Map<Consultation, Integer> consultations = budget.getConsultations();
......@@ -881,15 +903,15 @@ public class BudgetHandler {
for (Consultation item : consultations.keySet()) {
consultation = item;
}
items = (Map) budget.getConferences();
for (Item item : items.keySet()) {
conferences= budget.getConferences();
for (Item item : conferences.keySet()) {
if (item instanceof Conference) {
writer.write(comma + item.getName()
+ comma + consultation.getName()
+ comma + consultation.getPrice()
+ comma + ((Conference) item).getExperts()
+ comma + items.get(item)
+ comma + ((Conference) item).getExperts() * consultation.getPrice() * items.get(item));
+ comma + conferences.get(item).getDays()
+ comma + ((Conference) item).getExperts() * consultation.getPrice() * conferences.get(item).getDays());
writer.newLine();
}
}
......@@ -938,7 +960,7 @@ public class BudgetHandler {
* @param budget
* @param outputStream
*/
private void budgetToOutputStream(Budget budget, OutputStream outputStream) {
public static void budgetToOutputStream(Budget budget, OutputStream outputStream) {
System.out.println("GBK");
try {
budgetToOutputStream(budget, new PrintWriter(new OutputStreamWriter(outputStream, "GBK")));
......
package handlers;
import beans.Budget;
import beans.Indirect;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import service.IDetailService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/Budget/Detail")
public class DetailHandler {
@RequestMapping("Indirect")
public void showIndirect(HttpServletRequest request, HttpServletResponse response)
{
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
String sessionID = BudgetHandler.getSessionID(request.getCookies());
Budget budget = BudgetHandler.retrieveBudget(sessionID);
Map<Indirect, Integer> indirects = budget.getIndirects();
List<JSONObject> list=new LinkedList<>();
for (Indirect indirect : indirects.keySet()) {
JSONObject obj=new JSONObject();
obj.put("id",indirect.getId());
obj.put("name",indirect.getName());
obj.put("price",indirect.getPrice());
obj.put("nums",indirects.get(indirect));
list.add(obj);
}
object.put("indirects",list);
writer.write(object.toJSONString());
} catch (IOException e) {
e.printStackTrace();
}
}
@Autowired
private IDetailService detailService;
@RequestMapping("/Stats")
public void getStats(HttpServletRequest request,HttpServletResponse response)
{
try {
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
JSONObject object=new JSONObject();
String sessionID = BudgetHandler.getSessionID(request.getCookies());
Budget budget = BudgetHandler.retrieveBudget(sessionID);
double req_sofar=0.0,sum_sofar=0.0,req,sum;
JSONObject sub=new JSONObject();
req=budget.getRequirement().getEquip();
sum=detailService.sumEquipment(budget.getEquipments());
sub.put("req",req);
sub.put("sum",sum);
sub.put("diff",req-sum);
object.put("equipment",sub);
object.put("req",req_sofar);
object.put("sum",sum_sofar);
object.put("diff",req_sofar-sum_sofar);
writer.write(object.toJSONString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -17,7 +17,7 @@ public interface IBudgetService {
Map<Travel, Pair> doTravel(Double number);
Map<Conference,Integer> doConference(Double number);
Map<Conference, Pair> doConference(Double number);
Map<InternationalCommunication,Integer> doInternationalCommunication(Double number);
......@@ -30,6 +30,7 @@ public interface IBudgetService {
Map<Consultation,Integer> doConsultation(Map<Conference,Integer> conferences);
Map<Consultation,Integer> doConsultation(int n);
Map<Others,Integer> doOthers(Double number);
......
package service;
import beans.Equipment;
import beans.Indirect;
import beans.Material;
import beans.Travel;
public interface ICheckService {
boolean checkEquipment(Equipment equipment);
boolean checkMaterial(Material material);
boolean checkTravel(Travel travel);
boolean checkIndirect(Indirect indirect);
}
package service;
import beans.Equipment;
import java.util.Map;
public interface IDetailService {
double sumEquipment(Map<Equipment, Integer> equipments);
}
......@@ -194,28 +194,36 @@ public class BudgetService implements IBudgetService {
if(travels!=null && travels.size()!=0)
{
double sofar=0.0;
Pair pair=new Pair(1,1);
for (Travel travel : travels) {
if(sofar<number)
{
Pair pair=new Pair(1,1);
result.put(travel,pair);
sofar+=travel.cost(pair);
}
}
while (true)
while (sofar<number)
{
sofar=0.0;
for (Travel travel : result.keySet()) {
pair=result.get(travel);
Pair pair=result.get(travel);
double oldCost=travel.cost(pair);
pair.setDays(pair.getDays()+1);
sofar+=(travel.cost(pair));
if(sofar>=number) return result;
double newCost=travel.cost(pair);
sofar+=(newCost-oldCost);
System.out.println("oldCost:"+oldCost);
System.out.println("newCost:"+newCost);
System.out.println("sofar:"+sofar);
if(sofar>=number) {
System.out.println(result);
return result;
}
}
}
}
return result;
}
/////////////////////////////////////////////////////////待解决
/**
* 合成会议费
*
......@@ -223,9 +231,39 @@ public class BudgetService implements IBudgetService {
* @return
*/
@Override
public Map<Conference, Integer> doConference(Double number) {
public Map<Conference, Pair> doConference(Double number) {
Map<Conference,Pair> map=new HashMap<>();
List<Conference> conferences = conferenceDao.selectAll();
return generateMap((List) conferences, number);
List<Consultation> consultations = consultationDao.selectAll();
Consultation consultation=null;
if(consultations!=null && consultations.size()>0)
{
for (Consultation item : consultations) {
consultation=item;
break;
}
}
double sum=0.0;
for (Conference conference : conferences) {
if(sum<number)
{
Pair value = new Pair(1, 1);
map.put(conference,value);
sum+=conference.cost(value,consultation);
}
}
while (sum<number)
{
for (Conference conference : map.keySet()) {
Pair pair = map.get(conference);
double oldCost=conference.cost(pair,consultation);
pair.setPeople(pair.getPeople()+1);
double newCost=conference.cost(pair,consultation);
sum+=(newCost-oldCost);
if(sum>=number) return map;
}
}
return map;
}
/**
......@@ -301,6 +339,18 @@ public class BudgetService implements IBudgetService {
return result;
}
@Override
public Map<Consultation, Integer> doConsultation(int n) {
List<Consultation> consultations = consultationDao.selectAll();
Map<Consultation,Integer> map=new HashMap<>();
if(consultations!=null && consultations.size()>0)
{
Consultation consultation = consultations.get(0);
map.put(consultation,n);
}
return map;
}
/**
* 合成其他费用(补差价)
*
......
package service.impl;
import beans.Equipment;
import org.springframework.stereotype.Service;
import service.IDetailService;
import java.util.Map;
@Service
public class DetailService implements IDetailService {
@Override
public double sumEquipment(Map<Equipment, Integer> equipments) {
return 0;
}
}
......@@ -61,11 +61,11 @@
</div>
</div>
</nav>
<%--
<div>
<button class="btn btn-success">同步预算</button>
<p class="help-block center-block">当且仅当在生成预算之后对规则进行了更改时需要此操作</p>
</div>
</div>--%>
<ul id="myTab" class="nav nav-tabs">
<li class="active">
......@@ -73,17 +73,17 @@
设备费
</a>
</li>
<li><a href="#material" data-toggle="tab">材料费</a></li>
<li><a href="#material" data-toggle="tab" onclick=showMaterial()>材料费</a></li>
<li><a href="#test" data-toggle="tab">测试化验加工费</a></li>
<li><a href="#power" data-toggle="tab">燃料动力费</a></li>
<li><a href="#travel" data-toggle="tab">差旅费</a></li>
<li><a href="#conference" data-toggle="tab">会议费</a></li>
<li><a href="#conference" data-toggle="tab">会议费(包含咨询费)</a></li>
<li><a href="#international" data-toggle="tab">国际交流合作费</a></li>
<li><a href="#property" data-toggle="tab">出版/文献/信息传播/知识产权事务费</a></li>
<li><a href="#labour" data-toggle="tab">劳务费</a></li>
<li><a href="#consultation" data-toggle="tab">咨询费</a></li>
<li><a href="#others" data-toggle="tab">其他费用</a></li>
<li><a href="#indirect" data-toggle="tab">间接费用</a></li>
<li><a href="#indirect" data-toggle="tab" onclick=showIndirect()>间接费用</a></li>
</ul>
......@@ -94,6 +94,20 @@
<%
}
%>
<div>
<div class="text-center">
<label>总预算</label>
期望:<label id="total-req"></label>
实际:<label id="total-sum"></label>
还差:<label id="total-diff"></label>
</div>
<div class="text-center">
<label>本类预算</label>
期望:<label id="this-req"></label>
实际:<label id="this-sum"></label>
还差:<label id="this-diff"></label>
</div>
</div>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="equipment">
......@@ -170,7 +184,7 @@
<label id="material-sum"><%=sum%>
</label>
还差:
<label id="material-diff"><%=req-sum%>
<label id="material-diff"><%=req - sum%>
</label>
</div>
<table class="table table-hover">
......@@ -312,6 +326,30 @@
</div>
<div class="tab-pane fade" id="conference">
<%
sum=0.0;
req=budget.getRequirement().getConference();
Map<Conference, Pair> conferencesMap = budget.getConferences();
Map<Consultation, Integer> consultationsMap = budget.getConsultations();
Consultation consultation=null;
for (Consultation item : consultationsMap.keySet()) {
consultation=item;
}
for (Conference conference : conferencesMap.keySet()) {
sum+=conferencesMap.get(conference).getDays()*((consultation.getPrice()*conference.getExperts())
+conference.getPrice()*conferencesMap.get(conference).getPeople());
}
%>
<div class="center-block">
需求:<label id="conf-req"><%=req%>
</label>
实际:
<label id="conf-sum"><%=sum%>
</label>
还差:
<label id="conf-diff"><%=req - sum%>
</label>
</div>
<table class="table table-hover">
<thead>
<tr>
......@@ -319,14 +357,12 @@
<th>名称</th>
<th>单价</th>
<th>需要专家</th>
<th>参会人数</th>
<th>会议次数</th>
<th>参会人数*会议次数</th>
</tr>
</thead>
<tbody>
<%
map = (Map) budget.getConferences();
IConferenceDao conferenceDao =
applicationContext.getBean(IConferenceDao.class);
List<Conference> conferences = conferenceDao.selectAll();
......@@ -336,13 +372,14 @@
out.write("<td>" + item.getName() + "</td>");
out.write("<td>" + item.getPrice() + "</td>");
out.write("<td>" + item.getExperts() + "</td>");
out.write("<td>" + item.getPeople() + "</td>");
int num = 0;
if (map.get(item) != null) {
num = map.get(item);
int people = 0, days = 0;
if (conferencesMap.get(item) != null) {
people = conferencesMap.get(item).getPeople();
days = conferencesMap.get(item).getDays();
}
out.write("<td>" +
"<input type='number' value='" + num + "' />" +
"<input type='number' value='" + people + "' />" +
"<input type='number' value='" + days + "' />" +
"<button type='btn btn-default' class='updateItem' onclick=conference(this)>确认</button>" +
"</td>");
}
......@@ -503,8 +540,30 @@
</div>
<div class="tab-pane fade" id="indirect">
<p>Enterprise Java Beans(EJB)是一个创建高度可扩展性和强大企业级应用程序的开发架构,部署在兼容应用程序服务器(比如 JBOSS、Web Logic 等)的 J2EE 上。
</p>
<table class="table table-hover">
<thead>
<tr>
<th hidden>ID</th>
<th>名称</th>
<th>费用</th>
<th>数量</th>
</tr>
</thead>
<tbody id="indirect-body">
</tbody>
<tr>
<td>
<input type="text">
</td>
<td><input type="number">
</td>
<td>
<input type="number">
<button class="btn" onclick=updateIndirect(this)>添加</button>
</td>
</tr>
</table>
</div>
</div>
......@@ -619,17 +678,24 @@
function conference(btn) {
var id = btn.parentElement.parentElement.firstElementChild.innerHTML;
var num = btn.parentElement.firstElementChild.value;
var people = btn.parentElement.childNodes.item(0).value;
var days = btn.parentElement.childNodes.item(1).value;
$.ajax({
url: "${pageContext.request.contextPath}/Budget/Modify/Conference",
type: "post",
data: {
mode: 0,
id: id,
nums: num
people: people,
days: days
},
success: function () {
alert("success");
success: function (data) {
req = Number(document.getElementById("conf-req").innerHTML)
data = Number(data)
document.getElementById("conf-sum").innerHTML = data
document.getElementById("conf-diff").innerHTML = req - data
//alert("success");
//location.reload();
}
})
......@@ -660,16 +726,107 @@
})
}
/* function init() {
var updateEquips=document.getElementsByClassName("updateEquipment");
alert(updateEquips.length);
var i;
for(i=0;i<updateEquips.length;i++)
{
var btn=updateEquips[i];
var num=btn.parentElement.parentElement.firstElementChild.innerHTML
btn.addEventListener("click",function () { alert(num) })
}
}*/
/**
* 更新差值
* @param type 当前预算种类
*/
function updateBudgetPage(type) {
$.ajax({
url: "${pageContext.request.contextPath}/Budget/Detail/Stats",
type: "post",
dataType:"json",
success: function (data) {
document.getElementById("total-req").innerHTML=data.req;
document.getElementById("total-sum").innerHTML=data.sum;
document.getElementById("total-diff").innerHTML=data.diff;
if(data.diff<0)
document.getElementById("total-diff").style.color="red";
else
document.getElementById("total-diff").style.color="green";
document.getElementById("this-req").innerHTML=data[type].req;
document.getElementById("this-sum").innerHTML=data[type].sum;
document.getElementById("this-diff").innerHTML=data[type].diff;
if(data[type].diff<0)
document.getElementById("this-diff").style.color="red";
else
document.getElementById("this-diff").style.color="green";
alert("updateBudgetPage");
//location.reload();
}
})
}
function showIndirect() {
$.ajax({
url: "${pageContext.request.contextPath}/Budget/Detail/Indirect",
type: "post",
dataType:"json",
success: function (data) {
var table=document.getElementById("indirect-body");
table.innerText="";
//alert(data.length)
list=data.indirects;
for(var i=0;i<list.length;i++)
{
appendIndirect(list[i].id,list[i].name,list[i].price,list[i].nums)
}
updateBudgetPage("indirect");
},
error:function (data) {
alert(data);
}
})
}
function appendIndirect(id,name,price,nums)
{
var table=document.getElementById("indirect-body");
var tr=document.createElement("tr");
// var td=document.createElement("td");
//td.innerHTML=(id==null)?0:id;
//tr.appendChild(td);
td=document.createElement("td");
input=document.createElement("input");
input.type="text";
input.value=name;
td.appendChild(input);
tr.appendChild(td);
td=document.createElement("td");
input=document.createElement("input");
input.type="number";
input.value=price;
td.appendChild(input);
tr.appendChild(td);
td=document.createElement("td");
input=document.createElement("input");
input.type="number";
input.value=nums;
td.appendChild(input);
var button=document.createElement("button");
button.innerHTML="确认";
button.classList.add("btn");
button.onclick=function (ev) { updateIndirect(button)};
td.appendChild(button);
tr.appendChild(td);
table.appendChild(tr);
}
function updateIndirect(btn) {
//alert(btn.innerHTML);
$.ajax({
url: "${pageContext.request.contextPath}/Budget/Modify/Indirect",
type: "post",
dataType:"json",
success: function (data) {
showIndirect();
updateBudgetPage();
},
error:function (data) {
alert("error");
}
})
}
</script>
......@@ -59,7 +59,7 @@
test = 15,
power = 0,
travel = 12,
conference = 3,
conference = 5,
international = 6,
property = 8,
labour = 66,
......
......@@ -51,7 +51,8 @@
</div>
</nav>
<button class="btn btn-success" onclick=jsp()>test</button>
<label id="xxx">123445</label>
<a href="Crawler/Workstation">爬取工作站数据</a><br>
<a href="Budget/Download">下载</a><br>
......@@ -61,5 +62,14 @@ ${pageContext.request.contextPath}<br>
<font size="<%=i%>"> hhhh</font>
<% }
%>
<script type="text/javascript">
var colors=["red","green","blue","orange"];
var i=0;
function jsp() {
document.getElementById("xxx").style.color=colors[i%colors.length];
i++;
}
</script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment