index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="小区" prop="areaId">
  5. <el-select v-model="queryParams.areaId" placeholder="请选择小区" filterable @change="getBuildings">
  6. <el-option
  7. v-for="obj in areas"
  8. :key="obj.id"
  9. :label="obj.name"
  10. :value="obj.id"
  11. ></el-option>
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="楼栋" prop="buildingId">
  15. <el-select v-model="queryParams.buildingId" placeholder="请选择楼栋" filterable @change="getUnits">
  16. <el-option
  17. v-for="obj in builds"
  18. :key="obj.id"
  19. :label="obj.name"
  20. :value="obj.id"
  21. ></el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="单元" prop="unitId">
  25. <el-select v-model="queryParams.unitId" placeholder="请选择单元" filterable>
  26. <el-option
  27. v-for="obj in units"
  28. :key="obj.id"
  29. :label="obj.name"
  30. :value="obj.id"
  31. ></el-option>
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="房间名称" prop="name">
  35. <el-input
  36. v-model="queryParams.name"
  37. placeholder="请输入房间名称"
  38. clearable
  39. @keyup.enter.native="handleQuery"
  40. />
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  44. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  45. </el-form-item>
  46. </el-form>
  47. <el-row :gutter="10" class="mb8">
  48. <el-col :span="1.5">
  49. <el-button
  50. type="primary"
  51. plain
  52. icon="el-icon-plus"
  53. size="mini"
  54. @click="handleAdd"
  55. v-hasPermi="['zdsz:house:add']"
  56. >新增
  57. </el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="success"
  62. plain
  63. icon="el-icon-edit"
  64. size="mini"
  65. :disabled="single"
  66. @click="handleUpdate"
  67. v-hasPermi="['zdsz:house:edit']"
  68. >修改
  69. </el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button
  73. type="danger"
  74. plain
  75. icon="el-icon-delete"
  76. size="mini"
  77. :disabled="multiple"
  78. @click="handleDelete"
  79. v-hasPermi="['zdsz:house:remove']"
  80. >删除
  81. </el-button>
  82. </el-col>
  83. <!-- <el-col :span="1.5">-->
  84. <!-- <el-button-->
  85. <!-- type="warning"-->
  86. <!-- plain-->
  87. <!-- icon="el-icon-download"-->
  88. <!-- size="mini"-->
  89. <!-- @click="handleExport"-->
  90. <!-- v-hasPermi="['zdsz:house:export']"-->
  91. <!-- >导出</el-button>-->
  92. <!-- </el-col>-->
  93. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  94. </el-row>
  95. <el-table v-loading="loading" :data="houseList" @selection-change="handleSelectionChange">
  96. <el-table-column type="selection" width="55" align="center"/>
  97. <!-- <el-table-column label="" align="center" prop="id" v-if="true"/>-->
  98. <el-table-column label="小区" align="center" prop="areaName"/>
  99. <el-table-column label="楼栋" align="center" prop="buildingName"/>
  100. <el-table-column label="单元" align="center" prop="unitName"/>
  101. <el-table-column label="房间号" align="center" prop="name"/>
  102. <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>
  103. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  104. <template slot-scope="scope">
  105. <el-button
  106. size="mini"
  107. type="text"
  108. icon="el-icon-edit"
  109. @click="handleUpdate(scope.row)"
  110. v-hasPermi="['zdsz:house:edit']"
  111. >修改
  112. </el-button>
  113. <el-button
  114. size="mini"
  115. type="text"
  116. icon="el-icon-delete"
  117. @click="handleDelete(scope.row)"
  118. v-hasPermi="['zdsz:house:remove']"
  119. >删除
  120. </el-button>
  121. </template>
  122. </el-table-column>
  123. </el-table>
  124. <pagination
  125. v-show="total>0"
  126. :total="total"
  127. :page.sync="queryParams.pageNum"
  128. :limit.sync="queryParams.pageSize"
  129. @pagination="getList"
  130. />
  131. <!-- 添加或修改房间管理对话框 -->
  132. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  133. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  134. <el-row :gutter="20">
  135. <el-col :span="12">
  136. <el-form-item label="小区" prop="areaId">
  137. <el-select v-model="form.areaId" placeholder="请选择小区" filterable @change="getBuildings1">
  138. <el-option
  139. v-for="obj in areas"
  140. :key="obj.id"
  141. :label="obj.name"
  142. :value="obj.id"
  143. ></el-option>
  144. </el-select>
  145. </el-form-item>
  146. </el-col>
  147. <el-col :span="12">
  148. <el-form-item label="楼栋" prop="buildingId">
  149. <el-select v-model="form.buildingId" placeholder="请选择楼栋" filterable @change="getUnits1" style="width: 270px;">
  150. <el-option
  151. v-for="obj in builds"
  152. :key="obj.id"
  153. :label="obj.name"
  154. :value="obj.id"
  155. ></el-option>
  156. </el-select>
  157. </el-form-item>
  158. </el-col>
  159. </el-row>
  160. <el-row :gutter="20">
  161. <el-col :span="12">
  162. <el-form-item label="单元" prop="unitId">
  163. <el-select v-model="form.unitId" placeholder="请选择单元" filterable>
  164. <el-option
  165. v-for="obj in units"
  166. :key="obj.id"
  167. :label="obj.name"
  168. :value="obj.id"
  169. ></el-option>
  170. </el-select>
  171. </el-form-item>
  172. </el-col>
  173. <el-col :span="12">
  174. <el-form-item label="房间号" prop="name">
  175. <el-input v-model="form.name" placeholder="请输入" maxlength="10"/>
  176. </el-form-item>
  177. </el-col>
  178. </el-row>
  179. <el-row :gutter="20">
  180. <el-col :span="24">
  181. <el-form-item label="备注" prop="remark">
  182. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" maxlength="100"/>
  183. </el-form-item>
  184. </el-col>
  185. </el-row>
  186. </el-form>
  187. <div slot="footer" class="dialog-footer">
  188. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  189. <el-button @click="cancel">取 消</el-button>
  190. </div>
  191. </el-dialog>
  192. </div>
  193. </template>
  194. <script>
  195. import {listHouse, getHouse, delHouse, addHouse, updateHouse} from "@/api/zdsz/house";
  196. import {getAreas} from "@/api/zdsz/area";
  197. import {getBuildings} from "@/api/zdsz/building";
  198. import {getUnits} from "@/api/zdsz/unit";
  199. export default {
  200. name: "House",
  201. data() {
  202. return {
  203. // 按钮loading
  204. buttonLoading: false,
  205. // 遮罩层
  206. loading: true,
  207. // 选中数组
  208. ids: [],
  209. // 非单个禁用
  210. single: true,
  211. // 非多个禁用
  212. multiple: true,
  213. // 显示搜索条件
  214. showSearch: true,
  215. // 总条数
  216. total: 0,
  217. // 房间管理表格数据
  218. houseList: [],
  219. // 弹出层标题
  220. title: "",
  221. // 是否显示弹出层
  222. open: false,
  223. // 查询参数
  224. queryParams: {
  225. pageNum: 1,
  226. pageSize: 10,
  227. areaId: undefined,
  228. buildingId: undefined,
  229. unitId: undefined,
  230. name: undefined,
  231. },
  232. // 表单参数
  233. form: {},
  234. // 表单校验
  235. rules: {
  236. id: [
  237. {required: true, message: "不能为空", trigger: "blur"}
  238. ],
  239. areaId: [
  240. {required: true, message: "不能为空", trigger: "change"}
  241. ],
  242. buildingId: [
  243. {required: true, message: "不能为空", trigger: "change"}
  244. ],
  245. unitId: [
  246. {required: true, message: "不能为空", trigger: "change"}
  247. ],
  248. name: [
  249. {required: true, message: "不能为空", trigger: "blur"}
  250. ],
  251. remark: [
  252. {required: false, message: "备注不能为空", trigger: "blur"}
  253. ],
  254. },
  255. areas: [],
  256. builds: [],
  257. units: [],
  258. };
  259. },
  260. created() {
  261. this.getList();
  262. this.getAreas();
  263. },
  264. methods: {
  265. /** 查询楼栋下拉 */
  266. getBuildings(id) {
  267. this.builds = []
  268. this.units = []
  269. this.queryParams.buildingId = undefined
  270. this.queryParams.unitId = undefined
  271. getBuildings(id).then(res => {
  272. this.builds = res.data
  273. })
  274. },
  275. getBuildings1(id) {
  276. this.builds = []
  277. this.units = []
  278. this.form.buildingId = undefined
  279. this.form.unitId = undefined
  280. getBuildings(id).then(res => {
  281. this.builds = res.data
  282. })
  283. },
  284. /** 查询单元下拉 */
  285. getUnits(id) {
  286. this.units = []
  287. this.queryParams.unitId = undefined
  288. getUnits(id).then(res => {
  289. this.units = res.data
  290. })
  291. },
  292. getUnits1(id) {
  293. this.units = []
  294. this.form.unitId = undefined
  295. getUnits(id).then(res => {
  296. this.units = res.data
  297. })
  298. },
  299. /** 查询房间管理列表 */
  300. getList() {
  301. this.loading = true;
  302. listHouse(this.queryParams).then(response => {
  303. this.houseList = response.rows;
  304. this.total = response.total;
  305. this.loading = false;
  306. });
  307. },
  308. /** 查询小区下拉 */
  309. getAreas() {
  310. this.builds = []
  311. this.units = []
  312. getAreas().then(res => {
  313. this.areas = res.data;
  314. });
  315. },
  316. // 取消按钮
  317. cancel() {
  318. this.open = false;
  319. this.builds = []
  320. this.units = []
  321. this.reset();
  322. },
  323. // 表单重置
  324. reset() {
  325. this.form = {
  326. id: undefined,
  327. areaId: undefined,
  328. buildingId: undefined,
  329. unitId: undefined,
  330. name: undefined,
  331. remark: undefined,
  332. delFlag: 0,
  333. createBy: undefined,
  334. createTime: undefined,
  335. updateBy: undefined,
  336. updateTime: undefined
  337. };
  338. this.resetForm("form");
  339. },
  340. /** 搜索按钮操作 */
  341. handleQuery() {
  342. this.queryParams.pageNum = 1;
  343. // this.builds = []
  344. // this.units = []
  345. this.getList();
  346. },
  347. /** 重置按钮操作 */
  348. resetQuery() {
  349. this.queryParams= {
  350. pageNum: 1,
  351. pageSize: 10,
  352. areaId: undefined,
  353. buildingId: undefined,
  354. unitId: undefined,
  355. name: undefined,
  356. };
  357. this.builds = []
  358. this.units = []
  359. this.resetForm("queryForm");
  360. this.handleQuery();
  361. },
  362. // 多选框选中数据
  363. handleSelectionChange(selection) {
  364. this.ids = selection.map(item => item.id)
  365. this.single = selection.length !== 1
  366. this.multiple = !selection.length
  367. },
  368. /** 新增按钮操作 */
  369. handleAdd() {
  370. this.reset();
  371. this.open = true;
  372. this.title = "添加房间管理";
  373. },
  374. /** 修改按钮操作 */
  375. handleUpdate(row) {
  376. this.loading = true;
  377. this.reset();
  378. const id = row.id || this.ids
  379. getHouse(id).then(response => {
  380. getBuildings(response.data.areaId).then(res => {
  381. this.builds = res.data
  382. })
  383. getUnits(response.data.buildingId).then(res => {
  384. this.units = res.data
  385. })
  386. this.loading = false;
  387. this.form = response.data;
  388. this.open = true;
  389. this.title = "修改房间管理";
  390. });
  391. },
  392. /** 提交按钮 */
  393. submitForm() {
  394. this.$refs["form"].validate(valid => {
  395. if (valid) {
  396. this.buttonLoading = true;
  397. if (this.form.id != null) {
  398. updateHouse(this.form).then(response => {
  399. this.$modal.msgSuccess("修改成功");
  400. this.open = false;
  401. this.getList();
  402. }).finally(() => {
  403. this.buttonLoading = false;
  404. this.builds = []
  405. this.units = []
  406. });
  407. } else {
  408. addHouse(this.form).then(response => {
  409. this.$modal.msgSuccess("新增成功");
  410. this.open = false;
  411. this.getList();
  412. }).finally(() => {
  413. this.buttonLoading = false;
  414. this.builds = []
  415. this.units = []
  416. });
  417. }
  418. }
  419. });
  420. },
  421. /** 删除按钮操作 */
  422. handleDelete(row) {
  423. const ids = row.id || this.ids;
  424. this.$modal.confirm('是否确认删除房间管理编号为"' + ids + '"的数据项?').then(() => {
  425. this.loading = true;
  426. return delHouse(ids);
  427. }).then(() => {
  428. this.loading = false;
  429. this.getList();
  430. this.$modal.msgSuccess("删除成功");
  431. }).catch(() => {
  432. }).finally(() => {
  433. this.loading = false;
  434. });
  435. },
  436. /** 导出按钮操作 */
  437. handleExport() {
  438. this.download('zdsz/house/export', {
  439. ...this.queryParams
  440. }, `house_${new Date().getTime()}.xlsx`)
  441. }
  442. }
  443. };
  444. </script>