index1.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef H5 -->
  4. <view style="color: #fff;">
  5. <tn-nav-bar backgroundColor="#26B3A0" :bottomShadow="false" @rightClick="jumpScoreRed">支付状态
  6. <!-- <template slot="right">
  7. 课程购买记录
  8. </template> -->
  9. </tn-nav-bar>
  10. <view :style="{ height: tobheight + 'px' }"></view>
  11. </view>
  12. <!-- #endif -->
  13. <view class="content">
  14. <view class="topIcon">
  15. <!-- <image src="../../../static/posImg.png" mode=""></image> -->
  16. <icon :type="currScoreOrder.status?'success':'error'" size="54"
  17. :color="currScoreOrder.status?'#26B3A0':'red'" />
  18. <view class="txt" :style="{color:currScoreOrder.status?'#26B3A0':'red'}">
  19. {{currScoreOrder.status?'支付成功':'支付失败'}}
  20. </view>
  21. </view>
  22. <view class="btn" @click="handleShowRes" v-if="currScoreOrder.status">
  23. {{resShow?'收起学习资料':'查看学习资料'}}
  24. </view>
  25. <view class="res" v-if="resShow&&this.detail.content">
  26. <view class="inner" v-for="(i,index) in this.detail.content" @click="downLoad(i)">
  27. <text style="text-decoration: underline;">
  28. {{'学习资料'+(index+1)}}</text><text>{{i.slice(i.lastIndexOf('.'))}}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. courseDetail,
  37. } from '@/api/score/index.js'
  38. import {
  39. myScoreOrder
  40. } from '@/api/my/index.js'
  41. import {
  42. downLoad2
  43. } from '@/utils/download2.js'
  44. export default {
  45. components: {},
  46. data() {
  47. return {
  48. detail: {},
  49. tobheight: 45,
  50. resShow: false,
  51. currScoreOrder: {}
  52. };
  53. },
  54. computed: {
  55. },
  56. watch: {
  57. },
  58. async onLoad(o) {
  59. let res = await courseDetail({
  60. course_id: o.id
  61. })
  62. if (res.code == 0) {
  63. this.detail = res.data
  64. }
  65. let res1 = await myScoreOrder({})
  66. if (res1.code == 0) {
  67. this.detail = res1.data
  68. this.currScoreOrder = res1.data.find((item, index) => {
  69. return item.course_id == o.id
  70. })
  71. // this.currScoreOrder.status = 1
  72. }
  73. console.log('支付成功--课程详情返回值', res);
  74. console.log('支付成功--所有课程订单列表:', res1);
  75. console.log('支付成功--需判断支付状态的课程订单:', this.currScoreOrder, this.currScoreOrder.status);
  76. },
  77. onReady() {
  78. },
  79. onShow() {
  80. },
  81. onUnload() {
  82. },
  83. methods: {
  84. handleShowRes() {
  85. this.resShow = !this.resShow
  86. },
  87. downLoad(fileName) {
  88. let _this = this
  89. //判断是否在微信
  90. var ua = navigator.userAgent.toLowerCase();
  91. var isWeixin = ua.indexOf('micromessenger') != -1;
  92. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
  93. navigator.userAgent) ? false : true;
  94. if (isWeixin) {
  95. if (fileName.endsWith('.pdf')) {
  96. uni.navigateTo({
  97. url: '/pages/user/score/prePdf/index?url=' + fileName
  98. })
  99. } else if (fileName.endsWith('.mp4')) {
  100. uni.navigateTo({
  101. url: '/pages/user/score/preMp4/index?url=' + fileName
  102. })
  103. } else if (fileName.endsWith('.jpg') || fileName.endsWith('.png') || fileName.endsWith('.jpeg')) {
  104. uni.navigateTo({
  105. url: '/pages/user/score/preImg/index?url=' + fileName
  106. })
  107. } else if (fileName.endsWith('.zip') || fileName.endsWith('.rar')) {
  108. let _that = this
  109. uni.showModal({
  110. title: '温馨提示',
  111. content: '微信浏览器不支持直接打开zip或rar类型的文件,请复制链接至手机浏览器打开哦~',
  112. confirmText: '复制',
  113. confirmColor: '#26B3A0',
  114. success: function(res) {
  115. if (res.confirm) {
  116. console.log('用户点击确定');
  117. uni.setClipboardData({
  118. data: fileName,
  119. success: function() {
  120. console.log('success');
  121. uni.showToast({
  122. title: "复制成功",
  123. icon: 'success',
  124. })
  125. }
  126. });
  127. } else if (res.cancel) {
  128. console.log('用户点击取消');
  129. }
  130. }
  131. })
  132. }
  133. } else if (detectDeviceType()) {
  134. // pc端
  135. uni.downloadFile({
  136. url: fileName, //文件链接
  137. success: (res) => {
  138. if (res.statusCode === 200) {
  139. var oA = document.createElement("a");
  140. oA.download = _this.detail.course.name + '-学习资料'; // 设置下载的文件名,默认是'下载'
  141. oA.href = res.tempFilePath; //临时路径再保存到本地
  142. document.body.appendChild(oA);
  143. oA.click();
  144. oA.remove(); // 下载之后把创建的元素删除
  145. }
  146. },
  147. fail: (err) => {
  148. uni.showToast({
  149. icon: 'none',
  150. mask: true,
  151. title: '失败请重新下载',
  152. });
  153. },
  154. })
  155. } else {
  156. // 其他手机浏览器
  157. if (fileName.endsWith('.pdf')) {
  158. uni.navigateTo({
  159. url: '/pages/user/score/prePdf/index?url=' + fileName
  160. })
  161. } else if (fileName.endsWith('.mp4')) {
  162. uni.navigateTo({
  163. url: '/pages/user/score/preMp4/index?url=' + fileName
  164. })
  165. } else if (fileName.endsWith('.jpg') || fileName.endsWith('.png') || fileName.endsWith('.jpeg')) {
  166. uni.navigateTo({
  167. url: '/pages/user/score/preImg/index?url=' + fileName
  168. })
  169. } else if (fileName.endsWith('.zip') || fileName.endsWith('.rar')) {
  170. downLoad2(fileName, this.detail.course.name + '-学习资料', 'application/zip')
  171. // window.open(
  172. // fileName
  173. // )
  174. }
  175. }
  176. },
  177. goPay() {
  178. uni.navigateTo({
  179. url: '/pages/index/scorePaySuc/index'
  180. })
  181. }
  182. }
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. @import './index.scss';
  187. </style>