vipNewActive.vue 15 KB

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