createMember.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <div>
  3. <!-- <p class="title">已选择{{ multipleSelection.length }}名学员</p> -->
  4. <el-form :model="memberForm" label-width="110px" ref="memberForm">
  5. <el-form-item label="学练宝版本" prop="memberRankId" :rules="[
  6. { required: true, message: '请选择学练宝版本', trigger: 'blur' }
  7. ]">
  8. <el-cascader
  9. v-model.trim="memberForm.memberRankId"
  10. style="width: 100% !important"
  11. :options="memberRankList"
  12. :props="{ value: 'id', label: 'name', }"
  13. :show-all-levels="false"
  14. collapse-tags
  15. clearable
  16. @change="getMemberList"
  17. placeholder="请选择学练宝版本"
  18. ></el-cascader>
  19. <!-- <el-select
  20. placeholder="请选择学练宝版本"
  21. clearable
  22. v-model.trim="memberForm.memberRankId"
  23. @change="getMemberList"
  24. style="width: 100% !important"
  25. >
  26. <el-option v-for="(item, index) in memberFeeSettingList" :key="index" :label="item.rankName" :value="item.id"></el-option>
  27. </el-select> -->
  28. </el-form-item>
  29. <el-form-item
  30. label="学练宝周期"
  31. prop="period"
  32. :rules="[
  33. { required: true, message: '请选择学练宝周期', trigger: 'blur' }
  34. ]"
  35. >
  36. <el-select
  37. placeholder="学练宝周期"
  38. clearable
  39. v-model.trim="memberForm.period"
  40. @change="getMemberList"
  41. style="width: 100% !important"
  42. >
  43. <el-option label="月度" value="MONTH"></el-option>
  44. <!-- <el-option label="季度" value="QUARTERLY"></el-option> -->
  45. <el-option label="半年" value="YEAR_HALF"></el-option>
  46. <el-option label="年度" value="YEAR"></el-option>
  47. <!-- <el-option label="固定天数" value="DAY"></el-option> -->
  48. </el-select>
  49. </el-form-item>
  50. <el-form-item
  51. label="学练宝周期数"
  52. prop="memberNum"
  53. :rules="[
  54. { required: true, message: '请输入学练宝周期数', trigger: 'blur' }
  55. ]"
  56. >
  57. <el-input
  58. type="number"
  59. @input="getMemberList"
  60. onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
  61. v-model="memberForm.memberNum"
  62. placeholder="请输入学练宝周期数"
  63. >
  64. </el-input>
  65. </el-form-item>
  66. <el-form-item
  67. label="缴费金额"
  68. prop="actualAmount"
  69. :rules="[
  70. { required: true, message: '请输入缴费金额', trigger: 'blur' },
  71. { validator: validateMember, trigger: 'blur' }
  72. ]"
  73. >
  74. <!-- onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" -->
  75. <el-input
  76. type="number"
  77. @keyup.native="keyupEvent($event)"
  78. v-model="memberForm.actualAmount"
  79. placeholder="请输入缴费金额"
  80. >
  81. <div slot="append">元/人</div>
  82. </el-input>
  83. </el-form-item>
  84. <p style="color: red; padding: 0 0 20px 100px">
  85. 若修改默认金额需审核通过后生效
  86. </p>
  87. <el-form-item
  88. label="备注"
  89. prop="remark"
  90. :rules="[{ required: true, message: '请输入备注', trigger: 'blur' }]"
  91. >
  92. <el-input
  93. type="textarea"
  94. show-word-limit
  95. maxlength="100"
  96. :rows="3"
  97. v-model.trim="memberForm.remark"
  98. placeholder="请输入备注"
  99. ></el-input>
  100. </el-form-item>
  101. </el-form>
  102. </div>
  103. </template>
  104. <script>
  105. import { add, update } from "../api";
  106. import { getmemberRankOrganizationFeeMapper, getAllMemberFindByOrganIds } from "@/views/categroyManager/productSystem/api";
  107. import { sysConfigList } from "@/api/generalSettings"; // 平台的修改和查
  108. export default {
  109. props: ["multipleSelection", "type"],
  110. data() {
  111. return {
  112. memberForm: {
  113. memberRankId: [],
  114. memberNum: null,
  115. actualAmount: null,
  116. period: null,
  117. remark: null
  118. },
  119. userIds: [],
  120. memberRankList: [],
  121. organId: null,
  122. rulesForm: null, // 范围
  123. memberFeeSettingList: [],
  124. memberFeeSetting: null
  125. };
  126. },
  127. async mounted() {
  128. if (this.type == "update") {
  129. const {
  130. memberNum,
  131. actualAmount,
  132. memberRankSettingId,
  133. period,
  134. remark,
  135. organId,
  136. id
  137. } = this.multipleSelection;
  138. this.organId = organId;
  139. // const memberInfo = await getAllMemberFindByOrganIds([organId])
  140. // this.memberRankList = memberInfo.data || []
  141. this.memberForm = {
  142. memberNum,
  143. memberRankId: memberRankSettingId, // this.formatParentId(memberRankSettingId, this.memberRankList),
  144. period,
  145. actualAmount,
  146. remark,
  147. id
  148. };
  149. } else {
  150. this.userIds = this.multipleSelection.map(stu => {
  151. return stu.userId;
  152. });
  153. this.organId = this.multipleSelection[0].organId; //
  154. // const memberInfo = await getAllMemberFindByOrganIds([this.organId])
  155. // this.memberRankList = memberInfo.data || []
  156. }
  157. this.__init();
  158. },
  159. methods: {
  160. formatParentId(id, list, ids = []) {
  161. for (const item of list) {
  162. if (item.children) {
  163. const cIds = this.formatParentId(
  164. id,
  165. item.children,
  166. [...ids, item.id]
  167. );
  168. if (cIds.includes(id)) {
  169. return cIds;
  170. }
  171. }
  172. if (item.id === id) {
  173. return [...ids, id];
  174. }
  175. }
  176. return ids;
  177. },
  178. async __init() {
  179. try {
  180. const res = await sysConfigList({ group: "DEFAULT" });
  181. const paramName = "cloud_price_range";
  182. res.data.forEach(item => {
  183. if (item.paramName == paramName) {
  184. const itemValue = item.paranValue
  185. ? JSON.parse(item.paranValue)
  186. : null;
  187. if (itemValue) {
  188. this.rulesForm = itemValue;
  189. }
  190. }
  191. });
  192. // const rankInfo = await getmemberRankOrganizationFeeMapper({
  193. // page: 1,
  194. // rows: 10,
  195. // organId: this.organId
  196. // });
  197. // const { rows } = rankInfo.data;
  198. // this.memberFeeSettingList = rows || [];
  199. // if (this.memberFeeSettingList.length <= 0) {
  200. // this.$bus.$emit("showguide", ["memberList"]);
  201. // }
  202. const rankInfo = await getAllMemberFindByOrganIds([this.organId], true)
  203. this.memberRankList = rankInfo.data || []
  204. if (this.type == "update") {
  205. const { memberRankSettingId } = this.multipleSelection;
  206. this.memberForm.memberRankId = this.formatParentId(memberRankSettingId, this.memberRankList);
  207. this.$forceUpdate()
  208. }
  209. } catch (e) {}
  210. },
  211. getMemberList() {
  212. let money = 0;
  213. const memberForm = this.memberForm;
  214. let memberFeeSetting = null
  215. const memberRankId = this.memberForm.memberRankId || []
  216. this.memberRankList.forEach(item => {
  217. if(item.id === memberRankId[0]) {
  218. item.children.forEach(child => {
  219. if(child.id === memberRankId[1]) {
  220. memberFeeSetting = child.memberFeeSetting
  221. }
  222. })
  223. }
  224. })
  225. if (memberFeeSetting) {
  226. switch (memberForm?.period) {
  227. case "MONTH": {
  228. money = Number(
  229. memberFeeSetting.groupPurchaseMonthFee * memberForm.memberNum
  230. );
  231. break;
  232. }
  233. case "QUARTERLY": {
  234. money = Number(
  235. memberFeeSetting.groupPurchaseQuarterlyFee * memberForm.memberNum
  236. );
  237. break;
  238. }
  239. case "YEAR_HALF": {
  240. money = Number(
  241. memberFeeSetting.groupPurchaseHalfYearFee * memberForm.memberNum
  242. );
  243. break;
  244. }
  245. case "YEAR": {
  246. money = Number(
  247. memberFeeSetting.groupPurchaseYearFee * memberForm.memberNum
  248. );
  249. break;
  250. }
  251. }
  252. }
  253. if (memberForm.memberNum && memberForm.period) {
  254. this.memberForm.actualAmount = money;
  255. }
  256. },
  257. submit() {
  258. this.$refs.memberForm.validate(async res => {
  259. console.log(res, this.type, "res");
  260. if (res) {
  261. try {
  262. let rankId = null
  263. if(this.memberForm.memberRankId && this.memberForm.memberRankId.length > 0) {
  264. rankId = this.memberForm.memberRankId[this.memberForm.memberRankId.length - 1]
  265. }
  266. if (this.type == "update") {
  267. await update({
  268. ...this.memberForm,
  269. memberRankSettingId: rankId,
  270. organId: this.organId
  271. });
  272. this.$message.success("创建学练宝成功");
  273. } else {
  274. await add({
  275. ...this.memberForm,
  276. memberRankSettingId: rankId,
  277. userIds: this.userIds,
  278. organId: this.organId
  279. });
  280. this.$message.success("创建学练宝成功");
  281. }
  282. this.$emit("close");
  283. this.$emit("submited");
  284. } catch (e) {
  285. console.log(e);
  286. }
  287. }
  288. });
  289. },
  290. validateMember(rule, value, callback) {
  291. const one = Number(value);
  292. let min = 0;
  293. let max = 0;
  294. switch (this.memberForm?.period) {
  295. case "MONTH": {
  296. min = Number(this.rulesForm.minMonthFee) * this.memberForm.memberNum;
  297. max = Number(this.rulesForm.maxMonthFee) * this.memberForm.memberNum;
  298. break;
  299. }
  300. case "QUARTERLY": {
  301. min =
  302. Number(this.rulesForm.minQuarterlyFee) * this.memberForm.memberNum;
  303. max =
  304. Number(this.rulesForm.maxQuarterlyFee) * this.memberForm.memberNum;
  305. break;
  306. }
  307. case "YEAR_HALF": {
  308. min =
  309. Number(this.rulesForm.minHalfYearFee) * this.memberForm.memberNum;
  310. max =
  311. Number(this.rulesForm.maxHalfYearFee) * this.memberForm.memberNum;
  312. break;
  313. }
  314. case "YEAR": {
  315. min = Number(this.rulesForm.minYearFee) * this.memberForm.memberNum;
  316. max = Number(this.rulesForm.maxYearFee) * this.memberForm.memberNum;
  317. break;
  318. }
  319. }
  320. if (one >= min && one <= max) {
  321. return callback();
  322. }
  323. return callback(new Error(`定价应在${min}-${max}之间`));
  324. }
  325. }
  326. };
  327. </script>
  328. <style lang="scss" scoped>
  329. .title {
  330. margin-bottom: 30px;
  331. font-size: 16px;
  332. color: #000;
  333. }
  334. </style>