index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <div class="body">
  3. <!-- 头部区域 -->
  4. <div class="head">
  5. <div class="head-img">
  6. <img src="../../../public/images/img-1.png" />
  7. </div>
  8. <div class="head-info">设备与组绑定</div>
  9. </div>
  10. <!-- 搜索区域 -->
  11. <div class="form-head">
  12. <span>序列号:</span>
  13. <span class="input">
  14. <el-input
  15. v-model="listQuery.serialNumber"
  16. placeholder="请输入序列号"
  17. clearable
  18. @clear="handleChangeFilter"
  19. @keyup.enter.native="handleFilter"
  20. >
  21. </el-input>
  22. </span>
  23. <span>设备名称:</span>
  24. <span class="input">
  25. <el-input
  26. v-model="listQuery.name"
  27. placeholder="请输入设备名称"
  28. clearable
  29. @clear="handleChangeFilter"
  30. @keyup.enter.native="handleFilter"
  31. >
  32. </el-input>
  33. </span>
  34. <el-button type="primary" size="mini" class="button" @click="handleFilter"
  35. >查询</el-button
  36. >
  37. </div>
  38. <!-- 表格区域 -->
  39. <div class="form">
  40. <el-table :data="list">
  41. <el-table-column label="序列号" align="center" width="440px">
  42. <template slot-scope="{ row }">
  43. <span>{{ row.serialNumber }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="名称" align="center" width="440px">
  47. <template slot-scope="{ row }">
  48. <span>{{ row.name }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="操作" width="440px" align="center">
  52. <template slot-scope="{ row }">
  53. <el-button type="text" size="small" @click="checkGroup(row)"
  54. >查看当前分组</el-button
  55. >
  56. <el-button type="text" size="small" @click="bindGroup(row)"
  57. >绑定分组</el-button
  58. >
  59. <el-button type="text" size="small" @click="unbindGroup(row)"
  60. >解绑分组</el-button
  61. >
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <!-- 底部分页区 -->
  66. <div class="block">
  67. <template>
  68. <pagination
  69. :total="total"
  70. :page.sync="listQuery.page"
  71. :limit.sync="listQuery.limit"
  72. @pagination="getList"
  73. />
  74. </template>
  75. </div>
  76. </div>
  77. <!-- 查看分组弹窗区域 -->
  78. <el-dialog
  79. title="查看当前分组"
  80. :visible.sync="dialogCheckGroups"
  81. width="30%"
  82. center
  83. >
  84. <el-form>
  85. <el-form-item label="已绑定分组:" class="switch-button-item">
  86. <span>
  87. <el-tag
  88. class="groupclass"
  89. v-for="item in groupWithDeviceList"
  90. :key="item.idGroup"
  91. >
  92. {{ item.groupName }}
  93. </el-tag>
  94. </span>
  95. </el-form-item>
  96. </el-form>
  97. </el-dialog>
  98. <!-- 绑定分组弹窗区域 -->
  99. <el-dialog
  100. title="绑定分组"
  101. :visible.sync="dialogBindGroup"
  102. width="30%"
  103. center
  104. >
  105. <el-form ref="dataForm" :model="temp" :rules="rules">
  106. <el-form-item
  107. style="white-space: pre"
  108. label="选择分组:"
  109. class="switch-button-item"
  110. prop="groups"
  111. >
  112. <el-col :span="12">
  113. <el-select
  114. v-model="temp.groups"
  115. filterable
  116. multiple
  117. value-key="id"
  118. placeholder="请选择"
  119. >
  120. <el-option
  121. v-for="item in groupList"
  122. :key="item.id"
  123. :label="item.name"
  124. :value="item.id"
  125. >
  126. </el-option>
  127. </el-select>
  128. </el-col>
  129. </el-form-item>
  130. </el-form>
  131. <span slot="footer">
  132. <el-button type="primary" @click="updateData()">确 定</el-button>
  133. <el-button @click="dialogBindGroup = false">取 消</el-button>
  134. </span>
  135. </el-dialog>
  136. <!-- 解绑分组弹窗区域 -->
  137. <el-dialog
  138. title="解绑分组"
  139. :visible.sync="dialogUnbindGroup"
  140. width="30%"
  141. center
  142. >
  143. <el-table :data="groupWithDeviceList">
  144. <el-table-column label="分组" align="center">
  145. <template slot-scope="{ row }">
  146. <span>{{ row.groupName }}</span>
  147. </template>
  148. </el-table-column>
  149. <el-table-column label="操作" width="340px" align="center">
  150. <template slot-scope="{ row, $index }">
  151. <el-button
  152. type="text"
  153. size="small"
  154. @click="deleteGroup(row, $index)"
  155. >解绑</el-button
  156. >
  157. </template>
  158. </el-table-column>
  159. </el-table>
  160. </el-dialog>
  161. </div>
  162. </template>
  163. <script>
  164. import Pagination from "@/components/Pagination";
  165. import {
  166. fetchList,
  167. fetchGroupList,
  168. bindGroups,
  169. searchList,
  170. deleteGroups,
  171. checkGroups,
  172. } from "@/api/devicewithgroup";
  173. export default {
  174. components: {
  175. Pagination,
  176. },
  177. data() {
  178. return {
  179. list: [],
  180. groupList: [],
  181. groupWithDeviceList: [],
  182. temp: {
  183. serialNumber: "",
  184. name: "",
  185. groups: [],
  186. groupIds: [],
  187. },
  188. total: 0, //数据的总数//
  189. listQuery: {
  190. page: 1, //当前在第几页//
  191. limit: 8, //一页几条//
  192. name: "",
  193. serialNumber: "",
  194. },
  195. dialogBindGroup: false,
  196. dialogUnbindGroup: false,
  197. dialogCheckGroups: false,
  198. rules: {
  199. groups: [
  200. {
  201. required: true,
  202. message: "请选择分组",
  203. trigger: "change",
  204. },
  205. ],
  206. },
  207. };
  208. },
  209. created() {
  210. this.getList();
  211. this.getgroupList();
  212. },
  213. methods: {
  214. getList() {
  215. if (this.listQuery.name || this.listQuery.serialNumber) {
  216. searchList(this.listQuery).then((response) => {
  217. this.list = response.data;
  218. this.total = response.total;
  219. });
  220. } else {
  221. fetchList({
  222. page: this.listQuery.page,
  223. limit: this.listQuery.limit,
  224. }).then((response) => {
  225. this.list = response.data;
  226. this.total = response.total;
  227. });
  228. }
  229. },
  230. getgroupList() {
  231. fetchGroupList({ page: this.listQuery.page, limit: "999" }).then(
  232. (response) => {
  233. this.groupList = response.data;
  234. }
  235. );
  236. },
  237. checkGroup(row) {
  238. this.temp = Object.assign({}, row);
  239. checkGroups({ deviceId: row.id }).then((response) => {
  240. this.groupWithDeviceList = response.data;
  241. });
  242. this.dialogCheckGroups = true;
  243. },
  244. bindGroup(row) {
  245. this.temp = Object.assign({}, row);
  246. this.dialogBindGroup = true;
  247. this.$nextTick(() => {
  248. this.$refs["dataForm"].clearValidate();
  249. });
  250. },
  251. updateData() {
  252. this.$refs["dataForm"].validate((valid) => {
  253. if (valid) {
  254. const tempData = Object.assign({}, this.temp);
  255. bindGroups({
  256. id: tempData.id,
  257. serialNumber: tempData.serialNumber,
  258. groups: tempData.groups,
  259. }).then(() => {
  260. this.dialogBindGroup = false;
  261. this.$notify({
  262. title: "绑定分组成功",
  263. type: "success",
  264. duration: 1500,
  265. });
  266. });
  267. }
  268. });
  269. },
  270. unbindGroup(row) {
  271. this.temp = Object.assign({}, row);
  272. checkGroups({ deviceId: row.id }).then((response) => {
  273. this.groupWithDeviceList = response.data;
  274. });
  275. this.dialogUnbindGroup = true;
  276. },
  277. deleteGroup(row, index) {
  278. if (confirm("确定解绑吗?")) {
  279. deleteGroups({
  280. id: this.temp.id,
  281. serialNumber: this.temp.serialNumber,
  282. groups: [row.idGroup],
  283. }).then(() => {
  284. this.$notify({
  285. title: "解绑成功",
  286. type: "success",
  287. duration: 1500,
  288. });
  289. this.groupWithDeviceList.splice(index, 1);
  290. });
  291. }
  292. },
  293. handleChangeFilter() {
  294. if (!this.listQuery.name && !this.listQuery.serialNumber) {
  295. this.getList();
  296. } else {
  297. searchList(this.listQuery).then((response) => {
  298. this.list = response.data;
  299. this.total = response.total;
  300. });
  301. }
  302. },
  303. handleFilter() {
  304. if (!this.listQuery.name && !this.listQuery.serialNumber) {
  305. alert("请输入搜索条件");
  306. } else {
  307. let temp = Object.assign({}, this.listQuery);
  308. temp.page = 1;
  309. searchList(temp).then((response) => {
  310. this.list = response.data;
  311. this.total = response.total;
  312. });
  313. this.listQuery.page = 1;
  314. }
  315. },
  316. },
  317. };
  318. </script>
  319. <style lang="scss" scoped>
  320. .body {
  321. width: 1551px;
  322. margin: 29px 29px 0 31px;
  323. .head {
  324. display: flex;
  325. width: 1380px;
  326. height: 55px;
  327. margin-left: 40px;
  328. border-bottom: 1px solid #cccccc;
  329. .head-img {
  330. width: 30px;
  331. height: 30px;
  332. img {
  333. width: 30px;
  334. }
  335. }
  336. .head-info {
  337. height: 22px;
  338. margin-top: 5px;
  339. margin-left: 16px;
  340. font-weight: bold;
  341. }
  342. .input {
  343. width: 240px;
  344. margin-left: 21px;
  345. }
  346. .input-serch {
  347. margin-left: 32px;
  348. }
  349. }
  350. .form-head {
  351. margin: 0 40px;
  352. width: 1504px;
  353. line-height: 118px;
  354. font-size: 9px;
  355. .input {
  356. display: inline-block;
  357. margin-right: 30px;
  358. width: 210px;
  359. }
  360. .button {
  361. margin-left: 41px;
  362. }
  363. }
  364. .form {
  365. margin-left: 40px;
  366. width: 1380px;
  367. .block {
  368. float: right;
  369. }
  370. }
  371. .switch-button-item {
  372. margin-left: 120px;
  373. .groupclass {
  374. float: left;
  375. margin-right: 10px;
  376. margin-bottom: 10px;
  377. }
  378. }
  379. }
  380. </style>