index.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { defineComponent, onMounted, reactive, ref, nextTick } from 'vue'
  2. import { Image, Popup, showDialog, Sticky, Tab, Tabs } from 'vant'
  3. import styles from './index.module.less'
  4. // import { useRect } from '@vant/use'
  5. import Apply from './component/apply'
  6. import Payment from './component/payment'
  7. import Order from './component/order'
  8. import { useRoute, useRouter } from 'vue-router'
  9. import { setLogout } from '@/state'
  10. import request from '@/helpers/request'
  11. import { browser, getUrlCode } from '@/helpers/utils'
  12. export default defineComponent({
  13. name: 'pre-apply',
  14. setup() {
  15. const route = useRoute()
  16. const router = useRouter()
  17. const bannerRef = ref()
  18. const state = reactive({
  19. tabValue: 'apply',
  20. heightV: 235,
  21. registerInfo: {} as any,
  22. purchase: false, // 购买状态
  23. register: true, // 是否注册
  24. // showPopup: false,
  25. code: '' as any
  26. })
  27. const onNext = async (name: string) => {
  28. if (name === 'payment') {
  29. await getRegisterStatus()
  30. }
  31. nextTick(() => {
  32. state.tabValue = name
  33. })
  34. }
  35. const getRegisterStatus = async () => {
  36. try {
  37. const { data } = await request.get(
  38. '/api-student/orchestraRegister/registerStatus/' + route.query.id
  39. )
  40. state.registerInfo = data || {}
  41. // 判断是否报名注册过
  42. state.register = data.register
  43. if (data.register) {
  44. nextTick(() => {
  45. state.tabValue = 'payment'
  46. })
  47. }
  48. // 购买状态, 判断是否已经购买完了
  49. if (data.purchase) {
  50. state.purchase = data.purchase
  51. nextTick(() => {
  52. state.tabValue = 'order'
  53. })
  54. }
  55. // INITIATION_SURVEY: '启蒙调查',
  56. // PRE_REGISTER: '预报名',
  57. // REGISTER: '乐团报名',
  58. // DOING: '乐团交付',
  59. // DONE: '已交付'
  60. // CLOSE: '已交付'
  61. // 判断乐团报名,只有 乐团报名 乐团交付 已交付才可以报名
  62. const oStatus = data.status // 乐团状态
  63. if (oStatus !== 'REGISTER' && oStatus !== 'DOING' && oStatus !== 'DONE') {
  64. showDialog({
  65. title: '提示',
  66. message: '乐团建设中,请稍等'
  67. }).then(() => {
  68. setLogout()
  69. const query = {
  70. returnUrl: route.path,
  71. ...route.query
  72. } as any
  73. router.replace({
  74. path: '/loginMusic',
  75. query: query
  76. })
  77. })
  78. return
  79. }
  80. // 判断乐团
  81. if (data.registerOrchestra >= 1) {
  82. showDialog({
  83. title: '提示',
  84. message: '您已在其它乐团'
  85. }).then(() => {
  86. setLogout()
  87. const query = {
  88. returnUrl: route.path,
  89. ...route.query
  90. } as any
  91. router.replace({
  92. path: '/loginMusic',
  93. query: query
  94. })
  95. })
  96. return
  97. }
  98. // 判断是否有openId 并且 purchase
  99. if (!data.openId && !data.purchase) {
  100. if (browser().weixin) {
  101. // 微信公众号支付
  102. //授权
  103. const code = getUrlCode()
  104. if (!code || !state.code) {
  105. goAuth(data.wxAppId)
  106. } else {
  107. state.code = code
  108. }
  109. }
  110. }
  111. } catch {
  112. //
  113. }
  114. }
  115. const getRegisterInfo = async (val: string) => {
  116. // 重新查询状态
  117. if (val === 'apply') {
  118. try {
  119. const { data } = await request.get(
  120. '/api-student/orchestraRegister/registerStatus/' + route.query.id
  121. )
  122. state.registerInfo = data || {}
  123. } catch {
  124. //
  125. }
  126. }
  127. }
  128. const goAuth = (wxAppId: string) => {
  129. // 用户授权
  130. const urlNow = encodeURIComponent(window.location.href)
  131. const scope = 'snsapi_base' //snsapi_userinfo //静默授权 用户无感知
  132. const appid = wxAppId || 'wx8654c671631cfade'
  133. const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
  134. window.location.replace(url)
  135. }
  136. const getAppIdAndCode = async () => {
  137. try {
  138. const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
  139. // 判断是否有微信appId
  140. if (data) {
  141. goAuth(data)
  142. }
  143. } catch {
  144. //
  145. }
  146. }
  147. // 先请求接口
  148. getRegisterStatus()
  149. onMounted(() => {
  150. // state.code = route.query.code || ''
  151. // const { height } = useRect(bannerRef.value)
  152. // state.heightV = height
  153. // 判断是否是微信,只能微信中打开
  154. // if (browser().weixin) {
  155. // // 微信公众号支付
  156. // //授权
  157. // const code = getUrlCode()
  158. // if (!code || !state.code) {
  159. // getAppIdAndCode()
  160. // } else {
  161. // state.code = code
  162. // }
  163. // }
  164. })
  165. return () => (
  166. <div class={styles.preApply}>
  167. <div class={styles.banner} ref={bannerRef}>
  168. <span>
  169. {state.registerInfo.orchestraName} <br />
  170. 乐团报名
  171. </span>
  172. </div>
  173. <Sticky position="top">
  174. <Tabs
  175. lineWidth={20}
  176. lineHeight={4}
  177. v-model:active={state.tabValue}
  178. onChange={(val: any) => getRegisterInfo(val)}
  179. >
  180. <Tab title="报名信息" name="apply" disabled={state.purchase}></Tab>
  181. <Tab title="缴费信息" name="payment" disabled={state.purchase || !state.register}></Tab>
  182. <Tab title="我的订单" name="order" disabled={!state.register}></Tab>
  183. </Tabs>
  184. </Sticky>
  185. {state.tabValue === 'apply' && (
  186. <Apply
  187. onNext={onNext}
  188. code={state.code}
  189. registerInfo={state.registerInfo}
  190. schoolSystem={state.registerInfo.schoolSystem}
  191. />
  192. )}
  193. {state.tabValue === 'payment' && <Payment onNext={onNext} />}
  194. {state.tabValue === 'order' && <Order onNext={onNext} />}
  195. {/* <Popup
  196. v-model:show={state.showPopup}
  197. round
  198. style={{ width: '92%' }}
  199. closeOnClickOverlay={false}
  200. >
  201. <div class={styles.popupContainer}>
  202. <div class={styles.dialogTitle}>
  203. <i></i>
  204. 提示
  205. </div>
  206. <p class={styles.popupTips}>请使用微信打开</p>
  207. </div>
  208. </Popup> */}
  209. </div>
  210. )
  211. }
  212. })