video-detail.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. import CourseVideoItem from '@/business-components/course-video-item'
  2. import SectionDetail from '@/business-components/section-detail'
  3. import UserDetail from '@/business-components/user-detail'
  4. import { Sticky, Button, Dialog, Popup, Toast } from 'vant'
  5. import { defineComponent } from 'vue'
  6. import styles from './video-detail.module.less'
  7. import request from '@/helpers/request'
  8. import ColHeader from '@/components/col-header'
  9. import { onSubmitZero, orderStatus } from '@/views/order-detail/orderStatus'
  10. import { tradeOrder } from '../trade/tradeOrder'
  11. import ColSticky from '@/components/col-sticky'
  12. import iconShare from '@/views/shop-mall/images/icon-share.svg'
  13. import ColShare from '@/components/col-share'
  14. import LiveItem from '@/views/live-class/live-item'
  15. import { state } from '@/state'
  16. import { browser } from '@/helpers/utils'
  17. export default defineComponent({
  18. name: 'VideoDetail',
  19. data() {
  20. const query = this.$route.query
  21. return {
  22. userInfo: {} as any,
  23. detailList: [],
  24. recomUserId: query.recomUserId, // 推荐人id
  25. params: {
  26. groupId: query.groupId
  27. },
  28. shareStatus: false,
  29. shareUrl: ''
  30. }
  31. },
  32. async mounted() {
  33. await this._init()
  34. if (/(localhost|192)/g.test(location.origin)) {
  35. this.shareUrl = `https://dev.colexiu.com/teacher#/shareVideo?recomUserId=${state.user.data?.userId}&groupId=${this.params.groupId}&userType=${state.platformType}`
  36. } else {
  37. this.shareUrl = `${location.origin}/teacher#/shareVideo?recomUserId=${state.user.data?.userId}&groupId=${this.params.groupId}&userType=${state.platformType}`
  38. }
  39. },
  40. methods: {
  41. async _init() {
  42. try {
  43. const res = await request.get(
  44. '/api-student/videoLesson/selectVideoLesson',
  45. {
  46. params: {
  47. groupId: this.params.groupId
  48. }
  49. }
  50. )
  51. const result = res.data || {}
  52. const lessonGroup = result.lessonGroup || {}
  53. const teachertTag = result.teachertTag || ''
  54. this.userInfo = {
  55. alreadyBuy: result.alreadyBuy,
  56. username:
  57. lessonGroup.username || `游客${lessonGroup.teacherId || ''}`,
  58. headUrl: lessonGroup.avatar,
  59. buyNum: lessonGroup.countStudent,
  60. id: lessonGroup.id,
  61. lessonNum: lessonGroup.lessonCount,
  62. lessonName: lessonGroup.lessonName,
  63. lessonDesc: lessonGroup.lessonDesc,
  64. lessonPrice: lessonGroup.lessonPrice,
  65. relationType: lessonGroup.relationType,
  66. teacherId: lessonGroup.teacherId,
  67. lessonCoverUrl: lessonGroup.lessonCoverUrl,
  68. auditVersion: lessonGroup.auditVersion,
  69. isDegree: result.degreeFlag ? true : false,
  70. isTeacher: result.teacherFlag ? true : false
  71. }
  72. this.detailList = result.detailList || []
  73. } catch {
  74. //
  75. }
  76. },
  77. onPlay(detail: any) {
  78. this.$router.push({
  79. path: '/videoClassDetail',
  80. query: {
  81. groupId: this.params.groupId,
  82. classId: detail.id
  83. }
  84. })
  85. },
  86. async onBuy() {
  87. try {
  88. const userInfo = this.userInfo
  89. orderStatus.orderObject.orderType = 'VIDEO'
  90. orderStatus.orderObject.orderName = '视频课购买'
  91. orderStatus.orderObject.orderDesc = '视频课购买'
  92. orderStatus.orderObject.actualPrice = userInfo.lessonPrice
  93. orderStatus.orderObject.recomUserId = this.recomUserId
  94. orderStatus.orderObject.orderNo = ''
  95. orderStatus.orderObject.orderList = [
  96. {
  97. orderType: 'VIDEO',
  98. goodsName: '视频课购买',
  99. courseGroupId: userInfo.id,
  100. courseGroupName: userInfo.lessonName,
  101. coursePrice: userInfo.lessonPrice,
  102. teacherName: userInfo.username || `游客${userInfo.teacherId || ''}`,
  103. teacherId: userInfo.teacherId,
  104. avatar: userInfo.headUrl,
  105. relationType: this.userInfo.relationType,
  106. courseInfo: this.detailList,
  107. recomUserId: this.recomUserId
  108. }
  109. ]
  110. // 判断是否是0无订单
  111. if (userInfo.lessonPrice <= 0) {
  112. await onSubmitZero(() => {
  113. Dialog.alert({
  114. message: '领取成功',
  115. confirmButtonText: '确定',
  116. confirmButtonColor: '#2dc7aa'
  117. }).then(() => {
  118. this._init()
  119. })
  120. })
  121. return
  122. }
  123. const res = await request.post(
  124. '/api-student/userOrder/getPendingOrder',
  125. {
  126. data: {
  127. goodType: 'VIDEO',
  128. bizId: this.params.groupId
  129. }
  130. }
  131. )
  132. const result = res.data
  133. if (result) {
  134. Dialog.confirm({
  135. title: '提示',
  136. message: '您有一个未支付的订单,是否继续支付?',
  137. confirmButtonColor: '#269a93',
  138. cancelButtonText: '取消订单',
  139. confirmButtonText: '继续支付'
  140. })
  141. .then(async () => {
  142. tradeOrder(result, this.routerTo)
  143. })
  144. .catch(() => {
  145. Dialog.close()
  146. // 只用取消订单,不用做其它处理
  147. this.cancelPayment(result.orderNo)
  148. })
  149. } else {
  150. this.routerTo()
  151. }
  152. } catch {}
  153. },
  154. routerTo() {
  155. this.$router.push({
  156. path: '/orderDetail',
  157. query: {
  158. orderType: 'VIDEO',
  159. courseGroupId: this.params.groupId
  160. }
  161. })
  162. },
  163. async cancelPayment(orderNo: string) {
  164. try {
  165. await request.post('/api-student/userOrder/orderCancel', {
  166. data: {
  167. orderNo
  168. }
  169. })
  170. } catch {}
  171. }
  172. },
  173. render() {
  174. return (
  175. <div class={[styles['video-detail']]}>
  176. <ColHeader
  177. v-slots={{
  178. right: () => (
  179. <img src={iconShare} onClick={() => (this.shareStatus = true)} />
  180. )
  181. }}
  182. />
  183. <UserDetail
  184. userInfo={this.userInfo}
  185. onUserDetail={(item: any) => {
  186. console.log(item)
  187. if (browser().isApp && state.platformType === 'STUDENT') {
  188. this.$router.push({
  189. path: '/teacherHome',
  190. query: {
  191. teacherId: item.teacherId,
  192. tabs: 'video'
  193. }
  194. })
  195. }
  196. }}
  197. />
  198. <SectionDetail border={false}>
  199. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  200. </SectionDetail>
  201. <SectionDetail
  202. title="课程列表"
  203. icon="courseList"
  204. class="mb12"
  205. border={false}
  206. >
  207. {this.detailList.map((item: any) => {
  208. const musicAlbumInfos = item.musicAlbumInfos || []
  209. const temp = musicAlbumInfos.map((info: any) => {
  210. return {
  211. relationMusicAlbum: info.relationType,
  212. musicAlbumName: info.name,
  213. musicAlbumId: info.musicAlbumId,
  214. status: info.status, // 是否上架
  215. useRelationType: this.userInfo.relationType
  216. }
  217. })
  218. return (
  219. <CourseVideoItem
  220. musicAlbumInfos={temp}
  221. class={[styles.videoItem]}
  222. detail={{
  223. id: item.id,
  224. title: item.videoTitle,
  225. content: item.videoContent,
  226. imgUrl: item.coverUrl
  227. }}
  228. onPlay={this.onPlay}
  229. onMusicAlbumDetail={(item: any) => {
  230. if (!this.userInfo.alreadyBuy && !item.status) {
  231. Toast('数据正在更新,请稍后再试')
  232. return
  233. }
  234. if (item.relationMusicAlbum === 'MUSIC') {
  235. this.$router.push({
  236. path: '/music-detail',
  237. query: {
  238. id: item.musicAlbumId
  239. }
  240. })
  241. } else if (item.relationMusicAlbum === 'ALBUM') {
  242. this.$router.push({
  243. path: '/music-album-detail/' + item.musicAlbumId
  244. })
  245. }
  246. }}
  247. />
  248. )
  249. })}
  250. </SectionDetail>
  251. {this.userInfo.id && !this.userInfo.alreadyBuy && (
  252. // <Sticky offsetBottom={0} position="bottom">
  253. // <div class={['btnGroup', styles.btnMore]}>
  254. // <Button block round type="primary" onClick={this.onBuy}>
  255. // {this.userInfo.lessonPrice <= 0 ? '免费领取' : `立即购买`}
  256. // </Button>
  257. // </div>
  258. // </Sticky>
  259. <ColSticky position="bottom" background="white">
  260. <div class={['btnGroup', styles.btnMore]}>
  261. <Button block round type="primary" onClick={this.onBuy}>
  262. {this.userInfo.lessonPrice <= 0 ? '免费领取' : `立即购买`}
  263. </Button>
  264. </div>
  265. </ColSticky>
  266. )}
  267. <Popup
  268. v-model:show={this.shareStatus}
  269. style={{ background: 'transparent' }}
  270. >
  271. <ColShare
  272. teacherId={this.userInfo.id}
  273. shareUrl={this.shareUrl}
  274. shareType="video"
  275. >
  276. <LiveItem
  277. class={styles.shareCourse}
  278. coverClass={styles.coverClass}
  279. liveInfo={{
  280. backgroundPic: this.userInfo.lessonCoverUrl,
  281. courseGroupId: this.userInfo.lessonId,
  282. courseGroupName: this.userInfo.lessonName,
  283. courseNum: this.userInfo.lessonNum,
  284. coursePrice: this.userInfo.lessonPrice,
  285. teacherName: this.userInfo.username,
  286. teacherId: this.userInfo.id,
  287. avatar: this.userInfo.headUrl,
  288. studentCount: this.userInfo.buyNum,
  289. existBuy: 0,
  290. subjectName: this.userInfo.lessonSubjectName
  291. }}
  292. />
  293. </ColShare>
  294. </Popup>
  295. </div>
  296. )
  297. }
  298. })