index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* eslint-disable no-duplicate-case */
  2. <template>
  3. <div class="school-container">
  4. <div class="topic">
  5. <el-form :inline="true" :model="formInline" class="demo-form-inline">
  6. <el-form-item label="code">
  7. <el-input v-model="formInline.code" placeholder="code" clearable />
  8. </el-form-item>
  9. <el-form-item label="状态">
  10. <el-select v-model="formInline.status" placeholder="请选择状态">
  11. <el-option label="未上架" value="NOT_ON_STOCK" />
  12. <el-option label="上架" value="HAS_ON_STOCK" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" @click="onSubmit">查询</el-button>
  17. </el-form-item>
  18. </el-form>
  19. <el-button
  20. type="primary"
  21. style="position: absolute;right: 20px; top: 15px;"
  22. @click="addTopic"
  23. >添加</el-button>
  24. <el-table
  25. :data="getTopicData.list"
  26. style="width: 100%"
  27. >
  28. <el-table-column
  29. label="id"
  30. width="180"
  31. prop="id"
  32. />
  33. <el-table-column
  34. label="code"
  35. width="180"
  36. prop="code"
  37. />
  38. <el-table-column
  39. label="背景图"
  40. width="140"
  41. >
  42. <template slot-scope="scope">
  43. <img :src="scope.row.bgImg" width="128">
  44. </template>
  45. </el-table-column>
  46. <el-table-column
  47. label="标题"
  48. width="200"
  49. prop="title"
  50. />
  51. <el-table-column
  52. label="状态"
  53. width="100"
  54. >
  55. <template slot-scope="scope">
  56. <span style="margin-left: 10px">{{ scope.row.status === 'NOT_ON_STOCK' ? '未上架' : '已上架' }}</span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column
  60. label="创建时间"
  61. width="200"
  62. >
  63. <template slot-scope="scope">
  64. <i class="el-icon-time" />
  65. <span style="margin-left: 10px">{{ scope.row.gmtCreated }}</span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column
  69. label="修改时间"
  70. width="200"
  71. >
  72. <template slot-scope="scope">
  73. <i class="el-icon-time" />
  74. <span style="margin-left: 10px">{{ scope.row.gmtModified }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="操作">
  78. <template slot-scope="scope">
  79. <el-button
  80. size="mini"
  81. @click="handleDel(scope.$index, scope.row)"
  82. >{{ scope.row.status === 'NOT_ON_STOCK' ? '上架' : '下架' }}</el-button>
  83. <el-button
  84. size="mini"
  85. @click="handleDetail(scope.$index, scope.row)"
  86. >课件</el-button>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <el-dialog title="专题" :visible.sync="dialogFormVisible">
  91. <el-form ref="ruleForm" :model="form" :rules="rules">
  92. <el-form-item label="code" :label-width="formLabelWidth" prop="code">
  93. <el-input v-model="form.code" autocomplete="off" clearable />
  94. </el-form-item>
  95. <el-form-item label="背景图" :label-width="formLabelWidth" prop="bgImg">
  96. <el-input v-model="form.bgImg" autocomplete="off" clearable />
  97. </el-form-item>
  98. <el-form-item label="标题" :label-width="formLabelWidth" prop="title">
  99. <el-input v-model="form.title" autocomplete="off" clearable />
  100. </el-form-item>
  101. <el-form-item label="状态" :label-width="formLabelWidth" prop="status">
  102. <el-select v-model="form.status" placeholder="请选择状态">
  103. <el-option label="未上架" value="NOT_ON_STOCK" />
  104. <el-option label="上架" value="HAS_ON_STOCK" />
  105. </el-select>
  106. </el-form-item>
  107. </el-form>
  108. <div slot="footer" class="dialog-footer">
  109. <el-button @click="dialogFormVisible = false">取 消</el-button>
  110. <el-button type="primary" @click="handOk('ruleForm')">确 定</el-button>
  111. </div>
  112. </el-dialog>
  113. <el-pagination
  114. background
  115. layout="prev, pager, next"
  116. :total="getTopicData.totalSize"
  117. @current-change="handleCurrentChange"
  118. />
  119. </div>
  120. </div>
  121. </template>
  122. <script>
  123. import { mapGetters } from 'vuex'
  124. export default {
  125. data() {
  126. return {
  127. dialogFormVisible: false,
  128. formInline: {
  129. code: '',
  130. status: ''
  131. },
  132. form: {
  133. code: '',
  134. title: '',
  135. bgImg: '',
  136. status: ''
  137. },
  138. formLabelWidth: '120px',
  139. rules: {
  140. code: [{ required: true, message: '请输入code', trigger: 'blur' }],
  141. title: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  142. bgImg: [{ required: true, message: '请输入背景图', trigger: 'blur' }],
  143. status: [{ required: true, message: '请选择状态', trigger: 'change' }]
  144. },
  145. page: 1
  146. }
  147. },
  148. created() {
  149. this.$store.dispatch('topicList/getTopicLists', {
  150. page: this.page
  151. })
  152. },
  153. // eslint-disable-next-line vue/order-in-components
  154. computed: {
  155. ...mapGetters([
  156. 'getTopicData'
  157. ])
  158. },
  159. methods: {
  160. onSubmit() {
  161. this.$store.dispatch('topicList/getTopicLists', this.formInline)
  162. },
  163. handleDel(index, row) {
  164. const id = row.id
  165. const status = row.status === 'NOT_ON_STOCK' ? 'HAS_ON_STOCK' : 'NOT_ON_STOCK'
  166. this.$store.dispatch('topicList/setTopicLists', {
  167. id,
  168. status
  169. }).then(() => {
  170. this.dialogFormVisible = false
  171. this.$store.dispatch('topicList/getTopicLists', {
  172. page: this.page
  173. })
  174. })
  175. },
  176. handleDetail(index, row) {
  177. console.log(index, row)
  178. this.$router.push({
  179. path: '/topicRelation/topicRelation',
  180. query: {
  181. topicId: row.id
  182. }
  183. })
  184. },
  185. handOk(formName) {
  186. this.$refs[formName].validate((valid) => {
  187. if (valid) {
  188. this.$store.dispatch('topicList/addTopicLists', this.form).then(() => {
  189. this.dialogFormVisible = false
  190. this.$store.dispatch('topicList/getTopicLists', {
  191. page: this.page
  192. })
  193. })
  194. } else {
  195. console.log('error submit!!')
  196. return false
  197. }
  198. })
  199. },
  200. addTopic() {
  201. this.dialogFormVisible = true
  202. },
  203. handleCurrentChange(val) {
  204. console.log(val)
  205. this.page = val
  206. this.$store.dispatch('topicList/getTopicLists', {
  207. page: this.page
  208. })
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .topic {
  215. margin-top: 20px;
  216. }
  217. .el-form {
  218. width: 50%;
  219. }
  220. .el-input {
  221. width: 300px;
  222. }
  223. .el-select>.el-input {
  224. width: 300px;
  225. }
  226. .el-pagination {
  227. text-align: center;
  228. margin-top: 20px;
  229. }
  230. </style>