signForm.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="content">
  3. <u-card :title="'总数(' + studentList.length + ')人'" 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. status: '',
  52. uploadUrl: API.uploadFile,
  53. uploadHeader: {
  54. Authorization: uni.getStorageSync('token')
  55. },
  56. studentList: [],
  57. cardStyle: {
  58. fontWeight: 'bold'
  59. },
  60. gridCustomStyle: {
  61. padding: '0 2px'
  62. }
  63. }
  64. },
  65. onLoad(options) {
  66. this.classId = options.id
  67. this.status = options.status
  68. },
  69. onShow() {
  70. this.initialize()
  71. },
  72. methods: {
  73. // 获取初始化数据
  74. initialize() {
  75. NET.request(API.getSignStudentList, {
  76. id: this.classId
  77. }, 'POST').then(res => {
  78. res.data.forEach(site => site.checked = false)
  79. this.studentList = res.data
  80. const checkedList = uni.getStorageSync('signUserList').length ? uni.getStorageSync('signUserList') : []
  81. checkedList.forEach(
  82. checkedItem => {
  83. if(this.studentList.filter(item=>checkedItem.id==item.id).length==0){
  84. this.studentList.push(checkedItem)
  85. }
  86. }
  87. )
  88. }).catch(error => {
  89. this.$refs.uTips.show({
  90. title: error.message,
  91. type: 'warning',
  92. })
  93. })
  94. },
  95. // 文件上传成功回调
  96. uploadSuccess(res, index, lists, name) {
  97. this.studentList[name].url = res.data.url
  98. this.studentList[name].fileId = res.data.id
  99. this.$refs.uTips.show({
  100. title: '文件上传成功',
  101. type: 'success',
  102. })
  103. return true
  104. },
  105. // 文件上传失败回调
  106. uploadError(res, index, lists, name) {
  107. this.$refs.uTips.show({
  108. title: '文件上传失败',
  109. type: 'warning',
  110. })
  111. },
  112. // 移除文件回调
  113. uploadRemove(index, lists, name) {
  114. this.studentList[name].url = ''
  115. this.studentList[name].fileId = ''
  116. },
  117. // 预览文件回调
  118. uploadPreview(url, lists, name) {
  119. if (this.status == 0) {
  120. this.studentList[name].checked = this.studentList[name].checked ? false : true
  121. }
  122. },
  123. // 设置是否签到
  124. setSignCheck(item) {
  125. if (this.status == 0) {
  126. item.checked = item.checked ? false : true
  127. }
  128. },
  129. // 跳转选择学生页面
  130. goToSelectStudent() {
  131. uni.navigateTo({
  132. url: '/pagesClass/signStudentList'
  133. });
  134. },
  135. // 跳转签到表单
  136. goToSignForm() {
  137. uni.navigateTo({
  138. url: '/pagesMember/signForm?id=' + this.classId
  139. });
  140. },
  141. // 提交表单
  142. submitForm() {
  143. NET.request(API.submitSignForm, {
  144. classId: this.classId,
  145. signStudentIdList: this.studentList.filter(site => site.state == 1 || site.checked).map(site => {
  146. if (site.fileId) {
  147. return {
  148. id: site.id,
  149. fileId: site.fileId,
  150. }
  151. } else {
  152. return {
  153. id: site.id,
  154. }
  155. }
  156. })
  157. }, 'POST').then(res => {
  158. this.$refs.uTips.show({
  159. title: '签到成功',
  160. type: 'success',
  161. })
  162. setTimeout(() => {
  163. uni.navigateBack()
  164. }, 1000)
  165. }).catch(error => {
  166. this.$refs.uTips.show({
  167. title: error.message,
  168. type: 'warning',
  169. })
  170. })
  171. },
  172. },
  173. }
  174. </script>
  175. <style>
  176. page {
  177. width: 100%;
  178. height: 100%;
  179. position: relative;
  180. }
  181. </style>
  182. <style lang="scss" scoped>
  183. @import "@/static/css/themes.scss";
  184. .content {
  185. width: 100%;
  186. float: left;
  187. padding-bottom: 60px;
  188. /deep/.u-list-item {
  189. width: 160rpx !important;
  190. height: 160rpx !important;
  191. border-radius: 50% !important;
  192. margin: 0 !important;
  193. }
  194. /deep/.u-avatar__level {
  195. left: 50%;
  196. transform: translateX(-50%);
  197. bottom: -6px !important;
  198. }
  199. /deep/.u-upload {
  200. height: 160rpx !important;
  201. }
  202. .check-icon {
  203. color: $mainColor;
  204. font-size: 20px;
  205. color: #ff6e3e;
  206. font-size: 16px;
  207. position: absolute;
  208. top: 136rpx;
  209. left: 50%;
  210. transform: translateX(-50%);
  211. background: #ffffff;
  212. border-radius: 50%;
  213. }
  214. .avatar-box {
  215. height: 200rpx;
  216. position: relative;
  217. }
  218. .grid-text {
  219. line-height: 40rpx;
  220. text-align: center;
  221. margin-top: 10rpx;
  222. }
  223. .slot-btn {
  224. width: 160rpx;
  225. height: 160rpx;
  226. border-radius: 50%;
  227. border: 1px solid #999999;
  228. display: flex;
  229. justify-content: center;
  230. align-items: center;
  231. }
  232. }
  233. </style>