device-door-simple-crud.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div>
  3. <div style="display:flex;margin:6px;flex-wrap: wrap;overflow: hidden;">
  4. <el-tag size="mini" type="info" style="margin:4px" class="animate__animated animate__fadeInDown animate__faster" @close="close(item)" closable v-for="(item,index) in selectionList" :key="index">{{item.name}}</el-tag>
  5. </div>
  6. <avue-crud :option="option" :table-loading="loading" :data="data" :page="page" :permission="permissionList"
  7. :before-open="beforeOpen" v-model="form" ref="crud"
  8. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  9. @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
  10. <template slot="menuLeft">
  11. <el-button @click="pushFace" size="mini" type="primary" v-if="$isNotEmpty(selectionList)">确认下发</el-button>
  12. </template>
  13. <template slot="deviceStatus" slot-scope="{row}">
  14. <el-tag v-if="row.deviceStatus === 0" type="danger">离线</el-tag>
  15. <el-tag v-if="row.deviceStatus === 1" type="success">在线</el-tag>
  16. </template>
  17. </avue-crud>
  18. </div>
  19. </template>
  20. <script>
  21. import {
  22. getList,
  23. getDetail,
  24. add,
  25. update,
  26. remove,
  27. remoteOpenDoor
  28. } from "@/api/device/doordevice.js";
  29. import {
  30. mapGetters
  31. } from "vuex";
  32. import customAvueMap from "@/components/residential/customAvueMap.vue"
  33. import editPolygonMap from "@/components/residential/editPolygonMap.vue";
  34. import SelectDialogResidential from "@/components/select-dialog/select-dialog-residential";
  35. import {deepClone} from "@/util/util.js"
  36. export default {
  37. components: {
  38. SelectDialogResidential,
  39. customAvueMap,
  40. editPolygonMap
  41. },
  42. data() {
  43. return {
  44. mapVisible: false,
  45. form: {},
  46. query: {},
  47. loading: true,
  48. page: {
  49. pageSize: 10,
  50. currentPage: 1,
  51. total: 0
  52. },
  53. selectionList: [],
  54. option: {
  55. height: 'auto',
  56. calcHeight: 60,
  57. tip: false,
  58. searchShow: true,
  59. searchMenuSpan: 6,
  60. border: true,
  61. index: true,
  62. viewBtn: false,
  63. delBtn: false,
  64. editBtn: false,
  65. selection: true,
  66. reserveSelection: true,
  67. menu: false,
  68. addBtn: false,
  69. align: 'center',
  70. dialogClickModal: false,
  71. column: [
  72. {
  73. label: "设备名称",
  74. prop: "name",
  75. search: true,
  76. overHidden: true,
  77. rules: [{
  78. required: true,
  79. message: "请输入名称",
  80. trigger: "blur"
  81. }]
  82. },
  83. {
  84. label: "设备序列号",
  85. prop: "macAddress",
  86. hide: true,
  87. width: 200,
  88. rules: [{
  89. required: true,
  90. message: "请输入Mac编码",
  91. trigger: "blur"
  92. }]
  93. },
  94. {
  95. label: "所属区域",
  96. prop: "residentialName",
  97. width: 160,
  98. editDisplay: false,
  99. addDisplay: false
  100. },
  101. {
  102. label: "所属楼栋",
  103. prop: "buildingName",
  104. width: 100,
  105. editDisplay: false,
  106. addDisplay: false
  107. },
  108. {
  109. label: "所属单元",
  110. prop: "unitName",
  111. width: 100,
  112. editDisplay: false,
  113. addDisplay: false
  114. },
  115. {
  116. label: "所属楼层",
  117. width: 100,
  118. prop: "floorName",
  119. editDisplay: false,
  120. addDisplay: false
  121. },
  122. {
  123. label: "安装位置",
  124. prop: "address",
  125. width: 160,
  126. overHidden: true,
  127. rules: [{
  128. required: true,
  129. message: "请输入安装位置",
  130. trigger: "blur"
  131. }]
  132. },
  133. {
  134. label: "最近心跳",
  135. width: 130,
  136. prop: "heartbeatTime"
  137. },
  138. {
  139. label: "设备状态",
  140. prop: "deviceStatus",
  141. type: "select",
  142. width: 100,
  143. dicUrl: "/api/blade-system/dict-biz/dictionary?code=face_device_status",
  144. props: {
  145. label: 'dictValue',
  146. value: 'dictKey'
  147. },
  148. dataType: "number",
  149. display: false,
  150. slot: true
  151. }
  152. ]
  153. },
  154. data: []
  155. };
  156. },
  157. computed: {
  158. ...mapGetters(["permission"]),
  159. permissionList() {
  160. return {
  161. addBtn: this.vaildData(this.permission.doordevice_add, false),
  162. viewBtn: this.vaildData(this.permission.doordevice_view, false),
  163. delBtn: this.vaildData(this.permission.doordevice_delete, false),
  164. editBtn: this.vaildData(this.permission.doordevice_edit, false)
  165. };
  166. },
  167. ids() {
  168. let ids = [];
  169. this.selectionList.forEach(ele => {
  170. ids.push(ele.id);
  171. });
  172. return ids.join(",");
  173. }
  174. },
  175. watch: {
  176. 'form.mapSelect': {
  177. handler: function(value) {
  178. if (!value) {
  179. return
  180. } else {
  181. this.form.longitude = this.form.mapSelect.longitude;
  182. this.form.latitude = this.form.mapSelect.latitude;
  183. }
  184. },
  185. }
  186. },
  187. methods: {
  188. pushFace(){
  189. let deviceIds=this.selectionList.map(item=>item.id)
  190. this.$emit("pushFace",deviceIds)
  191. },
  192. openDoor(row) {
  193. remoteOpenDoor(row.id, true).then(res => {
  194. this.$message({
  195. type: "success",
  196. message: "操作成功!"
  197. });
  198. });
  199. },
  200. selectCallback(row) {
  201. this.form.latitude = row.latitude;
  202. this.form.longitude = row.longitude;
  203. this.form.address = row.address;
  204. this.form.residentialId = row.id;
  205. this.form.residentialName = row.name;
  206. },
  207. rowSave(row, done, loading) {
  208. add(row).then(() => {
  209. this.onLoad(this.page);
  210. this.$message({
  211. type: "success",
  212. message: "操作成功!"
  213. });
  214. done();
  215. }, error => {
  216. loading();
  217. window.console.log(error);
  218. });
  219. },
  220. rowUpdate(row, index, done, loading) {
  221. update(row).then(() => {
  222. this.onLoad(this.page);
  223. this.$message({
  224. type: "success",
  225. message: "操作成功!"
  226. });
  227. done();
  228. }, error => {
  229. loading();
  230. console.log(error);
  231. });
  232. },
  233. rowDel(row) {
  234. this.$confirm("确定将选择数据删除?", {
  235. confirmButtonText: "确定",
  236. cancelButtonText: "取消",
  237. type: "warning"
  238. })
  239. .then(() => {
  240. return remove(row.id);
  241. })
  242. .then(() => {
  243. this.onLoad(this.page);
  244. this.$message({
  245. type: "success",
  246. message: "操作成功!"
  247. });
  248. });
  249. },
  250. handleDelete() {
  251. if (this.selectionList.length === 0) {
  252. this.$message.warning("请选择至少一条数据");
  253. return;
  254. }
  255. this.$confirm("确定将选择数据删除?", {
  256. confirmButtonText: "确定",
  257. cancelButtonText: "取消",
  258. type: "warning"
  259. })
  260. .then(() => {
  261. return remove(this.ids);
  262. })
  263. .then(() => {
  264. this.onLoad(this.page);
  265. this.$message({
  266. type: "success",
  267. message: "操作成功!"
  268. });
  269. this.$refs.crud.toggleSelection();
  270. });
  271. },
  272. beforeOpen(done, type) {
  273. if (["edit", "view"].includes(type)) {
  274. getDetail(this.form.id).then(res => {
  275. this.form = res.data.data;
  276. });
  277. }
  278. done();
  279. },
  280. searchReset() {
  281. this.query = {};
  282. this.onLoad(this.page);
  283. },
  284. searchChange(params, done) {
  285. this.query = params;
  286. this.page.currentPage = 1;
  287. this.onLoad(this.page, params);
  288. done();
  289. },
  290. selectionChange(list) {
  291. this.selectionList = list;
  292. },
  293. selectionClear() {
  294. this.selectionList = [];
  295. this.$refs.crud.toggleSelection();
  296. },
  297. close(data){
  298. let arr=[]
  299. this.selectionList.forEach((item,index)=>{
  300. if (data.id==item.id) {
  301. arr.push(item)
  302. this.selectionList.splice(index,1)
  303. }
  304. })
  305. console.log(this.selectionList);
  306. this.$refs.crud.toggleSelection(arr);
  307. },
  308. currentChange(currentPage) {
  309. this.page.currentPage = currentPage;
  310. },
  311. sizeChange(pageSize) {
  312. this.page.pageSize = pageSize;
  313. },
  314. refreshChange() {
  315. this.onLoad(this.page, this.query);
  316. },
  317. fetchList(page, params) {
  318. this.loading = true;
  319. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  320. const data = res.data.data;
  321. this.page.total = data.total;
  322. this.data = data.records;
  323. this.loading = false;
  324. })
  325. },
  326. onLoad(page, params = {}) {
  327. this.fetchList(page, params)
  328. }
  329. }
  330. };
  331. </script>
  332. <style>
  333. </style>