courseOrder.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view class="container">
  3. <view class="course-item">
  4. <view class="course-item-image">
  5. <image class="course-image" :src="course.thumImg" mode="aspectFill"></image>
  6. </view>
  7. <view class="course-item-content">
  8. <view class="course-title">
  9. <text>{{ course.title }}</text>
  10. <!-- <image style="width: 25rpx;height: 25rpx;padding-left: 20rpx;"
  11. :src="course.hasFavi ? `${FILE_URL}/edu-icon/favi-icon.png` : `${FILE_URL}/edu-icon/no-favi-icon.png`">
  12. </image> -->
  13. </view>
  14. <view class="course-type">{{ course.type }}</view>
  15. <view class="course-teacher">
  16. <u-icon name="account" size="28"></u-icon>
  17. {{ course.lecturer }}
  18. </view>
  19. <view class="course-date">
  20. <u-icon name="clock" size="28"></u-icon>
  21. {{ course.date ? getDateWeek(course.date) : ""}}
  22. </view>
  23. <view class="course-price">¥{{ isMember ? course.priceMember : course.price }}元</view>
  24. </view>
  25. </view>
  26. <view class="course-form" style="margin-top: 20rpx;">
  27. <view class="course-form-item">
  28. <view class="course-label">
  29. 开课时间
  30. </view>
  31. <view class="course-value">
  32. {{ course.date }}开课
  33. </view>
  34. </view>
  35. <view class="course-form-item">
  36. <view class="course-label">
  37. 支付方式
  38. </view>
  39. <view class="course-value" @click="payTypeShow = true">
  40. {{ activePayType }}<i class="iconfont icon-sangedian-copy"></i>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="course-form" style="margin-top: 20rpx;">
  45. <view class="course-form-item">
  46. <view class="course-label">
  47. 课程金额
  48. </view>
  49. <view class="course-value">
  50. ¥{{ isMember ? course.priceMember : course.price }}
  51. </view>
  52. </view>
  53. <view class="course-form-item">
  54. <view class="course-label">
  55. 积分抵扣
  56. </view>
  57. <view class="course-value">
  58. </view>
  59. </view>
  60. <view class="course-form-item">
  61. <view class="course-label">
  62. 合计金额
  63. </view>
  64. <view class="course-value">
  65. ¥{{ price }}
  66. </view>
  67. </view>
  68. </view>
  69. <view class="course-form" style="margin-top: 20rpx;">
  70. <view class="course-form-item">
  71. <view class="course-label">
  72. 课程有效期:<text class="text-red">{{ course.expired }}</text>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="course-form" style="background: none;" v-if="!isMember && course.viewMode === '2'">
  77. <view class="course-form-item" @click="toJoin">
  78. <text class="text-red" style="font-weight: bold;">个人会员或单位会员免费,点击现在入会></text>
  79. </view>
  80. </view>
  81. <view class="pay">
  82. <view class="pay-price">
  83. ¥:{{price}}
  84. </view>
  85. <view>
  86. <button class="pay-btn" @click="toBuy">立即购买</button>
  87. </view>
  88. </view>
  89. <u-action-sheet :list="list" v-model="payTypeShow" @click="clickAction" safe-area-inset-bottom></u-action-sheet>
  90. </view>
  91. </template>
  92. <script setup>
  93. import {
  94. ref,
  95. computed
  96. } from 'vue'
  97. import {
  98. onLoad, onShow
  99. } from '@dcloudio/uni-app'
  100. import configService from '@/utils/baseurl.js'
  101. import {
  102. loadCourseDetail,
  103. payCourse,
  104. regCourse
  105. } from "@/api/edu.js"
  106. import {
  107. msgError,
  108. msgSuccess
  109. } from "@/utils/common.js"
  110. import {
  111. useAuthStore
  112. } from '@/store/authStore'
  113. const authStore = useAuthStore();
  114. const isMember = computed(() => {
  115. authStore.loadUserInfo()
  116. return authStore.userInfo.isMember == '0' ? false : true
  117. })
  118. const openid = computed(() => {
  119. authStore.loadOpenid()
  120. return authStore.openid
  121. })
  122. const FILE_URL = configService.FILE_URL;
  123. const courseId = ref("");
  124. const course = ref({})
  125. const price = computed(() => {
  126. let val;
  127. if (isMember.value) {
  128. val = course.value.priceMember
  129. } else {
  130. val = course.value.price
  131. }
  132. // 如果后续有积分需求可以写在这里,计算一下积分,返回最终值
  133. payForm.value.amount = val
  134. return val
  135. })
  136. const activePayType = ref("微信支付")
  137. const list = ref([{
  138. text: '微信支付'
  139. }])
  140. const payForm = ref({
  141. title: "",
  142. desc: "",
  143. id: "",
  144. amount: "",
  145. openid: ""
  146. })
  147. const payTypeShow = ref(false)
  148. // 支付完成
  149. const toBuy = () => {
  150. payForm.value.openid = openid.value
  151. // console.log(payForm.value)
  152. // 支付部分
  153. payCourse(payForm.value).then(res => {
  154. if (res && res.code === 0) {
  155. const params = res.data
  156. wx.requestPayment({
  157. nonceStr: params.nonceStr,
  158. package: params.package,
  159. paySign: params.paySign,
  160. signType: params.signType,
  161. timeStamp: params.timeStamp,
  162. success(res){
  163. // 购买成功后报名,报名成功后跳转页面
  164. regCourse(courseId.value).then(res=>{
  165. if(res.code===0){
  166. uni.navigateTo({
  167. url:"/pages/goOnEdu/course/courseDetail/coursePay?id="+ courseId.value+"&viewMode=" + course.value.viewMode
  168. })
  169. }
  170. })
  171. },
  172. fail(res){
  173. msgError("支付失败")
  174. }
  175. })
  176. }
  177. })
  178. // uni.navigateTo({
  179. // url:"/pages/goOnEdu/course/courseDetail/coursePay?id="+ courseId.value+"&viewMode=" + course.value.viewMode
  180. // })
  181. }
  182. function clickAction(i){
  183. // console.log(i)
  184. activePayType.value = list.value[i].text
  185. payTypeShow.value = false
  186. }
  187. function formatDateS(dateStr) {
  188. return dateStr.replace(" ", "T");
  189. }
  190. // 日期格式:xxxx年xx月xx日(星期x)
  191. function getDateWeek(val) {
  192. const date = new Date(formatDateS(val));
  193. const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
  194. const year = date.getFullYear();
  195. const month = date.getMonth() + 1; // 注意:月份从0开始
  196. const day = date.getDate();
  197. const dayOfWeek = daysOfWeek[date.getUTCDay()];
  198. // const result = `${year}年${month}月${day}日(星期${dayOfWeek})`
  199. return `${year}年${month}月${day}日(星期${dayOfWeek})`
  200. }
  201. function toJoin(){
  202. uni.navigateTo({
  203. url: '/pages/joinClub/joinClub'
  204. })
  205. }
  206. // 初始化
  207. function init(id) {
  208. loadCourseDetail(id).then(res => {
  209. if (res?.data) {
  210. course.value = res.data;
  211. payForm.value.id = res.data.id;
  212. payForm.value.title = res.data.title
  213. payForm.value.desc = res.data.title
  214. //如果已经买了,就返回倒详情页
  215. if(res.data.hasBuy){
  216. uni.navigateBack({
  217. delta: 1
  218. });
  219. }
  220. }
  221. })
  222. }
  223. onLoad((option) => {
  224. const {
  225. id
  226. } = option;
  227. courseId.value = id
  228. console.log('onLoad', id)
  229. })
  230. onShow(()=>{
  231. init(courseId.value)
  232. })
  233. </script>
  234. <style lang="scss" scoped>
  235. .container {
  236. height: 100vh;
  237. width: 100vw;
  238. background-color: $uni-bg-color;
  239. // padding: 0 20rpx;
  240. }
  241. .course-item {
  242. padding: 20rpx;
  243. background-color: #fff;
  244. display: flex;
  245. overflow: hidden;
  246. margin: 0 20rpx;
  247. border-radius: 10rpx;
  248. .course-item-image {
  249. width: 200rpx;
  250. height: 280rpx;
  251. flex: 0 0 auto;
  252. margin-right: 20rpx;
  253. .course-image {
  254. width: 100%;
  255. height: 100%;
  256. }
  257. }
  258. .course-item-content {
  259. flex: 1;
  260. position: relative;
  261. view {
  262. margin-bottom: 22rpx;
  263. }
  264. .course-title {
  265. font-weight: bold;
  266. margin-right: 10px;
  267. font-size: 28rpx;
  268. color: #000;
  269. }
  270. .course-type,
  271. .course-teacher,
  272. .course-date,
  273. .course-price {
  274. font-size: 30rpx;
  275. color: #000;
  276. }
  277. .course-price {
  278. color: #fe0000;
  279. letter-spacing: 2rpx;
  280. }
  281. .button::after {
  282. content: none;
  283. /* 移除内容 */
  284. }
  285. .button {
  286. position: absolute;
  287. right: 0;
  288. bottom: 0;
  289. min-width: 80px;
  290. padding: 0 40rpx;
  291. white-space: nowrap;
  292. height: 45rpx;
  293. line-height: 45rpx;
  294. font-size: 22rpx;
  295. /* padding: 0; */
  296. border-radius: 50rpx;
  297. color: white;
  298. border: none;
  299. }
  300. .free {
  301. background-color: #006af4;
  302. }
  303. .purchase {
  304. background-color: #fe0000;
  305. }
  306. .member-free {
  307. background-color: transparent;
  308. background-image: url('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  309. background-size: cover;
  310. background-repeat: no-repeat;
  311. color: #000;
  312. height: initial;
  313. padding: 6rpx 0 3rpx;
  314. border-radius: 0;
  315. }
  316. .replay {
  317. background-color: #006af4;
  318. }
  319. .purchased {
  320. background-color: #006af4;
  321. }
  322. }
  323. }
  324. .course-form {
  325. padding: 20rpx;
  326. background-color: #fff;
  327. display: flex;
  328. overflow: hidden;
  329. border-radius: 10rpx;
  330. flex-direction: column;
  331. font-size: 30rpx;
  332. margin: 0 20rpx;
  333. .course-form-item {
  334. display: flex;
  335. justify-content: space-between;
  336. width: 100%;
  337. margin: 20rpx 0;
  338. .iconfont {
  339. display: inline-block;
  340. font-size: 24rpx;
  341. }
  342. }
  343. }
  344. .pay {
  345. position: fixed;
  346. bottom: 0;
  347. width: 100%;
  348. display: flex;
  349. justify-content: space-between;
  350. padding: 30rpx 20rpx calc(10rpx + env(safe-area-inset-bottom, 0));
  351. background-color: #fff;
  352. align-items: center;
  353. .pay-price {
  354. font-size: 60rpx;
  355. color: red;
  356. font-weight: bold;
  357. }
  358. .pay-btn {
  359. // width: 200rpx;
  360. height: 70rpx;
  361. line-height: 70rpx;
  362. background-color: red;
  363. color: #fff;
  364. border-radius: 40rpx;
  365. }
  366. }
  367. .text-red {
  368. color: red;
  369. }
  370. </style>