club-register.vue 12 KB

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