vipNewActive.vue 13 KB

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