jobTemplateSetting.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div class='m-container'>
  3. <!-- <h2>作业模板管理</h2> -->
  4. <div class="m-core">
  5. <div class='newBand' v-permission="'courseHomeworkTemplate/add'"
  6. @click="openJob('create')">添加</div>
  7. <!-- 列表 -->
  8. <div class="tableWrap">
  9. <el-table :data='tableList'
  10. :header-cell-style="{background:'#EDEEF0',color:'#444'}">
  11. <el-table-column align='center'
  12. prop="name"
  13. label="作业模板名称">
  14. </el-table-column>
  15. <el-table-column align='center'
  16. prop="classGroupTypeName"
  17. label="对应课程类型">
  18. </el-table-column>
  19. <el-table-column align='center'
  20. label="声部">
  21. <template slot-scope="scope">
  22. {{ scope.row.subjectName ? scope.row.subjectName : '无' }}
  23. </template>
  24. </el-table-column>
  25. <el-table-column align='center'
  26. prop="content"
  27. label="模板内容">
  28. </el-table-column>
  29. <el-table-column align='center'
  30. label="操作">
  31. <template slot-scope="scope">
  32. <el-button @click="openJob('update', scope.row)"
  33. v-permission="'courseHomeworkTemplate/update'"
  34. type="text">修改</el-button>
  35. <el-button @click="onJobDel(scope.row)"
  36. v-permission="'courseHomeworkTemplate/del'"
  37. type="text">删除</el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <pagination :total="pageInfo.total"
  42. :page.sync="pageInfo.page"
  43. :limit.sync="pageInfo.limit"
  44. :page-sizes="pageInfo.page_size"
  45. @pagination="getList" />
  46. </div>
  47. <el-dialog :title="formTitle[formActionTitle]"
  48. :visible.sync="jobStatus"
  49. @close="onFormClose('ruleForm')"
  50. width="500px">
  51. <el-form :model="form"
  52. :rules="rules"
  53. ref="ruleForm">
  54. <el-form-item label="作业模板名称"
  55. prop="name"
  56. :label-width="formLabelWidth">
  57. <el-input v-model.trim="form.name"
  58. autocomplete="off"></el-input>
  59. </el-form-item>
  60. <el-form-item label="对应课程类型"
  61. prop="classGroupType"
  62. :label-width="formLabelWidth">
  63. <el-radio-group :disabled="formActionTitle == 'update' ? true: false"
  64. v-model.trim="form.classGroupType">
  65. <el-radio label="NORMAL">声部课</el-radio>
  66. <el-radio label="MIX">合奏课</el-radio>
  67. </el-radio-group>
  68. </el-form-item>
  69. <el-form-item label="声部选择"
  70. v-if="form.classGroupType != 'MIX'"
  71. prop="subjectId"
  72. :label-width="formLabelWidth">
  73. <el-select v-model.trim="form.subjectId"
  74. clearable
  75. filterable>
  76. <el-option v-for="item in selects.subjects"
  77. :key="item.id"
  78. :label="item.name"
  79. :value="item.id">
  80. </el-option>
  81. </el-select>
  82. </el-form-item>
  83. <el-form-item label="作业内容"
  84. prop="content"
  85. :label-width="formLabelWidth">
  86. <el-input type="textarea"
  87. :autosize="{ minRows: 2, maxRows: 4}"
  88. placeholder="请输入内容"
  89. v-model.trim="form.content"></el-input>
  90. </el-form-item>
  91. </el-form>
  92. <span slot="footer"
  93. class="dialog-footer">
  94. <el-button @click="jobStatus = false">取 消</el-button>
  95. <el-button type="primary"
  96. @click="onJobSubmit('ruleForm')">确 定</el-button>
  97. </span>
  98. </el-dialog>
  99. </div>
  100. </div>
  101. </template>
  102. <script>
  103. import pagination from '@/components/Pagination/index'
  104. import { courseHomeworkTemplateList, homeWorkUpdate, homeWorkAdd, homeWorkDel } from '@/api/specialSetting'
  105. export default {
  106. components: { pagination },
  107. name: 'jobTemplateSetting',
  108. data () {
  109. return {
  110. tableList: [],
  111. formActionTitle: 'create',
  112. formTitle: {
  113. create: '添加作业模板',
  114. update: '修改作业模板'
  115. },
  116. jobStatus: false, // 添加教学点
  117. formLabelWidth: '120px',
  118. form: {
  119. name: null, // 作业模块名称
  120. classGroupType: null,
  121. subjectId: null,
  122. content: null
  123. },
  124. rules: {
  125. name: [{ required: true, message: '请输入作业模板名称', trigger: 'blur' }],
  126. classGroupType: [{ required: true, message: '请选择对应课程类型', trigger: 'change' }],
  127. subjectId: [{ required: true, message: '请选择声部', trigger: 'change' }],
  128. content: [{ required: true, message: '请输入作业内容', trigger: 'blur' }]
  129. },
  130. pageInfo: {
  131. // 分页规则
  132. limit: 10, // 限制显示条数
  133. page: 1, // 当前页
  134. total: 0, // 总条数
  135. page_size: [10, 20, 40, 50] // 选择限制显示条数
  136. }
  137. }
  138. },
  139. mounted () {
  140. this.getList()
  141. // 获取声部
  142. this.$store.dispatch('setSubjects')
  143. },
  144. methods: {
  145. onJobSubmit (formName) { // 添加数据
  146. this.$refs[formName].validate((valid) => {
  147. if (valid) {
  148. if (this.formActionTitle == 'create') {
  149. if (this.form.id) { // 判断有没有Id,如果有则删除
  150. delete this.form.id
  151. }
  152. homeWorkAdd(this.form).then(res => {
  153. this.messageTips('添加', res)
  154. })
  155. } else if (this.formActionTitle == 'update') {
  156. if (this.form.classGroupType == 'MIX') {
  157. this.form.subjectId = ''
  158. }
  159. homeWorkUpdate(this.form).then(res => {
  160. this.messageTips('修改', res)
  161. })
  162. }
  163. } else {
  164. return false;
  165. }
  166. })
  167. },
  168. openJob (type, row) {
  169. this.jobStatus = true
  170. this.formActionTitle = type
  171. // 修改的时候赋值
  172. if (type == 'update') {
  173. this.form = {
  174. id: row.id,
  175. name: row.name, // 作业模块名称
  176. classGroupType: row.classGroupType,
  177. subjectId: row.subjectId,
  178. content: row.content
  179. }
  180. }
  181. },
  182. onJobDel (row) {
  183. homeWorkDel(row.id).then(res => {
  184. this.messageTips('删除', res)
  185. })
  186. },
  187. messageTips (title, res) {
  188. if (res.code == 200) {
  189. this.$message.success(title + '成功')
  190. this.jobStatus = false
  191. this.getList()
  192. } else {
  193. this.$message.error(res.msg)
  194. }
  195. },
  196. getList () {
  197. courseHomeworkTemplateList({
  198. delFlag: 0,
  199. rows: this.pageInfo.limit,
  200. page: this.pageInfo.page
  201. }).then(res => {
  202. if (res.code == 200 && res.data) {
  203. this.tableList = res.data.rows
  204. this.pageInfo.total = res.data.total
  205. }
  206. })
  207. },
  208. onFormClose (formName) { // 关闭弹窗重置验证
  209. this.form = {
  210. name: null, // 作业模块名称
  211. classGroupType: null,
  212. subjectId: null,
  213. content: null
  214. }
  215. this.$refs[formName].resetFields()
  216. },
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. /deep/.el-button--primary {
  222. background: #14928a;
  223. border-color: #14928a;
  224. color: #fff;
  225. &:hover,
  226. &:active,
  227. &:focus {
  228. background: #14928a;
  229. border-color: #14928a;
  230. color: #fff;
  231. }
  232. }
  233. /deep/.el-date-editor.el-input {
  234. width: 100% !important;
  235. }
  236. /deep/.el-select {
  237. width: 98% !important;
  238. }
  239. </style>