index.vue 7.7 KB

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