courseOrder.vue 8.0 KB

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