index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="title"
  5. class="upload-upload"
  6. :visible.sync="topVisible"
  7. :before-close="handleClose"
  8. :width="selectType ? '50%' : '30%'">
  9. <template v-if="selectType">
  10. <template v-if="gradeData.length > 0">
  11. <div style="margin-bottom: 15px;">
  12. <div style="text-align: center;" v-if="selectType == 'class'">
  13. <el-radio-group v-model="selTab">
  14. <el-radio-button label="班级"></el-radio-button>
  15. <el-radio-button label="个人"></el-radio-button>
  16. </el-radio-group>
  17. </div>
  18. </div>
  19. <div style="border: 1px solid #ebebeb; padding: 8px;">
  20. <div style="font-weight: 600;margin-bottom: 8px;">选择年级</div>
  21. <el-radio-group v-model="checkedGrade" size="mini">
  22. <el-radio v-for="grade in gradeData" :label="grade.gradeId" :key="grade.gradeId" @change="changeGrade"
  23. border>{{ grade.gradeName }}
  24. </el-radio>
  25. </el-radio-group>
  26. <div v-if="classData.length > 0">
  27. <div style="font-weight: 600;margin-bottom: 8px;margin-top: 8px;">选择班级</div>
  28. <el-radio-group v-model="checkedClass" size="mini">
  29. <el-radio v-for="classes in classData" :label="classes.classId" :key="classes.classId"
  30. @change="changeClass" border>{{ classes.className }}
  31. </el-radio>
  32. </el-radio-group>
  33. </div>
  34. </div>
  35. </template>
  36. <div v-else style="color: #dbdbdb; text-align: center;margin-bottom: 20px;">当前用户没有查找到班级和学生信息</div>
  37. <template v-if="'class' != selectType || selTab == '个人'">
  38. <div class="student_container" v-if="studentData.length > 0"
  39. style="border: 1px solid #ebebeb; padding: 15px;margin-top: 15px;">
  40. <el-checkbox :indeterminate="studentIndeterminate" v-model="studentAll" @change="handleStudentAllChange">
  41. 全选学生
  42. </el-checkbox>
  43. <el-checkbox-group v-model="checkedStudent" @change="handleStudentChange">
  44. <el-checkbox v-for="student in studentData" :label="student.code" :key="student.id"
  45. :disabled="defaultSelected.includes(student.code)">{{ student.name }}
  46. </el-checkbox>
  47. </el-checkbox-group>
  48. </div>
  49. </template>
  50. <div style="margin-top: 8px;" v-if="'class' != selectType">
  51. <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="remark"></el-input>
  52. </div>
  53. </template>
  54. <div v-else class="text-center" style="margin: 20px 0 50px 0;">
  55. <el-button v-if="pageName" :type="type==1?'primary':''" @click="type=1">{{ pageName }}</el-button>
  56. <el-button v-if="isZdy" :type="type==2?'primary':''" @click="type=2,visible=true" style="margin-left:20px">自定义
  57. </el-button>
  58. </div>
  59. <div class="text-center">
  60. <el-button type="primary" style="margin-top: 20px;" round @click="handleSave">确定{{ scene }}</el-button>
  61. </div>
  62. </el-dialog>
  63. <el-dialog class="upload-upload" title="自定义" :visible.sync="visible" width="30%">
  64. <el-form ref="form" :model="form" :rules="rules" label-width="80px" style="margin-top:20px">
  65. <el-form-item label="文件名称" prop="name">
  66. <el-input v-model="form.name"></el-input>
  67. </el-form-item>
  68. </el-form>
  69. <div class="text-center">
  70. <el-button type="primary" round @click="save" style=" margin-top: 30px;margin-bottom: 30px;">确定{{ scene }}
  71. </el-button>
  72. </div>
  73. </el-dialog>
  74. </div>
  75. </template>
  76. <script>
  77. import * as back from '@/api/webApi/back'
  78. import { getClassStudents } from '@/api/webApi/front'
  79. export default {
  80. props: {
  81. title: { //标题
  82. type: String,
  83. default: () => {
  84. }
  85. },
  86. pageName: {
  87. type: String,
  88. default: () => {
  89. }
  90. },
  91. dialogVisible: {// 显示隐藏
  92. type: Boolean,
  93. default: false
  94. },
  95. isZdy: {
  96. // 是否自定义
  97. type: Boolean,
  98. default: true
  99. },
  100. selectType: {
  101. type: String,
  102. default: ''
  103. },
  104. scene: {
  105. type: String,
  106. default: '上传'
  107. },
  108. defaultSelected: {
  109. type: Array,
  110. default: () => []
  111. }
  112. },
  113. data() {
  114. return {
  115. form: {
  116. name: ''
  117. },
  118. visible: false,
  119. type: 1,
  120. gradeData: [],
  121. classData: [],
  122. studentData: [],
  123. checkedGrade: '',
  124. checkedClass: '',
  125. checkedStudent: [...this.defaultSelected],
  126. gradeIndeterminate: true,
  127. classIndeterminate: true,
  128. studentIndeterminate: true,
  129. gradeAll: false,
  130. classAll: false,
  131. studentAll: false,
  132. rules: {
  133. name: [
  134. { required: true, message: '请输入文件名称', trigger: 'blur' },
  135. { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' }
  136. ]
  137. },
  138. selTab: this.selectType == 'class' ? '班级' : '个人',
  139. remark: ''
  140. }
  141. },
  142. computed: {
  143. topVisible: {
  144. get: function() {
  145. return this.dialogVisible
  146. },
  147. set: function(val) {
  148. this.$emit('update:dialogVisible', val)
  149. }
  150. }
  151. },
  152. watch: {
  153. 'gradeId': function(value) {
  154. this.checkList = []
  155. this.group = []
  156. if (value) {
  157. let subjectParam = {
  158. gradeId: value
  159. }
  160. back.getUserClasses(subjectParam).then(response => {
  161. this.group = response.data
  162. }).catch(err => {
  163. })
  164. } else {
  165. }
  166. }
  167. },
  168. created() {
  169. if (this.selectType) {
  170. this.getStudentsData()
  171. }
  172. },
  173. methods: {
  174. handleGradeAllChange(val) {
  175. this.checkedGrade = val ? this.forClassStudent(this.gradeData, 'gradeId') : []
  176. if (val) {
  177. this.handleClassAllChange(true)
  178. this.handleStudentAllChange(true)
  179. } else {
  180. this.handleClassAllChange(false)
  181. this.handleStudentAllChange(false)
  182. }
  183. },
  184. handleGradeChange(value) {
  185. let checkedCount = value.length
  186. this.gradeAll = checkedCount === this.gradeData.length
  187. this.gradeIndeterminate = checkedCount > 0 && checkedCount < this.gradeData.length
  188. },
  189. changeGrade() {
  190. this.checkedClass = ''
  191. this.studentData = []
  192. this.checkedStudent = [...this.defaultSelected]
  193. this.gradeData.forEach(item => {
  194. if (item.gradeId == this.checkedGrade) {
  195. this.classData = item.classes
  196. }
  197. })
  198. },
  199. handleClassAllChange(val) {
  200. this.checkedClass = val ? this.forClassStudent(this.classData, 'classId') : []
  201. if (val) {
  202. this.handleStudentAllChange(true)
  203. } else {
  204. this.handleStudentAllChange(false)
  205. }
  206. },
  207. handleClassChange(value) {
  208. let checkedCount = value.length
  209. this.classAll = checkedCount === this.classData.length
  210. this.classIndeterminate = checkedCount > 0 && checkedCount < this.classData.length
  211. },
  212. changeClass() {
  213. this.checkedStudent = [...this.defaultSelected]
  214. this.classData.forEach(item => {
  215. if (item.classId == this.checkedClass) {
  216. this.studentData = item.students
  217. }
  218. })
  219. },
  220. handleStudentAllChange(val) {
  221. this.checkedStudent = val ? this.forClassStudent(this.studentData, 'code') : []
  222. },
  223. handleStudentChange(value) {
  224. let checkedCount = value.length
  225. this.studentAll = checkedCount === this.studentData.length
  226. this.studentIndeterminate = checkedCount > 0 && checkedCount < this.studentData.length
  227. },
  228. forClassStudent(data, k) {
  229. return data.map(item => item[k])
  230. },
  231. getStudentsData() {
  232. getClassStudents().then(response => {
  233. this.gradeData = []
  234. // this.classData = []
  235. // this.studentData = []
  236. response.data.forEach(gitem => {
  237. this.gradeData.push(gitem)
  238. // if (gitem.classes) {
  239. // gitem.classes.forEach((citem, cindex) => {
  240. // citem.gradeId = gitem.gradeId
  241. // this.classData.push(citem)
  242. // if (citem.students) {
  243. // citem.students.forEach(sitem => {
  244. // sitem.gradeId = gitem.gradeId
  245. // sitem.classId = citem.classId
  246. // this.studentData.push(sitem)
  247. // })
  248. // }
  249. // })
  250. // }
  251. })
  252. }).catch(err => {
  253. })
  254. },
  255. handleClose(done) {
  256. this.$emit('dialogVisibleClose', false)
  257. done()
  258. },
  259. save() {
  260. this.$refs.form.validate((valid) => {
  261. if (valid) {
  262. this.$emit('handleClose', this.type, this.form.name)
  263. } else {
  264. return false
  265. }
  266. })
  267. },
  268. handleSave() {
  269. if (this.selectType) {
  270. // this.$emit('handleClose', this.type ,'')
  271. if (this.selTab == '班级') {
  272. if (this.checkedClass) {
  273. // todo 调接口只要传classId(参数:this.checkedClass,年级id不是必传参数,把数据返回到父页面调接口)
  274. let ids = []
  275. this.studentData.forEach(item => {
  276. ids.push(item.code)
  277. })
  278. let resData = {
  279. checkedGrade: this.checkedGrade,
  280. checkedClass: this.checkedClass,
  281. // checkedStudent:ids,
  282. remark: this.remark
  283. }
  284. this.$emit('handleClose', this.type, '', resData)
  285. } else {
  286. this.$message.warning('请选择年级和班级!')
  287. return
  288. }
  289. } else {
  290. if (this.checkedStudent.length == 0) {
  291. this.$message.warning('请选择年级班级与学生!')
  292. return
  293. } else {
  294. // todo 调接口保存数据(参数:this.checkedClass 和 this.checkedStudent ,年级id不是必传参数,全选传全部学生的code,把数据返回到父页面调接口)
  295. let resData = {
  296. checkedGrade: this.checkedGrade,
  297. checkedClass: this.checkedClass,
  298. checkedStudent: this.checkedStudent,
  299. remark: this.remark
  300. }
  301. this.$emit('handleClose', this.type, '', resData)
  302. }
  303. }
  304. } else {
  305. this.$emit('handleClose', this.type, '')
  306. }
  307. }
  308. }
  309. }
  310. </script>
  311. <style scoped>
  312. .upload-upload .student_container /deep/ .el-checkbox-group {
  313. max-height: 105px;
  314. overflow-y: auto;
  315. }
  316. .upload-upload /deep/ .el-dialog__header {
  317. text-align: center;
  318. background: #47C6A2;
  319. }
  320. .upload-upload /deep/ .el-dialog__body {
  321. max-height: 570px;
  322. overflow-y: auto;
  323. }
  324. .upload-upload /deep/ .el-dialog__title {
  325. color: #fff
  326. }
  327. .upload-upload /deep/ .el-icon-close {
  328. color: #fff
  329. }
  330. /deep/ .checkbox-list {
  331. border: 1px solid #999;
  332. padding: 10px;
  333. margin: 20px 0;
  334. }
  335. .el-checkbox {
  336. margin-bottom: 10px
  337. }
  338. /deep/ .el-radio.is-bordered + .el-radio.is-bordered {
  339. margin-left: 0px;
  340. margin-bottom: 3px;
  341. }
  342. </style>