8
0

list.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <hc-card id-ref="hc-certificate-list" div-p="12px">
  3. <template #header>
  4. <div class="w-100">
  5. <el-select v-model="searchForm.projectId" filterable block placeholder="选择项目" @change="searchClick">
  6. <el-option v-for="item in projectData" :key="item.id" :label="item.projectName" :value="item.id" />
  7. </el-select>
  8. </div>
  9. <div class="ml-3 w-[300px]">
  10. <hc-search-input v-model="searchForm.certificateUserName" placeholder="请输入关键词" @search="searchClick" />
  11. </div>
  12. </template>
  13. <template #extra>
  14. <el-button hc-btn type="primary" @click="addClick">新增</el-button>
  15. </template>
  16. <hc-table :loading="tableLoading" :column="tableColumn" :datas="tableData" :index-style="{ width: 60 }">
  17. <template #certificateType="{ row }">{{ row.certificateType === 1 ? '个人证书' : '企业证书' }}</template>
  18. <template #isRegister="{ row }">
  19. <el-link v-if="row.isRegister === 0" type="primary" @click="registerRowClick(row)">注册</el-link>
  20. <span v-else>已注册</span>
  21. </template>
  22. <template #action="{ row }">
  23. <el-link type="warning" @click="editRowClick(row)">修改</el-link>
  24. <el-link v-del-com:[delRowClick]="row" type="danger">删除</el-link>
  25. </template>
  26. </hc-table>
  27. <template #action>
  28. <hc-pages :pages="searchForm" @change="pageChange" />
  29. </template>
  30. <!-- 查看 -->
  31. <hc-drawer v-model="isRowDrawer" to-id="hc-certificate-list">
  32. <HcListForm v-if="isRowDrawer" :info="tableRowItem" @close="isRowDrawer = false" />
  33. </hc-drawer>
  34. </hc-card>
  35. </template>
  36. <script setup>
  37. import { nextTick, onActivated, ref } from 'vue'
  38. import { getArrValue } from 'js-fast-way'
  39. import HcListForm from './modules/list/form.vue'
  40. import adminApi from '~api/certificate/admin'
  41. import mainApi from '~api/certificate/list'
  42. //激活
  43. onActivated(() => {
  44. getProjectData()
  45. })
  46. //项目列表
  47. const projectData = ref([])
  48. const getProjectData = async () => {
  49. const { data } = await adminApi.queryProjectList()
  50. const res = getArrValue(data)
  51. if (res.length > 0) {
  52. searchForm.value.projectId = res[0].id
  53. } else {
  54. searchForm.value.projectId = ''
  55. }
  56. projectData.value = res
  57. searchClick()
  58. }
  59. //搜索条件
  60. const searchForm = ref({ projectId: '', current: 1, size: 20, total: 0 })
  61. //搜索
  62. const searchClick = () => {
  63. searchForm.value.current = 1
  64. getTableData()
  65. }
  66. //分页
  67. const pageChange = ({ current, size }) => {
  68. searchForm.value.current = current
  69. searchForm.value.size = size
  70. getTableData()
  71. }
  72. //表格数据
  73. const tableColumn = ref([
  74. { key: 'certificateUserName', name: '证书所有者' },
  75. { key: 'certificateId', name: '证书ID/企业统一社会信用代码' },
  76. { key: 'certificateType', name: '证书类型' },
  77. { key: 'isRegister', name: '注册' },
  78. { key: 'action', name: '操作', width: 100, align: 'center' },
  79. ])
  80. const tableData = ref([])
  81. //获取表格数据
  82. const tableLoading = ref(true)
  83. const getTableData = async () => {
  84. tableData.value = []
  85. tableLoading.value = true
  86. const { data } = await mainApi.page({
  87. ...searchForm.value,
  88. total: null,
  89. })
  90. tableLoading.value = false
  91. tableData.value = getArrValue(data?.records)
  92. searchForm.value.total = data?.total ?? 0
  93. }
  94. const isRowDrawer = ref(false)
  95. const tableRowItem = ref({})
  96. //新增
  97. const addClick = () => {
  98. tableRowItem.value = {}
  99. nextTick(() => {
  100. isRowDrawer.value = true
  101. })
  102. }
  103. //修改
  104. const editRowClick = (row) => {
  105. tableRowItem.value = row
  106. nextTick(() => {
  107. isRowDrawer.value = true
  108. })
  109. }
  110. //注册
  111. const registerRowClick = async (row) => {
  112. const { isRes } = await mainApi.goRegister({
  113. key: row.id,
  114. })
  115. if (!isRes) return
  116. window.$message.success('操作成功')
  117. getTableData().then()
  118. }
  119. //删除
  120. const delRowClick = async ({ item }, resolve) => {
  121. const { isRes } = await mainApi.del(item.id)
  122. resolve() //关闭弹窗
  123. if (!isRes) return
  124. window.$message.success('删除成功')
  125. getTableData().then()
  126. }
  127. </script>