index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--地址数据-->
  5. <el-col :span="4" :xs="24" class="treeBox">
  6. <div class="head-container">
  7. <el-input
  8. v-model="addrName"
  9. placeholder="请输入地址名称"
  10. clearable
  11. size="small"
  12. prefix-icon="el-icon-search"
  13. style="margin-bottom: 20px"
  14. />
  15. </div>
  16. <div class="head-container">
  17. <el-tree
  18. :data="addrOptions"
  19. :props="defaultProps"
  20. :expand-on-click-node="false"
  21. :filter-node-method="filterNode"
  22. :accordion="true"
  23. ref="tree"
  24. highlight-current
  25. @node-click="handleNodeClick"
  26. />
  27. </div>
  28. </el-col>
  29. <!--用户数据-->
  30. <el-col :span="20" :xs="24">
  31. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  32. <el-form-item label="单元" prop="unit">
  33. <el-input
  34. v-model="queryParams.unit"
  35. placeholder="请输入单元"
  36. clearable
  37. @keyup.enter.native="handleQuery"
  38. />
  39. </el-form-item>
  40. <el-form-item label="楼层" prop="floor">
  41. <el-input
  42. v-model="queryParams.floor"
  43. placeholder="请输入楼层"
  44. clearable
  45. @keyup.enter.native="handleQuery"
  46. />
  47. </el-form-item>
  48. <el-form-item label="门牌号" prop="number">
  49. <el-input
  50. v-model="queryParams.number"
  51. placeholder="请输入门牌号"
  52. clearable
  53. @keyup.enter.native="handleQuery"
  54. />
  55. </el-form-item>
  56. <el-form-item>
  57. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  58. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  59. </el-form-item>
  60. </el-form>
  61. <el-row :gutter="10" class="mb8">
  62. <el-col :span="1.5">
  63. <el-button
  64. type="primary"
  65. plain
  66. icon="el-icon-plus"
  67. size="mini"
  68. @click="handleAdd"
  69. v-hasPermi="['community:house:add']"
  70. >新增</el-button>
  71. </el-col>
  72. </el-row>
  73. <el-table v-loading="loading" :data="houseList" @selection-change="handleSelectionChange">
  74. <el-table-column type="selection" width="55" align="center" />
  75. <el-table-column label="小区" align="center" prop="estate.name" />
  76. <el-table-column label="楼栋" align="center" prop="building.number" />
  77. <el-table-column label="单元" align="center" prop="unit" />
  78. <el-table-column label="楼层" align="center" prop="floor" />
  79. <el-table-column label="门牌号" align="center" prop="number" />
  80. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  81. <template slot-scope="scope">
  82. <el-button
  83. size="mini"
  84. type="text"
  85. icon="el-icon-edit"
  86. @click="handleUpdate(scope.row)"
  87. v-hasPermi="['community:house:edit']"
  88. >修改</el-button>
  89. <el-button
  90. size="mini"
  91. type="text"
  92. icon="el-icon-delete"
  93. @click="handleDelete(scope.row)"
  94. v-hasPermi="['community:house:remove']"
  95. >删除</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <pagination
  100. v-show="total>0"
  101. :total="total"
  102. :page.sync="queryParams.pageNum"
  103. :limit.sync="queryParams.pageSize"
  104. @pagination="getList"
  105. />
  106. </el-col>
  107. </el-row>
  108. <!-- 添加或修改住宅管理对话框 -->
  109. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  110. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  111. <el-form-item label="楼栋" prop="buildingId">
  112. <el-select v-model="form.buildingId" placeholder="请选择楼栋" :style="{width: '100%'}">
  113. <el-option v-for="(b, index) in buildingOptions" :key="index" :label="b.number" :value="b.buildingId">
  114. </el-option>
  115. </el-select>
  116. </el-form-item>
  117. <el-form-item label="单元" prop="unit">
  118. <el-input v-model="form.unit" placeholder="请输入单元" />
  119. </el-form-item>
  120. <el-form-item label="楼层" prop="floor">
  121. <el-input v-model="form.floor" placeholder="请输入楼层" />
  122. </el-form-item>
  123. <el-form-item label="门牌号" prop="number">
  124. <el-input v-model="form.number" placeholder="请输入门牌号" />
  125. </el-form-item>
  126. </el-form>
  127. <div slot="footer" class="dialog-footer">
  128. <el-button type="primary" @click="submitForm">确 定</el-button>
  129. <el-button @click="cancel">取 消</el-button>
  130. </div>
  131. </el-dialog>
  132. </div>
  133. </template>
  134. <script>
  135. import { listHouse, getHouse, delHouse, addHouse, updateHouse } from "@/api/community/house";
  136. import { listBuilding, getBuilding } from "@/api/community/building";
  137. import { addrTreeSelect } from "@/api/community/addr";
  138. import Treeselect from "@riophae/vue-treeselect";
  139. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  140. export default {
  141. name: "House",
  142. components: { Treeselect },
  143. data() {
  144. return {
  145. // 遮罩层
  146. loading: true,
  147. // 选中数组
  148. ids: [],
  149. // 非单个禁用
  150. single: true,
  151. // 非多个禁用
  152. multiple: true,
  153. // 显示搜索条件
  154. showSearch: true,
  155. // 总条数
  156. total: 0,
  157. // 住宅管理表格数据
  158. houseList: [],
  159. // 弹出层标题
  160. title: "",
  161. // 地址树选项
  162. addrOptions: undefined,
  163. // 地址名称
  164. addrName: undefined,
  165. // 地址类型
  166. addrType: undefined,
  167. // 楼栋列表
  168. buildingOptions: undefined,
  169. // 是否显示弹出层
  170. open: false,
  171. // 查询参数
  172. queryParams: {
  173. pageNum: 1,
  174. pageSize: 10,
  175. unit: null,
  176. floor: null,
  177. number: null,
  178. buildingId: null,
  179. estateId: null,
  180. deptId: null
  181. },
  182. // 楼栋查询参数
  183. queryBuildingParams:{
  184. pageNum: 1,
  185. pageSize: 10,
  186. buildingId: null,
  187. number: null,
  188. linkman: null,
  189. phone: null,
  190. estateId: null,
  191. deptId: null
  192. },
  193. // 表单参数
  194. form: {},
  195. // 表单校验
  196. rules: {
  197. },
  198. defaultProps: {}
  199. };
  200. },
  201. watch: {
  202. // 根据名称筛选地址树
  203. addrName(val) {
  204. this.$refs.tree.filter(val);
  205. }
  206. },
  207. created() {
  208. this.getList();
  209. this.getAddrTree();
  210. },
  211. methods: {
  212. /** 查询住宅列表 */
  213. getList() {
  214. this.loading = true;
  215. listHouse(this.queryParams).then(response => {
  216. this.houseList = response.rows;
  217. this.total = response.total;
  218. this.loading = false;
  219. });
  220. },
  221. /** 查询地址下拉树结构 */
  222. getAddrTree() {
  223. addrTreeSelect(this.queryParams).then(response => {
  224. this.addrOptions = response.data;
  225. });
  226. },
  227. // 筛选节点
  228. filterNode(value, data) {
  229. if (!value) return true;
  230. return data.label.indexOf(value) !== -1;
  231. },
  232. // 节点单击事件
  233. handleNodeClick(data) {
  234. // TODO : 应改为在后端依据type和interId处理
  235. this.addrType = data.type;
  236. if(data.type=="street" || data.type=="community" || data.type=="grid"){
  237. // 查询所有住宅
  238. this.queryParams.deptId = null;
  239. this.queryBuildingParams.deptId = null;
  240. this.queryParams.estateId = null;
  241. this.queryBuildingParams.estateId = null;
  242. this.queryParams.buildingId = null;
  243. this.queryBuildingParams.buildingId = null;
  244. }else if(data.type=="estate"){
  245. // 按小区Id查询
  246. this.queryParams.estateId = data.interId;
  247. this.queryBuildingParams.estateId = data.interId;
  248. this.queryParams.buildingId = null;
  249. this.queryBuildingParams.buildingId = null;
  250. }else if(data.type=="building"){
  251. // 按楼栋Id查询
  252. this.queryParams.estateId = null;
  253. this.queryBuildingParams.estateId = null;
  254. this.queryParams.buildingId = data.interId;
  255. this.queryBuildingParams.buildingId = data.interId;
  256. }else{
  257. //this.queryParams.addrId = data.id;
  258. }
  259. this.handleQuery();
  260. },
  261. // 取消按钮
  262. cancel() {
  263. this.open = false;
  264. this.reset();
  265. },
  266. // 表单重置
  267. reset() {
  268. this.form = {
  269. houseId: null,
  270. unit: null,
  271. floor: null,
  272. number: null,
  273. buildingId: null,
  274. estateId: null,
  275. deptId: null
  276. };
  277. this.resetForm("form");
  278. },
  279. /** 搜索按钮操作 */
  280. handleQuery() {
  281. this.queryParams.pageNum = 1;
  282. this.getList();
  283. },
  284. /** 重置按钮操作 */
  285. resetQuery() {
  286. this.resetForm("queryForm");
  287. this.handleQuery();
  288. },
  289. // 多选框选中数据
  290. handleSelectionChange(selection) {
  291. this.ids = selection.map(item => item.houseId)
  292. this.single = selection.length!==1
  293. this.multiple = !selection.length
  294. },
  295. /** 新增按钮操作 */
  296. handleAdd() {
  297. this.reset();
  298. this.buildingOptions = null;
  299. if(this.addrType == "estate" || this.addrType == "building"){
  300. listBuilding({ ...this.queryBuildingParams, pageEnable: false }).then(response => {
  301. this.buildingOptions = response.rows;
  302. });
  303. this.open = true;
  304. this.title = "添加住宅管理";
  305. }else{
  306. this.$alert('请先选择小区或楼栋', '提示:', {confirmButtonText: '确定'});
  307. }
  308. },
  309. /** 修改按钮操作 */
  310. handleUpdate(row) {
  311. this.reset();
  312. const houseId = row.houseId || this.ids
  313. getHouse(houseId).then(response => {
  314. this.form = response.data;
  315. this.queryBuildingParams.estateId = row.estateId;
  316. listBuilding(this.queryBuildingParams).then(response => {
  317. this.buildingOptions = response.rows;
  318. });
  319. this.open = true;
  320. this.title = "修改住宅管理";
  321. });
  322. },
  323. /** 提交按钮 */
  324. submitForm() {
  325. this.$refs["form"].validate(valid => {
  326. if (valid) {
  327. var data= this.buildingOptions.find((item) => item.buildingId == this.form.buildingId);
  328. this.form.estateId = data.estateId;
  329. this.form.deptId = data.deptId;
  330. if (this.form.houseId != null) {
  331. updateHouse(this.form).then(response => {
  332. this.$modal.msgSuccess("修改成功");
  333. this.open = false;
  334. this.getList();
  335. });
  336. } else {
  337. addHouse(this.form).then(response => {
  338. this.$modal.msgSuccess("新增成功");
  339. this.open = false;
  340. this.getList();
  341. });
  342. }
  343. }
  344. });
  345. },
  346. /** 删除按钮操作 */
  347. handleDelete(row) {
  348. const houseIds = row.houseId || this.ids;
  349. this.$modal.confirm('是否确认删除住宅管理编号为"' + houseIds + '"的数据项?').then(function() {
  350. return delHouse(houseIds);
  351. }).then(() => {
  352. this.getList();
  353. this.$modal.msgSuccess("删除成功");
  354. }).catch(() => {});
  355. },
  356. /** 导出按钮操作 */
  357. handleExport() {
  358. this.download('community/house/export', {
  359. ...this.queryParams
  360. }, `house_${new Date().getTime()}.xlsx`)
  361. }
  362. }
  363. };
  364. </script>
  365. <style scoped>
  366. .treeBox {
  367. height: 80vh;
  368. overflow-y: auto;
  369. }
  370. ::-webkit-scrollbar {
  371. width: 1px;
  372. background-color: skyblue;
  373. }
  374. ::-webkit-scrollbar-thumb {
  375. background-color: orange;
  376. }
  377. </style>