ListView.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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: 'gradesIdName',
  65. width: '12%'
  66. },
  67. {
  68. title: '学期',
  69. dataIndex: 'semesterIdName',
  70. width: '10%'
  71. },
  72. {
  73. title: '开始节次',
  74. dataIndex: 'startPeriod',
  75. width: '10%'
  76. },
  77. {
  78. title: '结束节次',
  79. dataIndex: 'endPeriod',
  80. width: '10%'
  81. },
  82. {
  83. title: '上课周期',
  84. dataIndex: 'scheduleTimeName',
  85. width: '10%'
  86. },
  87. {
  88. title: '单双周',
  89. dataIndex: 'weekTypeName',
  90. width: '10%'
  91. },
  92. {
  93. title: '老师',
  94. dataIndex: 'teacherIdName',
  95. width: '8%'
  96. },
  97. {
  98. title: '状态',
  99. dataIndex: 'statusName',
  100. width: '8%'
  101. },
  102. // {
  103. // title: '发布时间',
  104. // dataIndex: 'createTime',
  105. // sorter: true,
  106. // width: '10%'
  107. // },
  108. {
  109. title: '操作',
  110. dataIndex: 'action',
  111. width: '12%'
  112. }
  113. ]
  114. // tool.formatTimestamp()
  115. const formatTimestamp = (time) => {
  116. return tool.formatTimestamp(time)
  117. }
  118. const total = ref(0)
  119. const pagination = ref({
  120. size: 10,
  121. current: 1,
  122. })
  123. const onChangeCurrent = (current) => {
  124. router.push({
  125. path: '/' + current
  126. })
  127. }
  128. const handlerChange = (page, pageSize) => {
  129. console.log('分页参数', page, pageSize)
  130. // pagination.value.size = pageSize
  131. // pagination.value.current = page
  132. getList()
  133. }
  134. const handleDetail = (record) => {
  135. console.log('查看详情', record)
  136. router.push({
  137. path: '/portal/courseDetails',
  138. query: {
  139. id: record.courseId
  140. }
  141. })
  142. // 在这里添加查看详情的逻辑
  143. }
  144. // 编辑按钮点击事件
  145. const handleEdit = (record) => {
  146. console.log('编辑记录', record)
  147. // 在这里添加编辑记录的逻辑
  148. emit('handleEdit', record)
  149. }
  150. // 上架按钮点击事件
  151. const handleShelf = (record,num) => {
  152. console.log('上架记录', record)
  153. popoverVisible.value[record.collegeId] = false
  154. // 在这里添加上架记录的逻辑
  155. // {
  156. // "courseId": "1948183431150227458",
  157. // "putawayStatus": 1
  158. // }
  159. // updateCourseStatus({courseId : record.courseId,putawayStatus : num}).then((res)=>{
  160. // getList()
  161. // })
  162. }
  163. // 删除按钮点击事件
  164. const handleDelete = (record) => {
  165. console.log('删除记录', record)
  166. popoverVisibles[record.id] = false
  167. deletess([{id : record.id}]).then((res)=>{
  168. getList()
  169. })
  170. // 在这里添加删除记录的逻辑
  171. }
  172. const getList = () => {
  173. console.log('获取列表 getList')
  174. list({...pagination.value}).then((data) => {
  175. if (data.code == 200) {
  176. console.log('获取列表 新数组', data.data.records)
  177. dataSources.value = []
  178. dataSources.value = data.data.records
  179. console.log('获取列表 最新数组', dataSources.value)
  180. pagination.value.current = data.data.current
  181. pagination.value.size = data.data.size
  182. total.value = data.data.total
  183. }
  184. // data.records
  185. })
  186. }
  187. const setList = (search) => {
  188. console.log('获取列表 setList',search)
  189. // courseName: '',
  190. // collegeId: '',
  191. // majorId: '',
  192. // courseType: '',
  193. // loacl: []
  194. formState.value = search
  195. pagination.value.current = 1
  196. list({...pagination.value, ...formState.value}).then((data) => {
  197. if (data.code == 200) {
  198. dataSources.value = data.data.records
  199. pagination.value.current = data.data.current
  200. pagination.value.size = data.data.size
  201. total.value = data.data.total
  202. }
  203. // data.records
  204. })
  205. }
  206. // 重置按钮点击事件
  207. onMounted(() => {
  208. // getListData()
  209. getList()
  210. })
  211. // watch(
  212. // () => dataSources.value,
  213. // (newVal, oldVal) => {
  214. // console.log('数据源变化了 ', ' 新的 ',newVal, ' 旧的 ',oldVal)
  215. // },
  216. // { deep: true, immediate: true }
  217. // )
  218. defineExpose({
  219. setList,getList
  220. })
  221. </script>
  222. <style scoped>
  223. .desc p {
  224. margin-bottom: 1em;
  225. }
  226. </style>