index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div v-loading="tableLoading" class="hc-layout-box anonaly-page">
  3. <hc-card :scrollbar="false" action-size="lg">
  4. <template #header>
  5. <el-select v-model="searchForm.type" class="w-[148px]" placeholder="异常类型" clearable>
  6. <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
  7. </el-select>
  8. <el-select v-model="searchForm.grade" class="ml-2 w-[100px]" placeholder="异常等级" clearable>
  9. <el-option v-for="item in levelOptions" :key="item.value" :label="item.label" :value="item.value" />
  10. </el-select>
  11. <el-select v-model="searchForm.isAnnul" class="ml-2 w-[100px]" placeholder="是否撤销" clearable>
  12. <el-option :value="1" label="是" />
  13. <el-option :value="0" label="否" />
  14. </el-select>
  15. <div class="relative ml-3 w-[300px]">
  16. <hc-search-input v-model="searchForm.searchValue" color="#151921" text="搜索" @search="searchClick" />
  17. </div>
  18. </template>
  19. <template #extra>
  20. <el-button v-yes-com:[batchExportClick] :disabled="tableCheckedKeys.length === 0" class="ml-2" color=" #6DC2FF" type="info">
  21. <hc-icon class="text-white" name="download" />
  22. <span class="text-white">批量导出</span>
  23. </el-button>
  24. </template>
  25. <hc-table
  26. :cell-style="tableCellStyle" :check-style="{ fixed: true, width: 29 }"
  27. :column="tableColumn" :datas="tableData" :index-style="{ fixed: true, width: 60 }"
  28. class="anonaly-page-table" is-check @selection-change="tableSelectionChange"
  29. >
  30. <template #action="{ row }">
  31. <el-link type="success" @click="cancleClick(row)">
  32. <hc-icon name="arrow-go-back" />撤销
  33. </el-link>
  34. <el-link v-yes-com:[exportClick] type="success" yes-com-text="确定导出项目预警数据?">
  35. <hc-icon name="download" />
  36. <span>导出</span>
  37. </el-link>
  38. </template>
  39. </hc-table>
  40. <template #action>
  41. <hc-pages :pages="searchForm" @change="pageChange" />
  42. </template>
  43. </hc-card>
  44. <!-- 撤销弹窗 -->
  45. <hc-dialog v-model="cancelModal" title="请选择撤销结束时间" widths="400px" @close="cancelModalClose">
  46. <div class="relative pb-[8px] pt-[8px]">
  47. <el-date-picker v-model="cancelForm.repealEndDate" class="block" value-format="YYYY-MM-DD" placeholder="撤销结束时间" type="date" />
  48. </div>
  49. <template #footer>
  50. <div class="dialog-footer">
  51. <el-button size="large" @click="cancelModalClose">取消</el-button>
  52. <el-button :loading="cancelLoding" type="primary" @click="saveCancelClick">确定</el-button>
  53. </div>
  54. </template>
  55. </hc-dialog>
  56. <!-- 导出弹窗 -->
  57. <hc-dialog v-model="exportModal" title="导出">
  58. <el-alert :closable="false" class="export mb-4" show-icon title="确定导出项目预警数据?" type="warning" />
  59. </hc-dialog>
  60. </div>
  61. </template>
  62. <script setup>
  63. import { onMounted, ref } from 'vue'
  64. import mainApi from '~api/anomaly/api'
  65. import { getArrValue, isNullES } from 'js-fast-way'
  66. //渲染完成
  67. onMounted(() => {
  68. searchClick()
  69. })
  70. //搜索表单
  71. const searchForm = ref({ searchValue: null, current: 1, size: 20, total: 0 })
  72. const typeOptions = ref([{ value: '2', label: '项目进度异常' }, { value: '1', label: '项目投资异常' }])
  73. const levelOptions = ref([{ value: '1', label: '一级' }, { value: '2', label: '二级' }, { value: '2', label: '三级' }])
  74. const searchClick = () => {
  75. searchForm.value.current = 1
  76. getTableData()
  77. }
  78. //分页被点击
  79. const pageChange = ({ current, size }) => {
  80. searchForm.value.current = current
  81. searchForm.value.size = size
  82. getTableData()
  83. }
  84. //表格
  85. const tableColumn = [
  86. { key: 'projectName', name: '项目名称', align: 'center' },
  87. { key: 'warningTypeName', name: '异常类型', align: 'center' },
  88. { key: 'quarterName', name: '季度', align: 'center' },
  89. { key: 'warningDate', name: '异常时间', align: 'center' },
  90. { key: 'warningGradeName', name: '异常等级', width: 80, align: 'center' },
  91. { key: 'isRepeal', name: '是否撤销', align: 'center' },
  92. { key: 'repealStartDate', name: '撤销开始时间', align: 'center' },
  93. { key: 'repealEndDate', name: '撤销结束时间', align: 'center' },
  94. { key: 'action', name: '操作', fixed: 'right', align: 'center' },
  95. ]
  96. const tableData = ref([])
  97. //设置单元格的样式
  98. const tableCellStyle = ({ row, column }) => {
  99. if (column.property === 'warningGradeName') {
  100. if (row.warningGradeName === '二级') {
  101. return { backgroundColor: '#FF9102', color: 'white' }
  102. } else if (row.warningGradeName === '三级') {
  103. return { backgroundColor: '#06B2F6', color: 'white' }
  104. } else if (row.warningGradeName === '一级') {
  105. return { backgroundColor: '#FF0001', color: 'white' }
  106. }
  107. }
  108. }
  109. //获取表格数据
  110. const tableLoading = ref(false)
  111. const getTableData = async () => {
  112. tableData.value = []
  113. tableLoading.value = true
  114. const { error, code, data } = await mainApi.page(searchForm.value)
  115. //处理数据
  116. tableLoading.value = false
  117. if (!error && code === 200) {
  118. tableData.value = getArrValue(data['records'])
  119. searchForm.value.total = data.total || 0
  120. } else {
  121. tableData.value = []
  122. searchForm.value.total = 0
  123. }
  124. }
  125. //多选事件
  126. const tableCheckedKeys = ref([])
  127. const tableSelectionChange = (rows) => {
  128. tableCheckedKeys.value = rows
  129. }
  130. //撤销
  131. const cancelModal = ref(false)
  132. const cancelForm = ref({})
  133. const cancleClick = (row) => {
  134. cancelModal.value = true
  135. cancelForm.value = {
  136. projectId: row.projectId,
  137. warningType: row.warningType,
  138. quarter: row.quarter,
  139. planYear: row.planYear,
  140. repealEndDate: null,
  141. }
  142. }
  143. //提交撤销
  144. const cancelLoding = ref(false)
  145. const saveCancelClick = async () => {
  146. const form = cancelForm.value
  147. if (isNullES(form.repealEndDate)) {
  148. window.$message.error('请选择撤销结束时间')
  149. return
  150. }
  151. //发起请求
  152. const { error, code, msg } = await mainApi.repeal(form)
  153. if (!error && code === 200) {
  154. window.$message.success('撤销成功')
  155. cancelModalClose()
  156. getTableData().then()
  157. } else {
  158. window.$message.error(msg ?? '操作失败')
  159. }
  160. }
  161. //关闭撤销
  162. const cancelModalClose = () => {
  163. cancelModal.value = false
  164. cancelForm.value = {}
  165. }
  166. const exportModal = ref(false)
  167. //批量导出
  168. const batchExportClick = (_, resolve) => {
  169. //这里可以写一些操作
  170. resolve() //这个一定要存在,否则不会关闭弹窗
  171. }
  172. //单个导出
  173. const exportClick = async (_, resolve) => {
  174. //这里可以写一些操作
  175. resolve() //这个一定要存在,否则不会关闭弹窗
  176. }
  177. </script>
  178. <style lang='scss' scoped>
  179. .hc-layout-box {
  180. position: relative;
  181. height: 100%;
  182. width: 100%;
  183. }
  184. </style>