specially.vue 25 KB

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