123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- import { connect } from 'herculex';
- import { Ajax, valueToBase64 } from '../utils';
- const cardInfoApi = 'api/v1/proxy/isvRequest.healthCard.details';
- const openCardApi = 'api/v1/proxy/isvRequest.healthCard.open';
- const refreshCardApi = 'api/v1/proxy/isvRequest.healthCard.refresh';
- const {
- windowHeight: wH,
- titleBarHeight: tH,
- statusBarHeight: sH
- } = my.getSystemInfoSync();
- const pageHeight = wH - tH - sH;
- Component(connect({})({
- data: {
- step: -1,
- cardInfo: {},
- loading: true,
- viewHeight: `${pageHeight}px`
- },
- props: {
- componentData: {}
- },
- async didMount() {
- const {
- storeConfig
- } = this;
- const state = storeConfig.state;
- const {
- userInfo
- } = state.$global;
- const {
- isLogin = false
- } = userInfo || {};
- /*
- * 判断是否已经登录
- * */
- if (isLogin) {
- await this.getCardInfo();
- return;
- }
- this.setData({
- loading: false
- });
- },
- methods: {
- /*
- * 获取当前页面实例
- * */
- getCurPage() {
- const pages = getCurrentPages();
- return pages[pages.length - 1];
- },
- /*
- * 打开loading
- * */
- loadingShow(msg = '') {
- my.showLoading({
- content: msg
- }).then(() => null);
- },
- /*
- * 关闭loading
- * */
- loadingClose() {
- my.hideLoading({
- page: this.getCurPage()
- }).then(() => null);
- },
- /*
- * 退出页面
- * */
- onExitPage() {
- my.navigateBack();
- },
- /*
- * 获取卡的详情
- * */
- async getCardInfo() {
- let info = null;
- let success = true;
- try {
- // my.showLoading();
- info = await Ajax(cardInfoApi); // my.hideLoading();
- } catch (e) {
- success = false;
- this.getCardInfoFail();
- }
- const _data = {
- loading: false,
- step: 0
- };
- if (success && info) {
- _data.step = 1;
- _data.cardInfo = await this.getInfo(info);
- }
- this.setData(_data);
- },
- /*
- * 获取卡详情失败
- * */
- getCardInfoFail() {
- my.confirm({
- title: '获取卡信息失败!',
- cancelButtonText: '取消',
- confirmButtonText: '重新获取',
- success: ({
- confirm
- }) => !confirm ? this.onExitPage() : this.getCardInfo()
- });
- },
- /*
- * 开卡
- * */
- async onCardOpen() {
- let info = null;
- let success = true;
- this.loadingShow('领取中..');
- try {
- info = await Ajax(openCardApi);
- } catch (e) {
- success = false;
- this.onCardOpenFail();
- }
- const _data = {
- loading: false
- };
- if (success && info) {
- _data.step = 1;
- _data.cardInfo = await this.getInfo(info);
- }
- this.setData(_data);
- this.loadingClose();
- },
- /*
- * 开卡失败
- * */
- onCardOpenFail() {
- my.confirm({
- title: '领取卡片失败!',
- cancelButtonText: '取消',
- confirmButtonText: '重新领取',
- success: async ({
- confirm
- }) => {
- if (confirm) await this.onCardOpen();
- }
- });
- },
- /*
- * 刷新健康卡
- * */
- async onRefreshCard(healthCardId) {
- let info = null;
- let success = true;
- const para = {
- healthCardId
- };
- this.setData({
- loading: true
- });
- try {
- my.showLoading();
- info = await Ajax(refreshCardApi, para);
- my.hideLoading();
- } catch (e) {
- success = false;
- this.onRefreshCardFail();
- }
- const _data = {
- loading: false
- };
- if (success && info) {
- _data.cardInfo = await this.getInfo(info);
- }
- this.setData(_data);
- },
- /*
- * 刷新卡信息失败
- * */
- onRefreshCardFail() {
- my.confirm({
- title: '刷新失败',
- cancelButtonText: '取消',
- confirmButtonText: '重试',
- success: async ({
- confirm
- }) => {
- if (confirm) await this.onRefreshCard();
- }
- });
- },
- /*
- * 组装二维码url数据
- * */
- async getInfo(_info_) {
- const {
- qrCode,
- qrCodeUrl
- } = _info_;
- if (!qrCodeUrl) {
- _info_.qrCodeUrl = await valueToBase64(qrCode);
- }
- return _info_;
- },
- /*
- * 点击认证按钮
- * */
- async onAuthTap() {
- /*
- * 调用授权接口登录
- * */
- const type = '$global:onPageLogin';
- const isLoginSuccess = await this.dispatch(type);
- if (isLoginSuccess) {
- await this.onCardOpen();
- }
- },
- toNextPage(page) {
- this.setData({
- step: page
- });
- },
- onBackCard() {
- this.setData({
- step: 1
- });
- }
- }
- }));
|