Page.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <script setup lang="tsx">
  2. import { ContentWrap } from '@common/src/components/ContentWrap'
  3. import { Search } from '@common/src/components/Search'
  4. import { Table, TableColumn } from '@common/src/components/Table'
  5. import { BaseButton } from '@common/src/components/Button'
  6. import { useTable } from '@common/src/hooks/web/useTable'
  7. import { FormSchema } from '@common/src/components/Form'
  8. import { ref, unref, reactive } from 'vue'
  9. import { list, del } from '@/api/xxx'
  10. import { useRouter } from 'vue-router'
  11. const { push } = useRouter()
  12. const props = defineProps({
  13. tabName: {
  14. type: String,
  15. default: '1'
  16. }
  17. })
  18. const { tableRegister, tableState, tableMethods } = useTable({
  19. fetchDataApi: async () => {
  20. const { currentPage, pageSize } = tableState
  21. const res = await list({
  22. current: unref(currentPage),
  23. size: unref(pageSize),
  24. ...unref(searchParams)
  25. })
  26. return {
  27. list: res.data.list,
  28. total: res.data.totalCount
  29. }
  30. }
  31. })
  32. const { loading, dataList, total, currentPage, pageSize } = tableState
  33. const { getList } = tableMethods
  34. interface ISearch {
  35. caseId?: string
  36. userName?: string
  37. createTimeStart?: string
  38. createTimeEnd?: string
  39. }
  40. const searchParams = ref<ISearch>({})
  41. const setSearchParams = (params: any) => {
  42. searchParams.value = params
  43. if (params.time) {
  44. searchParams.value.createTimeStart = params.time[0]
  45. searchParams.value.createTimeEnd = params.time[1]
  46. }
  47. getList()
  48. }
  49. const searchSchema = reactive<FormSchema[]>([
  50. {
  51. field: 'caseId',
  52. label: '病例ID',
  53. component: 'Input',
  54. componentProps: {
  55. placeholder: '请输入'
  56. }
  57. },
  58. {
  59. field: 'userName',
  60. label: '对象名称',
  61. component: 'Input',
  62. componentProps: {
  63. placeholder: '请输入'
  64. }
  65. },
  66. {
  67. field: 'time',
  68. component: 'DatePicker',
  69. label: '创建时间段',
  70. componentProps: {
  71. type: 'datetimerange',
  72. ...window.dateRangeProps
  73. }
  74. }
  75. ])
  76. const tableColumns = reactive<TableColumn[]>([
  77. {
  78. field: 'index',
  79. label: '序号',
  80. type: 'index'
  81. },
  82. {
  83. field: 'caseId',
  84. label: '病例ID'
  85. },
  86. {
  87. field: 'userName',
  88. label: '对象名称'
  89. },
  90. {
  91. field: 'taskNo',
  92. label: '关联事件编号'
  93. },
  94. {
  95. field: 'createTime',
  96. label: '创建时间'
  97. },
  98. {
  99. field: 'action',
  100. width: '220px',
  101. label: '操作',
  102. slots: {
  103. default: (data: any) => {
  104. return (
  105. <>
  106. <BaseButton size="small" type="primary" onClick={() => action(data.row, 'detail')}>
  107. 查看详情
  108. </BaseButton>
  109. <BaseButton size="small" type="primary" onClick={() => action(data.row, 'edit')}>
  110. 编辑
  111. </BaseButton>
  112. <BaseButton size="small" type="danger" onClick={() => delData(data.row)}>
  113. 删除
  114. </BaseButton>
  115. </>
  116. )
  117. }
  118. }
  119. }
  120. ])
  121. const actionType = ref('')
  122. const AddAction = () => {
  123. actionType.value = 'add'
  124. push({
  125. path: '/survey-case-manage/write',
  126. query: {
  127. actionType: 'add',
  128. tabName: props.tabName
  129. }
  130. })
  131. }
  132. const delData = async (row) => {
  133. ElMessageBox.confirm('确认删除?', '提示', {
  134. confirmButtonText: '确认',
  135. cancelButtonText: '取消',
  136. type: 'warning'
  137. }).then(async () => {
  138. await del({
  139. caseId: row?.caseId
  140. })
  141. getList()
  142. })
  143. }
  144. const action = (row, type: string) => {
  145. actionType.value = type
  146. if (type === 'edit') {
  147. push({
  148. path: '/survey-case-manage/write',
  149. query: {
  150. actionType: 'edit',
  151. caseId: row?.caseId
  152. }
  153. })
  154. } else {
  155. push({
  156. path: '/survey-case-manage/detail',
  157. query: {
  158. caseId: row?.caseId
  159. }
  160. })
  161. }
  162. }
  163. </script>
  164. <template>
  165. <ContentWrap>
  166. <Search :schema="searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  167. <div class="mb-10px">
  168. <BaseButton type="primary" @click="AddAction">新增</BaseButton>
  169. </div>
  170. <Table
  171. v-model:pageSize="pageSize"
  172. v-model:currentPage="currentPage"
  173. :columns="tableColumns"
  174. :data="dataList"
  175. :loading="loading"
  176. :pagination="{
  177. total: total
  178. }"
  179. @register="tableRegister"
  180. />
  181. </ContentWrap>
  182. </template>