vipNewActive.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <div class="m-container">
  3. <!-- <h2><div class="squrt"></div>VIP活动方案新增 </h2> -->
  4. <h2>
  5. <el-page-header @back="onCancel" :content="title"></el-page-header>
  6. </h2>
  7. <div class="m-core">
  8. <el-steps
  9. :active="active"
  10. finish-status="success"
  11. align-center
  12. class="steps"
  13. >
  14. <el-step title="基础信息"></el-step>
  15. <el-step title="缴费信息"></el-step>
  16. <el-step title="课酬信息"></el-step>
  17. </el-steps>
  18. <div class="wrap">
  19. <baseInfo
  20. :baseForm="baseForm"
  21. v-if="active == 1"
  22. ref="baseForm"
  23. @resetPayInfo="resetPayInfo"
  24. @resetBaseChannel="resetBaseChannel"
  25. :isDisabled="isDisabled"
  26. :status="statuss"
  27. />
  28. <payInfo
  29. :payForm="payForm"
  30. ref="payInfo"
  31. :activeType="baseForm.activityType"
  32. :activityChannel="baseForm.activityChannel"
  33. @changeCourseType="changeCourseType"
  34. @changeGiveCourseType="changeGiveCourseType"
  35. @chageSalary="chageSalary"
  36. @resetIsLimitNum="resetIsLimitNum"
  37. v-if="active == 2"
  38. :remberList="remberList"
  39. :isDisabled="isDisabled || statuss != 'DRAFT'"
  40. />
  41. <salaryInfo
  42. ref="salaryInfo"
  43. :salaryForm="salaryForm"
  44. v-if="active == 3"
  45. :activeType="baseForm.activityType"
  46. :payForm="payForm"
  47. :isDisabled="isDisabled || statuss != 'DRAFT'"
  48. :status="statuss"
  49. />
  50. </div>
  51. <el-button
  52. style="margin-top: 12px"
  53. type="primary"
  54. @click="prve"
  55. v-if="active > 1"
  56. >上一步</el-button
  57. >
  58. <el-button
  59. style="margin-top: 12px"
  60. type="primary"
  61. @click="next"
  62. v-if="active < 3"
  63. >下一步</el-button
  64. >
  65. <el-button
  66. style="margin-top: 12px"
  67. type="danger"
  68. @click="save"
  69. v-if="!isDisabled && statuss == 'DRAFT'"
  70. >保存草稿</el-button
  71. >
  72. <el-button
  73. style="margin-top: 12px"
  74. type="danger"
  75. @click="submit"
  76. v-if="active == 3 && !isDisabled && statuss == 'DRAFT'"
  77. >创建活动</el-button
  78. >
  79. <el-button
  80. style="margin-top: 12px"
  81. type="danger"
  82. @click="submit"
  83. v-if="active == 3 && !isDisabled && statuss != 'DRAFT'"
  84. >提交修改</el-button
  85. >
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import baseInfo from "./modals/baseInfo.vue";
  91. import payInfo from "./modals/payInfo.vue";
  92. import salaryInfo from "./modals/salaryInfo.vue";
  93. import { getAllmemberRank } from "@/views/categroyManager/productSystem/api";
  94. import merge from "webpack-merge";
  95. import {
  96. vipGroupCategory,
  97. addVipActive,
  98. resetVipActive,
  99. getVipGroupActivity,
  100. } from "@/api/vipSeting";
  101. import cleanDeep from "clean-deep";
  102. const payBaseForm = {
  103. courseType: "",
  104. vipGroupCategoryIdList: "",
  105. applyToStudentType: [],
  106. teachMode: null,
  107. allowOnlineToOffline: "",
  108. singleCourseTime: null,
  109. isLimitNum: null,
  110. minCourseNum: null,
  111. maxCourseNum: null,
  112. memberRankId: null,
  113. periodEnum: null,
  114. discount: 100,
  115. fullMinusCourseTimes: null,
  116. giveCourseType: null,
  117. giveTeachMode: null,
  118. giveCategoryId: null,
  119. giveSingleCourseTime: null,
  120. giveCourseNum: null,
  121. giveMemberRankId: null,
  122. giveMemberTime: null,
  123. giveAllowOnlineToOffline: null,
  124. };
  125. const baseSalaryForm = {
  126. vipOnlineSalarySettlement: {
  127. salarySettlementType: null,
  128. settlementValue: null,
  129. },
  130. offlineSalarySettlement: {
  131. salarySettlementType: null,
  132. settlementValue: null,
  133. },
  134. giveVipOnlineSalarySettlement: {
  135. salarySettlementType: null,
  136. settlementValue: null,
  137. },
  138. giveVipOfflineSalarySettlement: {
  139. salarySettlementType: null,
  140. settlementValue: null,
  141. },
  142. practiceSalarySettlement: {
  143. salarySettlementType: null,
  144. settlementValue: null,
  145. },
  146. givePracticeSalarySettlement: {
  147. salarySettlementType: null,
  148. settlementValue: null,
  149. },
  150. };
  151. export default {
  152. components: {
  153. baseInfo,
  154. payInfo,
  155. salaryInfo,
  156. },
  157. data() {
  158. return {
  159. status: "DRAFT",
  160. active: 1,
  161. baseForm: {
  162. name: "",
  163. description: "",
  164. activeTime: [],
  165. courseTime: [],
  166. organ: [],
  167. activityType: "",
  168. applyToStudentType: [],
  169. studentMaxUsedTimes: "",
  170. isPayToBalance: "",
  171. marketPrice: "",
  172. activityChannel: null,
  173. originalPrice:null
  174. },
  175. title: "新建课程活动方案",
  176. payForm: {
  177. ...payBaseForm,
  178. },
  179. salaryForm: {
  180. ...baseSalaryForm,
  181. },
  182. remberList: [],
  183. };
  184. },
  185. async mounted() {
  186. try {
  187. const res = await getAllmemberRank({ isDefault: 0 });
  188. this.remberList = res.data;
  189. } catch {}
  190. if (this.$route.query.id) {
  191. this.baseForm.id = this.$route.query.id;
  192. const rusult = await getVipGroupActivity({ id: this.$route.query.id });
  193. this.formatDetail(rusult.data);
  194. this.$router
  195. } else {
  196. this.payInfo = { ...payBaseForm };
  197. this.salaryForm = JSON.parse(JSON.stringify({ ...baseSalaryForm }));
  198. }
  199. },
  200. methods: {
  201. onCancel() {
  202. // if (this.active > 1) {
  203. // this.active--;
  204. // console.log(this.active);
  205. // } else {
  206. this.$store.dispatch("delVisitedViews", this.$route);
  207. this.$router.push({
  208. path: "/vipActiveManager/vipActiveList",
  209. query: { rules: this.rules, searchForm: this.searchForm },
  210. });
  211. // }
  212. },
  213. next() {
  214. let flags = true;
  215. if (this.active == 1) {
  216. this.$refs.baseForm.$refs.vipform.validate((flag) => {
  217. flags = flag;
  218. });
  219. // 验证表单1
  220. } else if (this.active == 2) {
  221. // 验证表单2
  222. this.$refs.payInfo.$refs.form.validate((flag) => {
  223. flags = flag;
  224. });
  225. }
  226. if (!flags) {
  227. return;
  228. }
  229. if (this.active < 3) {
  230. this.active++;
  231. }
  232. },
  233. prve() {
  234. if (this.active >= 2) {
  235. this.active--;
  236. }
  237. },
  238. resetPayInfo() {
  239. this.payForm = {
  240. ...payBaseForm,
  241. };
  242. },
  243. resetBaseChannel(val) {
  244. this.$set(this.baseForm, "courseTime", []);
  245. this.$set(this.baseForm, "activityType", null);
  246. this.$set(this.baseForm, "applyToStudentType", []);
  247. this.$set(this.baseForm, "studentMaxUsedTimes", null);
  248. this.$set(this.baseForm, "isPayToBalance", null);
  249. this.$set(this.baseForm, "marketPrice", null);
  250. this.$set(this.baseForm, "originalPrice", null);
  251. if(val == 1){
  252. this.$set(this.baseForm, "activityType", 0);
  253. this.$set(this.payForm, "allowOnlineToOffline",1);
  254. this.$set(this.payForm, "teachMode", -1);
  255. }
  256. },
  257. changeCourseType(val) {
  258. // this.$emit("changeCourseType", val);
  259. if (val == "PRACTICE") {
  260. this.$set(this.payForm, "vipGroupCategoryIdList", "");
  261. this.$set(this.payForm, "teachMode", "");
  262. this.$set(this.payForm, "singleCourseTime", 25);
  263. this.$set(this.payForm, "allowOnlineToOffline", '');
  264. } else {
  265. this.$set(this.payForm, "singleCourseTime", 45);
  266. this.$set(this.payForm, "allowOnlineToOffline", '');
  267. this.$set(this.payForm, "vipGroupCategoryIdList", "");
  268. this.$set(this.payForm, "teachMode", "");
  269. }
  270. // vip
  271. // 课程形式
  272. // 上课模式
  273. // 单课时长
  274. // 课程调整方式
  275. // PRACTICE
  276. },
  277. changeGiveCourseType(val) {
  278. if (val == "PRACTICE") {
  279. this.$set(this.payForm, "giveSingleCourseTime", 25);
  280. } else if (val == "VIP") {
  281. this.$set(this.payForm, "giveSingleCourseTime", 45);
  282. } else {
  283. this.$set(this.payForm, "giveSingleCourseTime", null);
  284. }
  285. this.$set(this.payForm, "giveCourseNum", null);
  286. this.$set(this.payForm, "giveCategoryId", null);
  287. this.$set(this.payForm, "giveMemberRankId", null);
  288. this.$set(this.payForm, "givePeriod", null);
  289. this.$set(this.payForm, "giveTeachMode", "");
  290. this.$set(this.payForm, "giveAllowOnlineToOffline", "");
  291. },
  292. chageSalary() {
  293. this.salaryForm = null;
  294. this.salaryForm = JSON.parse(JSON.stringify({ ...baseSalaryForm }));
  295. this.$forceUpdate();
  296. },
  297. resetIsLimitNum() {
  298. this.$set(this.payForm, "maxCourseNum", null);
  299. this.$set(this.payForm, "minCourseNum", null);
  300. },
  301. async submit() {
  302. if (this.$refs?.salaryInfo?.$refs?.salaryForm) {
  303. this.$refs.salaryInfo.$refs.salaryForm.validate((flag) => {
  304. if (flag) {
  305. this.baseForm.status = "PROGRESS";
  306. this.submitDataFormat("PROGRESS");
  307. }
  308. });
  309. } else {
  310. this.baseForm.status = "PROGRESS";
  311. this.submitDataFormat("PROGRESS");
  312. }
  313. },
  314. save() {
  315. this.baseForm.status = "DRAFT";
  316. this.submitDataFormat("DRAFT");
  317. },
  318. submitDataFormat(status) {
  319. let coursesStartTime = null,
  320. coursesEndTime = null,
  321. startTime = null,
  322. endTime = null;
  323. if (this.baseForm.courseTime && this.baseForm.courseTime.length > 0) {
  324. coursesStartTime = this.baseForm.courseTime[0];
  325. coursesEndTime = this.baseForm.courseTime[1];
  326. }
  327. if (this.baseForm.activeTime && this.baseForm.activeTime.length > 0) {
  328. startTime = this.baseForm.activeTime[0];
  329. endTime = this.baseForm.activeTime[1];
  330. }
  331. let organId = this.baseForm.organ.join(",");
  332. this.baseForm.studentMaxUsedTimes
  333. ? this.baseForm.studentMaxUsedTimes
  334. : (this.baseForm.studentMaxUsedTimes = -1);
  335. for (let item in this.salaryForm) {
  336. if (this.salaryForm[item].salarySettlementType == "TEACHER_DEFAULT") {
  337. this.salaryForm[item].settlementValue = null;
  338. }
  339. }
  340. let applyToStudentType = this.baseForm.applyToStudentType.join(",");
  341. // let vipGroupCategoryIdList =
  342. // this.payForm.vipGroupCategoryIdList.join(",");
  343. let vipGroupSalarySettlement = this.salaryForm;
  344. if(this.baseForm.activityChannel == 1){
  345. this.payForm.maxCourseNum = this.payForm.minCourseNum;
  346. }
  347. let obj = {
  348. ...this.baseForm,
  349. ...this.payForm,
  350. organId,
  351. coursesStartTime,
  352. coursesEndTime,
  353. startTime,
  354. endTime,
  355. applyToStudentType,
  356. vipGroupSalarySettlement,
  357. };
  358. if (this.baseForm.id) {
  359. resetVipActive(cleanDeep(obj)).then((res) => {
  360. if (res.code == 200) {
  361. if (status == "DRAFT") {
  362. this.$message.success("恭喜你,保存草稿成功");
  363. this.baseForm.id = res.data.id;
  364. this.$router.push({
  365. query: merge(this.$route.query, {
  366. id: res.data.id,
  367. }),
  368. });
  369. this.formatDetail(res.data);
  370. } else {
  371. localStorage.removeItem("newVip");
  372. localStorage.removeItem(`newPractice`);
  373. this.$message.success("活动修改成功");
  374. this.$store.dispatch("delVisitedViews", this.$route);
  375. this.$router.push({
  376. path: "/vipActiveManager/vipActiveList",
  377. });
  378. }
  379. // this.onReSet();
  380. // this.$store.dispatch("delVisitedViews", this.$route);
  381. // this.$router.push({
  382. // path: "/vipActiveManager/vipActiveList",
  383. // });
  384. }
  385. });
  386. } else {
  387. addVipActive(cleanDeep(obj)).then((res) => {
  388. if (res.code == 200) {
  389. if (status == "DRAFT") {
  390. this.$message.success("恭喜你,保存草稿成功");
  391. this.baseForm.id = res.data.id;
  392. this.$nextTick(() => {
  393. this.formatDetail(res.data);
  394. });
  395. this.$router.push({
  396. query: merge(this.$route.query, {
  397. id: res.data.id,
  398. }),
  399. });
  400. } else {
  401. this.$message.success("活动创建成功");
  402. this.$store.dispatch("delVisitedViews", this.$route);
  403. this.$router.push({
  404. path: "/vipActiveManager/vipActiveList",
  405. });
  406. }
  407. }
  408. });
  409. }
  410. },
  411. formatDetail(data) {
  412. this.status = data.status;
  413. for (let item in data) {
  414. if (!(item == "teachMode" || item == "giveTeachMode")) {
  415. if (data[item] == -1) {
  416. data[item] = null;
  417. }
  418. }
  419. }
  420. let activeTime = [];
  421. let courseTime = [];
  422. this.title = data.name;
  423. if (data.startTime) {
  424. activeTime = [data.startTime, data.endTime];
  425. }
  426. if (data.coursesStartTime) {
  427. courseTime = [data.coursesStartTime, data.coursesEndTime];
  428. }
  429. let applyToStudentType = data.applyToStudentType
  430. ? data.applyToStudentType.split(",")
  431. : [];
  432. // 格式化 baseForm
  433. this.$set(this, "baseForm", {
  434. name: data.name,
  435. description: data.description,
  436. activeTime,
  437. courseTime,
  438. marketPrice: data.marketPrice,
  439. organ: data.organId.split(",").map((organ) => {
  440. return Number(organ);
  441. }),
  442. activityType: data.activityType,
  443. applyToStudentType,
  444. studentMaxUsedTimes: data.studentMaxUsedTimes,
  445. isPayToBalance: Number(data.payToBalance),
  446. id: this.$route.query.id,
  447. activityChannel: data.activityChannel,
  448. originalPrice:data.originalPrice
  449. });
  450. // this.baseForm = {
  451. // name: data.name,
  452. // description: data.description,
  453. // activeTime,
  454. // courseTime,
  455. // marketPrice: data.marketPrice,
  456. // organ: data.organId.split(",").map((organ) => {
  457. // return Number(organ);
  458. // }),
  459. // activityType: data.activityType,
  460. // applyToStudentType,
  461. // studentMaxUsedTimes,
  462. // isPayToBalance: Number(data.payToBalance),
  463. // id: this.$route.query.id,
  464. // };
  465. // this.$set()
  466. //格式化payForm
  467. // console.log(data.vipGroupCategoryIdList
  468. // .split(",")
  469. // .map((id) => {
  470. // return Number(id);
  471. // }),)
  472. this.payForm = {
  473. courseType: data.courseType,
  474. vipGroupCategoryIdList: data.vipGroupCategoryIdList
  475. ? data.vipGroupCategoryIdList.split(",").map((id) => {
  476. return Number(id);
  477. })[0]
  478. : null,
  479. teachMode: data.teachMode + "",
  480. allowOnlineToOffline: data.allowOnlineToOffline + "",
  481. singleCourseTime: data.singleCourseTime,
  482. isLimitNum: data.minCourseNum ? true : false,
  483. minCourseNum: data.minCourseNum,
  484. maxCourseNum: data.maxCourseNum,
  485. memberRankId: data.memberRankId,
  486. periodEnum: data.periodEnum,
  487. discount: data.discount,
  488. fullMinusCourseTimes: data.fullMinusCourseTimes,
  489. giveCourseType: data.giveCourseType,
  490. giveTeachMode: data.giveTeachMode + "",
  491. giveCategoryId:
  492. data.giveCategoryId * 1 ? data.giveCategoryId * 1 : null,
  493. giveSingleCourseTime: data.giveSingleCourseTime,
  494. giveCourseNum: data.giveCourseNum,
  495. giveMemberRankId: data.giveMemberRankId,
  496. givePeriod: data.givePeriodEnum,
  497. giveMemberTime: data.giveMemberTime ? data.giveMemberTime : null,
  498. giveAllowOnlineToOffline: data.giveAllowOnlineToOffline + "",
  499. };
  500. // 格式化缴费金额
  501. if (data.salarySettlementJson && data.salarySettlementJson != "null") {
  502. this.salaryForm = JSON.parse(JSON.stringify({ ...baseSalaryForm }));
  503. let result = JSON.parse(data.salarySettlementJson);
  504. for (let key in result) {
  505. this.salaryForm[key] = result[key];
  506. }
  507. } else {
  508. this.salaryForm = JSON.parse(JSON.stringify({ ...baseSalaryForm }));
  509. }
  510. this.$forceUpdate();
  511. },
  512. },
  513. computed: {
  514. isDisabled() {
  515. if (this.$route.query.type == "look") {
  516. return true;
  517. } else {
  518. return false;
  519. }
  520. },
  521. statuss() {
  522. return this.status;
  523. },
  524. },
  525. };
  526. </script>
  527. <style lang="scss" scoped>
  528. .steps {
  529. margin-top: 30px;
  530. }
  531. ::v-deep .is-success {
  532. color: var(--color-primary) !important;
  533. border-color: var(--color-primary) !important;
  534. }
  535. </style>