index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="设备代码" prop="deviceCode">
  5. <el-input
  6. v-model="queryParams.deviceCode"
  7. placeholder="请输入设备代码"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="设备名称" prop="deviceName">
  13. <el-input
  14. v-model="queryParams.deviceName"
  15. placeholder="请输入设备名称"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="归属区域" prop="refArea">
  21. <el-input
  22. v-model="queryParams.refArea"
  23. placeholder="请输入归属区域"
  24. clearable
  25. @keyup.enter.native="handleQuery"
  26. />
  27. </el-form-item>
  28. <el-form-item label="归属设施" prop="refFacs">
  29. <el-input
  30. v-model="queryParams.refFacs"
  31. placeholder="请输入归属设施"
  32. clearable
  33. @keyup.enter.native="handleQuery"
  34. />
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  38. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  39. </el-form-item>
  40. </el-form>
  41. <el-row :gutter="10" class="mb8">
  42. <el-col :span="1.5">
  43. <el-button
  44. type="primary"
  45. plain
  46. icon="el-icon-plus"
  47. size="mini"
  48. @click="handleAdd"
  49. v-hasPermi="['basecfg:device:add']"
  50. >新增</el-button>
  51. </el-col>
  52. <el-col :span="1.5">
  53. <el-button
  54. type="success"
  55. plain
  56. icon="el-icon-edit"
  57. size="mini"
  58. :disabled="single"
  59. @click="handleUpdate"
  60. v-hasPermi="['basecfg:device:edit']"
  61. >修改</el-button>
  62. </el-col>
  63. <el-col :span="1.5">
  64. <el-button
  65. type="danger"
  66. plain
  67. icon="el-icon-delete"
  68. size="mini"
  69. :disabled="multiple"
  70. @click="handleDelete"
  71. v-hasPermi="['basecfg:device:remove']"
  72. >删除</el-button>
  73. </el-col>
  74. <el-col :span="1.5">
  75. <el-button
  76. type="warning"
  77. plain
  78. icon="el-icon-download"
  79. size="mini"
  80. @click="handleExport"
  81. v-hasPermi="['basecfg:device:export']"
  82. >导出</el-button>
  83. </el-col>
  84. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  85. </el-row>
  86. <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
  87. <el-table-column type="selection" width="55" align="center" />
  88. <el-table-column label="序号" align="center" prop="id" />
  89. <el-table-column label="设备代码" align="center" prop="deviceCode" />
  90. <el-table-column label="设备名称" align="center" prop="deviceName" />
  91. <el-table-column label="设备类型" align="center" prop="deviceType" />
  92. <el-table-column label="设备状态" align="center" prop="deviceStatus" />
  93. <el-table-column label="归属区域" align="center" prop="refArea" />
  94. <el-table-column label="归属设施" align="center" prop="refFacs" />
  95. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  96. <template slot-scope="scope">
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-edit"
  101. @click="handleUpdate(scope.row)"
  102. v-hasPermi="['basecfg:device:edit']"
  103. >修改</el-button>
  104. <el-button
  105. size="mini"
  106. type="text"
  107. icon="el-icon-delete"
  108. @click="handleDelete(scope.row)"
  109. v-hasPermi="['basecfg:device:remove']"
  110. >删除</el-button>
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. <pagination
  115. v-show="total>0"
  116. :total="total"
  117. :page.sync="queryParams.pageNum"
  118. :limit.sync="queryParams.pageSize"
  119. @pagination="getList"
  120. />
  121. <!-- 添加或修改能源设备对话框 -->
  122. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  123. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  124. <el-form-item label="设备代码" prop="deviceCode">
  125. <el-input v-model="form.deviceCode" placeholder="请输入设备代码" />
  126. </el-form-item>
  127. <el-form-item label="设备名称" prop="deviceName">
  128. <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
  129. </el-form-item>
  130. <el-form-item label="设备类型" prop="deviceType">
  131. <el-input v-model="form.deviceType" placeholder="请输入设备类型" />
  132. </el-form-item>
  133. <el-form-item label="归属区域" prop="refArea">
  134. <el-input v-model="form.refArea" placeholder="请输入归属区域" />
  135. </el-form-item>
  136. <el-form-item label="归属设施" prop="refFacs">
  137. <el-input v-model="form.refFacs" placeholder="请输入归属设施" />
  138. </el-form-item>
  139. </el-form>
  140. <div slot="footer" class="dialog-footer">
  141. <el-button type="primary" @click="submitForm">确 定</el-button>
  142. <el-button @click="cancel">取 消</el-button>
  143. </div>
  144. </el-dialog>
  145. </div>
  146. </template>
  147. <script>
  148. import { listDevice, getDevice, delDevice, addDevice, updateDevice } from "@/api/basecfg/device";
  149. export default {
  150. name: "Device",
  151. data() {
  152. return {
  153. // 遮罩层
  154. loading: true,
  155. // 选中数组
  156. ids: [],
  157. // 非单个禁用
  158. single: true,
  159. // 非多个禁用
  160. multiple: true,
  161. // 显示搜索条件
  162. showSearch: true,
  163. // 总条数
  164. total: 0,
  165. // 能源设备表格数据
  166. deviceList: [],
  167. // 弹出层标题
  168. title: "",
  169. // 是否显示弹出层
  170. open: false,
  171. // 查询参数
  172. queryParams: {
  173. pageNum: 1,
  174. pageSize: 10,
  175. deviceCode: null,
  176. deviceName: null,
  177. deviceType: null,
  178. deviceStatus: null,
  179. refArea: null,
  180. refFacs: null,
  181. },
  182. // 表单参数
  183. form: {},
  184. // 表单校验
  185. rules: {
  186. deviceCode: [
  187. { required: true, message: "设备代码不能为空", trigger: "blur" }
  188. ],
  189. deviceName: [
  190. { required: true, message: "设备名称不能为空", trigger: "blur" }
  191. ],
  192. }
  193. };
  194. },
  195. created() {
  196. this.getList();
  197. },
  198. methods: {
  199. /** 查询能源设备列表 */
  200. getList() {
  201. this.loading = true;
  202. listDevice(this.queryParams).then(response => {
  203. this.deviceList = response.rows;
  204. this.total = response.total;
  205. this.loading = false;
  206. });
  207. },
  208. // 取消按钮
  209. cancel() {
  210. this.open = false;
  211. this.reset();
  212. },
  213. // 表单重置
  214. reset() {
  215. this.form = {
  216. id: null,
  217. deviceCode: null,
  218. deviceName: null,
  219. deviceType: null,
  220. deviceStatus: null,
  221. refArea: null,
  222. refFacs: null,
  223. createTime: null,
  224. updateTime: null
  225. };
  226. this.resetForm("form");
  227. },
  228. /** 搜索按钮操作 */
  229. handleQuery() {
  230. this.queryParams.pageNum = 1;
  231. this.getList();
  232. },
  233. /** 重置按钮操作 */
  234. resetQuery() {
  235. this.resetForm("queryForm");
  236. this.handleQuery();
  237. },
  238. // 多选框选中数据
  239. handleSelectionChange(selection) {
  240. this.ids = selection.map(item => item.id)
  241. this.single = selection.length!==1
  242. this.multiple = !selection.length
  243. },
  244. /** 新增按钮操作 */
  245. handleAdd() {
  246. this.reset();
  247. this.open = true;
  248. this.title = "添加能源设备";
  249. },
  250. /** 修改按钮操作 */
  251. handleUpdate(row) {
  252. this.reset();
  253. const id = row.id || this.ids
  254. getDevice(id).then(response => {
  255. this.form = response.data;
  256. this.open = true;
  257. this.title = "修改能源设备";
  258. });
  259. },
  260. /** 提交按钮 */
  261. submitForm() {
  262. this.$refs["form"].validate(valid => {
  263. if (valid) {
  264. if (this.form.id != null) {
  265. updateDevice(this.form).then(response => {
  266. this.$modal.msgSuccess("修改成功");
  267. this.open = false;
  268. this.getList();
  269. });
  270. } else {
  271. addDevice(this.form).then(response => {
  272. this.$modal.msgSuccess("新增成功");
  273. this.open = false;
  274. this.getList();
  275. });
  276. }
  277. }
  278. });
  279. },
  280. /** 删除按钮操作 */
  281. handleDelete(row) {
  282. const ids = row.id || this.ids;
  283. this.$modal.confirm('是否确认删除能源设备编号为"' + ids + '"的数据项?').then(function() {
  284. return delDevice(ids);
  285. }).then(() => {
  286. this.getList();
  287. this.$modal.msgSuccess("删除成功");
  288. }).catch(() => {});
  289. },
  290. /** 导出按钮操作 */
  291. handleExport() {
  292. this.download('ems/basecfg/device/export', {
  293. ...this.queryParams
  294. }, `device_${new Date().getTime()}.xlsx`)
  295. }
  296. }
  297. };
  298. </script>