addAndEdit.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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, getSelectById } 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. var isPhone = (rule, value, callback) => {
  88. let reg = /^1[23456789]\d{9}$/;
  89. let reg1 = /^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/;
  90. if (!reg.test(value)) {
  91. if(reg1.test(value)){
  92. callback();
  93. }
  94. callback(new Error('请输入正确开票电话'));
  95. } else {
  96. callback();
  97. }
  98. };
  99. return {
  100. title: "编辑",
  101. model: "EDIT",
  102. open: false,
  103. loading: false,
  104. form: {
  105. id: undefined,
  106. },
  107. rules: {
  108. name: [{ required: true, message: "请输入主办方名你", trigger: "blur" }],
  109. corporationName: [{ required: true, message: "请输入法人名你", trigger: "blur" }],
  110. contactName: [{ required: true, message: "请输入负责人名你", trigger: "blur" }],
  111. contactMobile: [
  112. { required: true, message: "请输入负责人联系电话", trigger: "blur" },
  113. { validator: isPhone, trigger: 'blur' }
  114. ],
  115. },
  116. uploadObj: {
  117. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  118. Headers: { Authorization: "Bearer " + getToken() },
  119. },
  120. };
  121. },
  122. methods: {
  123. /**
  124. * 打开弹框
  125. * @date 2023-11-22
  126. * @param {any} obj
  127. * @returns {any}
  128. */
  129. openDialog(title, obj) {
  130. this.open = true;
  131. if (obj){
  132. this.title = "编辑";
  133. this.getSelectByIdApi(obj);
  134. }else{
  135. this.title = "新增";
  136. this.$nextTick(() => {
  137. this.$refs["form"].clearValidate();
  138. });
  139. }
  140. },
  141. /** 获取详情 */
  142. getSelectByIdApi(row) {
  143. const id = row.id
  144. getSelectById(id).then(response => {
  145. let obj = response.data;
  146. this.$set(this.form, 'id', obj.id);
  147. this.$set(this.form, 'name', obj.name);
  148. this.$set(this.form, 'corporationName', obj.corporationName);
  149. this.$set(this.form, 'contactName', obj.contactName);
  150. this.$set(this.form, 'contactMobile', obj.contactMobile);
  151. });
  152. },
  153. /**
  154. * 保存
  155. * @date 2023-11-22
  156. * @returns {any}
  157. */
  158. submitForm() {
  159. this.$refs["form"].validate(async (valid) => {
  160. if (valid) {
  161. try {
  162. this.loading = true;
  163. const { code } = await saveAndEdit({ ...this.form });
  164. if (code === 200) {
  165. this.$message.success("修改成功!");
  166. this.$emit("getList");
  167. this.cancel();
  168. }
  169. } catch (error) {
  170. } finally {
  171. this.loading = false;
  172. }
  173. }
  174. });
  175. },
  176. /**
  177. * 重置
  178. * @date 2023-11-22
  179. * @returns {any}
  180. */
  181. reset() {
  182. this.$refs["form"].resetFields();
  183. this.form.id = undefined;
  184. },
  185. /**
  186. * 关闭弹框
  187. * @date 2023-11-22
  188. * @returns {any}
  189. */
  190. cancel() {
  191. this.reset();
  192. this.open = false;
  193. },
  194. /**
  195. * 上传成功
  196. * @date 2023-11-22
  197. * @param {any} res
  198. * @returns {any}
  199. */
  200. handleAvatarSuccess(res) {
  201. if (res.code === 200) {
  202. // this.form.mainImg = res?.data?.url;
  203. this.$set(this.form, 'mainImg', res?.data?.url)
  204. }
  205. },
  206. /**
  207. * 上传文件之前之前
  208. * @date 2023-11-22
  209. * @param {any} file
  210. * @returns {any}
  211. */
  212. beforeAvatarUpload(file) {
  213. const isJPG = file.type === "image/jpeg" || "image/png";
  214. if (!isJPG) {
  215. this.$message.error("上传头像图片只能是jpg或png格式!");
  216. }
  217. return isJPG;
  218. },
  219. },
  220. };
  221. </script>
  222. <style lang="scss" scoped>
  223. .dialog {
  224. padding: 0 30px;
  225. max-height: 65vh;
  226. overflow-y: auto;
  227. }
  228. .dialog {
  229. padding: 0 30px;
  230. .upload-btn {
  231. width: 100px;
  232. height: 100px;
  233. background-color: #fbfdff;
  234. border: dashed 1px #c0ccda;
  235. border-radius: 5px;
  236. i {
  237. font-size: 30px;
  238. margin-top: 20px;
  239. }
  240. &-text {
  241. margin-top: -10px;
  242. }
  243. }
  244. .avatar {
  245. cursor: pointer;
  246. }
  247. }
  248. </style>