signForm.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="content">
  3. <u-card :title="'总数(' + studentNum + ')人'" title-size="32" margin="0px 0px 10px 0px" :head-style="cardStyle">
  4. <u-grid :col="3" slot="body" :border="false">
  5. <u-grid-item v-for="(item, index) in studentList" :key="index" :custom-style="gridCustomStyle" @click.native.stop="setSignCheck(item)">
  6. <view class="avatar-box">
  7. <u-avatar :src="item.url" mode="circle" size="160" v-if="item.hasHead == 1"></u-avatar>
  8. <u-upload :custom-btn="true" :max-count="1" :index="index" :multiple="false" :show-progress="false"
  9. :preview-full-image="false" :action="uploadUrl" :header="uploadHeader" @on-success="uploadSuccess" @on-error="uploadError"
  10. @on-remove="uploadRemove" @on-preview-error="uploadPreview" v-else>
  11. <view slot="addBtn" class="slot-btn">
  12. <u-icon name="camera-fill" size="60" color="#999999"></u-icon>
  13. </view>
  14. </u-upload>
  15. <u-icon name="checkmark-circle-fill" v-if="item.state == 1 || item.checked" class="check-icon"></u-icon>
  16. <view class="grid-text">{{item.name}}</view>
  17. </view>
  18. </u-grid-item>
  19. <u-grid-item :custom-style="gridCustomStyle" @click="goToSelectStudent()">
  20. <view class="slot-btn">
  21. <u-icon name="plus" size="60" color="#999999"></u-icon>
  22. </view>
  23. </u-grid-item>
  24. </u-grid>
  25. </u-card>
  26. <view class="handle-fix-box">
  27. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">
  28. {{status == 0 ? '签到确认' : '今日已签到'}}
  29. <!-- :disabled="status != 0" -->
  30. </u-button>
  31. </view>
  32. <u-top-tips ref="uTips"></u-top-tips>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. mapGetters
  38. } from 'vuex'
  39. const NET = require('@/utils/request')
  40. const API = require('@/config/api')
  41. export default {
  42. computed: {
  43. ...mapGetters([
  44. 'mainColor',
  45. 'customStyle',
  46. ])
  47. },
  48. data() {
  49. return {
  50. classId: '',
  51. venueId:'',
  52. status: 0,
  53. uploadUrl: API.uploadFile,
  54. uploadHeader: {
  55. Authorization: uni.getStorageSync('token')
  56. },
  57. studentList: [],
  58. cardStyle: {
  59. fontWeight: 'bold'
  60. },
  61. gridCustomStyle: {
  62. padding: '0 2px'
  63. },
  64. studentNum: 0
  65. }
  66. },
  67. onLoad(options) {
  68. this.classId = options.id
  69. //this.status = options.status
  70. this.status = 0
  71. this.venueId = options.venueId
  72. },
  73. onShow() {
  74. this.initialize()
  75. },
  76. methods: {
  77. // 获取初始化数据
  78. initialize() {
  79. NET.request(API.getSignStudentList, {
  80. id: this.classId
  81. }, 'POST').then(res => {
  82. res.data.forEach(site => site.checked = false)
  83. this.studentList = res.data
  84. const checkedList = uni.getStorageSync('signUserList').length ? uni.getStorageSync('signUserList') : []
  85. checkedList.forEach(
  86. checkedItem => {
  87. if(this.studentList.filter(item=>checkedItem.id==item.id).length==0){
  88. this.studentList.push(checkedItem)
  89. }
  90. }
  91. )
  92. this.studentNum = this.studentList.length
  93. }).catch(error => {
  94. this.$refs.uTips.show({
  95. title: error.message,
  96. type: 'warning',
  97. })
  98. })
  99. },
  100. // 文件上传成功回调
  101. uploadSuccess(res, index, lists, name) {
  102. this.studentList[name].url = res.data.url
  103. this.studentList[name].fileId = res.data.id
  104. this.$refs.uTips.show({
  105. title: '文件上传成功',
  106. type: 'success',
  107. })
  108. return true
  109. },
  110. // 文件上传失败回调
  111. uploadError(res, index, lists, name) {
  112. this.$refs.uTips.show({
  113. title: '文件上传失败',
  114. type: 'warning',
  115. })
  116. },
  117. // 移除文件回调
  118. uploadRemove(index, lists, name) {
  119. this.studentList[name].url = ''
  120. this.studentList[name].fileId = ''
  121. },
  122. // 预览文件回调
  123. uploadPreview(url, lists, name) {
  124. if (this.status == 0) {
  125. this.studentList[name].checked = this.studentList[name].checked ? false : true
  126. }
  127. },
  128. // 设置是否签到
  129. setSignCheck(item) {
  130. if (this.status == 0) {
  131. item.checked = item.checked ? false : true
  132. }
  133. },
  134. // 跳转选择学生页面
  135. goToSelectStudent() {
  136. uni.navigateTo({
  137. url: '/pagesClass/signStudentList?venueId='+this.venueId
  138. });
  139. },
  140. // 跳转签到表单
  141. goToSignForm() {
  142. uni.navigateTo({
  143. url: '/pagesMember/signForm?id=' + this.classId
  144. });
  145. },
  146. // 提交表单
  147. submitForm() {
  148. console.log(this.studentList)
  149. NET.request(API.submitSignForm, {
  150. classId: this.classId,
  151. signStudentIdList: this.studentList.filter(site => site.state != 1 && site.checked).map(site => {
  152. if (site.fileId) {
  153. return {
  154. id: site.id,
  155. fileId: site.fileId,
  156. }
  157. } else {
  158. return {
  159. id: site.id,
  160. }
  161. }
  162. })
  163. }, 'POST').then(res => {
  164. this.$refs.uTips.show({
  165. title: '签到成功',
  166. type: 'success',
  167. })
  168. setTimeout(() => {
  169. uni.navigateBack()
  170. }, 1000)
  171. }).catch(error => {
  172. this.$refs.uTips.show({
  173. title: error.message,
  174. type: 'warning',
  175. })
  176. })
  177. },
  178. },
  179. }
  180. </script>
  181. <style>
  182. page {
  183. width: 100%;
  184. height: 100%;
  185. position: relative;
  186. }
  187. </style>
  188. <style lang="scss" scoped>
  189. @import "@/static/css/themes.scss";
  190. .content {
  191. width: 100%;
  192. float: left;
  193. padding-bottom: 60px;
  194. /deep/.u-list-item {
  195. width: 160rpx !important;
  196. height: 160rpx !important;
  197. border-radius: 50% !important;
  198. margin: 0 !important;
  199. }
  200. /deep/.u-avatar__level {
  201. left: 50%;
  202. transform: translateX(-50%);
  203. bottom: -6px !important;
  204. }
  205. /deep/.u-upload {
  206. height: 160rpx !important;
  207. }
  208. .check-icon {
  209. color: $mainColor;
  210. font-size: 20px;
  211. color: #ff6e3e;
  212. font-size: 26px;
  213. position: absolute;
  214. top: 120rpx;
  215. left: 50%;
  216. transform: translateX(-50%);
  217. background: #ffffff;
  218. border-radius: 50%;
  219. }
  220. .avatar-box {
  221. height: 200rpx;
  222. position: relative;
  223. }
  224. .grid-text {
  225. line-height: 40rpx;
  226. text-align: center;
  227. margin-top: 10rpx;
  228. }
  229. .slot-btn {
  230. width: 160rpx;
  231. height: 160rpx;
  232. border-radius: 50%;
  233. border: 1px solid #999999;
  234. display: flex;
  235. justify-content: center;
  236. align-items: center;
  237. }
  238. }
  239. </style>