applyAuth.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <template>
  2. <view class="apply-auth-page">
  3. <!-- 页面内挂载公共弹窗,保证 APP 真机可用 -->
  4. <AppConfirm ref="AppConfirm" />
  5. <scroll-view class="page-scroll" :scroll-y="true" :scroll-with-animation="true" :scroll-into-view="activeRowId" :style="{ '--kb-gap': kbGap + 'px' }">
  6. <!-- 顶部背景图:请将图片放入本页 images 目录,文件名仅使用字母/下划线 -->
  7. <view class="top-banner">
  8. <image class="top-bg-img" src="/static/images/bgtop.png" mode="widthFix" />
  9. <!-- 顶部信息区:logo、标题、说明(覆盖在背景图上) -->
  10. <view class="head">
  11. <image class="logo" :src="logoSrc" mode="widthFix" @error="onImageError" @load="onImageLoad" />
  12. <view class="tit-wrap">
  13. <text class="title">{{ pageTitle }}</text>
  14. <text class="desc">{{ pageDesc }}</text>
  15. </view>
  16. </view>
  17. </view>
  18. <!-- 信息表单卡片 -->
  19. <view class="form">
  20. <!-- 待审核状态或授权到期状态:只读展示 -->
  21. <view v-if="isReviewing || isExpired" class="review-mode">
  22. <view class="row">
  23. <view class="label-with-icon">
  24. <image class="label-icon" src="/static/images/hosp.png" mode="aspectFit" />
  25. <text class="label">医院</text>
  26. </view>
  27. <text class="value">{{ form.hospital }}</text>
  28. </view>
  29. <view class="row">
  30. <view class="label-with-icon">
  31. <image class="label-icon" src="/static/images/depart.png" mode="aspectFit" />
  32. <text class="label">科室</text>
  33. </view>
  34. <text class="value">{{ form.department }}</text>
  35. </view>
  36. <view class="row">
  37. <view class="label-with-icon">
  38. <image class="label-icon" src="/static/images/name.png" mode="aspectFit" />
  39. <text class="label">姓名</text>
  40. </view>
  41. <text class="value">{{ form.name }}</text>
  42. </view>
  43. <view class="row">
  44. <view class="label-with-icon">
  45. <image class="label-icon" src="/static/images/number.png" mode="aspectFit" />
  46. <text class="label">电话</text>
  47. </view>
  48. <text class="value">{{ form.phone }}</text>
  49. </view>
  50. <view class="row">
  51. <view class="label-with-icon">
  52. <image class="label-icon" src="/static/images/time.png" mode="aspectFit" />
  53. <text class="label">申请时间</text>
  54. </view>
  55. <text class="value">{{ applyTime }}</text>
  56. </view>
  57. <view class="row no-border">
  58. <view class="label-with-icon">
  59. <image class="label-icon" src="/static/images/remark.png" mode="aspectFit" />
  60. <text class="label">备注</text>
  61. </view>
  62. <text class="value">{{ form.remark }}</text>
  63. </view>
  64. </view>
  65. <!-- 申请状态:可输入 -->
  66. <view v-else>
  67. <view class="row" id="row-hospital"><text class="label">医院</text><input class="ipt" v-model="form.hospital" placeholder="请输入" placeholder-class="ph" @focus="onFocus('row-hospital','hospital')" @blur="onBlur" cursor-spacing="20" confirm-type="next" :confirm-hold="true" @confirm="onConfirmNext('hospital')" :focus="focusField==='hospital'" /></view>
  68. <view class="row" id="row-department"><text class="label">科室</text><input class="ipt" v-model="form.department" placeholder="请输入" placeholder-class="ph" @focus="onFocus('row-department','department')" @blur="onBlur" cursor-spacing="20" confirm-type="next" :confirm-hold="true" @confirm="onConfirmNext('department')" :focus="focusField==='department'" /></view>
  69. <view class="row" id="row-name"><text class="label">姓名</text><input class="ipt" v-model="form.name" placeholder="请输入" placeholder-class="ph" @focus="onFocus('row-name','name')" @blur="onBlur" cursor-spacing="20" confirm-type="next" :confirm-hold="true" @confirm="onConfirmNext('name')" :focus="focusField==='name'" /></view>
  70. <view class="row no-border" id="row-phone"><text class="label">电话</text><input class="ipt" v-model="form.phone" placeholder="请输入" placeholder-class="ph" @focus="onFocus('row-phone','phone')" @blur="onBlur" cursor-spacing="20" confirm-type="next" :confirm-hold="true" @confirm="onConfirmNext('phone')" :focus="focusField==='phone'" /></view>
  71. </view>
  72. </view>
  73. <!-- 备注独立卡片 - 只在申请状态显示 -->
  74. <view class="remark-card" v-if="!isReviewing && !isExpired">
  75. <view class="row no-border" id="row-remark">
  76. <text class="label">备注</text>
  77. <input class="ipt" v-model="form.remark" placeholder="请输入(选填)" placeholder-class="ph" @focus="onFocus('row-remark','remark')" @blur="onBlur" cursor-spacing="20" confirm-type="done" @confirm="onConfirmNext('remark')" :focus="focusField==='remark'" />
  78. </view>
  79. </view>
  80. <!-- 在非审核状态或授权到期状态显示提交按钮 -->
  81. <view v-if="!isReviewing || isExpired" class="fixed-buttom-btn" :class="{ 'can-submit': canSubmit || isExpired }" @click="onSubmit">
  82. <text class="btn-text">{{ isExpired ? '重新申请' : '申请授权' }}</text>
  83. </view>
  84. </scroll-view>
  85. </view>
  86. </template>
  87. <script>
  88. import { submitAuthorizationApply } from '@/utils/authorize.js';
  89. import AppConfirm from '@/components/app-confirm/app-confirm.vue'
  90. export default {
  91. components: { AppConfirm },
  92. data() {
  93. return {
  94. form: {
  95. hospital: '',
  96. department: '',
  97. name: '',
  98. phone: '',
  99. remark: ''
  100. },
  101. imei: '',
  102. // 当前聚焦的行,用于 scroll-into-view 将其滚入可视区域
  103. activeRowId: '',
  104. // 键盘占用的高度,H5 通过 visualViewport 获取
  105. kbGap: 0,
  106. // 是否处于待审核状态
  107. isReviewing: false,
  108. // 是否授权已到期
  109. isExpired: false,
  110. // 申请时间
  111. applyTime: '',
  112. // 当前聚焦字段,用于回车切换焦点
  113. focusField: ''
  114. }
  115. },
  116. onLoad(params) {
  117. this.imei = params && params.imei ? params.imei : '';
  118. // 检查是否授权到期
  119. if (params && params.expired === 'true') {
  120. this.isExpired = true;
  121. }
  122. // 若明确携带未授权状态,强制清空本地审核/到期缓存,避免误判
  123. if (params && params.status === 'unauthorized') {
  124. try {
  125. uni.removeStorageSync('authApplyInfo');
  126. uni.removeStorageSync('authExpiredInfo');
  127. } catch (e) {}
  128. }
  129. // 检查页面状态(审核中或授权到期)
  130. this.checkPageStatus();
  131. },
  132. mounted(){
  133. // 调试信息
  134. console.log('页面mounted - 当前状态:', {
  135. isReviewing: this.isReviewing,
  136. isExpired: this.isExpired,
  137. logoSrc: this.logoSrc,
  138. pageTitle: this.pageTitle
  139. });
  140. // 仅 H5:使用 visualViewport 计算键盘占用高度,作为底部填充,避免遮挡
  141. // #ifdef H5
  142. if (typeof window !== 'undefined' && window.visualViewport){
  143. const applyGap = () => {
  144. const gap = Math.max(0, window.innerHeight - window.visualViewport.height);
  145. this.kbGap = gap;
  146. document.documentElement.style.setProperty('--kb-gap', gap + 'px');
  147. };
  148. window.visualViewport.addEventListener('resize', applyGap);
  149. this.$once('hook:beforeDestroy', () => {
  150. window.visualViewport && window.visualViewport.removeEventListener('resize', applyGap);
  151. });
  152. applyGap();
  153. }
  154. // #endif
  155. },
  156. computed: {
  157. // 判断必填项是否都已填写(备注为选填)
  158. canSubmit() {
  159. return this.form.hospital &&
  160. this.form.department &&
  161. this.form.name &&
  162. this.form.phone;
  163. },
  164. // Logo源路径
  165. logoSrc() {
  166. console.log('计算logoSrc:', { isExpired: this.isExpired, isReviewing: this.isReviewing });
  167. if (this.isExpired) {
  168. return '/static/images/gray_logo.png';
  169. }
  170. return '/static/images/blue_logo.png';
  171. },
  172. // 页面标题
  173. pageTitle() {
  174. if (this.isExpired) {
  175. return '授权已到期';
  176. }
  177. if (this.isReviewing) {
  178. return '申请审核中...';
  179. }
  180. return '设备未授权';
  181. },
  182. // 页面描述
  183. pageDesc() {
  184. if (this.isExpired) {
  185. return '如需继续使用设备,请重新申请授权';
  186. }
  187. if (this.isReviewing) {
  188. return '您的申请已提交,我们将在3个工作日内联系您';
  189. }
  190. return '提交以下信息申请开通,我们将在3个工作日内联系您';
  191. }
  192. },
  193. methods: {
  194. // 检查页面状态(审核中或授权到期)
  195. checkPageStatus() {
  196. try {
  197. // 如果是授权到期状态
  198. if (this.isExpired) {
  199. // 授权到期时,从本地存储获取之前的申请信息用于显示
  200. const expiredInfo = uni.getStorageSync('authExpiredInfo');
  201. if (expiredInfo && expiredInfo.imei === this.imei) {
  202. this.form = {
  203. hospital: expiredInfo.hospital || '',
  204. department: expiredInfo.department || '',
  205. name: expiredInfo.name || '',
  206. phone: expiredInfo.phone || '',
  207. remark: expiredInfo.remark || ''
  208. };
  209. this.applyTime = expiredInfo.applyTime || '';
  210. }
  211. console.log('授权到期状态数据:', {
  212. isExpired: this.isExpired,
  213. form: this.form,
  214. applyTime: this.applyTime
  215. });
  216. return;
  217. }
  218. // 检查是否有待审核的申请信息
  219. const applyInfo = uni.getStorageSync('authApplyInfo');
  220. if (applyInfo && applyInfo.imei === this.imei) {
  221. // 如果存在申请信息且IMEI匹配,显示待审核状态
  222. this.isReviewing = true;
  223. this.form = {
  224. hospital: applyInfo.hospital || '',
  225. department: applyInfo.department || '',
  226. name: applyInfo.name || '',
  227. phone: applyInfo.phone || '',
  228. remark: applyInfo.remark || ''
  229. };
  230. this.applyTime = applyInfo.applyTime || '';
  231. console.log('待审核状态数据:', {
  232. isReviewing: this.isReviewing,
  233. form: this.form,
  234. applyTime: this.applyTime
  235. });
  236. return;
  237. }
  238. // 如果没有找到状态数据,显示默认的申请表单状态
  239. console.log('显示申请表单状态:', {
  240. isReviewing: this.isReviewing,
  241. isExpired: this.isExpired,
  242. imei: this.imei
  243. });
  244. } catch (e) {
  245. console.error('获取状态信息失败:', e);
  246. }
  247. },
  248. // 格式化申请时间
  249. formatApplyTime() {
  250. const now = new Date();
  251. const year = now.getFullYear();
  252. const month = String(now.getMonth() + 1).padStart(2, '0');
  253. const day = String(now.getDate()).padStart(2, '0');
  254. return `${year}年${month}月${day}日`;
  255. },
  256. onFocus(id){
  257. // 记录当前聚焦行,触发 scroll-into-view
  258. this.activeRowId = id;
  259. // H5 再次触发一次,等待键盘动画后保证可见
  260. // #ifdef H5
  261. setTimeout(() => { this.activeRowId = id; }, 250);
  262. // #endif
  263. },
  264. onBlur(){
  265. this.activeRowId = '';
  266. },
  267. // 回车切换到下一个表单项
  268. onConfirmNext(field){
  269. const order = ['hospital','department','name','phone','remark'];
  270. const idx = order.indexOf(field);
  271. const next = order[idx + 1];
  272. if (next) {
  273. this.focusField = next;
  274. // 触发展示到视口
  275. const idMap = {
  276. hospital: 'row-hospital',
  277. department: 'row-department',
  278. name: 'row-name',
  279. phone: 'row-phone',
  280. remark: 'row-remark'
  281. };
  282. this.onFocus(idMap[next]);
  283. } else {
  284. // 最后一项回车:提交
  285. this.focusField = '';
  286. this.onSubmit();
  287. }
  288. },
  289. // 图片加载成功
  290. onImageLoad() {
  291. console.log('Logo加载成功:', this.logoSrc);
  292. },
  293. // 图片加载失败
  294. onImageError(e) {
  295. console.error('Logo加载失败:', this.logoSrc, e);
  296. },
  297. async onSubmit() {
  298. // 如果是授权到期状态,切换到申请表单状态
  299. if (this.isExpired) {
  300. // 清除到期状态数据
  301. uni.removeStorageSync('authExpiredInfo');
  302. // 重置表单为初始空值(过期态下展示的 data 不能带入填写态)
  303. this.form = {
  304. hospital: '',
  305. department: '',
  306. name: '',
  307. phone: '',
  308. remark: ''
  309. };
  310. this.applyTime = '';
  311. // 切换到申请状态
  312. this.isExpired = false;
  313. this.isReviewing = false;
  314. uni.showToast({ title: '请重新填写申请信息', icon: 'none' });
  315. return;
  316. }
  317. // 普通申请状态的校验和提交
  318. if (!this.form.hospital || !this.form.department || !this.form.name || !this.form.phone) {
  319. uni.showToast({ title: '请完整填写必填信息', icon: 'none' });
  320. return;
  321. }
  322. const payload = { ...this.form, imei: this.imei };
  323. try {
  324. const ok = await submitAuthorizationApply(payload);
  325. if (ok) {
  326. // 保存申请信息到本地存储
  327. const applyInfo = {
  328. ...this.form,
  329. imei: this.imei,
  330. applyTime: this.formatApplyTime()
  331. };
  332. uni.setStorageSync('authApplyInfo', applyInfo);
  333. // 更新为待审核状态
  334. this.isReviewing = true;
  335. this.applyTime = applyInfo.applyTime;
  336. uni.showToast({ title: '提交成功,等待授权', icon: 'none' });
  337. // 不再跳转,直接在当前页面显示待审核状态
  338. }
  339. } catch(e) {
  340. // 接口层已统一弹窗提示错误,这里只阻止后续逻辑
  341. }
  342. }
  343. }
  344. }
  345. </script>
  346. <style lang="less" scoped>
  347. .apply-auth-page{
  348. background-color: #F5F7FA;
  349. /* 让整体随可视视口高度缩放,避免键盘遮挡 */
  350. .page-scroll{
  351. height: 100vh;
  352. height: 100svh;
  353. overflow-y: auto;
  354. -webkit-overflow-scrolling: touch;
  355. padding-bottom: calc(env(safe-area-inset-bottom) + var(--kb-gap, 0px));
  356. /* 使 scroll-into-view 目标行在底部仍留出空间 */
  357. scroll-padding-bottom: calc(env(safe-area-inset-bottom) + var(--kb-gap, 0px));
  358. }
  359. .top-banner{
  360. position: relative;
  361. margin-bottom: 0vh;
  362. .top-bg-img{width: 100%; display: block;}
  363. .head{
  364. position: absolute; left: 24rpx; top: 10vh; right: 24rpx;
  365. display:flex;align-items:flex-start;flex-direction:column;
  366. padding: 0 30rpx;
  367. .logo{
  368. width: 120rpx;
  369. height: 120rpx;
  370. margin-bottom: 60rpx;
  371. display: block;
  372. }
  373. .tit-wrap{display:flex;flex-direction:column;}
  374. .title{font-size: 45rpx;color:#292C33;margin-bottom: 20rpx;}
  375. .desc{font-size: 25rpx;color:#7A8499;line-height: 40rpx;}
  376. }
  377. }
  378. // 主表单卡片样式
  379. .form{
  380. background: #fff;
  381. border-radius: 18rpx;
  382. padding: 0 30rpx;
  383. margin:0 50rpx;
  384. box-shadow: 0 12rpx 36rpx rgba(0,0,0,0.04);
  385. .row{
  386. display:flex;align-items:center;min-height: 80rpx;
  387. &.no-border{border-bottom: none;}
  388. .label{width: 140rpx;color:#525866;font-size: 28rpx;}
  389. .ipt{flex:1;height: 100rpx;border: none;padding: 0 4rpx;font-size:28rpx;text-align: right;}
  390. .ph{color:#B8BFCC;font-size: 28rpx;}
  391. // 待审核状态的只读值样式
  392. .value{
  393. flex:1;
  394. text-align: right;
  395. font-size: 28rpx;
  396. color: #292C33;
  397. padding: 0 4rpx;
  398. }
  399. // 带图标的标签样式
  400. .label-with-icon{
  401. width: 180rpx;
  402. display: flex;
  403. align-items: center;
  404. flex-shrink: 0;
  405. .label-icon{
  406. width: 32rpx;
  407. height: 32rpx;
  408. margin-right: 16rpx;
  409. flex-shrink: 0;
  410. }
  411. .label{
  412. width: auto;
  413. flex: 1;
  414. white-space: nowrap;
  415. }
  416. }
  417. }
  418. // 待审核模式的特殊样式
  419. .review-mode{
  420. .row{
  421. padding: 30rpx 0;
  422. min-height: auto;
  423. }
  424. }
  425. }
  426. // 备注卡片
  427. .remark-card{
  428. margin:0 50rpx;
  429. margin-top: 1.5vh;
  430. background: #fff;
  431. border-radius: 18rpx;
  432. padding:5rpx 30rpx;
  433. box-shadow: 0 12rpx 36rpx rgba(0,0,0,0.04);
  434. .row{
  435. display:flex;
  436. align-items:center;
  437. min-height: 80rpx;
  438. // padding: 25rpx 0;
  439. }
  440. .label{width: 140rpx;color:#525866;font-size: 28rpx;}
  441. .ipt{flex:1;height: 100rpx;border: none;padding: 0 4rpx;font-size:28rpx;text-align: right;}
  442. .ph{color:#B8C0CC;font-size: 28rpx;}
  443. // 待审核状态的只读值样式
  444. .value{
  445. flex:1;
  446. text-align: right;
  447. font-size: 28rpx;
  448. color: #292C33;
  449. padding: 0 4rpx;
  450. }
  451. // 带图标的标签样式
  452. .label-with-icon{
  453. width: 180rpx;
  454. display: flex;
  455. align-items: center;
  456. flex-shrink: 0;
  457. .label-icon{
  458. width: 32rpx;
  459. height: 32rpx;
  460. margin-right: 16rpx;
  461. flex-shrink: 0;
  462. }
  463. .label{
  464. width: auto;
  465. flex: 1;
  466. white-space: nowrap;
  467. }
  468. }
  469. }
  470. // 申请授权按钮样式,跟随在内容后面 (使用!important覆盖全局样式)
  471. .fixed-buttom-btn{
  472. position: static !important;
  473. left: auto !important;
  474. bottom: auto !important;
  475. width: auto !important;
  476. margin: 3vh 50rpx 0vh 50rpx !important;
  477. height: 100rpx !important;
  478. border-radius: 60rpx !important;
  479. // 默认状态:灰色渐变背景
  480. background: linear-gradient(135deg, #A3B1CC 0%, #A3B1CC 100%) !important;
  481. box-shadow: 0 8rpx 24rpx rgba(139, 157, 195, 0.4) !important;
  482. display: flex !important;
  483. align-items: center !important;
  484. justify-content: center !important;
  485. transition: all 0.3s ease !important;
  486. // 可提交状态:蓝色背景
  487. &.can-submit {
  488. background: #3377FF !important;
  489. box-shadow: 0 8rpx 24rpx rgba(51, 119, 255, 0.4) !important;
  490. }
  491. &:active {
  492. transform: scale(0.98);
  493. }
  494. &:active:not(.can-submit) {
  495. box-shadow: 0 4rpx 12rpx rgba(139, 157, 195, 0.3);
  496. }
  497. &:active.can-submit {
  498. box-shadow: 0 4rpx 12rpx rgba(51, 119, 255, 0.3);
  499. }
  500. .btn-text{
  501. flex: none !important;
  502. font-size: 34rpx !important;
  503. color: #FFFFFF !important;
  504. font-weight: 600 !important;
  505. letter-spacing: 2rpx !important;
  506. }
  507. }
  508. }
  509. </style>
  510. ie a