index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div class="system-dic-container">
  3. <el-card shadow="hover">
  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="organizationId">
  7. <el-tree-select
  8. v-model="tableData.param.organizationId"
  9. :data="orgList"
  10. :props="{
  11. label: 'name',
  12. children: 'children'
  13. }"
  14. placeholder="请选择"
  15. node-key="id"
  16. :clearable="true"
  17. check-strictly
  18. style="width: 100%;"
  19. :render-after-expand="true"
  20. size="default"
  21. />
  22. </el-form-item>
  23. <el-form-item label="小区名称" prop="plotId">
  24. <el-select v-model="tableData.param.plotId" @change="onPlotChange" placeholder="选择小区名称" filterable clearable size="default">
  25. <el-option
  26. v-for="item in plotList"
  27. :key="item.id"
  28. :label="item.name"
  29. :value="item.id">
  30. </el-option>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="楼宇名称" prop="floorId">
  34. <el-select v-model="tableData.param.floorId" placeholder="选择楼宇名称" filterable clearable size="default">
  35. <el-option
  36. v-for="item in floorList"
  37. :key="item.id"
  38. :label="item.name"
  39. :value="item.id">
  40. </el-option>
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label="单元名称" prop="name">
  44. <el-input v-model="tableData.param.name" placeholder="请输入单元名称" clearable size="default" style="width: 240px" @keyup.enter="queryList" />
  45. </el-form-item>
  46. <el-form-item>
  47. <el-button size="default" type="primary" class="ml10" @click="queryList">
  48. <el-icon>
  49. <ele-Search />
  50. </el-icon>
  51. 查询
  52. </el-button>
  53. <el-button size="default" @click="resetQuery(queryRef)">
  54. <el-icon>
  55. <ele-Refresh />
  56. </el-icon>
  57. 重置
  58. </el-button>
  59. <el-button size="default" type="success" class="ml10" @click="onOpenDialog()">
  60. <el-icon>
  61. <ele-FolderAdd />
  62. </el-icon>
  63. 新增
  64. </el-button>
  65. <!-- <el-button size="default" type="danger" class="ml10" @click="onRowDel(null)">
  66. <el-icon>
  67. <ele-Delete />
  68. </el-icon>
  69. 删除
  70. </el-button> -->
  71. </el-form-item>
  72. </el-form>
  73. </div>
  74. <el-table :data="tableData.data" style="width: 100%" >
  75. <!-- <el-table-column type="selection" width="55" align="center" /> -->
  76. <el-table-column label="ID" align="center" prop="id" width="60" />
  77. <el-table-column label="组织名称" prop="organizationInfo.name" min-width="100" />
  78. <el-table-column label="小区名称" prop="plotInfo.name" min-width="100" />
  79. <el-table-column label="楼宇名称" prop="floorInfo.name" min-width="100" />
  80. <el-table-column label="单元名称" prop="name" min-width="100" />
  81. <el-table-column label="单元号" prop="number" min-width="100" />
  82. <el-table-column label="更新时间" prop="updatedAt" width="180" />
  83. <el-table-column prop="status" label="启用状态" width="120" align="center">
  84. <template #default="scope">
  85. <el-switch v-model="scope.row.status" inline-prompt :active-value="1" :inactive-value="0" active-text="启" inactive-text="禁" @change="handleStatusChange(scope.row)">
  86. </el-switch>
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="操作" width="200" align="center" fixed="right">
  90. <template #default="scope">
  91. <el-button size="small" text type="warning" @click="onOpenDialog(scope.row)">修改</el-button>
  92. <el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <pagination v-show="tableData.total>0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="queryList" />
  97. </el-card>
  98. <EditDic ref="editDicRef" @queryList="queryList" />
  99. <Detail ref="detailRef" />
  100. </div>
  101. </template>
  102. <script lang="ts">
  103. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  104. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  105. import EditDic from './component/edit.vue';
  106. import Detail from './component/detail.vue';
  107. import api from '/@/api/heatingDistrict';
  108. import systemApi from '/@/api/system';
  109. export default defineComponent({
  110. name: 'loop',
  111. components: { EditDic,Detail },
  112. setup() {
  113. const addDicRef = ref();
  114. const editDicRef = ref();
  115. const detailRef=ref();
  116. const queryRef = ref();
  117. const state = reactive({
  118. ids: [],
  119. tableData: {
  120. data: [],
  121. total: 0,
  122. loading: false,
  123. param: {
  124. pageNum: 1,
  125. pageSize: 10,
  126. name: '',
  127. plotId: '',
  128. floorId: '',
  129. organizationId: '',
  130. status: -1
  131. },
  132. },
  133. });
  134. // 组织
  135. const orgList = ref([])
  136. // 小区
  137. const plotList = ref([])
  138. // 楼宇
  139. const floorList = ref([])
  140. // 初始化表格数据
  141. const initTableData = () => {
  142. queryList();
  143. };
  144. // 获取组织
  145. const getOrgList = () => {
  146. systemApi.org.getList({ name: '', status: -1 }).then((res: any) => {
  147. orgList.value = res;
  148. });
  149. }
  150. // 获取区域
  151. const getPlotList = () => {
  152. api.regionalManage.allList({})
  153. .then((res: any) => {
  154. plotList.value = res.Info || []
  155. })
  156. }
  157. // 获取楼宇
  158. const getFloorList = () => {
  159. api.floor.allList({ plotId: state.tableData.param.plotId })
  160. .then((res: any) => {
  161. floorList.value = res.Info || []
  162. })
  163. }
  164. const queryList = () => {
  165. api.unit.getList(state.tableData.param).then((res: any) => {
  166. console.log(res);
  167. state.tableData.data = res.Data || [];
  168. state.tableData.total = res.Total;
  169. });
  170. };
  171. const onPlotChange = () => {
  172. floorList.value = []
  173. state.tableData.param.floorId = ''
  174. if (state.tableData.param.plotId) {
  175. getFloorList()
  176. }
  177. }
  178. //查看详情
  179. const onOpenDetail=(row: any)=>{
  180. detailRef.value.openDialog(row);
  181. }
  182. // 打开新增修改弹窗
  183. const onOpenDialog = (row: any) => {
  184. editDicRef.value.orgList = orgList.value
  185. editDicRef.value.plotList = plotList.value
  186. editDicRef.value.openDialog(row);
  187. };
  188. // 状态修改
  189. const handleStatusChange = (row: any) => {
  190. let text = row.status === 1 ? '启用' : '停用';
  191. ElMessageBox.confirm('确认要"' + text + '":"' + row.name + '"单元吗?', '警告', {
  192. confirmButtonText: '确定',
  193. cancelButtonText: '取消',
  194. type: 'warning',
  195. })
  196. .then(function () {
  197. return api.unit.setStatus(row.id, row.status);
  198. })
  199. .then(() => {
  200. ElMessage.success(text + '成功');
  201. })
  202. .catch(function () {
  203. row.status = row.status === 0 ? 1 : 0;
  204. });
  205. };
  206. // 删除产品
  207. const onRowDel = (row: any) => {
  208. let msg = `此操作将永久删除单元:“${row.name}”,是否继续?`;
  209. ElMessageBox.confirm(msg, '提示', {
  210. confirmButtonText: '确认',
  211. cancelButtonText: '取消',
  212. type: 'warning',
  213. })
  214. .then(() => {
  215. api.unit.del(row.id).then(() => {
  216. ElMessage.success('删除成功');
  217. queryList();
  218. });
  219. })
  220. .catch(() => {});
  221. };
  222. // 页面加载时
  223. onMounted(() => {
  224. initTableData();
  225. getOrgList();
  226. getPlotList()
  227. });
  228. /** 重置按钮操作 */
  229. const resetQuery = (formEl: FormInstance | undefined) => {
  230. if (!formEl) return;
  231. formEl.resetFields();
  232. queryList();
  233. };
  234. return {
  235. addDicRef,
  236. editDicRef,
  237. detailRef,
  238. queryRef,
  239. onOpenDetail,
  240. onOpenDialog,
  241. onRowDel,
  242. queryList,
  243. resetQuery,
  244. orgList,
  245. plotList,
  246. floorList,
  247. onPlotChange,
  248. handleStatusChange,
  249. ...toRefs(state),
  250. };
  251. },
  252. });
  253. </script>