vipNewActive.vue 16 KB

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