index.vue 14 KB

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