addAndEdit.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: Sugar.
  6. * @LastEditTime: 2023-11-24 13:55:00
  7. * @FilePath: \cattle_webui\src\views\performMr\dialog\AddOrEditDialog.vue
  8. * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. :title="title"
  13. :visible.sync="open"
  14. width="700px"
  15. append-to-body
  16. :close-on-click-modal="false"
  17. @close="cancel"
  18. >
  19. <div class="dialog">
  20. <el-form :model="form" ref="form" :rules="rules" label-width="120px">
  21. <el-form-item label="主办方名你" prop="name">
  22. <el-input
  23. v-model="form.name"
  24. placeholder="主办方名你"
  25. clearable
  26. style="width: 100%;"
  27. />
  28. </el-form-item>
  29. <el-form-item label="法人" prop="corporationName">
  30. <el-input
  31. v-model="form.corporationName"
  32. placeholder="法人"
  33. clearable
  34. style="width: 100%;"
  35. />
  36. </el-form-item>
  37. <el-form-item label="负责人" prop="contactName">
  38. <el-input
  39. v-model="form.contactName"
  40. placeholder="负责人"
  41. clearable
  42. style="width: 100%;"
  43. />
  44. </el-form-item>
  45. <el-form-item label="负责人联系电话" prop="contactMobile">
  46. <el-input
  47. v-model="form.contactMobile"
  48. placeholder="负责人联系电话"
  49. clearable
  50. style="width: 100%;"
  51. />
  52. </el-form-item>
  53. </el-form>
  54. </div>
  55. <span slot="footer" class="dialog-footer">
  56. <el-button @click="cancel">取消</el-button>
  57. <el-button
  58. type="primary"
  59. @click="submitForm"
  60. v-loading.fullscreen.lock="loading"
  61. element-loading-text="提交中..."
  62. element-loading-spinner="el-icon-loading"
  63. element-loading-background="rgba(0, 0, 0, 0.8)"
  64. >
  65. <span v-if="loading">提交中...</span>
  66. <span v-else>保存</span>
  67. </el-button>
  68. </span>
  69. </el-dialog>
  70. </template>
  71. <script>
  72. import { saveAndEdit } from "@/api/performMr/performMr";
  73. import Editor from "@/components/Editor";
  74. import { getToken } from "@/utils/auth";
  75. export default {
  76. name: "addAndEdit",
  77. props: {
  78. dict: {
  79. type: Object,
  80. default: () => [],
  81. },
  82. },
  83. components: {
  84. Editor,
  85. },
  86. data() {
  87. return {
  88. title: "编辑",
  89. model: "EDIT",
  90. open: false,
  91. loading: false,
  92. form: {
  93. id: undefined,
  94. },
  95. rules: {
  96. name: [{ required: true, message: "请输入主办方名你", trigger: "blur" }],
  97. corporationName: [{ required: true, message: "请输入法人名你", trigger: "blur" }],
  98. contactName: [{ required: true, message: "请输入负责人名你", trigger: "blur" }],
  99. contactMobile: [{ required: true, message: "请输入负责人联系电话", trigger: "blur" }],
  100. },
  101. uploadObj: {
  102. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  103. Headers: { Authorization: "Bearer " + getToken() },
  104. },
  105. };
  106. },
  107. methods: {
  108. /**
  109. * 打开弹框
  110. * @date 2023-11-22
  111. * @param {any} obj
  112. * @returns {any}
  113. */
  114. openDialog(title, obj) {
  115. this.open = true;
  116. if (obj){
  117. this.title = "编辑";
  118. this.$nextTick(() => {
  119. this.$set(this.form, 'id', obj.id);
  120. this.$set(this.form, 'name', obj.name);
  121. this.$set(this.form, 'corporationName', obj.corporationName);
  122. this.$set(this.form, 'contactName', obj.contactName);
  123. this.$set(this.form, 'contactMobile', obj.contactMobile);
  124. });
  125. }else{
  126. this.title = "新增";
  127. this.$nextTick(() => {
  128. this.$refs["form"].clearValidate();
  129. });
  130. }
  131. },
  132. /**
  133. * 保存
  134. * @date 2023-11-22
  135. * @returns {any}
  136. */
  137. submitForm() {
  138. this.$refs["form"].validate(async (valid) => {
  139. if (valid) {
  140. try {
  141. this.loading = true;
  142. const { code } = await saveAndEdit({ ...this.form });
  143. if (code === 200) {
  144. this.$message.success("操作成功!");
  145. this.$emit("getList");
  146. this.cancel();
  147. }
  148. } catch (error) {
  149. } finally {
  150. this.loading = false;
  151. }
  152. }
  153. });
  154. },
  155. /**
  156. * 重置
  157. * @date 2023-11-22
  158. * @returns {any}
  159. */
  160. reset() {
  161. this.$refs["form"].resetFields();
  162. this.form.id = undefined;
  163. },
  164. /**
  165. * 关闭弹框
  166. * @date 2023-11-22
  167. * @returns {any}
  168. */
  169. cancel() {
  170. this.reset();
  171. this.open = false;
  172. },
  173. /**
  174. * 上传成功
  175. * @date 2023-11-22
  176. * @param {any} res
  177. * @returns {any}
  178. */
  179. handleAvatarSuccess(res) {
  180. if (res.code === 200) {
  181. // this.form.mainImg = res?.data?.url;
  182. this.$set(this.form, 'mainImg', res?.data?.url)
  183. }
  184. },
  185. /**
  186. * 上传文件之前之前
  187. * @date 2023-11-22
  188. * @param {any} file
  189. * @returns {any}
  190. */
  191. beforeAvatarUpload(file) {
  192. const isJPG = file.type === "image/jpeg" || "image/png";
  193. if (!isJPG) {
  194. this.$message.error("上传头像图片只能是jpg或png格式!");
  195. }
  196. return isJPG;
  197. },
  198. },
  199. };
  200. </script>
  201. <style lang="scss" scoped>
  202. .dialog {
  203. padding: 0 30px;
  204. max-height: 65vh;
  205. overflow-y: auto;
  206. }
  207. .dialog {
  208. padding: 0 30px;
  209. .upload-btn {
  210. width: 100px;
  211. height: 100px;
  212. background-color: #fbfdff;
  213. border: dashed 1px #c0ccda;
  214. border-radius: 5px;
  215. i {
  216. font-size: 30px;
  217. margin-top: 20px;
  218. }
  219. &-text {
  220. margin-top: -10px;
  221. }
  222. }
  223. .avatar {
  224. cursor: pointer;
  225. }
  226. }
  227. </style>