index.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. center
  184. v-slots={{
  185. icon: () => (
  186. <div class={styles.userImgSection}>
  187. <Image
  188. class={styles.userImg}
  189. src={this.userInfo.avatar || iconStudent}
  190. fit="cover"
  191. />
  192. </div>
  193. ),
  194. title: () => (
  195. <div class={styles.userInfo}>
  196. <span class={styles.name}>{this.userInfo.username}</span>
  197. {!!this.userInfo.isVip && (
  198. <Image
  199. class={styles.level}
  200. src="https://daya.ks3-cn-beijing.ksyun.com/202107/ScSTL1D.png"
  201. />
  202. )}
  203. {this.userInfo.phone && (
  204. <span class={styles.phone} v-html={`(${this.userInfo.phone})`}></span>
  205. )}
  206. </div>
  207. ),
  208. label: () => (
  209. <div class={styles.member_time}>
  210. {this.userInfo.isVip ? (
  211. <div>
  212. 会员权益有效期剩余
  213. <span class={styles.remaining}>{this.userInfo.membershipDays}</span>天
  214. </div>
  215. ) : (
  216. <div>亲,您还不是会员哟</div>
  217. )}
  218. </div>
  219. )
  220. }}
  221. ></Cell>
  222. </div>
  223. <div class={styles.memberContainer}>
  224. <div class={styles.memberItem}>
  225. <div class={styles.title}>
  226. 会员<span>VIP</span>
  227. </div>
  228. <div class={styles['system-list']}>
  229. <div class={[styles['system-item'], styles.active]}>
  230. <p class={[styles.title, 'van-hairline--bottom']}>
  231. 半年会员
  232. <span>(6个月)</span>
  233. </p>
  234. <div class={styles.priceGroup}>
  235. <p class={styles.price}>
  236. <span>¥</span>
  237. {moneyFormat(this.selectMember.salePrice)}
  238. </p>
  239. <del class={styles.originalPrice}>
  240. ¥{moneyFormat(this.selectMember.originalPrice)}
  241. </del>
  242. </div>
  243. </div>
  244. </div>
  245. </div>
  246. <div class={[styles.intro]}>
  247. <p>
  248. 团练宝会员使用包括平台提供教材的所有训练乐谱,并专享“乐器练习云教练”八大核心功能,孩子在家就能轻松完成乐器自主规范练习。
  249. </p>
  250. </div>
  251. <div class={styles.memberItem}>
  252. <div class={styles.title}>会员功能</div>
  253. <div class={styles.member_function}>
  254. {this.functionList.map((item: any) => (
  255. <div class={styles.function_item}>
  256. <Icon name={item.icon} size={34} />
  257. <div class={styles.function_text} v-html={item.title}></div>
  258. </div>
  259. ))}
  260. </div>
  261. </div>
  262. </div>
  263. <div class={styles.btnGroup}>
  264. <div class={styles.priceSection}>
  265. 支付金额:
  266. <div class={styles.price}>
  267. <span class={styles.priceUnit}>¥</span>
  268. <span class={styles.priceNum}>
  269. {moneyFormat(this.calcSalePrice(this.selectMember) || 0)}
  270. </span>
  271. </div>
  272. {this.selectMember?.discount == 1 && (
  273. <div class={[styles.discountItem, styles.discountBuy]}>
  274. <img src={iconDiscount} />
  275. </div>
  276. )}
  277. </div>
  278. <Button
  279. color="linear-gradient(220deg, #DFA164 0%, #FAC87E 100%)"
  280. round
  281. class={styles.btn}
  282. onClick={this.onSubmit}
  283. >
  284. {this.userInfo.isVip ? '立即续费' : '立即开通'}
  285. </Button>
  286. </div>
  287. </div>
  288. )
  289. }
  290. })