<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="喊话标题" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入喊话标题"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['drone:hangar:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['drone:hangar:remove']"
>删除</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="hangarList" @selection-change="handleSelectionChange" :header-cell-style="getRowClass" class="elTable" :cell-style="rowClass" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="ID" align="center" width="120" prop="id" />
<el-table-column label="喊话标题" align="center" width="300" prop="name" />
<el-table-column label="喊话内容" align="center" prop="message" />
<el-table-column label="创建时间" align="center" width="180" prop="createTime" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="260">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['drone:hangar:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['drone:hangar:remove']"
>删除</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-coordinate"
@click="setDefaultJkFun(scope.row)"
v-hasPermi="['drone:hangar:remove']"
>执行</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!--喊话弹框-->
<el-dialog :title="title" :visible.sync="open" width="30%" :close-on-click-modal="false">
<el-form :model="addhForm" label-width="80px" :rules="rulesa" ref="elForm">
<el-row>
<el-col :span="22">
<el-form-item label="标题" prop="name">
<el-input v-model="addhForm.name" placeholder="标题"></el-input>
</el-form-item>
</el-col>
<el-col :span="22">
<el-form-item label="内容" prop="message">
<el-input v-model="addhForm.message" type="textarea" :autosize="{ minRows: 3, maxRows: 5 }"
placeholder="内容"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button type="primary" @click="open = false">取消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { hanHuaAddApi,gethuaMessaheApi,editHuaApi,deleteHuaApi,} from "@/api/hanhua/hanhua";
export default {
name: "Hangar",
data() {
return {
rulesa: {
name: [{
required: true,
message: "不能为空",
trigger: "blur"
}],
message: [{
required: true,
message: "不能为空",
trigger: "blur"
}],
},
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 机库管理表格数据
hangarList: [],
// 弹出层标题
title: "添加喊话",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
},
// 表单参数
addhForm: {
//喊话
name: "",
message: "",
id: "",
},
// 表单校验
rules: {
}
};
},
created() {
this.getList();
},
methods: {
getRowClass({ rowIndex, columnIndex }) {
if (rowIndex == 0) {
return "background:#071641;color:#ffffff;borderColor:#9292A4";
}
},
rowClass() {
return 'background:#071641;color:#ffffff;borderColor:#9292A4'
},
/** 查询机库管理列表 */
getList() {
this.loading = true;
gethuaMessaheApi(this.queryParams).then(response => {
console.log(response);
this.hangarList = response.data;
// if(response.rows.length>0){
// this.total = response.total;
// }
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
//设置默认机库
setDefaultJkFun(row) {},
// 表单重置
reset() {
this.addhForm = {
name: "",
message: "",
id: '',
};
this.resetForm("elForm");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加喊话";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.open=true;
this.addhForm=row;
this.title = "修改喊话";
},
/** 提交按钮 */
submitForm() {
let that=this;
this.$refs["elForm"].validate(valid => {
if (valid) {
console.log(that.addhForm);
if (that.addhForm.id != "") {
editHuaApi(that.addhForm).then(response => {
that.$modal.msgSuccess("修改成功");
that.open = false;
that.getList();
});
} else {
hanHuaAddApi(that.addhForm).then(response => {
that.$modal.msgSuccess("新增成功");
that.open = false;
that.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
var ids =row.id || this.ids;
if(typeof(ids)=="number"){ ids=[ids];}
this.$modal.confirm('是否确认删除喊话编号为"' + ids + '"的数据项?').then(function() {
return deleteHuaApi(ids);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
}
};
</script>