| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <template>
- <wrapper
- fill
- margin
- padding
- background
- >
- <schema-table
- ref="table"
- :schema="schema"
- />
- <confirm-dialog
- ref="editDialog"
- :title="dialogTitle"
- @confirm="onSave"
- >
- <div class="c-grid-form u-align-self--center">
- <span class="c-grid-form__label required">名称:</span>
- <el-input
- v-model.trim="currObj.name"
- placeholder="请填写分组名称"
- maxlength="50"
- />
- <span class="c-grid-form__label">备注:</span>
- <el-input
- v-model="currObj.remark"
- type="textarea"
- maxlength="100"
- :rows="3"
- show-word-limit
- />
- </div>
- </confirm-dialog>
- <table-dialog
- ref="subDeviceDialog"
- title="设备"
- :schema="subDeviceSchema"
- size="large"
- />
- <table-dialog
- ref="deviceDialog"
- title="添加设备"
- :schema="deviceSchema"
- append-to-body
- @choosen="onChooseDevice"
- />
- </wrapper>
- </template>
- <script>
- import {
- getDeviceGroups,
- addDeviceGroup,
- updateDeviceGroup,
- deleteDeviceGroup,
- getDevicesByGroup,
- getDevices,
- addDeviceToGroup,
- deleteDeviceFromGroup
- } from '@/api/device'
- import mixin from '../mixins'
- export default {
- name: 'DeviceGroup',
- mixins: [mixin],
- data () {
- return {
- type: '分组',
- proxy: {
- add: addDeviceGroup,
- update: updateDeviceGroup,
- del: deleteDeviceGroup
- },
- schema: {
- condition: { name: '' },
- list: getDeviceGroups,
- buttons: [
- { type: 'add', on: this.onAdd }
- ],
- filters: [
- { key: 'name', type: 'search', placeholder: '分组名称' }
- ],
- cols: [
- { prop: 'name', label: '分组名称' },
- { prop: 'remark', label: '备注' },
- {
- type: 'invoke', render: [
- { label: '编辑', on: this.onEdit },
- { label: '设备', on: this.onViewDevices },
- { label: '删除', on: this.onDel }
- ]
- }
- ]
- },
- subDeviceSchema: {
- singlePage: true,
- list: this.getDevicesByGroup,
- buttons: [
- { type: 'add', label: '添加设备', on: this.onAddDevice }
- ],
- cols: [
- { prop: 'name', label: '设备名称' },
- { prop: 'productName', label: '产品' },
- { prop: 'serialNumber', label: '序列号' },
- { prop: 'mac', label: 'MAC' },
- { prop: 'resolutionRatio', label: '分辨率' },
- { prop: 'remark', label: '备注' },
- {
- type: 'invoke', render: [
- { label: '移除', on: this.onDelDevice }
- ]
- }
- ]
- },
- deviceSchema: {
- condition: { name: '' },
- filters: [
- { key: 'name', type: 'search', placeholder: '设备名称' }
- ],
- list: getDevices,
- cols: [
- { prop: 'name', label: '设备名称' },
- { prop: 'productName', label: '产品' },
- { prop: 'serialNumber', label: '序列号' },
- { prop: 'mac', label: 'MAC' },
- { prop: 'resolutionRatio', label: '分辨率' },
- { prop: 'remark', label: '备注' }
- ]
- }
- }
- },
- methods: {
- onSave (done) {
- if (!this.currObj.name) {
- this.$message({
- type: 'warning',
- message: '名称不能为空'
- })
- return false
- }
- this.save(done).then(() => {
- if (this.isAdd) {
- this.$refs.table.resetCondition({ name: this.currObj.name })
- } else {
- this.$refs.table.pageTo()
- }
- })
- },
- onViewDevices ({ id }) {
- this.$refs.subDeviceDialog.show({ id })
- },
- getDevicesByGroup ({ id }) {
- return getDevicesByGroup(id)
- },
- onDelDevice (device, index) {
- const table = this.$refs.subDeviceDialog.getTable()
- deleteDeviceFromGroup(table.getCondition().id, device).then(() => {
- table.getData().splice(index, 1)
- })
- },
- onAddDevice () {
- this.$refs.deviceDialog.show()
- },
- onChooseDevice ({ value: { id }, done }) {
- const table = this.$refs.subDeviceDialog.getTable()
- addDeviceToGroup(table.getCondition().id, id).then(() => {
- done()
- table.pageTo()
- })
- }
- }
- }
- </script>
|