index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="courseManage app-container">
  3. <div class="search">
  4. <div>
  5. <el-date-picker
  6. v-model="date"
  7. size="small"
  8. class="item-width-350"
  9. value-format="yyyy-MM-dd hh:mm:ss"
  10. type="datetimerange"
  11. range-separator="至"
  12. start-placeholder="开始日期"
  13. end-placeholder="结束日期">
  14. </el-date-picker>
  15. <el-button
  16. class="ml10"
  17. type="primary"
  18. size="small"
  19. icon="el-icon-search"
  20. @click="handleSearch"
  21. >
  22. 搜索
  23. </el-button>
  24. </div>
  25. <el-button class="add-btn" type="primary" size="small" @click="handleAdd">添加</el-button>
  26. </div>
  27. <el-table
  28. :data="tableData"
  29. tooltip-effect="dark"
  30. border
  31. v-loading="loading"
  32. style="width: 100%"
  33. >
  34. <el-table-column
  35. align="center"
  36. label="课程封面"
  37. prop="publishUserId"
  38. show-overflow-tooltip
  39. >
  40. <template slot-scope="scope">
  41. <img style="width:80px;height:80px" :src="scope.row.courseImg" alt="" class="icon">
  42. </template>
  43. </el-table-column>
  44. <el-table-column
  45. prop="courseName"
  46. align="center"
  47. label="章节名称"
  48. show-overflow-tooltip
  49. >
  50. </el-table-column>
  51. <el-table-column
  52. prop="courseMsg"
  53. align="center"
  54. label="课程简介"
  55. show-overflow-tooltip
  56. >
  57. </el-table-column>
  58. <el-table-column
  59. prop="columnId"
  60. align="center"
  61. label="栏目名称"
  62. show-overflow-tooltip
  63. >
  64. <template slot-scope="scope">
  65. {{scope.row.columnId | filterColumn(that)}}
  66. </template>
  67. </el-table-column>
  68. <el-table-column
  69. prop="createTime"
  70. align="center"
  71. label="状态"
  72. show-overflow-tooltip
  73. >
  74. <template slot-scope="scope">
  75. <span :class="[scope.row.state == 1?'red':'green']">{{scope.row.state == 1?'隐藏':'显示' }}</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column
  79. prop="createTime"
  80. align="center"
  81. label="发布状态"
  82. show-overflow-tooltip
  83. >
  84. <template slot-scope="scope">
  85. <span :class="[scope.row.status == 1?'red':'green']">{{scope.row.status == 1?'未发布':'已发布' }}</span>
  86. </template>
  87. </el-table-column>
  88. <el-table-column prop="address" align="center" label="操作">
  89. <template slot-scope="scope">
  90. <el-button type="text" size="small" @click="handleDetail(scope.row.id)">查看</el-button>
  91. <el-button type="text" size="small" @click="handleEdit(scope.row.id)">编辑</el-button>
  92. <el-button type="text" size="small" @click="handleStatus(scope.row.id,scope.row.status == 1?2:1)">{{scope.row.status == 1?'立即发布':'取消发布' }}</el-button>
  93. <el-button type="text" size="small" @click="handleState(scope.row.id,scope.row.state == 1?2:1)">{{scope.row.state == 1?'显示':'隐藏' }}</el-button>
  94. <el-button type="text" class="red" size="small" @click="handleDel(scope.row.id)">删除</el-button>
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. <div class="page-box">
  99. <el-pagination
  100. @size-change="handleSizeChange"
  101. @current-change="handleCurrentChange"
  102. background
  103. :current-page="query.currentPage"
  104. :page-sizes="[10, 20, 30, 40]"
  105. :page-size="query.pageSize"
  106. layout="total, sizes, prev, pager, next, jumper"
  107. :total="total"
  108. >
  109. </el-pagination>
  110. </div>
  111. </div>
  112. </template>
  113. <script>
  114. import {debounce} from '@/utils/index'
  115. import {courseList,operateByState,operateByStatus,delCourse,getAllColumn} from '@/api/study'
  116. export default {
  117. name: "courseManage",
  118. data() {
  119. return {
  120. that:this,
  121. date:'',//时间
  122. tableData: [],
  123. options:[],
  124. loading: false,
  125. query: {
  126. "currentPage": 1,
  127. "pageSize": 10,
  128. "startDateTime":'',
  129. "endDateTime":'',
  130. },
  131. title: "",
  132. total: 0,
  133. };
  134. },
  135. watch: {
  136. // query: {
  137. // handler: debounce(function(val) {
  138. // this.courseList()
  139. // }),
  140. // deep:true
  141. // },
  142. date(val){
  143. if(val){
  144. this.query.startDateTime = val[0]
  145. this.query.endDateTime = val[1]
  146. }else{
  147. this.query.startDateTime = ''
  148. this.query.endDateTime = ''
  149. }
  150. }
  151. },
  152. filters: {
  153. filterColumn: function(val,that) {
  154. let res
  155. that.options.map(item=>{
  156. if(val == item.value){
  157. res = item.label
  158. }
  159. })
  160. return res
  161. }
  162. },
  163. methods: {
  164. handleSearch(){
  165. this.query.currentPage = 1
  166. this.courseList();
  167. },
  168. handleAdd(){
  169. this.$router.push({
  170. path:'/studyManage/courseManage/addCourse',
  171. })
  172. },
  173. handleStatus(id,status){
  174. let msg
  175. if(status == 2){
  176. msg = '发布'
  177. }else{
  178. msg = '取消发布'
  179. }
  180. this.$confirm(`此操作将${msg}该数据, 是否继续?`, '提示', {
  181. confirmButtonText: '确定',
  182. cancelButtonText: '取消',
  183. type: 'warning'
  184. }).then(() => {
  185. operateByStatus({id,status}).then(res=>{
  186. if(res.state == 'Success'){
  187. this.$notify({
  188. title: '成功',
  189. message: '操作成功',
  190. type: 'success'
  191. });
  192. this.courseList()
  193. }
  194. })
  195. })
  196. },
  197. handleState(id,state){
  198. let msg
  199. if(state == 2){
  200. msg = '显示'
  201. }else{
  202. msg = '隐藏'
  203. }
  204. this.$confirm(`此操作将${msg}该数据, 是否继续?`, '提示', {
  205. confirmButtonText: '确定',
  206. cancelButtonText: '取消',
  207. type: 'warning'
  208. }).then(() => {
  209. operateByState({id,state}).then(res=>{
  210. if(res.state == 'Success'){
  211. this.$notify({
  212. title: '成功',
  213. message: '操作成功',
  214. type: 'success'
  215. });
  216. this.courseList()
  217. }
  218. })
  219. })
  220. },
  221. // 点击删除
  222. handleDel(id) {
  223. this.$confirm(`此操作将删除该数据, 是否继续?`, '提示', {
  224. confirmButtonText: '确定',
  225. cancelButtonText: '取消',
  226. type: 'warning'
  227. }).then(() => {
  228. delCourse({id}).then(res=>{
  229. if(res.state == 'Success'){
  230. this.$notify({
  231. title: '成功',
  232. message: '操作成功',
  233. type: 'success'
  234. });
  235. this.search()
  236. }
  237. })
  238. })
  239. },
  240. handleDetail(id){
  241. this.$router.push({
  242. path:'/studyManage/courseManage/addCourse',
  243. query:{
  244. id,
  245. mode:'detail'
  246. }
  247. })
  248. },
  249. handleEdit(id){
  250. this.$router.push({
  251. path:'/studyManage/courseManage/addCourse',
  252. query:{
  253. id,
  254. mode:'edit'
  255. }
  256. })
  257. },
  258. handleSizeChange(val) {
  259. this.query.currentPage = 1;
  260. this.query.pageSize = val;
  261. this.courseList()
  262. },
  263. handleCurrentChange(val) {
  264. this.query.currentPage = val;
  265. this.courseList()
  266. },
  267. search() {
  268. this.query.currentPage = 1;
  269. this.courseList()
  270. },
  271. courseList(){
  272. this.loading = true
  273. courseList(this.query).then(res=>{
  274. this.loading = false
  275. if(res.state == 'Success'){
  276. this.tableData = res.content.records
  277. this.total = res.content.total
  278. }
  279. })
  280. },
  281. // 获取栏目
  282. getAllColumn() {
  283. getAllColumn().then((res) => {
  284. if (res.state == "Success") {
  285. res.content.map((item) => {
  286. this.options.push({
  287. value: item.id,
  288. label: item.columnName,
  289. });
  290. });
  291. }
  292. });
  293. },
  294. },
  295. created() {
  296. this.courseList()
  297. this.getAllColumn()
  298. },
  299. };
  300. </script>
  301. <style lang="scss" scoped>
  302. .courseManage {
  303. .search{
  304. display: flex;
  305. justify-content: space-between;
  306. align-items: center;
  307. }
  308. }
  309. </style>