index.tsx 9.0 KB

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