index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <!-- 教研中心录入 -->
  3. <div class="teacher-devEntering">
  4. <div class="nav">
  5. <Header />
  6. </div>
  7. <Nav />
  8. <div class="top">
  9. <div class="seek" @keydown="downSeekdata">
  10. <el-input
  11. v-model="keyWord"
  12. @change="keyWord = keyWord.trim()"
  13. style="width: 400px"
  14. placeholder="请输入内容"
  15. ></el-input>
  16. <img
  17. @click="seekData"
  18. src="../../assets/teacherdev/Group2149.png"
  19. alt=""
  20. />
  21. </div>
  22. <div class="btn">
  23. <!-- <el-button type="primary">批量上传</el-button> -->
  24. <div style="margin-right: 23px">
  25. <!--
  26. :fileList="fileList"
  27. -->
  28. <Upload
  29. type="批量上传"
  30. :changeFillId="changeFillId"
  31. :filleNumber="20"
  32. :accept="'.doc,.docx,.xls,.xlsx,.pdf,.ppt,.pptx'"
  33. />
  34. </div>
  35. <el-button type="primary" @click="newDocument">新建文档</el-button>
  36. </div>
  37. </div>
  38. <div class="table" v-loading="loading">
  39. <el-table :data="tableData.data" stripe style="width: 100%">
  40. <el-table-column
  41. label="文档名称"
  42. prop="name"
  43. width="300"
  44. ></el-table-column>
  45. <el-table-column
  46. label="文档类型"
  47. prop="type"
  48. width="150"
  49. :formatter="handlefileType"
  50. ></el-table-column>
  51. <el-table-column
  52. label="发布时间"
  53. prop="updateTime"
  54. width="200"
  55. ></el-table-column>
  56. <el-table-column
  57. :formatter="handledownload"
  58. label="下载"
  59. prop="download"
  60. width="150"
  61. ></el-table-column>
  62. <el-table-column
  63. label="状态"
  64. prop="status"
  65. width="150"
  66. :formatter="handleStatus"
  67. ></el-table-column>
  68. <el-table-column label="操作" prop>
  69. <template slot-scope="scope">
  70. <el-button @click="handleEdit(scope.row, scope.$index)" type="text"
  71. >编辑</el-button
  72. >
  73. <el-button @click="handleDel(scope.row)" type="text"
  74. >删除</el-button
  75. >
  76. <el-button
  77. v-if="scope.row.status != 4"
  78. @click="up(scope.row)"
  79. type="text"
  80. >上架</el-button
  81. >
  82. <el-button
  83. v-if="scope.row.status != 3"
  84. @click="down(scope.row)"
  85. type="text"
  86. >下架</el-button
  87. >
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <el-pagination
  92. @current-change="handleCurrentChange"
  93. layout="prev, pager, next"
  94. :page-size="pageSize"
  95. :total="tableData.total"
  96. :current-page="pageNum"
  97. >
  98. </el-pagination>
  99. </div>
  100. </div>
  101. </template>
  102. <script>
  103. import Header from "@/components/Header";
  104. import Nav from "@/components/teacher-devEntering/Nav";
  105. import Upload from "@/components/Upload";
  106. import { getToken } from "@/utils/auth";
  107. import {
  108. VerifyLogin,
  109. materiallist,
  110. materialdelete,
  111. materialinsert,
  112. attachmentinsert,
  113. materialoutOfStockAction,
  114. materialinStockAction,
  115. } from "@/api/api";
  116. import Cookies from "js-cookie";
  117. export default {
  118. name: "teacher-devEntering",
  119. components: {
  120. Header,
  121. Nav,
  122. Upload,
  123. },
  124. data() {
  125. return {
  126. tableData: [
  127. {
  128. name: "教师培训公开课1",
  129. type: "ppt",
  130. creadTime: "2021-10-10 15:30",
  131. download: 1,
  132. },
  133. {
  134. name: "教师培训公开课2",
  135. type: "pdf",
  136. creadTime: "2021-10-10 15:30",
  137. download: 0,
  138. },
  139. ],
  140. fileList: null,
  141. loading: false,
  142. keyWord: "",
  143. pageNum: 1,
  144. pageSize: 10,
  145. };
  146. },
  147. methods: {
  148. // 批量上传
  149. changeFillId(file, fileList) {
  150. this.loading = true;
  151. let name = file.file_name.split(".")[0];
  152. let type = file.file_name.split(".")[1];
  153. let tag = ["downloadable", "TEXTBOOK", type];
  154. let attachmentList = [];
  155. attachmentList.push({
  156. name: file.file_name,
  157. fileId: file.file_id,
  158. fileType: type,
  159. });
  160. attachmentinsert({
  161. attachmentList: attachmentList,
  162. type: "3",
  163. tenantId: "2021052017-HFTZIRVKWOWPAUU",
  164. })
  165. .then((res) => {
  166. materialinsert({
  167. name: name,
  168. price: "-1",
  169. teacherList: [""],
  170. tenantId: "2021052017-HFTZIRVKWOWPAUU",
  171. tagList: tag,
  172. attachmentIdList: res.data.attachmentIdList,
  173. })
  174. .then((ress) => {
  175. this.loading = false;
  176. this.getdata();
  177. })
  178. .catch((res) => {
  179. this.loading = false;
  180. });
  181. })
  182. .catch((res) => {
  183. this.loading = false;
  184. });
  185. // let fileList1 = JSON.parse(JSON.stringify(fileList));
  186. // this.fileList = fileList1;
  187. },
  188. // 搜索
  189. seekData() {
  190. this.pageNum = 1;
  191. this.getdata();
  192. },
  193. downSeekdata(e) {
  194. if (e.keyCode == 13) {
  195. this.pageNum = 1;
  196. this.getdata();
  197. }
  198. },
  199. // 换页
  200. async handleCurrentChange(pagesize) {
  201. this.pageNum = pagesize;
  202. this.getdata();
  203. },
  204. // 编辑
  205. handleEdit(item) {
  206. if (item.status == 4) {
  207. this.$message.warning("上架状态下不可以进行编辑操作");
  208. return;
  209. }
  210. this.$router.push({
  211. path: "/creadDocument",
  212. query: {
  213. materialId: item.id,
  214. },
  215. });
  216. },
  217. // 删除
  218. handleDel(item) {
  219. if (item.status == 4) {
  220. this.$message.warning("上架状态下不可以进行删除操作");
  221. return;
  222. }
  223. this.$confirm("确定要删除此学习资料吗?", "提示", {
  224. confirmButtonText: "确定",
  225. cancelButtonText: "取消",
  226. type: "warning",
  227. })
  228. .then(() => {
  229. this.loading = true;
  230. materialdelete({
  231. id: `${item.id}`,
  232. })
  233. .then((res) => {
  234. this.getdata();
  235. this.$message({
  236. type: "success",
  237. message: "删除成功",
  238. });
  239. })
  240. .catch((res) => {
  241. this.loading = false;
  242. });
  243. })
  244. .catch(() => {
  245. this.loading = false;
  246. });
  247. },
  248. // 上架
  249. up(item) {
  250. if (item.status == 4) {
  251. this.$message.warning("该课程已经上架了");
  252. return;
  253. }
  254. if (!item.price || !item.teacher[0]) {
  255. this.$message.warning("请先去完善信息再上架");
  256. return;
  257. }
  258. this.loading = true;
  259. materialinStockAction({
  260. id: `${item.id}`,
  261. })
  262. .then((res) => {
  263. this.getdata();
  264. this.$message({
  265. type: "success",
  266. message: "上架成功",
  267. });
  268. })
  269. .catch(() => {
  270. this.loading = false;
  271. });
  272. },
  273. // 下架
  274. down(item) {
  275. if (item.status == 3) {
  276. this.$message.warning("该课程已经下架了");
  277. return;
  278. }
  279. this.loading = true;
  280. materialoutOfStockAction({
  281. id: `${item.id}`,
  282. })
  283. .then((res) => {
  284. this.getdata();
  285. this.$message({
  286. type: "success",
  287. message: "下架成功",
  288. });
  289. })
  290. .catch(() => {
  291. this.loading = false;
  292. });
  293. },
  294. // 处理下载
  295. handledownload(row) {
  296. let index = row.tag.indexOf("downloadable");
  297. if (index != -1) {
  298. return "开启";
  299. } else {
  300. return "关闭";
  301. }
  302. },
  303. // 处理文档类型
  304. handlefileType(row) {
  305. let index = row.tag.indexOf("downloadable");
  306. if (index != -1) {
  307. return row.tag[2];
  308. } else {
  309. return row.tag[1];
  310. }
  311. },
  312. // 处理发布状态
  313. handleStatus(row) {
  314. if (row.status == 4) {
  315. return "已上架";
  316. } else if (row.status == 3) {
  317. return "已下架";
  318. }
  319. },
  320. // 新建文档
  321. newDocument() {
  322. this.$router.push({ path: "/creadDocument" });
  323. },
  324. getdata() {
  325. this.loading = true;
  326. materiallist({
  327. pageNum: this.pageNum,
  328. pageSize: this.pageSize,
  329. keyWord: this.keyWord,
  330. isSelectForUpdate: true,
  331. orderType: "DESC",
  332. orderColumn: "2",
  333. })
  334. .then((res) => {
  335. this.tableData = res.data;
  336. this.loading = false;
  337. })
  338. .catch(() => {
  339. this.loading = false;
  340. });
  341. },
  342. },
  343. mounted() {
  344. this.loading = true;
  345. let userInfor = JSON.parse(getToken());
  346. let userCode = "",
  347. userType = "",
  348. sessionId = "";
  349. if (userInfor) {
  350. userCode = userInfor.user_code;
  351. userType = userInfor.user_type;
  352. sessionId = userInfor.session_id;
  353. }
  354. // 验证登录拿到JSESSIONID放到cookies中后面的接口用来验证用户身份
  355. VerifyLogin({
  356. userCode,
  357. userType,
  358. sessionId,
  359. })
  360. .then((res) => {
  361. if (res.code != -1) {
  362. Cookies.set("JSESSIONID", res.data.JSESSSIONID);
  363. this.getdata();
  364. }
  365. })
  366. .catch(() => {
  367. this.loading = false;
  368. });
  369. },
  370. };
  371. </script>
  372. <style lang="scss" scoped>
  373. .teacher-devEntering {
  374. .nav {
  375. height: 64px;
  376. background: #424141;
  377. }
  378. .top {
  379. width: 1200px;
  380. margin: 0 auto;
  381. margin-top: 40px;
  382. display: flex;
  383. justify-content: space-between;
  384. padding: 0 90px;
  385. .seek {
  386. position: relative;
  387. img {
  388. cursor: pointer;
  389. width: 19px;
  390. position: absolute;
  391. right: 10px;
  392. top: 10px;
  393. }
  394. }
  395. .btn {
  396. display: flex;
  397. text-align: right;
  398. }
  399. }
  400. .table {
  401. width: 1200px;
  402. margin: 0 auto;
  403. margin-top: 50px;
  404. }
  405. }
  406. </style>