5 changed files with 173 additions and 62 deletions
@ -1,44 +1,85 @@ |
|||||||
/** |
/** |
||||||
* Created by zuowenqi on 2018/2/2 0002 |
* Created by zuowenqi on 2018/2/2 0002 |
||||||
*/ |
*/ |
||||||
class BS{ |
class BS { |
||||||
constructor(){ |
constructor() { |
||||||
|
|
||||||
} |
} |
||||||
static fetch(url,data,type){ |
|
||||||
return new Promise((resolve)=>{ |
static fetch(url, data, type) { |
||||||
|
return new Promise((resolve) => { |
||||||
$.ajax({ |
$.ajax({ |
||||||
type:type?type:'GET', |
type: type ? type : 'GET', |
||||||
data:data?data:{}, |
data: data ? data : {}, |
||||||
url, |
url, |
||||||
success(resp){ |
success(resp) { |
||||||
resolve(resp) |
resolve(resp) |
||||||
} |
} |
||||||
}) |
}) |
||||||
}) |
}) |
||||||
|
|
||||||
} |
} |
||||||
static addAwards(award_name,award_capacity){ |
|
||||||
console.log(); |
static addAwards(award_name, award_capacity) { |
||||||
return this.fetch('/add_award',{ |
award_capacity*=1; |
||||||
award_name,award_capacity |
return this.fetch('/add_award', { |
||||||
|
award_name, award_capacity |
||||||
}); |
}); |
||||||
} |
} |
||||||
static getAwards(){ |
|
||||||
|
static getAwards() { |
||||||
return this.fetch('/awards'); |
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=>{ |
$(function () { |
||||||
console.log(resp) |
$('#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) |
|
||||||
}); |
}); |
||||||
BS.addAwards("三等奖",10).then(resp=>{ |
|
||||||
console.log(resp) |
|
||||||
}); |
}); |
||||||
BS.getAwards().then(resp=>{ |
$('#reset').click(e => { |
||||||
console.log(resp); |
BS.fetch('/reset').then(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