categorize-list.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import { NButton, NDataTable, NModal, NSpace, NTag, useDialog, useMessage } from 'naive-ui'
  2. import { defineComponent, onMounted, reactive } from 'vue'
  3. import CategorizeSave from '@views/system-manage/subject-manage/subject-categorize/modal/categorize-save'
  4. import {
  5. subjectCategoryPage,
  6. subjectCategoryUpdateStatus
  7. } from '@views/system-manage/subject-manage/api'
  8. import { getTimes } from '@/utils/dateUtil'
  9. import Pagination from '@components/pagination'
  10. export default defineComponent({
  11. name: 'category-list',
  12. setup() {
  13. const dialog = useDialog()
  14. const message = useMessage()
  15. const state = reactive({
  16. loading: false,
  17. pagination: {
  18. page: 1,
  19. rows: 10,
  20. pageTotal: 0
  21. },
  22. dataList: [] as any,
  23. saveMode: 'add',
  24. showSaveDialog: false,
  25. rowData: {}
  26. })
  27. const searchForm = reactive({
  28. keyword: '',
  29. times: null as any,
  30. operatorKeyword: '' //创建人
  31. })
  32. const columns = (): any => {
  33. return [
  34. {
  35. title: '分类编号',
  36. key: 'id'
  37. },
  38. {
  39. title: '分类名称',
  40. key: 'name'
  41. },
  42. {
  43. title: '操作人',
  44. key: 'operator',
  45. render(row: any) {
  46. return (
  47. <div>
  48. <div>{row.operatorName}</div>
  49. <div>{row.updateTime}</div>
  50. </div>
  51. )
  52. }
  53. },
  54. {
  55. title: '操作',
  56. key: 'operation',
  57. fixed: 'right',
  58. width: 180,
  59. render(row: any) {
  60. return (
  61. <NSpace>
  62. <NButton
  63. type="primary"
  64. text
  65. v-auth="subjectCategory/update1750844787669336066"
  66. onClick={() => {
  67. state.saveMode = 'edit'
  68. state.showSaveDialog = true
  69. state.rowData = row
  70. }}
  71. >
  72. 修改
  73. </NButton>
  74. </NSpace>
  75. )
  76. }
  77. }
  78. ]
  79. }
  80. const getList = async () => {
  81. try {
  82. state.loading = true
  83. const { times, ...reset } = searchForm
  84. const body = {
  85. ...reset,
  86. ...getTimes(times, ['startTime', 'endTime']),
  87. page: state.pagination.page,
  88. rows: state.pagination.rows
  89. }
  90. const { data } = await subjectCategoryPage(body)
  91. state.loading = false
  92. state.pagination.pageTotal = Number(data.total)
  93. state.dataList = data.rows || []
  94. } catch {
  95. state.loading = false
  96. }
  97. }
  98. const onChangeStatus = (row: any) => {
  99. const statusStr = row.enableFlag ? '停用' : '启用'
  100. dialog.warning({
  101. title: '警告',
  102. content: `是否${statusStr}?`,
  103. positiveText: '确定',
  104. negativeText: '取消',
  105. onPositiveClick: async () => {
  106. try {
  107. await subjectCategoryUpdateStatus({
  108. id: row.id
  109. })
  110. getList()
  111. message.success(`${statusStr}成功`)
  112. } catch {}
  113. }
  114. })
  115. }
  116. onMounted(() => {
  117. getList()
  118. })
  119. return () => (
  120. <div class="system-menu-container">
  121. <div class={['section-container']}>
  122. <NSpace style={{ paddingBottom: '12px' }}>
  123. <NButton
  124. type="primary"
  125. v-auth="subjectCategory/save1750844729750192130"
  126. onClick={() => {
  127. state.saveMode = 'add'
  128. state.showSaveDialog = true
  129. }}
  130. disabled={state.loading}
  131. >
  132. 添加
  133. </NButton>
  134. </NSpace>
  135. <NDataTable
  136. scroll-x="1300"
  137. loading={state.loading}
  138. columns={columns()}
  139. data={state.dataList}
  140. children-key="subMaterialCategoryList"
  141. default-expand-all={false}
  142. row-key={(row: any) => row.id}
  143. ></NDataTable>
  144. <Pagination
  145. v-model:page={state.pagination.page}
  146. v-model:pageSize={state.pagination.rows}
  147. v-model:pageTotal={state.pagination.pageTotal}
  148. onList={getList}
  149. sync
  150. saveKey="categorize-list"
  151. ></Pagination>
  152. </div>
  153. <NModal
  154. v-model:show={state.showSaveDialog}
  155. preset="dialog"
  156. showIcon={false}
  157. title={state.saveMode === 'add' ? '新增分类' : '修改分类'}
  158. style={{ width: '400px' }}
  159. >
  160. <CategorizeSave
  161. type={state.saveMode}
  162. data={state.rowData}
  163. onClose={() => (state.showSaveDialog = false)}
  164. onGetList={getList}
  165. />
  166. </NModal>
  167. </div>
  168. )
  169. }
  170. })