personDeviceRelation-list.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <el-dialog
  3. :visible.sync="showDialog"
  4. title="查看设备"
  5. :modal-append-to-body="false"
  6. :modal="true"
  7. style="text-align:left;"
  8. @close="closeDialog"
  9. width="60%"
  10. >
  11. <div>
  12. <!--
  13. 要resetFields起作用,必须配置:model和prop
  14. -->
  15. <el-divider></el-divider>
  16. <el-row class="button-group">
  17. <el-button
  18. type="primary"
  19. size="small"
  20. plain
  21. icon="el-icon-circle-plus"
  22. :disabled="multipleSelection.length==0"
  23. @click="handleBatchBound"
  24. >批量绑定</el-button>
  25. </el-row>
  26. <el-table
  27. :data="tableData"
  28. style="min-height:400px;"
  29. v-loading="loading"
  30. stripe
  31. @sort-change="sortChange"
  32. @selection-change="handleSelectionChange"
  33. >
  34. <el-table-column type="selection" :selectable="disableSelect" width="55"></el-table-column>
  35. <el-table-column prop="deviceNo" label="设备编号" width="220"></el-table-column>
  36. <el-table-column prop="aliasName" label="设备名称" width="180"></el-table-column>
  37. <el-table-column prop="typeN" label="类型" width="120"></el-table-column>
  38. <el-table-column prop="isBindPerson" label="绑定状态" width="120">
  39. <template slot-scope="{row}">{{row.isBindPerson ? "已绑定" : "未绑定"}}</template>
  40. </el-table-column>
  41. <el-table-column label="操作">
  42. <template slot-scope="{row}">
  43. <span v-if="!row.isBindPerson">
  44. <el-button size="mini" type="success" @click="handleBound(row)">绑定设备</el-button>
  45. </span>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <el-pagination
  50. :current-page.sync="pageIndex"
  51. :total="totalElements"
  52. :page-sizes="pageSizeList"
  53. @current-change="changePage"
  54. @size-change="pageSizeChange"
  55. layout="total, sizes, prev, pager, next, jumper"
  56. ></el-pagination>
  57. <personDeviceRelation-detail
  58. v-if="showModal"
  59. :businessKey="businessKey"
  60. :title="modalTitle"
  61. @close="onDetailModalClose"
  62. ></personDeviceRelation-detail>
  63. </div>
  64. </el-dialog>
  65. </template>
  66. <script>
  67. import Constant from "@/constant";
  68. import PersonDeviceRelationDetail from "./personDeviceRelation-detail";
  69. import personDeviceRelationApi from "@/api/base/personDeviceRelation";
  70. import NProgress from "nprogress"; // progress bar
  71. import "nprogress/nprogress.css"; // progress bar style
  72. export default {
  73. props: ["personId"],
  74. data() {
  75. var self = this;
  76. return {
  77. formModel: {},
  78. queryModel: {
  79. deviceId: "",
  80. personId: ""
  81. },
  82. loading: false,
  83. tableData: [],
  84. pageIndex: 1,
  85. pageSize: 10,
  86. totalPages: 0,
  87. totalElements: 0,
  88. field: "",
  89. direction: "",
  90. pageSizeList: [10, 20, 30],
  91. multipleSelection: [],
  92. showModal: false,
  93. modalTitle: "",
  94. showDialog: true
  95. };
  96. },
  97. methods: {
  98. closeDialog() {
  99. this.$emit("close", false);
  100. },
  101. disableSelect(row, rowIndex) {
  102. //多选按钮是否禁用
  103. if (row.isBindPerson) {
  104. return false;
  105. } else {
  106. return true;
  107. }
  108. },
  109. changePage(pageIndex) {
  110. var self = this;
  111. self.loading = true;
  112. self.pageIndex = pageIndex;
  113. var formData = new FormData();
  114. formData.append("pageIndex", self.pageIndex);
  115. formData.append("pageSize", self.pageSize);
  116. formData.append("personId", self.personId);
  117. if (this.field != null) {
  118. formData.append("field", this.field);
  119. }
  120. if (this.direction != null) {
  121. formData.append("direction", this.direction);
  122. }
  123. personDeviceRelationApi
  124. .isUnbindDeviceList(formData)
  125. .then(function(response) {
  126. self.loading = false;
  127. var jsonData = response.data.data;
  128. self.tableData = jsonData.data;
  129. self.totalPages = jsonData.totalPages;
  130. self.totalElements = jsonData.recordsTotal;
  131. })
  132. .catch(error => {
  133. self.loading = false;
  134. // self.$message.error(error + "");
  135. });
  136. },
  137. pageSizeChange(pageSize) {
  138. this.pageSize = pageSize;
  139. },
  140. sortChange(data) {
  141. this.field = data.column.field;
  142. this.direction = data.order;
  143. this.changePage(this.pageIndex);
  144. },
  145. handleSelectionChange(val) {
  146. this.multipleSelection = val;
  147. },
  148. handleReset(name) {
  149. this.$refs[name].resetFields();
  150. },
  151. handleBound(record) {
  152. var self = this;
  153. // this.$confirm("是否绑定?", "提示", {
  154. // confirmButtonText: "确定",
  155. // cancelButtonText: "取消",
  156. // type: "warning",
  157. // distinguishCancelAndClose: true
  158. // })
  159. // .then(() => {
  160. if(confirm("是否绑定?")){
  161. self.formModel.personId = self.personId;
  162. self.formModel.deviceId = record.id;
  163. self.loading = true;
  164. return personDeviceRelationApi
  165. .add(self.formModel)
  166. .then(function(response) {
  167. self.loading = false;
  168. var jsonData = response.data;
  169. self.changePage(self.pageIndex);
  170. if (jsonData.result) {
  171. self.$message({
  172. message: "绑定成功!",
  173. type: "success"
  174. });
  175. } else {
  176. self.$message({
  177. message: jsonData.message + "",
  178. type: "warning"
  179. });
  180. }
  181. });
  182. }
  183. // })
  184. // .catch(error => {
  185. // self.loading = false;
  186. // // self.$message.error(error + "");
  187. // });
  188. },
  189. handleBatchBound() {
  190. var self = this;
  191. self.loading = true;
  192. var idList = this.multipleSelection.map(record => {
  193. return record.id;
  194. });
  195. this.$confirm("是否绑定选中项?", "提示", {
  196. confirmButtonText: "确定",
  197. cancelButtonText: "取消",
  198. type: "warning",
  199. distinguishCancelAndClose: true
  200. })
  201. .then(() => {
  202. var formData = new FormData();
  203. formData.append("personId", self.personId);
  204. formData.append("devices", idList);
  205. personDeviceRelationApi
  206. .batchBindDevice(formData)
  207. .then(function(response) {
  208. var jsonData = response.data;
  209. self.changePage(self.pageIndex);
  210. if (jsonData.result) {
  211. self.$message({
  212. type: "success",
  213. message: "绑定成功!"
  214. });
  215. } else {
  216. self.$message({
  217. type: "error",
  218. message: jsonData.message
  219. });
  220. }
  221. });
  222. })
  223. .catch(error => {
  224. self.loading = false;
  225. // self.$message.error(error + "");
  226. });
  227. },
  228. onDetailModalClose(refreshed) {
  229. //保存成功后回调
  230. this.showModal = false;
  231. if (refreshed) {
  232. this.changePage(this.pageIndex);
  233. }
  234. }
  235. },
  236. mounted: function() {
  237. this.changePage(1);
  238. },
  239. components: {
  240. "personDeviceRelation-detail": PersonDeviceRelationDetail
  241. }
  242. };
  243. </script>
  244. <style lang="scss" scoped>
  245. .el-breadcrumb {
  246. margin: 10px;
  247. line-height: 20px;
  248. }
  249. .el-divider {
  250. margin: 5px 0;
  251. }
  252. .demo-form-inline {
  253. margin-left: 10px;
  254. text-align: left;
  255. }
  256. .button-group {
  257. margin-left: 10px;
  258. text-align: left;
  259. }
  260. </style>