5 changed files with 173 additions and 62 deletions
@ -1,44 +1,85 @@
@@ -1,44 +1,85 @@
|
||||
/** |
||||
* Created by zuowenqi on 2018/2/2 0002 |
||||
*/ |
||||
class BS{ |
||||
constructor(){ |
||||
class BS { |
||||
constructor() { |
||||
|
||||
} |
||||
static fetch(url,data,type){ |
||||
return new Promise((resolve)=>{ |
||||
|
||||
static fetch(url, data, type) { |
||||
return new Promise((resolve) => { |
||||
$.ajax({ |
||||
type:type?type:'GET', |
||||
data:data?data:{}, |
||||
type: type ? type : 'GET', |
||||
data: data ? data : {}, |
||||
url, |
||||
success(resp){ |
||||
success(resp) { |
||||
resolve(resp) |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
} |
||||
static addAwards(award_name,award_capacity){ |
||||
console.log(); |
||||
return this.fetch('/add_award',{ |
||||
award_name,award_capacity |
||||
}); |
||||
|
||||
static addAwards(award_name, award_capacity) { |
||||
award_capacity*=1; |
||||
return this.fetch('/add_award', { |
||||
award_name, award_capacity |
||||
}); |
||||
} |
||||
static getAwards(){ |
||||
|
||||
static getAwards() { |
||||
return this.fetch('/awards'); |
||||
} |
||||
static setCurrent(id){ |
||||
return new Promise(resolve=>{ |
||||
let prev =localStorage.getItem('current_award')||''; |
||||
localStorage.setItem('prev_award',prev); |
||||
localStorage.setItem('current_award',id); |
||||
resolve(localStorage.getItem('current_award')); |
||||
}) |
||||
} |
||||
} |
||||
$(function(){ |
||||
BS.addAwards("一等奖",1).then(resp=>{ |
||||
console.log(resp) |
||||
|
||||
$(function () { |
||||
$('#add').click(e => { |
||||
layer.open({ |
||||
title:'增加', |
||||
content: `<div>
|
||||
奖品名<input type="text" id="addname"></div><div> |
||||
数量 <input type="text" id="addnum"> |
||||
</div>`, |
||||
yes: function () { |
||||
let name = $('#addname').val(); |
||||
let num = $('#addnum').val(); |
||||
BS.addAwards(name, num).then(resp => { |
||||
console.log(resp); |
||||
flushAwards() |
||||
}); |
||||
} |
||||
}); |
||||
}); |
||||
BS.addAwards("二等奖",5).then(resp=>{ |
||||
console.log(resp) |
||||
$('#reset').click(e => { |
||||
BS.fetch('/reset').then(resp => { |
||||
}); |
||||
}); |
||||
BS.addAwards("三等奖",10).then(resp=>{ |
||||
console.log(resp) |
||||
}); |
||||
BS.getAwards().then(resp=>{ |
||||
console.log(resp); |
||||
$(document).on('click','.set',e=>{ |
||||
let aid = $(e.target).data('aid'); |
||||
BS.setCurrent(aid).then((resp)=>{ |
||||
console.log(resp) |
||||
}) |
||||
}) |
||||
flushAwards() |
||||
|
||||
}); |
||||
|
||||
function flushAwards() { |
||||
BS.getAwards().then(resp => { |
||||
console.log(resp) |
||||
let ul = '' |
||||
resp.data.forEach((val) => { |
||||
let list = `<li><label>${val.award_name},${val.award_capacity}<a type="radio" class="button button-primary set" data-aid="${val.award_id}">设置成当前轮</a></label></li>` |
||||
ul += list; |
||||
}) |
||||
$('ul').html(ul) |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue