addAndEdit.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: Sugar.
  6. * @LastEditTime: 22023-11-24 13:55:00
  7. * @FilePath: \cattle_webui\src\views\distribution\personnelMr\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="type">
  30. <el-select
  31. v-model="form.type"
  32. placeholder="分销商类型"
  33. clearable
  34. style="width: 100%;"
  35. >
  36. <el-option
  37. v-for="dict in dict.type.distribution_type"
  38. :key="dict.value"
  39. :label="dict.label"
  40. :value="dict.value"
  41. />
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="负责人:" prop="contact">
  45. <el-input
  46. v-model="form.contact"
  47. placeholder="负责人"
  48. clearable
  49. style="width: 100%;"
  50. />
  51. </el-form-item>
  52. <el-form-item label="账号/联系电话:" prop="mobile">
  53. <el-input
  54. v-model="form.mobile"
  55. placeholder="联系电话"
  56. clearable
  57. style="width: 100%;"
  58. />
  59. </el-form-item>
  60. <el-form-item label="密码:">
  61. <el-input
  62. show-password
  63. v-model="form.password"
  64. placeholder="密码"
  65. autocomplete="new-password"
  66. clearable
  67. style="width: 100%;"
  68. />
  69. </el-form-item>
  70. </el-form>
  71. </div>
  72. <span slot="footer" class="dialog-footer">
  73. <el-button @click="cancel">取消</el-button>
  74. <el-button
  75. type="primary"
  76. @click="submitForm"
  77. v-loading.fullscreen.lock="loading"
  78. element-loading-text="提交中..."
  79. element-loading-spinner="el-icon-loading"
  80. element-loading-background="rgba(0, 0, 0, 0.8)"
  81. >
  82. <span v-if="loading">提交中...</span>
  83. <span v-else>保存</span>
  84. </el-button>
  85. </span>
  86. </el-dialog>
  87. </template>
  88. <script>
  89. // import { updateNoticeMgr } from "@/api/system/noticeMgr";
  90. import { saveAndEdit, getSelectById } from "@/api/distribution/personnelMr";
  91. import Editor from "@/components/Editor";
  92. import { getToken } from "@/utils/auth";
  93. export default {
  94. name: "addAndEdit",
  95. props: {
  96. dict: {
  97. type: Object,
  98. default: () => [],
  99. },
  100. },
  101. components: {
  102. Editor,
  103. },
  104. data() {
  105. return {
  106. title: "编辑",
  107. model: "EDIT",
  108. activeName: '01',
  109. open: false,
  110. loading: false,
  111. form: {
  112. id: undefined,
  113. },
  114. rules: {
  115. name: [{ required: true, message: "请输入分销商名称", trigger: "blur" }],
  116. type: [{ required: true, message: "请选择分销商类型", trigger: "blur" }],
  117. contact: [{ required: true, message: "请输入负责人", trigger: "blur" }],
  118. mobile: [{ required: true, message: "请输入账号/联系电话", trigger: "blur" }],
  119. },
  120. uploadObj: {
  121. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  122. Headers: { Authorization: "Bearer " + getToken() },
  123. },
  124. };
  125. },
  126. methods: {
  127. /**
  128. * 打开弹框
  129. * @date 2023-11-22
  130. * @param {any} obj
  131. * @returns {any}
  132. */
  133. openDialog(title, obj) {
  134. this.open = true;
  135. this.reset();
  136. if (obj){
  137. this.title = "编辑分销人员";
  138. this.getSelectByIdApi(obj);
  139. }else{
  140. this.title = "添加分销人员";
  141. this.$nextTick(() => {
  142. this.$refs["form"].clearValidate();
  143. });
  144. }
  145. },
  146. /** 获取详情 */
  147. getSelectByIdApi(row) {
  148. const id = row.id
  149. getSelectById(id).then(response => {
  150. const obj = response.data;
  151. this.$nextTick(() => {
  152. this.$set(this.form, 'id', obj.id);
  153. this.$set(this.form, 'name', obj.name);
  154. this.$set(this.form, 'type', obj.type + '');
  155. this.$set(this.form, 'contact', obj.contact);
  156. this.$set(this.form, 'mobile', obj.mobile);
  157. });
  158. });
  159. },
  160. /**
  161. * 保存
  162. * @date 2023-11-22
  163. * @returns {any}
  164. */
  165. submitForm() {
  166. this.$refs["form"].validate(async (valid) => {
  167. if (valid) {
  168. try {
  169. this.loading = true;
  170. const { code } = await saveAndEdit({ ...this.form });
  171. if (code === 200) {
  172. this.$message.success("操作成功!");
  173. this.$emit("getList");
  174. this.cancel();
  175. }
  176. } catch (error) {
  177. } finally {
  178. this.loading = false;
  179. }
  180. }
  181. });
  182. },
  183. /**
  184. * 重置
  185. * @date 2023-11-22
  186. * @returns {any}
  187. */
  188. reset() {
  189. this.$set(this.form, 'id', '');
  190. this.$set(this.form, 'name', '');
  191. this.$set(this.form, 'type', '');
  192. this.$set(this.form, 'contact', '');
  193. this.$set(this.form, 'mobile', '');
  194. this.$set(this.form, 'password', '');
  195. },
  196. /**
  197. * 关闭弹框
  198. * @date 2023-11-22
  199. * @returns {any}
  200. */
  201. cancel() {
  202. this.reset();
  203. this.open = false;
  204. },
  205. /**
  206. * 上传成功
  207. * @date 2023-11-22
  208. * @param {any} res
  209. * @returns {any}
  210. */
  211. handleAvatarSuccess(res) {
  212. if (res.code === 200) {
  213. // this.form.mainImg = res?.data?.url;
  214. this.$set(this.form, 'mainImg', res?.data?.url)
  215. }
  216. },
  217. /**
  218. * 上传文件之前之前
  219. * @date 2023-11-22
  220. * @param {any} file
  221. * @returns {any}
  222. */
  223. beforeAvatarUpload(file) {
  224. const isJPG = file.type === "image/jpeg" || "image/png";
  225. if (!isJPG) {
  226. this.$message.error("上传头像图片只能是jpg或png格式!");
  227. }
  228. return isJPG;
  229. },
  230. /**
  231. * 剧目海报上传成功
  232. * @date 2023-11-22
  233. * @param {any} res
  234. * @returns {any}
  235. */
  236. handlePhotoListSuccess(res) {
  237. if (res.code === 200) {
  238. let photo = {
  239. imageUrl: res?.data?.url,
  240. url: res?.data?.url,
  241. photoType: '2'
  242. }
  243. if(!this.form.photoList){
  244. this.form.photoList = []
  245. }
  246. // this.form.photoList.push(photo);
  247. this.$set(this.form.photoList, this.form.photoList.length, photo);
  248. }
  249. },
  250. handleRemove(file, fileList) {
  251. this.form.photoList.forEach((item, index) => {
  252. if(item.uid == file.uid){
  253. this.form.photoList.splice(index, 1)
  254. }
  255. })
  256. },
  257. },
  258. };
  259. </script>
  260. <style lang="scss" scoped>
  261. .dialog {
  262. padding: 0 30px;
  263. max-height: 65vh;
  264. overflow-y: auto;
  265. }
  266. .dialog {
  267. padding: 0 30px;
  268. .upload-btn {
  269. width: 100px;
  270. height: 100px;
  271. background-color: #fbfdff;
  272. border: dashed 1px #c0ccda;
  273. border-radius: 5px;
  274. i {
  275. font-size: 30px;
  276. margin-top: 20px;
  277. }
  278. &-text {
  279. margin-top: -10px;
  280. }
  281. }
  282. .avatar {
  283. cursor: pointer;
  284. }
  285. }
  286. </style>