123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <template>
- <view class="content">
- <u-card :title="'总数(' + studentNum + ')人'" title-size="32" margin="0px 0px 10px 0px" :head-style="cardStyle">
- <u-grid :col="3" slot="body" :border="false">
- <u-grid-item v-for="(item, index) in studentList" :key="index" :custom-style="gridCustomStyle" @click.native.stop="setSignCheck(item)">
- <view class="avatar-box">
- <u-avatar :src="item.url" mode="circle" size="160" v-if="item.hasHead == 1"></u-avatar>
- <u-upload :custom-btn="true" :max-count="1" :index="index" :multiple="false" :show-progress="false"
- :preview-full-image="false" :action="uploadUrl" :header="uploadHeader" @on-success="uploadSuccess" @on-error="uploadError"
- @on-remove="uploadRemove" @on-preview-error="uploadPreview" v-else>
- <view slot="addBtn" class="slot-btn">
- <u-icon name="camera-fill" size="60" color="#999999"></u-icon>
- </view>
- </u-upload>
- <u-icon name="checkmark-circle-fill" v-if="item.state == 1 || item.checked" class="check-icon"></u-icon>
- <view class="grid-text">{{item.name}}</view>
- </view>
- </u-grid-item>
- <u-grid-item :custom-style="gridCustomStyle" @click="goToSelectStudent()">
- <view class="slot-btn">
- <u-icon name="plus" size="60" color="#999999"></u-icon>
- </view>
- </u-grid-item>
- </u-grid>
- </u-card>
- <view class="handle-fix-box">
- <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">
- {{status == 0 ? '签到确认' : '今日已签到'}}
- <!-- :disabled="status != 0" -->
- </u-button>
- </view>
- <u-top-tips ref="uTips"></u-top-tips>
- </view>
- </template>
- <script>
- import {
- mapGetters
- } from 'vuex'
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- computed: {
- ...mapGetters([
- 'mainColor',
- 'customStyle',
- ])
- },
- data() {
- return {
- classId: '',
- venueId:'',
- status: 0,
- uploadUrl: API.uploadFile,
- uploadHeader: {
- Authorization: uni.getStorageSync('token')
- },
- studentList: [],
- cardStyle: {
- fontWeight: 'bold'
- },
- gridCustomStyle: {
- padding: '0 2px'
- },
- studentNum: 0
- }
- },
- onLoad(options) {
- this.classId = options.id
- //this.status = options.status
- this.status = 0
- this.venueId = options.venueId
- },
- onShow() {
- this.initialize()
- },
- methods: {
- // 获取初始化数据
- initialize() {
- NET.request(API.getSignStudentList, {
- id: this.classId
- }, 'POST').then(res => {
- res.data.forEach(site => site.checked = false)
- this.studentList = res.data
- const checkedList = uni.getStorageSync('signUserList').length ? uni.getStorageSync('signUserList') : []
- checkedList.forEach(
- checkedItem => {
- if(this.studentList.filter(item=>checkedItem.id==item.id).length==0){
- this.studentList.push(checkedItem)
- }
- }
- )
- this.studentNum = this.studentList.length
- }).catch(error => {
- this.$refs.uTips.show({
- title: error.message,
- type: 'warning',
- })
- })
- },
- // 文件上传成功回调
- uploadSuccess(res, index, lists, name) {
- this.studentList[name].url = res.data.url
- this.studentList[name].fileId = res.data.id
- this.$refs.uTips.show({
- title: '文件上传成功',
- type: 'success',
- })
- return true
- },
- // 文件上传失败回调
- uploadError(res, index, lists, name) {
- this.$refs.uTips.show({
- title: '文件上传失败',
- type: 'warning',
- })
- },
- // 移除文件回调
- uploadRemove(index, lists, name) {
- this.studentList[name].url = ''
- this.studentList[name].fileId = ''
- },
- // 预览文件回调
- uploadPreview(url, lists, name) {
- if (this.status == 0) {
- this.studentList[name].checked = this.studentList[name].checked ? false : true
- }
- },
- // 设置是否签到
- setSignCheck(item) {
- if (this.status == 0) {
- item.checked = item.checked ? false : true
- }
- },
- // 跳转选择学生页面
- goToSelectStudent() {
- uni.navigateTo({
- url: '/pagesClass/signStudentList?venueId='+this.venueId
- });
- },
- // 跳转签到表单
- goToSignForm() {
- uni.navigateTo({
- url: '/pagesMember/signForm?id=' + this.classId
- });
- },
- // 提交表单
- submitForm() {
- console.log(this.studentList)
- NET.request(API.submitSignForm, {
- classId: this.classId,
- signStudentIdList: this.studentList.filter(site => site.state != 1 && site.checked).map(site => {
- if (site.fileId) {
- return {
- id: site.id,
- fileId: site.fileId,
- }
- } else {
- return {
- id: site.id,
- }
- }
- })
- }, 'POST').then(res => {
- this.$refs.uTips.show({
- title: '签到成功',
- type: 'success',
- })
- setTimeout(() => {
- uni.navigateBack()
- }, 1000)
- }).catch(error => {
- this.$refs.uTips.show({
- title: error.message,
- type: 'warning',
- })
- })
- },
- },
- }
- </script>
- <style>
- page {
- width: 100%;
- height: 100%;
- position: relative;
- }
- </style>
- <style lang="scss" scoped>
- @import "@/static/css/themes.scss";
- .content {
- width: 100%;
- float: left;
- padding-bottom: 60px;
- /deep/.u-list-item {
- width: 160rpx !important;
- height: 160rpx !important;
- border-radius: 50% !important;
- margin: 0 !important;
- }
- /deep/.u-avatar__level {
- left: 50%;
- transform: translateX(-50%);
- bottom: -6px !important;
- }
- /deep/.u-upload {
- height: 160rpx !important;
- }
- .check-icon {
- color: $mainColor;
- font-size: 20px;
- color: #ff6e3e;
- font-size: 26px;
- position: absolute;
- top: 120rpx;
- left: 50%;
- transform: translateX(-50%);
- background: #ffffff;
- border-radius: 50%;
- }
- .avatar-box {
- height: 200rpx;
- position: relative;
- }
- .grid-text {
- line-height: 40rpx;
- text-align: center;
- margin-top: 10rpx;
- }
- .slot-btn {
- width: 160rpx;
- height: 160rpx;
- border-radius: 50%;
- border: 1px solid #999999;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- }
- </style>
|