club-register.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div class="page">
  3. <div class="page-top"></div>
  4. <div class="page-content" v-if="!isRequest">
  5. <template>
  6. <!-- 进步条 -->
  7. <SimpleStep :list="stepList" :active="step" v-if="showStepBar" />
  8. <div class="step-list py-4">
  9. <!-- 账号注册表单 -->
  10. <keep-alive>
  11. <FormClubRegister
  12. v-if="step === 1"
  13. ref="userForm"
  14. @step="onUserFormStep"
  15. />
  16. </keep-alive>
  17. <!-- 机构认证表单 -->
  18. <keep-alive>
  19. <FormClubInfo
  20. v-if="step === 2 && registerType.indexOf(2) !== -1"
  21. ref="clubInfoForm"
  22. @step="onClubInfoFormStep"
  23. />
  24. </keep-alive>
  25. <!-- 设备认证表单 -->
  26. <keep-alive>
  27. <FormClubDevice
  28. v-if="step === 3"
  29. ref="clubDeviceForm"
  30. @step="onclubDeviceFormStep"
  31. />
  32. </keep-alive>
  33. </div>
  34. </template>
  35. <!-- 机构已认证 || 机构认证中 || 机构认证失败 -->
  36. <template v-if="step === 2 && registerType.indexOf(2) === -1">
  37. <div class="message">
  38. <div class="status-icon" :class="autidStatusClass"></div>
  39. <div class="status">
  40. <span v-if="autidStatus === 0">机构认证失败</span>
  41. <span v-if="autidStatus === 1">机构认证成功</span>
  42. <span v-if="autidStatus === 2">机构认证中</span>
  43. </div>
  44. <div class="tip">提示:可点击认证记录看查看详情</div>
  45. </div>
  46. </template>
  47. <!-- 操作 -->
  48. <div class="control flex flex-col items-center">
  49. <div
  50. class="button next flex justify-center items-center mb-2"
  51. @click="onNextStep"
  52. >
  53. {{ step === 3 ? '提交' : '下一步' }}
  54. </div>
  55. <div
  56. class="button prev flex justify-center items-center"
  57. @click="onPrevStep"
  58. v-if="showPreButton"
  59. >
  60. 上一步
  61. </div>
  62. <div class="record mt-2" @click="toRecord">认证记录</div>
  63. </div>
  64. </div>
  65. <SimpleDialog
  66. v-model="active"
  67. @confirm="onConfirm"
  68. :cancel="false"
  69. description="抱歉,该用户已进行过正品授权申请"
  70. :center="true"
  71. />
  72. </div>
  73. </template>
  74. <script>
  75. import SimpleStep from '@/components/SimpleStep'
  76. import FormClubRegister from './components/form-club-register.vue'
  77. import FormClubInfo from './components/form-club-info.vue'
  78. import FormClubDevice from './components/form-club-device.vue'
  79. import { mapGetters } from 'vuex'
  80. export default {
  81. layout: 'app-hyt',
  82. components: {
  83. SimpleStep,
  84. FormClubRegister,
  85. FormClubInfo,
  86. FormClubDevice,
  87. },
  88. data() {
  89. return {
  90. isRequest: true,
  91. active: false,
  92. isSubmit: false,
  93. registerType: [3],
  94. step: 1,
  95. stepList: [
  96. {
  97. label: '账号注册',
  98. id: 1,
  99. recordRoute: '/record/club/detail',
  100. },
  101. {
  102. label: '机构认证',
  103. id: 2,
  104. recordRoute: '/record/club/detail',
  105. auditStatus: '',
  106. },
  107. {
  108. label: '设备认证',
  109. id: 3,
  110. recordRoute: '/record/device',
  111. auditStatus: '',
  112. },
  113. ],
  114. // 机构用户信息
  115. clubUserInfo: {},
  116. // 机构授权信息
  117. authInfo: {},
  118. // 机构认证设备列表信息
  119. productInfo: [],
  120. // 机构授权id
  121. authId: '',
  122. autidStatus: 0,
  123. }
  124. },
  125. computed: {
  126. ...mapGetters([
  127. 'supplierInfo',
  128. 'authUserId',
  129. 'routePrefix',
  130. 'accessToken',
  131. 'userInfo',
  132. 'clubUserId',
  133. ]),
  134. autidStatusClass() {
  135. if (this.autidStatus === 0) return 'danger'
  136. if (this.autidStatus === 1) return 'success'
  137. if (this.autidStatus === 2) return 'warning'
  138. },
  139. showStepBar() {
  140. if (this.step === 2) {
  141. if (this.registerType.indexOf(2) > -1) {
  142. return true
  143. } else {
  144. return false
  145. }
  146. }
  147. return true
  148. },
  149. showPreButton() {
  150. if (this.step === 1) return false
  151. if (this.step === 2) {
  152. if (this.registerType.indexOf(1) > -1) {
  153. return true
  154. } else {
  155. return false
  156. }
  157. }
  158. return true
  159. },
  160. },
  161. created() {
  162. this.authId = this.$route.query.authId || ''
  163. this.isRequest = true
  164. this.initPageForm()
  165. },
  166. beforeDestroy() {
  167. this.$toast.clear()
  168. this.isSubmit = false
  169. },
  170. methods: {
  171. onConfirm() {
  172. this.$router.push(this.routePrefix)
  173. },
  174. async onNextStep() {
  175. const validateAction = {
  176. 1: this.$refs.userForm?.validate,
  177. 2: this.$refs.clubInfoForm?.validate,
  178. 3: this.$refs.clubDeviceForm?.validate,
  179. }
  180. try {
  181. // 表单校验
  182. validateAction[this.step] && (await validateAction[this.step]())
  183. // 提交
  184. if (this.step === 3) {
  185. this.onSubmit()
  186. }
  187. // 下一步
  188. if (this.step < 3) {
  189. this.step++
  190. }
  191. } catch (error) {
  192. console.log(error)
  193. }
  194. console.log('userForm', this.clubUserInfo)
  195. },
  196. onPrevStep() {
  197. this.step > 1 && this.step--
  198. },
  199. async onSubmit() {
  200. this.$toast.loading({
  201. message: '正在提交注册信息,请勿操作...',
  202. duration: 0,
  203. })
  204. if (this.isSubmit) return
  205. this.isSubmit = true
  206. const params = {
  207. registerType: this.registerType.join(','),
  208. authUserId: this.authUserId,
  209. authId: this.authId,
  210. clubUserId: this.clubUserId,
  211. clubUserInfo: this.clubUserInfo,
  212. authInfo: this.authInfo,
  213. productInfo: this.productInfo,
  214. }
  215. console.log(params)
  216. try {
  217. const res = await this.$http.api.clubUserRegisterAll(params)
  218. console.log(res)
  219. this.$router.push(`${this.routePrefix}/record/message`)
  220. } catch (error) {
  221. console.log(error)
  222. this.$toast(error.msg)
  223. } finally {
  224. this.$toast.clear()
  225. this.isSubmit = false
  226. }
  227. },
  228. onUserFormStep(data) {
  229. console.log(data)
  230. this.clubUserInfo = data
  231. },
  232. onClubInfoFormStep(data) {
  233. console.log(data)
  234. this.authInfo = data
  235. },
  236. onclubDeviceFormStep(data) {
  237. console.log(data)
  238. this.productInfo = data
  239. },
  240. toRecord() {
  241. if (!this.accessToken) {
  242. this.$toast('请登录后查看')
  243. setTimeout(() => {
  244. this.$router.push(`${this.routePrefix}`)
  245. }, 1500)
  246. return
  247. }
  248. this.$router.push(`${this.routePrefix}/record/club/detail`)
  249. },
  250. // 初始化从页面进入的表单
  251. async initFormWithLink() {
  252. const authId = this.$route.query.authId
  253. if (this.accessToken) {
  254. // 已登录
  255. this.step = 2
  256. this.stepList = this.stepList.filter((item) => item.id !== 1)
  257. } else {
  258. this.registerType.push(1)
  259. }
  260. await this.initClubInfo({
  261. authUserId: this.authUserId,
  262. authId: authId,
  263. })
  264. this.isRequest = false
  265. },
  266. // 初始化从正常页面进入的表单
  267. async initFormWithNormal() {
  268. if (this.accessToken) {
  269. // 已登录
  270. this.step = 2
  271. this.stepList = this.stepList.filter((item) => item.id !== 1)
  272. await this.initClubInfo({
  273. authUserId: this.authUserId,
  274. mobile: this.userInfo.mobile,
  275. })
  276. } else {
  277. // 未登录
  278. this.registerType.push(1, 2)
  279. }
  280. this.isRequest = false
  281. },
  282. // 初始化表单
  283. initPageForm() {
  284. const linkType = this.$route.query.type || 'normal'
  285. const taskMap = {
  286. link: this.initFormWithLink,
  287. normal: this.initFormWithNormal,
  288. }
  289. taskMap[linkType]()
  290. },
  291. // 判断用户手机号是否绑定机构
  292. async initClubInfo(data) {
  293. try {
  294. const res = await this.$http.api.fetchClubAuthInfo(data)
  295. if (res.data.auth) {
  296. this.autidStatus = res.data.auth.auditStatus
  297. this.authId = res.data.auth.authId
  298. } else {
  299. this.registerType.push(2)
  300. }
  301. return Promise.resolve(res)
  302. } catch (error) {
  303. console.log(error)
  304. return Promise.reject(error)
  305. }
  306. },
  307. },
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. // pc 端
  312. @media screen and (min-width: 768px) {
  313. .page {
  314. background: #fff;
  315. }
  316. .page-top {
  317. height: 360px;
  318. background: url(~assets/theme-images/hyt/pc/banner-register.png);
  319. background-size: auto 360px;
  320. background-position: center;
  321. .logo {
  322. display: block;
  323. width: 120px;
  324. height: 120px;
  325. border-radius: 50%;
  326. background: #fff;
  327. }
  328. .name {
  329. font-size: 30px;
  330. color: #fff;
  331. }
  332. }
  333. .page-content {
  334. width: 1200px;
  335. margin: 0 auto;
  336. overflow: hidden;
  337. min-height: calc(100vh - 80px - 80px - 360px);
  338. box-sizing: border-box;
  339. padding-bottom: 40px;
  340. .message {
  341. display: flex;
  342. justify-content: center;
  343. align-items: center;
  344. flex-direction: column;
  345. margin-top: 60px;
  346. .status-icon {
  347. width: 88px;
  348. height: 88px;
  349. background-repeat: no-repeat;
  350. background-size: 75px auto;
  351. background-position: center;
  352. &.success {
  353. background-image: url(~assets/theme-images/common/icon-auth-primary.png);
  354. }
  355. &.warning {
  356. background-image: url(~assets/theme-images/common/icon-auth-warning.png);
  357. }
  358. &.danger {
  359. background-image: url(~assets/theme-images/common/icon-auth-danger.png);
  360. }
  361. }
  362. .status {
  363. font-size: 18px;
  364. color: #282828;
  365. margin: 12px 0;
  366. }
  367. .tip {
  368. color: #999999;
  369. font-size: 14px;
  370. }
  371. }
  372. .control {
  373. margin-top: 62px;
  374. .button {
  375. width: 295px;
  376. height: 50px;
  377. border-radius: 4px;
  378. cursor: pointer;
  379. &.prev {
  380. border: 1px solid #4093B5;
  381. color: #4093B5;
  382. }
  383. &.next {
  384. background-color: #4093B5;
  385. color: #fff;
  386. }
  387. }
  388. .record {
  389. font-size: 14px;
  390. cursor: pointer;
  391. color: #4093B5;
  392. }
  393. }
  394. .step-list {
  395. width: 700px;
  396. margin: 0 auto;
  397. }
  398. }
  399. }
  400. // 移动端
  401. @media screen and (max-width: 768px) {
  402. .page {
  403. background: #fff;
  404. }
  405. .page-top {
  406. height: 46vw;
  407. background: url(~assets/theme-images/hyt/h5/banner-register.png);
  408. background-size: auto 46vw;
  409. background-position: center;
  410. .logo {
  411. display: block;
  412. width: 14.8vw;
  413. height: 14.8vw;
  414. border-radius: 50%;
  415. background: #fff;
  416. }
  417. .name {
  418. font-size: 4vw;
  419. color: #fff;
  420. }
  421. }
  422. .page-content {
  423. padding: 0 7vw 7vw;
  424. .message {
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. flex-direction: column;
  429. margin: 22.8vw 0;
  430. .status-icon {
  431. width: 23.6vw;
  432. height: 23.6vw;
  433. background-repeat: no-repeat;
  434. background-size: 20vw auto;
  435. background-position: center;
  436. &.success {
  437. background-image: url(~assets/theme-images/common/icon-auth-primary.png);
  438. }
  439. &.warning {
  440. background-image: url(~assets/theme-images/common/icon-auth-warning.png);
  441. }
  442. &.danger {
  443. background-image: url(~assets/theme-images/common/icon-auth-danger.png);
  444. }
  445. }
  446. .status {
  447. font-size: 4.2vw;
  448. color: #282828;
  449. margin: 3.2vw 0 2.4vw;
  450. }
  451. .tip {
  452. color: #999999;
  453. font-size: 3.2vw;
  454. }
  455. }
  456. .control {
  457. .button {
  458. width: 85.6vw;
  459. height: 12vw;
  460. border-radius: 4px;
  461. cursor: pointer;
  462. &.prev {
  463. border: 1px solid #4093B5;
  464. color: #4093B5;
  465. }
  466. &.next {
  467. background-color: #4093B5;
  468. color: #fff;
  469. }
  470. }
  471. .record {
  472. margin-top: 4.8vw;
  473. font-size: 3.4vw;
  474. cursor: pointer;
  475. color: #4093B5;
  476. }
  477. }
  478. }
  479. }
  480. </style>