signForm.vue 5.6 KB

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