index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="system-dic-container">
  3. <div>
  4. <div class="system-user-search mb15">
  5. <el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="68px">
  6. <el-form-item label="楼宇名称" prop="name">
  7. <el-input v-model="tableData.param.name" placeholder="请输入楼宇名称" clearable size="default" style="width: 240px" @keyup.enter="queryList" />
  8. </el-form-item>
  9. <el-form-item label="楼号" prop="number">
  10. <el-input v-model="tableData.param.number" placeholder="请输入楼号" clearable size="default" style="width: 240px" @keyup.enter="queryList" />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button size="default" v-auth="'floor-query'" type="primary" class="ml10" @click="queryList">
  14. <el-icon>
  15. <ele-Search />
  16. </el-icon>
  17. 查询
  18. </el-button>
  19. <el-button size="default" v-auth="'floor-reset'" @click="resetQuery(queryRef)">
  20. <el-icon>
  21. <ele-Refresh />
  22. </el-icon>
  23. 重置
  24. </el-button>
  25. <el-button size="default" v-auth="'floor-add'" type="success" class="ml10" @click="onOpenDialog()">
  26. <el-icon>
  27. <ele-FolderAdd />
  28. </el-icon>
  29. 新增
  30. </el-button>
  31. </el-form-item>
  32. </el-form>
  33. </div>
  34. <el-table :data="tableData.data" v-loading="tableData.loading" style="width: 100%" >
  35. <el-table-column label="ID" align="center" prop="id" width="60" />
  36. <el-table-column label="楼宇名称" v-col="'floor-name'" prop="name" />
  37. <el-table-column label="楼号" v-col="'floor-number'" prop="number" />
  38. <el-table-column label="更新时间" v-col="'floor-createdAt'" prop="createdAt" width="180" />
  39. <el-table-column label="启用状态" v-col="'floor-status'" prop="status" width="120" align="center">
  40. <template #default="scope">
  41. <el-switch v-model="scope.row.status" inline-prompt :active-value="1" :inactive-value="0" active-text="启" inactive-text="禁" @change="handleStatusChange(scope.row)">
  42. </el-switch>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="操作" v-col="'floor-handle'" width="200" align="center" fixed="right">
  46. <template #default="scope">
  47. <el-button size="small" text type="warning" @click="onOpenDialog(scope.row)">修改</el-button>
  48. <el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. <pagination v-show="tableData.total>0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="queryList" />
  53. </div>
  54. <EditDic ref="editDicRef" @queryList="handleFinish()" />
  55. <Detail ref="detailRef" />
  56. </div>
  57. </template>
  58. <script lang="ts">
  59. import { toRefs, reactive, onMounted, ref, defineComponent, watch } from 'vue';
  60. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  61. import EditDic from './component/edit.vue';
  62. import Detail from './component/detail.vue';
  63. import api from '/@/api/heatingDistrict';
  64. export default defineComponent({
  65. name: 'loop',
  66. components: { EditDic,Detail },
  67. props: {
  68. nodeId: {
  69. default: ''
  70. }
  71. },
  72. setup(prop, { emit }) {
  73. const editDicRef = ref();
  74. const detailRef=ref();
  75. const queryRef = ref();
  76. const state = reactive({
  77. ids: [],
  78. tableData: {
  79. data: [],
  80. total: 0,
  81. loading: false,
  82. param: {
  83. pageNum: 1,
  84. pageSize: 10,
  85. name: '',
  86. number: '',
  87. nodeId: '',
  88. status: -1
  89. },
  90. },
  91. });
  92. const queryList = () => {
  93. state.tableData.loading = true
  94. api.floor.getList(state.tableData.param).then((res: any) => {
  95. state.tableData.data = res.Info || [];
  96. state.tableData.total = res.Total;
  97. state.tableData.loading = false
  98. });
  99. };
  100. const handleFinish = () => {
  101. emit('finish')
  102. queryList()
  103. }
  104. watch(() => prop.nodeId, () => {
  105. state.tableData.param.nodeId = prop.nodeId
  106. queryList()
  107. }, {
  108. deep: true,
  109. immediate: true
  110. })
  111. //查看详情
  112. const onOpenDetail=(row: any)=>{
  113. detailRef.value.openDialog(row);
  114. }
  115. // 打开新增修改弹窗
  116. const onOpenDialog = (row: any) => {
  117. editDicRef.value.openDialog(row, { nodeId: prop.nodeId });
  118. };
  119. // 状态修改
  120. const handleStatusChange = (row: any) => {
  121. let text = row.status === 1 ? '启用' : '停用';
  122. ElMessageBox.confirm('确认要"' + text + '":"' + row.name + '"楼宇吗?', '警告', {
  123. confirmButtonText: '确定',
  124. cancelButtonText: '取消',
  125. type: 'warning',
  126. })
  127. .then(function () {
  128. return api.floor.setStatus(row.id, row.status);
  129. })
  130. .then(() => {
  131. ElMessage.success(text + '成功');
  132. })
  133. .catch(function () {
  134. row.status = row.status === 0 ? 1 : 0;
  135. });
  136. };
  137. // 删除产品
  138. const onRowDel = (row: any) => {
  139. let msg = `此操作将永久删除楼宇:“${row.name}”,是否继续?`;
  140. ElMessageBox.confirm(msg, '提示', {
  141. confirmButtonText: '确认',
  142. cancelButtonText: '取消',
  143. type: 'warning',
  144. })
  145. .then(() => {
  146. api.floor.del(row.id).then(() => {
  147. ElMessage.success('删除成功');
  148. queryList();
  149. });
  150. })
  151. .catch(() => {});
  152. };
  153. /** 重置按钮操作 */
  154. const resetQuery = (formEl: FormInstance | undefined) => {
  155. if (!formEl) return;
  156. formEl.resetFields();
  157. queryList();
  158. };
  159. return {
  160. editDicRef,
  161. detailRef,
  162. queryRef,
  163. onOpenDetail,
  164. onOpenDialog,
  165. onRowDel,
  166. queryList,
  167. resetQuery,
  168. handleStatusChange,
  169. handleFinish,
  170. ...toRefs(state),
  171. };
  172. },
  173. });
  174. </script>