123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <!--
- * @Description: 新增/编辑弹框
- * @Author: 空白格
- * @Date: 2023-07-04 13:55:00
- * @LastEditors: 空白格
- * @LastEditTime: 2023-07-06 09:08:39
- * @FilePath: \cattle_webui\src\views\system\noticeMgr\Dialog\AddOrEditDialog.vue
- * @Copyright: Copyright (c) 2016~2023 by 空白格, All Rights Reserved.
- -->
- <template>
- <el-dialog
- :title="title"
- :visible.sync="open"
- width="700px"
- :close-on-click-modal="false"
- @close="cancel"
- >
- <div class="dialog"
- >
- <el-form
- v-loading="loading"
- :model="form"
- ref="form"
- :rules="rules"
- label-width="120px">
- <el-form-item label="设备名称:" prop="deviceName">
- <el-input v-if="type!=3" v-model="form.deviceName" placeholder="请输入设备名称" />
- <span v-else>{{ form.deviceName }}</span>
- </el-form-item>
- <el-form-item label="设备编号:" prop="deviceNo">
- <el-input v-if="type!=3" v-model="form.deviceNo" placeholder="请输入设备编号" />
- <span v-else>{{ form.deviceNo }}</span>
- </el-form-item>
- <el-form-item label="所在位置:" prop="deviceAddress">
- <el-input v-model="form.deviceAddress" placeholder="请输入所在位置" />
- </el-form-item>
- <el-form-item label="设备类型:" prop="deviceType">
- <dict-tag :options="dict.type.device_sys_type" :value="form.deviceType"/>
- </el-form-item>
- </el-form>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button @click="cancel">关闭</el-button>
- <el-button
- type="primary"
- @click="submitForm"
- :loading="loading"
- element-loading-text="提交中..."
- v-if="type!=3"
- >
- 保存
- </el-button>
- </span>
- </el-dialog>
- </template>
- <script>
- import {
- saveAndAdd,
- saveAndEdit} from "@/api/device/pda";
- export default {
- name: "addAndEdit",
- dicts: ['device_sys_type'],
- data() {
- return {
- title: "编辑",
- type: 0,
- model: "EDIT",
- open: false,
- loading: false,
- form: {},
- rules: {
- deviceName: [{ required: true, message: "请输入设备名称", trigger: "blur" }],
- deviceNo: [
- { required: true, message: "请输入设备编号", trigger: "blur" },
- ],
- deviceType: [
- { required: true, message: "请输入设备类型", trigger: "blur" },
- ],
- deviceAddress: [
- { required: true, message: "请输入所在位置", trigger: "blur" },
- ],
- },
- };
- },
- methods: {
- /**
- * 打开弹框
- * @date 2022-09-20
- * @param {any} obj
- * @returns {any}
- */
- openDialog(title, obj,type) {
- this.title = title;
- this.type = type
- this.open = true;
- if (obj){
- this.$nextTick(() => {
- this.form = Object.assign({},this.form,obj)
- });
- }else{
- this.$nextTick(() => {
- this.$refs["form"].clearValidate();
- this.$set(this.form,'deviceType',5)
- });
- }
- },
- /**
- * 保存
- * @date 2022-09-20
- * @returns {any}
- */
- submitForm() {
- this.$refs["form"].validate(async (valid) => {
- if (valid) {
- try {
- this.loading = true;
- if(this.form.id) {
- const { code } = await saveAndEdit({ ...this.form });
- if (code === 200) {
- this.$message.success("操作成功!");
- this.$emit("getList");
- this.cancel();
- }
- }else {
- const { code } = await saveAndAdd ({ ...this.form });
- if (code === 200) {
- this.$message.success("操作成功!");
- this.$emit("getList");
- this.cancel();
- }
- }
-
- } catch (error) {
- } finally {
- this.loading = false;
- }
- }
- });
- },
- /**
- * 重置
- * @date 2022-09-20
- * @returns {any}
- */
- reset() {
- this.$refs["form"].resetFields();
- this.form.id = undefined;
- },
- /**
- * 关闭弹框
- * @date 2022-09-20
- * @returns {any}
- */
- cancel() {
- this.reset();
- this.open = false;
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .dialog {
- padding: 0 30px;
- max-height: 65vh;
- overflow-y: auto;
- }
- </style>
|