doordevice.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page="page"
  7. :permission="permissionList"
  8. :before-open="beforeOpen"
  9. v-model="form"
  10. ref="crud"
  11. @row-update="rowUpdate"
  12. @row-save="rowSave"
  13. @row-del="rowDel"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad">
  21. <template slot="menuLeft">
  22. <el-button type="danger"
  23. size="small"
  24. icon="el-icon-delete"
  25. plain
  26. v-if="permission.facedevice_delete"
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. <template slot="mapSelectForm" slot-scope="scope">
  31. <!-- <avue-map v-model="scope.row.mapSelect"></avue-map> -->
  32. <div>
  33. <el-button @click="mapVisible = true">选择地址</el-button>
  34. <el-dialog :append-to-body="true" :close-on-click-modal="false" :modal-append-to-body="false" :visible.sync="mapVisible"
  35. title="编辑地址" width="80%">
  36. <!-- <customAvueMap v-if="mapVisible" v-model="scope.row.mapSelect"></customAvueMap>-->
  37. <editPolygonMap v-if="mapVisible" :editForm.sync="scope.row" :region.sync="scope.row.address" :latitude.sync="scope.row.latitude" :longitude.sync="scope.row.longitude" :visible.sync="mapVisible"></editPolygonMap>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <template slot="residentialId" slot-scope="scope">{{scope.row.residentialName}}</template>
  42. <template slot="residentialIdForm" slot-scope="scope">
  43. <select-dialog-residential :id="form.residentialId" :name="form.residentialName" :callback="selectCallback"></select-dialog-residential>
  44. </template>
  45. </avue-crud>
  46. </basic-container>
  47. </template>
  48. <script>
  49. import {getList, getDetail, add, update, remove} from "../../api/device/doordevice.js";
  50. import {mapGetters} from "vuex";
  51. import customAvueMap from "../../components/residential/customAvueMap.vue"
  52. import editPolygonMap from "../../components/residential/editPolygonMap.vue";
  53. import SelectDialogResidential from "../../components/select-dialog/select-dialog-residential";
  54. export default {
  55. components:{
  56. SelectDialogResidential,
  57. customAvueMap,editPolygonMap
  58. },
  59. data() {
  60. return {
  61. mapVisible:false,
  62. form: {},
  63. query: {},
  64. loading: true,
  65. page: {
  66. pageSize: 10,
  67. currentPage: 1,
  68. total: 0
  69. },
  70. selectionList: [],
  71. option: {
  72. height:'auto',
  73. calcHeight: 60,
  74. tip: false,
  75. searchShow: true,
  76. searchMenuSpan: 6,
  77. border: true,
  78. index: true,
  79. viewBtn: true,
  80. selection: true,
  81. dialogClickModal: false,
  82. menuWidth:350,
  83. column: [
  84. {
  85. label: "名称",
  86. prop: "name",
  87. search: true,
  88. overHidden: true,
  89. rules: [{
  90. required: true,
  91. message: "请输入名称",
  92. trigger: "blur"
  93. }]
  94. },
  95. {
  96. label: "Mac编码",
  97. prop: "macAddress",
  98. width: 200,
  99. rules: [{
  100. required: true,
  101. message: "请输入Mac编码",
  102. trigger: "blur"
  103. }]
  104. },
  105. {
  106. label: "所属小区",
  107. prop: "residentialId",
  108. dicFlag: true,
  109. type: "select",
  110. search: true,
  111. searchFilterable: true,
  112. slot: true,
  113. formslot: true,
  114. dataType: "number",
  115. dicUrl: "/api/cyzh-community/residential/list?size=500&name={{key}}",
  116. dicFormatter:(res)=>{
  117. return res.data.records;//返回字典的层级结构
  118. },
  119. props: {
  120. label: "name",
  121. value: "id"
  122. },
  123. rules: [{
  124. required: true,
  125. message: "请选择所属小区",
  126. trigger: "blur"
  127. }],
  128. },
  129. {
  130. label: "具体地址",
  131. prop: "address",
  132. width: 350,
  133. search: true,
  134. overHidden: true,
  135. rules: [{
  136. required: true,
  137. message: "请输入具体地址",
  138. trigger: "blur"
  139. }]
  140. },
  141. {
  142. label: "设备状态",
  143. prop: "deviceStatus",
  144. type: "select",
  145. hide: true,
  146. dicUrl:"/api/blade-system/dict-biz/dictionary?code=face_device_status",
  147. props: {
  148. label: 'dictValue',
  149. value: 'dictKey'
  150. },
  151. dataType: "number",
  152. rules: [{
  153. required: true,
  154. message: "请输入设备状态:离线 异常",
  155. trigger: "blur"
  156. }],
  157. display: false
  158. },
  159. {
  160. label:'',
  161. prop:'mapSelect',
  162. // row: true,
  163. // span: 20,
  164. viewDisplay: false,
  165. formslot: true,
  166. hide: true,
  167. },
  168. {
  169. label: "经度",
  170. prop: "longitude",
  171. width: 100,
  172. overHidden: true,
  173. hide:true,
  174. rules: [{
  175. required: true,
  176. message: "请输入经度",
  177. trigger: "blur"
  178. }]
  179. },
  180. {
  181. label: "纬度",
  182. prop: "latitude",
  183. width: 100,
  184. overHidden: true,
  185. hide:true,
  186. rules: [{
  187. required: true,
  188. message: "请输入纬度",
  189. trigger: "blur"
  190. }]
  191. },
  192. // {
  193. // label: "门禁设备",
  194. // prop: "id",
  195. // hide: true,
  196. // display:false,
  197. // rules: [{
  198. // required: true,
  199. // message: "请输入门禁设备",
  200. // trigger: "blur"
  201. // }]
  202. // },
  203. // {
  204. // label: "设备厂商",
  205. // prop: "deviceFactory",
  206. // type: "select",
  207. // dicUrl: "/api/blade-system/dict-biz/dictionary?code=door_device_factory",
  208. // props:{
  209. // label: "dictValue",
  210. // value: "dictKey"
  211. // },
  212. // width: 135,
  213. // rules: [{
  214. // required: true,
  215. // message: "请输入设备编号",
  216. // trigger: "blur"
  217. // }]
  218. // },
  219. // {
  220. // label: "所属省",
  221. // prop: "provinceCode",
  222. // // hide: true,
  223. // width: 150,
  224. // type: "select",
  225. // dicUrl: "/api/blade-system/region/lazy-tree?parentCode=000000",
  226. // cascaderItem:["cityCode"],
  227. // props:{
  228. // label:"title",
  229. // value: "id"
  230. // },
  231. // rules: [{
  232. // required: true,
  233. // message: "请输入省行政编码",
  234. // trigger: "blur"
  235. // }]
  236. // },
  237. // {
  238. // label: "所属市",
  239. // prop: "cityCode",
  240. // hide: true,
  241. // type: "select",
  242. // width: 150,
  243. // cascaderItem: ["areaCode"],
  244. // dicUrl: `/api/blade-system/region/lazy-tree?parentCode={{key}}`,
  245. // props:{
  246. // label: "title",
  247. // value: "id"
  248. // },
  249. // dicFlag: true,
  250. // rules: [{
  251. // required: true,
  252. // message: "请输入市行政编码",
  253. // trigger: "blur"
  254. // }]
  255. // },
  256. // {
  257. // label: "所属区",
  258. // prop: "areaCode",
  259. // type: "select",
  260. // width: 150,
  261. // dicFlag: true,
  262. // cascaderItem: ["residentialId"],
  263. // dicUrl: `/api/blade-system/region/lazy-tree?parentCode={{key}}`,
  264. // props:{
  265. // label: "title",
  266. // value: "id"
  267. // },
  268. // rules: [{
  269. // required: true,
  270. // message: "请输入区行政编码",
  271. // trigger: "blur"
  272. // }]
  273. // },
  274. ]
  275. },
  276. data: []
  277. };
  278. },
  279. computed: {
  280. ...mapGetters(["permission"]),
  281. permissionList() {
  282. return {
  283. addBtn: this.vaildData(this.permission.doordevice_add, false),
  284. viewBtn: this.vaildData(this.permission.doordevice_view, false),
  285. delBtn: this.vaildData(this.permission.doordevice_delete, false),
  286. editBtn: this.vaildData(this.permission.doordevice_edit, false)
  287. };
  288. },
  289. ids() {
  290. let ids = [];
  291. this.selectionList.forEach(ele => {
  292. ids.push(ele.id);
  293. });
  294. return ids.join(",");
  295. }
  296. },
  297. watch: {
  298. 'form.mapSelect': {
  299. handler: function(value) {
  300. if (!value){
  301. return
  302. }else{
  303. this.form.longitude = this.form.mapSelect.longitude;
  304. this.form.latitude = this.form.mapSelect.latitude;
  305. }
  306. },
  307. }
  308. },
  309. created() {
  310. const tenantType = localStorage.getItem("tenantType");
  311. if (tenantType == 0){
  312. this.option.column[2].label = "所属小区"
  313. }else if (tenantType == 1){
  314. this.option.column[2].label = "所属区域"
  315. }
  316. },
  317. /*mounted() {
  318. let tenantType = localStorage.getItem("tenantType");
  319. const residentialColumn = this.findObject(this.option.column, "residentialId");
  320. if (tenantType == 1) { //园区
  321. residentialColumn.label = "所属区域";
  322. } else { //社区
  323. residentialColumn.label = "所属小区";
  324. }
  325. },*/
  326. methods: {
  327. selectCallback(row){
  328. this.form.residentialId = row.id;
  329. this.form.residentialName = row.name;
  330. },
  331. rowSave(row, done, loading) {
  332. add(row).then(() => {
  333. this.onLoad(this.page);
  334. this.$message({
  335. type: "success",
  336. message: "操作成功!"
  337. });
  338. done();
  339. }, error => {
  340. loading();
  341. window.console.log(error);
  342. });
  343. },
  344. rowUpdate(row, index, done, loading) {
  345. update(row).then(() => {
  346. this.onLoad(this.page);
  347. this.$message({
  348. type: "success",
  349. message: "操作成功!"
  350. });
  351. done();
  352. }, error => {
  353. loading();
  354. console.log(error);
  355. });
  356. },
  357. rowDel(row) {
  358. this.$confirm("确定将选择数据删除?", {
  359. confirmButtonText: "确定",
  360. cancelButtonText: "取消",
  361. type: "warning"
  362. })
  363. .then(() => {
  364. return remove(row.id);
  365. })
  366. .then(() => {
  367. this.onLoad(this.page);
  368. this.$message({
  369. type: "success",
  370. message: "操作成功!"
  371. });
  372. });
  373. },
  374. handleDelete() {
  375. if (this.selectionList.length === 0) {
  376. this.$message.warning("请选择至少一条数据");
  377. return;
  378. }
  379. this.$confirm("确定将选择数据删除?", {
  380. confirmButtonText: "确定",
  381. cancelButtonText: "取消",
  382. type: "warning"
  383. })
  384. .then(() => {
  385. return remove(this.ids);
  386. })
  387. .then(() => {
  388. this.onLoad(this.page);
  389. this.$message({
  390. type: "success",
  391. message: "操作成功!"
  392. });
  393. this.$refs.crud.toggleSelection();
  394. });
  395. },
  396. beforeOpen(done, type) {
  397. if (["edit", "view"].includes(type)) {
  398. getDetail(this.form.id).then(res => {
  399. this.form = res.data.data;
  400. });
  401. }
  402. done();
  403. },
  404. searchReset() {
  405. this.query = {};
  406. this.onLoad(this.page);
  407. },
  408. searchChange(params, done) {
  409. this.query = params;
  410. this.page.currentPage = 1;
  411. this.onLoad(this.page, params);
  412. done();
  413. },
  414. selectionChange(list) {
  415. this.selectionList = list;
  416. },
  417. selectionClear() {
  418. this.selectionList = [];
  419. this.$refs.crud.toggleSelection();
  420. },
  421. currentChange(currentPage){
  422. this.page.currentPage = currentPage;
  423. },
  424. sizeChange(pageSize){
  425. this.page.pageSize = pageSize;
  426. },
  427. refreshChange() {
  428. this.onLoad(this.page, this.query);
  429. },
  430. onLoad(page, params = {}) {
  431. this.loading = true;
  432. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  433. const data = res.data.data;
  434. this.page.total = data.total;
  435. this.data = data.records;
  436. this.loading = false;
  437. this.selectionClear();
  438. });
  439. }
  440. }
  441. };
  442. </script>
  443. <style>
  444. </style>