index.vue 6.3 KB

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