courseOrder.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="container">
  3. <view class="course-item">
  4. <view class="course-item-image">
  5. <image class="course-image" :src="course.imgUrl" mode="aspectFill"></image>
  6. </view>
  7. <view class="course-item-content">
  8. <view class="course-title">
  9. <text>{{ course.courseName }}</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.courseType }}</view>
  15. <view class="course-teacher">
  16. <u-icon name="account" size="28"></u-icon>
  17. {{ course.name }}
  18. </view>
  19. <view class="course-date">
  20. <u-icon name="clock" size="28"></u-icon>
  21. {{ getDateWeek(course.courseDate) }}
  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.courseDate }}{{ course.courseTime }}开课
  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.expirationDate }}</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
  99. } from '@dcloudio/uni-app'
  100. import configService from '@/utils/baseurl.js'
  101. import {
  102. loadCourseDetail,
  103. payCourse
  104. } from "@/api/edu.js"
  105. import {
  106. msgError,
  107. msgSuccess
  108. } from "@/utils/common.js"
  109. import {
  110. useAuthStore
  111. } from '@/store/authStore'
  112. const authStore = useAuthStore();
  113. const isMember = computed(() => {
  114. authStore.loadUserInfo()
  115. return authStore.userInfo.isMember == '0' ? false : true
  116. })
  117. const openid = computed(() => {
  118. authStore.loadOpenid()
  119. return authStore.openid
  120. })
  121. const FILE_URL = configService.FILE_URL;
  122. const courseId = ref("");
  123. const course = ref({})
  124. const price = computed(() => {
  125. let val;
  126. if (isMember.value) {
  127. val = course.value.priceMember
  128. } else {
  129. val = course.value.price
  130. }
  131. // 如果后续有积分需求可以写在这里,计算一下积分,返回最终值
  132. payForm.value.amount = val
  133. return val
  134. })
  135. const activePayType = ref("微信支付")
  136. const list = ref([{
  137. text: '微信支付'
  138. }])
  139. const payForm = ref({
  140. title: "",
  141. desc: "",
  142. id: "",
  143. amount: "",
  144. openid: ""
  145. })
  146. const payTypeShow = ref(false)
  147. // 支付完成
  148. const toBuy = () => {
  149. payForm.value.openid = openid.value
  150. console.log(payForm.value)
  151. // 支付部分
  152. payCourse(payForm.value).then(res => {
  153. if (res && res.code === 0) {
  154. const params = res.data
  155. wx.requestPayment({
  156. nonceStr: params.nonceStr,
  157. package: params.package,
  158. paySign: params.paySign,
  159. signType: params.signType,
  160. timeStamp: params.timeStamp,
  161. success(res){
  162. uni.navigateTo({
  163. url:"/pages/goOnEdu/course/courseDetail/coursePay?id="+ courseId.value
  164. })
  165. },
  166. fail(res){
  167. msgError("支付失败")
  168. }
  169. })
  170. }
  171. })
  172. // uni.navigateTo({
  173. // url:"/pages/goOnEdu/course/courseDetail/coursePay?id="+ courseId.value
  174. // })
  175. // uni.redirectTo({
  176. // url: "/pages/goOnEdu/course/courseDetail/coursePay?id=" + courseId.value
  177. // })
  178. }
  179. const clickAction = (i) => {
  180. // console.log(i)
  181. activePayType.value = list.value[i].text
  182. payTypeShow.value = false
  183. }
  184. // 日期格式:xxxx年xx月xx日(星期x)
  185. function getDateWeek(val) {
  186. const date = new Date(val);
  187. const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
  188. const year = date.getFullYear();
  189. const month = date.getMonth() + 1; // 注意:月份从0开始
  190. const day = date.getDate();
  191. const dayOfWeek = daysOfWeek[date.getUTCDay()];
  192. // const result = `${year}年${month}月${day}日(星期${dayOfWeek})`
  193. return `${year}年${month}月${day}日(星期${dayOfWeek})`
  194. }
  195. const toJoin = () =>{
  196. uni.navigateTo({
  197. url: '/pages/joinClub/joinClub'
  198. })
  199. }
  200. // 初始化
  201. function init(id) {
  202. loadCourseDetail(id).then(res => {
  203. if (res?.data) {
  204. course.value = res.data;
  205. payForm.value.id = res.data.id;
  206. payForm.value.title = res.data.courseName
  207. payForm.value.desc = res.data.courseName
  208. }
  209. })
  210. }
  211. onLoad((option) => {
  212. const {
  213. id
  214. } = option;
  215. init(id);
  216. console.log('onLoad', id)
  217. })
  218. </script>
  219. <style lang="scss" scoped>
  220. .container {
  221. height: 100vh;
  222. width: 100vw;
  223. background-color: $uni-bg-color;
  224. // padding: 0 20rpx;
  225. }
  226. .course-item {
  227. padding: 20rpx;
  228. background-color: #fff;
  229. display: flex;
  230. overflow: hidden;
  231. margin: 0 20rpx;
  232. border-radius: 10rpx;
  233. .course-item-image {
  234. width: 200rpx;
  235. height: 280rpx;
  236. flex: 0 0 auto;
  237. margin-right: 20rpx;
  238. .course-image {
  239. width: 100%;
  240. height: 100%;
  241. }
  242. }
  243. .course-item-content {
  244. flex: 1;
  245. position: relative;
  246. view {
  247. margin-bottom: 22rpx;
  248. }
  249. .course-title {
  250. font-weight: bold;
  251. margin-right: 10px;
  252. font-size: 28rpx;
  253. color: #000;
  254. }
  255. .course-type,
  256. .course-teacher,
  257. .course-date,
  258. .course-price {
  259. font-size: 30rpx;
  260. color: #000;
  261. }
  262. .course-price {
  263. color: #fe0000;
  264. letter-spacing: 2rpx;
  265. }
  266. .button::after {
  267. content: none;
  268. /* 移除内容 */
  269. }
  270. .button {
  271. position: absolute;
  272. right: 0;
  273. bottom: 0;
  274. min-width: 80px;
  275. padding: 0 40rpx;
  276. white-space: nowrap;
  277. height: 45rpx;
  278. line-height: 45rpx;
  279. font-size: 22rpx;
  280. /* padding: 0; */
  281. border-radius: 50rpx;
  282. color: white;
  283. border: none;
  284. }
  285. .free {
  286. background-color: #006af4;
  287. }
  288. .purchase {
  289. background-color: #fe0000;
  290. }
  291. .member-free {
  292. background-color: transparent;
  293. background-image: url('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  294. background-size: cover;
  295. background-repeat: no-repeat;
  296. color: #000;
  297. height: initial;
  298. padding: 6rpx 0 3rpx;
  299. border-radius: 0;
  300. }
  301. .replay {
  302. background-color: #006af4;
  303. }
  304. .purchased {
  305. background-color: #006af4;
  306. }
  307. }
  308. }
  309. .course-form {
  310. padding: 20rpx;
  311. background-color: #fff;
  312. display: flex;
  313. overflow: hidden;
  314. border-radius: 10rpx;
  315. flex-direction: column;
  316. font-size: 30rpx;
  317. margin: 0 20rpx;
  318. .course-form-item {
  319. display: flex;
  320. justify-content: space-between;
  321. width: 100%;
  322. margin: 20rpx 0;
  323. .iconfont {
  324. display: inline-block;
  325. font-size: 24rpx;
  326. }
  327. }
  328. }
  329. .pay {
  330. position: fixed;
  331. bottom: 0;
  332. width: 100%;
  333. display: flex;
  334. justify-content: space-between;
  335. padding: 30rpx 20rpx calc(10rpx + env(safe-area-inset-bottom, 0));
  336. background-color: #fff;
  337. align-items: center;
  338. .pay-price {
  339. font-size: 60rpx;
  340. color: red;
  341. font-weight: bold;
  342. }
  343. .pay-btn {
  344. // width: 200rpx;
  345. height: 70rpx;
  346. line-height: 70rpx;
  347. background-color: red;
  348. color: #fff;
  349. border-radius: 40rpx;
  350. }
  351. }
  352. .text-red {
  353. color: red;
  354. }
  355. </style>