index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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="100px">
  6. <el-form-item label="城市名称" prop="name">
  7. <el-input v-model="tableData.param.name" placeholder="请输入城市名称" clearable size="default" @keyup.enter="queryList" />
  8. </el-form-item>
  9. <el-form-item label="城市编号" prop="code">
  10. <el-input v-model="tableData.param.code" placeholder="请输入城市编号" clearable size="default" @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="onOpenAddDic">
  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%" row-key="id" default-expand-all :indent="16" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
  35. <el-table-column label="城市名称" prop="name" :show-overflow-tooltip="true" />
  36. <el-table-column label="城市编号" prop="code" :show-overflow-tooltip="true" />
  37. <el-table-column label="状态" prop="status" width="80">
  38. <template #default="scope">
  39. {{ scope.row.status === 1 ? '在线' : '不在线' }}
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="排序" prop="sort" align="center" />
  43. <el-table-column label="创建时间" prop="createdAt" :show-overflow-tooltip="true" />
  44. <el-table-column label="操作" width="200" align="center">
  45. <template #default="scope">
  46. <!-- <el-button size="small" text type="primary" @click="onOpenDetail(scope.row)">详情</el-button> -->
  47. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)">修改</el-button>
  48. <el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. <pagination v-show="tableData.total>0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="queryList" />
  53. </el-card>
  54. <EditDic ref="editDicRef" :treeData="tableData.data" @queryList="queryList" />
  55. <!-- <Detail ref="detailRef" /> -->
  56. </div>
  57. </template>
  58. <script lang="ts">
  59. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  60. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  61. import EditDic from './component/edit.vue';
  62. // import Detail from './component/detail.vue';
  63. import api from '/@/api/system';
  64. // 定义接口来定义对象的类型
  65. interface TableDataRow {
  66. id: number;
  67. name: string;
  68. code: string;
  69. stationId: string;
  70. loopTypes: number;
  71. energyTypes: number;
  72. heatingObject: number;
  73. heatingTypes: number;
  74. heatingArea: string;
  75. forRealArea: string;
  76. decade: string;
  77. status: number;
  78. }
  79. interface TableDataState {
  80. ids: number[];
  81. tableData: {
  82. data: Array<TableDataRow>;
  83. loading: boolean;
  84. param: {
  85. name: string;
  86. code: string;
  87. status: number;
  88. };
  89. };
  90. }
  91. export default defineComponent({
  92. name: 'cityManage',
  93. components: { EditDic },
  94. setup() {
  95. const addDicRef = ref();
  96. const editDicRef = ref();
  97. // const detailRef = ref();
  98. const queryRef = ref();
  99. const state = reactive<TableDataState>({
  100. ids: [],
  101. tableData: {
  102. data: [],
  103. loading: false,
  104. param: {
  105. name: '',
  106. code: '',
  107. status: -1
  108. },
  109. },
  110. });
  111. // 初始化表格数据
  112. const initTableData = () => {
  113. queryList();
  114. };
  115. const queryList = () => {
  116. state.tableData.loading = true
  117. api.city.getList(state.tableData.param)
  118. .then((res: any) => {
  119. state.tableData.data = res || [];
  120. state.tableData.loading = false
  121. });
  122. };
  123. // //查看详情
  124. // const onOpenDetail=(row: TableDataRow)=>{
  125. // detailRef.value.openDialog(row);
  126. // }
  127. // 打开新增产品弹窗
  128. const onOpenAddDic = () => {
  129. editDicRef.value.openDialog(null, state.tableData.data);
  130. };
  131. // 打开修改产品弹窗
  132. const onOpenEditDic = (row: TableDataRow) => {
  133. editDicRef.value.openDialog(row, state.tableData.data);
  134. };
  135. // 删除产品
  136. const onRowDel = (row: TableDataRow) => {
  137. let msg = '你确定要删除所选数据?';
  138. // let ids: number[] = [];
  139. // if (row) {
  140. msg = `此操作将永久删除设备:“${row.name}”,是否继续?`;
  141. // ids = [row.id];
  142. // } else {
  143. // ids = state.ids;
  144. // }
  145. // if (ids.length === 0) {
  146. // ElMessage.error('请选择要删除的数据。');
  147. // return;
  148. // }
  149. ElMessageBox.confirm(msg, '提示', {
  150. confirmButtonText: '确认',
  151. cancelButtonText: '取消',
  152. type: 'warning',
  153. })
  154. .then(() => {
  155. api.city.del(row.id).then(() => {
  156. ElMessage.success('删除成功');
  157. queryList();
  158. });
  159. })
  160. .catch(() => {});
  161. };
  162. // 页面加载时
  163. onMounted(() => {
  164. initTableData();
  165. });
  166. /** 重置按钮操作 */
  167. const resetQuery = (formEl: FormInstance | undefined) => {
  168. if (!formEl) return;
  169. formEl.resetFields();
  170. queryList();
  171. };
  172. // 多选框选中数据
  173. const handleSelectionChange = (selection: TableDataRow[]) => {
  174. state.ids = selection.map((item) => item.id);
  175. };
  176. return {
  177. addDicRef,
  178. editDicRef,
  179. // detailRef,
  180. queryRef,
  181. // onOpenDetail,
  182. onOpenAddDic,
  183. onOpenEditDic,
  184. onRowDel,
  185. queryList,
  186. resetQuery,
  187. handleSelectionChange,
  188. ...toRefs(state),
  189. };
  190. },
  191. });
  192. </script>