1 var indexProductAdd;//定义一个index作为产品添加弹出窗的layer打开返回值 ,用于关闭的时候使用
2 var indexProductUpdate; //定义一个index作为添加产品的弹出框的返回值
3 var product;
4 var page;
5 var bindData;
6
7 $(document).ready( function () {
8
9 /**
10 * 查询类型 【eq:产品:product 疾病:disease 基因:gene 】
11 */
12 var queryType;
13
14 /**
15 * 添加产品 页面
16 */
17
18 $(".btn-primary").click( function(){
19 indexProductAdd = layer.open({
20 type: 2,
21 title: "添加产品",
22 content: 'productadd.htmls',
23 area: ['500px', '580px']
24 });
25 });
26
27 /**
28 * updateproduct.htmls 更新 产品信息
29 */
30 $(document).on("click",".table-bordered tbody tr a[class='up']",function(){
31 product = $.parseJSON( $(this).parents('tr').find("input").eq(1).val());
32 $(this).parents('tr').find("input[type='checkbox']").prop("checked",true);//在点击更新按钮之后,勾选本行对应的checkbox
33 indexProductUpdate = layer.open({
34 type: 2,
35 title: "修改产品",
36 content: 'updateproduct.htmls',
37 area: ['500px', '580px'],
38 end : function(){
39 $(".table-bordered tbody :checked").attr("checked",false);
40 }
41 });
42 });
43
44
45
46
47
48 /**
49 * 封装数据 的方法 在本页面的js中,
50 */
51 bindData = function bindData(){
52 var result = page.result;
53 $(".table-bordered tbody").empty();
54 if(result != "" && result != null && result != undefined) {
55 var temp = "";
56 $.each(result, function(index, item) {
57 //JSON.stringify(item) 对象转化字符串
58 temp += "<tr class='text-c'><td><input type='checkbox' value='"+item.productId+"'><input type='hidden' value='"+JSON.stringify(item)+"'/></td><td>"+item.productName+"</td><td><a href='disease.htmls?productId="+item.productId+"' class='check'>【查看疾病信息】</a><a href='JavaScript:void(0)' class='up'>【更新】</a></td></tr>";
59 });
60 $(".table-bordered tbody").append(temp);
61 }
62 page.setValue();
63 }
64
65 /**
66 * 实例化一个分页组件的 对象
67 */
68 page = new page("queryAllProduct2.htmls", bindData);
69 page.pageSet();
70
71
72
73 /**
74 * 批量删除
75 */
76 $(".btn-danger").click(function(){
77 var productId = [];
78 $(".table-bordered tbody :checked").each(function(index,item){ //注意:checked前面需要空格
79 productId.push(item.value); //数组中添加数据 需要push()
80 });
81
82 if(productId.length == 0){
83 layer.msg('请选择至少一条记录!', {
84 icon: 3,
85 time: 2000 //2秒关闭(如果不配置,默认是3秒)
86 }, function(){
87 //do something
88 });
89 return;
90 }else{
91 $.post("productDelete.htmls?productId="+productId, function(data){
92 if(data){
93 layer.msg('删除成功!', {
94 icon: 1,
95 time: 2000 //2秒关闭(如果不配置,默认是3秒)
96 }, function(){
97 //do something
98 });
99
100 // page.cleanUp();
101 if($(".table-bordered tbody :checked").length == $(".table-bordered tbody tr").length && page.pageNo>1){//若本页全部删除
102 page.pageNo--;
103 }
104 page.pageSet();
105 }else{
106 layer.msg('删除失败!', {
107 icon: 2,
108 time: 2000 //2秒关闭(如果不配置,默认是3秒)
109 }, function(){
110 //do something
111 });
112 }
113 $(".table-hover thead :checked").attr("checked",false);
114 return;
115 });
116 }
117 });
118
119
120
121
122
123
124 } );