add-teacher.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div class="add-courseware">
  3. <save-form
  4. :inline="true"
  5. :model="searchForm"
  6. @submit="search"
  7. @reset="onReSet"
  8. ref="searchForm"
  9. savekey="courseware-config-add-teacher"
  10. >
  11. <el-form-item prop="search">
  12. <el-input
  13. v-model.trim="searchForm.search"
  14. clearable
  15. @keyup.enter.native="
  16. e => {
  17. e.target.blur();
  18. $refs.searchForm.save();
  19. search();
  20. }
  21. "
  22. placeholder="编号/姓名/手机号"
  23. ></el-input>
  24. </el-form-item>
  25. <el-form-item prop="organId">
  26. <el-select
  27. v-model.trim="searchForm.organId"
  28. filterable
  29. clearable
  30. placeholder="请选择分部"
  31. >
  32. <el-option
  33. v-for="item in selects.branchs"
  34. :key="item.id"
  35. :label="item.name"
  36. :value="item.id"
  37. >
  38. </el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item prop="jobNature">
  42. <el-select
  43. v-model.trim="searchForm.jobNature"
  44. filterable
  45. clearable
  46. placeholder="工作类型"
  47. >
  48. <el-option
  49. v-for="item in jobNature"
  50. :key="item.value"
  51. :label="item.label"
  52. :value="item.value"
  53. ></el-option>
  54. </el-select>
  55. </el-form-item>
  56. <el-form-item>
  57. <el-button native-type="submit" type="primary">搜索</el-button>
  58. <el-button native-type="reset" type="danger">重置</el-button>
  59. </el-form-item>
  60. </save-form>
  61. <div class="tableWrap">
  62. <el-table
  63. :data="tableList"
  64. ref="multipleSelection"
  65. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  66. @select-all="handleSelectionChange"
  67. @select="onTableSelect"
  68. >
  69. <el-table-column type="selection" width="55" />
  70. <el-table-column
  71. align="center"
  72. prop="id"
  73. label="编号"
  74. ></el-table-column>
  75. <el-table-column
  76. align="center"
  77. prop="realName"
  78. label="姓名"
  79. ></el-table-column>
  80. <el-table-column
  81. align="center"
  82. label="手机号"
  83. prop="phone"
  84. ></el-table-column>
  85. <el-table-column
  86. align="center"
  87. label="分部"
  88. prop="organName"
  89. ></el-table-column>
  90. <el-table-column align="center" label="工作类型" prop="courseNum">
  91. <template slot-scope="scope">
  92. <p>{{ scope.row.jobNature | jobNature }}</p>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <pagination
  97. sync
  98. savekey="courseware-config-add-teacher"
  99. :total.sync="pageInfo.total"
  100. :page.sync="pageInfo.page"
  101. :limit.sync="pageInfo.limit"
  102. :page-sizes="pageInfo.page_size"
  103. @pagination="getList"
  104. />
  105. </div>
  106. <span slot="footer" class="dialog-footer">
  107. <el-button @click="$emit('close')">取 消</el-button>
  108. <el-button
  109. :disabled="activeChiose.length <= 0"
  110. @click="onSubmit"
  111. type="primary"
  112. >确 定</el-button
  113. >
  114. </span>
  115. </div>
  116. </template>
  117. <script>
  118. import pagination from "@/components/Pagination/index";
  119. import {
  120. lessonCoursewarePage,
  121. queryLessonCoursewareId,
  122. addLessonCourseware
  123. } from "./api";
  124. import { courseEmnuList, jobNature } from "@/utils/searchArray";
  125. import { teacherQueryPage } from "@/api/teacherManager";
  126. import deepClone from "@/helpers/deep-clone/";
  127. export default {
  128. name: "add-courseware",
  129. components: { pagination },
  130. props: ["list"],
  131. data() {
  132. return {
  133. jobNature, // 工作类型
  134. courseEmnuList,
  135. tableList: [],
  136. searchForm: {
  137. search: null,
  138. organId: null,
  139. jobNature: null
  140. },
  141. pageInfo: {
  142. // 分页规则
  143. limit: 10, // 限制显示条数
  144. page: 1, // 当前页
  145. total: 0, // 总条数
  146. page_size: [10, 20, 40, 50] // 选择限制显示条数
  147. },
  148. existIds: [],
  149. activeChiose: []
  150. };
  151. },
  152. async mounted() {
  153. this.activeChiose = this.list || [];
  154. await this.$store.dispatch("setBranchs");
  155. this.getList();
  156. },
  157. methods: {
  158. search() {
  159. this.pageInfo.page = 1;
  160. this.getList();
  161. },
  162. onReSet() {
  163. this.$refs.searchForm.resetFields();
  164. this.search();
  165. },
  166. onFormatSelectData(arr) {
  167. try {
  168. let currentPageList = [];
  169. const otherPageList = [];
  170. this.activeChiose.forEach(item => {
  171. if (item.currentPage == this.pageInfo.page) {
  172. currentPageList.push(item);
  173. } else {
  174. otherPageList.push(item);
  175. }
  176. });
  177. const lastPage = [];
  178. if (arr.length > 0) {
  179. arr.forEach(item => {
  180. const index = currentPageList.findIndex(
  181. child => child.id === item.id
  182. );
  183. if (index === -1) {
  184. lastPage.push(item);
  185. }
  186. });
  187. } else {
  188. currentPageList = [];
  189. }
  190. this.activeChiose = [
  191. ...lastPage,
  192. ...otherPageList,
  193. ...currentPageList
  194. ].sort((a, b) => a.id - b.id);
  195. } catch (e) {}
  196. },
  197. onTableSelect(arr) {
  198. // console.log(arr, "onTableSelect");
  199. this.onFormatSelectData(arr);
  200. },
  201. handleSelectionChange(arr) {
  202. // console.log(arr, "val");
  203. this.onFormatSelectData(arr);
  204. },
  205. async getList() {
  206. //
  207. try {
  208. let params = {
  209. ...this.searchForm,
  210. page: this.pageInfo.page,
  211. rows: this.pageInfo.limit
  212. };
  213. teacherQueryPage(params).then(res => {
  214. if (res.code == 200) {
  215. // (res)
  216. console.log(res, "data");
  217. const rows = res.data.rows || [];
  218. rows.forEach(row => {
  219. row.currentPage = this.pageInfo.page;
  220. });
  221. this.tableList = rows;
  222. this.pageInfo.total = res.data.total;
  223. // 反选对应数据
  224. const activeChiose = deepClone(this.activeChiose);
  225. console.log(activeChiose, "this.list");
  226. this.$nextTick(() => {
  227. this.tableList.forEach(item => {
  228. const index = activeChiose.findIndex(
  229. child => child.id == item.id
  230. );
  231. if (index > -1) {
  232. console.log(index, "tableList", item.id);
  233. this.activeChiose[index].currentPage = item.currentPage;
  234. this.$refs.multipleSelection.toggleRowSelection(item, true);
  235. }
  236. // this.tableList.forEach(course => {
  237. // if (idList.indexOf(course.skuStockId) != -1) {
  238. // this.$refs.multipleSelection.toggleRowSelection(course, true);
  239. // }
  240. // });
  241. });
  242. });
  243. }
  244. });
  245. } catch {
  246. //
  247. }
  248. },
  249. async onSubmit() {
  250. const userList = [];
  251. this.activeChiose.forEach(item => {
  252. userList.push({
  253. name: item.realName || item.name,
  254. id: item.id
  255. });
  256. });
  257. console.log(userList, "this.activeChiose");
  258. this.$emit("confirm", userList);
  259. this.$emit("close");
  260. }
  261. }
  262. };
  263. </script>
  264. <style lang="scss" scoped>
  265. .dialog-footer {
  266. display: block;
  267. text-align: right;
  268. }
  269. </style>