index.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 { goWechatAuth, setLogout } from '@/state'
  10. import request from '@/helpers/request'
  11. import { browser, getUrlCode } from '@/helpers/utils'
  12. import ODialog from '@/components/o-dialog'
  13. export default defineComponent({
  14. name: 'pre-apply',
  15. setup() {
  16. const route = useRoute()
  17. const router = useRouter()
  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. dialogStatus: false,
  27. dialogMessage: '',
  28. // 是否开启微信登录(测试使用)默认为false
  29. testIsWeixin: false
  30. })
  31. const onNext = async (name: string) => {
  32. if (name === 'payment') {
  33. await getRegisterStatus()
  34. }
  35. nextTick(() => {
  36. state.tabValue = name
  37. window.scrollTo(0, 0)
  38. })
  39. }
  40. const getRegisterStatus = async () => {
  41. try {
  42. const { data } = await request.get(
  43. '/api-student/orchestraRegister/registerStatus/' + route.query.id
  44. )
  45. state.registerInfo = data || {}
  46. if (data.registerStatus === 'OUTOF_ORCHESTRA') {
  47. nextTick(() => {
  48. state.tabValue = 'apply'
  49. })
  50. } else {
  51. // 判断是否报名注册过
  52. state.register = data.register
  53. if (data.register) {
  54. nextTick(() => {
  55. state.tabValue = 'payment'
  56. })
  57. }
  58. // 购买状态, 判断是否已经购买完了
  59. if (data.purchase) {
  60. state.purchase = data.purchase
  61. nextTick(() => {
  62. state.tabValue = 'order'
  63. })
  64. }
  65. }
  66. // INITIATION_SURVEY: '启蒙调查',
  67. // PRE_REGISTER: '预报名',
  68. // REGISTER: '乐团报名',
  69. // DOING: '乐团交付',
  70. // DONE: '已交付'
  71. // CLOSE: '已交付'
  72. // 判断乐团报名,只有 乐团报名 乐团交付 已交付才可以报名
  73. const oStatus = data.status // 乐团状态
  74. if (oStatus !== 'REGISTER' && oStatus !== 'DOING' && oStatus !== 'DONE') {
  75. // showDialog({
  76. // title: '提示',
  77. // message: '乐团建设中,请稍等'
  78. // }).then(() => {
  79. // setLogout()
  80. // const query = {
  81. // returnUrl: route.path,
  82. // ...route.query
  83. // } as any
  84. // router.replace({
  85. // path: '/loginMusic',
  86. // query: query
  87. // })
  88. // })
  89. state.dialogMessage = '乐团建设中,请稍等'
  90. state.dialogStatus = true
  91. return
  92. }
  93. // 判断乐团
  94. if (data.registerOrchestra >= 1) {
  95. // showDialog({
  96. // title: '提示',
  97. // message: '您已在其它乐团'
  98. // }).then(() => {
  99. // setLogout()
  100. // const query = {
  101. // returnUrl: route.path,
  102. // ...route.query
  103. // } as any
  104. // router.replace({
  105. // path: '/loginMusic',
  106. // query: query
  107. // })
  108. // })
  109. state.dialogMessage = '您已在其它乐团'
  110. state.dialogStatus = true
  111. return
  112. }
  113. // 判断是否有openId 并且 purchase
  114. // if (!data.openId && !data.purchase) {
  115. // if (browser().weixin) {
  116. // // 微信公众号支付
  117. // //授权
  118. // const code = getUrlCode()
  119. // if (!code) {
  120. // goAuth(data.wxAppId)
  121. // } else {
  122. // state.code = code
  123. // }
  124. // }
  125. // }
  126. // nextTick(() => {
  127. // state.tabValue = 'order'
  128. // })
  129. } catch {
  130. //
  131. }
  132. }
  133. const getRegisterInfo = async (val: string) => {
  134. // 重新查询状态
  135. if (val === 'apply') {
  136. try {
  137. const { data } = await request.get(
  138. '/api-student/orchestraRegister/registerStatus/' + route.query.id
  139. )
  140. state.registerInfo = data || {}
  141. } catch {
  142. //
  143. }
  144. }
  145. // document.getElementById('app')?.scrollTo(0, 0)
  146. window.scrollTo(0, 0)
  147. }
  148. // const goAuth = (wxAppId: string) => {
  149. // // 用户授权
  150. // const urlNow = encodeURIComponent(window.location.href)
  151. // const scope = 'snsapi_base' //snsapi_userinfo //静默授权 用户无感知
  152. // const appid = wxAppId || 'wx8654c671631cfade'
  153. // 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`
  154. // window.location.replace(url)
  155. // }
  156. const getAppIdAndCode = async () => {
  157. try {
  158. const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
  159. // 判断是否有微信appId
  160. if (data) {
  161. // goAuth(data)
  162. goWechatAuth(data)
  163. }
  164. } catch {
  165. //
  166. }
  167. }
  168. // 先请求接口 判断是否有code
  169. if (state.testIsWeixin) {
  170. getRegisterStatus()
  171. } else {
  172. if (browser().weixin) {
  173. // 微信公众号支付
  174. //授权
  175. const code = getUrlCode()
  176. if (!code) {
  177. getAppIdAndCode()
  178. } else {
  179. state.code = code
  180. getRegisterStatus()
  181. }
  182. } else {
  183. setLogout()
  184. const query = {
  185. returnUrl: route.path,
  186. ...route.query
  187. } as any
  188. router.replace({
  189. path: '/loginMusic',
  190. query: query
  191. })
  192. }
  193. }
  194. return () => (
  195. <div class={styles.preApply}>
  196. <div class={styles.banner}>
  197. <p class={styles.orchestraName}>{state.registerInfo.orchestraName}</p>
  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. <ODialog
  236. title="提示"
  237. v-model:show={state.dialogStatus}
  238. message={state.dialogMessage}
  239. confirmButtonText="确定"
  240. onConfirm={() => {
  241. setLogout()
  242. const query = {
  243. returnUrl: route.path,
  244. ...route.query
  245. } as any
  246. router.replace({
  247. path: '/loginMusic',
  248. query: query
  249. })
  250. }}
  251. />
  252. </div>
  253. )
  254. }
  255. })