memberSetting.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <!-- -->
  2. <template>
  3. <div>
  4. <el-alert
  5. title="机构学练宝设置"
  6. type="info"
  7. :closable="false"
  8. style="margin-bottom: 20px"
  9. ></el-alert>
  10. <el-form
  11. ref="form"
  12. label-position="top"
  13. :model="form"
  14. label-width="140px"
  15. :inline="true"
  16. >
  17. <el-form-item
  18. label="按天会员激活金额"
  19. prop="day_divide"
  20. :rules="[
  21. { required: true, message: '请输入会员激活金额', trigger: 'blur' }
  22. ]"
  23. >
  24. <el-input
  25. :disabled="isDisabled"
  26. placeholder="请输入会员激活金额"
  27. v-model="form.day_divide"
  28. @keyup.native="keyupEvent($event)"
  29. style="width: 238px;"
  30. >
  31. <div slot="append">元/天/人</div>
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item
  35. label="月度会员激活价"
  36. prop="month_divide"
  37. :rules="[
  38. { required: true, message: '请输入会员激活价', trigger: 'blur' }
  39. ]"
  40. >
  41. <el-input
  42. :disabled="isDisabled"
  43. placeholder="请输入会员激活价"
  44. v-model="form.month_divide"
  45. @keyup.native="keyupEvent($event)"
  46. style="width: 238px;"
  47. >
  48. <div slot="append">元/月/人</div>
  49. </el-input>
  50. </el-form-item>
  51. <!-- <el-form-item
  52. label="季度会员激活价"
  53. prop="quarter_divide"
  54. :rules="[
  55. { required: true, message: '请输入会员激活价', trigger: 'blur' }
  56. ]"
  57. >
  58. <el-input
  59. :disabled="isDisabled"
  60. placeholder="请输入会员激活价"
  61. v-model="form.quarter_divide"
  62. @keyup.native="keyupEvent($event)"
  63. style="width: 238px;"
  64. >
  65. <div slot="append">元/季/人</div>
  66. </el-input>
  67. </el-form-item> -->
  68. <el-form-item
  69. label="半年会员激活价"
  70. prop="half_year_divide"
  71. :rules="[
  72. { required: true, message: '请输入会员激活价', trigger: 'blur' }
  73. ]"
  74. >
  75. <el-input
  76. :disabled="isDisabled"
  77. placeholder="请输入会员激活价"
  78. @keyup.native="keyupEvent($event)"
  79. v-model="form.half_year_divide"
  80. style="width: 238px;"
  81. >
  82. <div slot="append">元/半年/人</div>
  83. </el-input>
  84. </el-form-item>
  85. <el-form-item
  86. label="年度会员激活价"
  87. prop="year_divide"
  88. :rules="[
  89. { required: true, message: '请输入会员激活价', trigger: 'blur' }
  90. ]"
  91. >
  92. <el-input
  93. :disabled="isDisabled"
  94. placeholder="请输入会员激活价"
  95. @keyup.native="keyupEvent($event)"
  96. v-model="form.year_divide"
  97. style="width: 238px;"
  98. >
  99. <div slot="append">元/年/人</div>
  100. </el-input>
  101. </el-form-item>
  102. <el-form-item label="可用教材" prop="teachingMaterialId">
  103. <el-cascader
  104. v-model.trim="form.teachingMaterialId"
  105. :disabled="isDisabled"
  106. v-show="!isDisabled"
  107. style="width: 300px !important"
  108. :options="teachList"
  109. :props="{ multiple: true }"
  110. :show-all-levels="false"
  111. collapse-tags
  112. ref="cascader"
  113. @change="onChange"
  114. clearable
  115. ></el-cascader>
  116. <el-tag
  117. :key="tag.id"
  118. v-show="isDisabled"
  119. v-for="tag in dynamicTags"
  120. :disable-transitions="false"
  121. @close="handleClose(tag)"
  122. >
  123. {{ tag.name }}
  124. </el-tag>
  125. </el-form-item>
  126. </el-form>
  127. </div>
  128. </template>
  129. <script>
  130. // {
  131. // "member_config": {
  132. // "month_divide": "10",
  133. // "quarter_divide": "20",
  134. // "half_year_divide": "30",
  135. // "year_divide": "40"
  136. // },
  137. // "cloud_room_rule": {
  138. // "cloud_room_up_limit": "2",
  139. // "cloud_room_config": {
  140. // "3": "10",
  141. // "4": "20",
  142. // "5": "30"
  143. // }
  144. // }
  145. // }
  146. // import { getSysMusicScoreList } from '@/views/teachManager/api'
  147. import { queryTree } from "../../accompaniment/api";
  148. import _ from "lodash";
  149. export default {
  150. props: ["type", "data"],
  151. data() {
  152. return {
  153. form: {
  154. day_divide: null,
  155. month_divide: null,
  156. quarter_divide: null,
  157. half_year_divide: null,
  158. year_divide: null,
  159. teachingMaterialId: [] // 可用教材
  160. },
  161. teachList: [], // 教材列表
  162. dynamicTags: []
  163. };
  164. },
  165. async mounted() {
  166. await this.__init();
  167. if (this.data) {
  168. const { config, teachingMaterialId } = this.data;
  169. const tmpConfig = config ? JSON.parse(config) : {};
  170. let tempIdArr = [];
  171. if (teachingMaterialId) {
  172. const tempIds = teachingMaterialId.split(",").map(i => Number(i));
  173. tempIds.forEach(id => {
  174. tempIdArr.push(this.formatParentId(id, this.teachList));
  175. });
  176. }
  177. this.form = {
  178. ...tmpConfig.member_config,
  179. teachingMaterialId: tempIdArr
  180. };
  181. this.$nextTick(() => {
  182. this.onChange();
  183. });
  184. }
  185. },
  186. computed: {
  187. isDisabled() {
  188. return this.type == "setting" ? true : false;
  189. }
  190. },
  191. methods: {
  192. async __init() {
  193. try {
  194. // 不管是添加、查看、修改都传-1
  195. const tenantId = -1;
  196. const res = await queryTree({ enable: 1, tenantId, queryType: 'ALL' });
  197. const rows = res.data || [];
  198. rows.forEach(item => {
  199. let children = [];
  200. item.label = item.name;
  201. item.value = item.id;
  202. let childList = item.sysMusicScoreCategoriesList
  203. ? item.sysMusicScoreCategoriesList
  204. : [];
  205. if (childList.length > 0) {
  206. childList.forEach(child => {
  207. child.label = child.name;
  208. child.value = child.id;
  209. child.sysMusicScoreCategoriesList = [];
  210. children.push(child);
  211. });
  212. }
  213. item.children = children.length > 0 ? children : null;
  214. this.teachList.push(item);
  215. });
  216. } catch (e) {
  217. console.log(e);
  218. }
  219. },
  220. onChange() {
  221. let childNodes = this.$refs.cascader.getCheckedNodes(true);
  222. this.dynamicTags = [];
  223. childNodes.forEach(node => {
  224. this.dynamicTags.push({
  225. name: node.label,
  226. id: node.value
  227. });
  228. });
  229. },
  230. formatParentId(id, list, ids = []) {
  231. for (const item of list) {
  232. if (item.sysMusicScoreCategoriesList) {
  233. const cIds = this.formatParentId(
  234. id,
  235. item.sysMusicScoreCategoriesList,
  236. [...ids, item.id]
  237. );
  238. if (cIds.includes(id)) {
  239. return cIds;
  240. }
  241. }
  242. if (item.id === id) {
  243. return [...ids, id];
  244. }
  245. }
  246. return ids;
  247. },
  248. handleClose(tag) {},
  249. onSubmit() {
  250. let status = false;
  251. this.$refs.form.validate(_ => {
  252. status = _;
  253. });
  254. return status;
  255. },
  256. getValues() {
  257. const { teachingMaterialId, ...res } = this.form;
  258. let tempArr = [];
  259. teachingMaterialId.forEach(ids => {
  260. tempArr.push(_.last(ids));
  261. });
  262. return {
  263. member_config: { ...res },
  264. teachingMaterialId: tempArr
  265. };
  266. }
  267. }
  268. };
  269. </script>
  270. <style lang="scss" scoped>
  271. .el-tag + .el-tag {
  272. margin-left: 10px;
  273. }
  274. .el-input,
  275. .el-select,
  276. .el-cascader__dropdown {
  277. width: 300px !important;
  278. }
  279. .el-cascader-menu {
  280. width: 100%;
  281. }
  282. </style>