index.vue 6.7 KB

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