system-unit.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <hc-card>
  3. <template #header>
  4. <div class="w-60">
  5. <hc-search-input v-model="searchForm.name" placeholder="请输入名称关键词" @search="searchClick" />
  6. </div>
  7. </template>
  8. <template #extra>
  9. <el-button hc-btn type="primary" @click="addClick">新增</el-button>
  10. </template>
  11. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" :index-style="{ width: 60 }" :is-current-row="false">
  12. <template #action="{ row }">
  13. <el-link type="warning" @click="editRowClick(row)">修改</el-link>
  14. <el-link type="primary" @click="setTempShow(row)">编辑计量系统单元</el-link>
  15. <el-link type="danger" @click="delRowClick(row)">删除</el-link>
  16. </template>
  17. </hc-table>
  18. <template #action>
  19. <hc-pages :pages="searchForm" @change="pageChange" />
  20. </template>
  21. <!-- 新增/修改 -->
  22. <hc-dialog v-model="isDialogShow" widths="24rem" is-footer-center :title="formModel.id ? '新增' : '修改'" @close="dialogClose">
  23. <el-form ref="formRef" :model="formModel" :rules="formRules" size="large" label-width="auto">
  24. <el-form-item label="名称:" prop="name">
  25. <el-input v-model="formModel.name" clearable placeholder="请输入模版名称" />
  26. </el-form-item>
  27. <el-form-item label="备注:">
  28. <el-input v-model="formModel.remarks" clearable placeholder="请输入备注" />
  29. </el-form-item>
  30. </el-form>
  31. <template #footer>
  32. <el-button hc-btn @click="dialogClose">取消</el-button>
  33. <el-button hc-btn type="primary" :loading="submitLoading" @click="dialogSubmit">提交</el-button>
  34. </template>
  35. </hc-dialog>
  36. <!-- 编辑计量系统单元 -->
  37. <HcTemp v-model="isTempShow" :data="tempData" />
  38. </hc-card>
  39. </template>
  40. <script setup>
  41. import { nextTick, onActivated, onDeactivated, onUnmounted, ref } from 'vue'
  42. import { deepClone, formValidate, getArrValue } from 'js-fast-way'
  43. import HcTemp from './system-unit/temp.vue'
  44. import { HcDelMsg } from 'hc-vue3-ui'
  45. import mainApi from '~api/desk/system-unit'
  46. //激活
  47. onActivated(() => {
  48. searchForm.value.current = 1
  49. getTableData()
  50. })
  51. //搜索表单
  52. const searchForm = ref({ current: 1, size: 30, total: 0 })
  53. //搜索
  54. const searchClick = () => {
  55. searchForm.value.current = 1
  56. getTableData()
  57. }
  58. //分页
  59. const pageChange = ({ current, size }) => {
  60. searchForm.value.current = current
  61. searchForm.value.size = size
  62. getTableData()
  63. }
  64. //表格数据
  65. const tableColumn = ref([
  66. { key: 'name', name: '模版名称' },
  67. { key: 'remarks', name: '备注' },
  68. { key: 'action', name: '操作', width: 220, align: 'center' },
  69. ])
  70. //获取表格数据
  71. const tableLoading = ref(true)
  72. const tableData = ref([{}])
  73. const getTableData = async () => {
  74. tableData.value = []
  75. tableLoading.value = true
  76. const { data } = await mainApi.page({
  77. ...searchForm.value,
  78. total: null,
  79. })
  80. tableLoading.value = false
  81. tableData.value = getArrValue(data?.records)
  82. searchForm.value.total = data?.total || 0
  83. }
  84. //新增/修改 弹窗
  85. const isDialogShow = ref(false)
  86. const formRef = ref(null)
  87. const formModel = ref({})
  88. const formRules = { name: { required: true, trigger: 'blur', message: '请输入模版名称' } }
  89. //新增
  90. const addClick = async () => {
  91. formModel.value = {}
  92. await nextTick()
  93. isDialogShow.value = true
  94. }
  95. //修改
  96. const editRowClick = async (row) => {
  97. formModel.value = deepClone(row)
  98. await nextTick()
  99. isDialogShow.value = true
  100. }
  101. //提交表单
  102. const submitLoading = ref(false)
  103. const dialogSubmit = async () => {
  104. const isForm = await formValidate(formRef.value)
  105. if (!isForm) return false
  106. submitLoading.value = true
  107. const { error, code } = await mainApi.submit(formModel.value)
  108. submitLoading.value = false
  109. if (!error && code === 200) {
  110. window?.$message?.success('操作成功')
  111. dialogClose()
  112. getTableData().then()
  113. }
  114. }
  115. //删除
  116. const delRowClick = (row) => {
  117. HcDelMsg(async (resolve) => {
  118. const { code } = await mainApi.del(row.id)
  119. resolve() //关闭弹窗的回调
  120. if (code !== 200) return
  121. window.$message.success('删除成功')
  122. getTableData().then()
  123. })
  124. }
  125. //编辑计量系统单元
  126. const isTempShow = ref(false)
  127. const tempData = ref({})
  128. // 编辑计量系统单元
  129. const setTempShow = async (row) => {
  130. tempData.value = deepClone(row)
  131. await nextTick()
  132. isTempShow.value = true
  133. }
  134. //关闭弹窗
  135. const dialogClose = () => {
  136. isDialogShow.value = false
  137. formModel.value = {}
  138. }
  139. //关闭
  140. onDeactivated(() => {
  141. isTempShow.value = false
  142. isDialogShow.value = false
  143. })
  144. //卸载
  145. onUnmounted(()=> {
  146. isTempShow.value = false
  147. isDialogShow.value = false
  148. })
  149. </script>