ModifyTeacherSimple.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <el-dialog
  3. class="modify-teacher-simple"
  4. :visible.sync="modalIsShow"
  5. title="添加教师"
  6. top="10px"
  7. width="800px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <div class="mb-4 tab-btns">
  14. <el-button
  15. v-for="tab in tabs"
  16. :key="tab.val"
  17. size="medium"
  18. :type="curTab == tab.val ? 'primary' : 'default'"
  19. @click="selectMenu(tab.val)"
  20. >{{ tab.name }}
  21. </el-button>
  22. </div>
  23. <!-- input -->
  24. <div v-if="curTab === 'input'" class="tab-body">
  25. <el-form
  26. ref="modalFormComp"
  27. :model="modalForm"
  28. :rules="rules"
  29. :key="modalForm.id"
  30. label-position="top"
  31. >
  32. <el-form-item prop="loginName" label="姓名:">
  33. <el-input
  34. v-model.trim="modalForm.loginName"
  35. placeholder="请输入姓名"
  36. clearable
  37. ></el-input>
  38. </el-form-item>
  39. <el-form-item prop="code" label="工号:">
  40. <el-input
  41. v-model.trim="modalForm.code"
  42. placeholder="请输入工号"
  43. clearable
  44. ></el-input>
  45. </el-form-item>
  46. </el-form>
  47. </div>
  48. <!-- select -->
  49. <div v-if="curTab === 'select'" class="tab-body">
  50. <select-simple-teacher
  51. ref="SelectSimpleTeacher"
  52. v-model="selectedTeacherIds"
  53. ></select-simple-teacher>
  54. </div>
  55. <!-- import -->
  56. <div v-if="curTab === 'import'" class="tab-body">
  57. <el-button type="success" icon="el-icon-download"
  58. ><a :href="downloadUrl" :download="dfilename">模板下载</a></el-button
  59. >
  60. <upload-button
  61. btn-icon="el-icon-circle-plus-outline"
  62. btn-content="批量导入"
  63. btn-type="success"
  64. :upload-url="uploadUrl"
  65. :upload-data="uploadData"
  66. :format="['xls', 'xlsx']"
  67. accept=".xls,.xlsx"
  68. @valid-error="validError"
  69. @upload-success="uploadSuccess"
  70. >
  71. </upload-button>
  72. </div>
  73. <div v-if="!IS_IMPORT" slot="footer">
  74. <el-button type="primary" :disabled="isSubmit" @click="submit"
  75. >确认</el-button
  76. >
  77. <el-button @click="cancel">取消</el-button>
  78. </div>
  79. </el-dialog>
  80. </template>
  81. <script>
  82. import { updateTeacherSimple, batchAddTeacherSimple } from "../../api";
  83. import UploadButton from "@/components/UploadButton";
  84. import SelectSimpleTeacher from "./SelectSimpleTeacher.vue";
  85. const initModalForm = {
  86. id: null,
  87. loginName: "",
  88. code: ""
  89. };
  90. export default {
  91. name: "modify-teacher-simple",
  92. components: { UploadButton, SelectSimpleTeacher },
  93. computed: {
  94. IS_IMPORT() {
  95. return this.curTab === "import";
  96. }
  97. },
  98. data() {
  99. return {
  100. modalIsShow: false,
  101. isSubmit: false,
  102. curTab: "select",
  103. tabs: [
  104. {
  105. name: "手动添加",
  106. val: "input"
  107. },
  108. {
  109. name: "教师库添加",
  110. val: "select"
  111. },
  112. {
  113. name: "批量导入",
  114. val: "import"
  115. }
  116. ],
  117. modalForm: { ...initModalForm },
  118. courses: [],
  119. rules: {
  120. loginName: [
  121. {
  122. required: true,
  123. // pattern: /^[0-9a-zA-Z\u4E00-\u9FA5]{1,20}$/,
  124. // message: "姓名只能输入汉字、数字和字母,长度不能超过20",
  125. message: "姓名不能超过30个字",
  126. max: 30,
  127. trigger: "change"
  128. }
  129. ],
  130. code: [
  131. {
  132. required: true,
  133. pattern: /^[0-9a-zA-Z_-]{3,30}$/,
  134. message: "工号只能由数字字母短横线组成,长度在3-30之间",
  135. trigger: "change"
  136. }
  137. ]
  138. },
  139. selectedTeacherIds: [],
  140. // import
  141. uploadData: {},
  142. uploadUrl: "/api/admin/teach/course/import",
  143. downloadUrl: "/temps/courseSimpleTemplate.xlsx",
  144. dfilename: "教学课程导入模板.xlsx"
  145. };
  146. },
  147. methods: {
  148. visibleChange() {
  149. this.modalForm = { ...initModalForm };
  150. },
  151. cancel() {
  152. this.modalIsShow = false;
  153. },
  154. open() {
  155. this.modalIsShow = true;
  156. },
  157. selectMenu(tab) {
  158. this.curTab = tab;
  159. },
  160. submit() {
  161. const submitFunc = {
  162. input: this.submitInput,
  163. select: this.submitSelect
  164. };
  165. submitFunc[this.curTab]();
  166. },
  167. async submitInput() {
  168. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  169. if (!valid) return;
  170. if (this.isSubmit) return;
  171. this.isSubmit = true;
  172. let datas = { ...this.modalForm };
  173. const data = await updateTeacherSimple(datas).catch(() => {
  174. this.isSubmit = false;
  175. });
  176. if (!data) return;
  177. this.isSubmit = false;
  178. this.$message.success(this.title + "成功!");
  179. this.$emit("modified");
  180. this.cancel();
  181. },
  182. async submitSelect() {
  183. if (!this.selectedTeacherIds.length) {
  184. this.$message.error("请选择教师");
  185. return;
  186. }
  187. if (this.isSubmit) return;
  188. this.isSubmit = true;
  189. const data = await batchAddTeacherSimple({
  190. basicTeacherIdSet: this.selectedTeacherIds
  191. }).catch(() => {});
  192. this.isSubmit = false;
  193. if (!data) return;
  194. this.$message.success("添加成功!");
  195. this.$emit("modified");
  196. this.selectedTeacherIds = [];
  197. this.$refs.SelectSimpleTeacher.clearSelection();
  198. },
  199. // import
  200. validError(errorData) {
  201. this.$message.error(errorData.message);
  202. },
  203. uploadSuccess(data) {
  204. this.$message.success(data.data || "教师导入成功!");
  205. this.$emit("modified");
  206. this.cancel();
  207. }
  208. }
  209. };
  210. </script>