ListView.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <a-table
  3. ref="table"
  4. :columns="columns"
  5. :data-source="dataSources"
  6. :row-key="(record) => record.courseId"
  7. bordered
  8. :expand-row-by-click="true"
  9. :pagination="false"
  10. size="small"
  11. >
  12. <template #bodyCell="{ column, text, record }">
  13. <template v-if="column.dataIndex === 'publishTime'">{{ formatTimestamp(text) }}</template>
  14. <template v-if="column.dataIndex === 'action'">
  15. <a-button size="small" @click="handleDetail(record)" style="margin-right: 5px">详情</a-button>
  16. <a-button size="small" @click="handleEdit(record)" style="margin-right: 5px">编辑</a-button>
  17. <a-button size="small" @click="handleCopy(record)" style="margin-right: 5px">复制</a-button>
  18. <a-popover v-model:visible="popoverVisible[record.courseId]" title="确定下架?" trigger="click">
  19. <template #content>
  20. <a-button style="margin-right: 10px" type="primary" @click="handleShelf(record, 0)">确定 </a-button>
  21. <a-button
  22. @click="
  23. () => {
  24. popoverVisible[record.courseId] = false
  25. }
  26. "
  27. >取消</a-button
  28. >
  29. </template>
  30. <!-- <a-button size="small" style="margin-right: 5px">选择</a-button>-->
  31. <a-button v-if="record.putawayStatus == 1" size="small" style="margin-right: 5px">下架</a-button>
  32. </a-popover>
  33. <a-popover v-model:visible="popoverVisibles[record.courseId]" title="确定上架?" trigger="click">
  34. <template #content>
  35. <a-button style="margin-right: 10px" type="primary" @click="handleShelf(record, 1)">确定 </a-button>
  36. <a-button
  37. @click="
  38. () => {
  39. popoverVisibles[record.courseId] = false
  40. }
  41. "
  42. >取消</a-button
  43. >
  44. </template>
  45. <!-- <a-button size="small" style="margin-right: 5px">选择</a-button>-->
  46. <a-button v-if="record.putawayStatus == 0" size="small" style="margin-right: 5px">上架</a-button>
  47. </a-popover>
  48. <a-button size="small" @click="handleDelete(record)" style="margin-right: 5px">删除</a-button>
  49. </template>
  50. </template>
  51. </a-table>
  52. <div style="display: flex; width: 100%; justify-content: flex-end; margin-top: 10px">
  53. <a-pagination
  54. v-model:current="pagination.current"
  55. v-model:pageSize="pagination.size"
  56. :total="total"
  57. show-less-items
  58. @change="handlerChange"
  59. />
  60. </div>
  61. </template>
  62. <script setup>
  63. import tool from '@/utils/tool'
  64. import { ref, onMounted } from 'vue'
  65. import { EyeOutlined, EditOutlined, SnippetsOutlined, DeleteOutlined } from '@ant-design/icons-vue'
  66. import { list, copy } from '@/api/courseinfo'
  67. import { useRouter } from 'vue-router'
  68. import collegeApi from '@/api/college'
  69. import { updateCourseStatus } from '@/api/course/courseDetail'
  70. const router = useRouter()
  71. const emit = defineEmits(['handleEdit', 'handleDetail'])
  72. //发布按钮状态
  73. const releaseVisible = ref(false)
  74. const loading = ref(false) // 列表loading
  75. const dataSources = ref([])
  76. const popoverVisible = ref({})
  77. const popoverVisibles = ref({})
  78. const formState = ref({
  79. name: '',
  80. loacl: ''
  81. }) // 列表loading
  82. const columns = [
  83. {
  84. title: '课程名称',
  85. dataIndex: 'courseName',
  86. sorter: true,
  87. width: '15%'
  88. },
  89. {
  90. title: '状态',
  91. dataIndex: 'putawayStatusName',
  92. sorter: true,
  93. width: '10%'
  94. },
  95. {
  96. title: '院系',
  97. dataIndex: 'collegeTwoIdName',
  98. sorter: true,
  99. width: '15%'
  100. },
  101. {
  102. title: '课程类型',
  103. dataIndex: 'courseTypeName',
  104. sorter: true,
  105. width: '8%'
  106. },
  107. {
  108. title: '课时数量',
  109. dataIndex: 'hourCount',
  110. sorter: true,
  111. width: '7%'
  112. },
  113. {
  114. title: '发布时间',
  115. dataIndex: 'publishTime',
  116. sorter: true,
  117. width: '12%'
  118. },
  119. {
  120. title: '操作',
  121. dataIndex: 'action',
  122. sorter: true,
  123. width: '20%'
  124. }
  125. ]
  126. // tool.formatTimestamp()
  127. const formatTimestamp = (time) => {
  128. return tool.formatTimestamp(time)
  129. }
  130. const total = ref(0)
  131. const pagination = ref({
  132. size: 10,
  133. current: 1
  134. })
  135. const onChangeCurrent = (current) => {
  136. router.push({
  137. path: '/' + current
  138. })
  139. }
  140. const handlerChange = (page, pageSize) => {
  141. console.log('分页参数', page, pageSize)
  142. // pagination.value.size = pageSize
  143. // pagination.value.current = page
  144. getList()
  145. }
  146. const handleDetail = (record) => {
  147. console.log('查看详情', record)
  148. // router.push({
  149. // path: '/portal/courseDetails',
  150. // query: {
  151. // id: record.courseId
  152. // }
  153. // })
  154. emit('handleDetail', record)
  155. }
  156. // 编辑按钮点击事件
  157. const handleEdit = (record) => {
  158. console.log('编辑记录', record)
  159. // 在这里添加编辑记录的逻辑
  160. emit('handleEdit', record)
  161. }
  162. const handleCopy = (record) => {
  163. console.log('拷贝记录', record)
  164. // 在这里添加编辑记录的逻辑
  165. copy({ courseId: record.courseId }).then((res) => {
  166. if (res.code == 200) {
  167. getList()
  168. }
  169. })
  170. // getList()
  171. }
  172. // 上架按钮点击事件
  173. const handleShelf = (record, num) => {
  174. console.log('上架记录', record)
  175. popoverVisible.value[record.courseId] = false
  176. popoverVisibles.value[record.courseId] = false
  177. // 在这里添加上架记录的逻辑
  178. // {
  179. // "courseId": "1948183431150227458",
  180. // "putawayStatus": 1
  181. // }
  182. updateCourseStatus({ courseId: record.courseId, putawayStatus: num }).then((res) => {
  183. getList()
  184. })
  185. }
  186. // 删除按钮点击事件
  187. const handleDelete = (record) => {
  188. console.log('删除记录', record)
  189. // 在这里添加删除记录的逻辑
  190. }
  191. const getList = () => {
  192. list({ ...pagination.value }).then((data) => {
  193. if (data.code == 200) {
  194. dataSources.value = []
  195. dataSources.value = data.data.records
  196. pagination.value.current = data.data.current
  197. pagination.value.size = data.data.size
  198. total.value = data.data.total
  199. }
  200. // data.records
  201. })
  202. }
  203. const setList = (search) => {
  204. console.log('获取列表 setList', search)
  205. // courseName: '',
  206. // collegeId: '',
  207. // majorId: '',
  208. // courseType: '',
  209. // loacl: []
  210. formState.value = search
  211. pagination.value.current = 1
  212. list({ ...pagination.value, ...formState.value }).then((data) => {
  213. if (data.code == 200) {
  214. dataSources.value = data.data.records
  215. pagination.value.current = data.data.current
  216. pagination.value.size = data.data.size
  217. total.value = data.data.total
  218. }
  219. // data.records
  220. })
  221. }
  222. // 重置按钮点击事件
  223. onMounted(() => {
  224. // getListData()
  225. getList()
  226. })
  227. // watch(
  228. // () => dataSources.value,
  229. // (newVal, oldVal) => {
  230. // console.log('数据源变化了 ', ' 新的 ',newVal, ' 旧的 ',oldVal)
  231. // },
  232. // { deep: true, immediate: true }
  233. // )
  234. defineExpose({
  235. setList
  236. })
  237. </script>
  238. <style scoped>
  239. .desc p {
  240. margin-bottom: 1em;
  241. }
  242. </style>