123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- <template>
- <div class="app-container">
- <div class="filter-container" style="margin-bottom:20px">
- <el-input style="width: 200px;" class="filter-item" placeholder="所属服务器编号" v-model="listQuery.scode">
- </el-input>
- <el-input style="width: 200px;" class="filter-item" placeholder="采集盒编号" v-model="listQuery.code">
- </el-input>
- <el-button v-waves class="filter-item" style="margin-left: 10px;" @click="handleFilter" type="primary" icon="el-icon-search">查找</el-button>
- <el-button v-waves class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">添加采集盒</el-button>
- </div>
- <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
- style="width: 100%;min-height:550px;">
- <el-table-column width="150px" align="center" label="采集盒编号">
- <template slot-scope="scope">
- <span>{{scope.row.code}}</span>
- </template>
- </el-table-column>
- <el-table-column width="150px" align="center" label="采集盒信道数量">
- <template slot-scope="scope">
- <span>{{scope.row.channels}}</span>
- </template>
- </el-table-column>
- <el-table-column min-width="150px" align="center" label="所属服务器编号">
- <template slot-scope="scope">
- <span>{{scope.row.serverName}}</span>
- </template>
- </el-table-column>
- <el-table-column min-width="200px" align="center" label="备注信息">
- <template slot-scope="scope">
- <span>{{scope.row.remark}}</span>
- </template>
- </el-table-column>
- <el-table-column align="center" label="操作" width="230" class-name="small-padding fixed-width">
- <template slot-scope="scope">
- <el-button v-waves v-waves type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
- <el-button v-waves size="mini" type="danger" @click="handleModifyStatus(scope.row,'deleted')">删除
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <el-dialog title="采集盒配置" ref="ruleForm" :visible.sync="dialogTableVisible" width="860px" @close='closed'>
- <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" class="form-main" label-position='right' status-icon>
- <el-row>
- <el-col :span="12">
- <el-form-item label="采集盒编号" prop="code">
- <el-input placeholder="请输入采集盒编号" v-model="ruleForm2.code"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="采集盒信道数量" prop="channels">
- <el-input placeholder="请输入采集盒信道数量" v-model="ruleForm2.channels"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="所属服务器编号" prop="server">
- <el-autocomplete
- v-model="ruleForm2.server"
- :fetch-suggestions="querySearchAsync"
- placeholder="请选择服务器编号"
- @select="handleSelect">
- </el-autocomplete>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="内部编号" prop="seq">
- <el-input placeholder="请输入内部编号" v-model="ruleForm2.seq"></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="24" >
- <el-form-item label="备注" prop="remark">
- <el-input type="textarea" maxlength=100 v-model="ruleForm2.remark" rows=4></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="24" class="el-btn-col">
- <div class="el-btn-col-box">
- <el-button v-waves type="primary" @click="submitForm('ruleForm2')">确认</el-button>
- <el-button v-waves type="info" @click="resetForm('ruleForm2')">返回</el-button>
- </div>
- </el-col>
- </el-row>
- </el-form>
- </el-dialog>
- <div class="pagination-container" style="text-align:center;">
- <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.pageNo" :page-size="listQuery.pageSize" layout="prev, pager, next, jumper" :total="total">
- </el-pagination>
- </div>
- </div>
- </template>
- <script>
- import { addDevice, updateDevice, deleteDevice, pageQueryDevice, DeviceOfservice, checkDeviceCode, checkDeviceInternalCode, queryServer } from '@/api/collectionbox'
- import waves from '@/directive/waves'
- export default {
- name: 'complexTable',
- directives: {
- waves
- },
- data() {
- var server = (rule, value, callback) => {
- const that = this
- setTimeout(function() {
- if (that.ruleForm2.server === '' || that.ruleForm2.serverId === '') {
- callback(new Error('请选择服务器编号'))
- } else {
- callback()
- }
- }, 300)
- }
- var seq = (rule, value, callback) => {
- if (value === '') {
- callback(new Error('请输入内部编号'))
- } else {
- if (!this.ruleForm2.serverId) {
- callback('请先选择所属服务器编号')
- return
- }
- if (this.edit) {
- checkDeviceInternalCode({ seq: value, id: this.edit, serverId: this.ruleForm2.serverId }).then(response => {
- if (response.data) {
- callback(new Error('内部编号已存在,请重新输入'))
- } else {
- callback()
- }
- })
- } else {
- checkDeviceInternalCode({ seq: value, serverId: this.ruleForm2.serverId }).then(response => {
- if (response.data) {
- callback(new Error('内部编号已存在,请重新输入'))
- } else {
- callback()
- }
- })
- }
- }
- }
- var code = (rule, value, callback) => {
- if (value === '') {
- callback(new Error('请输入采集盒编号'))
- } else {
- if (this.edit) {
- checkDeviceCode({ code: value, id: this.edit }).then(response => {
- if (response.data) {
- callback(new Error('采集盒编号已存在,请重新输入'))
- } else {
- callback()
- }
- })
- } else {
- checkDeviceCode({ code: value }).then(response => {
- if (response.data) {
- callback(new Error('采集盒编号已存在,请重新输入'))
- } else {
- callback()
- }
- })
- }
- }
- }
- return {
- edit: '',
- ruleForm2: {
- code: '',
- channels: '',
- server: '',
- seq: '',
- serverId: '',
- remark: ''
- },
- rules2: {
- code: [
- { required: true, validator: code, trigger: 'blur' }
- ],
- channels: [
- { required: true, message: '请输入采集盒数量', trigger: 'blur' }
- ],
- server: [
- { required: true, validator: server, trigger: 'blur' }
- ],
- seq: [
- { required: true, validator: seq, trigger: 'blur' }
- ]
- },
- timeout: null,
- dialogTableVisible: false,
- tableKey: 0,
- list: null,
- total: null,
- listLoading: true,
- listQuery: {
- scode: '',
- code: '',
- active: 1,
- pageSize: 10,
- pageNo: 1
- }
- }
- },
- filters: {
- typeFilter(type) {
- }
- },
- created() {
- this.getList()
- },
- methods: {
- submitForm(formName) {
- const that = this
- this.$refs[formName].validate((valid) => {
- if (valid) {
- if (!this.edit) {
- addDevice(this.ruleForm2).then(response => {
- this.getList()
- setTimeout(function() {
- that.pop('已成功添加采集盒')
- }, 1000)
- this.resetForm('ruleForm2')
- this.dialogTableVisible = false
- }).catch(error => {
- console.log(error)
- })
- } else {
- const par = this.ruleForm2
- par.id = this.edit
- updateDevice(par).then(response => {
- if (response.success) {
- setTimeout(function() {
- that.pop('已成功更新采集盒')
- }, 1000)
- this.resetForm('ruleForm2')
- this.getList()
- this.dialogTableVisible = false
- this.edit = ''
- this.ruleForm2 = {
- code: '',
- channels: '',
- server: '',
- seq: '',
- serverId: '',
- remark: ''
- }
- }
- })
- }
- }
- })
- },
- resetForm(formName) {
- this.dialogTableVisible = false
- this.$refs[formName].resetFields()
- this.edit = ''
- },
- closed() {
- this.$refs['ruleForm2'].resetFields()
- this.edit = ''
- },
- getList() {
- this.listLoading = true
- pageQueryDevice(this.listQuery).then(response => {
- const $data = response.data.data
- for (let i = 0; i < $data.length; i++) {
- $data[i].serverName = ''
- queryServer({ id: $data[i].serverId }).then(response => {
- $data[i].serverName = response.data.code
- })
- }
- this.list = $data
- this.total = response.data.total
- setTimeout(() => {
- this.listLoading = false
- }, 1.5 * 1000)
- })
- },
- handleFilter() {
- this.listQuery.pageNo = 1
- this.getList()
- },
- handleSizeChange(val) {
- this.listQuery.pageSize = val
- this.getList()
- },
- handleCurrentChange(val) {
- this.listQuery.pageNo = val
- this.getList()
- },
- handleModifyStatus(row, status) {
- this.$confirm('确实要删除:采集盒' + row.code + '吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- center: true
- }).then(() => {
- deleteDevice({ id: row.id }).then(response => {
- if (response.success) {
- this.getList()
- this.pop('已成功删除该采集盒')
-
- type: 'success',
- message: '已成功删除该采集盒!'
- }) */
- }
- })
- }).catch(() => {
- })
- },
- pop($par) {
- this.$confirm($par, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'success',
- showCancelButton: false,
- center: true
- }).then(() => {
- }).catch(() => {
- })
- },
- resetTemp(row) {
- this.ruleForm2 = {
- code: row.code,
- channels: row.channels,
- server: row.serverName,
- seq: row.seq,
- serverId: row.serverId,
- remark: row.remark
- }
- this.edit = row.id
- },
- handleCreate() {
- this.dialogTableVisible = true
- },
- handleUpdate(row) {
- const that = this
- setTimeout(function() {
- that.resetTemp(row)
- }, 500)
- this.dialogTableVisible = true
- },
- querySearchAsync(queryString, cb) {
- this.ruleForm2.serverId = ''
- clearTimeout(this.timeout)
- this.timeout = setTimeout(() => {
- DeviceOfservice({ code: this.ruleForm2.server }).then(response => {
- const $info = response.data
- if ($info.length) {
- const $data = $info.map(item => {
- return { 'value': item.code, 'id': item.id }
- })
- cb($data)
- if ($info.length === 1 && this.ruleForm2.server === $info[0].code) {
- this.ruleForm2.serverId = $info[0].id
- } else {
- this.ruleForm2.serverId = ''
- }
- } else {
- cb([])
- }
- })
- }, 3000 * Math.random())
- },
- handleSelect(item) {
- this.ruleForm2.serverId = item.id
- }
- }
- }
- </script>
- <style rel="stylesheet/scss" lang="scss" scoped>
- .el-autocomplete{
- display: block
- }
- .el-btn-col{
- margin-top: 45px
- }
- .el-form-item{
- margin: 0px 10px
- }
- .el-select{
- width: 100%
- }
- .el-col{
- margin-bottom: 15px
- }
- .el-form-item__label{
- padding: 0px
- }
- </style>
|