核酸检测期间,每个宿舍都会根据实际居住人数,发放对应数量的检测盒,但是由于宿舍比较多,需要通过绕大圈的方式,来避免有遗漏的宿舍,而且抗原检测需要15分钟之内有效,最终需要把这些结果进行汇总。
因此,为了提高工作效率,不希望使用手工统计,都是先绕大圈,先发放试剂盒,再绕大圈回来查看检测结果,最终汇总的结果,需要得出,楼层总人数,检测正常总人数,检测异常总人数。同样拿着纸笔记录统计十分麻烦,不方便而且效率很低。因此可以以微信小程序为载体,进行抗原检测统计小程序的搭建,尽可能的规避上述问题,为管理人员提供便捷。
index.wxml
<form bindsubmit="formsubmit">
<view class="view">宿舍号:</view>
<input type="number" name="code" placeholder="请输入宿舍号(数字)"/>
<view class="view">当前宿舍人数:</view>
<radio-group id="group" name="person">
<label><radio value="0"/>0</label>
<label><radio value="1"/>1</label>
<label><radio value="2"/>2</label>
<label><radio value="3"/>3</label>
<label><radio value="4"/>4</label>
<label><radio value="5"/>5</label>
<label><radio value="6"/>6</label>
</radio-group>
<view>
<button type="primary" class="button" form-type="submit" size="mini">点击提交</button>
<button type="primary" class="button" form-type="reset" size="mini">点击重置</button>
</view>
</form>
index.js
const db = wx.cloud.database()
Page({
data: {
//宿舍号
code:'',
//宿舍总人数
person:'',
//记录id,用于查询更新
id:''
},
formsubmit:function(e){
var that = this
//获取表单参数
that.setData({
code:e.detail.value.code,
person:e.detail.value.person
})
//判断表单项是否为空
if(that.data.code==''||that.data.code==undefined||that.data.person==''||that.data.person==undefined){
that.setData({
code:'',
person:''
})
wx.showToast({
title: '请填写完整',
icon:'error'
})
//判断宿舍号是否全是数字
}else if(!(/(^[0-9]*$)/.test(that.data.code))){
that.setData({
code:''
})
wx.showToast({
title: '宿舍号为数字',
icon:'error'
})
}else{
//查询数据库是否有该宿舍数据,如果有就更新,没有就创建
//查询数据库是否有数据
db.collection('WJX').where({
code:that.data.code,
}).get({
success:function(res){
let result = res.data[0]
console.log(result)
if(result!=undefined){
that.setData({
id:result._id
})
//更新数据
let time = new Date()
db.collection('WJX').doc(that.data.id).update({
data:{
person:parseInt(that.data.person),
time:time
},success:function(res){
wx.showToast({
title: '更新成功',
icon:'success'
})
console.log('更新成功')
}
})
}else{
//添加数据
let shijian = new Date()
db.collection('WJX').add({
data:{
code:that.data.code,
person:parseInt(that.data.person),
num1:'未提交',
num2:'未提交',
time:shijian
},success:function(e){
wx.showToast({
title: '添加成功',
icon:'success'
})
}
})
console.log('添加完成')
}
}
})
}}
})
one.wxml
<view class="view">宿舍号:</view>
<input type="number" name="code" placeholder="请输入宿舍号(数字)" bindblur="blur"/>
<view class="view">当前宿舍人数:<text>{{person}}</text></view>
<form bindsubmit="formsubmit">
<view class="view">当前宿舍检测正常人数:</view>
<radio-group class="group" name="person1">
<label><radio value="0"/>0</label>
<label><radio value="1"/>1</label>
<label><radio value="2"/>2</label>
<label><radio value="3"/>3</label>
<label><radio value="4"/>4</label>
<label><radio value="5"/>5</label>
<label><radio value="6"/>6</label>
</radio-group>
<view class="view">当前宿舍检测异常人数:</view>
<radio-group class="group" name="person2">
<label><radio value="0"/>0</label>
<label><radio value="1"/>1</label>
<label><radio value="2"/>2</label>
<label><radio value="3"/>3</label>
<label><radio value="4"/>4</label>
<label><radio value="5"/>5</label>
<label><radio value="6"/>6</label>
</radio-group>
<view>
<button type="primary" class="button" form-type="submit" size="mini">点击提交</button>
<button type="primary" class="button" form-type="reset" size="mini">点击重置</button>
</view>
</form>
one.js
const db = wx.cloud.database()
Page({
data: {
id:'',
//宿舍号
code:'',
//宿舍人数
person:undefined,
//正常人数
num1:'',
//异常人数
num2:''
},
//宿舍号失去焦点,宿舍号空/非数字提示,查询为空提示,查询到数据人数回显页面
blur:function(e){
var that = this
that.setData({
code:e.detail.value
})
//判断宿舍号是否为空
if(that.data.code==''||that.data.code==undefined){
wx.showToast({
title: '请输入宿舍号',
icon:'error'
})
}else{
console.log(that.data.code)
//判断宿舍号是否是数字
if(!(/(^[0-9]*$)/.test(that.data.code))){
that.setData({
code:''
})
wx.showToast({
title: '宿舍号是数字',
icon:'error'
})
}else{
//根据宿舍号查询
console.log('开始查询')
db.collection('WJX').where({
code:that.data.code
}).get({
success:function(res){
let result = res.data[0]
if(result!=undefined){
//获取宿舍人数
that.setData({
person:result.person,
id:result._id
})
console.log(that.data.id)
}else{
//查询数据为空,提示登记
that.setData({
code:''
})
wx.showToast({
title: '宿舍未登记',
icon:'error'
})
}
}
})
}
}
},
//宿舍检测结果提交
formsubmit:function(e){
var that = this
that.setData({
num1 : e.detail.value.person1,
num2 : e.detail.value.person2
})
if(that.data.code==''||that.data.code==undefined){
wx.showToast({
title: '请输入宿舍号',
icon:'error'
})
}else{
if(that.data.person==undefined){
wx.showToast({
title: '宿舍号有误',
icon:'error'
})
}else{
if(parseInt(that.data.num1)+parseInt(that.data.num2)!=parseInt(that.data.person)){
that.setData({
num1:'',
num2:''
})
wx.showToast({
title: '检测人数错误',
icon:'error'
})
}else{
console.log(that.data.num1)
console.log(that.data.num2)
let time = new Date()
db.collection('WJX').doc(that.data.id).update({
data:{
num1:parseInt(that.data.num1),
num2:parseInt(that.data.num2),
time:time
},success:function(res){
console.log('修改成功')
wx.showToast({
title: '提交成功',
icon:'success'
})
}
})
}
}
}
}
})
two.wxml
<view id="container">
<view class="view">宿舍号</view>
<view class="view">宿舍人数</view>
<view class="view">正常人数</view>
<view class="view">异常人数</view>
</view>
<view>
<block wx:for="{{list}}" wx:for-item="item" wx:key="index">
<view class="view">{{item.code}}</view>
<view class="view">{{item.person}}</view>
<view class="view">{{item.num1}}</view>
<view class="view">{{item.num2}}</view>
</block>
<view class="container_foot">
<button type="primary" size="mini" class="button" bindtap="btn_left">上一页</button>
当前页码:{{pagenum}}
<button type="primary" size="mini" class="button" bindtap="btn_right">下一页</button>
</view>
<view class="container_foot">
<view id="text">总页数:{{page}},总记录数:{{total}}</view>
</view>
</view>
<view id="foot">
<view class="text">宿舍总数:{{total}}</view>
<view class="text">宿舍总人数:{{person}}</view>
<view class="text">宿舍正常总人数:{{normal}}</view>
<view class="text">宿舍异常总人数:{{abnormal}}</view>
</view>
two.js
const db = wx.cloud.database()
const $ = db.command.aggregate
Page({
data: {
//当前页数据
list:[],
//当前页码
pagenum:1,
//每页显示条数
PAGE_SUM:5,
//总记录数
total:'',
//总页数
page:'',
//总人数
person:'',
//正常总人数
normal:'',
//异常总人数
abnormal:''
},
onLoad:function(e){
var that = this
//查询总记录数和总页数
db.collection('WJX').count({
success:function(s){
let total = s.total
let page = Math.ceil(total/that.data.PAGE_SUM)
console.log('总页数:'+page)
that.setData({
total:total,
page:page
})
}
})
//第一页显示
db.collection('WJX').skip((that.data.pagenum-1)*that.data.PAGE_SUM)
.limit(that.data.PAGE_SUM).get({
success:function(res){
console.log(res.data)
that.setData({
list:res.data
})
}
})
//聚合获取总人数(宿舍,正常,异常)
db.collection('WJX').aggregate().group({
_id:'totalperson',
totalperson:$.sum('$person'),
totalnormal:$.sum('$num1'),
totalabnormal:$.sum('$num2')
}).end({
success:function(res){
console.log(res.list[0])
that.setData({
person:res.list[0].totalperson,
normal:res.list[0].totalnormal,
abnormal:res.list[0].totalabnormal
})
console.log('person:'+that.data.person+',normal:'+that.data.normal+',abnormal:'+that.data.abnormal)
}
})
},
//上一页显示
btn_left:function(e){
var that = this
if(that.data.pagenum==1){
wx.showToast({
title: '已是首页',
icon:'error'
})
}else{
that.setData({
pagenum:that.data.pagenum-1
})
console.log(that.data.pagenum)
db.collection('WJX').skip((that.data.pagenum-1)*that.data.PAGE_SUM)
.limit(that.data.PAGE_SUM).get({
success:function(res){
console.log(res.data)
that.setData({
list:res.data
})
}
})
}
},
//下一页显示
btn_right:function(e){
var that = this
if(that.data.pagenum==that.data.page){
wx.showToast({
title: '已是末页',
icon:'error'
})
}else{
that.setData({
pagenum:that.data.pagenum+1
})
}
console.log(that.data.pagenum)
db.collection('WJX').skip((that.data.pagenum-1)*that.data.PAGE_SUM)
.limit(that.data.PAGE_SUM).get({
success:function(res){
console.log(res.data)
that.setData({
list:res.data
})
}
})
}
})
three.wxml
<view class="denglu">
<image src="{{touxiang}}" mode="widthFix" style="width:70px"></image>
<text style="color:#FFF;font:40px">{{nicheng}}</text>
</view>
<view wx:if="{{appid==''}}">
<button bindtap="getProfile" type="primary">点击获取用户信息</button>
</view>
<view wx:else>
<view class="view">欢迎【{{nicheng}}】登录</view>
<view class="view">我的appid:{{appid}}</view>
<view id="view">
<view class="view">积极配合</view>
<view class="view">听从指挥</view>
<view class="view">做好防护</view>
</view>
</view>
three.wxss
.denglu{
width: 100%;
height: 200px;
background-color: #E54847;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
}
image{
border-radius:35px;
}
.view{
text-align: center;
margin-top: 5%;
}
#view{
margin-top: 20%;
}
three.js
Page({
data: {
touxiang:'/images/profile.png',
nicheng:'',
appid:''
},
getProfile(event) {
var that=this
console.log(event);
wx.getUserProfile({
"desc":"获取授权"
}).then( res => {
console.log(res)
wx.cloud.callFunction({
name:'profile'
}).then( res => {
console.log(res)
that.setData({
appid:res.result.appid
})
})
that.setData({
touxiang:res.userInfo.avatarUrl,
nicheng: res.userInfo.nickName,
})
})
},
})