building.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <basic-container style="width:100%;height:100%">
  3. <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList"
  4. :before-open="beforeOpen" v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
  5. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  6. @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
  7. <template slot="menuLeft">
  8. <el-button type="danger" size="small" icon="el-icon-delete" plain v-if="permission.doctor_delete"
  9. @click="handleDelete">删 除
  10. </el-button>
  11. </template>
  12. </avue-crud>
  13. <!-- tree新增 -->
  14. <el-dialog :modal-append-to-body="true" :append-to-body="true" title="新增楼栋" :destroy-on-close="true" :center="true"
  15. :visible.sync="addShow" width="45%" :close-on-click-modal="false" top="4%">
  16. <avue-form ref="avueForm" :option="option" v-model="addForm" @submit="addSubmit"></avue-form>
  17. </el-dialog>
  18. </basic-container>
  19. </template>
  20. <script>
  21. import {
  22. getList,
  23. getDetail,
  24. add,
  25. update,
  26. remove,
  27. removeAll
  28. } from "@/api/community/building";
  29. import {
  30. mapGetters
  31. } from "vuex";
  32. import {
  33. validatePhone
  34. } from "@/util/validator.js";
  35. let _this;
  36. export default {
  37. inject: ['agencymng', 'index'],
  38. watch: {
  39. 'agencymng.residentialId': {
  40. handler: (value) => {
  41. _this.refreshChange()
  42. },
  43. deep: true
  44. }
  45. },
  46. created() {
  47. _this = this
  48. },
  49. data() {
  50. return {
  51. addShow: false,
  52. addForm: {},
  53. form: {},
  54. query: {},
  55. loading: true,
  56. page: {
  57. pageSize: 10,
  58. currentPage: 1,
  59. total: 0
  60. },
  61. selectionList: [],
  62. option: {
  63. editBtnText: '确认',
  64. dialogWidth: '46%',
  65. searchMenuSpan: 5,
  66. labelWidth: 120,
  67. align: "center",
  68. height: '500px',
  69. calcHeight: 10,
  70. tip: false,
  71. searchShow: true,
  72. searchMenuSpan: 6,
  73. border: true,
  74. index: false,
  75. viewBtn: true,
  76. selection: false,
  77. menu: false,
  78. searchShow: false,
  79. dialogClickModal: false,
  80. viewTitle: '',
  81. addTitle: '',
  82. editTitle: '',
  83. column: [{
  84. label: "楼栋名称",
  85. prop: "name",
  86. rules: [{
  87. required: true,
  88. message: "请输入楼栋名称",
  89. trigger: "blur"
  90. }]
  91. },
  92. {
  93. label: "所属区域",
  94. prop: "residentialName",
  95. disabled: true
  96. },
  97. {
  98. label: "所属区域",
  99. prop: "residentialId",
  100. slot: true,
  101. type: "select",
  102. search: true,
  103. display: false,
  104. hide: true,
  105. searchFilterable: true,
  106. // cascaderItem: ['buildingId'],
  107. dicUrl: "/api/cyzh-community/residential/select?size=100",
  108. // dicFormatter:(res)=>{
  109. // return res.data.records;//返回字典的层级结构
  110. // },
  111. // dicFlag: false,
  112. // filterable: true,
  113. props: {
  114. label: "name",
  115. value: "id"
  116. },
  117. rules: [{
  118. required: true,
  119. message: "请选择所属区域",
  120. trigger: "blur"
  121. }]
  122. },
  123. {
  124. label: "图片",
  125. prop: "pic",
  126. type: 'upload',
  127. // dataType: 'string',
  128. hide: true,
  129. propsHttp: {
  130. res: "data",
  131. url: 'link'
  132. },
  133. listType: 'picture-img',
  134. span: 24,
  135. row: true,
  136. // value: "/img/default/building.png",
  137. action: "/api/blade-resource/oss/endpoint/put-file",
  138. rules: [{
  139. required: false,
  140. message: "请上传封面图片",
  141. trigger: "blur"
  142. }]
  143. },
  144. {
  145. label: "单元数",
  146. prop: "unitCount",
  147. display: false,
  148. rules: [{
  149. required: false,
  150. message: "请输入",
  151. trigger: "blur"
  152. }]
  153. },
  154. {
  155. label: "楼层数",
  156. prop: "floorCount",
  157. display: false,
  158. rules: [{
  159. required: false,
  160. message: "请输入",
  161. trigger: "blur"
  162. }]
  163. },
  164. {
  165. label: "房间数",
  166. prop: "roomCount",
  167. display: false,
  168. rules: [{
  169. required: false,
  170. message: "请输入",
  171. trigger: "blur"
  172. }]
  173. },
  174. {
  175. label: "总人口数",
  176. prop: "userCount",
  177. display: false,
  178. hide: true,
  179. rules: [{
  180. required: false,
  181. message: "请输入",
  182. trigger: "blur"
  183. }]
  184. },
  185. ]
  186. },
  187. data: []
  188. };
  189. },
  190. computed: {
  191. ...mapGetters(["permission"]),
  192. permissionList() {
  193. return {
  194. addBtn: this.vaildData(this.permission.doctor_add, false),
  195. viewBtn: this.vaildData(this.permission.doctor_view, false),
  196. delBtn: this.vaildData(this.permission.doctor_delete, false),
  197. editBtn: this.vaildData(this.permission.doctor_edit, false)
  198. };
  199. },
  200. ids() {
  201. let ids = [];
  202. this.selectionList.forEach(ele => {
  203. ids.push(ele.id);
  204. });
  205. return ids.join(",");
  206. }
  207. },
  208. methods: {
  209. //树的crud
  210. showAdd(row) {
  211. this.addForm = {
  212. residentialId: row.id,
  213. residentialName: row.name
  214. }
  215. this.addShow = true
  216. },
  217. async addSubmit(row, done, loading) {
  218. let flag = await this.rowSave(row, done, loading)
  219. this.addShow = false
  220. },
  221. showDetail(row) {
  222. this.option.viewTitle = `查看【${row.name}】`
  223. this.$refs.crud.rowView(row)
  224. },
  225. showEdit(row) {
  226. this.isTreeAdd = false
  227. this.option.editTitle = `编辑【${row.name}】`
  228. this.$refs.crud.rowEdit(row)
  229. },
  230. delConfirm(id) {
  231. removeAll(id).then(res => {
  232. return res.data.success
  233. })
  234. },
  235. //树的crud
  236. async rowSave(row, done, loading) {
  237. let res = await add(row)
  238. let flag = res.data.success
  239. if (flag) {
  240. this.onLoad(this.page);
  241. this.$message({
  242. type: "success",
  243. message: "操作成功!"
  244. });
  245. done();
  246. } else {
  247. loading();
  248. window.console.log(error);
  249. }
  250. return flag
  251. },
  252. rowUpdate(row, index, done, loading) {
  253. update(row).then(() => {
  254. this.index.reload()
  255. this.onLoad(this.page);
  256. this.$message({
  257. type: "success",
  258. message: "操作成功!"
  259. });
  260. done();
  261. }, error => {
  262. loading();
  263. });
  264. },
  265. rowDel(row) {
  266. this.$confirm("确定将选择数据删除?", {
  267. confirmButtonText: "确定",
  268. cancelButtonText: "取消",
  269. type: "warning"
  270. })
  271. .then(() => {
  272. return remove(row.id);
  273. })
  274. .then(() => {
  275. this.onLoad(this.page);
  276. this.$message({
  277. type: "success",
  278. message: "操作成功!"
  279. });
  280. });
  281. },
  282. handleDelete() {
  283. if (this.selectionList.length === 0) {
  284. this.$message.warning("请选择至少一条数据");
  285. return;
  286. }
  287. this.$confirm("确定将选择数据删除?", {
  288. confirmButtonText: "确定",
  289. cancelButtonText: "取消",
  290. type: "warning"
  291. })
  292. .then(() => {
  293. return remove(this.ids);
  294. })
  295. .then(() => {
  296. this.onLoad(this.page);
  297. this.$message({
  298. type: "success",
  299. message: "操作成功!"
  300. });
  301. this.$refs.crud.toggleSelection();
  302. });
  303. },
  304. beforeOpen(done, type) {
  305. if (["edit", "view"].includes(type)) {
  306. getDetail(this.form.id).then(res => {
  307. this.form = res.data.data;
  308. });
  309. }
  310. done();
  311. },
  312. searchReset() {
  313. this.query = {};
  314. this.onLoad(this.page);
  315. },
  316. searchChange(params, done) {
  317. this.query = params;
  318. this.page.currentPage = 1;
  319. this.onLoad(this.page, params);
  320. done();
  321. },
  322. selectionChange(list) {
  323. this.selectionList = list;
  324. },
  325. selectionClear() {
  326. this.selectionList = [];
  327. this.$refs.crud.toggleSelection();
  328. },
  329. currentChange(currentPage) {
  330. this.page.currentPage = currentPage;
  331. },
  332. sizeChange(pageSize) {
  333. this.page.pageSize = pageSize;
  334. },
  335. refreshChange() {
  336. this.onLoad(this.page, this.query);
  337. },
  338. onLoad(page, params = {}) {
  339. let residentialId = this.agencymng.residentialId
  340. if (this.$isEmpty(residentialId)) {
  341. return
  342. }
  343. console.log("加载楼栋");
  344. this.loading = true;
  345. this.query.residentialId = this.agencymng.residentialId
  346. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  347. const data = res.data.data;
  348. this.page.total = data.total;
  349. this.data = data.records;
  350. this.loading = false;
  351. this.selectionClear();
  352. this.$emit('getList', this.data)
  353. });
  354. }
  355. }
  356. };
  357. </script>
  358. <style>
  359. </style>