specially.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. <template>
  2. <section class="content">
  3. <div class="box-body">
  4. <el-form :inline="true" :model="formSearch" ref="primaryForm">
  5. <el-row>
  6. <el-form-item label="专业名称">
  7. <el-input
  8. class="input_width_lg"
  9. placeholder="请输入专业名称"
  10. v-model="formSearch.name"
  11. />
  12. </el-form-item>
  13. <el-form-item label="专业代码">
  14. <el-input
  15. class="input_width_lg"
  16. placeholder="请输入专业代码"
  17. v-model="formSearch.code"
  18. />
  19. </el-form-item>
  20. <el-form-item label="课程">
  21. <el-select
  22. class="input"
  23. :remote-method="getCourses"
  24. @focus="e => getCourses(e.target.value)"
  25. :loading="courseLoading"
  26. remote
  27. filterable
  28. clearable
  29. v-model="formSearch.courseId"
  30. placeholder="请选择"
  31. >
  32. <el-option
  33. v-for="item in courseList4SearchWrapper"
  34. :label="item.name"
  35. :value="item.id"
  36. :key="item.id"
  37. />
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button
  42. size="small"
  43. type="primary"
  44. icon="el-icon-search"
  45. @click="handleSearchBtn"
  46. >
  47. 查询
  48. </el-button>
  49. <el-button
  50. size="small"
  51. @click="resetPrimaryForm"
  52. icon="el-icon-refresh"
  53. >
  54. 重置
  55. </el-button>
  56. <el-button
  57. size="small"
  58. type="primary"
  59. icon="el-icon-plus"
  60. @click="insert"
  61. >
  62. 新增
  63. </el-button>
  64. </el-form-item>
  65. </el-row>
  66. </el-form>
  67. <div class="block-seperator"></div>
  68. <span>操作:</span>
  69. <el-button
  70. size="small"
  71. type="danger"
  72. @click="deleteIds"
  73. :disabled="noBatchSelected"
  74. icon="el-icon-delete"
  75. >
  76. 删除
  77. </el-button>
  78. <el-button
  79. size="small"
  80. type="primary"
  81. @click="impSpecialty"
  82. icon="el-icon-upload2"
  83. >
  84. 导入
  85. </el-button>
  86. <el-button
  87. size="small"
  88. type="primary"
  89. @click="exportSpeciatly"
  90. icon="el-icon-download"
  91. >
  92. 导出
  93. </el-button>
  94. <div style="width: 100%;margin-bottom: 10px;"></div>
  95. <!-- 新增或修改弹出框 -->
  96. <el-dialog
  97. title="专业信息"
  98. width="450px"
  99. :visible.sync="speciallyDialog"
  100. @close="dialogBeforeClose"
  101. >
  102. <el-form
  103. :inline="true"
  104. inline-message
  105. :model="speciallyForm"
  106. ref="speciallyForm"
  107. :rules="rules"
  108. label-position="right"
  109. label-width="90px"
  110. >
  111. <el-form-item label="专业代码" prop="code">
  112. <el-input
  113. :disabled="null != speciallyForm.id"
  114. class="pull_length"
  115. v-model="speciallyForm.code"
  116. auto-complete="off"
  117. placeholder="专业代码"
  118. maxlength="100"
  119. />
  120. </el-form-item>
  121. <el-form-item label="专业名称" prop="name">
  122. <el-input
  123. class="pull_length"
  124. v-model="speciallyForm.name"
  125. auto-complete="off"
  126. placeholder="专业名称"
  127. maxlength="100"
  128. />
  129. </el-form-item>
  130. <el-row class="pull_center">
  131. <el-button type="primary" @click="submitForm('speciallyForm')">
  132. 保 存
  133. </el-button>
  134. <el-button @click="close">取 消</el-button>
  135. </el-row>
  136. </el-form>
  137. </el-dialog>
  138. <!-- 关联课程弹出框 -->
  139. <el-dialog
  140. :title="courseDialogTitle"
  141. width="740px"
  142. :visible.sync="courseDialog"
  143. >
  144. <!-- 表单 -->
  145. <el-form :inline="true" :model="courseSearchForm">
  146. <el-row>
  147. <el-form-item label="课程名称" class="pull-left">
  148. <el-input
  149. class="input_width_lg"
  150. placeholder="请输入课程名称"
  151. v-model="courseSearchForm.name"
  152. />
  153. </el-form-item>
  154. <el-form-item label="课程代码" class="pull-left">
  155. <el-input
  156. class="input_width_lg"
  157. placeholder="请输入课程代码"
  158. v-model="courseSearchForm.code"
  159. />
  160. </el-form-item>
  161. <el-form-item class="pull-right">
  162. <el-button
  163. size="small"
  164. type="primary"
  165. icon="el-icon-search"
  166. @click="searchCoursePage"
  167. >
  168. 查询
  169. </el-button>
  170. <el-button
  171. size="small"
  172. type="primary"
  173. icon="el-icon-plus"
  174. @click="addRelation"
  175. >
  176. 新增
  177. </el-button>
  178. </el-form-item>
  179. </el-row>
  180. </el-form>
  181. <!-- 课程列表 -->
  182. <el-table :data="courseTableData" border resizable stripe>
  183. <el-table-column prop="id" label="ID" width="60" />
  184. <el-table-column prop="name" label="课程名称" width="220" />
  185. <el-table-column prop="code" label="课程代码" />
  186. <el-table-column prop="updateTime" label="更新时间" width="170" />
  187. <el-table-column label="操作" width="120">
  188. <span slot-scope="scope">
  189. <el-button
  190. size="mini"
  191. type="primary"
  192. @click="deleteRelation(scope.row)"
  193. icon="el-icon-edit"
  194. >
  195. 取消关联
  196. </el-button>
  197. </span>
  198. </el-table-column>
  199. </el-table>
  200. <div class="pull-right">
  201. <el-pagination
  202. @current-change="handleCourseCurrentChange"
  203. :current-page="currentCoursePage"
  204. :page-size="10"
  205. layout="total, prev, pager, next, jumper"
  206. :total="courseTotal"
  207. />
  208. </div>
  209. </el-dialog>
  210. <!-- 添加关联 -->
  211. <el-dialog
  212. title="添加关联课程"
  213. width="500px"
  214. :visible.sync="addRelationDialog"
  215. >
  216. <el-form
  217. :inline="true"
  218. :model="addRelationForm"
  219. ref="addRelationForm"
  220. :rules="addRelationRules"
  221. >
  222. <el-row>
  223. <el-form-item label="课程" class="pull-left" prop="courseId">
  224. <el-select
  225. class="input"
  226. :remote-method="getCourses4AddRelation"
  227. @focus="e => getCourses4AddRelation(e.target.value)"
  228. :loading="courseLoading4AddRelation"
  229. remote
  230. filterable
  231. clearable
  232. v-model="addRelationForm.courseId"
  233. placeholder="请选择"
  234. >
  235. <el-option
  236. v-for="item in courseList4AddRelationWrapper"
  237. :label="item.name"
  238. :value="item.id"
  239. :key="item.id"
  240. />
  241. </el-select>
  242. </el-form-item>
  243. <el-button type="primary" @click="submitAddRelationForm">
  244. 保 存
  245. </el-button>
  246. <el-button @click="addRelationDialog = false">取 消</el-button>
  247. </el-row>
  248. </el-form>
  249. </el-dialog>
  250. <!-- 页面列表 -->
  251. <el-table
  252. :data="tableData"
  253. border
  254. @selection-change="handleSelectionChange"
  255. >
  256. <el-table-column type="selection" width="35"> </el-table-column>
  257. <el-table-column prop="id" label="ID" width="60"> </el-table-column>
  258. <el-table-column prop="code" label="专业代码"> </el-table-column>
  259. <el-table-column prop="name" label="专业名称"> </el-table-column>
  260. <el-table-column prop="updateTime" label="更新时间" width="170">
  261. </el-table-column>
  262. <el-table-column label="操作" width="300">
  263. <template slot-scope="scope">
  264. <div>
  265. <el-button
  266. size="mini"
  267. type="primary"
  268. @click="relation(scope.row)"
  269. plain
  270. icon="el-icon-share"
  271. >
  272. 关联课程
  273. </el-button>
  274. <el-button
  275. size="mini"
  276. type="primary"
  277. icon="el-icon-edit"
  278. @click="edit(scope.row)"
  279. plain
  280. >
  281. 编辑
  282. </el-button>
  283. <el-button
  284. size="mini"
  285. type="danger"
  286. icon="el-icon-delete"
  287. @click="deleteId(scope.row)"
  288. >
  289. 删除
  290. </el-button>
  291. </div>
  292. </template>
  293. </el-table-column>
  294. </el-table>
  295. <div class="page pull-right">
  296. <el-pagination
  297. @current-change="handleCurrentChange"
  298. :current-page="currentPage"
  299. :page-size="pageSize"
  300. :page-sizes="[10, 20, 50, 100]"
  301. @size-change="handleSizeChange"
  302. layout="total, sizes, prev, pager, next, jumper"
  303. :total="total"
  304. />
  305. </div>
  306. <!-- 导入弹窗 -->
  307. <el-dialog title="导入窗口" width="420px" :visible.sync="impDialog">
  308. <el-form>
  309. <el-row>
  310. <el-form-item style="margin-left:20px">
  311. <el-upload
  312. class="form_left"
  313. ref="upload"
  314. accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  315. :action="uploadAction"
  316. :headers="uploadHeaders"
  317. :data="uploadData"
  318. :before-upload="beforeUpload"
  319. :on-progress="uploadProgress"
  320. :on-success="uploadSuccess"
  321. :on-error="uploadError"
  322. :file-list="fileList"
  323. :auto-upload="false"
  324. :multiple="false"
  325. >
  326. <el-button size="small" slot="trigger" type="primary">
  327. 选择文件
  328. </el-button>
  329. &nbsp;
  330. <el-button size="small" type="success" @click="submitUpload">
  331. 确认上传
  332. </el-button>
  333. <el-button size="small" type="danger" @click="removeFile">
  334. 清空文件
  335. </el-button>
  336. <el-button size="small" type="info" @click="exportFile">
  337. 下载模板
  338. </el-button>
  339. <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
  340. </el-upload>
  341. </el-form-item>
  342. </el-row>
  343. </el-form>
  344. </el-dialog>
  345. <!-- 导入错误信息列表 -->
  346. <el-dialog title="错误提示" :visible.sync="errDialog">
  347. <div
  348. class="text-danger"
  349. v-for="errMessage in errMessages"
  350. :key="errMessage.lineNum"
  351. >
  352. 第{{ errMessage.lineNum }}行:{{ errMessage.msg }}
  353. </div>
  354. <span slot="footer" class="dialog-footer">
  355. <el-button @click="errDialog = false">确定</el-button>
  356. </span>
  357. </el-dialog>
  358. </div>
  359. </section>
  360. </template>
  361. <script>
  362. import { CORE_API } from "@/constants/constants.js";
  363. import { mapState } from "vuex";
  364. export default {
  365. name: "Specially",
  366. data() {
  367. return {
  368. courseLoading: false,
  369. formSearch: {
  370. name: "",
  371. code: "",
  372. courseId: ""
  373. },
  374. speciallyForm: {
  375. id: null,
  376. name: "",
  377. code: ""
  378. },
  379. speciatlyId: "",
  380. speciallyDialog: false,
  381. courseDialog: false,
  382. loading: false,
  383. multipleSelection: [],
  384. tableData: [],
  385. currentPage: 1,
  386. pageSize: 10,
  387. total: 10,
  388. courseAllList: [],
  389. courseList: [],
  390. courseList4Search: [],
  391. courseAll: [],
  392. impDialog: false,
  393. uploadAction: CORE_API + "/specialty/import",
  394. uploadHeaders: {},
  395. uploadData: {},
  396. errMessages: [],
  397. errDialog: false,
  398. fileLoading: false,
  399. fileList: [],
  400. rules: {
  401. name: [{ required: true, message: "请输入专业名称", trigger: "blur" }],
  402. code: [{ required: true, message: "请输入专业代码", trigger: "blur" }]
  403. },
  404. courseDialogTitle: null,
  405. courseSearchForm: {
  406. specialtyId: null,
  407. code: "",
  408. name: ""
  409. },
  410. courseTableData: [],
  411. currentCoursePage: 1,
  412. coursePageSize: 10,
  413. courseTotal: 10,
  414. addRelationDialog: false,
  415. addRelationForm: {
  416. specialtyId: null,
  417. courseId: null
  418. },
  419. courseLoading4AddRelation: false,
  420. courseList4AddRelation: [],
  421. addRelationRules: {
  422. courseId: [
  423. {
  424. required: true,
  425. type: "number",
  426. message: "请选择课程",
  427. trigger: "change"
  428. }
  429. ]
  430. }
  431. };
  432. },
  433. computed: {
  434. ...mapState({
  435. user: state => state.user
  436. }),
  437. noBatchSelected() {
  438. return this.multipleSelection.length === 0;
  439. },
  440. courseAllListSelect() {
  441. let courseList = [];
  442. for (let course of this.courseAllList) {
  443. let courseInfo = course.name + "(" + course.code + ")";
  444. courseList.push({ id: course.id, courseInfo: courseInfo });
  445. }
  446. return courseList;
  447. },
  448. courseList4SearchWrapper() {
  449. var courseList = [];
  450. for (let course of this.courseList4Search) {
  451. var name = course.name + " - " + course.code;
  452. var id = course.id;
  453. courseList.push({ id: id, name: name, enable: course.enable });
  454. }
  455. return courseList;
  456. },
  457. courseList4AddRelationWrapper() {
  458. var courseList = [];
  459. for (let course of this.courseList4AddRelation) {
  460. var name = course.name + " - " + course.code;
  461. var id = course.id;
  462. courseList.push({ id: id, name: name, enable: course.enable });
  463. }
  464. return courseList;
  465. }
  466. },
  467. methods: {
  468. dialogBeforeClose() {
  469. this.$refs.speciallyForm.clearValidate();
  470. },
  471. handleSizeChange(val) {
  472. this.pageSize = val;
  473. this.searchForm();
  474. },
  475. resetPrimaryForm() {
  476. this.formSearch = {
  477. name: "",
  478. code: "",
  479. enable: "",
  480. level: "",
  481. specialtyId: ""
  482. };
  483. this.$refs.primaryForm.resetFields();
  484. },
  485. deleteRelation(row) {
  486. var courseId = row.id;
  487. var specialtyId = this.courseSearchForm.specialtyId;
  488. var param = new URLSearchParams({
  489. courseId: courseId,
  490. specialtyId: specialtyId
  491. });
  492. var url = CORE_API + "/courseSpeciatlyRelation/delete?" + param;
  493. this.$httpWithMsg.delete(url).then(() => {
  494. this.$notify({
  495. type: "success",
  496. message: "取消关联成功!"
  497. });
  498. return this.searchCoursePage();
  499. });
  500. },
  501. submitAddRelationForm() {
  502. this.$refs.addRelationForm.validate(valid => {
  503. if (valid) {
  504. var param = new URLSearchParams(this.addRelationForm);
  505. var url = CORE_API + "/courseSpeciatlyRelation/add?" + param;
  506. this.$httpWithMsg.post(url, this.speciallyForm).then(
  507. () => {
  508. this.$notify({
  509. type: "success",
  510. message: "添加成功!"
  511. });
  512. this.searchCoursePage();
  513. this.addRelationDialog = false;
  514. },
  515. () => (this.addRelationDialog = false)
  516. );
  517. } else {
  518. console.log("error submit!");
  519. return false;
  520. }
  521. });
  522. },
  523. addRelation() {
  524. this.addRelationForm.courseId = null;
  525. this.addRelationForm.specialtyId = this.courseSearchForm.specialtyId;
  526. this.addRelationDialog = true;
  527. // this.$refs.addRelationForm.resetFields();
  528. },
  529. searchCoursePage() {
  530. var param = new URLSearchParams(this.courseSearchForm);
  531. var url =
  532. CORE_API +
  533. "/course/coursePage/" +
  534. (this.currentPage - 1) +
  535. "/" +
  536. this.pageSize +
  537. "?" +
  538. param;
  539. this.$httpWithMsg.get(url).then(response => {
  540. console.log(response);
  541. this.courseTableData = response.data.content;
  542. this.courseTotal = response.data.totalElements;
  543. });
  544. },
  545. getCourses(query) {
  546. this.courseLoading = true;
  547. this.$httpWithMsg
  548. .get(CORE_API + "/course/query?name=" + query)
  549. .then(response => {
  550. this.courseList4Search = response.data;
  551. this.courseLoading = false;
  552. });
  553. },
  554. getCourses4AddRelation(query) {
  555. this.courseLoading4AddRelation = true;
  556. this.$httpWithMsg
  557. .get(CORE_API + "/course/query?name=" + query)
  558. .then(response => {
  559. this.courseList4AddRelation = response.data;
  560. this.courseLoading4AddRelation = false;
  561. });
  562. },
  563. handleSearchBtn() {
  564. this.currentPage = 1;
  565. this.searchForm();
  566. },
  567. //查询
  568. searchForm() {
  569. var param = new URLSearchParams(this.formSearch);
  570. var url =
  571. CORE_API +
  572. "/specialty/specialtyPage/" +
  573. (this.currentPage - 1) +
  574. "/" +
  575. this.pageSize +
  576. "?" +
  577. param;
  578. this.$httpWithMsg.get(url).then(response => {
  579. console.log("response :", response);
  580. this.tableData = response.data.content;
  581. this.total = response.data.totalElements;
  582. });
  583. },
  584. handleCurrentChange(val) {
  585. this.currentPage = val;
  586. this.currentPage = 1;
  587. this.searchForm();
  588. },
  589. handleCourseCurrentChange(val) {
  590. this.currentCoursePage = val;
  591. this.searchCoursePage();
  592. },
  593. //全选
  594. handleSelectionChange(val) {
  595. this.multipleSelection = val;
  596. },
  597. //删除方法
  598. deleteSchool() {
  599. this.$confirm("是否删除学校信息?", "提示", {
  600. confirmButtonText: "确定",
  601. cancelButtonText: "取消",
  602. type: "error"
  603. }).then(() => {
  604. this.loading = true;
  605. var vm = this;
  606. var url = CORE_API;
  607. vm.$httpWithMsg.delete(url).then(() => {
  608. this.loading = false;
  609. this.$notify({
  610. type: "success",
  611. message: "删除成功!"
  612. });
  613. //this.searchForm()
  614. });
  615. });
  616. },
  617. //保存
  618. submitForm(formData) {
  619. this.$refs[formData].validate(valid => {
  620. if (valid) {
  621. var url = CORE_API + "/specialty";
  622. //修改
  623. if (null != this.speciallyForm.id) {
  624. this.$httpWithMsg.put(url, this.speciallyForm).then(
  625. () => {
  626. this.$notify({
  627. type: "success",
  628. message: "修改成功!"
  629. });
  630. this.searchForm();
  631. this.speciallyDialog = false;
  632. },
  633. () => {
  634. this.searchForm();
  635. this.speciallyDialog = false;
  636. }
  637. );
  638. }
  639. //新增
  640. else {
  641. this.$httpWithMsg.post(url, this.speciallyForm).then(
  642. () => {
  643. this.$notify({
  644. type: "success",
  645. message: "新增成功!"
  646. });
  647. this.speciallyDialog = false;
  648. this.searchForm();
  649. },
  650. () => {
  651. this.speciallyDialog = false;
  652. return this.searchForm();
  653. }
  654. );
  655. }
  656. } else {
  657. console.log("error submit!");
  658. return false;
  659. }
  660. });
  661. },
  662. //重置
  663. resetForm(formData) {
  664. this.$refs[formData].resetFields();
  665. },
  666. close() {
  667. this.speciallyDialog = false;
  668. },
  669. //新增
  670. insert() {
  671. this.speciallyForm.id = null;
  672. this.speciallyForm.name = "";
  673. this.speciallyForm.code = "";
  674. this.speciallyDialog = true;
  675. },
  676. //修改
  677. edit(row) {
  678. this.speciallyForm = Object.assign({}, row);
  679. this.speciallyDialog = true;
  680. },
  681. //删除
  682. deleteId(row) {
  683. this.$confirm("是否删除该条课程信息?", "提示", {
  684. confirmButtonText: "确定",
  685. cancelButtonText: "取消",
  686. type: "error"
  687. }).then(() => {
  688. var url = CORE_API + "/specialty/" + row.id;
  689. this.$httpWithMsg.delete(url).then(() => {
  690. this.$notify({
  691. type: "success",
  692. message: "删除成功!"
  693. });
  694. this.searchForm();
  695. });
  696. });
  697. },
  698. //删除多条信息
  699. deleteIds() {
  700. if (this.multipleSelection.length === 0) {
  701. this.$notify({
  702. type: "warning",
  703. message: "请选择要删除的专业"
  704. });
  705. } else {
  706. this.$confirm("是否删除这些课程信息?", "提示", {
  707. confirmButtonText: "确定",
  708. cancelButtonText: "取消",
  709. type: "error"
  710. }).then(() => {
  711. var ids = [];
  712. for (var i = 0; i < this.multipleSelection.length; i++) {
  713. ids.push(this.multipleSelection[i].id);
  714. }
  715. var url = CORE_API + "/specialty/" + ids;
  716. this.$httpWithMsg.delete(url).then(() => {
  717. this.$notify({
  718. type: "success",
  719. message: "删除成功!"
  720. });
  721. this.searchForm();
  722. });
  723. });
  724. }
  725. },
  726. //关联课程
  727. relation(row) {
  728. this.courseDialogTitle =
  729. "关联课程列表 【专业名称:" +
  730. row.name +
  731. "】【专业代码:" +
  732. row.code +
  733. "】";
  734. this.courseSearchForm.specialtyId = row.id;
  735. this.courseSearchForm.code = "";
  736. this.courseSearchForm.name = "";
  737. this.searchCoursePage();
  738. this.courseDialog = true;
  739. },
  740. closeCourse() {
  741. this.courseDialog = false;
  742. },
  743. saveCourse() {
  744. //debugger;
  745. var url = CORE_API + "/CourseSpeciatly/addCourse/" + this.speciatlyId;
  746. this.$httpWithMsg.post(url, this.courseList).then(
  747. () => {
  748. this.$notify({
  749. type: "success",
  750. message: "课程关联成功!"
  751. });
  752. this.courseDialog = false;
  753. this.searchForm();
  754. },
  755. () => {
  756. this.$notify({
  757. type: "error",
  758. message: "课程关联失败!"
  759. });
  760. this.courseDialog = false;
  761. this.searchForm();
  762. }
  763. );
  764. },
  765. exportSpeciatly() {
  766. let param = new URLSearchParams(this.formSearch);
  767. window.open(
  768. CORE_API +
  769. "/specialty/export?$key=" +
  770. this.user.key +
  771. "&$token=" +
  772. this.user.token +
  773. "&" +
  774. param
  775. );
  776. },
  777. //导入
  778. impSpecialty() {
  779. this.impDialog = true;
  780. this.initUpload();
  781. },
  782. initUpload() {
  783. this.fileList = [];
  784. },
  785. beforeUpload(file) {
  786. console.log(file);
  787. },
  788. uploadProgress() {
  789. console.log("uploadProgress");
  790. },
  791. uploadSuccess(response) {
  792. if (!response.hasError) {
  793. this.$notify({
  794. message: "上传成功",
  795. type: "success"
  796. });
  797. this.fileLoading = false;
  798. this.impDialog = false;
  799. this.searchForm();
  800. } else {
  801. this.fileLoading = false;
  802. this.impDialog = false;
  803. this.errMessages = response.failRecords;
  804. this.errDialog = true;
  805. }
  806. },
  807. uploadError(response) {
  808. var json = JSON.parse(response.message);
  809. if (response.status == 500) {
  810. this.$notify({
  811. message: json.desc,
  812. type: "error"
  813. });
  814. }
  815. this.fileLoading = false;
  816. },
  817. //确定上传
  818. submitUpload() {
  819. if (!this.checkUpload()) {
  820. return false;
  821. }
  822. this.$refs.upload.submit();
  823. this.fileLoading = true;
  824. },
  825. checkUpload() {
  826. var fileList = this.$refs.upload.uploadFiles;
  827. if (fileList.length == 0) {
  828. this.$notify({
  829. message: "上传文件不能为空",
  830. type: "error"
  831. });
  832. return false;
  833. }
  834. if (fileList.length > 1) {
  835. this.$notify({
  836. message: "每次只能上传一个文件",
  837. type: "error"
  838. });
  839. return false;
  840. }
  841. for (let file of fileList) {
  842. if (!file.name.endsWith(".xlsx")) {
  843. this.$notify({
  844. message: "上传文件必须为xlsx格式",
  845. type: "error"
  846. });
  847. this.initUpload();
  848. return false;
  849. }
  850. }
  851. return true;
  852. },
  853. //清空文件
  854. removeFile() {
  855. // this.fileList = [];
  856. this.$refs.upload.clearFiles();
  857. },
  858. //下载模板
  859. exportFile() {
  860. window.location.href =
  861. CORE_API +
  862. "/specialty/importTemplate?$key=" +
  863. this.user.key +
  864. "&$token=" +
  865. this.user.token;
  866. }
  867. },
  868. //初始化查询
  869. created() {
  870. this.searchForm();
  871. this.uploadHeaders = {
  872. key: this.user.key,
  873. token: this.user.token
  874. };
  875. }
  876. };
  877. </script>
  878. <style scoped>
  879. .page {
  880. margin-top: 10px;
  881. }
  882. .pull_center {
  883. margin-left: 120px;
  884. }
  885. .pull_length {
  886. width: 200px;
  887. }
  888. </style>