Preview.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <!-- 预览 -->
  3. <div class="tarcer-dev-Preview" v-loading="loading">
  4. <div class="header">
  5. <Header />
  6. <div class="shade"></div>
  7. </div>
  8. <HeaderOne v-if="!Ispreview && data" :text="data.name" :allList="allList" />
  9. <div class="main" v-if="data">
  10. <div class="flassify">
  11. <div class="text">
  12. <p class="p1">{{ data.name }}</p>
  13. <p class="p2">
  14. <span v-for="(item, i) in data.teacher" :key="i + item">
  15. {{ item }}{{ i == data.teacher.length - 1 ? "" : "," }}
  16. </span>
  17. </p>
  18. <p>{{ data.updateTime }}</p>
  19. </div>
  20. <div class="pay_collect" v-if="!Ispreview">
  21. <div class="price" v-if="!data.isPurchased">
  22. <span class="price_1" v-text="changePrice('1', data.price)"></span>
  23. <span class="price_2" v-text="changePrice('2', data.price)"></span>
  24. </div>
  25. <div class="pay" @click="buy" v-if="!data.isPurchased">购买</div>
  26. <div class="download" v-if="data.isPurchased && IsDownload">
  27. <img
  28. @click="download"
  29. src="../../assets/teacherdev/download.png"
  30. alt=""
  31. />
  32. <!-- <span>DOWNLOAD</span> -->
  33. </div>
  34. <div class="collect">
  35. <img
  36. @click="changeCollect"
  37. v-show="!data.isFavorite"
  38. src="../../assets/teacherdev/collect4.png"
  39. alt=""
  40. />
  41. <img
  42. @click="changeCollect"
  43. v-show="data.isFavorite"
  44. src="../../assets/teacherdev/collect3.png"
  45. alt=""
  46. />
  47. </div>
  48. </div>
  49. </div>
  50. <div :class="data.isPurchased || Ispreview ? 'buy' : 'NObuy'">
  51. <!--fileUrl需要改成安全地址 file_url_https -->
  52. <iframe
  53. v-if="
  54. attachment[0].fileType != 'pdf' && attachment[0].fileType != 'PDF'
  55. "
  56. :src="
  57. 'https://view.officeapps.live.com/op/view.aspx?src=' +
  58. `${attachment[0].fileUrlHttps}`
  59. "
  60. width="100%"
  61. height="1000px"
  62. scrolling="no"
  63. id="if"
  64. >
  65. </iframe>
  66. <pdf
  67. v-else
  68. ref="pdf"
  69. :src="attachment[0].fileRelativePath"
  70. v-for="i in numPages"
  71. :key="i"
  72. :page="i"
  73. >
  74. {{ i / numPages }}
  75. </pdf>
  76. </div>
  77. <div v-if="!data.isPurchased && !Ispreview" @click="buy" class="buyBtn">
  78. 点击购买
  79. </div>
  80. </div>
  81. <el-dialog
  82. :visible.sync="NopymentShow"
  83. width="720px"
  84. :before-close="closeNoPyment"
  85. >
  86. <div class="dialogTitle" slot="title">商品详情</div>
  87. <Confirmorder
  88. ref="Confirmorder"
  89. :data="data"
  90. :goods_type="401"
  91. :changeOrderNumber="changeOrderNumber"
  92. />
  93. </el-dialog>
  94. <el-dialog
  95. top="50px"
  96. :title="'订单号:' + orderNumber"
  97. :visible.sync="PymentShow"
  98. width="720px"
  99. :before-close="closePyment"
  100. >
  101. <Payment
  102. :data="data"
  103. :orderNumber="orderNumber"
  104. :closePyment="closePyment"
  105. />
  106. </el-dialog>
  107. </div>
  108. </template>
  109. <script>
  110. import Header from "@/components/Header";
  111. import HeaderOne from "@/components/teacher-dev/HeaderOne";
  112. import pdf from "vue-pdf";
  113. import Confirmorder from "@/components/payment/Confirmorder";
  114. import Payment from "@/components/payment/Payment";
  115. import Cookies from "js-cookie";
  116. import { getToken } from "@/utils/auth";
  117. import {
  118. materialdetail,
  119. materialfavoriteinsert,
  120. materialfavoritedelete,
  121. materialvisit,
  122. LearnWebSI,
  123. } from "@/api/api";
  124. export default {
  125. name: "tarcer-dev-Preview",
  126. components: {
  127. Header,
  128. HeaderOne,
  129. pdf,
  130. Confirmorder,
  131. Payment,
  132. },
  133. data() {
  134. return {
  135. numPages: null,
  136. isCollect: false,
  137. materialId: null,
  138. data: null,
  139. attachment: null,
  140. loading: false,
  141. Ispreview: "", // 是不是预览
  142. NopymentShow: false, //添加订单弹窗
  143. PymentShow: false, //支付订单弹窗
  144. orderNumber: null, //订单号
  145. IsDownload: false, //是否可以下载
  146. allList: null,
  147. };
  148. },
  149. computed: {},
  150. methods: {
  151. // 下载
  152. download() {
  153. let userInfor = JSON.parse(getToken());
  154. let UserCode = "",
  155. UserType = "",
  156. SessionID = "";
  157. if (userInfor) {
  158. UserCode = userInfor.user_code;
  159. UserType = userInfor.user_type;
  160. SessionID = userInfor.session_id;
  161. }
  162. let FileID = this.attachment[0].fileId;
  163. let data = {
  164. SessionID,
  165. UserCode,
  166. UserType,
  167. FileID,
  168. };
  169. location.href =
  170. process.env.VUE_APP_BASE_API +
  171. `/GCLSFileServer/WebFileDownload?UserCode=${data.UserCode}&UserType=${data.UserType}&SessionID=${data.SessionID}&FileID=${data.FileID}`;
  172. },
  173. // 生成订单 同时切换到支付弹窗
  174. changeOrderNumber(
  175. val,
  176. back_discount_code,
  177. discount_money,
  178. receivables_money
  179. ) {
  180. this.orderNumber = val;
  181. this.NopymentShow = false;
  182. this.data.back_discount_code = back_discount_code;
  183. this.data.discount_money = discount_money;
  184. this.data.receivables_money = receivables_money;
  185. this.PymentShow = true;
  186. console.log(this.data);
  187. },
  188. closeNoPyment() {
  189. this.NopymentShow = false;
  190. this.$refs.Confirmorder.clearData();
  191. },
  192. closePyment(str) {
  193. this.PymentShow = false;
  194. if (str == "支付成功") {
  195. this.getdetail();
  196. }
  197. },
  198. // 处理价格
  199. changePrice(type, item) {
  200. if (item.indexOf(".") != -1) {
  201. this.data.price = item.split(".")[0] + "." + item.split(".")[1];
  202. if (type == 1) {
  203. return item.split(".")[0];
  204. } else if (type == 2) {
  205. return "." + item.split(".")[1];
  206. }
  207. } else {
  208. this.data.price = item + ".00";
  209. if (type == 1) {
  210. return item;
  211. }
  212. if (type == 2) {
  213. return ".00";
  214. }
  215. }
  216. },
  217. // 获取pdf的页数
  218. getNumPages() {
  219. this.loading = true;
  220. let _this = this;
  221. let loadingTask = pdf.createLoadingTask(
  222. _this.attachment[0].fileRelativePath
  223. );
  224. loadingTask.promise
  225. .then((pdf) => {
  226. if (_this.data.isPurchased) {
  227. _this.numPages = pdf.numPages;
  228. } else {
  229. _this.numPages = 2;
  230. }
  231. _this.loading = false;
  232. })
  233. .catch((err) => {
  234. console.error("pdf 加载失败", err);
  235. });
  236. },
  237. // 修改收藏状态
  238. changeCollect() {
  239. this.loading = true;
  240. if (this.data.isFavorite) {
  241. let Mname = "order-collection_manager-CancelMyGoodsCollection";
  242. LearnWebSI(Mname, {
  243. goods_id_list: [this.materialId],
  244. goods_type: 401,
  245. })
  246. .then((res) => {
  247. this.$message({
  248. type: "success",
  249. message: "取消收藏成功",
  250. });
  251. this.loading = false;
  252. this.getdetail();
  253. })
  254. .catch((res) => {
  255. this.loading = false;
  256. });
  257. } else {
  258. let Mname = "order-collection_manager-AddMyCollection";
  259. LearnWebSI(Mname, {
  260. goods_id: this.materialId,
  261. goods_type: 401,
  262. goods_name: this.data.name,
  263. goods_person_name_desc: this.data.teacher,
  264. goods_picture_id: this.data.coverFileId,
  265. goods_price: this.data.price,
  266. })
  267. .then((res) => {
  268. this.$message({
  269. type: "success",
  270. message: "收藏成功",
  271. });
  272. this.loading = false;
  273. this.getdetail();
  274. })
  275. .catch((res) => {
  276. this.loading = false;
  277. });
  278. }
  279. },
  280. // 购买
  281. buy() {
  282. if (!this.data.isAudited) {
  283. this.$message.warning("您还未通过审核不能购买");
  284. return;
  285. }
  286. this.NopymentShow = true;
  287. },
  288. // 获取学习资料详情
  289. getdetail() {
  290. this.loading = true;
  291. materialdetail({
  292. materialId: this.materialId,
  293. isSelectForUpdate: this.Ispreview ? true : false,
  294. })
  295. .then((res) => {
  296. if (res.data.result) {
  297. let index = res.data.result.tag.indexOf("downloadable");
  298. if (index != -1) {
  299. this.IsDownload = true;
  300. }
  301. this.data = res.data.result;
  302. this.data.pymentTeacher = "";
  303. res.data.result.teacher.forEach((item, i) => {
  304. if (i != this.data.teacher.length - 1) {
  305. this.data.pymentTeacher += item + ";";
  306. } else {
  307. this.data.pymentTeacher += item;
  308. }
  309. });
  310. this.data.fileType = this.data.tag[this.data.tag.length - 1];
  311. this.attachment = JSON.parse(res.data.result.attachment);
  312. this.loading = false;
  313. if (
  314. this.attachment[0].fileType == "pdf" ||
  315. this.attachment[0].fileType == "PDF"
  316. ) {
  317. // this.attachment[0].fileRelativePath =
  318. // process.env.VUE_APP_BASE_API + this.attachment[0].fileRelativePath;
  319. this.attachment[0].fileRelativePath =
  320. process.env.VUE_APP_PDF_API +
  321. this.attachment[0].fileRelativePath;
  322. console.log(this.attachment[0].fileRelativePath);
  323. this.getNumPages();
  324. }
  325. this.changePrice(this.data.price);
  326. }
  327. })
  328. .catch((res) => {
  329. this.loading = false;
  330. });
  331. },
  332. },
  333. created() {},
  334. mounted() {
  335. this.materialId = this.$route.query.id;
  336. this.Ispreview = this.$route.query.type;
  337. this.allList = this.$route.query.allList;
  338. if (this.materialId) {
  339. this.getdetail();
  340. if (!this.Ispreview) {
  341. materialvisit({
  342. id: this.materialId,
  343. })
  344. .then((res) => {})
  345. .catch((res) => {
  346. this.loading = false;
  347. });
  348. }
  349. }
  350. let node = document.getElementsByClassName("cui-ribbonTopBars")[0];
  351. console.log(node);
  352. },
  353. };
  354. </script>
  355. <style lang="scss" scoped>
  356. .tarcer-dev-Preview {
  357. height: 100%;
  358. .header {
  359. height: 64px;
  360. background: url("../../assets/teacherdev/Homebg2.png") no-repeat;
  361. background-size: 100% 100%;
  362. position: relative;
  363. .shade {
  364. position: absolute;
  365. top: 0;
  366. width: 100%;
  367. height: 100%;
  368. background: rgba(0, 0, 0, 0.5);
  369. display: flex;
  370. color: #fff;
  371. font-weight: bold;
  372. font-size: 18px;
  373. justify-content: space-around;
  374. align-items: center;
  375. .el-menu-demo {
  376. background: rgba(0, 0, 0, 0);
  377. li:hover {
  378. background: none;
  379. }
  380. li {
  381. background: none;
  382. }
  383. }
  384. }
  385. }
  386. .main {
  387. min-height: 543px;
  388. background: #f6f6f6;
  389. padding-bottom: 20px;
  390. padding-top: 30px;
  391. position: relative;
  392. }
  393. .flassify {
  394. position: relative;
  395. width: 1140px;
  396. height: 154px;
  397. margin: 0 auto;
  398. background-color: #fff;
  399. border-radius: 8px;
  400. display: flex;
  401. justify-content: space-between;
  402. align-items: center;
  403. padding: 0 30px;
  404. .text {
  405. .p1 {
  406. font-weight: bold;
  407. font-size: 30px;
  408. color: #1f2127;
  409. }
  410. .p2 {
  411. margin-top: 8px;
  412. margin-bottom: 8px;
  413. font-size: 16px;
  414. color: #1f2127;
  415. }
  416. }
  417. .pay_collect {
  418. position: absolute;
  419. right: 30px;
  420. bottom: 24px;
  421. display: flex;
  422. align-items: center;
  423. .price {
  424. font-weight: bold;
  425. font-size: 24px;
  426. margin-right: 20px;
  427. .price_2 {
  428. font-size: 16px;
  429. }
  430. }
  431. .pay {
  432. width: 120px;
  433. height: 40px;
  434. background: #ff9900;
  435. border-radius: 4px;
  436. color: white;
  437. font-weight: 600;
  438. font-size: 20px;
  439. text-align: center;
  440. line-height: 40px;
  441. cursor: pointer;
  442. margin-right: 20px;
  443. }
  444. .collect {
  445. display: flex;
  446. align-items: center;
  447. font-weight: bold;
  448. font-size: 24px;
  449. color: #1f2127;
  450. img {
  451. width: 24px;
  452. margin-right: 10px;
  453. cursor: pointer;
  454. }
  455. }
  456. .download {
  457. margin-right: 20px;
  458. display: flex;
  459. align-items: center;
  460. font-weight: bold;
  461. font-size: 24px;
  462. color: #1f2127;
  463. img {
  464. width: 24px;
  465. margin-right: 10px;
  466. cursor: pointer;
  467. }
  468. }
  469. }
  470. }
  471. .buy {
  472. width: 1200px;
  473. margin: 24px auto;
  474. min-height: 1000px;
  475. // filter: blur(8px);
  476. }
  477. .NObuy {
  478. width: 1200px;
  479. margin: 24px auto;
  480. min-height: 1000px;
  481. filter: blur(8px);
  482. }
  483. .buyBtn {
  484. width: 284px;
  485. height: 67px;
  486. background: #ff9900;
  487. border-radius: 8px;
  488. text-align: center;
  489. line-height: 67px;
  490. color: white;
  491. font-weight: bold;
  492. font-size: 22px;
  493. margin: 0 auto;
  494. cursor: pointer;
  495. position: relative;
  496. top: -150px;
  497. }
  498. .dialogTitle {
  499. }
  500. }
  501. </style>
  502. <style lang="scss">
  503. .tarcer-dev-Preview {
  504. .el-dialog__body {
  505. padding: 30px 32px;
  506. }
  507. }
  508. .cui-ribbonTopBars {
  509. display: none !important;
  510. }
  511. </style>