index.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 showPopup = ref(false)
  32. const noPaymentList = ref([
  33. '1656572729093021697',
  34. '1656488025144713217',
  35. '1661221287237820418',
  36. '1661222465069686785'
  37. ])
  38. console.log(
  39. '提示乐团报名失败',
  40. route.query.id,
  41. noPaymentList.value.indexOf(route.query.id as string)
  42. )
  43. if (route.query.id && noPaymentList.value.indexOf(route.query.id as string) != -1) {
  44. console.log('提示乐团报名失败')
  45. // 提示乐团报名失败
  46. showPopup.value = true
  47. }
  48. const onNext = async (name: string) => {
  49. if (name === 'payment') {
  50. await getRegisterStatus()
  51. }
  52. nextTick(() => {
  53. state.tabValue = name
  54. window.scrollTo(0, 0)
  55. })
  56. }
  57. const getRegisterStatus = async () => {
  58. try {
  59. const { data } = await request.get(
  60. '/api-student/orchestraRegister/registerStatus/' + route.query.id
  61. )
  62. state.registerInfo = data || {}
  63. if (data.registerStatus === 'OUTOF_ORCHESTRA') {
  64. nextTick(() => {
  65. state.tabValue = 'apply'
  66. })
  67. } else {
  68. // 判断是否报名注册过
  69. state.register = data.register
  70. if (data.register) {
  71. nextTick(() => {
  72. state.tabValue = 'payment'
  73. })
  74. }
  75. // 购买状态, 判断是否已经购买完了
  76. if (data.purchase) {
  77. state.purchase = data.purchase
  78. nextTick(() => {
  79. state.tabValue = 'order'
  80. })
  81. }
  82. }
  83. // INITIATION_SURVEY: '启蒙调查',
  84. // PRE_REGISTER: '预报名',
  85. // REGISTER: '乐团报名',
  86. // PARENT_TEACHER_REGISTRATION "家长会报名"
  87. // DOING: '乐团交付',
  88. // DONE: '已交付'
  89. // CLOSE: '已交付'
  90. // 判断乐团报名,只有 乐团报名 乐团交付 已交付才可以报名
  91. const oStatus = data.status // 乐团状态
  92. if (
  93. oStatus !== 'REGISTER' &&
  94. oStatus !== 'DOING' &&
  95. oStatus !== 'DONE' &&
  96. oStatus !== 'PARENT_TEACHER_REGISTRATION'
  97. ) {
  98. state.dialogMessage = '乐团建设中,请稍等'
  99. state.dialogStatus = true
  100. return
  101. }
  102. // 判断乐团
  103. if (data.registerOrchestra >= 1) {
  104. state.dialogMessage = '您已在其它乐团'
  105. state.dialogStatus = true
  106. return
  107. }
  108. // 判断是否有openId 并且 purchase
  109. // if (!data.openId && !data.purchase) {
  110. // if (browser().weixin) {
  111. // // 微信公众号支付
  112. // //授权
  113. // const code = getUrlCode()
  114. // if (!code) {
  115. // goAuth(data.wxAppId)
  116. // } else {
  117. // state.code = code
  118. // }
  119. // }
  120. // }
  121. // nextTick(() => {
  122. // state.tabValue = 'order'
  123. // })
  124. } catch {
  125. //
  126. }
  127. }
  128. const getRegisterInfo = async (val: string) => {
  129. // 重新查询状态
  130. if (val === 'apply') {
  131. try {
  132. const { data } = await request.get(
  133. '/api-student/orchestraRegister/registerStatus/' + route.query.id
  134. )
  135. state.registerInfo = data || {}
  136. } catch {
  137. //
  138. }
  139. }
  140. // document.getElementById('app')?.scrollTo(0, 0)
  141. window.scrollTo(0, 0)
  142. }
  143. // const goAuth = (wxAppId: string) => {
  144. // // 用户授权
  145. // const urlNow = encodeURIComponent(window.location.href)
  146. // const scope = 'snsapi_base' //snsapi_userinfo //静默授权 用户无感知
  147. // const appid = wxAppId || 'wx8654c671631cfade'
  148. // 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`
  149. // window.location.replace(url)
  150. // }
  151. const getAppIdAndCode = async () => {
  152. try {
  153. const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
  154. // 判断是否有微信appId
  155. if (data) {
  156. // goAuth(data)
  157. goWechatAuth(data)
  158. }
  159. } catch {
  160. //
  161. }
  162. }
  163. // 先请求接口 判断是否有code
  164. if (state.testIsWeixin) {
  165. getRegisterStatus()
  166. } else {
  167. if (browser().weixin) {
  168. // 微信公众号支付
  169. //授权
  170. const code = getUrlCode()
  171. if (!code) {
  172. getAppIdAndCode()
  173. } else {
  174. state.code = code
  175. getRegisterStatus()
  176. }
  177. } else {
  178. setLogout()
  179. const query = {
  180. returnUrl: route.path,
  181. ...route.query
  182. } as any
  183. router.replace({
  184. path: '/loginMusic',
  185. query: query
  186. })
  187. }
  188. }
  189. return () => (
  190. <div class={styles.preApply}>
  191. <div class={styles.banner}>
  192. <p class={styles.orchestraName}>{state.registerInfo.orchestraName}</p>
  193. </div>
  194. <Sticky position="top">
  195. <Tabs
  196. lineWidth={20}
  197. lineHeight={4}
  198. v-model:active={state.tabValue}
  199. onChange={(val: any) => getRegisterInfo(val)}
  200. >
  201. <Tab title="基础信息" name="apply" disabled={state.purchase}></Tab>
  202. <Tab title="工具准备" name="payment" disabled={state.purchase || !state.register}></Tab>
  203. <Tab title="完成报名" name="order" disabled={!state.register}></Tab>
  204. </Tabs>
  205. </Sticky>
  206. {state.tabValue === 'apply' && (
  207. <Apply
  208. onNext={onNext}
  209. code={state.code}
  210. registerInfo={state.registerInfo}
  211. schoolSystem={state.registerInfo.schoolSystem}
  212. />
  213. )}
  214. {state.tabValue === 'payment' && <Payment onNext={onNext} />}
  215. {state.tabValue === 'order' && <Order onNext={onNext} />}
  216. {/* <Popup
  217. v-model:show={state.showPopup}
  218. round
  219. style={{ width: '92%' }}
  220. closeOnClickOverlay={false}
  221. >
  222. <div class={styles.popupContainer}>
  223. <div class={styles.dialogTitle}>
  224. <i></i>
  225. 提示
  226. </div>
  227. <p class={styles.popupTips}>请使用微信打开</p>
  228. </div>
  229. </Popup> */}
  230. <ODialog
  231. title="提示"
  232. v-model:show={state.dialogStatus}
  233. message={state.dialogMessage}
  234. confirmButtonText="确定"
  235. onConfirm={() => {
  236. setLogout()
  237. const query = {
  238. returnUrl: route.path,
  239. ...route.query
  240. } as any
  241. router.replace({
  242. path: '/loginMusic',
  243. query: query
  244. })
  245. }}
  246. />
  247. <Popup
  248. v-model:show={showPopup.value}
  249. round
  250. style={{ width: '88%', marginTop: '-6vh' }}
  251. closeOnClickOverlay={false}
  252. class={styles.wxPopupDialog}
  253. >
  254. <div class={styles.popupContainer}>
  255. <p class={styles.title1}>温馨提示</p>
  256. <p class={styles.popupTips}>乐团报名时间已过,请等待通知</p>
  257. </div>
  258. </Popup>
  259. </div>
  260. )
  261. }
  262. })