index.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. import {
  2. Image,
  3. Cell,
  4. CellGroup,
  5. Tag,
  6. Button,
  7. Stepper,
  8. Icon,
  9. Popup,
  10. showConfirmDialog,
  11. showToast
  12. } from 'vant';
  13. import { computed, defineComponent, onMounted, reactive } from 'vue';
  14. import styles from './index.module.less';
  15. import iconGift from './images/icon-gift.png';
  16. import shopEmpty from './images/shop-empty.png';
  17. import iconDateMember from './images/icon-date-member.png';
  18. import MSticky from '@/components/m-sticky';
  19. import MVideo from '@/components/m-video';
  20. import { useRoute, useRouter } from 'vue-router';
  21. import RegisterModal from './register-modal';
  22. import { useStudentRegisterStore } from '@/store/modules/student-register-store';
  23. import request from '@/helpers/request';
  24. import { browser, moneyFormat } from '@/helpers/utils';
  25. import deepClone from '@/helpers/deep-clone';
  26. import OWxTip from '@/components/m-wx-tip';
  27. import MDialog from '@/components/m-dialog';
  28. export default defineComponent({
  29. name: 'student-register',
  30. setup() {
  31. const route = useRoute();
  32. const studentRegisterStore = useStudentRegisterStore();
  33. const router = useRouter();
  34. // 初始化学校编号
  35. studentRegisterStore.setShoolId(route.query.sId as any);
  36. const forms = reactive({
  37. schoolId: route.query.sId as any,
  38. paymentType: '', // 支付类型
  39. popupShow: false,
  40. details: [] as any[],
  41. schoolType: '', // 学校类型
  42. gradeYear: '', // 学制
  43. bugGoods: false, // 是否购买AI
  44. registerType: '', // 报名类型
  45. giftVipDay: 0, // 赠送天数
  46. submitLoading: false,
  47. showMore: true,
  48. showTips: false,
  49. showButton: false,
  50. showMessage: '请使用微信打开'
  51. });
  52. const getRegisterGoods = async () => {
  53. try {
  54. const { data } = await request.get(
  55. '/edu-app/open/userOrder/registerGoods/' + forms.schoolId,
  56. {
  57. noAuthorization: true // 是否请求接口的时候添加toekn
  58. }
  59. );
  60. // 默认选中商品
  61. studentRegisterStore.setVip(data.details || []);
  62. forms.details = deepClone(data.details || []);
  63. if (forms.details.length > 0) {
  64. forms.giftVipDay = forms.details[0].membershipDays;
  65. }
  66. forms.bugGoods = data.bugGoods;
  67. forms.schoolType = data.schoolType;
  68. forms.gradeYear = data.gradeYear;
  69. forms.registerType = data.registerType;
  70. if (browser().weixin) {
  71. if (data.registerType !== 'BUG_GOODS' || data.schoolStatus === 0) {
  72. forms.showTips = true;
  73. forms.showMessage = '二维码已经失效,详情请咨询学校老师';
  74. forms.showButton = false;
  75. }
  76. } else {
  77. forms.showTips = true;
  78. }
  79. } catch {}
  80. };
  81. // 计算金额
  82. const calcPrice = computed(() => {
  83. let amount: number = 0; //现价
  84. let originAmount: number = 0; // 原价
  85. const vipList: any[] = studentRegisterStore.getVip;
  86. vipList.forEach((vip: any) => {
  87. amount += Number(vip.currentPrice);
  88. originAmount += Number(vip.originalPrice);
  89. });
  90. const goodsList: any[] = studentRegisterStore.getGoods;
  91. goodsList.forEach((good: any) => {
  92. amount += Number(good.price) * good.quantity;
  93. originAmount += Number(good.originalPrice) * good.quantity;
  94. });
  95. return {
  96. amount,
  97. originAmount
  98. };
  99. });
  100. // 删除商品
  101. const onGoodsRemove = (item: any) => {
  102. showConfirmDialog({
  103. message: '是否删除该商品',
  104. confirmButtonColor: '#FF8633'
  105. }).then(() => {
  106. studentRegisterStore.deleteGoods(item.productSkuId);
  107. });
  108. };
  109. // 登记成功之后购买
  110. const onRegisterSubmit = async () => {
  111. try {
  112. forms.submitLoading = true;
  113. // 检测token是否失效
  114. // const Authorization = storage.get(ACCESS_TOKEN) || '';
  115. // const authInfo = await request.post('/edu-app/open/user/verification', {
  116. // noAuthorization: true,
  117. // data: { token: Authorization }
  118. // });
  119. // // 判断当前token是否失效
  120. // if (!authInfo.data) {
  121. // storage.remove(ACCESS_TOKEN);
  122. // studentRegisterStore.deleteToken();
  123. // forms.popupRegister = true;
  124. // return;
  125. // }
  126. // // 请求是否有待支付订单,如果有则自动关闭
  127. // const status = await paymentOrderUnpaid();
  128. // if (status) return;
  129. // const schoolInfo = await request.get(
  130. // '/edu-app/userPaymentOrder/registerStatus/' + forms.schoolId
  131. // );
  132. // const vipList = studentRegisterStore.getVip;
  133. // if (schoolInfo.data.hasBuyCourse && vipList.length > 0) {
  134. // // setTimeout(() => {
  135. // // showToast('您已购买乐器AI学练工具,请勿重复购买');
  136. // // }, 100);
  137. // forms.dialogConfirmStatus = true;
  138. // return;
  139. // }
  140. // await paymentContinue();
  141. router.push({
  142. path: '/student-register-form',
  143. query: {
  144. schoolId: forms.schoolId
  145. }
  146. });
  147. } finally {
  148. forms.submitLoading = false;
  149. }
  150. };
  151. onMounted(async () => {
  152. try {
  153. getRegisterGoods();
  154. } catch {}
  155. });
  156. return () => (
  157. <div class={styles['student-register']}>
  158. <div class={styles.studentSection} style={{ marginTop: '18px' }}>
  159. <div class={styles.titleTool}></div>
  160. {forms.details.map((item: any) => (
  161. <CellGroup
  162. class={styles.goodsSection}
  163. onClick={() => {
  164. if (studentRegisterStore.selectedVip(item.goodsId)) {
  165. studentRegisterStore.deleteVip(item.goodsId);
  166. } else {
  167. studentRegisterStore.setVip([item]);
  168. }
  169. }}>
  170. <Cell border={false} class={styles.goodsCell}>
  171. {{
  172. icon: () => <Image class={styles.img} src={item.goodsUrl} />,
  173. title: () => (
  174. <div class={styles.section}>
  175. <div class={styles.sectionContent}>
  176. <h2>
  177. <img
  178. src={iconDateMember}
  179. class={styles.iconDateMember}
  180. />
  181. </h2>
  182. <p
  183. class={[
  184. styles.model,
  185. forms.showMore ? styles.more : ''
  186. ]}>
  187. {item.description}
  188. </p>
  189. {item.description &&
  190. item.description.length >= 36 &&
  191. forms.showMore ? (
  192. <span
  193. class={styles.moreBtn}
  194. onClick={(e: MouseEvent) => {
  195. e.stopPropagation();
  196. forms.showMore = false;
  197. }}>
  198. 查看更多
  199. <Icon name="arrow-down" color="#aaa" />
  200. </span>
  201. ) : (
  202. ''
  203. )}
  204. {/* <div class={styles.sbtnGroup}>
  205. <span
  206. class={styles.btnDetail}
  207. onClick={(e: MouseEvent) => {
  208. e.stopPropagation();
  209. router.push('/student-digital-tools');
  210. }}>
  211. 查看详情
  212. </span>
  213. <span
  214. class={styles.btnVideo}
  215. onClick={(e: MouseEvent) => {
  216. e.stopPropagation();
  217. forms.popupShow = true;
  218. }}>
  219. 介绍视频
  220. </span>
  221. </div> */}
  222. </div>
  223. <i
  224. class={
  225. studentRegisterStore.selectedVip(item.goodsId)
  226. ? styles.selected
  227. : styles.noSelected
  228. }></i>
  229. </div>
  230. )
  231. }}
  232. </Cell>
  233. <Cell border={false} class={styles.priceCell}>
  234. {{
  235. title: () => (
  236. <div class={styles.sPriceGroup}>
  237. <div class={styles.tg}>
  238. 团购价:
  239. <span>
  240. <i>¥ </i>
  241. {moneyFormat(item.currentPrice)}
  242. </span>
  243. </div>
  244. {item.currentPrice < item.originalPrice && (
  245. <del>¥{moneyFormat(item.originalPrice)}</del>
  246. )}
  247. </div>
  248. )
  249. }}
  250. </Cell>
  251. {item.membershipDays > 0 && (
  252. <Cell border={false} class={styles.giftCell}>
  253. {{
  254. title: () => (
  255. <div class={styles.gift}>
  256. <img src={iconGift} class={styles.iconGift} />
  257. 现在购买赠送 <span>{item.membershipDays || 0}</span>
  258. 天有效期
  259. </div>
  260. )
  261. }}
  262. </Cell>
  263. )}
  264. </CellGroup>
  265. ))}
  266. </div>
  267. {forms.bugGoods && (
  268. <>
  269. <div class={styles.studentSection}>
  270. <div class={styles.titleBuy}></div>
  271. {studentRegisterStore.getGoods &&
  272. studentRegisterStore.getGoods.length <= 0 ? (
  273. <div class={styles.goodsEmpty}>
  274. <img src={shopEmpty} class={styles.shopImg} />
  275. <div class={styles.goodsContainer}>
  276. <h2>
  277. 为你的<span>音乐之旅</span>做好准备
  278. </h2>
  279. <p class={styles.tips}>快去选购乐器吧~</p>
  280. <Button
  281. class={styles.goSelect}
  282. type="primary"
  283. onClick={() => {
  284. router.push('/goods-list');
  285. }}>
  286. 进入商城选购
  287. <Icon name="arrow" />
  288. </Button>
  289. </div>
  290. </div>
  291. ) : (
  292. studentRegisterStore.getGoods.map((goods: any) => (
  293. <CellGroup class={styles.goodsSection}>
  294. <Cell border={false} class={styles.goodsCell}>
  295. {{
  296. icon: () => (
  297. <Image class={styles.img} src={goods.pic} />
  298. ),
  299. title: () => (
  300. <div class={styles.section}>
  301. <div class={styles.sectionContent}>
  302. <h2>
  303. {goods.name}
  304. <Tag class={styles.brandName}>
  305. {goods.brandName}
  306. </Tag>
  307. </h2>
  308. <p class={[styles.model]}>
  309. 规格:{goods.spDataJson}
  310. </p>
  311. <p class={[styles.model]}>{goods.productSn}</p>
  312. <Stepper
  313. min={1}
  314. max={99}
  315. v-model={goods.quantity}
  316. disableInput
  317. />
  318. </div>
  319. <i
  320. class={styles.delete}
  321. onClick={() => onGoodsRemove(goods)}></i>
  322. </div>
  323. )
  324. }}
  325. </Cell>
  326. <Cell border={false} class={styles.priceCell}>
  327. {{
  328. title: () => (
  329. <div class={styles.sPriceGroup}>
  330. <div class={styles.tg}>
  331. 团购价:
  332. <span>
  333. <i>¥ </i>
  334. {moneyFormat(goods.price)}
  335. </span>
  336. </div>
  337. {goods.price < goods.originalPrice && (
  338. <del>¥{moneyFormat(goods.originalPrice)}</del>
  339. )}
  340. </div>
  341. )
  342. }}
  343. </Cell>
  344. </CellGroup>
  345. ))
  346. )}
  347. </div>
  348. {studentRegisterStore.getGoods &&
  349. studentRegisterStore.getGoods.length > 0 && (
  350. <Button
  351. class={styles.addButton}
  352. block
  353. onClick={() => {
  354. router.push('/goods-list');
  355. }}>
  356. <Icon name="add-o" />
  357. 进入商城选购
  358. </Button>
  359. )}
  360. </>
  361. )}
  362. <MSticky position="bottom">
  363. <div class={styles.paymentContainer}>
  364. <div class={styles.payemntPrice}>
  365. <span class={styles.needPrice}>
  366. <i style="font-style: normal">¥ </i>
  367. <span>{moneyFormat(calcPrice.value.amount)}</span>
  368. </span>
  369. {calcPrice.value.originAmount > calcPrice.value.amount ? (
  370. <del class={styles.allPrice}>
  371. ¥ {moneyFormat(calcPrice.value.originAmount)}
  372. </del>
  373. ) : (
  374. ''
  375. )}
  376. </div>
  377. <div
  378. class={styles.paymentBtn}
  379. onClick={() => {
  380. const vipList = studentRegisterStore.getVip;
  381. const goodsList = studentRegisterStore.getGoods;
  382. if (vipList.length <= 0 && goodsList.length <= 0) {
  383. setTimeout(() => {
  384. showToast('请选择需要购买的商品');
  385. }, 100);
  386. return;
  387. }
  388. onRegisterSubmit();
  389. }}>
  390. <Button
  391. disabled={forms.submitLoading}
  392. loading={forms.submitLoading}>
  393. 确认购买
  394. </Button>
  395. </div>
  396. </div>
  397. </MSticky>
  398. <Popup v-model:show={forms.popupShow} class={styles.videoPopup}>
  399. {forms.popupShow && (
  400. <MVideo src={'https://oss.dayaedu.com/daya/202105/SWmqmvW.mp4'} />
  401. )}
  402. </Popup>
  403. {/* 是否在微信中打开 */}
  404. <OWxTip
  405. show={forms.showTips}
  406. message={forms.showMessage}
  407. showButton={forms.showButton}
  408. buttonText="刷新"
  409. onConfirm={() => window.location.reload()}
  410. />
  411. </div>
  412. );
  413. }
  414. });