dataBox.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: 空白格
  4. * @Date: 2023-07-04 13:55:00
  5. * @LastEditors: 空白格
  6. * @LastEditTime: 2023-07-06 09:08:39
  7. * @FilePath: \cattle_webui\src\views\system\noticeMgr\Dialog\AddOrEditDialog.vue
  8. * @Copyright: Copyright (c) 2016~2023 by 空白格, All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. :title="title"
  13. :visible.sync="open"
  14. width="700px"
  15. :close-on-click-modal="false"
  16. @close="cancel"
  17. >
  18. <div class="dialog"
  19. >
  20. <el-form
  21. v-loading="loading"
  22. :model="form"
  23. ref="form"
  24. :rules="rules"
  25. label-width="120px">
  26. <el-form-item label="设备名称:" prop="deviceName">
  27. <el-input v-if="type!=3" v-model="form.deviceName" placeholder="请输入设备名称" />
  28. <span v-else>{{ form.deviceName }}</span>
  29. </el-form-item>
  30. <el-form-item label="设备编号:" prop="deviceNo">
  31. <el-input v-if="type!=3" v-model="form.deviceNo" placeholder="请输入设备编号" />
  32. <span v-else>{{ form.deviceNo }}</span>
  33. </el-form-item>
  34. <el-form-item label="所在位置:" prop="deviceAddress">
  35. <el-input v-model="form.deviceAddress" placeholder="请输入所在位置" />
  36. </el-form-item>
  37. <el-form-item label="设备类型:" prop="deviceType">
  38. <dict-tag :options="dict.type.device_sys_type" :value="form.deviceType"/>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. <span slot="footer" class="dialog-footer">
  43. <el-button @click="cancel">关闭</el-button>
  44. <el-button
  45. type="primary"
  46. @click="submitForm"
  47. :loading="loading"
  48. element-loading-text="提交中..."
  49. v-if="type!=3"
  50. >
  51. 保存
  52. </el-button>
  53. </span>
  54. </el-dialog>
  55. </template>
  56. <script>
  57. import {
  58. saveAndAdd,
  59. saveAndEdit} from "@/api/device/pda";
  60. export default {
  61. name: "addAndEdit",
  62. dicts: ['device_sys_type'],
  63. data() {
  64. return {
  65. title: "编辑",
  66. type: 0,
  67. model: "EDIT",
  68. open: false,
  69. loading: false,
  70. form: {},
  71. rules: {
  72. deviceName: [{ required: true, message: "请输入设备名称", trigger: "blur" }],
  73. deviceNo: [
  74. { required: true, message: "请输入设备编号", trigger: "blur" },
  75. ],
  76. deviceType: [
  77. { required: true, message: "请输入设备类型", trigger: "blur" },
  78. ],
  79. deviceAddress: [
  80. { required: true, message: "请输入所在位置", trigger: "blur" },
  81. ],
  82. },
  83. };
  84. },
  85. methods: {
  86. /**
  87. * 打开弹框
  88. * @date 2022-09-20
  89. * @param {any} obj
  90. * @returns {any}
  91. */
  92. openDialog(title, obj,type) {
  93. this.title = title;
  94. this.type = type
  95. this.open = true;
  96. if (obj){
  97. this.$nextTick(() => {
  98. this.form = Object.assign({},this.form,obj)
  99. });
  100. }else{
  101. this.$nextTick(() => {
  102. this.$refs["form"].clearValidate();
  103. this.$set(this.form,'deviceType',5)
  104. });
  105. }
  106. },
  107. /**
  108. * 保存
  109. * @date 2022-09-20
  110. * @returns {any}
  111. */
  112. submitForm() {
  113. this.$refs["form"].validate(async (valid) => {
  114. if (valid) {
  115. try {
  116. this.loading = true;
  117. if(this.form.id) {
  118. const { code } = await saveAndEdit({ ...this.form });
  119. if (code === 200) {
  120. this.$message.success("操作成功!");
  121. this.$emit("getList");
  122. this.cancel();
  123. }
  124. }else {
  125. const { code } = await saveAndAdd ({ ...this.form });
  126. if (code === 200) {
  127. this.$message.success("操作成功!");
  128. this.$emit("getList");
  129. this.cancel();
  130. }
  131. }
  132. } catch (error) {
  133. } finally {
  134. this.loading = false;
  135. }
  136. }
  137. });
  138. },
  139. /**
  140. * 重置
  141. * @date 2022-09-20
  142. * @returns {any}
  143. */
  144. reset() {
  145. this.$refs["form"].resetFields();
  146. this.form.id = undefined;
  147. },
  148. /**
  149. * 关闭弹框
  150. * @date 2022-09-20
  151. * @returns {any}
  152. */
  153. cancel() {
  154. this.reset();
  155. this.open = false;
  156. },
  157. },
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. .dialog {
  162. padding: 0 30px;
  163. max-height: 65vh;
  164. overflow-y: auto;
  165. }
  166. </style>