addShareStudentList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <div class="m-container">
  3. <!-- -->
  4. <h2>
  5. <el-page-header
  6. @back="onCancel"
  7. :content="$route.query.name + '分享名单'"
  8. ></el-page-header>
  9. </h2>
  10. <div class="m-core">
  11. <el-form :inline="true" :model="searchForm">
  12. <el-form-item>
  13. <el-input
  14. v-model.trim="searchForm.search"
  15. clearable
  16. @keyup.enter.native="search"
  17. placeholder="学员名/编号/手机号"
  18. ></el-input>
  19. </el-form-item>
  20. <el-form-item prop="organIdList">
  21. <select-all
  22. class="multiple"
  23. clearable
  24. filterable
  25. collapse-tags
  26. multiple
  27. v-model.trim="searchForm.organIdList"
  28. placeholder="请选择分部"
  29. @change="onBranchChange"
  30. >
  31. <el-option
  32. v-for="(item, index) in selects.branchs"
  33. :key="index"
  34. :label="item.name"
  35. :value="item.id"
  36. ></el-option>
  37. </select-all>
  38. </el-form-item>
  39. <el-form-item>
  40. <el-select
  41. multiple
  42. collapse-tags
  43. v-model.trim="searchForm.cooperationOrganId"
  44. clearable
  45. filterable
  46. placeholder="请选择合作单位"
  47. :disabled="searchForm.organIdList.length <= 0"
  48. >
  49. <el-option
  50. v-for="(item, index) in cooperationList"
  51. :key="index"
  52. :value="item.id"
  53. :label="item.name"
  54. ></el-option>
  55. </el-select>
  56. </el-form-item>
  57. <el-form-item>
  58. <el-select
  59. multiple
  60. collapse-tags
  61. :disabled="searchForm.organIdList.length <= 0"
  62. v-model.trim="searchForm.musicGroupId"
  63. clearable
  64. filterable
  65. placeholder="请选择乐团"
  66. >
  67. <el-option
  68. v-for="(item, index) in teamList"
  69. :key="index"
  70. :value="item.id"
  71. :label="item.name"
  72. ></el-option>
  73. </el-select>
  74. </el-form-item>
  75. <el-form-item prop="subjectId">
  76. <el-select
  77. v-model="searchForm.subjectId"
  78. clearable
  79. filterable
  80. placeholder="请选择声部"
  81. >
  82. <el-option
  83. v-for="item in selects.subjects"
  84. :value="item.id"
  85. :label="item.name"
  86. :key="item.id"
  87. ></el-option>
  88. </el-select>
  89. </el-form-item>
  90. <el-form-item>
  91. <el-select
  92. multiple
  93. collapse-tags
  94. v-model.trim="searchForm.groupList"
  95. clearable
  96. filterable
  97. placeholder="请选择群聊"
  98. >
  99. <el-option
  100. v-for="(item, index) in groupList"
  101. :key="index"
  102. :value="item.id"
  103. :label="item.name"
  104. ></el-option>
  105. </el-select>
  106. </el-form-item>
  107. <el-form-item>
  108. <el-button @click="search" type="primary">搜索</el-button>
  109. <el-button @click="onReSet" type="danger">重置</el-button>
  110. </el-form-item>
  111. </el-form>
  112. <div class="btnWrap">
  113. <auth auths="courseShare/saveCourseShare">
  114. <el-button @click="addBlack" type="primary" style="margin-bottom: 10px"
  115. >添加学员</el-button
  116. >
  117. </auth>
  118. <auth auths="courseShare/importStudent">
  119. <el-button type="primary" @click="() => (importVisible = true)">导入</el-button>
  120. </auth>
  121. <auth auths="courseShare/deleteShareStudent">
  122. <el-button @click="removes" type="danger" style="margin-bottom: 10px"
  123. >删除学员</el-button
  124. >
  125. </auth>
  126. </div>
  127. <div class="tableWrap">
  128. <el-table
  129. style="width: 100%"
  130. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  131. :data="tableList"
  132. @selection-change="handleSelectionChange"
  133. @select="onTableSelect"
  134. ref="multipleSelection"
  135. >
  136. <el-table-column type="selection" width="55"> </el-table-column>
  137. <el-table-column align="center" prop="userId" label="编号"></el-table-column>
  138. <el-table-column
  139. align="center"
  140. prop="username"
  141. label="学员姓名"
  142. ></el-table-column>
  143. <el-table-column align="center" prop="organName" label="分部"></el-table-column>
  144. <el-table-column
  145. align="center"
  146. prop="subjectName"
  147. label="声部"
  148. ></el-table-column>
  149. <el-table-column align="center" prop="phone" label="手机号"></el-table-column>
  150. <el-table-column align="center" prop="studentId" label="操作">
  151. <template slot-scope="scope">
  152. <div>
  153. <auth auths="courseShare/deleteShareStudent">
  154. <el-button type="text" @click="deteleBlack(scope.row)">删除</el-button>
  155. </auth>
  156. </div>
  157. </template>
  158. </el-table-column>
  159. </el-table>
  160. <pagination
  161. sync
  162. :total.sync="rules.total"
  163. :page.sync="rules.page"
  164. :limit.sync="rules.limit"
  165. :page-sizes="rules.page_size"
  166. @pagination="getList"
  167. />
  168. </div>
  169. </div>
  170. <addShareStudentModel @getList="getList" ref="addStudentModel" />
  171. <el-dialog title="导入" width="400px" :visible.sync="importVisible">
  172. <div class="importWrap">
  173. <el-button type="primary" @click="() => downImport()">下载模板</el-button>
  174. <el-upload
  175. v-permission="'courseShare/importStudent'"
  176. action="/api-web/courseShare/importStudent"
  177. :show-file-list="false"
  178. :before-upload="beforeUpload"
  179. accept=".xlsx,.xls"
  180. :data="{
  181. courseId: $route.query.courseId,
  182. }"
  183. :headers="headers"
  184. :on-error="handleError"
  185. :on-success="handleSuccess"
  186. >
  187. <el-button type="primary" style="margin-left: 20px"> 导入学员 </el-button>
  188. </el-upload>
  189. </div>
  190. <div slot="footer" class="dialog-footer">
  191. <el-button type="primary" @click="importVisible = false">确 定</el-button>
  192. </div>
  193. </el-dialog>
  194. </div>
  195. </template>
  196. <script>
  197. import { getLiveGroupShareStudent, deleteShareStudent } from "../../api";
  198. import pagination from "@/components/Pagination/index";
  199. import addShareStudentModel from "../../modals/addShareStudentModel";
  200. import { getGroupList } from "@/views/groupChatManager/api";
  201. import { queryByOrganId } from "@/api/systemManage";
  202. import { getTeamList } from "@/api/teamServer";
  203. import { getToken, getTenantId } from "@/utils/auth";
  204. import load from "@/utils/loading";
  205. export default {
  206. name: "liveAddStudentList",
  207. //
  208. components: { pagination, addShareStudentModel },
  209. data() {
  210. return {
  211. headers: { Authorization: getToken(), tenantId: getTenantId() },
  212. searchForm: {
  213. search: "",
  214. organIdList: [],
  215. cooperationOrganId: [],
  216. musicGroupId: [],
  217. groupList: [],
  218. },
  219. tableList: [],
  220. organList: [],
  221. cooperationList: [],
  222. groupList: [],
  223. teamList: [],
  224. rules: {
  225. // 分页规则
  226. limit: 10, // 限制显示条数
  227. page: 1, // 当前页
  228. total: 0, // 总条数
  229. page_size: [10, 20, 40, 50], // 选择限制显示条数
  230. },
  231. addMuiscVisible: false,
  232. multipleSelection: [],
  233. chioseIdList: [],
  234. isNewPage: false,
  235. lookVisible: false,
  236. activeRow: { sendFlag: false },
  237. importVisible: false,
  238. };
  239. },
  240. mounted() {
  241. this.$store.dispatch("setSubjects");
  242. this.$store.dispatch("setBranchs");
  243. this.getGroupList();
  244. this.getList();
  245. },
  246. methods: {
  247. downImport() {
  248. window.location.href =
  249. "https://daya-docs.ks3-cn-beijing.ksyuncs.com/%E7%9B%B4%E6%92%AD%E8%AF%BE-%E5%88%86%E4%BA%AB%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx";
  250. },
  251. async getGroupList() {
  252. const res = await getGroupList({ page: 1, rows: 9999 });
  253. this.groupList = res.data.rows;
  254. },
  255. async getList() {
  256. try {
  257. const {
  258. organIdList,
  259. cooperationOrganId,
  260. musicGroupId,
  261. groupList,
  262. ...rest
  263. } = this.searchForm;
  264. const res = await getLiveGroupShareStudent({
  265. organIds: organIdList.join(","),
  266. schoolIds: cooperationOrganId.join(","),
  267. teamIds: musicGroupId.join(","),
  268. groupIds: groupList.join(","),
  269. ...rest,
  270. page: this.rules.page,
  271. rows: this.rules.limit,
  272. courseId: this.$route.query.courseId,
  273. });
  274. this.tableList = res.data.rows;
  275. this.rules.total = res.data.total;
  276. let idList = this.chioseIdList.map((group) => {
  277. return group.userId;
  278. });
  279. this.isNewPage = true;
  280. this.$nextTick(() => {
  281. this.tableList.forEach((course) => {
  282. if (idList.indexOf(course.userId) != -1) {
  283. this.$refs.multipleSelection.toggleRowSelection(course, true);
  284. }
  285. });
  286. this.isNewPage = false;
  287. });
  288. } catch (e) {
  289. console.log(e);
  290. }
  291. },
  292. search() {
  293. this.rules.page = 1;
  294. this.getList();
  295. },
  296. onReSet() {
  297. (this.searchForm = {
  298. search: "",
  299. organIdList: [],
  300. cooperationOrganId: [],
  301. musicGroupId: [],
  302. groupList: [],
  303. }),
  304. this.clearCom();
  305. this.search();
  306. },
  307. handleSelectionChange(val) {
  308. if (val.length > 0) {
  309. this.chioseIdList = this.chioseIdList.concat(val);
  310. this.chioseIdList = this.$helpers.lodash.uniqBy(this.chioseIdList, "userId");
  311. } else {
  312. if (this.isNewPage) return;
  313. let idList = this.chioseIdList.map((group) => {
  314. return group.userId;
  315. });
  316. this.$nextTick(() => {
  317. let tableIdList = [];
  318. this.tableList.forEach((group) => {
  319. tableIdList.push(group.userId);
  320. if (idList.indexOf(group.userId) != -1) {
  321. this.$refs.multipleSelection.toggleRowSelection(group, false);
  322. }
  323. });
  324. this.chioseIdList = this.$helpers.lodash.remove(
  325. this.chioseIdList,
  326. function (item) {
  327. return tableIdList.indexOf(item.userId) == -1;
  328. }
  329. );
  330. if (this.chioseIdList.length <= 0) {
  331. this.clearCom();
  332. }
  333. });
  334. }
  335. },
  336. clearCom() {
  337. this.chioseIdList = [];
  338. this.$refs.multipleSelection.clearSelection();
  339. },
  340. onTableSelect(rows, row) {
  341. let idList = this.chioseIdList.map((group) => {
  342. return group.userId;
  343. });
  344. if (idList.indexOf(row.userId) != -1) {
  345. this.chioseIdList.splice(idList.indexOf(row.userId), 1);
  346. if (this.chioseIdList.length <= 0) {
  347. this.clearCom();
  348. }
  349. }
  350. },
  351. onCancel() {
  352. this.$router.push("/liveClassManager");
  353. this.$store.dispatch("delVisitedViews", this.$route);
  354. },
  355. async deteleBlack(row) {
  356. this.$confirm(`你确定将${row.username}移除分享列表?`, "提示", {
  357. confirmButtonText: "确定",
  358. cancelButtonText: "取消",
  359. type: "warning",
  360. })
  361. .then(async () => {
  362. try {
  363. const res = await deleteShareStudent({
  364. courseId: this.$route.query.courseId,
  365. userIds: [row.userId],
  366. });
  367. this.getList();
  368. this.clearCom();
  369. } catch (e) {
  370. console.log(e);
  371. }
  372. })
  373. .catch();
  374. },
  375. addBlack() {
  376. this.$refs.addStudentModel.openDioag({
  377. courseId: this.$route.query.courseId,
  378. });
  379. },
  380. removes() {
  381. if (!this.chioseIdList || this.chioseIdList.length <= 0) {
  382. this.$message.error("请至少选择一名学员");
  383. return;
  384. }
  385. let str = this.chioseIdList
  386. .map((group) => {
  387. return group.username;
  388. })
  389. .join(",");
  390. this.$confirm(`你确定将${str}移除分享列表?`, "提示", {
  391. confirmButtonText: "确定",
  392. cancelButtonText: "取消",
  393. type: "warning",
  394. })
  395. .then(async () => {
  396. let idList = this.chioseIdList.map((group) => {
  397. return group.userId;
  398. });
  399. try {
  400. const res = await deleteShareStudent({
  401. courseId: this.$route.query.courseId,
  402. userIds: idList,
  403. });
  404. this.$message.success("删除成功");
  405. this.getList();
  406. this.clearCom();
  407. } catch (e) {
  408. console.log(e);
  409. }
  410. })
  411. .catch();
  412. },
  413. async onBranchChange(val) {
  414. // this.searchForm.cooperationOrganId = [];
  415. this.$set(this.searchForm, "cooperationOrganId", []);
  416. if (val && val.length > 0) {
  417. let organId = val.join(",");
  418. try {
  419. await queryByOrganId({ organId }).then((res) => {
  420. if (res.code == 200) {
  421. this.cooperationList = res.data;
  422. }
  423. });
  424. await getTeamList({ organId, page: 1, rows: 9999 }).then((res) => {
  425. if (res.code == 200) {
  426. this.teamList = res.data.rows;
  427. }
  428. });
  429. } catch (e) {
  430. console.log(e);
  431. }
  432. }
  433. },
  434. beforeUpload(file) {
  435. // (file.type)
  436. // const isJPG = file.type === '.xlsx' || file.type === '.xls';
  437. // // const isLt2M = file.size / 1024 / 1024 < 2;
  438. // if (!isJPG) {
  439. // this.$message.error('上传头像图片只能是 JPG 格式!');
  440. // }
  441. // return isJPG;
  442. // this.goodsLoading = true
  443. load.startLoading();
  444. },
  445. handleSuccess(response, file, fileList) {
  446. // 导入商品
  447. // 报表导出
  448. load.endLoading();
  449. if (response.code == 200) {
  450. this.$message.success("导入成功");
  451. this.importVisible = false;
  452. this.getList();
  453. } else {
  454. this.$message.error(response.msg);
  455. }
  456. },
  457. handleError(err, file, fileList) {
  458. load.endLoading();
  459. },
  460. },
  461. };
  462. </script>
  463. <style lang="scss" scoped>
  464. .w100 {
  465. width: 100%;
  466. }
  467. .btnWrap {
  468. justify-content: flex-start;
  469. }
  470. .importWrap {
  471. display: flex;
  472. flex-direction: row;
  473. align-items: center;
  474. }
  475. </style>