personDeviceRelation-BoundList.vue 11 KB

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