ListView.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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.collegeId]" title="确定删除?" trigger="click">
  18. <template #content>
  19. <a-button style="margin-right: 10px" type="primary" @click="handleShelf(record,1)">确定
  20. </a-button>
  21. <a-button @click="()=>{ popoverVisibles[record.collegeId] = false}">取消</a-button>
  22. </template>
  23. <!-- <a-button size="small" style="margin-right: 5px">选择</a-button>-->
  24. <a-button size="small" @click="handleDelete(record)" 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 {EyeOutlined, EditOutlined, SnippetsOutlined, DeleteOutlined} from '@ant-design/icons-vue'
  43. import {list} from '@/api/grades'
  44. import {useRouter} from 'vue-router'
  45. import collegeApi from '@/api/college'
  46. import {updateCourseStatus} from '@/api/course/courseDetail'
  47. const router = useRouter()
  48. const emit = defineEmits(['handleEdit'])
  49. //发布按钮状态
  50. const releaseVisible = ref(false)
  51. const loading = ref(false) // 列表loading
  52. const dataSources = ref([])
  53. const popoverVisible = ref({})
  54. const popoverVisibles = ref({})
  55. const formState = ref({
  56. name: '',
  57. loacl: ''
  58. }) // 列表loading
  59. const columns = [
  60. {
  61. title: '班级名称',
  62. dataIndex: 'gradesName',
  63. // sorter: true,
  64. width: '12%'
  65. },
  66. {
  67. title: '学院',
  68. dataIndex: 'collegeName',
  69. // sorter: true,
  70. width: '10%'
  71. },
  72. {
  73. title: '专业',
  74. dataIndex: 'majoreName',
  75. // sorter: true,
  76. width: '8%'
  77. },
  78. {
  79. title: '发布时间',
  80. dataIndex: 'createTime',
  81. // sorter: true,
  82. width: '10%'
  83. },
  84. {
  85. title: '操作',
  86. dataIndex: 'action',
  87. // sorter: true,
  88. width: '7%'
  89. }
  90. ]
  91. // tool.formatTimestamp()
  92. const formatTimestamp = (time) => {
  93. return tool.formatTimestamp(time)
  94. }
  95. const total = ref(0)
  96. const pagination = ref({
  97. size: 10,
  98. current: 1,
  99. })
  100. const onChangeCurrent = (current) => {
  101. router.push({
  102. path: '/' + current
  103. })
  104. }
  105. const handlerChange = (page, pageSize) => {
  106. console.log('分页参数', page, pageSize)
  107. // pagination.value.size = pageSize
  108. // pagination.value.current = page
  109. getList()
  110. }
  111. const handleDetail = (record) => {
  112. console.log('查看详情', record)
  113. router.push({
  114. path: '/portal/courseDetails',
  115. query: {
  116. id: record.courseId
  117. }
  118. })
  119. // 在这里添加查看详情的逻辑
  120. }
  121. // 编辑按钮点击事件
  122. const handleEdit = (record) => {
  123. console.log('编辑记录', record)
  124. // 在这里添加编辑记录的逻辑
  125. emit('handleEdit', record)
  126. }
  127. // 上架按钮点击事件
  128. const handleShelf = (record,num) => {
  129. console.log('上架记录', record)
  130. popoverVisible.value[record.collegeId] = false
  131. // 在这里添加上架记录的逻辑
  132. // {
  133. // "courseId": "1948183431150227458",
  134. // "putawayStatus": 1
  135. // }
  136. // updateCourseStatus({courseId : record.courseId,putawayStatus : num}).then((res)=>{
  137. // getList()
  138. // })
  139. }
  140. // 删除按钮点击事件
  141. const handleDelete = (record) => {
  142. console.log('删除记录', record)
  143. // 在这里添加删除记录的逻辑
  144. }
  145. const getList = () => {
  146. console.log('获取列表 getList')
  147. list({...pagination.value}).then((data) => {
  148. if (data.code == 200) {
  149. console.log('获取列表 新数组', data.data.records)
  150. dataSources.value = []
  151. dataSources.value = data.data.records
  152. console.log('获取列表 最新数组', dataSources.value)
  153. pagination.value.current = data.data.current
  154. pagination.value.size = data.data.size
  155. total.value = data.data.total
  156. }
  157. // data.records
  158. })
  159. }
  160. const setList = (search) => {
  161. console.log('获取列表 setList',search)
  162. // courseName: '',
  163. // collegeId: '',
  164. // majorId: '',
  165. // courseType: '',
  166. // loacl: []
  167. formState.value = search
  168. pagination.value.current = 1
  169. list({...pagination.value, ...formState.value}).then((data) => {
  170. if (data.code == 200) {
  171. dataSources.value = data.data.records
  172. pagination.value.current = data.data.current
  173. pagination.value.size = data.data.size
  174. total.value = data.data.total
  175. }
  176. // data.records
  177. })
  178. }
  179. // 重置按钮点击事件
  180. onMounted(() => {
  181. // getListData()
  182. getList()
  183. })
  184. // watch(
  185. // () => dataSources.value,
  186. // (newVal, oldVal) => {
  187. // console.log('数据源变化了 ', ' 新的 ',newVal, ' 旧的 ',oldVal)
  188. // },
  189. // { deep: true, immediate: true }
  190. // )
  191. defineExpose({
  192. setList,getList
  193. })
  194. </script>
  195. <style scoped>
  196. .desc p {
  197. margin-bottom: 1em;
  198. }
  199. </style>