addStudentSenior.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <div>
  3. <el-alert title="资格信息" :closable="false" class="alert" type="info" />
  4. <el-form :inline="true" :model="topForm" label-width="110px" ref="form">
  5. <el-row>
  6. <el-col :span="12">
  7. <el-form-item
  8. label="付费课资格:"
  9. prop="paySeniorNum"
  10. style="width: 100%"
  11. :rules="[
  12. { required: true, message: '请输入资格数', trigger: 'blur' },
  13. {
  14. pattern: /^(0|\+?[1-9][0-9]*)$/,
  15. message: '请输入正确的资格数',
  16. trigger: 'blur',
  17. },
  18. ]"
  19. >
  20. <el-input
  21. v-model="topForm.paySeniorNum"
  22. style="width: 370px"
  23. ></el-input>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="12">
  27. <el-form-item
  28. label="赠课资格:"
  29. v-if="hasGive"
  30. :rules="[
  31. { required: true, message: '请输入赠课资格数', trigger: 'blur' },
  32. {
  33. pattern: /^(0|\+?[1-9][0-9]*)$/,
  34. message: '请输入正确的赠课资格数',
  35. trigger: 'blur',
  36. },
  37. ]"
  38. >
  39. <el-input
  40. v-model="topForm.giveSeniorNum"
  41. style="width: 370px"
  42. ></el-input>
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. <el-row>
  47. <el-form-item
  48. label="备注:"
  49. prop="memo"
  50. :rules="[{ required: true, message: '请输入备注', trigger: 'blur' }]"
  51. >
  52. <el-input
  53. type="textarea"
  54. :rows="3"
  55. v-model="topForm.memo"
  56. style="width: 370px"
  57. maxlength="50"
  58. show-word-limit
  59. ></el-input>
  60. </el-form-item>
  61. </el-row>
  62. <!-- <p style="color: red; margin-bottom: 20px">
  63. 资格调整不影响该活动学员购买次数
  64. </p> -->
  65. </el-form>
  66. <el-alert title="添加学员" :closable="false" class="alert" type="info" />
  67. <el-form
  68. :inline="true"
  69. @submit="search"
  70. ref="searchForm"
  71. :model="searchForm"
  72. >
  73. <el-form-item prop="search">
  74. <el-input
  75. class="search"
  76. type="text"
  77. clearable
  78. v-model="searchForm.search"
  79. placeholder="学员名称/编号/手机号"
  80. ></el-input>
  81. </el-form-item>
  82. <el-form-item prop="organId">
  83. <el-select
  84. class="multiple"
  85. filterable
  86. style="width: 180px !important"
  87. v-model.trim="searchForm.organId"
  88. clearable
  89. multiple
  90. placeholder="请选择分部"
  91. >
  92. <el-option
  93. v-for="(item, index) in organList"
  94. :key="index"
  95. :label="item.name"
  96. :value="item.id"
  97. ></el-option>
  98. </el-select>
  99. </el-form-item>
  100. <el-form-item prop="subjectId">
  101. <el-select
  102. clearable
  103. v-model="searchForm.subjectId"
  104. filterable
  105. placeholder="声部"
  106. >
  107. <el-option
  108. v-for="item in selects.subjects"
  109. :value="item.id"
  110. :label="item.name"
  111. :key="item.id"
  112. ></el-option>
  113. </el-select>
  114. </el-form-item>
  115. <el-form-item prop="hasMusicCourse">
  116. <el-select
  117. clearable
  118. v-model="searchForm.hasMusicCourse"
  119. filterable
  120. placeholder="是否乐团在读"
  121. >
  122. <el-option value="1" label="是"></el-option>
  123. <el-option value="0" label="否"></el-option>
  124. </el-select>
  125. </el-form-item>
  126. <el-form-item prop="hasVipCourse">
  127. <el-select
  128. clearable
  129. v-model="searchForm.hasVipCourse"
  130. filterable
  131. placeholder="是否vip在读"
  132. >
  133. <el-option value="1" label="是"></el-option>
  134. <el-option value="0" label="否"></el-option>
  135. </el-select>
  136. </el-form-item>
  137. <el-form-item prop="hasPracticeCourse">
  138. <el-select
  139. clearable
  140. v-model="searchForm.hasPracticeCourse"
  141. filterable
  142. placeholder="是否网管课在读"
  143. >
  144. <el-option value="1" label="是"></el-option>
  145. <el-option value="0" label="否"></el-option>
  146. </el-select>
  147. </el-form-item>
  148. <el-form-item prop="hasMember">
  149. <el-select
  150. clearable
  151. v-model="searchForm.hasMember"
  152. filterable
  153. placeholder="是否会员"
  154. >
  155. <el-option value="1" label="是"></el-option>
  156. <el-option value="0" label="否"></el-option>
  157. </el-select>
  158. </el-form-item>
  159. <el-form-item>
  160. <el-button type="danger" @click="search">搜索</el-button>
  161. <el-button native-type="reset" type="primary" @click="onReSet"
  162. >重置</el-button
  163. >
  164. </el-form-item>
  165. </el-form>
  166. <div class="tableWrap">
  167. <el-table
  168. style="width: 100%"
  169. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  170. :data="tableList"
  171. ref="tableList"
  172. @selection-change="handleSelectionChange"
  173. @select="onTableSelect"
  174. row-key="userId"
  175. >
  176. <el-table-column type="selection" width="55"> </el-table-column>
  177. <el-table-column
  178. align="center"
  179. prop="organName"
  180. label="分部"
  181. ></el-table-column>
  182. <el-table-column
  183. align="center"
  184. prop="userId"
  185. label="学员编号"
  186. ></el-table-column>
  187. <el-table-column
  188. align="center"
  189. prop="username"
  190. label="学员姓名"
  191. ></el-table-column>
  192. <el-table-column
  193. align="center"
  194. prop="phone"
  195. label="手机号"
  196. ></el-table-column>
  197. <el-table-column
  198. align="center"
  199. prop="subjectNames"
  200. label="声部"
  201. ></el-table-column>
  202. </el-table>
  203. <pagination
  204. :total.sync="rules.total"
  205. :page.sync="rules.page"
  206. :limit.sync="rules.limit"
  207. :page-sizes.sync="rules.page_size"
  208. @pagination="getList"
  209. />
  210. </div>
  211. </div>
  212. </template>
  213. <script>
  214. import pagination from "@/components/Pagination/index";
  215. import { getStudentList, addActivityUserMapperStudents } from "@/api/vipSeting";
  216. export default {
  217. components: { pagination },
  218. props: ["organList", "hasGive"],
  219. data() {
  220. return {
  221. topForm: {
  222. paySeniorNum: null,
  223. giveSeniorNum: null,
  224. memo: "",
  225. },
  226. searchForm: {
  227. search: null,
  228. organId: this.organList.map((organ) => {
  229. return organ.id;
  230. }),
  231. subjectId: null,
  232. hasMember: null,
  233. hasMusicCourse: null,
  234. hasPracticeCourse: null,
  235. hasVipCourse: null,
  236. },
  237. tableList: [],
  238. rules: {
  239. // 分页规则
  240. limit: 10, // 限制显示条数
  241. page: 1, // 当前页
  242. total: 0, // 总条数
  243. page_size: [10, 20, 40, 50], // 选择限制显示条数
  244. },
  245. isDetele: false,
  246. deleteList: [],
  247. };
  248. },
  249. async mounted() {
  250. await this.$store.dispatch("setSubjects");
  251. this.getList();
  252. },
  253. methods: {
  254. search() {
  255. this.rules.page = 1;
  256. this.getList();
  257. },
  258. onReSet() {
  259. this.$refs.searchForm.resetFields();
  260. this.search();
  261. },
  262. async getList() {
  263. try {
  264. let { organId, ...rest } = this.searchForm;
  265. let params = {
  266. ...rest,
  267. page: this.rules.page,
  268. rows: this.rules.limit,
  269. organId: organId.join(","),
  270. };
  271. const res = await getStudentList(params);
  272. this.tableList = res.data.rows;
  273. this.rules.total = res.data.total;
  274. let idList = this.deleteList.map((course) => {
  275. return course.userId;
  276. });
  277. this.isDetele = true;
  278. this.$nextTick(() => {
  279. this.tableList.forEach((course) => {
  280. if (idList.indexOf(course.userId) != -1) {
  281. console.log(course);
  282. this.$refs.tableList.toggleRowSelection(course, true);
  283. }
  284. });
  285. this.isDetele = false;
  286. });
  287. } catch (e) {
  288. console.log(e);
  289. }
  290. /**
  291. *
  292. */
  293. },
  294. handleSelectionChange(arr) {
  295. // this.deleteList = arr;
  296. if (arr.length > 0) {
  297. // 有可能加 有可能减
  298. this.deleteList = this.deleteList.concat(arr);
  299. // 去重
  300. this.deleteList = this.$helpers.lodash.uniqBy(
  301. this.deleteList,
  302. "userId"
  303. );
  304. }
  305. // else if(){}
  306. else {
  307. if (this.isDetele) return;
  308. // 有2种 1是新页
  309. // 2是点击反选
  310. let idList = this.deleteList.map((course) => {
  311. return course.userId;
  312. });
  313. this.$nextTick(() => {
  314. let tableIdList = [];
  315. this.tableList.forEach((course) => {
  316. tableIdList.push(course.userId);
  317. if (idList.indexOf(course.userId) != -1) {
  318. this.$refs.tableList.toggleRowSelection(course, false);
  319. // 删除这个元素
  320. }
  321. });
  322. this.deleteList = this.$helpers.lodash.remove(
  323. this.deleteList,
  324. function (item) {
  325. return tableIdList.indexOf(item.userId) == -1;
  326. }
  327. );
  328. if (this.deleteList.length <= 0) {
  329. this.clearCom();
  330. }
  331. });
  332. }
  333. },
  334. onTableSelect(rows, row) {
  335. let idList = this.deleteList.map((course) => {
  336. return course.userId;
  337. });
  338. if (idList.indexOf(row.userId) != -1) {
  339. this.deleteList.splice(idList.indexOf(row.userId), 1);
  340. if (this.deleteList.length <= 0) {
  341. this.clearCom();
  342. }
  343. }
  344. },
  345. clearCom() {
  346. // this.deleteList = [];
  347. this.$set(this, "deleteList", []);
  348. this.$refs.tableList.clearSelection();
  349. },
  350. async submit() {
  351. this.$refs.form.validate(async (flag) => {
  352. if (flag) {
  353. let obj = {
  354. activityId: this.$route.query.id,
  355. memo: this.topForm.memo,
  356. };
  357. let activityStudentAdjustDtos = this.deleteList.map((stu) => {
  358. return {
  359. userId: stu.userId,
  360. courseNum: this.topForm.paySeniorNum,
  361. giveCourseNum: this.topForm.giveSeniorNum,
  362. };
  363. });
  364. obj.activityStudentAdjustDtos = activityStudentAdjustDtos;
  365. try {
  366. const res = await addActivityUserMapperStudents(obj);
  367. this.$message.success("添加成功");
  368. this.$emit("getList");
  369. this.$emit("close");
  370. } catch (e) {
  371. console.log(e);
  372. }
  373. }
  374. });
  375. },
  376. },
  377. };
  378. </script>
  379. <style lang="scss" scoped>
  380. .submitP {
  381. margin-bottom: 20px;
  382. }
  383. .alert {
  384. margin-bottom: 20px;
  385. }
  386. ::v-deep .el-form--inline .el-form-item {
  387. margin-right: 0;
  388. }
  389. .search {
  390. ::v-deep .el-input__inner {
  391. width: 200px !important;
  392. }
  393. }
  394. </style>