creadDocument.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <div
  3. :class="['creadDocument', language_type == 'AR' ? 'text_right' : '']"
  4. v-loading="loading"
  5. v-if="isData"
  6. >
  7. <Header />
  8. <!-- 创建文档 -->
  9. <Nav :title="$t('Key551')" />
  10. <div class="title">
  11. <div>
  12. <!-- 创建文档 -->
  13. {{ $t("Key551") }}
  14. </div>
  15. <div class="btn">
  16. <!-- 完成 -->
  17. <el-button @click="submit('form')" style="width: 180px" type="primary">{{
  18. $t("Key82")
  19. }}</el-button>
  20. <el-button @click="preview" style="width: 180px" type="warning">
  21. <!-- 预览 -->{{ $t("Key144") }}
  22. </el-button>
  23. </div>
  24. </div>
  25. <div class="content">
  26. <div class="from">
  27. <!-- 基本信息的form表单 -->
  28. <el-form
  29. ref="form"
  30. :model="form"
  31. :rules="rules"
  32. label-width="180px"
  33. :show-message="false"
  34. >
  35. <!-- 文档 -->
  36. <el-form-item :label="$t('Key225')" prop="name">
  37. <!-- 请输入文档名称 -->
  38. <el-input
  39. v-model="form.name"
  40. style="width: 500px"
  41. :placeholder="$t('Key552')"
  42. @change="form.name = form.name.trim()"
  43. maxlength="50"
  44. show-word-limit
  45. ></el-input>
  46. </el-form-item>
  47. <!-- 作者 -->
  48. <el-form-item :label="$t('Key227')" prop="author">
  49. <!-- 多个作者请用逗号隔开 -->
  50. <el-input
  51. v-model="form.author"
  52. style="width: 500px"
  53. :placeholder="$t('Key553')"
  54. @change="authorChange"
  55. maxlength="20"
  56. show-word-limit
  57. ></el-input>
  58. </el-form-item>
  59. <!-- 定价 -->
  60. <el-form-item :label="$t('Key135')" prop="price">
  61. <el-input
  62. v-model="form.price"
  63. style="width: 500px"
  64. :placeholder="$t('Key138')"
  65. @input="priceInput"
  66. @blur="priceBlur"
  67. >
  68. <template slot="prepend">¥</template>
  69. </el-input>
  70. </el-form-item>
  71. <!-- 所属机构 -->
  72. <el-form-item :label="$t('Key136')" prop="institutionID">
  73. <el-select
  74. v-model="form.institutionID"
  75. style="width: 500px"
  76. :placeholder="$t('Key139')"
  77. >
  78. <el-option
  79. v-for="item in institutionList"
  80. :key="item.id"
  81. :label="item.tenantName"
  82. :value="item.tenantId"
  83. >
  84. </el-option>
  85. </el-select>
  86. </el-form-item>
  87. <!-- 下载 -->
  88. <el-form-item :label="$t('Key242')" prop="download">
  89. <el-radio-group v-model="form.download">
  90. <el-radio label="downloadable"> <!-- 开启 -->{{ $t("Key245") }} </el-radio>
  91. <el-radio label="0"> <!-- 关闭 -->{{ $t("Key246") }} </el-radio>
  92. </el-radio-group>
  93. </el-form-item>
  94. <!-- 分类 -->
  95. <el-form-item :label="$t('Key243')" prop="classify">
  96. <el-radio-group v-model="form.classify">
  97. <el-radio label="TEXTBOOK"> <!-- 教辅资料 -->{{ $t("Key554") }}</el-radio>
  98. <el-radio label="TEACHING"> <!-- 教研资料 -->{{ $t("Key214") }} </el-radio>
  99. <el-radio label="TOOLBOOK">
  100. <!-- 工具书 -->
  101. {{ $t("Key555") }}
  102. </el-radio>
  103. </el-radio-group>
  104. </el-form-item>
  105. <!-- 文档 -->
  106. <el-form-item :label="$t('Key244')" prop="file">
  107. <Upload
  108. :accept="'.doc,.docx,.xls,.xlsx,.pdf,.ppt,.pptx'"
  109. :fileList="form.fileList"
  110. :changeFillId="changeFillId"
  111. :filleNumber="1"
  112. >
  113. </Upload>
  114. </el-form-item>
  115. </el-form>
  116. </div>
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import Header from "@/components/Header";
  122. import Nav from "@/components/teacher-devEntering/Nav";
  123. import Upload from "@/components/Upload";
  124. import { mapGetters } from "vuex";
  125. import { updateWordPack } from "@/utils/i18n";
  126. import {
  127. materialdetail,
  128. attachmentinsert,
  129. materialinsert,
  130. materialupdate,
  131. usertenant,
  132. } from "@/api/api";
  133. export default {
  134. name: "creadDocument",
  135. components: {
  136. Header,
  137. Nav,
  138. Upload,
  139. },
  140. data() {
  141. return {
  142. isData: false,
  143. form: {
  144. name: "",
  145. author: "",
  146. price: "",
  147. download: "downloadable",
  148. classify: "TEXTBOOK",
  149. fileList: [],
  150. file: null,
  151. institutionID: null, //当前机构id
  152. },
  153. authorList: null,
  154. loading: false,
  155. rules: {
  156. name: [{ required: true }],
  157. price: [{ required: true }],
  158. author: [{ required: true }],
  159. institutionID: [{ required: true }],
  160. },
  161. isSubmit: false, //是更新还是插入
  162. materialId: null, //学习资料id
  163. institutionList: null, //机构列表
  164. };
  165. },
  166. computed: {
  167. ...mapGetters(["language_type"]),
  168. },
  169. methods: {
  170. priceInput(e) {
  171. this.form.price = this.form.price.match(/^\d*(\.?\d{0,2})/g)[0] || "";
  172. },
  173. // 处理教材价格 失去焦点保留两位小数
  174. priceBlur() {
  175. if (this.form.price) this.form.price = Number(this.form.price).toFixed(2);
  176. },
  177. // 预览
  178. preview() {
  179. if (!this.isSubmit) {
  180. this.$message.warning(this.$t("Key556")); //"请先保存再预览"
  181. return;
  182. }
  183. const { href } = this.$router.resolve({
  184. path: "Preview",
  185. query: {
  186. id: this.materialId,
  187. type: "preview",
  188. },
  189. });
  190. window.open(href, "_blank");
  191. },
  192. // 处理作者数据
  193. authorChange() {
  194. this.form.author = this.form.author.trim();
  195. let index1 = this.form.author.indexOf(",");
  196. let index2 = this.form.author.indexOf(",");
  197. let newauthorList = []; //处理之后的老师
  198. if (index1 != -1) {
  199. let arr = this.form.author.split(",");
  200. arr.forEach((item) => {
  201. newauthorList.push(item);
  202. });
  203. } else if (index2 != -1) {
  204. let arr = this.form.author.split(",");
  205. arr.forEach((item) => {
  206. newauthorList.push(item);
  207. });
  208. } else {
  209. newauthorList.push(this.form.author);
  210. }
  211. this.authorList = newauthorList;
  212. },
  213. changeFillId(file, fileList) {
  214. let fileList1 = JSON.parse(JSON.stringify(fileList));
  215. this.form.fileList = fileList1;
  216. },
  217. // 完成
  218. submit(formName) {
  219. this.loading = true;
  220. let flag = false;
  221. this.$refs[formName].validate((valid) => {
  222. if (valid) {
  223. } else {
  224. flag = true;
  225. return false;
  226. }
  227. });
  228. if (flag) {
  229. this.$message.warning(this.$t("Key605")); //"请填写完整"
  230. this.loading = false;
  231. return;
  232. }
  233. if ((this.form.price * 1).toString() == "NaN") {
  234. this.$message.warning(this.$t("Key557")); //"价格必须为数字"
  235. this.loading = false;
  236. return;
  237. }
  238. if (this.form.fileList.length == 0) {
  239. this.$message.warning(this.$t("Key558")); // "请上传文件"
  240. this.loading = false;
  241. return;
  242. }
  243. // 处理上传附件的数据
  244. let attachmentList = [];
  245. let fileType = "";
  246. this.form.fileList.forEach((item) => {
  247. let type = item.name.split(".")[1];
  248. if (item.response) {
  249. attachmentList.push({
  250. name: item.name,
  251. fileId: item.response.file_info_list[0].file_id,
  252. fileType: type,
  253. });
  254. fileType = type;
  255. } else {
  256. attachmentList.push({
  257. name: item.name,
  258. fileId: item.fileId,
  259. fileType: item.fileType,
  260. });
  261. fileType = item.fileType;
  262. }
  263. });
  264. let tag = null;
  265. if (this.form.download == "downloadable") {
  266. tag = ["downloadable", `${this.form.classify}`, fileType];
  267. } else {
  268. tag = [`${this.form.classify}`, fileType];
  269. }
  270. if (!this.isSubmit) {
  271. // 插入接口 北语机构id 2021052017-HFTZIRVKWOWPAUU
  272. // 首先上传附件获取文件对应id
  273. attachmentinsert({
  274. attachmentList: attachmentList,
  275. type: "3",
  276. tenantId: this.form.institutionID,
  277. })
  278. .then((res) => {
  279. console.log(res);
  280. // 保存
  281. materialinsert({
  282. name: this.form.name,
  283. price: this.form.price,
  284. teacherList: this.authorList,
  285. tenantId: this.form.institutionID,
  286. tagList: tag,
  287. attachmentIdList: res.data.attachmentIdList,
  288. })
  289. .then((ress) => {
  290. this.materialId = ress.data.materialId;
  291. this.isSubmit = true;
  292. this.loading = false;
  293. this.$message({
  294. type: "success",
  295. message: ress.msg,
  296. });
  297. this.$router.replace({
  298. path: "/creadDocument",
  299. query: {
  300. materialId: this.materialId,
  301. },
  302. });
  303. })
  304. .catch((res) => {
  305. this.loading = false;
  306. });
  307. })
  308. .catch((res) => {
  309. this.loading = false;
  310. });
  311. } else {
  312. console.log("走更新接口");
  313. attachmentinsert({
  314. attachmentList: attachmentList,
  315. type: "3",
  316. tenantId: this.form.institutionID,
  317. })
  318. .then((res) => {
  319. materialupdate({
  320. id: this.materialId,
  321. name: this.form.name,
  322. price: this.form.price,
  323. teacherList: this.authorList,
  324. tenantId: this.form.institutionID,
  325. tagList: tag,
  326. attachmentIdList: res.data.attachmentIdList,
  327. })
  328. .then((ress) => {
  329. this.loading = false;
  330. this.$message({
  331. type: "success",
  332. message: ress.msg,
  333. });
  334. this.getdetail();
  335. })
  336. .catch((res) => {
  337. this.loading = false;
  338. });
  339. })
  340. .catch((res) => {
  341. this.loading = false;
  342. });
  343. }
  344. },
  345. // 查询详情
  346. getdetail() {
  347. this.loading = true;
  348. materialdetail({
  349. materialId: this.materialId,
  350. isSelectForUpdate: true,
  351. })
  352. .then((res) => {
  353. if (res.data.result.status == 4) {
  354. this.$router.push("/teacherdevEntering");
  355. // "此课程处于上架状态不可以进行编辑"
  356. this.$message.warning(this.$t("Key559"));
  357. return;
  358. }
  359. for (let key in this.form) {
  360. this.form[key] = res.data.result[key];
  361. }
  362. this.loading = false;
  363. this.isSubmit = true;
  364. this.form.fileList = JSON.parse(res.data.result.attachment);
  365. this.form.author = "";
  366. this.form.institutionID = res.data.result.tenantId;
  367. res.data.result.teacher.forEach((item, i) => {
  368. if (i == res.data.result.teacher.length - 1) {
  369. this.form.author += item;
  370. } else {
  371. this.form.author += item + ",";
  372. }
  373. });
  374. let index = res.data.result.tag.indexOf("downloadable");
  375. if (index != -1) {
  376. this.form.download = res.data.result.tag[0];
  377. this.form.classify = res.data.result.tag[1];
  378. } else {
  379. this.form.download = "0";
  380. this.form.classify = res.data.result.tag[0];
  381. }
  382. })
  383. .catch((res) => {
  384. this.loading = false;
  385. });
  386. },
  387. },
  388. async created() {
  389. await updateWordPack({
  390. word_key_list: [
  391. "Key5",
  392. "Key8",
  393. "Key9",
  394. "Key39",
  395. "Key83",
  396. "Key114",
  397. "Key135",
  398. "Key136",
  399. "Key138",
  400. "Key139",
  401. "Key144",
  402. "Key152",
  403. "Key214",
  404. "Key225",
  405. "Key227",
  406. "Key242",
  407. "Key243",
  408. "Key244",
  409. "Key245",
  410. "Key246",
  411. "Key82",
  412. "Key551",
  413. "Key552",
  414. "Key553",
  415. "Key554",
  416. "Key555",
  417. "Key556",
  418. "Key557",
  419. "Key558",
  420. "Key559",
  421. "Key605",
  422. ],
  423. });
  424. this.isData = true;
  425. this.loading = true;
  426. this.materialId = this.$route.query.materialId;
  427. if (this.materialId) {
  428. this.getdetail();
  429. }
  430. usertenant({})
  431. .then((res) => {
  432. if (res.status == 1) {
  433. this.institutionList = res.data.tenantIdAndNameListEditable;
  434. this.loading = false;
  435. }
  436. })
  437. .catch((res) => {
  438. this.loading = false;
  439. });
  440. },
  441. mounted() {},
  442. };
  443. </script>
  444. <style lang="scss" scoped>
  445. .creadDocument {
  446. height: 100%;
  447. .title {
  448. display: flex;
  449. justify-content: space-between;
  450. height: 100px;
  451. background: #f3f7fa;
  452. line-height: 80px;
  453. padding-left: 40px;
  454. padding-right: 40px;
  455. font-size: 32px;
  456. }
  457. .content {
  458. height: 100%;
  459. display: flex;
  460. .from {
  461. width: 100%;
  462. padding: 50px 20px;
  463. // max-width: 753px;
  464. }
  465. .addclass {
  466. width: 500px;
  467. height: 300px;
  468. border: 1px solid black;
  469. ul {
  470. list-style: none;
  471. }
  472. padding-left: 20px;
  473. }
  474. }
  475. }
  476. </style>
  477. <style lang="scss">
  478. .content {
  479. .el-form-item__label {
  480. font-size: 16px;
  481. color: #000000;
  482. }
  483. .el-upload-list__item-name {
  484. margin-left: 50px;
  485. }
  486. .el-form-item__error {
  487. margin-left: 50px;
  488. }
  489. }
  490. .text_right {
  491. .el-form-item {
  492. display: flex;
  493. .el-form-item__label {
  494. float: none;
  495. }
  496. }
  497. }
  498. </style>