import { C as c } from './index.84afa5a4.js'
import { S as d } from './index.2778830d.js'
import { U as l } from './index.fdb44d83.js'
import { d as u, D as i, a as o, x as m, B as p } from './vendor.3506a68e.js'
import { r as n } from './index.9e4b607f.js'
import { C as h } from './index.9a4c80cd.js'
import { o as s, a as f } from './orderStatus.81f9c36b.js'
import { t as I } from './tradeOrder.2a9cc20f.js'
import { C as y } from './index.e311a214.js'
/* empty css              */ /* empty css               */ import './bars.4f1962a6.js'
/* empty css               */ import './icon_teacher.cb128c00.js'
import './icon_timer2.5fb1750d.js'
import './icon-jiaozi.20e415ca.js'
/* empty css               */ import './index.aec0a459.js'
const b = '_introduction_lw312_1',
  j = '_btnGroup_lw312_6',
  _ = '_btnMore_lw312_10',
  g = '_videoItem_lw312_17'
var a = {
  'video-detail': '_video-detail_lw312_1',
  introduction: b,
  btnGroup: j,
  btnMore: _,
  videoItem: g,
  'van-cell__title': '_van-cell__title_lw312_17'
}
function v(e) {
  return (
    typeof e == 'function' ||
    (Object.prototype.toString.call(e) === '[object Object]' && !m(e))
  )
}
var z = u({
  name: 'VideoDetail',
  data() {
    const e = this.$route.query
    return {
      userInfo: {},
      detailList: [],
      recomUserId: e.recomUserId,
      params: { groupId: e.groupId }
    }
  },
  async mounted() {
    await this._init()
  },
  methods: {
    async _init() {
      try {
        const r =
            (
              await n.get('/api-student/videoLesson/selectVideoLesson', {
                params: { groupId: this.params.groupId }
              })
            ).data || {},
          t = r.lessonGroup || {},
          O = r.teachertTag || ''
        ;(this.userInfo = {
          alreadyBuy: r.alreadyBuy,
          username: t.username || `\u6E38\u5BA2${t.teacherId || ''}`,
          headUrl: t.avatar,
          buyNum: t.countStudent,
          id: t.id,
          lessonNum: t.lessonCount,
          lessonName: t.lessonName,
          lessonDesc: t.lessonDesc,
          lessonPrice: t.lessonPrice,
          teacherId: t.teacherId,
          lessonCoverUrl: t.lessonCoverUrl,
          auditVersion: t.auditVersion,
          isDegree: !!r.degreeFlag,
          isTeacher: !!r.teacherFlag
        }),
          (this.detailList = r.detailList || [])
      } catch {}
    },
    onPlay(e) {
      this.$router.push({
        path: '/videoClassDetail',
        query: { groupId: this.params.groupId, classId: e.id }
      })
    },
    async onBuy() {
      try {
        const e = this.userInfo
        if (
          ((s.orderObject.orderType = 'VIDEO'),
          (s.orderObject.orderName = '\u89C6\u9891\u8BFE\u8D2D\u4E70'),
          (s.orderObject.orderDesc = '\u89C6\u9891\u8BFE\u8D2D\u4E70'),
          (s.orderObject.actualPrice = e.lessonPrice),
          (s.orderObject.recomUserId = this.recomUserId),
          (s.orderObject.orderNo = ''),
          (s.orderObject.orderList = [
            {
              orderType: 'VIDEO',
              goodsName: '\u89C6\u9891\u8BFE\u8D2D\u4E70',
              courseGroupId: e.id,
              courseGroupName: e.lessonName,
              coursePrice: e.lessonPrice,
              teacherName: e.username || `\u6E38\u5BA2${e.teacherId || ''}`,
              teacherId: e.teacherId,
              avatar: e.headUrl,
              courseInfo: this.detailList,
              recomUserId: this.recomUserId
            }
          ]),
          e.lessonPrice <= 0)
        ) {
          await f(() => {
            i.alert({
              message: '\u9886\u53D6\u6210\u529F',
              confirmButtonText: '\u786E\u5B9A',
              confirmButtonColor: '#01C1B5'
            }).then(() => {
              this._init()
            })
          })
          return
        }
        const t = (
          await n.post('/api-student/userOrder/getPendingOrder', {
            data: { goodType: 'VIDEO', bizId: this.params.groupId }
          })
        ).data
        t
          ? i
              .confirm({
                title: '\u63D0\u793A',
                message:
                  '\u60A8\u6709\u4E00\u4E2A\u672A\u652F\u4ED8\u7684\u8BA2\u5355\uFF0C\u662F\u5426\u7EE7\u7EED\u652F\u4ED8\uFF1F',
                confirmButtonColor: '#269a93',
                cancelButtonText: '\u53D6\u6D88\u8BA2\u5355',
                confirmButtonText: '\u7EE7\u7EED\u652F\u4ED8'
              })
              .then(async () => {
                I(t, this.routerTo)
              })
              .catch(() => {
                i.close(), this.cancelPayment(t.orderNo)
              })
          : this.routerTo()
      } catch {}
    },
    routerTo() {
      this.$router.push({
        path: '/orderDetail',
        query: { orderType: 'VIDEO', courseGroupId: this.params.groupId }
      })
    },
    async cancelPayment(e) {
      try {
        await n.post('/api-student/userOrder/orderCancel', {
          data: { orderNo: e }
        })
      } catch {}
    }
  },
  render() {
    let e
    return o('div', { class: [a['video-detail']] }, [
      o(h, null, null),
      o(l, { userInfo: this.userInfo }, null),
      o(
        d,
        { border: !0 },
        {
          default: () => [
            o('p', { class: a.introduction }, [this.userInfo.lessonDesc])
          ]
        }
      ),
      o(
        d,
        {
          title: '\u8BFE\u7A0B\u5217\u8868',
          icon: 'courseList',
          class: 'mb12',
          border: !0
        },
        v(
          (e = this.detailList.map(r =>
            o(
              c,
              {
                class: ['mb12', a.videoItem],
                detail: {
                  id: r.id,
                  title: r.videoTitle,
                  content: r.videoContent,
                  imgUrl: r.coverUrl
                },
                onPlay: this.onPlay
              },
              null
            )
          ))
        )
          ? e
          : { default: () => [e] }
      ),
      this.userInfo.id &&
        !this.userInfo.alreadyBuy &&
        o(
          y,
          { position: 'bottom', background: 'white' },
          {
            default: () => [
              o('div', { class: ['btnGroup', a.btnMore] }, [
                o(
                  p,
                  {
                    block: !0,
                    round: !0,
                    type: 'primary',
                    onClick: this.onBuy
                  },
                  {
                    default: () => [
                      this.userInfo.lessonPrice <= 0
                        ? '\u514D\u8D39\u9886\u53D6'
                        : '\u7ACB\u5373\u8D2D\u4E70'
                    ]
                  }
                )
              ])
            ]
          }
        )
    ])
  }
})
export { z as default }
