index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div>
  3. <div class="content">
  4. <div class="navigation">
  5. <router-link to="/">首页</router-link>
  6. <span>&gt; </span>
  7. 在线课程
  8. </div>
  9. <div class="photo" v-if="isLoginOk">
  10. <ul class="pt-line clear ng-scope">
  11. <li class="pt-sola ng-scope" v-for="(item,index) in list" :key="index">
  12. <div class="img">
  13. <a>
  14. <img class="p-o" :src="item.tb" ></a>
  15. <div class="hover-block ng-scope">
  16. <div class="mask"></div>
  17. <a class="btn-normal" @click="gotoDetail(item.courseId)">
  18. 立即学习
  19. </a>
  20. </div>
  21. </div>
  22. <div class="bth">
  23. <a>
  24. <span class="zt ng-binding">{{item.name}}
  25. <span class="db">
  26. <span class="status status0" @click="goPay( index)" v-if="item.status==0">立即购买</span>
  27. <span class="status status1" @click="goPay( index)" v-if="item.status==1">继续购买</span>
  28. <span class="status status2" v-if="item.status==2">已经购买</span>
  29. </span>
  30. </span>
  31. </a>
  32. </div>
  33. <div class="hb">
  34. <img class="hb-head" src="@/assets/images/user-man.jpg">
  35. <span class="name ng-binding" >{{item.author||'-'}}</span>
  36. <span class="da ng-binding">
  37. 发布时间:{{item.publishAt|dateFilter}}
  38. </span>
  39. </div>
  40. </li>
  41. </ul>
  42. <!-- -->
  43. <el-pagination class="m-pages"
  44. @current-change="handleCurrentChange"
  45. :current-page="page"
  46. :page-size="size" layout="total, prev, pager, next"
  47. :total="total">
  48. </el-pagination>
  49. </div>
  50. <div vl-else>
  51. <div class="m-no-data tc" @click="loginDialog=true">
  52. <img src="../../../assets/images/no-data-2_hash6c469a3790.png" alt="">
  53. <p class="mt10 b t-b" >点击登入</p>
  54. <p class="mt10 txt-g">本页面需要先登入</p>
  55. </div>
  56. </div>
  57. </div>
  58. <el-dialog
  59. class="fc tc"
  60. :visible.sync="loginDialog"
  61. :close-on-click-modal="false"
  62. width="500px"
  63. @close="loginDialog=false"
  64. >
  65. <div class="login-dialog m-login">
  66. <un-login @login="login"></un-login>
  67. </div>
  68. </el-dialog>
  69. <el-dialog
  70. title="用户登入"
  71. class="fc tc"
  72. :visible.sync="qrcode"
  73. width="500px"
  74. :append-to-body="true"
  75. @close="closeDialog"
  76. >
  77. <div class="qrcode">
  78. <img :src="qrcodeUrl" />
  79. <div class="notice">请注意:报名学习通过不代表报名考试成功</div>
  80. </div>
  81. </el-dialog>
  82. </div>
  83. </template>
  84. <script>
  85. import {httpServer} from "@/components/httpServer/httpServer.js";
  86. import { MessageBox } from "element-ui";
  87. import unLogin from "../../login/components/unLogin.vue";
  88. import {parseTime} from "@/utils";
  89. export default {
  90. name: "Index",
  91. data() {
  92. return {
  93. page: 1,
  94. size: 8,
  95. total: 0,
  96. list: [],
  97. showData: [],
  98. qrcode: false,
  99. qrcodeUrl: "",
  100. outTradeNo: "",
  101. title:'',
  102. timer: null,
  103. tickCount: 0,
  104. listLoading: false,
  105. loginDialog:false,
  106. isLoginOk: false,
  107. user:{}
  108. };
  109. },
  110. components:{unLogin},
  111. filters:{
  112. dateFilter(val) {
  113. return parseTime(val, '{y}-{m}-{d}')
  114. }
  115. },
  116. created() {
  117. if( !localStorage.uid || !localStorage.token){
  118. this.loginDialog = true;
  119. return;
  120. }else{
  121. this.isLoginOk = true;
  122. this.getData();
  123. }
  124. },
  125. beforeDestroy() {
  126. if (this.timer) window.clearInterval(this.timer);
  127. },
  128. methods: {
  129. initTimer() {
  130. if (this.timer) window.clearInterval(this.timer);
  131. this.timer = window.setInterval(() => {
  132. this.tickCount++;
  133. this.tickTimer();
  134. }, 2000);
  135. },
  136. tickTimer() {
  137. if (this.tickCount > 30) {
  138. if (this.timer) window.clearInterval(this.timer);
  139. this.qrcode = false;
  140. }
  141. let outTradeNo = this.outTradeNo;
  142. httpServer("weixin.iswxPay", { outTradeNo }).then((res) => {
  143. if (res.code == 200) {
  144. if (!!res.data) {
  145. if (this.timer) window.clearInterval(this.timer);
  146. MessageBox("支付成功", "提示", {
  147. confirmButtonText: "确定",
  148. showClose: true,
  149. type: "sucess",
  150. });
  151. this.qrcode = false;
  152. this.getData();
  153. }
  154. }
  155. });
  156. },
  157. closeDialog() {
  158. if (this.timer) window.clearInterval(this.timer);
  159. },
  160. getData() {
  161. let param = {
  162. size: this.size,
  163. from: (this.page - 1) * this.size
  164. }
  165. httpServer("course.getcoursemarket", param).then((res) => {
  166. this.list = res.data.list;
  167. this.total = res.data.total;
  168. });
  169. },
  170. gotoDetail(courseId) {
  171. this.$router.push({name:'play', params:{courseId}})
  172. },
  173. goPay(index) {
  174. let item = this.list[index];
  175. httpServer("weixin.DoWxpay", { courseId: item.courseId }).then((res) => {
  176. if (res.code == 200) {
  177. let { outTradeNo, showUrl } = res.data;
  178. this.qrcode = true;
  179. this.qrcodeUrl = showUrl;
  180. this.outTradeNo = outTradeNo;
  181. this.title = '购买课程'+ item.name
  182. this.initTimer();
  183. }
  184. });
  185. },
  186. handleCurrentChange(page){
  187. this.page = page;
  188. this.getData()
  189. },
  190. login( param ){
  191. httpServer("Auth.LoginStudy" , param).then( res => {
  192. if(res.code==200){
  193. let { nickname, token, uid } = res.data;
  194. localStorage.nickname = nickname;
  195. localStorage.token = token;
  196. localStorage.uid = uid
  197. this.user = { nickname, token, uid };
  198. this.loginOk = true
  199. this.loginDialog = false
  200. }
  201. })
  202. }
  203. },
  204. };
  205. </script>
  206. <style>
  207. @import "../../../assets/css/content.css";
  208. @import url("./index.css");
  209. </style>