courseOrder.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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.redirectTo({
  173. // url: "/pages/goOnEdu/course/courseDetail/coursePay?id=" + courseId.value
  174. // })
  175. }
  176. const clickAction = (i) => {
  177. // console.log(i)
  178. activePayType.value = list.value[i].text
  179. payTypeShow.value = false
  180. }
  181. // 日期格式:xxxx年xx月xx日(星期x)
  182. function getDateWeek(val) {
  183. const date = new Date(val);
  184. const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
  185. const year = date.getFullYear();
  186. const month = date.getMonth() + 1; // 注意:月份从0开始
  187. const day = date.getDate();
  188. const dayOfWeek = daysOfWeek[date.getUTCDay()];
  189. // const result = `${year}年${month}月${day}日(星期${dayOfWeek})`
  190. return `${year}年${month}月${day}日(星期${dayOfWeek})`
  191. }
  192. const toJoin = () =>{
  193. uni.navigateTo({
  194. url: '/pages/joinClub/joinClub'
  195. })
  196. }
  197. // 初始化
  198. function init(id) {
  199. loadCourseDetail(id).then(res => {
  200. if (res?.data) {
  201. course.value = res.data;
  202. payForm.value.id = res.data.id;
  203. payForm.value.title = res.data.courseName
  204. payForm.value.desc = res.data.courseName
  205. }
  206. })
  207. }
  208. onLoad((option) => {
  209. const {
  210. id
  211. } = option;
  212. init(id);
  213. console.log('onLoad', id)
  214. })
  215. </script>
  216. <style lang="scss" scoped>
  217. .container {
  218. height: 100vh;
  219. width: 100vw;
  220. background-color: $uni-bg-color;
  221. // padding: 0 20rpx;
  222. }
  223. .course-item {
  224. padding: 20rpx;
  225. background-color: #fff;
  226. display: flex;
  227. overflow: hidden;
  228. margin: 0 20rpx;
  229. border-radius: 10rpx;
  230. .course-item-image {
  231. width: 200rpx;
  232. height: 280rpx;
  233. flex: 0 0 auto;
  234. margin-right: 20rpx;
  235. .course-image {
  236. width: 100%;
  237. height: 100%;
  238. }
  239. }
  240. .course-item-content {
  241. flex: 1;
  242. position: relative;
  243. view {
  244. margin-bottom: 22rpx;
  245. }
  246. .course-title {
  247. font-weight: bold;
  248. margin-right: 10px;
  249. font-size: 28rpx;
  250. color: #000;
  251. }
  252. .course-type,
  253. .course-teacher,
  254. .course-date,
  255. .course-price {
  256. font-size: 30rpx;
  257. color: #000;
  258. }
  259. .course-price {
  260. color: #fe0000;
  261. letter-spacing: 2rpx;
  262. }
  263. .button::after {
  264. content: none;
  265. /* 移除内容 */
  266. }
  267. .button {
  268. position: absolute;
  269. right: 0;
  270. bottom: 0;
  271. min-width: 80px;
  272. padding: 0 40rpx;
  273. white-space: nowrap;
  274. height: 45rpx;
  275. line-height: 45rpx;
  276. font-size: 22rpx;
  277. /* padding: 0; */
  278. border-radius: 50rpx;
  279. color: white;
  280. border: none;
  281. }
  282. .free {
  283. background-color: #006af4;
  284. }
  285. .purchase {
  286. background-color: #fe0000;
  287. }
  288. .member-free {
  289. background-color: transparent;
  290. background-image: url('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  291. background-size: cover;
  292. background-repeat: no-repeat;
  293. color: #000;
  294. height: initial;
  295. padding: 6rpx 0 3rpx;
  296. border-radius: 0;
  297. }
  298. .replay {
  299. background-color: #006af4;
  300. }
  301. .purchased {
  302. background-color: #006af4;
  303. }
  304. }
  305. }
  306. .course-form {
  307. padding: 20rpx;
  308. background-color: #fff;
  309. display: flex;
  310. overflow: hidden;
  311. border-radius: 10rpx;
  312. flex-direction: column;
  313. font-size: 30rpx;
  314. margin: 0 20rpx;
  315. .course-form-item {
  316. display: flex;
  317. justify-content: space-between;
  318. width: 100%;
  319. margin: 20rpx 0;
  320. .iconfont {
  321. display: inline-block;
  322. font-size: 24rpx;
  323. }
  324. }
  325. }
  326. .pay {
  327. position: fixed;
  328. bottom: 0;
  329. width: 100%;
  330. display: flex;
  331. justify-content: space-between;
  332. padding: 40rpx 20rpx env(safe-area-inset-bottom, 0);
  333. background-color: #fff;
  334. align-items: center;
  335. .pay-price {
  336. font-size: 60rpx;
  337. color: red;
  338. font-weight: bold;
  339. }
  340. .pay-btn {
  341. width: 200rpx;
  342. height: 70rpx;
  343. line-height: 70rpx;
  344. background-color: red;
  345. color: #fff;
  346. border-radius: 40rpx;
  347. }
  348. }
  349. .text-red {
  350. color: red;
  351. }
  352. </style>