Preview.vue 17 KB

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