iotalarmgroup.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template>
  2. <el-row>
  3. <el-col :span="12">
  4. <basic-container>
  5. <avue-crud :option="optionParent" :table-loading="loading" :data="dataParent" :page="pageParent" :permission="permissionList"
  6. :before-open="beforeOpen" v-model="formParent" ref="crud" @row-click="handleRowClick" @row-update="rowUpdate"
  7. @row-save="rowSave" @row-del="rowDel" @search-change="searchChange" @search-reset="searchReset"
  8. @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
  9. @on-load="onLoadParent">
  10. <template slot="menuLeft">
  11. <el-button type="danger" size="small" icon="el-icon-delete" plain v-if="permission.alarmgroup_delete"
  12. @click="handleDelete">删 除
  13. </el-button>
  14. </template>
  15. <template slot="residentialId" slot-scope="scope">
  16. <div>{{scope.row.residentialName}}</div>
  17. </template>
  18. </avue-crud>
  19. </basic-container>
  20. </el-col>
  21. <el-col :span="12">
  22. <basic-container>
  23. <avue-crud :option="optionChild" :table-loading="loadingChild" :data="dataChild" :page="pageChild" :permission="permissionListChild"
  24. :before-open="beforeOpenChild" v-model="formChild" ref="crudChild" @row-update="rowUpdateChild" @row-save="rowSaveChild"
  25. @row-del="rowDelChild" @search-change="searchChangeChild" @search-reset="searchResetChild" @selection-change="selectionChangeChild"
  26. @current-change="currentChangeChild" @size-change="sizeChangeChild" @refresh-change="refreshChangeChild"
  27. @on-load="onLoadChild">
  28. <template slot="menuLeft">
  29. <el-button type="danger" size="small" icon="el-icon-delete" plain v-if="permission.alarmgroupuser_delete"
  30. @click="handleDeleteChild">删 除
  31. </el-button>
  32. </template>
  33. </avue-crud>
  34. </basic-container>
  35. </el-col>
  36. </el-row>
  37. </template>
  38. <script>
  39. import {
  40. getList,
  41. getDetail,
  42. add,
  43. update,
  44. remove
  45. } from "@/api/device/iotalarmgroup";
  46. import {
  47. getList as getUserList,
  48. getDetail as getUserDetail,
  49. add as addUser,
  50. updata as updateUser,
  51. remove as removeUser
  52. } from "@/api/device/iotalarmgroupuser";
  53. import {
  54. mapGetters
  55. } from "vuex";
  56. var DIC = {
  57. yes_no: [{
  58. label: '否',
  59. value: 0
  60. }, {
  61. label: '是',
  62. value: 1
  63. }]
  64. }
  65. export default {
  66. data() {
  67. return {
  68. formParent: {},
  69. query: {},
  70. loading: true,
  71. pageParent: {
  72. pageSize: 10,
  73. currentPage: 1,
  74. total: 0
  75. },
  76. selectionList: [],
  77. optionParent: {
  78. height: 'auto',
  79. calcHeight: 30,
  80. tip: false,
  81. searchShow: true,
  82. searchMenuSpan: 8,
  83. border: true,
  84. index: true,
  85. viewBtn: true,
  86. dialogWidth: 600,
  87. selection: true,
  88. dialogClickModal: false,
  89. menuPosition: "center",
  90. menuWidth:340,
  91. column: [{
  92. label: "组名",
  93. prop: "name",
  94. row: true,
  95. span: 20,
  96. rules: [{
  97. required: true,
  98. message: "请输入组名",
  99. trigger: "blur"
  100. }]
  101. },
  102. {
  103. label: "归属",
  104. prop: "residentialId",
  105. span: 20,
  106. row: true,
  107. type: "select",
  108. searchSpan: 12,
  109. remote: true,
  110. //回显的时候有问题,如果所选不在前十条内,下拉框只会显示id
  111. dicUrl: "/api/cyzh-community/residential/list?size=10000&name={{key}}",
  112. props: {
  113. label: "name",
  114. value: "id"
  115. },
  116. searchFilterable: true,
  117. search: true,
  118. slot: true,
  119. rules: [{
  120. required: true,
  121. message: "请输入",
  122. trigger: "blur"
  123. }]
  124. },
  125. {
  126. label: "设备类型",
  127. prop: "tag",
  128. type: "select",
  129. row: true,
  130. span: 20,
  131. dicUrl: "/api/blade-system/dict-biz/dictionary?code=iot_device_type",
  132. props: {
  133. label: "dictValue",
  134. value: "dictKey",
  135. },
  136. dataType: "number",
  137. rules: [{
  138. required: true,
  139. message: "请输入标识",
  140. trigger: "blur"
  141. }]
  142. },
  143. ]
  144. },
  145. dataParent: [],
  146. //-----------------------------------------------------------------------------------------
  147. formChild: {},
  148. loadingChild: true,
  149. pageChild: {
  150. pageSize: 10,
  151. currentPage: 1,
  152. total: 0
  153. },
  154. optionChild: {
  155. height: 'auto',
  156. calcHeight: 30,
  157. tip: false,
  158. searchShow: true,
  159. searchMenuSpan: 6,
  160. menuPosition: "center",
  161. dialogWidth: 600,
  162. border: true,
  163. index: true,
  164. viewBtn: true,
  165. selection: true,
  166. dialogClickModal: false,
  167. menuWidth:340,
  168. column: [{
  169. label: "责任人",
  170. prop: "person",
  171. row: true,
  172. span: 20,
  173. labelWidth: 120,
  174. rules: [{
  175. required: true,
  176. message: "请输入责任人",
  177. trigger: "blur"
  178. }]
  179. },
  180. {
  181. label: "责任人电话",
  182. prop: "phone",
  183. row: true,
  184. labelWidth: 120,
  185. span: 20,
  186. rules: [{
  187. required: true,
  188. message: "请输入责任人电话",
  189. trigger: "blur"
  190. }]
  191. },
  192. {
  193. label: "是否为处理人",
  194. prop: "isHandler",
  195. type: "switch",
  196. row: true,
  197. span: 20,
  198. labelWidth: 120,
  199. // dicData: DIC.yes_no,
  200. // mock: {
  201. // type: 'dic'
  202. // },
  203. dicData:[
  204. {
  205. label:'是',
  206. value:true
  207. },
  208. {
  209. label:'否',
  210. value: false
  211. }
  212. ],
  213. displayAs: 'switch',
  214. rules: [{
  215. required: false,
  216. message: "请输入是否为处理人",
  217. trigger: "blur"
  218. }]
  219. },
  220. ]
  221. },
  222. dataChild: []
  223. };
  224. },
  225. computed: {
  226. ...mapGetters(["permission"]),
  227. permissionList() {
  228. return {
  229. addBtn: this.vaildData(this.permission.iotalarmgroup_add, false),
  230. viewBtn: this.vaildData(this.permission.iotalarmgroup_view, false),
  231. delBtn: this.vaildData(this.permission.iotalarmgroup_delete, false),
  232. editBtn: this.vaildData(this.permission.iotalarmgroup_edit, false)
  233. };
  234. },
  235. permissionListChild() {
  236. return {
  237. addBtn: this.vaildData(this.permission.iotalarmgroupuser_add, false),
  238. viewBtn: this.vaildData(this.permission.iotalarmgroupuser_view, false),
  239. delBtn: this.vaildData(this.permission.iotalarmgroupuser_delete, false),
  240. editBtn: this.vaildData(this.permission.iotalarmgroupuser_edit, false)
  241. };
  242. },
  243. ids() {
  244. let ids = [];
  245. this.selectionList.forEach(ele => {
  246. ids.push(ele.id);
  247. });
  248. return ids.join(",");
  249. }
  250. },
  251. mounted() {
  252. let tenantType = localStorage.getItem("tenantType");
  253. const residentialIdColumn = this.findObject(this.optionParent.column, "residentialId");
  254. if (tenantType == 1) { //园区
  255. residentialIdColumn.label = "所属区域"
  256. } else { //社区
  257. residentialIdColumn.label = "所属小区"
  258. }
  259. },
  260. methods: {
  261. rowSave(row, done, loading) {
  262. add(row).then(() => {
  263. this.onLoadParent(this.pageParent);
  264. this.$message({
  265. type: "success",
  266. message: "操作成功!"
  267. });
  268. done();
  269. }, error => {
  270. loading();
  271. window.console.log(error);
  272. });
  273. },
  274. rowUpdate(row, index, done, loading) {
  275. update(row).then(() => {
  276. this.onLoadParent(this.pageParent);
  277. this.$message({
  278. type: "success",
  279. message: "操作成功!"
  280. });
  281. done();
  282. }, error => {
  283. loading();
  284. console.log(error);
  285. });
  286. },
  287. rowDel(row) {
  288. this.$confirm("确定将选择数据删除?", {
  289. confirmButtonText: "确定",
  290. cancelButtonText: "取消",
  291. type: "warning"
  292. })
  293. .then(() => {
  294. return remove(row.id);
  295. })
  296. .then(() => {
  297. this.onLoadParent(this.pageParent);
  298. this.$message({
  299. type: "success",
  300. message: "操作成功!"
  301. });
  302. });
  303. },
  304. handleDelete() {
  305. if (this.selectionList.length === 0) {
  306. this.$message.warning("请选择至少一条数据");
  307. return;
  308. }
  309. this.$confirm("确定将选择数据删除?", {
  310. confirmButtonText: "确定",
  311. cancelButtonText: "取消",
  312. type: "warning"
  313. })
  314. .then(() => {
  315. return remove(this.ids);
  316. })
  317. .then(() => {
  318. this.onLoadParent(this.pageParent);
  319. this.$message({
  320. type: "success",
  321. message: "操作成功!"
  322. });
  323. this.$refs.crud.toggleSelection();
  324. });
  325. },
  326. beforeOpen(done, type) {
  327. if (["edit", "view"].includes(type)) {
  328. getDetail(this.formParent.id).then(res => {
  329. this.formParent = res.data.data;
  330. });
  331. }
  332. done();
  333. },
  334. handleRowClick(row) {
  335. this.query = {};
  336. this.parentId = row.id;
  337. debugger
  338. this.dictValue = row.dictValue;
  339. this.$refs.crudChild.value.code = row.code;
  340. this.$refs.crudChild.value.parentId = row.id;
  341. // this.$refs.crudChild.option.column.filter(item => {
  342. // if (item.prop === "code") {
  343. // item.value = row.code;
  344. // }
  345. // if (item.prop === "parentId") {
  346. // item.value = row.id;
  347. // }
  348. // });
  349. this.onLoadChild(this.pageChild);
  350. },
  351. searchReset() {
  352. this.query = {};
  353. this.onLoadParent(this.pageParent);
  354. },
  355. searchChange(params, done) {
  356. this.query = params;
  357. this.pageParent.currentPage = 1;
  358. this.onLoadParent(this.pageParent, params);
  359. done();
  360. },
  361. selectionChange(list) {
  362. this.selectionList = list;
  363. },
  364. selectionClear() {
  365. this.selectionList = [];
  366. this.$refs.crud.toggleSelection();
  367. },
  368. currentChange(currentPage) {
  369. this.pageParent.currentPage = currentPage;
  370. },
  371. sizeChange(pageSize) {
  372. this.pageParent.pageSize = pageSize;
  373. },
  374. refreshChange() {
  375. this.onLoadParent(this.pageParent, this.query);
  376. },
  377. onLoadParent(page, params = {}) {
  378. this.loading = true;
  379. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  380. const data = res.data.data;
  381. this.pageParent.total = data.total;
  382. this.dataParent = data.records;
  383. if (this.dataParent.length > 0) {
  384. this.parentId = this.dataParent[0].id;
  385. this.onLoadChild(this.pageChild);
  386. }
  387. this.loading = false;
  388. this.selectionClear();
  389. });
  390. },
  391. rowSaveChild(row, done, loading) {
  392. row.groupId = this.parentId;
  393. addUser(row).then(() => {
  394. this.onLoadChild(this.pageChild);
  395. this.$message({
  396. type: "success",
  397. message: "操作成功!"
  398. });
  399. done();
  400. }, error => {
  401. loading();
  402. window.console.log(error);
  403. });
  404. },
  405. rowUpdateChild(row, index, done, loading) {
  406. // row.groupId = this.parentId;
  407. updateUser(row).then(() => {
  408. this.onLoadChild(this.pageChild);
  409. this.$message({
  410. type: "success",
  411. message: "操作成功!"
  412. });
  413. done();
  414. }, error => {
  415. loading();
  416. console.log(error);
  417. });
  418. },
  419. rowDelChild(row) {
  420. this.$confirm("确定将选择数据删除?", {
  421. confirmButtonText: "确定",
  422. cancelButtonText: "取消",
  423. type: "warning"
  424. })
  425. .then(() => {
  426. return removeUser(row.id);
  427. })
  428. .then(() => {
  429. this.onLoadChild(this.pageChild);
  430. this.$message({
  431. type: "success",
  432. message: "操作成功!"
  433. });
  434. });
  435. },
  436. handleDeleteChild() {
  437. if (this.selectionList.length === 0) {
  438. this.$message.warning("请选择至少一条数据");
  439. return;
  440. }
  441. this.$confirm("确定将选择数据删除?", {
  442. confirmButtonText: "确定",
  443. cancelButtonText: "取消",
  444. type: "warning"
  445. })
  446. .then(() => {
  447. return remove(this.ids);
  448. })
  449. .then(() => {
  450. this.onLoadChild(this.pageChild);
  451. this.$message({
  452. type: "success",
  453. message: "操作成功!"
  454. });
  455. this.$refs.crud.toggleSelection();
  456. });
  457. },
  458. beforeOpenChild(done, type) {
  459. if (["edit", "view"].includes(type)) {
  460. getUserDetail(this.formChild.id).then(res => {
  461. this.formChild = res.data.data;
  462. });
  463. }
  464. done();
  465. },
  466. searchResetChild() {
  467. this.query = {};
  468. this.onLoadChild(this.pageChild);
  469. },
  470. searchChangeChild(params, done) {
  471. this.query = params;
  472. this.pageChild.currentPage = 1;
  473. this.onLoadChild(this.pageChild, params);
  474. done();
  475. },
  476. selectionChangeChild(list) {
  477. this.selectionList = list;
  478. },
  479. selectionClearChild() {
  480. this.selectionList = [];
  481. this.$refs.crud.toggleSelection();
  482. },
  483. currentChangeChild(currentPage) {
  484. this.pageChild.currentPage = currentPage;
  485. },
  486. sizeChangeChild(pageSize) {
  487. this.pageChild.pageSize = pageSize;
  488. },
  489. refreshChangeChild() {
  490. this.onLoadChild(this.pageChild, this.query);
  491. },
  492. onLoadChild(page, params = {}) {
  493. this.loadingChild = true;
  494. params.groupId = this.parentId;
  495. getUserList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  496. const data = res.data.data;
  497. this.pageChild.total = data.total;
  498. this.dataChild = data.records;
  499. this.dataChild.forEach(item => {
  500. item.isHandler = item.isHandler == 1;
  501. })
  502. this.loadingChild = false;
  503. this.selectionClearChild();
  504. });
  505. }
  506. }
  507. };
  508. </script>
  509. <style>
  510. </style>