index.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. const name = data.orchestraName
  42. // const name = '华中科技大学大学同济医学院附'
  43. // console.log(name.length)
  44. if (name.length > 12 && name.length / 12 > 1 && name.length / 12 <= 2) {
  45. const len = name.substring(12, 24)
  46. if (len.length < 5) {
  47. const splitLen = Math.ceil(name.length / 2)
  48. const first = name.substring(0, splitLen)
  49. const last = name.substring(splitLen, name.length)
  50. state.registerInfo.orchestraName = first + '<br />' + last
  51. } else {
  52. state.registerInfo.orchestraName = name
  53. }
  54. }
  55. // 判断是否报名注册过
  56. state.register = data.register
  57. if (data.register) {
  58. nextTick(() => {
  59. state.tabValue = 'payment'
  60. })
  61. }
  62. // 购买状态, 判断是否已经购买完了
  63. if (data.purchase) {
  64. state.purchase = data.purchase
  65. nextTick(() => {
  66. state.tabValue = 'order'
  67. })
  68. }
  69. // INITIATION_SURVEY: '启蒙调查',
  70. // PRE_REGISTER: '预报名',
  71. // REGISTER: '乐团报名',
  72. // DOING: '乐团交付',
  73. // DONE: '已交付'
  74. // CLOSE: '已交付'
  75. // 判断乐团报名,只有 乐团报名 乐团交付 已交付才可以报名
  76. const oStatus = data.status // 乐团状态
  77. if (oStatus !== 'REGISTER' && oStatus !== 'DOING' && oStatus !== 'DONE') {
  78. showDialog({
  79. title: '提示',
  80. message: '乐团建设中,请稍等'
  81. }).then(() => {
  82. setLogout()
  83. const query = {
  84. returnUrl: route.path,
  85. ...route.query
  86. } as any
  87. router.replace({
  88. path: '/loginMusic',
  89. query: query
  90. })
  91. })
  92. return
  93. }
  94. // 判断乐团
  95. if (data.registerOrchestra >= 1) {
  96. showDialog({
  97. title: '提示',
  98. message: '您已在其它乐团'
  99. }).then(() => {
  100. setLogout()
  101. const query = {
  102. returnUrl: route.path,
  103. ...route.query
  104. } as any
  105. router.replace({
  106. path: '/loginMusic',
  107. query: query
  108. })
  109. })
  110. return
  111. }
  112. // 判断是否有openId 并且 purchase
  113. if (!data.openId && !data.purchase) {
  114. if (browser().weixin) {
  115. // 微信公众号支付
  116. //授权
  117. const code = getUrlCode()
  118. if (!code) {
  119. goAuth(data.wxAppId)
  120. } else {
  121. state.code = code
  122. }
  123. }
  124. }
  125. } catch {
  126. //
  127. }
  128. }
  129. const getRegisterInfo = async (val: string) => {
  130. // 重新查询状态
  131. if (val === 'apply') {
  132. try {
  133. const { data } = await request.get(
  134. '/api-student/orchestraRegister/registerStatus/' + route.query.id
  135. )
  136. state.registerInfo = data || {}
  137. } catch {
  138. //
  139. }
  140. }
  141. }
  142. const goAuth = (wxAppId: string) => {
  143. // 用户授权
  144. const urlNow = encodeURIComponent(window.location.href)
  145. const scope = 'snsapi_base' //snsapi_userinfo //静默授权 用户无感知
  146. const appid = wxAppId || 'wx8654c671631cfade'
  147. 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`
  148. window.location.replace(url)
  149. }
  150. const getAppIdAndCode = async () => {
  151. try {
  152. const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
  153. // 判断是否有微信appId
  154. if (data) {
  155. goAuth(data)
  156. }
  157. } catch {
  158. //
  159. }
  160. }
  161. // 先请求接口 判断是否有code
  162. if (browser().weixin) {
  163. // 微信公众号支付
  164. //授权
  165. const code = getUrlCode()
  166. if (!code) {
  167. getAppIdAndCode()
  168. } else {
  169. state.code = code
  170. getRegisterStatus()
  171. }
  172. }
  173. // onMounted(() => {
  174. // state.code = route.query.code || ''
  175. // const { height } = useRect(bannerRef.value)
  176. // state.heightV = height
  177. // 判断是否是微信,只能微信中打开
  178. // if (browser().weixin) {
  179. // // 微信公众号支付
  180. // //授权
  181. // const code = getUrlCode()
  182. // if (!code || !state.code) {
  183. // getAppIdAndCode()
  184. // } else {
  185. // state.code = code
  186. // }
  187. // }
  188. // })
  189. return () => (
  190. <div class={styles.preApply}>
  191. <div class={styles.banner} ref={bannerRef}>
  192. {state.registerInfo.orchestraName && (
  193. <>
  194. <p class={styles.orchestraName} v-html={state.registerInfo.orchestraName}></p>
  195. <div class={styles.tips}>快来参加乐团报名吧!</div>
  196. </>
  197. )}
  198. </div>
  199. <Sticky position="top">
  200. <Tabs
  201. lineWidth={20}
  202. lineHeight={4}
  203. v-model:active={state.tabValue}
  204. onChange={(val: any) => getRegisterInfo(val)}
  205. >
  206. <Tab title="报名信息" name="apply" disabled={state.purchase}></Tab>
  207. <Tab title="缴费信息" name="payment" disabled={state.purchase || !state.register}></Tab>
  208. <Tab title="我的订单" name="order" disabled={!state.register}></Tab>
  209. </Tabs>
  210. </Sticky>
  211. {state.tabValue === 'apply' && (
  212. <Apply
  213. onNext={onNext}
  214. code={state.code}
  215. registerInfo={state.registerInfo}
  216. schoolSystem={state.registerInfo.schoolSystem}
  217. />
  218. )}
  219. {state.tabValue === 'payment' && <Payment onNext={onNext} />}
  220. {state.tabValue === 'order' && <Order onNext={onNext} />}
  221. {/* <Popup
  222. v-model:show={state.showPopup}
  223. round
  224. style={{ width: '92%' }}
  225. closeOnClickOverlay={false}
  226. >
  227. <div class={styles.popupContainer}>
  228. <div class={styles.dialogTitle}>
  229. <i></i>
  230. 提示
  231. </div>
  232. <p class={styles.popupTips}>请使用微信打开</p>
  233. </div>
  234. </Popup> */}
  235. </div>
  236. )
  237. }
  238. })