抗原检测统计小程序

抗原检测统计小程序

一、需求分析

1、项目背景

​ 核酸检测期间,每个宿舍都会根据实际居住人数,发放对应数量的检测盒,但是由于宿舍比较多,需要通过绕大圈的方式,来避免有遗漏的宿舍,而且抗原检测需要15分钟之内有效,最终需要把这些结果进行汇总。

​ 因此,为了提高工作效率,不希望使用手工统计,都是先绕大圈,先发放试剂盒,再绕大圈回来查看检测结果,最终汇总的结果,需要得出,楼层总人数,检测正常总人数,检测异常总人数。同样拿着纸笔记录统计十分麻烦,不方便而且效率很低。因此可以以微信小程序为载体,进行抗原检测统计小程序的搭建,尽可能的规避上述问题,为管理人员提供便捷。

2、功能性需求

  • 宿舍人员登记宿舍号和当前宿舍人数。
  • 得到抗原检测结果,宿舍人员提交检测结果
  • 管理人员查看楼层每个宿舍信息,以及楼层汇总信息
  • 管理人员登录

二、效果图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

三、代码

1、宿舍登记

  • 输入宿舍信息,添加到数据库,并提示
  • 宿舍信息已存在,则更新信息,并提示
  • 判断输入的宿舍号是否为数字,并提示

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('添加完成')
          }
        }
       })
    }}
})

2、结果登记

  • 输入宿舍号判断是否为数字,是否登记,并提示
  • 输入宿舍号,显示当前宿舍人数
  • 提交检测信息
  • 判断宿舍人数与检测正异常人数和是否相等

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'
              })
            }
          })
        }
      }
    }
  }

})

3、信息汇总

  • 显示宿舍相关信息
  • 分页显示
  • 汇总显示

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
      })
      }
    })
  }
})

4、我的信息

  • 获取用户名称和头像

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,
			})
		})
	},
})
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值