| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- import OSticky from '@/components/o-sticky'
- import {
- Button,
- Cell,
- CellGroup,
- Checkbox,
- CheckboxGroup,
- Icon,
- Image,
- Popup,
- showConfirmDialog,
- showToast,
- Tag
- } from 'vant'
- import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue'
- import styles from '../index.module.less'
- import radioCheck from '@/common/images/icon-radio-check.png'
- import radioDefault from '@/common/images/icon-radio-default.png'
- import iconGives from '../images/icon-gives.png'
- import { useRoute, useRouter } from 'vue-router'
- import request from '@/helpers/request'
- import { moneyFormat } from '@/helpers/utils'
- import { CountUp } from 'countup.js'
- import OPopup from '@/components/o-popup'
- import MemberBao from '../../member-bao'
- import GoodsDetail from '../../goods-detail'
- import ODialog from '@/components/o-dialog'
- export default defineComponent({
- name: 'payment',
- emits: ['next'],
- setup() {
- const route = useRoute()
- const router = useRouter()
- const state = reactive({
- paymentType: '',
- musicPaymentType: '', // 乐团中对应支付方式
- check: [] as any, // 选中的数据
- checkboxRefs: [] as any,
- details: [] as any, //
- goodsInfo: {} as any, // 商品
- textBookInfo: {} as any, // 教材
- repaireInfo: {} as any, // 乐器保养
- vipInfo: {} as any, // 团练宝
- paymentOrderDetails: [] as any, // 购买状态
- orderInfo: {
- needPrice: 0,
- originalPrice: 0
- },
- memberBaoStatus: false, // 团练宝详情状态
- goodsStatus: false, //
- selectGoodsId: null as any,
- currentPrice: 0,
- selectGoodsInfo: {} as any,
- dialogStatus: false,
- dialogMessage: '',
- dialogOrchestraStatus: false, // 是否为不同的乐团
- dialogConfig: {} as any
- })
- // 获取支付渠道
- const sysParamConfig = async () => {
- try {
- const { data } = await request.get('/api-student/sysParamConfig/queryByParamName', {
- params: {
- paramName: 'payment_service_provider'
- }
- })
- state.paymentType = data.paramValue || ''
- } catch {
- //
- }
- }
- // 查询未支付订单
- const paymentOrderUnpaid = async () => {
- try {
- const { data } = await request.get('/api-student/userPaymentOrder/unpaid', {
- params: {
- orchestraId: route.query.id
- }
- })
- // 判断是否有待支付订单
- if (data.id) {
- if (data.orchestraId !== route.query.id) {
- state.dialogMessage = '您在其它乐团存在待支付订单,取消后才可继续报名,是否确认取消?'
- state.dialogStatus = true
- state.dialogOrchestraStatus = true
- state.dialogConfig = data
- } else {
- state.dialogMessage = '您有待支付的订单,是否继续支付'
- state.dialogStatus = true
- state.dialogConfig = data
- }
- }
- } catch {
- //
- }
- }
- // 获取商品信息
- const registerGoods = async () => {
- try {
- const { data } = await request.get(
- '/api-student/orchestraRegister/registerGoods/' + route.query.id
- )
- state.musicPaymentType = data.paymentServiceProvider || ''
- // 获取已经购买商品信息
- const paymentOrderDetails = data.paymentOrderDetails || []
- paymentOrderDetails.forEach((item: any) => {
- state.paymentOrderDetails.push(item.goodsType)
- })
- // 初始化数据商品数据
- const details = data.details || []
- details.forEach((item: any) => {
- if (item.goodsType === 'INSTRUMENTS') {
- const img = item.goodsUrl ? item.goodsUrl.split(',')[0] : ''
- state.goodsInfo = { ...item, goodsUrl: img }
- } else if (item.goodsType === 'TEXTBOOK') {
- const img = item.goodsUrl ? item.goodsUrl.split(',')[0] : ''
- state.textBookInfo = { ...item, goodsUrl: img }
- } else if (item.goodsType === 'REPAIR') {
- state.repaireInfo = { ...item }
- } else if (item.goodsType === 'VIP') {
- state.vipInfo = { ...item }
- }
- state.details = details
- // 默认选中所有的
- if (
- !state.paymentOrderDetails.includes(item.goodsType) &&
- ['INSTRUMENTS', 'TEXTBOOK', 'VIP'].includes(item.goodsType)
- ) {
- state.check.push(item.goodsId)
- }
- })
- calcPrice()
- } catch {
- //
- }
- }
- const onSelect = (type: string) => {
- state.checkboxRefs[type].toggle()
- calcPrice()
- }
- // 初始化金额
- const calcPrice = () => {
- const details = state.details
- const tempPrice = {
- needPrice: 0, //需要支付金额
- originalPrice: 0 // 原价
- }
- details.forEach((item: any) => {
- // 是否选中
- if (
- state.check.includes(item.goodsId) &&
- !state.paymentOrderDetails.includes(item.goodsType)
- ) {
- tempPrice.needPrice += parseFloat(item.currentPrice || 0)
- tempPrice.originalPrice += parseFloat(item.originalPrice || 0)
- }
- })
- state.orderInfo = tempPrice
- initNumCountUp()
- }
- const countUpRef = reactive({
- needPrice: null as any,
- originalPrice: null as any
- })
- const initNumCountUp = () => {
- nextTick(() => {
- // 在读学员
- if (countUpRef.needPrice) {
- countUpRef.needPrice.update(state.orderInfo.needPrice)
- } else {
- countUpRef.needPrice = new CountUp('needPrice', state.orderInfo.needPrice, {
- decimalPlaces: 2
- })
- if (!countUpRef.needPrice.error) {
- countUpRef.needPrice.start()
- } else {
- console.error(countUpRef.needPrice.error)
- }
- }
- // if (countUpRef.originalPrice) {
- // countUpRef.originalPrice.update(state.orderInfo.originalPrice)
- // } else {
- // countUpRef.originalPrice = new CountUp('originalPrice', state.orderInfo.originalPrice, {
- // decimalPlaces: 2
- // })
- // if (!countUpRef.originalPrice.error) {
- // countUpRef.originalPrice.start()
- // } else {
- // console.error(countUpRef.originalPrice.error)
- // }
- // }
- })
- }
- // 购买
- const onSubmit = async () => {
- try {
- // 判断订单号
- if (state.check.length <= 0) {
- showToast('请选择您要购买的商品')
- return
- }
- // 重新计算金额
- calcPrice()
- const params: any = [] // 支付参数
- const details = state.details
- let checkInstruments = false // 是否选择了乐器
- details.forEach((item: any) => {
- // 是否选中 并且没有购买过
- if (
- state.check.includes(item.goodsId) &&
- !state.paymentOrderDetails.includes(item.goodsType)
- ) {
- params.push({
- goodsId: item.goodsId,
- goodsNum: 1,
- goodsType: item.goodsType,
- paymentCashAmount: item.currentPrice, // 现金支付金额
- paymentCouponAmount: 0 // 优惠券金额
- })
- }
- // 判断是否是乐器
- if (
- item.goodsType === 'INSTRUMENTS' &&
- state.check.includes(item.goodsId) &&
- !state.paymentOrderDetails.includes(item.goodsType)
- ) {
- checkInstruments = false
- }
- })
- // 为了处理,商品和乐器保养做关联
- const repaire = state.repaireInfo
- if (checkInstruments && repaire.goodsId) {
- params.push({
- goodsId: repaire.goodsId,
- goodsNum: 1,
- goodsType: repaire.goodsType,
- paymentCashAmount: repaire.currentPrice, // 现金支付金额
- paymentCouponAmount: 0 // 优惠券金额
- })
- }
- // console.log({
- // bizId: route.query.id, // 乐团编号
- // orderType: 'ORCHESTRA',
- // paymentCashAmount: state.orderInfo.needPrice || 0,
- // paymentCouponAmount: 0,
- // goodsInfos: params
- // })
- // 创建订单
- const { data } = await request.post('/api-student/userPaymentOrder/executeOrder', {
- hideLoading: false,
- data: {
- paymentType: state.musicPaymentType || state.paymentType,
- bizId: route.query.id, // 乐团编号
- orderType: 'ORCHESTRA',
- paymentCashAmount: state.orderInfo.needPrice || 0,
- paymentCouponAmount: 0,
- goodsInfos: params,
- orderName: '乐团报名缴费',
- orderDesc: '乐团报名缴费'
- }
- })
- console.log(data)
- router.push({
- path: '/orderDetail',
- query: {
- pm: 1, // h5乐团报名
- config: JSON.stringify({ ...data.paymentConfig, paymentType: data.paymentType }),
- orderNo: data.orderNo
- }
- })
- } catch (e: any) {
- //
- console.log(e)
- }
- }
- onMounted(() => {
- sysParamConfig()
- // 查询未支付订单
- registerGoods()
- paymentOrderUnpaid()
- })
- return () => (
- <>
- <div class={styles.applyTitle}>报名须知</div>
- <div class={[styles.paymentTips, styles.mlr13]}>
- <p>
- 1、<span>乐团免费政策</span>:学生在团期间训练及教材免费政策(教材邮费需自理);
- </p>
- <p>
- 2、<span>入团须备工具</span>
- :家长在开训前自行为学生准备好①乐器、②乐团AI学练工具两项训练工具;
- </p>
- <p>
- 3、参加团购可享受同类工具同等品质价格低30%的团购政策,由基金会统一协调乐器调试及运输、学练工具安装及激活;
- </p>
- <p>
- 4、自行准备工具的家长,等收到开团确认信息后,可根据参考表开始为学生进行乐团训练工具准备。
- </p>
- </div>
- <CheckboxGroup
- v-model={state.check}
- style={{ paddingBottom: '20px' }}
- onChange={() => {
- calcPrice()
- }}
- >
- {/* 判断是否买了乐器学习系统 */}
- {!state.paymentOrderDetails.includes('VIP') && (
- <>
- {/* <div class={styles.applyTitle}>乐团学习系统</div> */}
- <CellGroup
- inset
- class={[styles.mlr13, styles.sectionCell]}
- onClick={() => onSelect(state.vipInfo.goodsId)}
- >
- <Cell border={false}>
- {{
- icon: () => (
- <Checkbox
- name={state.vipInfo.goodsId}
- class={styles.checkbox}
- ref={(el: any) => (state.checkboxRefs[state.vipInfo.goodsId] = el)}
- onClick={(e: Event) => {
- e.stopPropagation()
- }}
- v-slots={{
- icon: (props: any) => (
- <Icon
- class={styles.iconChecked}
- name={props.checked ? radioCheck : radioDefault}
- />
- )
- }}
- />
- ),
- title: () => (
- <div class={styles.section}>
- <Image
- class={styles.img}
- src={state.vipInfo.goodsUrl}
- onClick={(e: any) => {
- e.stopPropagation()
- state.memberBaoStatus = true
- }}
- />
- <div class={styles.sectionContent}>
- <h2
- onClick={(e: any) => {
- e.stopPropagation()
- state.memberBaoStatus = true
- }}
- >
- {state.vipInfo.goodsName}
- </h2>
- <Tag
- color="linear-gradient(135deg, #FF8C4A 0%, #FF531C 100%)"
- textColor="#fff"
- class={styles.brandName}
- >
- 6个月
- </Tag>
- <p class={[styles.model, 'van-multi-ellipsis--l2']}>
- {state.vipInfo.description}
- </p>
- </div>
- </div>
- )
- }}
- </Cell>
- <Cell>
- {{
- title: () => (
- <div class={styles.extra}>
- <div class={styles.sectionPrice}>
- <p class={styles.price}>
- 团购价:
- <span class={styles.numFont}>
- <span class={styles.numPrefix}>¥</span>
- {moneyFormat(state.vipInfo.currentPrice)}
- </span>
- </p>
- <p class={styles.originPrice}>
- 原价:
- <del class={styles.numFont}>
- ¥ {moneyFormat(state.vipInfo.originalPrice)}
- </del>
- </p>
- </div>
- </div>
- )
- }}
- </Cell>
- </CellGroup>
- </>
- )}
- {/* 判断是否已经购买乐器 */}
- {!state.paymentOrderDetails.includes('INSTRUMENTS') && (
- <>
- {/* <div class={styles.applyTitle}>乐器</div> */}
- <CellGroup
- inset
- class={[styles.mlr13, styles.sectionCell]}
- onClick={() => onSelect(state.goodsInfo.goodsId)}
- >
- <Cell border={false}>
- {{
- icon: () => (
- <Checkbox
- name={state.goodsInfo.goodsId}
- class={styles.checkbox}
- ref={(el: any) => (state.checkboxRefs[state.goodsInfo.goodsId] = el)}
- onClick={(e: Event) => {
- e.stopPropagation()
- }}
- v-slots={{
- icon: (props: any) => (
- <Icon
- class={styles.iconChecked}
- name={props.checked ? radioCheck : radioDefault}
- />
- )
- }}
- />
- ),
- title: () => (
- <div class={styles.section}>
- <Image
- class={styles.img}
- src={state.goodsInfo.goodsUrl}
- onClick={(e: any) => {
- e.stopPropagation()
- state.selectGoodsId = state.goodsInfo.goodsId
- state.currentPrice = state.goodsInfo.currentPrice
- state.selectGoodsInfo = {
- showFree: true,
- originalPrice: state.repaireInfo.originalPrice
- }
- state.goodsStatus = true
- }}
- />
- <div class={styles.sectionContent}>
- <h2
- onClick={(e: any) => {
- e.stopPropagation()
- state.selectGoodsId = state.goodsInfo.goodsId
- state.currentPrice = state.goodsInfo.currentPrice
- state.goodsStatus = true
- }}
- >
- {state.goodsInfo.goodsName}
- </h2>
- <Tag
- color="linear-gradient(135deg, #FF8C4A 0%, #FF531C 100%)"
- textColor="#fff"
- class={styles.brandName}
- >
- {state.goodsInfo.brandName}
- </Tag>
- <p class={[styles.model, 'van-multi-ellipsis--l2']}>
- {state.goodsInfo.description}
- </p>
- </div>
- </div>
- )
- }}
- </Cell>
- <Cell border={false}>
- {{
- title: () => (
- <div class={styles.extra}>
- <div class={styles.sectionPrice}>
- <p class={styles.price}>
- 团购价:
- <span class={styles.numFont}>
- <span class={styles.numPrefix}>¥ </span>
- {moneyFormat(state.goodsInfo.currentPrice)}
- </span>
- </p>
- <p class={styles.originPrice}>
- 原价:
- <del class={styles.numFont}>
- ¥ {moneyFormat(state.goodsInfo.originalPrice)}
- </del>
- </p>
- </div>
- </div>
- )
- }}
- </Cell>
- {/* <Cell center class={styles.gives}>
- {{
- title: () => (
- <div class={styles.sectionTips}>
- <Image src={iconGives} class={styles.iconGives} />
- 赠价值{state.repaireInfo.originalPrice}元乐器维保服务一年
- </div>
- )
- }}
- </Cell> */}
- </CellGroup>
- </>
- )}
- {/* 判断是否已经购买教材 */}
- {!state.paymentOrderDetails.includes('TEXTBOOK') && (
- <>
- {/* <div class={styles.applyTitle}>教材</div> */}
- <CellGroup
- inset
- class={[styles.mlr13, styles.sectionCell]}
- onClick={() => {
- return
- // onSelect(state.textBookInfo.goodsId)
- }}
- >
- <Cell border={false}>
- {{
- icon: () => (
- <Checkbox
- name={state.textBookInfo.goodsId}
- disabled
- class={styles.checkbox}
- ref={(el: any) => (state.checkboxRefs[state.textBookInfo.goodsId] = el)}
- onClick={(e: Event) => {
- e.stopPropagation()
- }}
- v-slots={{
- icon: (props: any) => (
- <Icon
- class={styles.iconChecked}
- name={props.checked ? radioCheck : radioDefault}
- />
- )
- }}
- />
- ),
- title: () => (
- <div class={styles.section}>
- <Image
- class={styles.img}
- src={state.textBookInfo.goodsUrl}
- onClick={(e: any) => {
- e.stopPropagation()
- state.selectGoodsId = state.textBookInfo.goodsId
- state.currentPrice = state.textBookInfo.currentPrice
- state.selectGoodsInfo = {}
- state.goodsStatus = true
- }}
- />
- <div class={styles.sectionContent}>
- <h2
- onClick={(e: any) => {
- e.stopPropagation()
- state.selectGoodsId = state.textBookInfo.goodsId
- state.currentPrice = state.textBookInfo.currentPrice
- state.selectGoodsInfo = {}
- state.goodsStatus = true
- }}
- >
- {state.textBookInfo.goodsName}
- </h2>
- <Tag
- color="linear-gradient(135deg, #FF8C4A 0%, #FF531C 100%)"
- textColor="#fff"
- class={styles.brandName}
- >
- {state.textBookInfo.brandName}
- </Tag>
- <p class={[styles.model, 'van-multi-ellipsis--l2']}>
- {state.textBookInfo.description}
- </p>
- </div>
- </div>
- )
- }}
- </Cell>
- <Cell>
- {{
- title: () => (
- <div class={styles.extra}>
- <div class={styles.sectionPrice}>
- <p class={styles.price}>
- 团购价:
- <span
- class={[
- state.textBookInfo.currentPrice > 0 ? styles.numFont : styles.free
- ]}
- >
- {state.textBookInfo.currentPrice > 0 ? (
- <>
- <span class={styles.numPrefix}>¥ </span>
- {moneyFormat(state.textBookInfo.currentPrice)}
- </>
- ) : (
- '免费'
- )}
- </span>
- </p>
- <p class={styles.originPrice}>
- 原价:
- <del class={styles.numFont}>
- ¥ {moneyFormat(state.textBookInfo.originalPrice)}
- </del>
- </p>
- </div>
- </div>
- )
- }}
- </Cell>
- </CellGroup>
- </>
- )}
- </CheckboxGroup>
- <OSticky position="bottom" background="white">
- <div class={styles.paymentContainer}>
- <div class={styles.payemntPrice}>
- <p class={styles.needPrice}>
- 支付金额:
- <span class={styles.numFont}>
- <span>¥ </span>
- <i style="font-style: normal" id="needPrice"></i>
- </span>
- </p>
- <p class={styles.allPrice}>
- <del class={styles.numFont}>
- 总原价:¥ {moneyFormat(state.orderInfo.originalPrice)}
- </del>
- </p>
- </div>
- <div class={styles.paymentBtn}>
- <Button
- color="linear-gradient(135deg, #FF8C4A 0%, #FF531C 100%)"
- round
- onClick={onSubmit}
- >
- 立即提交
- </Button>
- </div>
- </div>
- </OSticky>
- <OPopup v-model:modelValue={state.memberBaoStatus} position="right">
- <MemberBao />
- </OPopup>
- <OPopup v-model:modelValue={state.goodsStatus} position="right" destroy>
- {state.goodsStatus && (
- <GoodsDetail
- id={state.selectGoodsId}
- groupPrice={state.currentPrice}
- goodsInfo={state.selectGoodsInfo}
- />
- )}
- </OPopup>
- <ODialog
- title="提示"
- v-model:show={state.dialogStatus}
- message={state.dialogMessage}
- confirmButtonText={state.dialogOrchestraStatus ? '确认取消' : '继续支付'}
- cancelButtonText="取消订单"
- showCancelButton={!state.dialogOrchestraStatus}
- messageAlign={state.dialogOrchestraStatus ? 'left' : 'center'}
- onConfirm={async () => {
- if (state.dialogOrchestraStatus) {
- try {
- await request.post(
- '/api-student/userPaymentOrder/cancelPayment/' + state.dialogConfig.orderNo
- )
- } catch {
- //
- }
- } else {
- const paymentConfig = state.dialogConfig.paymentConfig
- router.push({
- path: '/orderDetail',
- query: {
- pm: 1, // h5乐团报名
- config: JSON.stringify({
- ...paymentConfig.paymentConfig,
- paymentType: paymentConfig.paymentType
- }),
- orderNo: paymentConfig.orderNo
- }
- })
- }
- }}
- onCancel={async () => {
- try {
- await request.post(
- '/api-student/userPaymentOrder/cancelPayment/' + state.dialogConfig.orderNo
- )
- } catch {
- //
- }
- }}
- />
- </>
- )
- }
- })
|