index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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.name"
  16. placeholder="请输入姓名"
  17. clearable
  18. @clear="getUserList"
  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.cardNumber"
  27. placeholder="请输入卡号"
  28. clearable
  29. @clear="getUserList"
  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.name }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="卡号" align="center" width="440px">
  47. <template slot-scope="{ row }">
  48. <span>{{ row.cardNumber }}</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="getUserList"
  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="groupsId"
  111. >
  112. <el-col :span="12">
  113. <el-select
  114. v-model="temp.groupsId"
  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. fetchUserList,
  167. fetchGroupList,
  168. editGroup,
  169. searchList,
  170. fetchList,
  171. bindGroups,
  172. deleteGroups,
  173. checkGroups,
  174. } from "@/api/userWithGroup";
  175. export default {
  176. components: {
  177. Pagination,
  178. },
  179. data() {
  180. return {
  181. list: [],
  182. groupList: [],
  183. groupWithDeviceList: [],
  184. temp: {
  185. userName: "",
  186. cardNumber: "",
  187. groupsId: [],
  188. },
  189. total: 0, //数据的总数//
  190. listQuery: {
  191. page: 1, //当前在第几页//
  192. limit: 8, //一页几条//
  193. name: "",
  194. cardNumber: "",
  195. },
  196. dialogCheckGroups: false,
  197. dialogBindGroup: false,
  198. dialogUnbindGroup: false,
  199. rules: {
  200. groupsId: [
  201. {
  202. required: true,
  203. message: "请选择分组",
  204. trigger: "change",
  205. },
  206. ],
  207. },
  208. };
  209. },
  210. created() {
  211. this.getUserList();
  212. this.getgroupList();
  213. },
  214. methods: {
  215. getUserList() {
  216. fetchUserList({
  217. page: this.listQuery.page,
  218. limit: this.listQuery.limit,
  219. }).then((response) => {
  220. this.list = response.data;
  221. this.total = response.total;
  222. });
  223. },
  224. getgroupList() {
  225. fetchGroupList({ page: this.listQuery.page, limit: "999" }).then(
  226. (response) => {
  227. this.groupList = response.data;
  228. }
  229. );
  230. },
  231. checkGroup(row) {
  232. this.temp = Object.assign({}, row);
  233. checkGroups({ userId: row.id }).then((response) => {
  234. this.groupWithDeviceList = response.data;
  235. });
  236. this.dialogCheckGroups = true;
  237. },
  238. bindGroup(row) {
  239. this.temp = Object.assign({}, row);
  240. this.dialogBindGroup = true;
  241. this.$nextTick(() => {
  242. this.$refs["dataForm"].clearValidate();
  243. });
  244. },
  245. updateData() {
  246. this.$refs["dataForm"].validate((valid) => {
  247. if (valid) {
  248. const tempData = Object.assign({}, this.temp);
  249. bindGroups({
  250. id: tempData.id,
  251. groups: tempData.groupsId,
  252. }).then(() => {
  253. this.dialogBindGroup = false;
  254. this.$notify({
  255. title: "绑定分组成功",
  256. type: "success",
  257. duration: 1500,
  258. });
  259. });
  260. }
  261. });
  262. },
  263. unbindGroup(row) {
  264. this.temp = Object.assign({}, row);
  265. checkGroups({ userId: row.id }).then((response) => {
  266. this.groupWithDeviceList = response.data;
  267. });
  268. this.dialogUnbindGroup = true;
  269. },
  270. deleteGroup(row, index) {
  271. console.log(row, index);
  272. if (confirm("确定解绑吗?")) {
  273. deleteGroups({
  274. id: this.temp.id,
  275. groups: [row.idGroup],
  276. }).then(() => {
  277. this.$notify({
  278. title: "解绑成功",
  279. type: "success",
  280. duration: 1500,
  281. });
  282. this.groupWithDeviceList.splice(index, 1);
  283. });
  284. }
  285. },
  286. handleFilter() {
  287. if (!this.listQuery.name && !this.listQuery.cardNumber) {
  288. alert("请输入搜索条件");
  289. } else {
  290. searchList(this.listQuery).then((response) => {
  291. this.list = response.data;
  292. this.total = response.total;
  293. });
  294. }
  295. },
  296. },
  297. };
  298. </script>
  299. <style lang="scss" scoped>
  300. .body {
  301. width: 1551px;
  302. margin: 29px 29px 0 31px;
  303. .head {
  304. display: flex;
  305. width: 1380px;
  306. height: 55px;
  307. margin-left: 40px;
  308. border-bottom: 1px solid #cccccc;
  309. .head-img {
  310. width: 30px;
  311. height: 30px;
  312. img {
  313. width: 30px;
  314. }
  315. }
  316. .head-info {
  317. height: 22px;
  318. margin-top: 5px;
  319. margin-left: 16px;
  320. font-weight: bold;
  321. }
  322. .input {
  323. width: 240px;
  324. margin-left: 21px;
  325. }
  326. .input-serch {
  327. margin-left: 32px;
  328. }
  329. }
  330. .form-head {
  331. margin: 0 40px;
  332. width: 1504px;
  333. line-height: 118px;
  334. font-size: 9px;
  335. .input {
  336. display: inline-block;
  337. margin-right: 30px;
  338. width: 210px;
  339. }
  340. .button {
  341. margin-left: 41px;
  342. }
  343. }
  344. .form {
  345. margin-left: 40px;
  346. width: 1380px;
  347. .block {
  348. float: right;
  349. }
  350. }
  351. .switch-button-item {
  352. margin-left: 120px;
  353. .groupclass {
  354. float: left;
  355. margin-right: 10px;
  356. margin-bottom: 10px;
  357. }
  358. }
  359. }
  360. </style>