index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="楼宇名" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入楼宇名"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="所属小区" prop="areaId">
  14. <el-select v-model="queryParams.areaId" filterable placeholder="请选择所属小区">
  15. <el-option v-for="item in areaList" :key="item.id" :value="item.id" :label="item.name">{{ item.name }}</el-option>
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  20. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  21. </el-form-item>
  22. </el-form>
  23. <el-row :gutter="10" class="mb8">
  24. <el-col :span="1.5">
  25. <el-button
  26. type="primary"
  27. plain
  28. icon="el-icon-plus"
  29. size="mini"
  30. @click="handleAdd"
  31. v-hasPermi="['gas:building:add']"
  32. >新增</el-button>
  33. </el-col>
  34. <el-col :span="1.5">
  35. <el-button
  36. type="danger"
  37. plain
  38. icon="el-icon-delete"
  39. size="mini"
  40. :disabled="multiple"
  41. @click="handleDelete"
  42. v-hasPermi="['gas:building:remove']"
  43. >删除</el-button>
  44. </el-col>
  45. <!-- <el-col :span="1.5">-->
  46. <!-- <el-button-->
  47. <!-- type="warning"-->
  48. <!-- plain-->
  49. <!-- icon="el-icon-download"-->
  50. <!-- size="mini"-->
  51. <!-- :loading="exportLoading"-->
  52. <!-- @click="handleExport"-->
  53. <!-- v-hasPermi="['gas:building:export']"-->
  54. <!-- >导出</el-button>-->
  55. <!-- </el-col>-->
  56. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  57. </el-row>
  58. <el-table v-loading="loading" :data="buildingList" @selection-change="handleSelectionChange">
  59. <el-table-column type="selection" width="55" align="center" />
  60. <el-table-column label="所属小区" align="center" prop="areaName" />
  61. <el-table-column label="楼宇名" align="center" prop="name" />
  62. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  63. <template slot-scope="scope">
  64. <!-- <el-button-->
  65. <!-- size="mini"-->
  66. <!-- type="text"-->
  67. <!-- icon="el-icon-edit"-->
  68. <!-- @click="handleUpdate(scope.row)"-->
  69. <!-- v-hasPermi="['gas:building:edit']"-->
  70. <!-- >修改</el-button>-->
  71. <el-button
  72. size="mini"
  73. type="text"
  74. icon="el-icon-delete"
  75. @click="handleDelete(scope.row)"
  76. v-hasPermi="['gas:building:remove']"
  77. >删除</el-button>
  78. </template>
  79. </el-table-column>
  80. </el-table>
  81. <pagination
  82. v-show="total>0"
  83. :total="total"
  84. :page.sync="queryParams.pageNum"
  85. :limit.sync="queryParams.pageSize"
  86. @pagination="getList"
  87. />
  88. <!-- 添加或修改楼宇对话框 -->
  89. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  90. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  91. <el-form-item label="楼宇名" prop="name">
  92. <el-input v-model="form.name" placeholder="请输入楼宇名" />
  93. </el-form-item>
  94. <el-form-item label="所属小区" prop="areaId">
  95. <el-select v-model="form.areaId" filterable placeholder="请选择所属小区">
  96. <el-option v-for="item in areaList" :key="item.id" :value="item.id" :label="item.name">{{ item.name }}</el-option>
  97. </el-select>
  98. </el-form-item>
  99. </el-form>
  100. <div slot="footer" class="dialog-footer">
  101. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  102. <el-button @click="cancel">取 消</el-button>
  103. </div>
  104. </el-dialog>
  105. </div>
  106. </template>
  107. <script>
  108. import { listBuilding, getBuilding, getArea,delBuilding, addBuilding, updateBuilding } from "@/api/gas/building";
  109. export default {
  110. name: "Building",
  111. data() {
  112. return {
  113. // 按钮loading
  114. buttonLoading: false,
  115. // 遮罩层
  116. loading: true,
  117. // 导出遮罩层
  118. exportLoading: false,
  119. // 选中数组
  120. ids: [],
  121. // 非单个禁用
  122. single: true,
  123. // 非多个禁用
  124. multiple: true,
  125. // 显示搜索条件
  126. showSearch: true,
  127. // 总条数
  128. total: 0,
  129. // 楼宇表格数据
  130. buildingList: [],
  131. // 弹出层标题
  132. title: "",
  133. // 是否显示弹出层
  134. open: false,
  135. // 查询参数
  136. queryParams: {
  137. pageNum: 1,
  138. pageSize: 10,
  139. name: undefined,
  140. areaId: undefined,
  141. },
  142. areaList:[],
  143. // 表单参数
  144. form: {},
  145. // 表单校验
  146. rules: {
  147. name: [
  148. { required: true, message: "楼宇名不能为空", trigger: "blur" }
  149. ],
  150. areaId: [
  151. { required: true, message: "小区id不能为空", trigger: "blur" }
  152. ],
  153. }
  154. };
  155. },
  156. created() {
  157. this.getList();
  158. this.getArea();
  159. },
  160. methods: {
  161. /** 查询楼宇列表 */
  162. getList() {
  163. this.loading = true;
  164. listBuilding(this.queryParams).then(response => {
  165. this.buildingList = response.rows;
  166. this.total = response.total;
  167. this.loading = false;
  168. });
  169. },
  170. /**小区下拉框*/
  171. getArea() {
  172. this.loading = true;
  173. getArea().then(response => {
  174. this.areaList = response.data;
  175. });
  176. },
  177. // 取消按钮
  178. cancel() {
  179. this.open = false;
  180. this.reset();
  181. },
  182. // 表单重置
  183. reset() {
  184. this.form = {
  185. id: undefined,
  186. name: undefined,
  187. areaId: undefined,
  188. delFlag: undefined,
  189. createBy: undefined,
  190. createTime: undefined,
  191. updateBy: undefined,
  192. updateTime: undefined
  193. };
  194. this.resetForm("form");
  195. },
  196. /** 搜索按钮操作 */
  197. handleQuery() {
  198. this.queryParams.pageNum = 1;
  199. this.getList();
  200. this.getArea();
  201. },
  202. /** 重置按钮操作 */
  203. resetQuery() {
  204. this.resetForm("queryForm");
  205. this.handleQuery();
  206. },
  207. // 多选框选中数据
  208. handleSelectionChange(selection) {
  209. this.ids = selection.map(item => item.id)
  210. this.single = selection.length!==1
  211. this.multiple = !selection.length
  212. },
  213. /** 新增按钮操作 */
  214. handleAdd() {
  215. this.reset();
  216. this.open = true;
  217. this.title = "添加楼宇";
  218. },
  219. /** 修改按钮操作 */
  220. handleUpdate(row) {
  221. this.loading = true;
  222. this.reset();
  223. const id = row.id || this.ids
  224. getBuilding(id).then(response => {
  225. this.loading = false;
  226. this.form = response.data;
  227. this.open = true;
  228. this.title = "修改楼宇";
  229. });
  230. },
  231. /** 提交按钮 */
  232. submitForm() {
  233. this.$refs["form"].validate(valid => {
  234. if (valid) {
  235. this.buttonLoading = true;
  236. if (this.form.id != null) {
  237. updateBuilding(this.form).then(response => {
  238. this.$modal.msgSuccess("修改成功");
  239. this.open = false;
  240. this.getList();
  241. this.getArea();
  242. }).finally(() => {
  243. this.buttonLoading = false;
  244. });
  245. } else {
  246. addBuilding(this.form).then(response => {
  247. if(response.data){
  248. this.$modal.msgSuccess("新增成功");
  249. this.open = false;
  250. this.getList();
  251. this.getArea();
  252. }else{
  253. this.$modal.msgError("同一小区下楼宇名称不允许重复,请重新填写!");
  254. }
  255. }).finally(() => {
  256. this.buttonLoading = false;
  257. });
  258. }
  259. }
  260. });
  261. },
  262. /** 删除按钮操作 */
  263. handleDelete(row) {
  264. const ids = row.id || this.ids;
  265. this.$modal.confirm('是否确认删除楼宇编号为"' + ids + '"的数据项?').then(() => {
  266. this.loading = true;
  267. return delBuilding(ids);
  268. }).then(() => {
  269. this.loading = false;
  270. this.getList();
  271. this.getArea();
  272. this.$modal.msgSuccess("删除成功");
  273. }).finally(() => {
  274. this.loading = false;
  275. });
  276. },
  277. /** 导出按钮操作 */
  278. handleExport() {
  279. this.$download.excel('/gas/building/export', this.queryParams);
  280. }
  281. }
  282. };
  283. </script>