personDeviceRelation-BoundList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <el-dialog
  3. :visible.sync="showDialog"
  4. title="查看关联设备"
  5. :modal-append-to-body="false"
  6. append-to-body
  7. :modal="true"
  8. style="text-align: left"
  9. @close="closeDialog"
  10. :close-on-click-modal="false"
  11. width="970px"
  12. >
  13. <div>
  14. <!--
  15. 要resetFields起作用,必须配置:model和prop
  16. -->
  17. <el-divider></el-divider>
  18. <el-row class="button-group">
  19. <el-button
  20. type="primary"
  21. size="small"
  22. plain
  23. icon="el-icon-remove"
  24. @click="handleRemoveAll"
  25. >解绑所有设备</el-button
  26. >
  27. <el-button
  28. type="primary"
  29. size="small"
  30. plain
  31. icon="el-icon-refresh"
  32. @click="handleUpdateIsWrite"
  33. >更新图片状态</el-button
  34. >
  35. <el-button
  36. type="primary"
  37. size="small"
  38. plain
  39. icon="el-icon-refresh"
  40. :disabled="multipleSelection.length == 0"
  41. @click="dataSync"
  42. >数据同步</el-button
  43. >
  44. <el-button
  45. type="primary"
  46. size="small"
  47. plain
  48. @click="handleReLoad"
  49. >刷新</el-button
  50. >
  51. </el-row>
  52. <el-table
  53. :data="tableData"
  54. style="min-height: 400px"
  55. v-loading="loading"
  56. stripe
  57. @sort-change="sortChange"
  58. @selection-change="handleSelectionChange"
  59. >
  60. <el-table-column type="selection" width="55"></el-table-column>
  61. <el-table-column
  62. prop="deviceInfo.aliasName"
  63. label="设备名称"
  64. width="220"
  65. ></el-table-column>
  66. <el-table-column
  67. prop="personInfo.name"
  68. label="人员名称"
  69. width="120"
  70. ></el-table-column>
  71. <el-table-column prop="deviceInfo.isOnline" label="运行状态" width="80">
  72. <template slot-scope="{ row }">
  73. <div
  74. v-if="row.deviceInfo.isOnline"
  75. style="
  76. border-radius: 30px;
  77. background-color: #67c23a;
  78. width: 20px;
  79. height: 20px;
  80. "
  81. ></div>
  82. <div
  83. v-if="!row.deviceInfo.isOnline"
  84. style="
  85. border-radius: 30px;
  86. background-color: #f56c6c;
  87. width: 20px;
  88. height: 20px;
  89. "
  90. ></div>
  91. </template>
  92. </el-table-column>
  93. <el-table-column prop="isBound" label="照片是否存在" width="120">
  94. <template slot-scope="{ row }">
  95. <div
  96. v-if="!row.deviceInfo.isOnline"
  97. style="
  98. border-radius: 30px;
  99. background-color: #767676;
  100. width: 20px;
  101. height: 20px;
  102. "
  103. ></div>
  104. <div
  105. v-if="row.deviceInfo.isOnline && row.isBound"
  106. style="
  107. border-radius: 30px;
  108. background-color: #67c23a;
  109. width: 20px;
  110. height: 20px;
  111. "
  112. ></div>
  113. <div
  114. v-if="row.deviceInfo.isOnline && !row.isBound"
  115. style="
  116. border-radius: 30px;
  117. background-color: #f56c6c;
  118. width: 20px;
  119. height: 20px;
  120. "
  121. ></div>
  122. </template>
  123. </el-table-column>
  124. <el-table-column prop="remoteOpen" label="远程开门" width="80">
  125. <template slot-scope="{ row }">
  126. <el-switch
  127. v-model="row.remoteOpen"
  128. active-color="#13ce66"
  129. inactive-color="#ff4949"
  130. @change="changeRemote(row)"
  131. :disabled="row.isDefault"
  132. ></el-switch>
  133. </template>
  134. </el-table-column>
  135. <el-table-column
  136. prop="createTime"
  137. label="关联时间"
  138. width="150"
  139. ></el-table-column>
  140. <el-table-column label="操作">
  141. <template slot-scope="{ row }">
  142. <el-button size="mini" type="danger" @click="handleDelete(row)"
  143. >解除关联</el-button
  144. >
  145. </template>
  146. </el-table-column>
  147. </el-table>
  148. <el-pagination
  149. :current-page.sync="pageIndex"
  150. :total="totalElements"
  151. :page-sizes="pageSizeList"
  152. @current-change="changePage"
  153. @size-change="pageSizeChange"
  154. layout="total, sizes, prev, pager, next, jumper"
  155. ></el-pagination>
  156. <personDeviceRelation-detail
  157. v-if="showModal"
  158. :businessKey="businessKey"
  159. :title="modalTitle"
  160. @close="onDetailModalClose"
  161. ></personDeviceRelation-detail>
  162. </div>
  163. </el-dialog>
  164. </template>
  165. <script>
  166. import Constant from "@/constant";
  167. import PersonDeviceRelationDetail from "./personDeviceRelation-detail";
  168. import personDeviceRelationApi from "@/api/base/personDeviceRelation";
  169. import NProgress from "nprogress"; // progress bar
  170. import "nprogress/nprogress.css"; // progress bar style
  171. export default {
  172. props: ["personId", "delFlag"],
  173. data() {
  174. var self = this;
  175. return {
  176. queryModel: {
  177. deviceId: "",
  178. personId: "",
  179. },
  180. loading: false,
  181. tableData: [],
  182. pageIndex: 1,
  183. pageSize: 10,
  184. totalPages: 0,
  185. totalElements: 0,
  186. field: "",
  187. direction: "",
  188. pageSizeList: [10, 20, 30],
  189. multipleSelection: [],
  190. showModal: false,
  191. modalTitle: "",
  192. showDialog: true,
  193. };
  194. },
  195. methods: {
  196. closeDialog() {
  197. this.$emit("close", false);
  198. },
  199. changePage(pageIndex) {
  200. var self = this;
  201. self.loading = true;
  202. self.pageIndex = pageIndex;
  203. var formData = new FormData();
  204. formData.append("pageIndex", self.pageIndex);
  205. formData.append("pageSize", self.pageSize);
  206. formData.append("deviceId", self.queryModel.deviceId);
  207. formData.append("personId", self.personId);
  208. if (self.delFlag == null) {
  209. self.delFlag = false;
  210. }
  211. formData.append("delFlag", self.delFlag);
  212. if (this.field != null) {
  213. formData.append("field", this.field);
  214. }
  215. if (this.direction != null) {
  216. formData.append("direction", this.direction);
  217. }
  218. personDeviceRelationApi
  219. .pageList(formData)
  220. .then(function (response) {
  221. self.loading = false;
  222. var jsonData = response.data.data;
  223. console.log(jsonData.data);
  224. self.tableData = jsonData.data;
  225. self.totalPages = jsonData.totalPages;
  226. self.totalElements = jsonData.recordsTotal;
  227. })
  228. .catch((error) => {
  229. self.loading = false;
  230. // self.$message.error(error + "");
  231. });
  232. },
  233. pageSizeChange(pageSize) {
  234. this.pageSize = pageSize;
  235. },
  236. sortChange(data) {
  237. this.field = data.column.field;
  238. this.direction = data.order;
  239. this.changePage(this.pageIndex);
  240. },
  241. handleSelectionChange(val) {
  242. this.multipleSelection = val;
  243. },
  244. handleReset(name) {
  245. this.$refs[name].resetFields();
  246. },
  247. handleDelete(record) {
  248. var self = this;
  249. this.$confirm("是否解除关联?", "提示", {
  250. confirmButtonText: "确定",
  251. cancelButtonText: "取消",
  252. type: "warning",
  253. distinguishCancelAndClose: true,
  254. })
  255. .then(() => {
  256. self.loading = true;
  257. personDeviceRelationApi.remove(record.id).then(function (response) {
  258. var jsonData = response.data;
  259. self.loading = false;
  260. if (jsonData.result) {
  261. // var index = self.tableData.indexOf(record);
  262. // self.tableData.splice(index, 1);
  263. self.changePage(self.pageIndex);
  264. self.$message({
  265. type: "success",
  266. message: "解绑成功!",
  267. });
  268. }
  269. });
  270. })
  271. .catch((error) => {
  272. self.loading = false;
  273. // self.$message.error(error + "");
  274. });
  275. },
  276. handleRemoveAll() {
  277. var self = this;
  278. this.$confirm("是否解除关联?", "提示", {
  279. confirmButtonText: "确定",
  280. cancelButtonText: "取消",
  281. type: "warning",
  282. distinguishCancelAndClose: true,
  283. })
  284. .then(() => {
  285. self.loading = true;
  286. var formData = new FormData();
  287. formData.append("personId", self.personId);
  288. personDeviceRelationApi
  289. .unbindDevice(formData)
  290. .then(function (response) {
  291. var jsonData = response.data;
  292. self.loading = false;
  293. if (jsonData.result) {
  294. self.changePage(self.pageIndex);
  295. self.$message({
  296. type: "success",
  297. message: "解绑成功!",
  298. });
  299. } else {
  300. self.$message({
  301. type: "warning",
  302. message: jsonData.message,
  303. });
  304. }
  305. });
  306. })
  307. .catch((error) => {
  308. self.loading = false;
  309. // self.$message.error(error + "");
  310. });
  311. },
  312. onDetailModalClose(refreshed) {
  313. //保存成功后回调
  314. this.showModal = false;
  315. if (refreshed) {
  316. this.changePage(this.pageIndex);
  317. }
  318. },
  319. handleUpdateIsWrite() {
  320. var self = this;
  321. self.loading = true;
  322. var formData = new FormData();
  323. formData.append("personId", self.personId);
  324. personDeviceRelationApi
  325. .updatePersonIsWrite(formData)
  326. .then(function (response) {
  327. var jsonData = response.data;
  328. self.loading = false;
  329. if (jsonData.result) {
  330. self.changePage(self.pageIndex);
  331. self.$message({
  332. type: "success",
  333. message: "更新成功!",
  334. });
  335. }
  336. });
  337. },
  338. dataSync() {
  339. //批量同步人脸
  340. var self = this;
  341. var deviceIdList = this.multipleSelection.map((record) => {
  342. return record.deviceId;
  343. });
  344. this.$confirm("是否确认同步选中项?", "提示", {
  345. confirmButtonText: "确定",
  346. cancelButtonText: "取消",
  347. type: "warning",
  348. })
  349. .then(() => {
  350. self.loading = true;
  351. var formData = new FormData();
  352. formData.append("personId", self.personId);
  353. formData.append("deviceIds", deviceIdList);
  354. personDeviceRelationApi
  355. .devicesPersonSync(formData)
  356. .then(function (response) {
  357. var jsonData = response.data;
  358. self.loading = false;
  359. if (jsonData.result) {
  360. if (jsonData.data) {
  361. self.changePage(self.pageIndex);
  362. self.$message({
  363. type: "success",
  364. message: "同步成功!",
  365. });
  366. } else {
  367. if (jsonData.message != null) {
  368. //下载有错误信息提示的报表
  369. //window.open(response.data);
  370. self.$message({
  371. showClose: true,
  372. dangerouslyUseHTMLString: true,
  373. message:
  374. "错误" +
  375. `,<a href="${jsonData.message}" target="_blank">点击下载错误报表</a>&nbsp;`,
  376. duration: 30000,
  377. });
  378. }
  379. }
  380. } else {
  381. self.$message({
  382. type: "warning",
  383. message: jsonData.message,
  384. });
  385. }
  386. });
  387. })
  388. .catch(() => {
  389. self.loading = false;
  390. });
  391. },
  392. changeRemote(row) {
  393. personDeviceRelationApi.update(row);
  394. },
  395. handleReLoad() {
  396. var self = this;
  397. self.changePage(self.pageIndex);
  398. },
  399. },
  400. mounted: function () {
  401. this.changePage(1);
  402. },
  403. components: {
  404. "personDeviceRelation-detail": PersonDeviceRelationDetail,
  405. },
  406. };
  407. </script>
  408. <style lang="scss" scoped>
  409. .el-breadcrumb {
  410. margin: 10px;
  411. line-height: 20px;
  412. }
  413. .el-divider {
  414. margin: 5px 0;
  415. }
  416. .demo-form-inline {
  417. margin-left: 10px;
  418. text-align: left;
  419. }
  420. .button-group {
  421. margin-left: 10px;
  422. text-align: left;
  423. }
  424. </style>