index.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import { Button, Cell, Icon, Image, Popup, showConfirmDialog, Toast } from 'vant'
  2. import { defineComponent } from 'vue'
  3. import styles from './index.module.less'
  4. import request from '@/helpers/request'
  5. import { setLogin, state } from '@/state'
  6. import iconStudent from '@common/images/icon_student.png'
  7. import iconTeacher from '@common/images/icon_teacher.png'
  8. import iconDiscount from './images/icon_discount.png'
  9. import iconMemberLogo from './images/member_logo.png'
  10. // import { orderStatus } from '@/views/order-detail/orderStatus'
  11. import dayjs from 'dayjs'
  12. import { memberType } from '@/constant'
  13. import { moneyFormat } from '@/helpers/utils'
  14. import OHeader from '@/components/o-header'
  15. export const getAssetsHomeFile = (fileName: string) => {
  16. const path = `./images/${fileName}`
  17. const modules = import.meta.globEager('./images/*')
  18. return modules[path].default
  19. }
  20. export default defineComponent({
  21. name: 'MemberCenter',
  22. data() {
  23. const query = this.$route.query
  24. return {
  25. functionList: [] as any,
  26. selectMember: {} as any,
  27. users: {} as any
  28. }
  29. },
  30. computed: {
  31. userInfo() {
  32. const users: any = this.users
  33. return {
  34. username: users?.nickname || '',
  35. phone: users?.phone || '',
  36. avatar: users?.avatar,
  37. id: users?.id,
  38. isVip: users?.vipMember,
  39. membershipDays: users?.membershipDays,
  40. membershipEndTime: users?.membershipEndTime
  41. }
  42. }
  43. },
  44. async mounted() {
  45. try {
  46. const userInfo = await request.get('/api-student/student/member')
  47. this.users = userInfo.data || {}
  48. this.functionList = [
  49. {
  50. title: '五线谱<br />跟播',
  51. icon: getAssetsHomeFile(`1.png`)
  52. },
  53. {
  54. title: '演奏指法<br />跟播',
  55. icon: getAssetsHomeFile(`2.png`)
  56. },
  57. {
  58. title: '原声/伴奏<br />切换',
  59. icon: getAssetsHomeFile(`3.png`)
  60. },
  61. {
  62. title: '播放速度<br />调整',
  63. icon: getAssetsHomeFile(`4.png`)
  64. },
  65. {
  66. title: '五线谱选段<br />播放',
  67. icon: getAssetsHomeFile(`5.png`)
  68. },
  69. {
  70. title: '智能评测',
  71. icon: getAssetsHomeFile(`6.png`)
  72. },
  73. {
  74. title: '评测报告',
  75. icon: getAssetsHomeFile(`7.png`)
  76. },
  77. {
  78. title: '评测音视频<br />云储存',
  79. icon: getAssetsHomeFile(`8.png`)
  80. }
  81. ]
  82. const { data } = await request.post(`/api-student/cityFeeSetting/member`)
  83. this.selectMember = data
  84. this.paymentOrderUnpaid()
  85. } catch {
  86. //
  87. }
  88. //
  89. },
  90. methods: {
  91. // 查询未支付订单
  92. async paymentOrderUnpaid() {
  93. try {
  94. const { data } = await request.get('/api-student/userPaymentOrder/unpaid', {
  95. requestType: 'form',
  96. params: {
  97. paymentType: 'VIP'
  98. }
  99. })
  100. // 判断是否有待支付订单
  101. if (data.id) {
  102. showConfirmDialog({
  103. message: '您有待支付的订单,是否继续支付',
  104. cancelButtonText: '取消订单',
  105. confirmButtonText: '继续支付'
  106. })
  107. .then(() => {
  108. const paymentConfig = data.paymentConfig
  109. this.$router.push({
  110. path: '/orderDetail',
  111. query: {
  112. config: JSON.stringify(paymentConfig.paymentConfig),
  113. orderNo: paymentConfig.orderNo
  114. }
  115. })
  116. })
  117. .catch(async () => {
  118. try {
  119. await request.post('/api-student/userPaymentOrder/cancelPayment/' + data.orderNo)
  120. } catch {
  121. //
  122. }
  123. })
  124. }
  125. } catch {
  126. //
  127. }
  128. },
  129. calcSalePrice(item: any) {
  130. // discount
  131. if (item.discount === 1) {
  132. const tempPrice = Number((item.salePrice - item.discountPrice).toFixed(2))
  133. return tempPrice >= 0 ? tempPrice : 0
  134. }
  135. return item.salePrice
  136. },
  137. // 购买
  138. async onSubmit() {
  139. try {
  140. const selectMember = this.selectMember
  141. const params: any = [
  142. {
  143. goodsId: selectMember.id,
  144. goodsNum: 1,
  145. goodsType: 'VIP',
  146. paymentCashAmount: selectMember.salePrice, // 现金支付金额
  147. paymentCouponAmount: 0 // 优惠券金额
  148. }
  149. ] // 支付参数
  150. // 创建订单
  151. const { data } = await request.post('/api-student/userPaymentOrder/executeOrder', {
  152. data: {
  153. orderType: 'VIP',
  154. paymentCashAmount: this.selectMember.salePrice || 0,
  155. paymentCouponAmount: 0,
  156. goodsInfos: params,
  157. orderName: '团练宝购买',
  158. orderDesc: '团练宝购买'
  159. }
  160. })
  161. console.log(data)
  162. this.$router.push({
  163. path: '/orderDetail',
  164. query: {
  165. config: JSON.stringify(data.paymentConfig),
  166. orderNo: data.orderNo
  167. }
  168. })
  169. } catch (e: any) {
  170. //
  171. console.log(e)
  172. }
  173. }
  174. },
  175. render() {
  176. return (
  177. <div class={styles['member-center']}>
  178. <OHeader background="#ffe5cc" />
  179. <div class={styles.member_container}>
  180. <Cell
  181. class={styles.userMember}
  182. labelClass={styles.timeRemaining}
  183. v-slots={{
  184. icon: () => (
  185. <div class={styles.userImgSection}>
  186. <Image
  187. class={styles.userImg}
  188. src={this.userInfo.avatar || iconStudent}
  189. fit="cover"
  190. />
  191. </div>
  192. ),
  193. title: () => (
  194. <div class={styles.userInfo}>
  195. <span class={styles.name}>{this.userInfo.username}</span>
  196. {!!this.userInfo.isVip && (
  197. <Image
  198. class={styles.level}
  199. src="https://daya.ks3-cn-beijing.ksyun.com/202107/ScSTL1D.png"
  200. />
  201. )}
  202. {this.userInfo.phone && (
  203. <span class={styles.phone} v-html={`(${this.userInfo.phone})`}></span>
  204. )}
  205. </div>
  206. ),
  207. label: () => (
  208. <div class={styles.member_time}>
  209. {this.userInfo.isVip ? (
  210. <div>
  211. 会员权益有效期剩余
  212. <span class={styles.remaining}>{this.userInfo.membershipDays}</span>天
  213. </div>
  214. ) : (
  215. <div>亲,您还不是会员哟</div>
  216. )}
  217. </div>
  218. )
  219. }}
  220. ></Cell>
  221. </div>
  222. <div class={styles.memberContainer}>
  223. <div class={styles.memberItem}>
  224. <div class={styles.title}>
  225. 会员<span>VIP</span>
  226. </div>
  227. <div class={styles['system-list']}>
  228. <div class={[styles['system-item'], styles.active]}>
  229. <p class={[styles.title, 'van-hairline--bottom']}>
  230. 半年会员
  231. <span>(6个月)</span>
  232. </p>
  233. <div class={styles.priceGroup}>
  234. <p class={styles.price}>
  235. <span>¥</span>
  236. {moneyFormat(this.selectMember.salePrice)}
  237. </p>
  238. <del class={styles.originalPrice}>
  239. ¥{moneyFormat(this.selectMember.originalPrice)}
  240. </del>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. <div class={[styles.intro]}>
  246. <p>
  247. 团练宝会员使用包括平台提供教材的所有训练乐谱,并专享“乐器练习云教练”八大核心功能,孩子在家就能轻松完成乐器自主规范练习。
  248. </p>
  249. </div>
  250. <div class={styles.memberItem}>
  251. <div class={styles.title}>会员功能</div>
  252. <div class={styles.member_function}>
  253. {this.functionList.map((item: any) => (
  254. <div class={styles.function_item}>
  255. <Icon name={item.icon} size={34} />
  256. <div class={styles.function_text} v-html={item.title}></div>
  257. </div>
  258. ))}
  259. </div>
  260. </div>
  261. </div>
  262. <div class={styles.btnGroup}>
  263. <div class={styles.priceSection}>
  264. 支付金额:
  265. <div class={styles.price}>
  266. <span class={styles.priceUnit}>¥</span>
  267. <span class={styles.priceNum}>
  268. {moneyFormat(this.calcSalePrice(this.selectMember) || 0)}
  269. </span>
  270. </div>
  271. {this.selectMember?.discount == 1 && (
  272. <div class={[styles.discountItem, styles.discountBuy]}>
  273. <img src={iconDiscount} />
  274. </div>
  275. )}
  276. </div>
  277. <Button
  278. color="linear-gradient(220deg, #DFA164 0%, #FAC87E 100%)"
  279. round
  280. class={styles.btn}
  281. onClick={this.onSubmit}
  282. >
  283. 立即开通
  284. </Button>
  285. </div>
  286. </div>
  287. )
  288. }
  289. })