Browse Source

增加精选项目超过9个数处理

tags/v1.21.12.2^2
wangjr 3 years ago
parent
commit
23e29f1e78
1 changed files with 20 additions and 7 deletions
  1. +20
    -7
      templates/org/select_pro.tmpl

+ 20
- 7
templates/org/select_pro.tmpl View File

@@ -20,7 +20,7 @@
} }


.content_list{ .content_list{
max-height: 200px;
max-height: 130px;
overflow: auto; overflow: auto;
} }
.Relist{ .Relist{
@@ -152,11 +152,12 @@
var num=0; var num=0;


function showcreate(obj){ function showcreate(obj){
document.getElementById("search_selectPro").value=''
$('.ui.modal') $('.ui.modal')
.modal({ .modal({
centered: false, centered: false,
onShow:function(){ onShow:function(){
$("#org_list").empty()
$("#org_list").empty()
getPro(1) getPro(1)
}, },
@@ -179,7 +180,7 @@
pro_html = getHTML(data) pro_html = getHTML(data)
$("#org_list").append(pro_html) $("#org_list").append(pro_html)
console.log('原始',data) console.log('原始',data)
checkedNum()
checkedNum(0)
} }
}); });
} }
@@ -188,11 +189,11 @@
for (let i=0;i<data.length;i++){ for (let i=0;i<data.length;i++){
if (data[i].Selected==true){ if (data[i].Selected==true){
console.log("data[i]:",data[i]) console.log("data[i]:",data[i])
pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" checked="" onclick="checkedNum()" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected=${data[i].Selected} > <label> ${data[i].RepoName} </label></div>`
pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" id = " ${i}" checked="" onclick="checkedNum(${i})" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected=${data[i].Selected} > <label> ${data[i].RepoName} </label></div>`
pro_html += '</div>' pro_html += '</div>'
} }
else{ else{
pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" onclick="checkedNum()" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected= ${data[i].Selected}> <label> ${data[i].RepoName} </label></div>`
pro_html += `<div class="ui checkbox" style="width: 33%;margin-bottom:10px" > <input type="checkbox" id = "${i}" onclick="checkedNum(${i})" class="Relist" name ='select_pro_name' data-repoid="${data[i].RepoID}" data-reponame="${data[i].RepoName}" data-selected= ${data[i].Selected}> <label> ${data[i].RepoName} </label></div>`
pro_html += '</div>' pro_html += '</div>'
} }
} }
@@ -205,6 +206,10 @@


saveData.push(parseInt(this.dataset.repoid)); saveData.push(parseInt(this.dataset.repoid));
}) })
if(saveData.length>9){
alert("最多可选9个,保存失败")
return
}
// saveData = getSelecteDataID(); // saveData = getSelecteDataID();
// console.log("数据:",saveData) // console.log("数据:",saveData)
$.ajax({ $.ajax({
@@ -227,7 +232,7 @@
var selectedData=[]; var selectedData=[];
$('input[name="select_pro_name"]:checked').each(function(){ $('input[name="select_pro_name"]:checked').each(function(){
// console.log(this) // console.log(this)
console.log('值',this.dataset.selected)
// console.log('值',this.dataset.selected)


selectedData.push({"RepoID":parseInt(this.dataset.repoid),"RepoName":this.dataset.reponame,"Selected":JSON.parse(this.dataset.selected)}); selectedData.push({"RepoID":parseInt(this.dataset.repoid),"RepoName":this.dataset.reponame,"Selected":JSON.parse(this.dataset.selected)});
}) })
@@ -272,14 +277,22 @@
} }
} }


function checkedNum(){
function checkedNum(id){

num=0; num=0;
var inputs = document.getElementsByName("select_pro_name") var inputs = document.getElementsByName("select_pro_name")
for (var i=0;i<inputs.length;i++){ for (var i=0;i<inputs.length;i++){
if(inputs[i].checked){ if(inputs[i].checked){
num++ num++
if(num>9){
document.getElementById(id).checked=false
alert("选择超过9个,请重新选择!")
return
}
} }
} }

var show_num = 9-num; var show_num = 9-num;
document.getElementById("recommend").innerHTML="还能推荐"+show_num+"个" document.getElementById("recommend").innerHTML="还能推荐"+show_num+"个"




Loading…
Cancel
Save