addAndEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. <span style="font-size: 12px;color: #777;">注:负责人姓名必须与微信实名信息一致</span>
  52. </el-form-item>
  53. <el-form-item label="岗位" prop="postLabel">
  54. <el-input v-model="form.postLabel" placeholder="请输入岗位"></el-input>
  55. </el-form-item>
  56. <el-form-item label="销售人员:" prop="salePerson">
  57. <el-input
  58. v-model="form.salePerson"
  59. placeholder="销售人员"
  60. clearable
  61. style="width: 100%;"
  62. />
  63. </el-form-item>
  64. <!-- <el-form-item label="上级分销人员:" prop="parentId">
  65. <el-select
  66. v-model="form.parentId"
  67. filterable
  68. remote
  69. clearable
  70. reserve-keyword
  71. placeholder="请选择上级分销人员"
  72. :remote-method="remoteMethod"
  73. :loading="parentNameLoading">
  74. <el-option
  75. v-for="item in parentNameList"
  76. :key="item.id"
  77. :label="item.name"
  78. :value="item.id">
  79. </el-option>
  80. </el-select>
  81. </el-form-item> -->
  82. <el-form-item label="是否可提现:" prop="allowWithdraw">
  83. <el-radio-group v-model="form.allowWithdraw">
  84. <el-radio v-for="dict in dict.type.user_allow_withdraw"
  85. :key="dict.value"
  86. :label="Number(dict.value)"
  87. >{{ dict.label }}</el-radio>
  88. </el-radio-group>
  89. </el-form-item>
  90. <el-form-item label="账号/联系电话:" prop="mobile">
  91. <el-input
  92. v-model="form.mobile"
  93. placeholder="联系电话"
  94. clearable
  95. style="width: 100%;"
  96. />
  97. </el-form-item>
  98. <el-form-item label="密码:">
  99. <el-input
  100. show-password
  101. v-model="form.password"
  102. placeholder="密码"
  103. autocomplete="new-password"
  104. clearable
  105. style="width: 100%;"
  106. />
  107. </el-form-item>
  108. </el-form>
  109. </div>
  110. <span slot="footer" class="dialog-footer">
  111. <el-button @click="cancel">取消</el-button>
  112. <el-button
  113. type="primary"
  114. @click="submitForm"
  115. v-loading.fullscreen.lock="loading"
  116. element-loading-text="提交中..."
  117. element-loading-spinner="el-icon-loading"
  118. element-loading-background="rgba(0, 0, 0, 0.8)"
  119. >
  120. <span v-if="loading">提交中...</span>
  121. <span v-else>保存</span>
  122. </el-button>
  123. </span>
  124. </el-dialog>
  125. </template>
  126. <script>
  127. // import { updateNoticeMgr } from "@/api/system/noticeMgr";
  128. import { saveAndEdit, getSelectById,pageList } from "@/api/distribution/personnelMr";
  129. import Editor from "@/components/Editor";
  130. import { getToken } from "@/utils/auth";
  131. export default {
  132. name: "addAndEdit",
  133. dicts:['user_allow_withdraw','distribution_type'],
  134. components: {
  135. Editor,
  136. },
  137. data() {
  138. return {
  139. title: "编辑",
  140. model: "EDIT",
  141. activeName: '01',
  142. open: false,
  143. loading: false,
  144. form: {
  145. id: undefined,
  146. },
  147. rules: {
  148. name: [{ required: true, message: "请输入分销商名称", trigger: ["change","blur"] }],
  149. type: [{ required: true, message: "请选择分销商类型", trigger: ["change","blur"] }],
  150. contact: [{ required: true, message: "请输入负责人", trigger: ["change","blur"] }],
  151. mobile: [{ required: true, message: "请输入账号/联系电话", trigger: ["change","blur"] }],
  152. allowWithdraw: [{ required: true, message: "请选择是否可提现", trigger: ["change","blur"] }],
  153. //parentId: [{ required: true, message: "请选择上级分销人员", trigger: ["change","blur"] }],
  154. salePerson: [{ required: true, message: "请输入销售人员名称", trigger: ["change","blur"] }],
  155. postLabel: [{ required: false, message: "请输入岗位", trigger: ["change","blur"] }],
  156. },
  157. uploadObj: {
  158. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  159. Headers: { Authorization: "Bearer " + getToken() },
  160. },
  161. parentNameLoading: false,
  162. parentNameList: [],
  163. parentId: null,
  164. };
  165. },
  166. methods: {
  167. /**
  168. * 打开弹框
  169. * @date 2023-11-22
  170. * @param {any} obj
  171. * @returns {any}
  172. */
  173. openDialog(title, obj) {
  174. this.open = true;
  175. this.parentId = null
  176. this.reset();
  177. this.parentNameList = []
  178. if (obj){
  179. this.title = "编辑分销人员";
  180. this.getSelectByIdApi(obj);
  181. }else{
  182. this.title = "添加分销人员";
  183. this.$nextTick(() => {
  184. this.$refs["form"].clearValidate();
  185. });
  186. }
  187. },
  188. /** 获取详情 */
  189. getSelectByIdApi(row) {
  190. const id = row.id
  191. getSelectById(id).then(response => {
  192. const obj = response.data;
  193. this.parentId = obj.id
  194. if(row.parentId && obj.parentId != 0){
  195. this.getList({id:row.parentId})
  196. }
  197. this.$nextTick(() => {
  198. this.$set(this.form, 'id', obj.id);
  199. this.$set(this.form, 'name', obj.name);
  200. this.$set(this.form, 'type', obj.type + '');
  201. this.$set(this.form, 'contact', obj.contact);
  202. this.$set(this.form, 'mobile', obj.mobile);
  203. this.$set(this.form, 'allowWithdraw', obj.allowWithdraw);
  204. this.$set(this.form, 'parentName', obj.parentName);
  205. this.$set(this.form, 'parentId', obj.parentId && obj.parentId != 0 ? obj.parentId : null);
  206. this.$set(this.form, 'salePerson', obj.salePerson);
  207. this.$set(this.form, 'postLabel', obj.postLabel);
  208. });
  209. });
  210. },
  211. /**
  212. * 保存
  213. * @date 2023-11-22
  214. * @returns {any}
  215. */
  216. submitForm() {
  217. this.$refs["form"].validate(async (valid) => {
  218. if (valid) {
  219. try {
  220. this.loading = true;
  221. const { code } = await saveAndEdit({
  222. ...this.form,
  223. parentId: this.form.parentId && this.form.parentId != 0 ? this.form.parentId : 0
  224. });
  225. if (code === 200) {
  226. this.$message.success("操作成功!");
  227. this.$emit("getList");
  228. this.cancel();
  229. }
  230. } catch (error) {
  231. } finally {
  232. this.loading = false;
  233. }
  234. }
  235. });
  236. },
  237. /**
  238. * 重置
  239. * @date 2023-11-22
  240. * @returns {any}
  241. */
  242. reset() {
  243. this.$set(this.form, 'id', '');
  244. this.$set(this.form, 'name', '');
  245. this.$set(this.form, 'type', '');
  246. this.$set(this.form, 'contact', '');
  247. this.$set(this.form, 'mobile', '');
  248. this.$set(this.form, 'password', '');
  249. this.$set(this.form, 'parentId', '');
  250. this.$set(this.form, 'salePerson', '');
  251. this.$set(this.form, 'postLabel', '');
  252. },
  253. /**
  254. * 关闭弹框
  255. * @date 2023-11-22
  256. * @returns {any}
  257. */
  258. cancel() {
  259. this.reset();
  260. this.open = false;
  261. },
  262. /**
  263. * 上传成功
  264. * @date 2023-11-22
  265. * @param {any} res
  266. * @returns {any}
  267. */
  268. handleAvatarSuccess(res) {
  269. if (res.code === 200) {
  270. // this.form.mainImg = res?.data?.url;
  271. this.$set(this.form, 'mainImg', res?.data?.url)
  272. }
  273. },
  274. /**
  275. * 上传文件之前之前
  276. * @date 2023-11-22
  277. * @param {any} file
  278. * @returns {any}
  279. */
  280. beforeAvatarUpload(file) {
  281. const isJPG = file.type === "image/jpeg" || "image/png";
  282. if (!isJPG) {
  283. this.$message.error("上传头像图片只能是jpg或png格式!");
  284. }
  285. return isJPG;
  286. },
  287. /**
  288. * 剧目海报上传成功
  289. * @date 2023-11-22
  290. * @param {any} res
  291. * @returns {any}
  292. */
  293. handlePhotoListSuccess(res) {
  294. if (res.code === 200) {
  295. let photo = {
  296. imageUrl: res?.data?.url,
  297. url: res?.data?.url,
  298. photoType: '2'
  299. }
  300. if(!this.form.photoList){
  301. this.form.photoList = []
  302. }
  303. // this.form.photoList.push(photo);
  304. this.$set(this.form.photoList, this.form.photoList.length, photo);
  305. }
  306. },
  307. handleRemove(file, fileList) {
  308. this.form.photoList.forEach((item, index) => {
  309. if(item.uid == file.uid){
  310. this.form.photoList.splice(index, 1)
  311. }
  312. })
  313. },
  314. remoteMethod(query) {
  315. if (query !== '') {
  316. this.parentNameLoading = true;
  317. pageList({
  318. name: query
  319. })
  320. .then(response => {
  321. this.parentNameLoading = false;
  322. let list = []
  323. console.log("list===",this.parentId)
  324. response.data.rows.forEach((item,index)=>{
  325. if(this.parentId != item.id) {
  326. list.push(item)
  327. }
  328. })
  329. this.parentNameList = [].concat(list);
  330. this.parentNameLoading = false;
  331. }
  332. ).catch ((error)=>{
  333. console.error('error===',error)
  334. this.parentNameLoading = false;
  335. })
  336. } else {
  337. this.parentNameList = [];
  338. }
  339. },
  340. getList(query) {
  341. if (query !== '') {
  342. this.parentNameLoading = true;
  343. pageList({
  344. ...query
  345. })
  346. .then(response => {
  347. this.parentNameLoading = false;
  348. let list = []
  349. response.data.rows.forEach((item,index)=>{
  350. if(this.parentId != item.id) {
  351. list.push(item)
  352. }
  353. })
  354. this.parentNameList = [].concat(list);
  355. this.parentNameLoading = false;
  356. }
  357. ).catch ((error)=>{
  358. console.error('error===',error)
  359. this.parentNameLoading = false;
  360. })
  361. } else {
  362. this.parentNameList = [];
  363. }
  364. }
  365. },
  366. };
  367. </script>
  368. <style lang="scss" scoped>
  369. .dialog {
  370. padding: 0 30px;
  371. max-height: 65vh;
  372. overflow-y: auto;
  373. }
  374. .dialog {
  375. padding: 0 30px;
  376. .upload-btn {
  377. width: 100px;
  378. height: 100px;
  379. background-color: #fbfdff;
  380. border: dashed 1px #c0ccda;
  381. border-radius: 5px;
  382. i {
  383. font-size: 30px;
  384. margin-top: 20px;
  385. }
  386. &-text {
  387. margin-top: -10px;
  388. }
  389. }
  390. .avatar {
  391. cursor: pointer;
  392. }
  393. }
  394. </style>