index.vue 5.7 KB

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