| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- <template>
- <div class="body">
- <!-- 头部区域 -->
- <div class="head">
- <div class="head-img">
- <img src="../../../public/images/img-1.png" />
- </div>
- <div class="head-info">设备与组绑定</div>
- </div>
- <!-- 搜索区域 -->
- <div class="form-head">
- <span>序列号:</span>
- <span class="input">
- <el-input
- v-model="listQuery.serialNumber"
- placeholder="请输入序列号"
- clearable
- @clear="handleChangeFilter"
- @keyup.enter.native="handleFilter"
- >
- </el-input>
- </span>
- <span>设备名称:</span>
- <span class="input">
- <el-input
- v-model="listQuery.name"
- placeholder="请输入设备名称"
- clearable
- @clear="handleChangeFilter"
- @keyup.enter.native="handleFilter"
- >
- </el-input>
- </span>
- <el-button type="primary" size="mini" class="button" @click="handleFilter"
- >查询</el-button
- >
- </div>
- <!-- 表格区域 -->
- <div class="form">
- <el-table :data="list">
- <el-table-column label="序列号" align="center" width="440px">
- <template slot-scope="{ row }">
- <span>{{ row.serialNumber }}</span>
- </template>
- </el-table-column>
- <el-table-column label="名称" align="center" width="440px">
- <template slot-scope="{ row }">
- <span>{{ row.name }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="440px" align="center">
- <template slot-scope="{ row }">
- <el-button type="text" size="small" @click="checkGroup(row)"
- >查看当前分组</el-button
- >
- <el-button type="text" size="small" @click="bindGroup(row)"
- >绑定分组</el-button
- >
- <el-button type="text" size="small" @click="unbindGroup(row)"
- >解绑分组</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- <!-- 底部分页区 -->
- <div class="block">
- <template>
- <pagination
- :total="total"
- :page.sync="listQuery.page"
- :limit.sync="listQuery.limit"
- @pagination="getList"
- />
- </template>
- </div>
- </div>
- <!-- 查看分组弹窗区域 -->
- <el-dialog
- title="查看当前分组"
- :visible.sync="dialogCheckGroups"
- width="30%"
- center
- >
- <el-form>
- <el-form-item label="已绑定分组:" class="switch-button-item">
- <span>
- <el-tag
- class="groupclass"
- v-for="item in groupWithDeviceList"
- :key="item.idGroup"
- >
- {{ item.groupName }}
- </el-tag>
- </span>
- </el-form-item>
- </el-form>
- </el-dialog>
- <!-- 绑定分组弹窗区域 -->
- <el-dialog
- title="绑定分组"
- :visible.sync="dialogBindGroup"
- width="30%"
- center
- >
- <el-form ref="dataForm" :model="temp" :rules="rules">
- <el-form-item
- style="white-space: pre"
- label="选择分组:"
- class="switch-button-item"
- prop="groups"
- >
- <el-col :span="12">
- <el-select
- v-model="temp.groups"
- filterable
- multiple
- value-key="id"
- placeholder="请选择"
- >
- <el-option
- v-for="item in groupList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-col>
- </el-form-item>
- </el-form>
- <span slot="footer">
- <el-button type="primary" @click="updateData()">确 定</el-button>
- <el-button @click="dialogBindGroup = false">取 消</el-button>
- </span>
- </el-dialog>
- <!-- 解绑分组弹窗区域 -->
- <el-dialog
- title="解绑分组"
- :visible.sync="dialogUnbindGroup"
- width="30%"
- center
- >
- <el-table :data="groupWithDeviceList">
- <el-table-column label="分组" align="center">
- <template slot-scope="{ row }">
- <span>{{ row.groupName }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="340px" align="center">
- <template slot-scope="{ row, $index }">
- <el-button
- type="text"
- size="small"
- @click="deleteGroup(row, $index)"
- >解绑</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- </el-dialog>
- </div>
- </template>
- <script>
- import Pagination from "@/components/Pagination";
- import {
- fetchList,
- fetchGroupList,
- bindGroups,
- searchList,
- deleteGroups,
- checkGroups,
- } from "@/api/devicewithgroup";
- export default {
- components: {
- Pagination,
- },
- data() {
- return {
- list: [],
- groupList: [],
- groupWithDeviceList: [],
- temp: {
- serialNumber: "",
- name: "",
- groups: [],
- groupIds: [],
- },
- total: 0, //数据的总数//
- listQuery: {
- page: 1, //当前在第几页//
- limit: 8, //一页几条//
- name: "",
- serialNumber: "",
- },
- dialogBindGroup: false,
- dialogUnbindGroup: false,
- dialogCheckGroups: false,
- rules: {
- groups: [
- {
- required: true,
- message: "请选择分组",
- trigger: "change",
- },
- ],
- },
- };
- },
- created() {
- this.getList();
- this.getgroupList();
- },
- methods: {
- getList() {
- if (this.listQuery.name || this.listQuery.serialNumber) {
- searchList(this.listQuery).then((response) => {
- this.list = response.data;
- this.total = response.total;
- });
- } else {
- fetchList({
- page: this.listQuery.page,
- limit: this.listQuery.limit,
- }).then((response) => {
- this.list = response.data;
- this.total = response.total;
- });
- }
- },
- getgroupList() {
- fetchGroupList({ page: this.listQuery.page, limit: "999" }).then(
- (response) => {
- this.groupList = response.data;
- }
- );
- },
- checkGroup(row) {
- this.temp = Object.assign({}, row);
- checkGroups({ deviceId: row.id }).then((response) => {
- this.groupWithDeviceList = response.data;
- });
- this.dialogCheckGroups = true;
- },
- bindGroup(row) {
- this.temp = Object.assign({}, row);
- this.dialogBindGroup = true;
- this.$nextTick(() => {
- this.$refs["dataForm"].clearValidate();
- });
- },
- updateData() {
- this.$refs["dataForm"].validate((valid) => {
- if (valid) {
- const tempData = Object.assign({}, this.temp);
- bindGroups({
- id: tempData.id,
- serialNumber: tempData.serialNumber,
- groups: tempData.groups,
- }).then(() => {
- this.dialogBindGroup = false;
- this.$notify({
- title: "绑定分组成功",
- type: "success",
- duration: 1500,
- });
- });
- }
- });
- },
- unbindGroup(row) {
- this.temp = Object.assign({}, row);
- checkGroups({ deviceId: row.id }).then((response) => {
- this.groupWithDeviceList = response.data;
- });
- this.dialogUnbindGroup = true;
- },
- deleteGroup(row, index) {
- if (confirm("确定解绑吗?")) {
- deleteGroups({
- id: this.temp.id,
- serialNumber: this.temp.serialNumber,
- groups: [row.idGroup],
- }).then(() => {
- this.$notify({
- title: "解绑成功",
- type: "success",
- duration: 1500,
- });
- this.groupWithDeviceList.splice(index, 1);
- });
- }
- },
- handleChangeFilter() {
- if (!this.listQuery.name && !this.listQuery.serialNumber) {
- this.getList();
- } else {
- searchList(this.listQuery).then((response) => {
- this.list = response.data;
- this.total = response.total;
- });
- }
- },
- handleFilter() {
- if (!this.listQuery.name && !this.listQuery.serialNumber) {
- alert("请输入搜索条件");
- } else {
- let temp = Object.assign({}, this.listQuery);
- temp.page = 1;
- searchList(temp).then((response) => {
- this.list = response.data;
- this.total = response.total;
- });
- this.listQuery.page = 1;
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .body {
- width: 1551px;
- margin: 29px 29px 0 31px;
- .head {
- display: flex;
- width: 1380px;
- height: 55px;
- margin-left: 40px;
- border-bottom: 1px solid #cccccc;
- .head-img {
- width: 30px;
- height: 30px;
- img {
- width: 30px;
- }
- }
- .head-info {
- height: 22px;
- margin-top: 5px;
- margin-left: 16px;
- font-weight: bold;
- }
- .input {
- width: 240px;
- margin-left: 21px;
- }
- .input-serch {
- margin-left: 32px;
- }
- }
- .form-head {
- margin: 0 40px;
- width: 1504px;
- line-height: 118px;
- font-size: 9px;
- .input {
- display: inline-block;
- margin-right: 30px;
- width: 210px;
- }
- .button {
- margin-left: 41px;
- }
- }
- .form {
- margin-left: 40px;
- width: 1380px;
- .block {
- float: right;
- }
- }
- .switch-button-item {
- margin-left: 120px;
- .groupclass {
- float: left;
- margin-right: 10px;
- margin-bottom: 10px;
- }
- }
- }
- </style>
|