ListView.vue 5.5 KB

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